winealsa.drv: Remove wave, mixer, and dsound driver code.

This commit is contained in:
Andrew Eikum 2011-09-23 15:03:51 -05:00 committed by Alexandre Julliard
parent 55542281f5
commit 8258a5188c
12 changed files with 74 additions and 7610 deletions

View file

@ -1,16 +1,9 @@
MODULE = winealsa.drv
IMPORTS = dxguid uuid winmm ole32 user32 advapi32
IMPORTS = uuid winmm ole32
EXTRALIBS = @ALSALIBS@
C_SRCS = \
alsa.c \
dscapture.c \
dsoutput.c \
midi.c \
mixer.c \
mmdevdrv.c \
wavein.c \
waveinit.c \
waveout.c
mmdevdrv.c
@MAKE_DLL_RULES@

View file

@ -1,755 +0,0 @@
/*
* Wine Driver for ALSA
*
* Copyright 2002 Eric Pouech
* Copyright 2006 Jaroslav Kysela
* Copyright 2007 Maarten Lankhorst
*
* This file has a few shared generic subroutines shared among the alsa
* implementation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "config.h"
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "wingdi.h"
#include "winuser.h"
#include "winnls.h"
#include "winerror.h"
#include "mmddk.h"
#include "mmreg.h"
#include "dsound.h"
#include "dsdriver.h"
#include "ks.h"
#include "wine/library.h"
#include "wine/unicode.h"
#include "wine/debug.h"
#include "alsa.h"
#include "initguid.h"
#include "ksmedia.h"
WINE_DEFAULT_DEBUG_CHANNEL(alsa);
/* unless someone makes a wineserver kernel module, Unix pipes are faster than win32 events */
#define USE_PIPE_SYNC
#ifdef USE_PIPE_SYNC
#define INIT_OMR(omr) do { if (pipe(omr->msg_pipe) < 0) { omr->msg_pipe[0] = omr->msg_pipe[1] = -1; } } while (0)
#define CLOSE_OMR(omr) do { close(omr->msg_pipe[0]); close(omr->msg_pipe[1]); } while (0)
#define SIGNAL_OMR(omr) do { int x = 0; write((omr)->msg_pipe[1], &x, sizeof(x)); } while (0)
#define CLEAR_OMR(omr) do { int x = 0; read((omr)->msg_pipe[0], &x, sizeof(x)); } while (0)
#define RESET_OMR(omr) do { } while (0)
#define WAIT_OMR(omr, sleep) \
do { struct pollfd pfd; pfd.fd = (omr)->msg_pipe[0]; \
pfd.events = POLLIN; poll(&pfd, 1, sleep); } while (0)
#else
#define INIT_OMR(omr) do { omr->msg_event = CreateEventW(NULL, FALSE, FALSE, NULL); } while (0)
#define CLOSE_OMR(omr) do { CloseHandle(omr->msg_event); } while (0)
#define SIGNAL_OMR(omr) do { SetEvent((omr)->msg_event); } while (0)
#define CLEAR_OMR(omr) do { } while (0)
#define RESET_OMR(omr) do { ResetEvent((omr)->msg_event); } while (0)
#define WAIT_OMR(omr, sleep) \
do { WaitForSingleObject((omr)->msg_event, sleep); } while (0)
#endif
#define ALSA_RING_BUFFER_INCREMENT 64
/******************************************************************
* ALSA_InitRingMessage
*
* Initialize the ring of messages for passing between driver's caller and playback/record
* thread
*/
int ALSA_InitRingMessage(ALSA_MSG_RING* omr)
{
omr->msg_toget = 0;
omr->msg_tosave = 0;
INIT_OMR(omr);
omr->ring_buffer_size = ALSA_RING_BUFFER_INCREMENT;
omr->messages = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,omr->ring_buffer_size * sizeof(ALSA_MSG));
InitializeCriticalSection(&omr->msg_crst);
omr->msg_crst.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": ALSA_MSG_RING.msg_crst");
return 0;
}
/******************************************************************
* ALSA_DestroyRingMessage
*
*/
int ALSA_DestroyRingMessage(ALSA_MSG_RING* omr)
{
CLOSE_OMR(omr);
HeapFree(GetProcessHeap(),0,omr->messages);
omr->ring_buffer_size = 0;
omr->msg_crst.DebugInfo->Spare[0] = 0;
DeleteCriticalSection(&omr->msg_crst);
return 0;
}
/******************************************************************
* ALSA_ResetRingMessage
*
*/
void ALSA_ResetRingMessage(ALSA_MSG_RING* omr)
{
RESET_OMR(omr);
}
/******************************************************************
* ALSA_WaitRingMessage
*
*/
void ALSA_WaitRingMessage(ALSA_MSG_RING* omr, DWORD sleep)
{
WAIT_OMR(omr, sleep);
}
/******************************************************************
* ALSA_AddRingMessage
*
* Inserts a new message into the ring (should be called from DriverProc derived routines)
*/
int ALSA_AddRingMessage(ALSA_MSG_RING* omr, enum win_wm_message msg, DWORD_PTR param, BOOL wait)
{
HANDLE hEvent = NULL;
EnterCriticalSection(&omr->msg_crst);
if (omr->msg_toget == ((omr->msg_tosave + 1) % omr->ring_buffer_size))
{
int old_ring_buffer_size = omr->ring_buffer_size;
omr->ring_buffer_size += ALSA_RING_BUFFER_INCREMENT;
omr->messages = HeapReAlloc(GetProcessHeap(),0,omr->messages, omr->ring_buffer_size * sizeof(ALSA_MSG));
/* Now we need to rearrange the ring buffer so that the new
buffers just allocated are in between omr->msg_tosave and
omr->msg_toget.
*/
if (omr->msg_tosave < omr->msg_toget)
{
memmove(&(omr->messages[omr->msg_toget + ALSA_RING_BUFFER_INCREMENT]),
&(omr->messages[omr->msg_toget]),
sizeof(ALSA_MSG)*(old_ring_buffer_size - omr->msg_toget)
);
omr->msg_toget += ALSA_RING_BUFFER_INCREMENT;
}
}
if (wait)
{
hEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
if (!hEvent)
{
ERR("can't create event !?\n");
LeaveCriticalSection(&omr->msg_crst);
return 0;
}
if (omr->msg_toget != omr->msg_tosave && omr->messages[omr->msg_toget].msg != WINE_WM_HEADER)
FIXME("two fast messages in the queue!!!! toget = %d(%s), tosave=%d(%s)\n",
omr->msg_toget,ALSA_getCmdString(omr->messages[omr->msg_toget].msg),
omr->msg_tosave,ALSA_getCmdString(omr->messages[omr->msg_tosave].msg));
/* fast messages have to be added at the start of the queue */
omr->msg_toget = (omr->msg_toget + omr->ring_buffer_size - 1) % omr->ring_buffer_size;
omr->messages[omr->msg_toget].msg = msg;
omr->messages[omr->msg_toget].param = param;
omr->messages[omr->msg_toget].hEvent = hEvent;
}
else
{
omr->messages[omr->msg_tosave].msg = msg;
omr->messages[omr->msg_tosave].param = param;
omr->messages[omr->msg_tosave].hEvent = NULL;
omr->msg_tosave = (omr->msg_tosave + 1) % omr->ring_buffer_size;
}
LeaveCriticalSection(&omr->msg_crst);
/* signal a new message */
SIGNAL_OMR(omr);
if (wait)
{
/* wait for playback/record thread to have processed the message */
WaitForSingleObject(hEvent, INFINITE);
CloseHandle(hEvent);
}
return 1;
}
/******************************************************************
* ALSA_RetrieveRingMessage
*
* Get a message from the ring. Should be called by the playback/record thread.
*/
int ALSA_RetrieveRingMessage(ALSA_MSG_RING* omr, enum win_wm_message *msg,
DWORD_PTR *param, HANDLE *hEvent)
{
EnterCriticalSection(&omr->msg_crst);
if (omr->msg_toget == omr->msg_tosave) /* buffer empty ? */
{
LeaveCriticalSection(&omr->msg_crst);
return 0;
}
*msg = omr->messages[omr->msg_toget].msg;
omr->messages[omr->msg_toget].msg = 0;
*param = omr->messages[omr->msg_toget].param;
*hEvent = omr->messages[omr->msg_toget].hEvent;
omr->msg_toget = (omr->msg_toget + 1) % omr->ring_buffer_size;
CLEAR_OMR(omr);
LeaveCriticalSection(&omr->msg_crst);
return 1;
}
/*======================================================================*
* Utility functions *
*======================================================================*/
/* These strings used only for tracing */
const char * ALSA_getCmdString(enum win_wm_message msg)
{
#define MSG_TO_STR(x) case x: return #x
switch(msg) {
MSG_TO_STR(WINE_WM_PAUSING);
MSG_TO_STR(WINE_WM_RESTARTING);
MSG_TO_STR(WINE_WM_RESETTING);
MSG_TO_STR(WINE_WM_HEADER);
MSG_TO_STR(WINE_WM_UPDATE);
MSG_TO_STR(WINE_WM_BREAKLOOP);
MSG_TO_STR(WINE_WM_CLOSING);
MSG_TO_STR(WINE_WM_STARTING);
MSG_TO_STR(WINE_WM_STOPPING);
}
#undef MSG_TO_STR
return wine_dbg_sprintf("UNKNOWN(0x%08x)", msg);
}
const char * ALSA_getMessage(UINT msg)
{
#define MSG_TO_STR(x) case x: return #x
switch(msg) {
MSG_TO_STR(DRVM_INIT);
MSG_TO_STR(DRVM_EXIT);
MSG_TO_STR(DRVM_ENABLE);
MSG_TO_STR(DRVM_DISABLE);
MSG_TO_STR(WIDM_OPEN);
MSG_TO_STR(WIDM_CLOSE);
MSG_TO_STR(WIDM_ADDBUFFER);
MSG_TO_STR(WIDM_PREPARE);
MSG_TO_STR(WIDM_UNPREPARE);
MSG_TO_STR(WIDM_GETDEVCAPS);
MSG_TO_STR(WIDM_GETNUMDEVS);
MSG_TO_STR(WIDM_GETPOS);
MSG_TO_STR(WIDM_RESET);
MSG_TO_STR(WIDM_START);
MSG_TO_STR(WIDM_STOP);
MSG_TO_STR(WODM_OPEN);
MSG_TO_STR(WODM_CLOSE);
MSG_TO_STR(WODM_WRITE);
MSG_TO_STR(WODM_PAUSE);
MSG_TO_STR(WODM_GETPOS);
MSG_TO_STR(WODM_BREAKLOOP);
MSG_TO_STR(WODM_PREPARE);
MSG_TO_STR(WODM_UNPREPARE);
MSG_TO_STR(WODM_GETDEVCAPS);
MSG_TO_STR(WODM_GETNUMDEVS);
MSG_TO_STR(WODM_GETPITCH);
MSG_TO_STR(WODM_SETPITCH);
MSG_TO_STR(WODM_GETPLAYBACKRATE);
MSG_TO_STR(WODM_SETPLAYBACKRATE);
MSG_TO_STR(WODM_GETVOLUME);
MSG_TO_STR(WODM_SETVOLUME);
MSG_TO_STR(WODM_RESTART);
MSG_TO_STR(WODM_RESET);
MSG_TO_STR(DRV_QUERYDEVICEINTERFACESIZE);
MSG_TO_STR(DRV_QUERYDEVICEINTERFACE);
MSG_TO_STR(DRV_QUERYDSOUNDIFACE);
MSG_TO_STR(DRV_QUERYDSOUNDDESC);
}
#undef MSG_TO_STR
return wine_dbg_sprintf("UNKNOWN(0x%04x)", msg);
}
const char * ALSA_getFormat(WORD wFormatTag)
{
#define FMT_TO_STR(x) case x: return #x
switch(wFormatTag) {
FMT_TO_STR(WAVE_FORMAT_PCM);
FMT_TO_STR(WAVE_FORMAT_EXTENSIBLE);
FMT_TO_STR(WAVE_FORMAT_MULAW);
FMT_TO_STR(WAVE_FORMAT_ALAW);
FMT_TO_STR(WAVE_FORMAT_ADPCM);
}
#undef FMT_TO_STR
return wine_dbg_sprintf("UNKNOWN(0x%04x)", wFormatTag);
}
/* Allow 1% deviation for sample rates (some ES137x cards) */
BOOL ALSA_NearMatch(int rate1, int rate2)
{
return (((100 * (rate1 - rate2)) / rate1) == 0);
}
DWORD ALSA_bytes_to_mmtime(LPMMTIME lpTime, DWORD position, WAVEFORMATPCMEX* format)
{
TRACE("wType=%04X wBitsPerSample=%u nSamplesPerSec=%u nChannels=%u nAvgBytesPerSec=%u\n",
lpTime->wType, format->Format.wBitsPerSample, format->Format.nSamplesPerSec,
format->Format.nChannels, format->Format.nAvgBytesPerSec);
TRACE("Position in bytes=%u\n", position);
switch (lpTime->wType) {
case TIME_SAMPLES:
lpTime->u.sample = position / (format->Format.wBitsPerSample / 8 * format->Format.nChannels);
TRACE("TIME_SAMPLES=%u\n", lpTime->u.sample);
break;
case TIME_MS:
lpTime->u.ms = 1000.0 * position / (format->Format.wBitsPerSample / 8 * format->Format.nChannels * format->Format.nSamplesPerSec);
TRACE("TIME_MS=%u\n", lpTime->u.ms);
break;
case TIME_SMPTE:
lpTime->u.smpte.fps = 30;
position = position / (format->Format.wBitsPerSample / 8 * format->Format.nChannels);
position += (format->Format.nSamplesPerSec / lpTime->u.smpte.fps) - 1; /* round up */
lpTime->u.smpte.sec = position / format->Format.nSamplesPerSec;
position -= lpTime->u.smpte.sec * format->Format.nSamplesPerSec;
lpTime->u.smpte.min = lpTime->u.smpte.sec / 60;
lpTime->u.smpte.sec -= 60 * lpTime->u.smpte.min;
lpTime->u.smpte.hour = lpTime->u.smpte.min / 60;
lpTime->u.smpte.min -= 60 * lpTime->u.smpte.hour;
lpTime->u.smpte.fps = 30;
lpTime->u.smpte.frame = position * lpTime->u.smpte.fps / format->Format.nSamplesPerSec;
TRACE("TIME_SMPTE=%02u:%02u:%02u:%02u\n",
lpTime->u.smpte.hour, lpTime->u.smpte.min,
lpTime->u.smpte.sec, lpTime->u.smpte.frame);
break;
default:
WARN("Format %d not supported, using TIME_BYTES !\n", lpTime->wType);
lpTime->wType = TIME_BYTES;
/* fall through */
case TIME_BYTES:
lpTime->u.cb = position;
TRACE("TIME_BYTES=%u\n", lpTime->u.cb);
break;
}
return MMSYSERR_NOERROR;
}
void ALSA_copyFormat(LPWAVEFORMATEX wf1, LPWAVEFORMATPCMEX wf2)
{
unsigned int iLength;
ZeroMemory(wf2, sizeof(*wf2));
if (wf1->wFormatTag == WAVE_FORMAT_PCM)
iLength = sizeof(PCMWAVEFORMAT);
else if (wf1->wFormatTag == WAVE_FORMAT_EXTENSIBLE)
iLength = sizeof(WAVEFORMATPCMEX);
else
iLength = sizeof(WAVEFORMATEX) + wf1->cbSize;
memcpy(wf2, wf1, iLength);
}
BOOL ALSA_supportedFormat(LPWAVEFORMATEX wf)
{
TRACE("(%p)\n",wf);
if (wf->nSamplesPerSec<DSBFREQUENCY_MIN||wf->nSamplesPerSec>DSBFREQUENCY_MAX)
return FALSE;
if (wf->wFormatTag == WAVE_FORMAT_PCM) {
if (wf->nChannels==1||wf->nChannels==2) {
if (wf->wBitsPerSample==8||wf->wBitsPerSample==16)
return TRUE;
}
} else if (wf->wFormatTag == WAVE_FORMAT_EXTENSIBLE) {
WAVEFORMATEXTENSIBLE * wfex = (WAVEFORMATEXTENSIBLE *)wf;
if (wf->cbSize == 22 &&
(IsEqualGUID(&wfex->SubFormat, &KSDATAFORMAT_SUBTYPE_PCM) ||
IsEqualGUID(&wfex->SubFormat, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT))) {
if (wf->nChannels>=1 && wf->nChannels<=6) {
if (wf->wBitsPerSample==wfex->Samples.wValidBitsPerSample) {
if (wf->wBitsPerSample==8||wf->wBitsPerSample==16||
wf->wBitsPerSample==24||wf->wBitsPerSample==32) {
return TRUE;
}
} else
WARN("wBitsPerSample != wValidBitsPerSample not supported yet\n");
}
} else
WARN("only KSDATAFORMAT_SUBTYPE_PCM and KSDATAFORMAT_SUBTYPE_IEEE_FLOAT "
"supported\n");
} else
WARN("only WAVE_FORMAT_PCM and WAVE_FORMAT_EXTENSIBLE supported\n");
return FALSE;
}
/*======================================================================*
* Low level WAVE implementation *
*======================================================================*/
/**************************************************************************
* ALSA_CheckSetVolume [internal]
*
* Helper function for Alsa volume queries. This tries to simplify
* the process of managing the volume. All parameters are optional
* (pass NULL to ignore or not use).
* Return values are MMSYSERR_NOERROR on success, or !0 on failure;
* error codes are normalized into the possible documented return
* values from waveOutGetVolume.
*/
int ALSA_CheckSetVolume(snd_hctl_t *hctl, int *out_left, int *out_right,
int *out_min, int *out_max, int *out_step,
int *new_left, int *new_right)
{
int rc = MMSYSERR_NOERROR;
int value_count = 0;
snd_hctl_elem_t * elem = NULL;
snd_ctl_elem_info_t * eleminfop = NULL;
snd_ctl_elem_value_t * elemvaluep = NULL;
snd_ctl_elem_id_t * elemidp = NULL;
const char *names[] = {"PCM Playback Volume", "Line Playback Volume", NULL};
const char **name;
#define EXIT_ON_ERROR(f,txt,exitcode) do \
{ \
int err; \
if ( (err = (f) ) < 0) \
{ \
ERR(txt " failed: %s\n", snd_strerror(err)); \
rc = exitcode; \
goto out; \
} \
} while(0)
if (! hctl)
return MMSYSERR_NOTSUPPORTED;
/* Allocate areas to return information about the volume */
EXIT_ON_ERROR(snd_ctl_elem_id_malloc(&elemidp), "snd_ctl_elem_id_malloc", MMSYSERR_NOMEM);
EXIT_ON_ERROR(snd_ctl_elem_value_malloc (&elemvaluep), "snd_ctl_elem_value_malloc", MMSYSERR_NOMEM);
EXIT_ON_ERROR(snd_ctl_elem_info_malloc (&eleminfop), "snd_ctl_elem_info_malloc", MMSYSERR_NOMEM);
snd_ctl_elem_id_clear(elemidp);
snd_ctl_elem_value_clear(elemvaluep);
snd_ctl_elem_info_clear(eleminfop);
/* Setup and find an element id that exactly matches the characteristic we want
** FIXME: It is probably short sighted to hard code and fixate on PCM Playback Volume */
for( name = names; *name; name++ )
{
snd_ctl_elem_id_set_name(elemidp, *name);
snd_ctl_elem_id_set_interface(elemidp, SND_CTL_ELEM_IFACE_MIXER);
elem = snd_hctl_find_elem(hctl, elemidp);
if (elem)
{
/* Read and return volume information */
EXIT_ON_ERROR(snd_hctl_elem_info(elem, eleminfop), "snd_hctl_elem_info", MMSYSERR_NOTSUPPORTED);
value_count = snd_ctl_elem_info_get_count(eleminfop);
if (out_min || out_max || out_step)
{
if (!snd_ctl_elem_info_is_readable(eleminfop))
{
ERR("snd_ctl_elem_info_is_readable returned false; cannot return info\n");
rc = MMSYSERR_NOTSUPPORTED;
goto out;
}
if (out_min)
*out_min = snd_ctl_elem_info_get_min(eleminfop);
if (out_max)
*out_max = snd_ctl_elem_info_get_max(eleminfop);
if (out_step)
*out_step = snd_ctl_elem_info_get_step(eleminfop);
}
if (out_left || out_right)
{
EXIT_ON_ERROR(snd_hctl_elem_read(elem, elemvaluep), "snd_hctl_elem_read", MMSYSERR_NOTSUPPORTED);
if (out_left)
*out_left = snd_ctl_elem_value_get_integer(elemvaluep, 0);
if (out_right)
{
if (value_count == 1)
*out_right = snd_ctl_elem_value_get_integer(elemvaluep, 0);
else if (value_count == 2)
*out_right = snd_ctl_elem_value_get_integer(elemvaluep, 1);
else
{
ERR("Unexpected value count %d from snd_ctl_elem_info_get_count while getting volume info\n", value_count);
rc = -1;
goto out;
}
}
}
/* Set the volume */
if (new_left || new_right)
{
EXIT_ON_ERROR(snd_hctl_elem_read(elem, elemvaluep), "snd_hctl_elem_read", MMSYSERR_NOTSUPPORTED);
if (new_left)
snd_ctl_elem_value_set_integer(elemvaluep, 0, *new_left);
if (new_right)
{
if (value_count == 1)
snd_ctl_elem_value_set_integer(elemvaluep, 0, *new_right);
else if (value_count == 2)
snd_ctl_elem_value_set_integer(elemvaluep, 1, *new_right);
else
{
ERR("Unexpected value count %d from snd_ctl_elem_info_get_count while setting volume info\n", value_count);
rc = -1;
goto out;
}
}
EXIT_ON_ERROR(snd_hctl_elem_write(elem, elemvaluep), "snd_hctl_elem_write", MMSYSERR_NOTSUPPORTED);
}
break;
}
}
if( !*name )
{
ERR("Could not find '{PCM,Line} Playback Volume' element\n");
rc = MMSYSERR_NOTSUPPORTED;
}
#undef EXIT_ON_ERROR
out:
if (elemvaluep)
snd_ctl_elem_value_free(elemvaluep);
if (eleminfop)
snd_ctl_elem_info_free(eleminfop);
if (elemidp)
snd_ctl_elem_id_free(elemidp);
return rc;
}
/**************************************************************************
* wine_snd_pcm_recover [internal]
*
* Code slightly modified from alsa-lib v1.0.23 snd_pcm_recover implementation.
* used to recover from XRUN errors (buffer underflow/overflow)
*/
int wine_snd_pcm_recover(snd_pcm_t *pcm, int err, int silent)
{
if (err > 0)
err = -err;
if (err == -EINTR) /* nothing to do, continue */
return 0;
if (err == -EPIPE) {
const char *s;
if (snd_pcm_stream(pcm) == SND_PCM_STREAM_PLAYBACK)
s = "underrun";
else
s = "overrun";
if (!silent)
ERR("%s occurred\n", s);
err = snd_pcm_prepare(pcm);
if (err < 0) {
ERR("cannot recover from %s, prepare failed: %s\n", s, snd_strerror(err));
return err;
}
return 0;
}
if (err == -ESTRPIPE) {
while ((err = snd_pcm_resume(pcm)) == -EAGAIN)
/* wait until suspend flag is released */
poll(NULL, 0, 1000);
if (err < 0) {
err = snd_pcm_prepare(pcm);
if (err < 0) {
ERR("cannot recover from suspend, prepare failed: %s\n", snd_strerror(err));
return err;
}
}
return 0;
}
return err;
}
/**************************************************************************
* ALSA_TraceParameters [internal]
*
* used to trace format changes, hw and sw parameters
*/
void ALSA_TraceParameters(snd_pcm_hw_params_t * hw_params, snd_pcm_sw_params_t * sw, int full)
{
int err;
snd_pcm_format_t format;
snd_pcm_access_t access;
#define X(x) ((x)? "true" : "false")
if (full)
TRACE("FLAGS: sampleres=%s overrng=%s pause=%s resume=%s syncstart=%s batch=%s block=%s double=%s "
"halfd=%s joint=%s\n",
X(snd_pcm_hw_params_can_mmap_sample_resolution(hw_params)),
X(snd_pcm_hw_params_can_overrange(hw_params)),
X(snd_pcm_hw_params_can_pause(hw_params)),
X(snd_pcm_hw_params_can_resume(hw_params)),
X(snd_pcm_hw_params_can_sync_start(hw_params)),
X(snd_pcm_hw_params_is_batch(hw_params)),
X(snd_pcm_hw_params_is_block_transfer(hw_params)),
X(snd_pcm_hw_params_is_double(hw_params)),
X(snd_pcm_hw_params_is_half_duplex(hw_params)),
X(snd_pcm_hw_params_is_joint_duplex(hw_params)));
#undef X
err = snd_pcm_hw_params_get_access(hw_params, &access);
if (err >= 0)
{
TRACE("access=%s\n", snd_pcm_access_name(access));
}
else
{
snd_pcm_access_mask_t * acmask;
acmask = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, snd_pcm_access_mask_sizeof());
snd_pcm_hw_params_get_access_mask(hw_params, acmask);
for ( access = SND_PCM_ACCESS_MMAP_INTERLEAVED; access <= SND_PCM_ACCESS_LAST; access++)
if (snd_pcm_access_mask_test(acmask, access))
TRACE("access=%s\n", snd_pcm_access_name(access));
HeapFree( GetProcessHeap(), 0, acmask );
}
err = snd_pcm_hw_params_get_format(hw_params, &format);
if (err >= 0)
{
TRACE("format=%s\n", snd_pcm_format_name(format));
}
else
{
snd_pcm_format_mask_t * fmask;
fmask = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, snd_pcm_format_mask_sizeof());
snd_pcm_hw_params_get_format_mask(hw_params, fmask);
for ( format = SND_PCM_FORMAT_S8; format <= SND_PCM_FORMAT_LAST ; format++)
if ( snd_pcm_format_mask_test(fmask, format) )
TRACE("format=%s\n", snd_pcm_format_name(format));
HeapFree( GetProcessHeap(), 0, fmask );
}
do {
int err=0;
unsigned int val=0;
err = snd_pcm_hw_params_get_channels(hw_params, &val);
if (err<0) {
unsigned int min = 0;
unsigned int max = 0;
err = snd_pcm_hw_params_get_channels_min(hw_params, &min),
err = snd_pcm_hw_params_get_channels_max(hw_params, &max);
TRACE("channels_min=%u, channels_min_max=%u\n", min, max);
} else {
TRACE("channels=%d\n", val);
}
} while(0);
do {
int err=0;
snd_pcm_uframes_t val=0;
err = snd_pcm_hw_params_get_buffer_size(hw_params, &val);
if (err<0) {
snd_pcm_uframes_t min = 0;
snd_pcm_uframes_t max = 0;
err = snd_pcm_hw_params_get_buffer_size_min(hw_params, &min),
err = snd_pcm_hw_params_get_buffer_size_max(hw_params, &max);
TRACE("buffer_size_min=%lu, buffer_size_min_max=%lu\n", min, max);
} else {
TRACE("buffer_size=%lu\n", val);
}
} while(0);
#define X(x) do { \
int err=0; \
int dir=0; \
unsigned int val=0; \
err = snd_pcm_hw_params_get_##x(hw_params,&val, &dir); \
if (err<0) { \
unsigned int min = 0; \
unsigned int max = 0; \
err = snd_pcm_hw_params_get_##x##_min(hw_params, &min, &dir); \
err = snd_pcm_hw_params_get_##x##_max(hw_params, &max, &dir); \
TRACE(#x "_min=%u " #x "_max=%u\n", min, max); \
} else \
TRACE(#x "=%d\n", val); \
} while(0)
X(rate);
X(buffer_time);
X(periods);
do {
int err=0;
int dir=0;
snd_pcm_uframes_t val=0;
err = snd_pcm_hw_params_get_period_size(hw_params, &val, &dir);
if (err<0) {
snd_pcm_uframes_t min = 0;
snd_pcm_uframes_t max = 0;
err = snd_pcm_hw_params_get_period_size_min(hw_params, &min, &dir),
err = snd_pcm_hw_params_get_period_size_max(hw_params, &max, &dir);
TRACE("period_size_min=%lu, period_size_min_max=%lu\n", min, max);
} else {
TRACE("period_size=%lu\n", val);
}
} while(0);
X(period_time);
#undef X
if (!sw)
return;
}
/**************************************************************************
* DriverProc (WINEALSA.@)
*/
LRESULT CALLBACK ALSA_DriverProc(DWORD_PTR dwDevID, HDRVR hDriv, UINT wMsg,
LPARAM dwParam1, LPARAM dwParam2)
{
/* EPP TRACE("(%08lX, %04X, %08lX, %08lX, %08lX)\n", */
/* EPP dwDevID, hDriv, wMsg, dwParam1, dwParam2); */
switch(wMsg) {
case DRV_LOAD:
case DRV_FREE:
case DRV_OPEN:
case DRV_CLOSE:
case DRV_ENABLE:
case DRV_DISABLE:
case DRV_QUERYCONFIGURE:
return 1;
case DRV_CONFIGURE: MessageBoxA(0, "ALSA MultiMedia Driver !", "ALSA Driver", MB_OK); return 1;
case DRV_INSTALL:
case DRV_REMOVE:
return DRV_SUCCESS;
default:
return 0;
}
}

View file

@ -1,197 +0,0 @@
/* Definition for ALSA drivers : wine multimedia system
*
* Copyright (C) 2002 Erich Pouech
* Copyright (C) 2002 Marco Pietrobono
* Copyright (C) 2003 Christian Costa
* Copyright (C) 2007 Maarten Lankhorst
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef __WINE_CONFIG_H
# error You must include config.h to use this header
#endif
#ifndef __ALSA_H
#define __ALSA_H
#ifdef interface
#undef interface
#endif
#define ALSA_PCM_NEW_HW_PARAMS_API
#define ALSA_PCM_NEW_SW_PARAMS_API
#ifdef HAVE_ALSA_ASOUNDLIB_H
#include <alsa/asoundlib.h>
#elif defined(HAVE_SYS_ASOUNDLIB_H)
#include <sys/asoundlib.h>
#endif
#ifdef HAVE_SYS_ERRNO_H
#include <sys/errno.h>
#endif
/* state diagram for waveOut writing:
*
* +---------+-------------+---------------+---------------------------------+
* | state | function | event | new state |
* +---------+-------------+---------------+---------------------------------+
* | | open() | | STOPPED |
* | PAUSED | write() | | PAUSED |
* | STOPPED | write() | <thrd create> | PLAYING |
* | PLAYING | write() | HEADER | PLAYING |
* | (other) | write() | <error> | |
* | (any) | pause() | PAUSING | PAUSED |
* | PAUSED | restart() | RESTARTING | PLAYING (if no thrd => STOPPED) |
* | (any) | reset() | RESETTING | STOPPED |
* | (any) | close() | CLOSING | CLOSED |
* +---------+-------------+---------------+---------------------------------+
*/
/* states of the playing device */
#define WINE_WS_PLAYING 0
#define WINE_WS_PAUSED 1
#define WINE_WS_STOPPED 2
#define WINE_WS_CLOSED 3
/* events to be send to device */
enum win_wm_message {
WINE_WM_PAUSING = WM_USER + 1, WINE_WM_RESTARTING, WINE_WM_RESETTING, WINE_WM_HEADER,
WINE_WM_UPDATE, WINE_WM_BREAKLOOP, WINE_WM_CLOSING, WINE_WM_STARTING, WINE_WM_STOPPING
};
typedef struct {
enum win_wm_message msg; /* message identifier */
DWORD_PTR param; /* parameter for this message */
HANDLE hEvent; /* if message is synchronous, handle of event for synchro */
} ALSA_MSG;
/* implement an in-process message ring for better performance
* (compared to passing thru the server)
* this ring will be used by the input (resp output) record (resp playback) routine
*/
typedef struct {
ALSA_MSG * messages;
int ring_buffer_size;
int msg_tosave;
int msg_toget;
/* Either pipe or event is used, but that is defined in alsa.c,
* since this is a global header we define both here */
int msg_pipe[2];
HANDLE msg_event;
CRITICAL_SECTION msg_crst;
} ALSA_MSG_RING;
typedef struct {
volatile int state; /* one of the WINE_WS_ manifest constants */
WAVEOPENDESC waveDesc;
WORD wFlags;
WAVEFORMATPCMEX format;
char* pcmname; /* string name of alsa PCM device */
char* ctlname; /* string name of alsa control device */
char interface_name[MAXPNAMELEN * 2];
snd_pcm_t* pcm; /* handle to ALSA playback device */
snd_pcm_hw_params_t * hw_params;
DWORD dwBufferSize; /* size of whole ALSA buffer in bytes */
LPWAVEHDR lpQueuePtr; /* start of queued WAVEHDRs (waiting to be notified) */
LPWAVEHDR lpPlayPtr; /* start of not yet fully played buffers */
LPWAVEHDR lpLoopPtr; /* pointer of first buffer in loop, if any */
DWORD dwLoops; /* private copy of loop counter */
DWORD dwPlayedTotal; /* number of bytes actually played since opening */
DWORD dwWrittenTotal; /* number of bytes written to ALSA buffer since opening */
/* synchronization stuff */
HANDLE hStartUpEvent;
HANDLE hThread;
DWORD dwThreadID;
ALSA_MSG_RING msgRing;
/* DirectSound stuff */
DSDRIVERDESC ds_desc;
DSDRIVERCAPS ds_caps;
/* Waveout only fields */
WAVEOUTCAPSW outcaps;
snd_hctl_t * hctl; /* control handle for the playback volume */
snd_pcm_sframes_t (*write)(snd_pcm_t *, const void *, snd_pcm_uframes_t );
DWORD dwPartialOffset; /* Offset of not yet written bytes in lpPlayPtr */
/* Wavein only fields */
WAVEINCAPSW incaps;
DWORD dwSupport;
snd_pcm_sframes_t (*read)(snd_pcm_t *, void *, snd_pcm_uframes_t );
DWORD dwPeriodSize; /* size of OSS buffer period */
DWORD dwTotalRecorded;
} WINE_WAVEDEV;
/*----------------------------------------------------------------------------
** Global array of output and input devices, initialized via ALSA_WaveInit
*/
#define WAVEDEV_ALLOC_EXTENT_SIZE 10
/* wavein.c */
extern WINE_WAVEDEV *WInDev DECLSPEC_HIDDEN;
extern DWORD ALSA_WidNumMallocedDevs DECLSPEC_HIDDEN;
extern DWORD ALSA_WidNumDevs DECLSPEC_HIDDEN;
/* waveout.c */
extern WINE_WAVEDEV *WOutDev DECLSPEC_HIDDEN;
extern DWORD ALSA_WodNumMallocedDevs DECLSPEC_HIDDEN;
extern DWORD ALSA_WodNumDevs DECLSPEC_HIDDEN;
/* alsa.c */
int ALSA_InitRingMessage(ALSA_MSG_RING* omr) DECLSPEC_HIDDEN;
int ALSA_DestroyRingMessage(ALSA_MSG_RING* omr) DECLSPEC_HIDDEN;
void ALSA_ResetRingMessage(ALSA_MSG_RING* omr) DECLSPEC_HIDDEN;
void ALSA_WaitRingMessage(ALSA_MSG_RING* omr, DWORD sleep) DECLSPEC_HIDDEN;
int ALSA_AddRingMessage(ALSA_MSG_RING* omr, enum win_wm_message msg, DWORD_PTR param, BOOL wait) DECLSPEC_HIDDEN;
int ALSA_RetrieveRingMessage(ALSA_MSG_RING* omr, enum win_wm_message *msg, DWORD_PTR *param, HANDLE *hEvent) DECLSPEC_HIDDEN;
int ALSA_CheckSetVolume(snd_hctl_t *hctl, int *out_left, int *out_right, int *out_min, int *out_max, int *out_step, int *new_left, int *new_right) DECLSPEC_HIDDEN;
const char * ALSA_getCmdString(enum win_wm_message msg) DECLSPEC_HIDDEN;
const char * ALSA_getMessage(UINT msg) DECLSPEC_HIDDEN;
const char * ALSA_getFormat(WORD wFormatTag) DECLSPEC_HIDDEN;
BOOL ALSA_NearMatch(int rate1, int rate2) DECLSPEC_HIDDEN;
DWORD ALSA_bytes_to_mmtime(LPMMTIME lpTime, DWORD position, WAVEFORMATPCMEX* format) DECLSPEC_HIDDEN;
void ALSA_TraceParameters(snd_pcm_hw_params_t * hw_params, snd_pcm_sw_params_t * sw, int full) DECLSPEC_HIDDEN;
int wine_snd_pcm_recover(snd_pcm_t *pcm, int err, int silent) DECLSPEC_HIDDEN;
void ALSA_copyFormat(LPWAVEFORMATEX wf1, LPWAVEFORMATPCMEX wf2) DECLSPEC_HIDDEN;
BOOL ALSA_supportedFormat(LPWAVEFORMATEX wf) DECLSPEC_HIDDEN;
/* dscapture.c */
DWORD widDsCreate(UINT wDevID, PIDSCDRIVER* drv) DECLSPEC_HIDDEN;
DWORD widDsDesc(UINT wDevID, PDSDRIVERDESC desc) DECLSPEC_HIDDEN;
/* dsoutput.c */
DWORD wodDsCreate(UINT wDevID, PIDSDRIVER* drv) DECLSPEC_HIDDEN;
DWORD wodDsDesc(UINT wDevID, PDSDRIVERDESC desc) DECLSPEC_HIDDEN;
/* waveinit.c */
extern void ALSA_WaveInit(void) DECLSPEC_HIDDEN;
#endif /* __ALSA_H */

File diff suppressed because it is too large Load diff

View file

@ -1,962 +0,0 @@
/*
* Sample Wine Driver for Advanced Linux Sound System (ALSA)
* Based on version <final> of the ALSA API
*
* Copyright 2002 Eric Pouech
* 2002 Marco Pietrobono
* 2003 Christian Costa : WaveIn support
* 2006-2007 Maarten Lankhorst
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
/*======================================================================*
* Low level dsound output implementation *
*======================================================================*/
#include "config.h"
#include "wine/port.h"
#include <stdlib.h>
#include <assert.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include <errno.h>
#include <limits.h>
#include <fcntl.h>
#ifdef HAVE_SYS_IOCTL_H
# include <sys/ioctl.h>
#endif
#ifdef HAVE_SYS_MMAN_H
# include <sys/mman.h>
#endif
#include "windef.h"
#include "winbase.h"
#include "wingdi.h"
#include "winerror.h"
#include "winuser.h"
#include "mmddk.h"
#include "mmreg.h"
#include "dsound.h"
#include "dsdriver.h"
#include "alsa.h"
#include "wine/library.h"
#include "wine/unicode.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(dsalsa);
typedef struct IDsDriverImpl IDsDriverImpl;
typedef struct IDsDriverBufferImpl IDsDriverBufferImpl;
struct IDsDriverImpl
{
/* IUnknown fields */
IDsDriver IDsDriver_iface;
LONG ref;
/* IDsDriverImpl fields */
IDsDriverBufferImpl* primary;
UINT wDevID;
};
struct IDsDriverBufferImpl
{
IDsDriverBuffer IDsDriverBuffer_iface;
LONG ref;
IDsDriverImpl* drv;
CRITICAL_SECTION pcm_crst;
BYTE *mmap_buffer;
DWORD mmap_buflen_bytes;
BOOL mmap;
snd_pcm_t *pcm;
snd_pcm_hw_params_t *hw_params;
snd_pcm_sw_params_t *sw_params;
snd_pcm_uframes_t mmap_buflen_frames, mmap_pos, mmap_commitahead;
};
static inline IDsDriverImpl *impl_from_IDsDriver(IDsDriver *iface)
{
return CONTAINING_RECORD(iface, IDsDriverImpl, IDsDriver_iface);
}
static inline IDsDriverBufferImpl *impl_from_IDsDriverBuffer(IDsDriverBuffer *iface)
{
return CONTAINING_RECORD(iface, IDsDriverBufferImpl, IDsDriverBuffer_iface);
}
/** Fill buffers, for starting and stopping
* Alsa won't start playing until everything is filled up
* This also updates mmap_pos
*
* Returns: Amount of periods in use so snd_pcm_avail_update
* doesn't have to be called up to 4x in GetPosition()
*/
static snd_pcm_uframes_t CommitAll(IDsDriverBufferImpl *This)
{
const snd_pcm_channel_area_t *areas;
snd_pcm_sframes_t used;
const snd_pcm_uframes_t commitahead = This->mmap_commitahead;
used = This->mmap_buflen_frames - snd_pcm_avail_update(This->pcm);
if (used < 0) used = 0;
TRACE("%p needs to commit to %lu, used: %ld\n", This, commitahead, used);
if (used < commitahead)
{
snd_pcm_sframes_t done;
snd_pcm_uframes_t putin = commitahead - used;
if (This->mmap)
{
snd_pcm_mmap_begin(This->pcm, &areas, &This->mmap_pos, &putin);
done = snd_pcm_mmap_commit(This->pcm, This->mmap_pos, putin);
}
else
{
if (putin + This->mmap_pos > This->mmap_buflen_frames)
putin = This->mmap_buflen_frames - This->mmap_pos;
done = snd_pcm_writei(This->pcm, This->mmap_buffer + snd_pcm_frames_to_bytes(This->pcm, This->mmap_pos), putin);
if (done < putin) WARN("Short write %ld/%ld\n", putin, done);
}
if (done < 0) done = 0;
This->mmap_pos += done;
used += done;
putin = commitahead - used;
if (This->mmap_pos == This->mmap_buflen_frames && (snd_pcm_sframes_t)putin > 0)
{
if (This->mmap)
{
snd_pcm_mmap_begin(This->pcm, &areas, &This->mmap_pos, &putin);
done = snd_pcm_mmap_commit(This->pcm, This->mmap_pos, putin);
This->mmap_pos += done;
}
else
{
done = snd_pcm_writei(This->pcm, This->mmap_buffer, putin);
if (done < putin) WARN("Short write %ld/%ld\n", putin, done);
if (done < 0) done = 0;
This->mmap_pos = done;
}
used += done;
}
}
if (This->mmap_pos == This->mmap_buflen_frames)
This->mmap_pos = 0;
return used;
}
static void CheckXRUN(IDsDriverBufferImpl* This)
{
snd_pcm_state_t state = snd_pcm_state(This->pcm);
int err;
if ( state == SND_PCM_STATE_XRUN )
{
err = snd_pcm_prepare(This->pcm);
CommitAll(This);
snd_pcm_start(This->pcm);
WARN("xrun occurred\n");
if ( err < 0 )
ERR("recovery from xrun failed, prepare failed: %s\n", snd_strerror(err));
}
else if ( state == SND_PCM_STATE_SUSPENDED )
{
int err = snd_pcm_resume(This->pcm);
TRACE("recovery from suspension occurred\n");
if (err < 0 && err != -EAGAIN){
err = snd_pcm_prepare(This->pcm);
if (err < 0)
ERR("recovery from suspend failed, prepare failed: %s\n", snd_strerror(err));
}
} else if ( state != SND_PCM_STATE_RUNNING ) {
FIXME("Unhandled state: %d\n", state);
}
}
/**
* Allocate the memory-mapped buffer for direct sound, and set up the
* callback.
*/
static int DSDB_CreateMMAP(IDsDriverBufferImpl* pdbi)
{
snd_pcm_t *pcm = pdbi->pcm;
snd_pcm_format_t format;
snd_pcm_uframes_t frames, ofs, avail, psize, boundary;
unsigned int channels, bits_per_sample, bits_per_frame;
int err, mmap_mode;
const snd_pcm_channel_area_t *areas;
snd_pcm_hw_params_t *hw_params = pdbi->hw_params;
snd_pcm_sw_params_t *sw_params = pdbi->sw_params;
void *buf;
mmap_mode = snd_pcm_type(pcm);
if (mmap_mode == SND_PCM_TYPE_HW)
TRACE("mmap'd buffer is a direct hardware buffer.\n");
else if (mmap_mode == SND_PCM_TYPE_DMIX)
TRACE("mmap'd buffer is an ALSA dmix buffer\n");
else
TRACE("mmap'd buffer is an ALSA type %d buffer\n", mmap_mode);
err = snd_pcm_hw_params_get_period_size(hw_params, &psize, NULL);
err = snd_pcm_hw_params_get_format(hw_params, &format);
err = snd_pcm_hw_params_get_buffer_size(hw_params, &frames);
err = snd_pcm_hw_params_get_channels(hw_params, &channels);
bits_per_sample = snd_pcm_format_physical_width(format);
bits_per_frame = bits_per_sample * channels;
if (TRACE_ON(dsalsa))
ALSA_TraceParameters(hw_params, NULL, FALSE);
TRACE("format=%s frames=%ld channels=%d bits_per_sample=%d bits_per_frame=%d\n",
snd_pcm_format_name(format), frames, channels, bits_per_sample, bits_per_frame);
pdbi->mmap_buflen_frames = frames;
pdbi->mmap_buflen_bytes = snd_pcm_frames_to_bytes( pcm, frames );
snd_pcm_sw_params_current(pcm, sw_params);
snd_pcm_sw_params_set_start_threshold(pcm, sw_params, 0);
snd_pcm_sw_params_get_boundary(sw_params, &boundary);
snd_pcm_sw_params_set_stop_threshold(pcm, sw_params, boundary);
snd_pcm_sw_params_set_silence_threshold(pcm, sw_params, boundary);
snd_pcm_sw_params_set_silence_size(pcm, sw_params, 0);
snd_pcm_sw_params_set_avail_min(pcm, sw_params, 0);
err = snd_pcm_sw_params(pcm, sw_params);
avail = snd_pcm_avail_update(pcm);
if ((snd_pcm_sframes_t)avail < 0)
{
ERR("No buffer is available: %s.\n", snd_strerror(avail));
return DSERR_GENERIC;
}
if (!pdbi->mmap)
{
buf = pdbi->mmap_buffer = HeapAlloc(GetProcessHeap(), 0, pdbi->mmap_buflen_bytes);
if (!buf)
return DSERR_OUTOFMEMORY;
snd_pcm_format_set_silence(format, buf, pdbi->mmap_buflen_frames);
pdbi->mmap_pos = 0;
}
else
{
err = snd_pcm_mmap_begin(pcm, &areas, &ofs, &avail);
if ( err < 0 )
{
ERR("Can't map sound device for direct access: %s/%d\n", snd_strerror(err), err);
return DSERR_GENERIC;
}
snd_pcm_format_set_silence(format, areas->addr, pdbi->mmap_buflen_frames);
pdbi->mmap_pos = ofs + snd_pcm_mmap_commit(pcm, ofs, 0);
pdbi->mmap_buffer = areas->addr;
}
TRACE("created mmap buffer of %ld frames (%d bytes) at %p\n",
frames, pdbi->mmap_buflen_bytes, pdbi->mmap_buffer);
return DS_OK;
}
static HRESULT WINAPI IDsDriverBufferImpl_QueryInterface(PIDSDRIVERBUFFER iface, REFIID riid, LPVOID *ppobj)
{
/* IDsDriverBufferImpl *This = (IDsDriverBufferImpl *)iface; */
FIXME("(): stub!\n");
return DSERR_UNSUPPORTED;
}
static ULONG WINAPI IDsDriverBufferImpl_AddRef(PIDSDRIVERBUFFER iface)
{
IDsDriverBufferImpl *This = impl_from_IDsDriverBuffer(iface);
ULONG refCount = InterlockedIncrement(&This->ref);
TRACE("(%p)->(ref before=%u)\n",This, refCount - 1);
return refCount;
}
static ULONG WINAPI IDsDriverBufferImpl_Release(PIDSDRIVERBUFFER iface)
{
IDsDriverBufferImpl *This = impl_from_IDsDriverBuffer(iface);
ULONG refCount = InterlockedDecrement(&This->ref);
TRACE("(%p)->(ref before=%u)\n",This, refCount + 1);
if (refCount)
return refCount;
TRACE("mmap buffer %p destroyed\n", This->mmap_buffer);
if (This == This->drv->primary)
This->drv->primary = NULL;
This->pcm_crst.DebugInfo->Spare[0] = 0;
DeleteCriticalSection(&This->pcm_crst);
snd_pcm_drop(This->pcm);
snd_pcm_close(This->pcm);
This->pcm = NULL;
HeapFree(GetProcessHeap(), 0, This->sw_params);
HeapFree(GetProcessHeap(), 0, This->hw_params);
if (!This->mmap)
HeapFree(GetProcessHeap(), 0, This->mmap_buffer);
HeapFree(GetProcessHeap(), 0, This);
return 0;
}
static HRESULT WINAPI IDsDriverBufferImpl_Lock(PIDSDRIVERBUFFER iface,
LPVOID*ppvAudio1,LPDWORD pdwLen1,
LPVOID*ppvAudio2,LPDWORD pdwLen2,
DWORD dwWritePosition,DWORD dwWriteLen,
DWORD dwFlags)
{
IDsDriverBufferImpl *This = impl_from_IDsDriverBuffer(iface);
snd_pcm_uframes_t writepos;
TRACE("%d bytes from %d\n", dwWriteLen, dwWritePosition);
/* **** */
EnterCriticalSection(&This->pcm_crst);
if (dwFlags & DSBLOCK_ENTIREBUFFER)
dwWriteLen = This->mmap_buflen_bytes;
if (dwWriteLen > This->mmap_buflen_bytes || dwWritePosition >= This->mmap_buflen_bytes)
{
/* **** */
LeaveCriticalSection(&This->pcm_crst);
return DSERR_INVALIDPARAM;
}
if (ppvAudio2) *ppvAudio2 = NULL;
if (pdwLen2) *pdwLen2 = 0;
*ppvAudio1 = This->mmap_buffer + dwWritePosition;
*pdwLen1 = dwWriteLen;
if (dwWritePosition+dwWriteLen > This->mmap_buflen_bytes)
{
DWORD remainder = This->mmap_buflen_bytes - dwWritePosition;
*pdwLen1 = remainder;
if (ppvAudio2 && pdwLen2)
{
*ppvAudio2 = This->mmap_buffer;
*pdwLen2 = dwWriteLen - remainder;
}
else dwWriteLen = remainder;
}
writepos = snd_pcm_bytes_to_frames(This->pcm, dwWritePosition);
if (writepos == This->mmap_pos)
{
const snd_pcm_channel_area_t *areas;
snd_pcm_uframes_t writelen = snd_pcm_bytes_to_frames(This->pcm, dwWriteLen), putin = writelen;
TRACE("Hit mmap_pos, locking data!\n");
if (This->mmap)
snd_pcm_mmap_begin(This->pcm, &areas, &This->mmap_pos, &putin);
}
else
WARN("mmap_pos (%lu) != writepos (%lu) not locking data!\n", This->mmap_pos, writepos);
LeaveCriticalSection(&This->pcm_crst);
/* **** */
return DS_OK;
}
static HRESULT WINAPI IDsDriverBufferImpl_Unlock(PIDSDRIVERBUFFER iface,
LPVOID pvAudio1,DWORD dwLen1,
LPVOID pvAudio2,DWORD dwLen2)
{
IDsDriverBufferImpl *This = impl_from_IDsDriverBuffer(iface);
snd_pcm_uframes_t writepos;
if (!dwLen1)
return DS_OK;
/* **** */
EnterCriticalSection(&This->pcm_crst);
writepos = snd_pcm_bytes_to_frames(This->pcm, (DWORD_PTR)pvAudio1 - (DWORD_PTR)This->mmap_buffer);
if (writepos == This->mmap_pos)
{
const snd_pcm_channel_area_t *areas;
snd_pcm_uframes_t writelen = snd_pcm_bytes_to_frames(This->pcm, dwLen1);
TRACE("Committing data\n");
if (This->mmap)
This->mmap_pos += snd_pcm_mmap_commit(This->pcm, This->mmap_pos, writelen);
else
{
int ret;
ret = snd_pcm_writei(This->pcm, pvAudio1, writelen);
if (ret == -EPIPE)
{
WARN("Underrun occurred\n");
wine_snd_pcm_recover(This->pcm, -EPIPE, 1);
ret = snd_pcm_writei(This->pcm, pvAudio1, writelen);
/* Advance mmap pointer a little to make dsound notice the underrun and respond to it */
if (ret < writelen) WARN("Short write %ld/%d\n", writelen, ret);
This->mmap_pos += This->mmap_commitahead + ret;
This->mmap_pos %= This->mmap_buflen_frames;
}
else if (ret > 0)
This->mmap_pos += ret;
if (ret < 0)
WARN("Committing data: %d / %s (%p %ld)\n", ret, snd_strerror(ret), pvAudio1, writelen);
}
if (This->mmap_pos == This->mmap_buflen_frames)
This->mmap_pos = 0;
if (dwLen2)
{
writelen = snd_pcm_bytes_to_frames(This->pcm, dwLen2);
if (This->mmap)
{
snd_pcm_mmap_begin(This->pcm, &areas, &This->mmap_pos, &writelen);
This->mmap_pos += snd_pcm_mmap_commit(This->pcm, This->mmap_pos, writelen);
}
else
{
int ret;
ret = snd_pcm_writei(This->pcm, pvAudio2, writelen);
if (ret < writelen) WARN("Short write %ld/%d\n", writelen, ret);
This->mmap_pos = ret > 0 ? ret : 0;
}
assert(This->mmap_pos < This->mmap_buflen_frames);
}
}
LeaveCriticalSection(&This->pcm_crst);
/* **** */
return DS_OK;
}
static HRESULT SetFormat(IDsDriverBufferImpl *This, LPWAVEFORMATEX pwfx)
{
snd_pcm_t *pcm = NULL;
snd_pcm_hw_params_t *hw_params = This->hw_params;
unsigned int buffer_time = 500000;
snd_pcm_format_t format = -1;
snd_pcm_uframes_t psize;
DWORD rate = pwfx->nSamplesPerSec;
int err=0;
switch (pwfx->wBitsPerSample)
{
case 8: format = SND_PCM_FORMAT_U8; break;
case 16: format = SND_PCM_FORMAT_S16_LE; break;
case 24: format = SND_PCM_FORMAT_S24_3LE; break;
case 32: format = SND_PCM_FORMAT_S32_LE; break;
default: FIXME("Unsupported bpp: %d\n", pwfx->wBitsPerSample); return DSERR_GENERIC;
}
err = snd_pcm_open(&pcm, WOutDev[This->drv->wDevID].pcmname, SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
if (err < 0)
{
if (errno != EBUSY || !This->pcm)
{
WARN("Cannot open sound device: %s\n", snd_strerror(err));
return DSERR_GENERIC;
}
snd_pcm_drop(This->pcm);
snd_pcm_close(This->pcm);
This->pcm = NULL;
err = snd_pcm_open(&pcm, WOutDev[This->drv->wDevID].pcmname, SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
if (err < 0)
{
WARN("Cannot open sound device: %s\n", snd_strerror(err));
return DSERR_BUFFERLOST;
}
}
/* Set some defaults */
snd_pcm_hw_params_any(pcm, hw_params);
err = snd_pcm_hw_params_set_channels(pcm, hw_params, pwfx->nChannels);
if (err < 0) { WARN("Could not set channels to %d\n", pwfx->nChannels); goto err; }
err = snd_pcm_hw_params_set_format(pcm, hw_params, format);
if (err < 0) { WARN("Could not set format to %d bpp\n", pwfx->wBitsPerSample); goto err; }
/* Alsa's rate resampling is only used if the application specifically requests
* a buffer at a certain frequency, else it is better to disable it due to unwanted
* side effects, which may include: Less granular pointer, changing buffer sizes, etc
*/
#if SND_LIB_VERSION >= 0x010009
snd_pcm_hw_params_set_rate_resample(pcm, hw_params, 0);
#endif
err = snd_pcm_hw_params_set_rate_near(pcm, hw_params, &rate, NULL);
if (err < 0) { rate = pwfx->nSamplesPerSec; WARN("Could not set rate\n"); goto err; }
if (!ALSA_NearMatch(rate, pwfx->nSamplesPerSec))
{
WARN("Could not set sound rate to %d, but instead to %d\n", pwfx->nSamplesPerSec, rate);
pwfx->nSamplesPerSec = rate;
pwfx->nAvgBytesPerSec = rate * pwfx->nBlockAlign;
/* Let DirectSound detect this */
}
snd_pcm_hw_params_set_periods_integer(pcm, hw_params);
snd_pcm_hw_params_set_buffer_time_near(pcm, hw_params, &buffer_time, NULL);
buffer_time = 10000;
snd_pcm_hw_params_set_period_time_near(pcm, hw_params, &buffer_time, NULL);
err = snd_pcm_hw_params_get_period_size(hw_params, &psize, NULL);
buffer_time = 16;
snd_pcm_hw_params_set_periods_near(pcm, hw_params, &buffer_time, NULL);
if (!This->mmap)
{
HeapFree(GetProcessHeap(), 0, This->mmap_buffer);
This->mmap_buffer = NULL;
}
err = snd_pcm_hw_params_set_access (pcm, hw_params, SND_PCM_ACCESS_MMAP_INTERLEAVED);
if (err >= 0)
This->mmap = 1;
else
{
This->mmap = 0;
err = snd_pcm_hw_params_set_access (pcm, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED);
}
err = snd_pcm_hw_params(pcm, hw_params);
/* ALSA needs at least 3 buffers to work successfully */
This->mmap_commitahead = 3 * psize;
while (This->mmap_commitahead <= 512)
This->mmap_commitahead += psize;
if (This->pcm)
{
snd_pcm_drop(This->pcm);
snd_pcm_close(This->pcm);
}
This->pcm = pcm;
snd_pcm_prepare(This->pcm);
DSDB_CreateMMAP(This);
return S_OK;
err:
if (err < 0)
WARN("Failed to apply changes: %s\n", snd_strerror(err));
if (!This->pcm)
This->pcm = pcm;
else
snd_pcm_close(pcm);
if (This->pcm)
snd_pcm_hw_params_current(This->pcm, This->hw_params);
return DSERR_BADFORMAT;
}
static HRESULT WINAPI IDsDriverBufferImpl_SetFormat(PIDSDRIVERBUFFER iface, LPWAVEFORMATEX pwfx)
{
IDsDriverBufferImpl *This = impl_from_IDsDriverBuffer(iface);
HRESULT hr = S_OK;
TRACE("(%p, %p)\n", iface, pwfx);
/* **** */
EnterCriticalSection(&This->pcm_crst);
hr = SetFormat(This, pwfx);
/* **** */
LeaveCriticalSection(&This->pcm_crst);
if (hr == DS_OK)
return S_FALSE;
return hr;
}
static HRESULT WINAPI IDsDriverBufferImpl_SetFrequency(PIDSDRIVERBUFFER iface, DWORD dwFreq)
{
/* IDsDriverBufferImpl *This = (IDsDriverBufferImpl *)iface; */
FIXME("(%p,%d): stub\n",iface,dwFreq);
return S_OK;
}
static HRESULT WINAPI IDsDriverBufferImpl_SetVolumePan(PIDSDRIVERBUFFER iface, PDSVOLUMEPAN pVolPan)
{
IDsDriverBufferImpl *This = impl_from_IDsDriverBuffer(iface);
FIXME("(%p,%p): stub\n",This,pVolPan);
/* TODO: Bring volume control back */
return DS_OK;
}
static HRESULT WINAPI IDsDriverBufferImpl_SetPosition(PIDSDRIVERBUFFER iface, DWORD dwNewPos)
{
/* IDsDriverBufferImpl *This = (IDsDriverBufferImpl *)iface; */
/* I don't even think alsa allows this */
FIXME("(%p,%d): stub\n",iface,dwNewPos);
return DSERR_UNSUPPORTED;
}
static HRESULT WINAPI IDsDriverBufferImpl_GetPosition(PIDSDRIVERBUFFER iface,
LPDWORD lpdwPlay, LPDWORD lpdwWrite)
{
IDsDriverBufferImpl *This = impl_from_IDsDriverBuffer(iface);
snd_pcm_uframes_t hw_pptr, hw_wptr;
snd_pcm_state_t state;
/* **** */
EnterCriticalSection(&This->pcm_crst);
if (!This->pcm)
{
FIXME("Bad pointer for pcm: %p\n", This->pcm);
LeaveCriticalSection(&This->pcm_crst);
return DSERR_GENERIC;
}
if (!lpdwPlay && !lpdwWrite)
CommitAll(This);
state = snd_pcm_state(This->pcm);
if (state != SND_PCM_STATE_PREPARED && state != SND_PCM_STATE_RUNNING)
{
CheckXRUN(This);
state = snd_pcm_state(This->pcm);
}
if (state == SND_PCM_STATE_RUNNING)
{
snd_pcm_sframes_t used = This->mmap_buflen_frames - snd_pcm_avail_update(This->pcm);
if (used < 0)
{
WARN("Underrun: %ld / %ld\n", used, snd_pcm_avail_update(This->pcm));
if (This->mmap)
{
snd_pcm_forward(This->pcm, -used);
This->mmap_pos += -used;
This->mmap_pos %= This->mmap_buflen_frames;
}
used = 0;
}
if (This->mmap_pos > used)
hw_pptr = This->mmap_pos - used;
else
hw_pptr = This->mmap_buflen_frames + This->mmap_pos - used;
hw_pptr %= This->mmap_buflen_frames;
TRACE("At position: %ld (%ld) - Used %ld\n", hw_pptr, This->mmap_pos, used);
}
else hw_pptr = This->mmap_pos;
hw_wptr = This->mmap_pos;
LeaveCriticalSection(&This->pcm_crst);
/* **** */
if (lpdwPlay)
*lpdwPlay = snd_pcm_frames_to_bytes(This->pcm, hw_pptr);
if (lpdwWrite)
*lpdwWrite = snd_pcm_frames_to_bytes(This->pcm, hw_wptr);
TRACE("hw_pptr=0x%08x, hw_wptr=0x%08x playpos=%d, writepos=%d\n", (unsigned int)hw_pptr, (unsigned int)hw_wptr, lpdwPlay?*lpdwPlay:-1, lpdwWrite?*lpdwWrite:-1);
return DS_OK;
}
static HRESULT WINAPI IDsDriverBufferImpl_Play(PIDSDRIVERBUFFER iface, DWORD dwRes1, DWORD dwRes2, DWORD dwFlags)
{
IDsDriverBufferImpl *This = impl_from_IDsDriverBuffer(iface);
TRACE("(%p,%x,%x,%x)\n",iface,dwRes1,dwRes2,dwFlags);
/* **** */
EnterCriticalSection(&This->pcm_crst);
snd_pcm_start(This->pcm);
/* **** */
LeaveCriticalSection(&This->pcm_crst);
return DS_OK;
}
static HRESULT WINAPI IDsDriverBufferImpl_Stop(PIDSDRIVERBUFFER iface)
{
const snd_pcm_channel_area_t *areas;
snd_pcm_uframes_t avail;
snd_pcm_format_t format;
IDsDriverBufferImpl *This = impl_from_IDsDriverBuffer(iface);
TRACE("(%p)\n",iface);
/* **** */
EnterCriticalSection(&This->pcm_crst);
avail = This->mmap_buflen_frames;
snd_pcm_drop(This->pcm);
snd_pcm_prepare(This->pcm);
avail = snd_pcm_avail_update(This->pcm);
snd_pcm_hw_params_get_format(This->hw_params, &format);
if (This->mmap)
{
snd_pcm_mmap_begin(This->pcm, &areas, &This->mmap_pos, &avail);
snd_pcm_format_set_silence(format, areas->addr, This->mmap_buflen_frames);
snd_pcm_mmap_commit(This->pcm, This->mmap_pos, 0);
}
else
{
snd_pcm_format_set_silence(format, This->mmap_buffer, This->mmap_buflen_frames);
snd_pcm_writei(This->pcm, This->mmap_buffer, This->mmap_buflen_frames);
This->mmap_pos = 0;
}
/* **** */
LeaveCriticalSection(&This->pcm_crst);
return DS_OK;
}
static const IDsDriverBufferVtbl dsdbvt =
{
IDsDriverBufferImpl_QueryInterface,
IDsDriverBufferImpl_AddRef,
IDsDriverBufferImpl_Release,
IDsDriverBufferImpl_Lock,
IDsDriverBufferImpl_Unlock,
IDsDriverBufferImpl_SetFormat,
IDsDriverBufferImpl_SetFrequency,
IDsDriverBufferImpl_SetVolumePan,
IDsDriverBufferImpl_SetPosition,
IDsDriverBufferImpl_GetPosition,
IDsDriverBufferImpl_Play,
IDsDriverBufferImpl_Stop
};
static HRESULT WINAPI IDsDriverImpl_QueryInterface(PIDSDRIVER iface, REFIID riid, LPVOID *ppobj)
{
/* IDsDriverImpl *This = (IDsDriverImpl *)iface; */
FIXME("(%p): stub!\n",iface);
return DSERR_UNSUPPORTED;
}
static ULONG WINAPI IDsDriverImpl_AddRef(PIDSDRIVER iface)
{
IDsDriverImpl *This = impl_from_IDsDriver(iface);
ULONG refCount = InterlockedIncrement(&This->ref);
TRACE("(%p)->(ref before=%u)\n",This, refCount - 1);
return refCount;
}
static ULONG WINAPI IDsDriverImpl_Release(PIDSDRIVER iface)
{
IDsDriverImpl *This = impl_from_IDsDriver(iface);
ULONG refCount = InterlockedDecrement(&This->ref);
TRACE("(%p)->(ref before=%u)\n",This, refCount + 1);
if (refCount)
return refCount;
HeapFree(GetProcessHeap(), 0, This);
return 0;
}
static HRESULT WINAPI IDsDriverImpl_GetDriverDesc(PIDSDRIVER iface, PDSDRIVERDESC pDesc)
{
IDsDriverImpl *This = impl_from_IDsDriver(iface);
TRACE("(%p,%p)\n",iface,pDesc);
*pDesc = WOutDev[This->wDevID].ds_desc;
pDesc->dwFlags = DSDDESC_DONTNEEDSECONDARYLOCK | DSDDESC_DONTNEEDWRITELEAD;
pDesc->dnDevNode = WOutDev[This->wDevID].waveDesc.dnDevNode;
pDesc->wVxdId = 0;
pDesc->wReserved = 0;
pDesc->ulDeviceNum = This->wDevID;
pDesc->dwHeapType = DSDHEAP_NOHEAP;
pDesc->pvDirectDrawHeap = NULL;
pDesc->dwMemStartAddress = 0xDEAD0000;
pDesc->dwMemEndAddress = 0xDEAF0000;
pDesc->dwMemAllocExtra = 0;
pDesc->pvReserved1 = NULL;
pDesc->pvReserved2 = NULL;
return DS_OK;
}
static HRESULT WINAPI IDsDriverImpl_Open(PIDSDRIVER iface)
{
HRESULT hr = S_OK;
IDsDriverImpl *This = impl_from_IDsDriver(iface);
int err=0;
snd_pcm_t *pcm = NULL;
snd_pcm_hw_params_t *hw_params;
/* While this is not really needed, it is a good idea to do this,
* to see if sound can be initialized */
hw_params = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, snd_pcm_hw_params_sizeof());
if (!hw_params)
{
hr = DSERR_OUTOFMEMORY;
goto unalloc;
}
err = snd_pcm_open(&pcm, WOutDev[This->wDevID].pcmname, SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
if (err < 0) goto err;
err = snd_pcm_hw_params_any(pcm, hw_params);
if (err < 0) goto err;
err = snd_pcm_hw_params_set_access (pcm, hw_params, SND_PCM_ACCESS_MMAP_INTERLEAVED);
if (err < 0)
err = snd_pcm_hw_params_set_access (pcm, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED);
if (err < 0) goto err;
TRACE("Success\n");
snd_pcm_close(pcm);
goto unalloc;
err:
hr = DSERR_GENERIC;
FIXME("Failed to open device: %s\n", snd_strerror(err));
if (pcm)
snd_pcm_close(pcm);
unalloc:
HeapFree(GetProcessHeap(), 0, hw_params);
if (hr != S_OK)
WARN("--> %08x\n", hr);
return hr;
}
static HRESULT WINAPI IDsDriverImpl_Close(PIDSDRIVER iface)
{
IDsDriverImpl *This = impl_from_IDsDriver(iface);
TRACE("(%p) stub, harmless\n",This);
return DS_OK;
}
static HRESULT WINAPI IDsDriverImpl_GetCaps(PIDSDRIVER iface, PDSDRIVERCAPS pCaps)
{
IDsDriverImpl *This = impl_from_IDsDriver(iface);
TRACE("(%p,%p)\n",iface,pCaps);
*pCaps = WOutDev[This->wDevID].ds_caps;
return DS_OK;
}
static HRESULT WINAPI IDsDriverImpl_CreateSoundBuffer(PIDSDRIVER iface,
LPWAVEFORMATEX pwfx,
DWORD dwFlags, DWORD dwCardAddress,
LPDWORD pdwcbBufferSize,
LPBYTE *ppbBuffer,
LPVOID *ppvObj)
{
IDsDriverImpl *This = impl_from_IDsDriver(iface);
IDsDriverBufferImpl** ippdsdb = (IDsDriverBufferImpl**)ppvObj;
HRESULT err;
TRACE("(%p,%p,%x,%x)\n",iface,pwfx,dwFlags,dwCardAddress);
/* we only support primary buffers... for now */
if (!(dwFlags & DSBCAPS_PRIMARYBUFFER))
return DSERR_UNSUPPORTED;
if (This->primary)
return DSERR_ALLOCATED;
*ippdsdb = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDsDriverBufferImpl));
if (*ippdsdb == NULL)
return DSERR_OUTOFMEMORY;
(*ippdsdb)->hw_params = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, snd_pcm_hw_params_sizeof());
(*ippdsdb)->sw_params = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, snd_pcm_sw_params_sizeof());
if (!(*ippdsdb)->hw_params || !(*ippdsdb)->sw_params)
{
HeapFree(GetProcessHeap(), 0, (*ippdsdb)->sw_params);
HeapFree(GetProcessHeap(), 0, (*ippdsdb)->hw_params);
return DSERR_OUTOFMEMORY;
}
(*ippdsdb)->IDsDriverBuffer_iface.lpVtbl = &dsdbvt;
(*ippdsdb)->ref = 1;
(*ippdsdb)->drv = This;
InitializeCriticalSection(&(*ippdsdb)->pcm_crst);
(*ippdsdb)->pcm_crst.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": ALSA_DSOUTPUT.pcm_crst");
/* SetFormat has to re-initialize pcm here anyway */
err = SetFormat(*ippdsdb, pwfx);
if (FAILED(err))
{
WARN("Error occurred: %08x\n", err);
goto err;
}
if (dwFlags & DSBCAPS_PRIMARYBUFFER)
This->primary = *ippdsdb;
*pdwcbBufferSize = (*ippdsdb)->mmap_buflen_bytes;
*ppbBuffer = (*ippdsdb)->mmap_buffer;
/* buffer is ready to go */
TRACE("buffer created at %p\n", *ippdsdb);
return err;
err:
HeapFree(GetProcessHeap(), 0, (*ippdsdb)->sw_params);
HeapFree(GetProcessHeap(), 0, (*ippdsdb)->hw_params);
HeapFree(GetProcessHeap(), 0, *ippdsdb);
*ippdsdb = NULL;
return err;
}
static HRESULT WINAPI IDsDriverImpl_DuplicateSoundBuffer(PIDSDRIVER iface,
PIDSDRIVERBUFFER pBuffer,
LPVOID *ppvObj)
{
IDsDriverImpl *This = impl_from_IDsDriver(iface);
FIXME("(%p,%p): stub\n",This,pBuffer);
return DSERR_INVALIDCALL;
}
static const IDsDriverVtbl dsdvt =
{
IDsDriverImpl_QueryInterface,
IDsDriverImpl_AddRef,
IDsDriverImpl_Release,
IDsDriverImpl_GetDriverDesc,
IDsDriverImpl_Open,
IDsDriverImpl_Close,
IDsDriverImpl_GetCaps,
IDsDriverImpl_CreateSoundBuffer,
IDsDriverImpl_DuplicateSoundBuffer
};
DWORD wodDsCreate(UINT wDevID, PIDSDRIVER* drv)
{
IDsDriverImpl** idrv = (IDsDriverImpl**)drv;
TRACE("driver created\n");
*idrv = HeapAlloc(GetProcessHeap(),0,sizeof(IDsDriverImpl));
if (!*idrv)
return MMSYSERR_NOMEM;
(*idrv)->IDsDriver_iface.lpVtbl = &dsdvt;
(*idrv)->ref = 1;
(*idrv)->wDevID = wDevID;
(*idrv)->primary = NULL;
return MMSYSERR_NOERROR;
}
DWORD wodDsDesc(UINT wDevID, PDSDRIVERDESC desc)
{
*desc = WOutDev[wDevID].ds_desc;
return MMSYSERR_NOERROR;
}

View file

@ -51,9 +51,10 @@
#include "mmreg.h"
#include "dsound.h"
#include "dsdriver.h"
#include "alsa.h"
#include "wine/debug.h"
#include <alsa/asoundlib.h>
WINE_DEFAULT_DEBUG_CHANNEL(midi);
#ifndef SND_SEQ_PORT_TYPE_PORT
@ -1390,4 +1391,29 @@ DWORD WINAPI ALSA_modMessage(UINT wDevID, UINT wMsg, DWORD_PTR dwUser,
return MMSYSERR_NOTSUPPORTED;
}
/*-----------------------------------------------------------------------*/
/**************************************************************************
* DriverProc (WINEALSA.@)
*/
LRESULT CALLBACK ALSA_DriverProc(DWORD_PTR dwDevID, HDRVR hDriv, UINT wMsg,
LPARAM dwParam1, LPARAM dwParam2)
{
/* EPP TRACE("(%08lX, %04X, %08lX, %08lX, %08lX)\n", */
/* EPP dwDevID, hDriv, wMsg, dwParam1, dwParam2); */
switch(wMsg) {
case DRV_LOAD:
case DRV_FREE:
case DRV_OPEN:
case DRV_CLOSE:
case DRV_ENABLE:
case DRV_DISABLE:
case DRV_QUERYCONFIGURE:
case DRV_CONFIGURE:
return 1;
case DRV_INSTALL:
case DRV_REMOVE:
return DRV_SUCCESS;
default:
return 0;
}
}

File diff suppressed because it is too large Load diff

View file

@ -37,9 +37,9 @@
#include "devpkey.h"
#include "dshow.h"
#include "dsound.h"
#include "endpointvolume.h"
#include "initguid.h"
#include "endpointvolume.h"
#include "audioclient.h"
#include "audiopolicy.h"
#include "dsdriver.h"
@ -158,7 +158,6 @@ static const IAudioStreamVolumeVtbl AudioStreamVolume_Vtbl;
static const IChannelAudioVolumeVtbl ChannelAudioVolume_Vtbl;
static const IAudioSessionManager2Vtbl AudioSessionManager2_Vtbl;
int wine_snd_pcm_recover(snd_pcm_t *pcm, int err, int silent);
static AudioSessionWrapper *AudioSessionWrapper_Create(ACImpl *client);
static inline ACImpl *impl_from_IAudioClient(IAudioClient *iface)
@ -237,6 +236,49 @@ int WINAPI AUDDRV_GetPriority(void)
return Priority_Neutral;
}
/**************************************************************************
* wine_snd_pcm_recover [internal]
*
* Code slightly modified from alsa-lib v1.0.23 snd_pcm_recover implementation.
* used to recover from XRUN errors (buffer underflow/overflow)
*/
static int wine_snd_pcm_recover(snd_pcm_t *pcm, int err, int silent)
{
if (err > 0)
err = -err;
if (err == -EINTR) /* nothing to do, continue */
return 0;
if (err == -EPIPE) {
const char *s;
if (snd_pcm_stream(pcm) == SND_PCM_STREAM_PLAYBACK)
s = "underrun";
else
s = "overrun";
if (!silent)
ERR("%s occurred\n", s);
err = snd_pcm_prepare(pcm);
if (err < 0) {
ERR("cannot recover from %s, prepare failed: %s\n", s, snd_strerror(err));
return err;
}
return 0;
}
if (err == -ESTRPIPE) {
while ((err = snd_pcm_resume(pcm)) == -EAGAIN)
/* wait until suspend flag is released */
poll(NULL, 0, 1000);
if (err < 0) {
err = snd_pcm_prepare(pcm);
if (err < 0) {
ERR("cannot recover from suspend, prepare failed: %s\n", snd_strerror(err));
return err;
}
}
return 0;
}
return err;
}
static BOOL alsa_try_open(const char *devnode, snd_pcm_stream_t stream)
{
snd_pcm_t *handle;

View file

@ -1,780 +0,0 @@
/*
* Sample Wine Driver for Advanced Linux Sound System (ALSA)
* Based on version <final> of the ALSA API
*
* Copyright 2002 Eric Pouech
* 2002 Marco Pietrobono
* 2003 Christian Costa : WaveIn support
* 2006-2007 Maarten Lankhorst
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
/*======================================================================*
* Low level WAVE IN implementation *
*======================================================================*/
#include "config.h"
#include "wine/port.h"
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include <errno.h>
#include <limits.h>
#include <fcntl.h>
#ifdef HAVE_SYS_IOCTL_H
# include <sys/ioctl.h>
#endif
#ifdef HAVE_SYS_MMAN_H
# include <sys/mman.h>
#endif
#include "windef.h"
#include "winbase.h"
#include "wingdi.h"
#include "winuser.h"
#include "winnls.h"
#include "mmddk.h"
#include "mmreg.h"
#include "dsound.h"
#include "dsdriver.h"
#include "ks.h"
#include "ksmedia.h"
#include "alsa.h"
#include "wine/library.h"
#include "wine/unicode.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(wave);
WINE_WAVEDEV *WInDev;
DWORD ALSA_WidNumMallocedDevs;
DWORD ALSA_WidNumDevs;
/**************************************************************************
* widNotifyClient [internal]
*/
static void widNotifyClient(WINE_WAVEDEV* wwi, WORD wMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
{
TRACE("wMsg = 0x%04x dwParm1 = %04lX dwParam2 = %04lX\n", wMsg, dwParam1, dwParam2);
switch (wMsg) {
case WIM_OPEN:
case WIM_CLOSE:
case WIM_DATA:
DriverCallback(wwi->waveDesc.dwCallback, wwi->wFlags, (HDRVR)wwi->waveDesc.hWave,
wMsg, wwi->waveDesc.dwInstance, dwParam1, dwParam2);
break;
default:
FIXME("Unknown callback message %u\n", wMsg);
}
}
/**************************************************************************
* widGetDevCaps [internal]
*/
static DWORD widGetDevCaps(WORD wDevID, LPWAVEINCAPSW lpCaps, DWORD dwSize)
{
TRACE("(%u, %p, %u);\n", wDevID, lpCaps, dwSize);
if (lpCaps == NULL) return MMSYSERR_NOTENABLED;
if (wDevID >= ALSA_WidNumDevs) {
TRACE("Requested device %d, but only %d are known!\n", wDevID, ALSA_WidNumDevs);
return MMSYSERR_BADDEVICEID;
}
memcpy(lpCaps, &WInDev[wDevID].incaps, min(dwSize, sizeof(*lpCaps)));
return MMSYSERR_NOERROR;
}
/**************************************************************************
* widRecorder_ReadHeaders [internal]
*/
static void widRecorder_ReadHeaders(WINE_WAVEDEV * wwi)
{
enum win_wm_message tmp_msg;
DWORD_PTR tmp_param;
HANDLE tmp_ev;
WAVEHDR* lpWaveHdr;
while (ALSA_RetrieveRingMessage(&wwi->msgRing, &tmp_msg, &tmp_param, &tmp_ev)) {
if (tmp_msg == WINE_WM_HEADER) {
LPWAVEHDR* wh;
lpWaveHdr = (LPWAVEHDR)tmp_param;
lpWaveHdr->lpNext = 0;
if (wwi->lpQueuePtr == 0)
wwi->lpQueuePtr = lpWaveHdr;
else {
for (wh = &(wwi->lpQueuePtr); *wh; wh = &((*wh)->lpNext));
*wh = lpWaveHdr;
}
} else {
ERR("should only have headers left\n");
}
}
}
/**************************************************************************
* widRecorder [internal]
*/
static DWORD CALLBACK widRecorder(LPVOID pmt)
{
WORD uDevID = (DWORD_PTR)pmt;
WINE_WAVEDEV* wwi = &WInDev[uDevID];
WAVEHDR* lpWaveHdr;
DWORD dwSleepTime;
DWORD bytesRead;
enum win_wm_message msg;
DWORD_PTR param;
HANDLE ev;
wwi->state = WINE_WS_STOPPED;
InterlockedExchange((LONG*)&wwi->dwTotalRecorded, 0);
wwi->lpQueuePtr = NULL;
SetEvent(wwi->hStartUpEvent);
/* make sleep time to be # of ms to output a period */
dwSleepTime = (wwi->dwPeriodSize * 1000) / wwi->format.Format.nAvgBytesPerSec;
TRACE("sleeptime=%d ms, total buffer length=%d ms (%d bytes)\n", dwSleepTime, wwi->dwBufferSize * 1000 / wwi->format.Format.nAvgBytesPerSec, wwi->dwBufferSize);
for (;;) {
/* wait for dwSleepTime or an event in thread's queue */
if (wwi->lpQueuePtr != NULL && wwi->state == WINE_WS_PLAYING)
{
DWORD frames;
DWORD bytes;
DWORD read;
lpWaveHdr = wwi->lpQueuePtr;
/* read all the fragments accumulated so far */
frames = snd_pcm_avail_update(wwi->pcm);
bytes = snd_pcm_frames_to_bytes(wwi->pcm, frames);
TRACE("frames = %d bytes = %d state=%d\n", frames, bytes, snd_pcm_state(wwi->pcm));
if (snd_pcm_state(wwi->pcm) == SND_PCM_STATE_XRUN)
{
FIXME("Recovering from XRUN!\n");
snd_pcm_prepare(wwi->pcm);
frames = snd_pcm_avail_update(wwi->pcm);
bytes = snd_pcm_frames_to_bytes(wwi->pcm, frames);
snd_pcm_start(wwi->pcm);
snd_pcm_forward(wwi->pcm, frames - snd_pcm_bytes_to_frames(wwi->pcm, wwi->dwPeriodSize));
continue;
}
while (frames > 0 && wwi->lpQueuePtr)
{
TRACE("bytes = %d\n", bytes);
if (lpWaveHdr->dwBufferLength - lpWaveHdr->dwBytesRecorded < bytes)
{
bytes = lpWaveHdr->dwBufferLength - lpWaveHdr->dwBytesRecorded;
frames = snd_pcm_bytes_to_frames(wwi->pcm, bytes);
}
/* directly read fragment in wavehdr */
read = wwi->read(wwi->pcm, lpWaveHdr->lpData + lpWaveHdr->dwBytesRecorded, frames);
bytesRead = snd_pcm_frames_to_bytes(wwi->pcm, read);
TRACE("bytesRead=(%d(%d)/(%d)) -> (%d/%d)\n", bytesRead, read, frames, lpWaveHdr->dwBufferLength, lpWaveHdr->dwBufferLength - lpWaveHdr->dwBytesRecorded);
if (read != (DWORD) -1)
{
/* update number of bytes recorded in current buffer and by this device */
lpWaveHdr->dwBytesRecorded += bytesRead;
InterlockedExchangeAdd((LONG*)&wwi->dwTotalRecorded, bytesRead);
frames -= read;
bytes -= bytesRead;
/* buffer is full. notify client */
if (!snd_pcm_bytes_to_frames(wwi->pcm, lpWaveHdr->dwBytesRecorded - lpWaveHdr->dwBufferLength))
{
/* must copy the value of next waveHdr, because we have no idea of what
* will be done with the content of lpWaveHdr in callback
*/
LPWAVEHDR lpNext = lpWaveHdr->lpNext;
lpWaveHdr->dwFlags &= ~WHDR_INQUEUE;
lpWaveHdr->dwFlags |= WHDR_DONE;
wwi->lpQueuePtr = lpNext;
widNotifyClient(wwi, WIM_DATA, (DWORD_PTR)lpWaveHdr, 0);
lpWaveHdr = lpNext;
}
} else {
WARN("read(%s, %p, %d) failed (%d/%s)\n", wwi->pcmname,
lpWaveHdr->lpData + lpWaveHdr->dwBytesRecorded,
frames, frames, snd_strerror(read));
}
}
}
ALSA_WaitRingMessage(&wwi->msgRing, dwSleepTime);
while (ALSA_RetrieveRingMessage(&wwi->msgRing, &msg, &param, &ev))
{
TRACE("msg=%s param=0x%lx\n", ALSA_getCmdString(msg), param);
switch (msg) {
case WINE_WM_PAUSING:
wwi->state = WINE_WS_PAUSED;
/*FIXME("Device should stop recording\n");*/
SetEvent(ev);
break;
case WINE_WM_STARTING:
wwi->state = WINE_WS_PLAYING;
snd_pcm_start(wwi->pcm);
SetEvent(ev);
break;
case WINE_WM_HEADER:
lpWaveHdr = (LPWAVEHDR)param;
lpWaveHdr->lpNext = 0;
/* insert buffer at the end of queue */
{
LPWAVEHDR* wh;
for (wh = &(wwi->lpQueuePtr); *wh; wh = &((*wh)->lpNext));
*wh = lpWaveHdr;
}
break;
case WINE_WM_STOPPING:
if (wwi->state != WINE_WS_STOPPED)
{
snd_pcm_drain(wwi->pcm);
/* read any headers in queue */
widRecorder_ReadHeaders(wwi);
/* return current buffer to app */
lpWaveHdr = wwi->lpQueuePtr;
if (lpWaveHdr)
{
LPWAVEHDR lpNext = lpWaveHdr->lpNext;
TRACE("stop %p %p\n", lpWaveHdr, lpWaveHdr->lpNext);
lpWaveHdr->dwFlags &= ~WHDR_INQUEUE;
lpWaveHdr->dwFlags |= WHDR_DONE;
wwi->lpQueuePtr = lpNext;
widNotifyClient(wwi, WIM_DATA, (DWORD_PTR)lpWaveHdr, 0);
}
}
wwi->state = WINE_WS_STOPPED;
SetEvent(ev);
break;
case WINE_WM_RESETTING:
if (wwi->state != WINE_WS_STOPPED)
{
snd_pcm_drain(wwi->pcm);
}
wwi->state = WINE_WS_STOPPED;
wwi->dwTotalRecorded = 0;
/* read any headers in queue */
widRecorder_ReadHeaders(wwi);
/* return all buffers to the app */
while (wwi->lpQueuePtr) {
lpWaveHdr = wwi->lpQueuePtr;
TRACE("reset %p %p\n", lpWaveHdr, lpWaveHdr->lpNext);
wwi->lpQueuePtr = lpWaveHdr->lpNext;
lpWaveHdr->dwFlags &= ~WHDR_INQUEUE;
lpWaveHdr->dwFlags |= WHDR_DONE;
widNotifyClient(wwi, WIM_DATA, (DWORD_PTR)lpWaveHdr, 0);
}
SetEvent(ev);
break;
case WINE_WM_CLOSING:
wwi->hThread = 0;
wwi->state = WINE_WS_CLOSED;
SetEvent(ev);
ExitThread(0);
/* shouldn't go here */
default:
FIXME("unknown message %d\n", msg);
break;
}
}
}
ExitThread(0);
/* just for not generating compilation warnings... should never be executed */
return 0;
}
/**************************************************************************
* widOpen [internal]
*/
static DWORD widOpen(WORD wDevID, LPWAVEOPENDESC lpDesc, DWORD dwFlags)
{
WINE_WAVEDEV* wwi;
snd_pcm_hw_params_t * hw_params;
snd_pcm_sw_params_t * sw_params;
snd_pcm_access_t access;
snd_pcm_format_t format;
unsigned int rate;
unsigned int buffer_time = 500000;
unsigned int period_time = 10000;
snd_pcm_uframes_t buffer_size;
snd_pcm_uframes_t period_size;
int flags;
snd_pcm_t * pcm;
int err;
int dir;
DWORD ret;
/* JPW TODO - review this code */
TRACE("(%u, %p, %08X);\n", wDevID, lpDesc, dwFlags);
if (lpDesc == NULL) {
WARN("Invalid Parameter !\n");
return MMSYSERR_INVALPARAM;
}
if (wDevID >= ALSA_WidNumDevs) {
TRACE("Requested device %d, but only %d are known!\n", wDevID, ALSA_WidNumDevs);
return MMSYSERR_BADDEVICEID;
}
/* only PCM format is supported so far... */
if (!ALSA_supportedFormat(lpDesc->lpFormat)) {
WARN("Bad format: tag=%04X nChannels=%d nSamplesPerSec=%d !\n",
lpDesc->lpFormat->wFormatTag, lpDesc->lpFormat->nChannels,
lpDesc->lpFormat->nSamplesPerSec);
return WAVERR_BADFORMAT;
}
if (dwFlags & WAVE_FORMAT_QUERY) {
TRACE("Query format: tag=%04X nChannels=%d nSamplesPerSec=%d !\n",
lpDesc->lpFormat->wFormatTag, lpDesc->lpFormat->nChannels,
lpDesc->lpFormat->nSamplesPerSec);
return MMSYSERR_NOERROR;
}
wwi = &WInDev[wDevID];
if (wwi->pcm != NULL) {
WARN("already allocated\n");
return MMSYSERR_ALLOCATED;
}
flags = SND_PCM_NONBLOCK;
if ( (err=snd_pcm_open(&pcm, wwi->pcmname, SND_PCM_STREAM_CAPTURE, flags)) < 0 )
{
ERR("Error open: %s\n", snd_strerror(err));
return MMSYSERR_NOTENABLED;
}
wwi->wFlags = HIWORD(dwFlags & CALLBACK_TYPEMASK);
wwi->waveDesc = *lpDesc;
ALSA_copyFormat(lpDesc->lpFormat, &wwi->format);
if (wwi->format.Format.wBitsPerSample == 0) {
WARN("Resetting zeroed wBitsPerSample\n");
wwi->format.Format.wBitsPerSample = 8 *
(wwi->format.Format.nAvgBytesPerSec /
wwi->format.Format.nSamplesPerSec) /
wwi->format.Format.nChannels;
}
hw_params = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, snd_pcm_hw_params_sizeof() );
sw_params = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, snd_pcm_sw_params_sizeof() );
if (!hw_params || !sw_params)
{
ret = MMSYSERR_NOMEM;
goto error;
}
snd_pcm_hw_params_any(pcm, hw_params);
#define EXIT_ON_ERROR(f,e,txt) do \
{ \
int err; \
if ( (err = (f) ) < 0) \
{ \
WARN(txt ": %s\n", snd_strerror(err)); \
ret = (e); \
goto error; \
} \
} while(0)
access = SND_PCM_ACCESS_MMAP_INTERLEAVED;
if ( ( err = snd_pcm_hw_params_set_access(pcm, hw_params, access ) ) < 0) {
WARN("mmap not available. switching to standard write.\n");
access = SND_PCM_ACCESS_RW_INTERLEAVED;
EXIT_ON_ERROR( snd_pcm_hw_params_set_access(pcm, hw_params, access ), MMSYSERR_INVALPARAM, "unable to set access for playback");
wwi->read = snd_pcm_readi;
}
else
wwi->read = snd_pcm_mmap_readi;
EXIT_ON_ERROR( snd_pcm_hw_params_set_channels(pcm, hw_params, wwi->format.Format.nChannels), WAVERR_BADFORMAT, "unable to set required channels");
if ((wwi->format.Format.wFormatTag == WAVE_FORMAT_PCM) ||
((wwi->format.Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE) &&
IsEqualGUID(&wwi->format.SubFormat, &KSDATAFORMAT_SUBTYPE_PCM))) {
format = (wwi->format.Format.wBitsPerSample == 8) ? SND_PCM_FORMAT_U8 :
(wwi->format.Format.wBitsPerSample == 16) ? SND_PCM_FORMAT_S16_LE :
(wwi->format.Format.wBitsPerSample == 24) ? SND_PCM_FORMAT_S24_3LE :
(wwi->format.Format.wBitsPerSample == 32) ? SND_PCM_FORMAT_S32_LE : -1;
} else if ((wwi->format.Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE) &&
IsEqualGUID(&wwi->format.SubFormat, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT)){
format = (wwi->format.Format.wBitsPerSample == 32) ? SND_PCM_FORMAT_FLOAT_LE : -1;
} else if (wwi->format.Format.wFormatTag == WAVE_FORMAT_MULAW) {
FIXME("unimplemented format: WAVE_FORMAT_MULAW\n");
ret = WAVERR_BADFORMAT;
goto error;
} else if (wwi->format.Format.wFormatTag == WAVE_FORMAT_ALAW) {
FIXME("unimplemented format: WAVE_FORMAT_ALAW\n");
ret = WAVERR_BADFORMAT;
goto error;
} else if (wwi->format.Format.wFormatTag == WAVE_FORMAT_ADPCM) {
FIXME("unimplemented format: WAVE_FORMAT_ADPCM\n");
ret = WAVERR_BADFORMAT;
goto error;
} else {
ERR("invalid format: %0x04x\n", wwi->format.Format.wFormatTag);
ret = WAVERR_BADFORMAT;
goto error;
}
EXIT_ON_ERROR( snd_pcm_hw_params_set_format(pcm, hw_params, format), WAVERR_BADFORMAT, "unable to set required format");
rate = wwi->format.Format.nSamplesPerSec;
dir = 0;
err = snd_pcm_hw_params_set_rate_near(pcm, hw_params, &rate, &dir);
if (err < 0) {
WARN("Rate %d Hz not available for playback: %s\n", wwi->format.Format.nSamplesPerSec, snd_strerror(rate));
ret = WAVERR_BADFORMAT;
goto error;
}
if (!ALSA_NearMatch(rate, wwi->format.Format.nSamplesPerSec)) {
WARN("Rate doesn't match (requested %d Hz, got %d Hz)\n", wwi->format.Format.nSamplesPerSec, rate);
ret = WAVERR_BADFORMAT;
goto error;
}
dir=0;
EXIT_ON_ERROR( snd_pcm_hw_params_set_buffer_time_near(pcm, hw_params, &buffer_time, &dir), MMSYSERR_INVALPARAM, "unable to set buffer time");
dir=0;
EXIT_ON_ERROR( snd_pcm_hw_params_set_period_time_near(pcm, hw_params, &period_time, &dir), MMSYSERR_INVALPARAM, "unable to set period time");
EXIT_ON_ERROR( snd_pcm_hw_params(pcm, hw_params), MMSYSERR_INVALPARAM, "unable to set hw params for playback");
dir=0;
err = snd_pcm_hw_params_get_period_size(hw_params, &period_size, &dir);
err = snd_pcm_hw_params_get_buffer_size(hw_params, &buffer_size);
snd_pcm_sw_params_current(pcm, sw_params);
EXIT_ON_ERROR( snd_pcm_sw_params_set_start_threshold(pcm, sw_params, 1), MMSYSERR_ERROR, "unable to set start threshold");
EXIT_ON_ERROR( snd_pcm_sw_params_set_silence_size(pcm, sw_params, 0), MMSYSERR_ERROR, "unable to set silence size");
EXIT_ON_ERROR( snd_pcm_sw_params_set_avail_min(pcm, sw_params, period_size), MMSYSERR_ERROR, "unable to set avail min");
EXIT_ON_ERROR( snd_pcm_sw_params_set_silence_threshold(pcm, sw_params, 0), MMSYSERR_ERROR, "unable to set silence threshold");
EXIT_ON_ERROR( snd_pcm_sw_params(pcm, sw_params), MMSYSERR_ERROR, "unable to set sw params for playback");
#undef EXIT_ON_ERROR
snd_pcm_prepare(pcm);
if (TRACE_ON(wave))
ALSA_TraceParameters(hw_params, sw_params, FALSE);
/* now, we can save all required data for later use... */
wwi->dwBufferSize = snd_pcm_frames_to_bytes(pcm, buffer_size);
wwi->lpQueuePtr = wwi->lpPlayPtr = wwi->lpLoopPtr = NULL;
ALSA_InitRingMessage(&wwi->msgRing);
wwi->dwPeriodSize = snd_pcm_frames_to_bytes(pcm, period_size);
TRACE("dwPeriodSize=%u\n", wwi->dwPeriodSize);
TRACE("wBitsPerSample=%u, nAvgBytesPerSec=%u, nSamplesPerSec=%u, nChannels=%u nBlockAlign=%u!\n",
wwi->format.Format.wBitsPerSample, wwi->format.Format.nAvgBytesPerSec,
wwi->format.Format.nSamplesPerSec, wwi->format.Format.nChannels,
wwi->format.Format.nBlockAlign);
wwi->hStartUpEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
wwi->hThread = CreateThread(NULL, 0, widRecorder, (LPVOID)(DWORD_PTR)wDevID, 0, &(wwi->dwThreadID));
if (!wwi->hThread) {
ERR("Thread creation for the widRecorder failed!\n");
CloseHandle(wwi->hStartUpEvent);
ret = MMSYSERR_NOMEM;
goto error;
}
SetThreadPriority(wwi->hThread, THREAD_PRIORITY_TIME_CRITICAL);
WaitForSingleObject(wwi->hStartUpEvent, INFINITE);
CloseHandle(wwi->hStartUpEvent);
wwi->hStartUpEvent = NULL;
HeapFree( GetProcessHeap(), 0, sw_params );
wwi->hw_params = hw_params;
wwi->pcm = pcm;
widNotifyClient(wwi, WIM_OPEN, 0L, 0L);
return MMSYSERR_NOERROR;
error:
snd_pcm_close(pcm);
HeapFree( GetProcessHeap(), 0, hw_params );
HeapFree( GetProcessHeap(), 0, sw_params );
if (wwi->msgRing.ring_buffer_size > 0)
ALSA_DestroyRingMessage(&wwi->msgRing);
return ret;
}
/**************************************************************************
* widClose [internal]
*/
static DWORD widClose(WORD wDevID)
{
WINE_WAVEDEV* wwi;
TRACE("(%u);\n", wDevID);
if (wDevID >= ALSA_WidNumDevs) {
TRACE("Requested device %d, but only %d are known!\n", wDevID, ALSA_WidNumDevs);
return MMSYSERR_BADDEVICEID;
}
wwi = &WInDev[wDevID];
if (wwi->pcm == NULL) {
WARN("Requested to close already closed device %d!\n", wDevID);
return MMSYSERR_BADDEVICEID;
}
if (wwi->lpQueuePtr) {
WARN("buffers still playing !\n");
return WAVERR_STILLPLAYING;
} else {
if (wwi->hThread) {
ALSA_AddRingMessage(&wwi->msgRing, WINE_WM_CLOSING, 0, TRUE);
}
ALSA_DestroyRingMessage(&wwi->msgRing);
HeapFree( GetProcessHeap(), 0, wwi->hw_params );
wwi->hw_params = NULL;
snd_pcm_close(wwi->pcm);
wwi->pcm = NULL;
widNotifyClient(wwi, WIM_CLOSE, 0L, 0L);
}
return MMSYSERR_NOERROR;
}
/**************************************************************************
* widAddBuffer [internal]
*
*/
static DWORD widAddBuffer(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize)
{
TRACE("(%u, %p, %08X);\n", wDevID, lpWaveHdr, dwSize);
/* first, do the sanity checks... */
if (wDevID >= ALSA_WidNumDevs) {
TRACE("Requested device %d, but only %d are known!\n", wDevID, ALSA_WidNumDevs);
return MMSYSERR_BADDEVICEID;
}
if (WInDev[wDevID].pcm == NULL) {
WARN("Requested to add buffer to already closed device %d!\n", wDevID);
return MMSYSERR_BADDEVICEID;
}
if (lpWaveHdr->lpData == NULL || !(lpWaveHdr->dwFlags & WHDR_PREPARED))
return WAVERR_UNPREPARED;
if (lpWaveHdr->dwFlags & WHDR_INQUEUE)
return WAVERR_STILLPLAYING;
lpWaveHdr->dwFlags &= ~WHDR_DONE;
lpWaveHdr->dwFlags |= WHDR_INQUEUE;
lpWaveHdr->dwBytesRecorded = 0;
lpWaveHdr->lpNext = 0;
ALSA_AddRingMessage(&WInDev[wDevID].msgRing, WINE_WM_HEADER, (DWORD_PTR)lpWaveHdr, FALSE);
return MMSYSERR_NOERROR;
}
/**************************************************************************
* widStart [internal]
*
*/
static DWORD widStart(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize)
{
TRACE("(%u, %p, %08X);\n", wDevID, lpWaveHdr, dwSize);
/* first, do the sanity checks... */
if (wDevID >= ALSA_WidNumDevs) {
TRACE("Requested device %d, but only %d are known!\n", wDevID, ALSA_WidNumDevs);
return MMSYSERR_BADDEVICEID;
}
if (WInDev[wDevID].pcm == NULL) {
WARN("Requested to start closed device %d!\n", wDevID);
return MMSYSERR_BADDEVICEID;
}
ALSA_AddRingMessage(&WInDev[wDevID].msgRing, WINE_WM_STARTING, 0, TRUE);
return MMSYSERR_NOERROR;
}
/**************************************************************************
* widStop [internal]
*
*/
static DWORD widStop(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize)
{
TRACE("(%u, %p, %08X);\n", wDevID, lpWaveHdr, dwSize);
/* first, do the sanity checks... */
if (wDevID >= ALSA_WidNumDevs) {
TRACE("Requested device %d, but only %d are known!\n", wDevID, ALSA_WidNumDevs);
return MMSYSERR_BADDEVICEID;
}
if (WInDev[wDevID].pcm == NULL) {
WARN("Requested to stop closed device %d!\n", wDevID);
return MMSYSERR_BADDEVICEID;
}
ALSA_AddRingMessage(&WInDev[wDevID].msgRing, WINE_WM_STOPPING, 0, TRUE);
return MMSYSERR_NOERROR;
}
/**************************************************************************
* widReset [internal]
*/
static DWORD widReset(WORD wDevID)
{
TRACE("(%u);\n", wDevID);
if (wDevID >= ALSA_WidNumDevs) {
TRACE("Requested device %d, but only %d are known!\n", wDevID, ALSA_WidNumDevs);
return MMSYSERR_BADDEVICEID;
}
if (WInDev[wDevID].pcm == NULL) {
WARN("Requested to reset closed device %d!\n", wDevID);
return MMSYSERR_BADDEVICEID;
}
ALSA_AddRingMessage(&WInDev[wDevID].msgRing, WINE_WM_RESETTING, 0, TRUE);
return MMSYSERR_NOERROR;
}
/**************************************************************************
* widGetPosition [internal]
*/
static DWORD widGetPosition(WORD wDevID, LPMMTIME lpTime, DWORD uSize)
{
WINE_WAVEDEV* wwi;
TRACE("(%u, %p, %u);\n", wDevID, lpTime, uSize);
if (wDevID >= ALSA_WidNumDevs) {
TRACE("Requested device %d, but only %d are known!\n", wDevID, ALSA_WidNumDevs);
return MMSYSERR_BADDEVICEID;
}
if (WInDev[wDevID].state == WINE_WS_CLOSED) {
WARN("Requested position of closed device %d!\n", wDevID);
return MMSYSERR_BADDEVICEID;
}
if (lpTime == NULL) {
WARN("invalid parameter: lpTime = NULL\n");
return MMSYSERR_INVALPARAM;
}
wwi = &WInDev[wDevID];
return ALSA_bytes_to_mmtime(lpTime, wwi->dwTotalRecorded, &wwi->format);
}
/**************************************************************************
* widGetNumDevs [internal]
*/
static DWORD widGetNumDevs(void)
{
return ALSA_WidNumDevs;
}
/**************************************************************************
* widDevInterfaceSize [internal]
*/
static DWORD widDevInterfaceSize(UINT wDevID, LPDWORD dwParam1)
{
TRACE("(%u, %p)\n", wDevID, dwParam1);
*dwParam1 = MultiByteToWideChar(CP_UNIXCP, 0, WInDev[wDevID].interface_name, -1,
NULL, 0 ) * sizeof(WCHAR);
return MMSYSERR_NOERROR;
}
/**************************************************************************
* widDevInterface [internal]
*/
static DWORD widDevInterface(UINT wDevID, PWCHAR dwParam1, DWORD dwParam2)
{
if (dwParam2 >= MultiByteToWideChar(CP_UNIXCP, 0, WInDev[wDevID].interface_name, -1,
NULL, 0 ) * sizeof(WCHAR))
{
MultiByteToWideChar(CP_UNIXCP, 0, WInDev[wDevID].interface_name, -1,
dwParam1, dwParam2 / sizeof(WCHAR));
return MMSYSERR_NOERROR;
}
return MMSYSERR_INVALPARAM;
}
/**************************************************************************
* widMessage (WINEALSA.@)
*/
DWORD WINAPI ALSA_widMessage(UINT wDevID, UINT wMsg, DWORD_PTR dwUser,
DWORD_PTR dwParam1, DWORD_PTR dwParam2)
{
TRACE("(%u, %s, %08lX, %08lX, %08lX);\n",
wDevID, ALSA_getMessage(wMsg), dwUser, dwParam1, dwParam2);
switch (wMsg) {
case DRVM_INIT:
ALSA_WaveInit();
case DRVM_EXIT:
case DRVM_ENABLE:
case DRVM_DISABLE:
/* FIXME: Pretend this is supported */
return 0;
case WIDM_OPEN: return widOpen (wDevID, (LPWAVEOPENDESC)dwParam1, dwParam2);
case WIDM_CLOSE: return widClose (wDevID);
case WIDM_ADDBUFFER: return widAddBuffer (wDevID, (LPWAVEHDR)dwParam1, dwParam2);
case WIDM_PREPARE: return MMSYSERR_NOTSUPPORTED;
case WIDM_UNPREPARE: return MMSYSERR_NOTSUPPORTED;
case WIDM_GETDEVCAPS: return widGetDevCaps (wDevID, (LPWAVEINCAPSW)dwParam1, dwParam2);
case WIDM_GETNUMDEVS: return widGetNumDevs ();
case WIDM_GETPOS: return widGetPosition (wDevID, (LPMMTIME)dwParam1, dwParam2);
case WIDM_RESET: return widReset (wDevID);
case WIDM_START: return widStart (wDevID, (LPWAVEHDR)dwParam1, dwParam2);
case WIDM_STOP: return widStop (wDevID, (LPWAVEHDR)dwParam1, dwParam2);
case DRV_QUERYDEVICEINTERFACESIZE: return widDevInterfaceSize (wDevID, (LPDWORD)dwParam1);
case DRV_QUERYDEVICEINTERFACE: return widDevInterface (wDevID, (PWCHAR)dwParam1, dwParam2);
case DRV_QUERYDSOUNDIFACE: return widDsCreate (wDevID, (PIDSCDRIVER*)dwParam1);
case DRV_QUERYDSOUNDDESC: return widDsDesc (wDevID, (PDSDRIVERDESC)dwParam1);
default:
FIXME("unknown message %d!\n", wMsg);
}
return MMSYSERR_NOTSUPPORTED;
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -2,9 +2,6 @@
@ stdcall -private DriverProc(long long long long long) ALSA_DriverProc
@ stdcall -private midMessage(long long long long long) ALSA_midMessage
@ stdcall -private modMessage(long long long long long) ALSA_modMessage
@ stdcall -private mxdMessage(long long long long long) ALSA_mxdMessage
@ stdcall -private widMessage(long long long long long) ALSA_widMessage
@ stdcall -private wodMessage(long long long long long) ALSA_wodMessage
# MMDevAPI driver functions
@ stdcall -private GetPriority() AUDDRV_GetPriority