2006-05-28 22:46:23 +02:00
|
|
|
/*
|
|
|
|
* Wine Driver for CoreAudio based on Jack Driver
|
|
|
|
*
|
|
|
|
* Copyright 1994 Martin Ayotte
|
|
|
|
* Copyright 1999 Eric Pouech (async playing in waveOut/waveIn)
|
|
|
|
* Copyright 2000 Eric Pouech (loops in waveOut)
|
|
|
|
* Copyright 2002 Chris Morgan (jack version of this file)
|
|
|
|
* Copyright 2005, 2006 Emmanuel Maillard
|
|
|
|
*
|
|
|
|
* 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
|
2006-06-01 13:15:54 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2006-05-28 22:46:23 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#include <fcntl.h>
|
2009-04-11 14:18:18 +02:00
|
|
|
#include <assert.h>
|
2006-05-28 22:46:23 +02:00
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winnls.h"
|
|
|
|
#include "wingdi.h"
|
|
|
|
#include "winerror.h"
|
|
|
|
#include "mmddk.h"
|
2009-09-11 08:12:53 +02:00
|
|
|
#include "mmreg.h"
|
2006-05-28 22:46:23 +02:00
|
|
|
#include "dsound.h"
|
|
|
|
#include "dsdriver.h"
|
2009-09-11 08:12:53 +02:00
|
|
|
#include "ks.h"
|
|
|
|
#include "ksguid.h"
|
|
|
|
#include "ksmedia.h"
|
2006-05-28 22:46:23 +02:00
|
|
|
#include "coreaudio.h"
|
|
|
|
#include "wine/unicode.h"
|
|
|
|
#include "wine/library.h"
|
|
|
|
#include "wine/debug.h"
|
2009-10-11 21:13:23 +02:00
|
|
|
#include "wine/list.h"
|
2006-05-28 22:46:23 +02:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(wave);
|
|
|
|
|
|
|
|
#if defined(HAVE_COREAUDIO_COREAUDIO_H) && defined(HAVE_AUDIOUNIT_AUDIOUNIT_H)
|
|
|
|
#include <CoreAudio/CoreAudio.h>
|
|
|
|
#include <CoreFoundation/CoreFoundation.h>
|
2006-12-21 10:50:18 +01:00
|
|
|
#include <libkern/OSAtomic.h>
|
2006-05-28 22:46:23 +02:00
|
|
|
|
2009-10-11 21:11:37 +02:00
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(coreaudio);
|
|
|
|
|
2006-05-28 22:46:23 +02:00
|
|
|
/*
|
|
|
|
Due to AudioUnit headers conflict define some needed types.
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef void *AudioUnit;
|
|
|
|
|
|
|
|
/* From AudioUnit/AUComponents.h */
|
2006-12-21 10:49:24 +01:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
kAudioUnitRenderAction_OutputIsSilence = (1 << 4),
|
|
|
|
/* provides hint on return from Render(): if set the buffer contains all zeroes */
|
|
|
|
};
|
2006-05-28 22:46:23 +02:00
|
|
|
typedef UInt32 AudioUnitRenderActionFlags;
|
|
|
|
|
2006-12-28 18:07:16 +01:00
|
|
|
typedef long ComponentResult;
|
|
|
|
extern ComponentResult
|
|
|
|
AudioUnitRender( AudioUnit ci,
|
|
|
|
AudioUnitRenderActionFlags * ioActionFlags,
|
|
|
|
const AudioTimeStamp * inTimeStamp,
|
|
|
|
UInt32 inOutputBusNumber,
|
|
|
|
UInt32 inNumberFrames,
|
|
|
|
AudioBufferList * ioData) AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER;
|
|
|
|
|
2006-05-28 22:46:23 +02:00
|
|
|
/* only allow 10 output devices through this driver, this ought to be adequate */
|
|
|
|
#define MAX_WAVEOUTDRV (1)
|
|
|
|
#define MAX_WAVEINDRV (1)
|
|
|
|
|
|
|
|
/* state diagram for waveOut writing:
|
|
|
|
*
|
|
|
|
* +---------+-------------+---------------+---------------------------------+
|
|
|
|
* | state | function | event | new state |
|
|
|
|
* +---------+-------------+---------------+---------------------------------+
|
2009-04-11 14:18:27 +02:00
|
|
|
* | | open() | | PLAYING |
|
2006-05-28 22:46:23 +02:00
|
|
|
* | PAUSED | write() | | PAUSED |
|
|
|
|
* | PLAYING | write() | HEADER | PLAYING |
|
|
|
|
* | (other) | write() | <error> | |
|
|
|
|
* | (any) | pause() | PAUSING | PAUSED |
|
2009-04-11 14:18:27 +02:00
|
|
|
* | PAUSED | restart() | RESTARTING | PLAYING |
|
|
|
|
* | (any) | reset() | RESETTING | PLAYING |
|
2009-10-11 21:13:23 +02:00
|
|
|
* | (any) | close() | CLOSING | <deallocated> |
|
2006-05-28 22:46:23 +02:00
|
|
|
* +---------+-------------+---------------+---------------------------------+
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* states of the playing device */
|
2009-04-11 14:18:27 +02:00
|
|
|
#define WINE_WS_PLAYING 0 /* for waveOut: lpPlayPtr == NULL -> stopped */
|
2006-05-28 22:46:23 +02:00
|
|
|
#define WINE_WS_PAUSED 1
|
2009-04-11 14:18:27 +02:00
|
|
|
#define WINE_WS_STOPPED 2 /* Not used for waveOut */
|
2009-10-11 21:13:23 +02:00
|
|
|
#define WINE_WS_CLOSED 3 /* Not used for waveOut */
|
2009-04-11 14:18:18 +02:00
|
|
|
#define WINE_WS_OPENING 4
|
2009-04-11 14:18:23 +02:00
|
|
|
#define WINE_WS_CLOSING 5
|
2006-05-28 22:46:23 +02:00
|
|
|
|
|
|
|
typedef struct tagCoreAudio_Device {
|
|
|
|
char dev_name[32];
|
|
|
|
char mixer_name[32];
|
|
|
|
unsigned open_count;
|
|
|
|
char* interface_name;
|
|
|
|
|
2006-05-31 14:52:58 +02:00
|
|
|
WAVEOUTCAPSW out_caps;
|
|
|
|
WAVEINCAPSW in_caps;
|
2006-05-28 22:46:23 +02:00
|
|
|
DWORD in_caps_support;
|
|
|
|
int sample_rate;
|
|
|
|
int stereo;
|
|
|
|
int format;
|
|
|
|
unsigned audio_fragment;
|
|
|
|
BOOL full_duplex;
|
|
|
|
BOOL bTriggerSupport;
|
|
|
|
BOOL bOutputEnabled;
|
|
|
|
BOOL bInputEnabled;
|
|
|
|
DSDRIVERDESC ds_desc;
|
|
|
|
DSDRIVERCAPS ds_caps;
|
|
|
|
DSCDRIVERCAPS dsc_caps;
|
|
|
|
GUID ds_guid;
|
|
|
|
GUID dsc_guid;
|
|
|
|
|
|
|
|
AudioDeviceID outputDeviceID;
|
|
|
|
AudioDeviceID inputDeviceID;
|
|
|
|
AudioStreamBasicDescription streamDescription;
|
|
|
|
} CoreAudio_Device;
|
|
|
|
|
|
|
|
/* for now use the default device */
|
|
|
|
static CoreAudio_Device CoreAudio_DefaultDevice;
|
|
|
|
|
|
|
|
typedef struct {
|
2009-10-11 21:13:23 +02:00
|
|
|
struct list entry;
|
|
|
|
|
2006-05-28 22:46:23 +02:00
|
|
|
volatile int state; /* one of the WINE_WS_ manifest constants */
|
|
|
|
WAVEOPENDESC waveDesc;
|
|
|
|
WORD wFlags;
|
|
|
|
PCMWAVEFORMAT format;
|
|
|
|
DWORD woID;
|
|
|
|
AudioUnit audioUnit;
|
|
|
|
AudioStreamBasicDescription streamDescription;
|
2009-10-11 21:12:01 +02:00
|
|
|
|
|
|
|
LPWAVEHDR lpQueuePtr; /* start of queued WAVEHDRs (waiting to be notified) */
|
|
|
|
LPWAVEHDR lpPlayPtr; /* start of not yet fully played buffers */
|
|
|
|
DWORD dwPartialOffset; /* Offset of not yet written bytes in lpPlayPtr */
|
|
|
|
|
|
|
|
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 */
|
2006-05-28 22:46:23 +02:00
|
|
|
|
2006-12-21 10:50:18 +01:00
|
|
|
OSSpinLock lock; /* synchronization stuff */
|
2009-10-11 21:12:01 +02:00
|
|
|
} WINE_WAVEOUT_INSTANCE;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
CoreAudio_Device *cadev;
|
|
|
|
WAVEOUTCAPSW caps;
|
|
|
|
char interface_name[32];
|
2009-10-23 02:36:24 +02:00
|
|
|
DWORD device_volume;
|
2006-12-21 10:46:55 +01:00
|
|
|
|
|
|
|
BOOL trace_on;
|
|
|
|
BOOL warn_on;
|
|
|
|
BOOL err_on;
|
2009-10-11 21:12:01 +02:00
|
|
|
|
2009-10-11 21:13:23 +02:00
|
|
|
struct list instances;
|
|
|
|
OSSpinLock lock; /* guards the instances list */
|
2006-05-28 22:46:23 +02:00
|
|
|
} WINE_WAVEOUT;
|
|
|
|
|
|
|
|
typedef struct {
|
2006-12-28 18:06:35 +01:00
|
|
|
/* This device's device number */
|
|
|
|
DWORD wiID;
|
|
|
|
|
2006-12-28 18:03:50 +01:00
|
|
|
/* Access to the following fields is synchronized across threads. */
|
2006-05-28 22:46:23 +02:00
|
|
|
volatile int state;
|
2006-12-28 18:05:31 +01:00
|
|
|
LPWAVEHDR lpQueuePtr;
|
|
|
|
DWORD dwTotalRecorded;
|
2006-12-28 18:03:50 +01:00
|
|
|
|
|
|
|
/* Synchronization mechanism to protect above fields */
|
|
|
|
OSSpinLock lock;
|
|
|
|
|
|
|
|
/* Capabilities description */
|
|
|
|
WAVEINCAPSW caps;
|
2006-12-28 18:06:16 +01:00
|
|
|
char interface_name[32];
|
2006-12-28 18:03:50 +01:00
|
|
|
|
|
|
|
/* Record the arguments used when opening the device. */
|
2006-05-28 22:46:23 +02:00
|
|
|
WAVEOPENDESC waveDesc;
|
|
|
|
WORD wFlags;
|
2006-12-28 18:05:31 +01:00
|
|
|
PCMWAVEFORMAT format;
|
|
|
|
|
|
|
|
AudioUnit audioUnit;
|
2006-12-28 18:06:29 +01:00
|
|
|
AudioBufferList*bufferList;
|
2007-07-13 14:21:36 +02:00
|
|
|
AudioBufferList*bufferListCopy;
|
2006-12-28 18:05:31 +01:00
|
|
|
|
|
|
|
/* Record state of debug channels at open. Used to control fprintf's since
|
|
|
|
* we can't use Wine debug channel calls in non-Wine AudioUnit threads. */
|
|
|
|
BOOL trace_on;
|
|
|
|
BOOL warn_on;
|
|
|
|
BOOL err_on;
|
2006-12-28 18:03:50 +01:00
|
|
|
|
|
|
|
/* These fields aren't used. */
|
|
|
|
#if 0
|
|
|
|
CoreAudio_Device *cadev;
|
|
|
|
|
2006-05-28 22:46:23 +02:00
|
|
|
AudioStreamBasicDescription streamDescription;
|
2006-12-28 18:03:50 +01:00
|
|
|
#endif
|
2006-05-28 22:46:23 +02:00
|
|
|
} WINE_WAVEIN;
|
|
|
|
|
|
|
|
static WINE_WAVEOUT WOutDev [MAX_WAVEOUTDRV];
|
2006-12-28 18:03:50 +01:00
|
|
|
static WINE_WAVEIN WInDev [MAX_WAVEINDRV];
|
2006-05-28 22:46:23 +02:00
|
|
|
|
2007-01-01 11:22:58 +01:00
|
|
|
static HANDLE hThread = NULL; /* Track the thread we create so we can clean it up later */
|
2006-12-21 10:47:05 +01:00
|
|
|
static CFMessagePortRef Port_SendToMessageThread;
|
2006-05-24 12:43:14 +02:00
|
|
|
|
2009-10-11 21:12:01 +02:00
|
|
|
static void wodHelper_PlayPtrNext(WINE_WAVEOUT_INSTANCE* wwo);
|
|
|
|
static void wodHelper_NotifyDoneForList(WINE_WAVEOUT_INSTANCE* wwo, LPWAVEHDR lpWaveHdr);
|
|
|
|
static void wodHelper_NotifyCompletions(WINE_WAVEOUT_INSTANCE* wwo, BOOL force);
|
2006-12-28 18:06:43 +01:00
|
|
|
static void widHelper_NotifyCompletions(WINE_WAVEIN* wwi);
|
2006-05-28 22:46:23 +02:00
|
|
|
|
|
|
|
extern int AudioUnit_CreateDefaultAudioUnit(void *wwo, AudioUnit *au);
|
|
|
|
extern int AudioUnit_CloseAudioUnit(AudioUnit au);
|
2006-05-31 14:52:58 +02:00
|
|
|
extern int AudioUnit_InitializeWithStreamDescription(AudioUnit au, AudioStreamBasicDescription *streamFormat);
|
2006-05-28 22:46:23 +02:00
|
|
|
|
|
|
|
extern OSStatus AudioOutputUnitStart(AudioUnit au);
|
|
|
|
extern OSStatus AudioOutputUnitStop(AudioUnit au);
|
|
|
|
extern OSStatus AudioUnitUninitialize(AudioUnit au);
|
|
|
|
|
|
|
|
extern int AudioUnit_SetVolume(AudioUnit au, float left, float right);
|
|
|
|
extern int AudioUnit_GetVolume(AudioUnit au, float *left, float *right);
|
|
|
|
|
2006-12-28 18:07:24 +01:00
|
|
|
extern int AudioUnit_GetInputDeviceSampleRate(void);
|
|
|
|
|
2006-12-28 18:05:31 +01:00
|
|
|
extern int AudioUnit_CreateInputUnit(void* wwi, AudioUnit* out_au,
|
2006-12-28 18:06:23 +01:00
|
|
|
WORD nChannels, DWORD nSamplesPerSec, WORD wBitsPerSample,
|
|
|
|
UInt32* outFrameCount);
|
2006-12-28 18:05:31 +01:00
|
|
|
|
2006-05-28 22:46:23 +02:00
|
|
|
OSStatus CoreAudio_woAudioUnitIOProc(void *inRefCon,
|
|
|
|
AudioUnitRenderActionFlags *ioActionFlags,
|
|
|
|
const AudioTimeStamp *inTimeStamp,
|
|
|
|
UInt32 inBusNumber,
|
|
|
|
UInt32 inNumberFrames,
|
|
|
|
AudioBufferList *ioData);
|
2006-12-28 18:05:15 +01:00
|
|
|
OSStatus CoreAudio_wiAudioUnitIOProc(void *inRefCon,
|
|
|
|
AudioUnitRenderActionFlags *ioActionFlags,
|
|
|
|
const AudioTimeStamp *inTimeStamp,
|
|
|
|
UInt32 inBusNumber,
|
|
|
|
UInt32 inNumberFrames,
|
|
|
|
AudioBufferList *ioData);
|
2006-05-28 22:46:23 +02:00
|
|
|
|
|
|
|
/* These strings used only for tracing */
|
|
|
|
|
|
|
|
static const char * getMessage(UINT msg)
|
|
|
|
{
|
|
|
|
static char unknown[32];
|
|
|
|
#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
|
|
|
|
sprintf(unknown, "UNKNOWN(0x%04x)", msg);
|
|
|
|
return unknown;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define kStopLoopMessage 0
|
2006-12-21 10:49:43 +01:00
|
|
|
#define kWaveOutNotifyCompletionsMessage 1
|
2006-12-28 18:06:51 +01:00
|
|
|
#define kWaveInNotifyCompletionsMessage 2
|
2006-05-28 22:46:23 +02:00
|
|
|
|
|
|
|
/* Mach Message Handling */
|
2006-12-21 10:47:05 +01:00
|
|
|
static CFDataRef wodMessageHandler(CFMessagePortRef port_ReceiveInMessageThread, SInt32 msgid, CFDataRef data, void *info)
|
2006-05-28 22:46:23 +02:00
|
|
|
{
|
|
|
|
UInt32 *buffer = NULL;
|
2006-12-21 10:49:43 +01:00
|
|
|
|
2006-05-28 22:46:23 +02:00
|
|
|
switch (msgid)
|
|
|
|
{
|
2006-12-21 10:49:43 +01:00
|
|
|
case kWaveOutNotifyCompletionsMessage:
|
2009-10-11 21:12:48 +02:00
|
|
|
wodHelper_NotifyCompletions(*(WINE_WAVEOUT_INSTANCE**)CFDataGetBytePtr(data), FALSE);
|
2006-05-28 22:46:23 +02:00
|
|
|
break;
|
2006-12-28 18:06:51 +01:00
|
|
|
case kWaveInNotifyCompletionsMessage:
|
|
|
|
buffer = (UInt32 *) CFDataGetBytePtr(data);
|
|
|
|
widHelper_NotifyCompletions(&WInDev[buffer[0]]);
|
|
|
|
break;
|
2006-05-28 22:46:23 +02:00
|
|
|
default:
|
|
|
|
CFRunLoopStop(CFRunLoopGetCurrent());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-05-31 14:52:58 +02:00
|
|
|
static DWORD WINAPI messageThread(LPVOID p)
|
2006-05-28 22:46:23 +02:00
|
|
|
{
|
2006-12-21 10:47:05 +01:00
|
|
|
CFMessagePortRef port_ReceiveInMessageThread = (CFMessagePortRef) p;
|
2006-05-28 22:46:23 +02:00
|
|
|
CFRunLoopSourceRef source;
|
|
|
|
|
2006-12-21 10:47:05 +01:00
|
|
|
source = CFMessagePortCreateRunLoopSource(kCFAllocatorDefault, port_ReceiveInMessageThread, (CFIndex)0);
|
2006-05-28 22:46:23 +02:00
|
|
|
CFRunLoopAddSource(CFRunLoopGetCurrent(), source, kCFRunLoopDefaultMode);
|
2007-01-01 11:22:58 +01:00
|
|
|
|
2006-05-28 22:46:23 +02:00
|
|
|
CFRunLoopRun();
|
2006-05-24 12:28:18 +02:00
|
|
|
|
|
|
|
CFRunLoopSourceInvalidate(source);
|
|
|
|
CFRelease(source);
|
2006-12-21 10:47:05 +01:00
|
|
|
CFRelease(port_ReceiveInMessageThread);
|
2006-05-24 12:28:18 +02:00
|
|
|
|
2006-05-28 22:46:23 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-12-21 10:49:43 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* wodSendNotifyCompletionsMessage [internal]
|
|
|
|
* Call from AudioUnit IO thread can't use Wine debug channels.
|
|
|
|
*/
|
2009-10-11 21:12:01 +02:00
|
|
|
static void wodSendNotifyCompletionsMessage(WINE_WAVEOUT_INSTANCE* wwo)
|
2006-05-28 22:46:23 +02:00
|
|
|
{
|
|
|
|
CFDataRef data;
|
2006-12-21 10:49:43 +01:00
|
|
|
|
2008-07-10 04:28:56 +02:00
|
|
|
if (!Port_SendToMessageThread)
|
|
|
|
return;
|
|
|
|
|
2009-10-11 21:12:48 +02:00
|
|
|
data = CFDataCreate(kCFAllocatorDefault, (UInt8 *)&wwo, sizeof(wwo));
|
2006-05-28 22:46:23 +02:00
|
|
|
if (!data)
|
2006-12-21 10:49:43 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
CFMessagePortSendRequest(Port_SendToMessageThread, kWaveOutNotifyCompletionsMessage, data, 0.0, 0.0, NULL, NULL);
|
2006-05-28 22:46:23 +02:00
|
|
|
CFRelease(data);
|
|
|
|
}
|
|
|
|
|
2006-12-28 18:06:51 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* wodSendNotifyInputCompletionsMessage [internal]
|
|
|
|
* Call from AudioUnit IO thread can't use Wine debug channels.
|
|
|
|
*/
|
|
|
|
static void wodSendNotifyInputCompletionsMessage(WINE_WAVEIN* wwi)
|
|
|
|
{
|
|
|
|
CFDataRef data;
|
|
|
|
UInt32 buffer;
|
|
|
|
|
2008-07-10 04:28:56 +02:00
|
|
|
if (!Port_SendToMessageThread)
|
|
|
|
return;
|
|
|
|
|
2006-12-28 18:06:51 +01:00
|
|
|
buffer = (UInt32) wwi->wiID;
|
|
|
|
|
|
|
|
data = CFDataCreate(kCFAllocatorDefault, (UInt8 *)&buffer, sizeof(buffer));
|
|
|
|
if (!data)
|
|
|
|
return;
|
|
|
|
|
|
|
|
CFMessagePortSendRequest(Port_SendToMessageThread, kWaveInNotifyCompletionsMessage, data, 0.0, 0.0, NULL, NULL);
|
|
|
|
CFRelease(data);
|
|
|
|
}
|
|
|
|
|
2006-05-28 22:46:23 +02:00
|
|
|
static DWORD bytes_to_mmtime(LPMMTIME lpTime, DWORD position,
|
|
|
|
PCMWAVEFORMAT* format)
|
|
|
|
{
|
2006-10-20 12:36:38 +02:00
|
|
|
TRACE("wType=%04X wBitsPerSample=%u nSamplesPerSec=%u nChannels=%u nAvgBytesPerSec=%u\n",
|
2006-05-28 22:46:23 +02:00
|
|
|
lpTime->wType, format->wBitsPerSample, format->wf.nSamplesPerSec,
|
|
|
|
format->wf.nChannels, format->wf.nAvgBytesPerSec);
|
2006-10-20 12:36:38 +02:00
|
|
|
TRACE("Position in bytes=%u\n", position);
|
2006-05-28 22:46:23 +02:00
|
|
|
|
|
|
|
switch (lpTime->wType) {
|
|
|
|
case TIME_SAMPLES:
|
|
|
|
lpTime->u.sample = position / (format->wBitsPerSample / 8 * format->wf.nChannels);
|
2006-10-20 12:36:38 +02:00
|
|
|
TRACE("TIME_SAMPLES=%u\n", lpTime->u.sample);
|
2006-05-28 22:46:23 +02:00
|
|
|
break;
|
|
|
|
case TIME_MS:
|
|
|
|
lpTime->u.ms = 1000.0 * position / (format->wBitsPerSample / 8 * format->wf.nChannels * format->wf.nSamplesPerSec);
|
2006-10-20 12:36:38 +02:00
|
|
|
TRACE("TIME_MS=%u\n", lpTime->u.ms);
|
2006-05-28 22:46:23 +02:00
|
|
|
break;
|
|
|
|
case TIME_SMPTE:
|
|
|
|
lpTime->u.smpte.fps = 30;
|
|
|
|
position = position / (format->wBitsPerSample / 8 * format->wf.nChannels);
|
|
|
|
position += (format->wf.nSamplesPerSec / lpTime->u.smpte.fps) - 1; /* round up */
|
|
|
|
lpTime->u.smpte.sec = position / format->wf.nSamplesPerSec;
|
|
|
|
position -= lpTime->u.smpte.sec * format->wf.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->wf.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;
|
2006-10-20 12:36:38 +02:00
|
|
|
TRACE("TIME_BYTES=%u\n", lpTime->u.cb);
|
2006-05-28 22:46:23 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return MMSYSERR_NOERROR;
|
|
|
|
}
|
|
|
|
|
2009-09-11 07:43:45 +02:00
|
|
|
static BOOL supportedFormat(LPWAVEFORMATEX wf)
|
|
|
|
{
|
|
|
|
if (wf->nSamplesPerSec == 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (wf->wFormatTag == WAVE_FORMAT_PCM) {
|
|
|
|
if (wf->nChannels >= 1 && wf->nChannels <= 2) {
|
|
|
|
if (wf->wBitsPerSample==8||wf->wBitsPerSample==16)
|
|
|
|
return TRUE;
|
|
|
|
}
|
2009-09-11 08:12:53 +02:00
|
|
|
} else if (wf->wFormatTag == WAVE_FORMAT_EXTENSIBLE) {
|
|
|
|
WAVEFORMATEXTENSIBLE * wfex = (WAVEFORMATEXTENSIBLE *)wf;
|
|
|
|
|
|
|
|
if (wf->cbSize == 22 && IsEqualGUID(&wfex->SubFormat, &KSDATAFORMAT_SUBTYPE_PCM)) {
|
2009-10-05 10:34:24 +02:00
|
|
|
if (wf->nChannels >=1 && wf->nChannels <= 8) {
|
2009-09-11 08:12:53 +02:00
|
|
|
if (wf->wBitsPerSample==wfex->Samples.wValidBitsPerSample) {
|
|
|
|
if (wf->wBitsPerSample==8||wf->wBitsPerSample==16)
|
|
|
|
return TRUE;
|
|
|
|
} else
|
|
|
|
WARN("wBitsPerSample != wValidBitsPerSample not supported yet\n");
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
WARN("only KSDATAFORMAT_SUBTYPE_PCM supported\n");
|
2009-09-11 07:43:45 +02:00
|
|
|
} else
|
|
|
|
WARN("only WAVE_FORMAT_PCM supported\n");
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-09-11 08:12:53 +02:00
|
|
|
void copyFormat(LPWAVEFORMATEX wf1, LPPCMWAVEFORMAT wf2)
|
|
|
|
{
|
|
|
|
memcpy(wf2, wf1, sizeof(PCMWAVEFORMAT));
|
|
|
|
/* Downgrade WAVE_FORMAT_EXTENSIBLE KSDATAFORMAT_SUBTYPE_PCM
|
|
|
|
* to smaller yet compatible WAVE_FORMAT_PCM structure */
|
|
|
|
if (wf2->wf.wFormatTag == WAVE_FORMAT_EXTENSIBLE)
|
|
|
|
wf2->wf.wFormatTag = WAVE_FORMAT_PCM;
|
|
|
|
}
|
|
|
|
|
2006-05-28 22:46:23 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* CoreAudio_GetDevCaps [internal]
|
|
|
|
*/
|
|
|
|
BOOL CoreAudio_GetDevCaps (void)
|
|
|
|
{
|
|
|
|
OSStatus status;
|
|
|
|
UInt32 propertySize;
|
|
|
|
AudioDeviceID devId = CoreAudio_DefaultDevice.outputDeviceID;
|
|
|
|
|
|
|
|
char name[MAXPNAMELEN];
|
|
|
|
|
|
|
|
propertySize = MAXPNAMELEN;
|
|
|
|
status = AudioDeviceGetProperty(devId, 0 , FALSE, kAudioDevicePropertyDeviceName, &propertySize, name);
|
|
|
|
if (status) {
|
2009-10-11 21:11:19 +02:00
|
|
|
ERR("AudioHardwareGetProperty for kAudioDevicePropertyDeviceName return %s\n", wine_dbgstr_fourcc(status));
|
2006-05-28 22:46:23 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(CoreAudio_DefaultDevice.ds_desc.szDesc, name, sizeof(name));
|
|
|
|
strcpy(CoreAudio_DefaultDevice.ds_desc.szDrvname, "winecoreaudio.drv");
|
2009-01-02 13:13:47 +01:00
|
|
|
MultiByteToWideChar(CP_UNIXCP, 0, name, sizeof(name),
|
2006-05-28 22:46:23 +02:00
|
|
|
CoreAudio_DefaultDevice.out_caps.szPname,
|
|
|
|
sizeof(CoreAudio_DefaultDevice.out_caps.szPname) / sizeof(WCHAR));
|
|
|
|
memcpy(CoreAudio_DefaultDevice.dev_name, name, 32);
|
|
|
|
|
|
|
|
propertySize = sizeof(CoreAudio_DefaultDevice.streamDescription);
|
|
|
|
status = AudioDeviceGetProperty(devId, 0, FALSE , kAudioDevicePropertyStreamFormat, &propertySize, &CoreAudio_DefaultDevice.streamDescription);
|
|
|
|
if (status != noErr) {
|
2009-10-11 21:11:19 +02:00
|
|
|
ERR("AudioHardwareGetProperty for kAudioDevicePropertyStreamFormat return %s\n", wine_dbgstr_fourcc(status));
|
2006-05-28 22:46:23 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-10-11 21:11:19 +02:00
|
|
|
TRACE("Device Stream Description mSampleRate : %f\n mFormatID : %s\n"
|
2006-05-31 14:52:58 +02:00
|
|
|
"mFormatFlags : %lX\n mBytesPerPacket : %lu\n mFramesPerPacket : %lu\n"
|
|
|
|
"mBytesPerFrame : %lu\n mChannelsPerFrame : %lu\n mBitsPerChannel : %lu\n",
|
2006-05-28 22:46:23 +02:00
|
|
|
CoreAudio_DefaultDevice.streamDescription.mSampleRate,
|
2009-10-11 21:11:19 +02:00
|
|
|
wine_dbgstr_fourcc(CoreAudio_DefaultDevice.streamDescription.mFormatID),
|
2006-05-28 22:46:23 +02:00
|
|
|
CoreAudio_DefaultDevice.streamDescription.mFormatFlags,
|
|
|
|
CoreAudio_DefaultDevice.streamDescription.mBytesPerPacket,
|
|
|
|
CoreAudio_DefaultDevice.streamDescription.mFramesPerPacket,
|
|
|
|
CoreAudio_DefaultDevice.streamDescription.mBytesPerFrame,
|
|
|
|
CoreAudio_DefaultDevice.streamDescription.mChannelsPerFrame,
|
|
|
|
CoreAudio_DefaultDevice.streamDescription.mBitsPerChannel);
|
|
|
|
|
|
|
|
CoreAudio_DefaultDevice.out_caps.wMid = 0xcafe;
|
|
|
|
CoreAudio_DefaultDevice.out_caps.wPid = 0x0001;
|
|
|
|
|
|
|
|
CoreAudio_DefaultDevice.out_caps.vDriverVersion = 0x0001;
|
|
|
|
CoreAudio_DefaultDevice.out_caps.dwFormats = 0x00000000;
|
|
|
|
CoreAudio_DefaultDevice.out_caps.wReserved1 = 0;
|
|
|
|
CoreAudio_DefaultDevice.out_caps.dwSupport = WAVECAPS_VOLUME;
|
|
|
|
CoreAudio_DefaultDevice.out_caps.dwSupport |= WAVECAPS_LRVOLUME;
|
|
|
|
|
|
|
|
CoreAudio_DefaultDevice.out_caps.wChannels = 2;
|
|
|
|
CoreAudio_DefaultDevice.out_caps.dwFormats|= WAVE_FORMAT_4S16;
|
2009-10-11 21:11:37 +02:00
|
|
|
|
|
|
|
TRACE_(coreaudio)("out dwFormats = %08x, dwSupport = %08x\n",
|
|
|
|
CoreAudio_DefaultDevice.out_caps.dwFormats, CoreAudio_DefaultDevice.out_caps.dwSupport);
|
2006-05-28 22:46:23 +02:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* CoreAudio_WaveInit
|
|
|
|
*
|
|
|
|
* Initialize CoreAudio_DefaultDevice
|
|
|
|
*/
|
|
|
|
LONG CoreAudio_WaveInit(void)
|
|
|
|
{
|
|
|
|
OSStatus status;
|
|
|
|
UInt32 propertySize;
|
|
|
|
int i;
|
2006-12-21 10:47:05 +01:00
|
|
|
CFStringRef messageThreadPortName;
|
|
|
|
CFMessagePortRef port_ReceiveInMessageThread;
|
2006-12-28 18:07:24 +01:00
|
|
|
int inputSampleRate;
|
2006-05-28 22:46:23 +02:00
|
|
|
|
|
|
|
TRACE("()\n");
|
|
|
|
|
|
|
|
/* number of sound cards */
|
|
|
|
AudioHardwareGetPropertyInfo(kAudioHardwarePropertyDevices, &propertySize, NULL);
|
|
|
|
propertySize /= sizeof(AudioDeviceID);
|
2006-05-31 14:52:58 +02:00
|
|
|
TRACE("sound cards : %lu\n", propertySize);
|
2006-05-28 22:46:23 +02:00
|
|
|
|
|
|
|
/* Get the output device */
|
|
|
|
propertySize = sizeof(CoreAudio_DefaultDevice.outputDeviceID);
|
|
|
|
status = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultOutputDevice, &propertySize, &CoreAudio_DefaultDevice.outputDeviceID);
|
|
|
|
if (status) {
|
2009-10-11 21:11:19 +02:00
|
|
|
ERR("AudioHardwareGetProperty return %s for kAudioHardwarePropertyDefaultOutputDevice\n", wine_dbgstr_fourcc(status));
|
2008-03-12 08:06:17 +01:00
|
|
|
return DRV_FAILURE;
|
2006-05-28 22:46:23 +02:00
|
|
|
}
|
|
|
|
if (CoreAudio_DefaultDevice.outputDeviceID == kAudioDeviceUnknown) {
|
|
|
|
ERR("AudioHardwareGetProperty: CoreAudio_DefaultDevice.outputDeviceID == kAudioDeviceUnknown\n");
|
2008-03-12 08:06:17 +01:00
|
|
|
return DRV_FAILURE;
|
2006-05-28 22:46:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! CoreAudio_GetDevCaps() )
|
2008-03-12 08:06:17 +01:00
|
|
|
return DRV_FAILURE;
|
2006-05-28 22:46:23 +02:00
|
|
|
|
|
|
|
CoreAudio_DefaultDevice.interface_name=HeapAlloc(GetProcessHeap(),0,strlen(CoreAudio_DefaultDevice.dev_name)+1);
|
2009-01-02 13:13:47 +01:00
|
|
|
strcpy(CoreAudio_DefaultDevice.interface_name, CoreAudio_DefaultDevice.dev_name);
|
2006-05-28 22:46:23 +02:00
|
|
|
|
|
|
|
for (i = 0; i < MAX_WAVEOUTDRV; ++i)
|
|
|
|
{
|
2009-01-02 13:13:47 +01:00
|
|
|
static const WCHAR wszWaveOutFormat[] =
|
2009-02-24 00:34:07 +01:00
|
|
|
{'C','o','r','e','A','u','d','i','o',' ','W','a','v','e','O','u','t',' ','%','d',0};
|
2009-01-02 13:13:47 +01:00
|
|
|
|
2009-10-11 21:13:23 +02:00
|
|
|
list_init(&WOutDev[i].instances);
|
2006-05-28 22:46:23 +02:00
|
|
|
WOutDev[i].cadev = &CoreAudio_DefaultDevice;
|
|
|
|
|
|
|
|
memset(&WOutDev[i].caps, 0, sizeof(WOutDev[i].caps));
|
|
|
|
|
|
|
|
WOutDev[i].caps.wMid = 0xcafe; /* Manufac ID */
|
|
|
|
WOutDev[i].caps.wPid = 0x0001; /* Product ID */
|
2009-01-02 13:13:47 +01:00
|
|
|
snprintfW(WOutDev[i].caps.szPname, sizeof(WOutDev[i].caps.szPname)/sizeof(WCHAR), wszWaveOutFormat, i);
|
2006-05-28 22:46:23 +02:00
|
|
|
snprintf(WOutDev[i].interface_name, sizeof(WOutDev[i].interface_name), "winecoreaudio: %d", i);
|
|
|
|
|
|
|
|
WOutDev[i].caps.vDriverVersion = 0x0001;
|
|
|
|
WOutDev[i].caps.dwFormats = 0x00000000;
|
|
|
|
WOutDev[i].caps.dwSupport = WAVECAPS_VOLUME;
|
|
|
|
|
|
|
|
WOutDev[i].caps.wChannels = 2;
|
|
|
|
/* WOutDev[i].caps.dwSupport |= WAVECAPS_LRVOLUME; */ /* FIXME */
|
|
|
|
|
2006-12-28 18:07:24 +01:00
|
|
|
WOutDev[i].caps.dwFormats |= WAVE_FORMAT_96M08;
|
|
|
|
WOutDev[i].caps.dwFormats |= WAVE_FORMAT_96S08;
|
|
|
|
WOutDev[i].caps.dwFormats |= WAVE_FORMAT_96M16;
|
|
|
|
WOutDev[i].caps.dwFormats |= WAVE_FORMAT_96S16;
|
|
|
|
WOutDev[i].caps.dwFormats |= WAVE_FORMAT_48M08;
|
|
|
|
WOutDev[i].caps.dwFormats |= WAVE_FORMAT_48S08;
|
|
|
|
WOutDev[i].caps.dwFormats |= WAVE_FORMAT_48M16;
|
|
|
|
WOutDev[i].caps.dwFormats |= WAVE_FORMAT_48S16;
|
2006-05-28 22:46:23 +02:00
|
|
|
WOutDev[i].caps.dwFormats |= WAVE_FORMAT_4M08;
|
|
|
|
WOutDev[i].caps.dwFormats |= WAVE_FORMAT_4S08;
|
|
|
|
WOutDev[i].caps.dwFormats |= WAVE_FORMAT_4S16;
|
|
|
|
WOutDev[i].caps.dwFormats |= WAVE_FORMAT_4M16;
|
|
|
|
WOutDev[i].caps.dwFormats |= WAVE_FORMAT_2M08;
|
|
|
|
WOutDev[i].caps.dwFormats |= WAVE_FORMAT_2S08;
|
|
|
|
WOutDev[i].caps.dwFormats |= WAVE_FORMAT_2M16;
|
|
|
|
WOutDev[i].caps.dwFormats |= WAVE_FORMAT_2S16;
|
|
|
|
WOutDev[i].caps.dwFormats |= WAVE_FORMAT_1M08;
|
|
|
|
WOutDev[i].caps.dwFormats |= WAVE_FORMAT_1S08;
|
|
|
|
WOutDev[i].caps.dwFormats |= WAVE_FORMAT_1M16;
|
|
|
|
WOutDev[i].caps.dwFormats |= WAVE_FORMAT_1S16;
|
2006-05-24 12:27:24 +02:00
|
|
|
|
2009-10-23 02:36:24 +02:00
|
|
|
WOutDev[i].device_volume = 0xffffffff;
|
|
|
|
|
2009-10-11 21:13:23 +02:00
|
|
|
WOutDev[i].lock = 0; /* initialize the mutex */
|
2006-05-28 22:46:23 +02:00
|
|
|
}
|
2006-12-28 18:03:50 +01:00
|
|
|
|
2006-12-28 18:07:24 +01:00
|
|
|
/* FIXME: implement sample rate conversion on input */
|
|
|
|
inputSampleRate = AudioUnit_GetInputDeviceSampleRate();
|
|
|
|
|
2006-12-28 18:03:50 +01:00
|
|
|
for (i = 0; i < MAX_WAVEINDRV; ++i)
|
|
|
|
{
|
2009-01-02 13:13:47 +01:00
|
|
|
static const WCHAR wszWaveInFormat[] =
|
|
|
|
{'C','o','r','e','A','u','d','i','o',' ','W','a','v','e','I','n',' ','%','d',0};
|
|
|
|
|
2006-12-28 18:03:50 +01:00
|
|
|
memset(&WInDev[i], 0, sizeof(WInDev[i]));
|
2006-12-28 18:06:35 +01:00
|
|
|
WInDev[i].wiID = i;
|
2006-12-28 18:03:50 +01:00
|
|
|
|
|
|
|
/* Establish preconditions for widOpen */
|
|
|
|
WInDev[i].state = WINE_WS_CLOSED;
|
|
|
|
WInDev[i].lock = 0; /* initialize the mutex */
|
|
|
|
|
|
|
|
/* Fill in capabilities. widGetDevCaps can be called at any time. */
|
|
|
|
WInDev[i].caps.wMid = 0xcafe; /* Manufac ID */
|
|
|
|
WInDev[i].caps.wPid = 0x0001; /* Product ID */
|
|
|
|
WInDev[i].caps.vDriverVersion = 0x0001;
|
|
|
|
|
2009-01-02 13:13:47 +01:00
|
|
|
snprintfW(WInDev[i].caps.szPname, sizeof(WInDev[i].caps.szPname)/sizeof(WCHAR), wszWaveInFormat, i);
|
2006-12-28 18:06:16 +01:00
|
|
|
snprintf(WInDev[i].interface_name, sizeof(WInDev[i].interface_name), "winecoreaudio in: %d", i);
|
2006-12-28 18:03:50 +01:00
|
|
|
|
2006-12-28 18:07:24 +01:00
|
|
|
if (inputSampleRate == 96000)
|
|
|
|
{
|
|
|
|
WInDev[i].caps.dwFormats |= WAVE_FORMAT_96M08;
|
|
|
|
WInDev[i].caps.dwFormats |= WAVE_FORMAT_96S08;
|
|
|
|
WInDev[i].caps.dwFormats |= WAVE_FORMAT_96M16;
|
|
|
|
WInDev[i].caps.dwFormats |= WAVE_FORMAT_96S16;
|
|
|
|
}
|
|
|
|
if (inputSampleRate == 48000)
|
|
|
|
{
|
|
|
|
WInDev[i].caps.dwFormats |= WAVE_FORMAT_48M08;
|
|
|
|
WInDev[i].caps.dwFormats |= WAVE_FORMAT_48S08;
|
|
|
|
WInDev[i].caps.dwFormats |= WAVE_FORMAT_48M16;
|
|
|
|
WInDev[i].caps.dwFormats |= WAVE_FORMAT_48S16;
|
|
|
|
}
|
|
|
|
if (inputSampleRate == 44100)
|
|
|
|
{
|
|
|
|
WInDev[i].caps.dwFormats |= WAVE_FORMAT_4M08;
|
|
|
|
WInDev[i].caps.dwFormats |= WAVE_FORMAT_4S08;
|
|
|
|
WInDev[i].caps.dwFormats |= WAVE_FORMAT_4M16;
|
|
|
|
WInDev[i].caps.dwFormats |= WAVE_FORMAT_4S16;
|
|
|
|
}
|
|
|
|
if (inputSampleRate == 22050)
|
|
|
|
{
|
|
|
|
WInDev[i].caps.dwFormats |= WAVE_FORMAT_2M08;
|
|
|
|
WInDev[i].caps.dwFormats |= WAVE_FORMAT_2S08;
|
|
|
|
WInDev[i].caps.dwFormats |= WAVE_FORMAT_2M16;
|
|
|
|
WInDev[i].caps.dwFormats |= WAVE_FORMAT_2S16;
|
|
|
|
}
|
|
|
|
if (inputSampleRate == 11025)
|
|
|
|
{
|
|
|
|
WInDev[i].caps.dwFormats |= WAVE_FORMAT_1M08;
|
|
|
|
WInDev[i].caps.dwFormats |= WAVE_FORMAT_1S08;
|
|
|
|
WInDev[i].caps.dwFormats |= WAVE_FORMAT_1M16;
|
|
|
|
WInDev[i].caps.dwFormats |= WAVE_FORMAT_1S16;
|
|
|
|
}
|
2006-12-28 18:03:50 +01:00
|
|
|
|
|
|
|
WInDev[i].caps.wChannels = 2;
|
|
|
|
}
|
|
|
|
|
2006-05-28 22:46:23 +02:00
|
|
|
/* create mach messages handler */
|
2006-05-24 12:43:14 +02:00
|
|
|
srandomdev();
|
2006-12-21 10:47:05 +01:00
|
|
|
messageThreadPortName = CFStringCreateWithFormat(kCFAllocatorDefault, NULL,
|
2006-05-24 12:43:14 +02:00
|
|
|
CFSTR("WaveMessagePort.%d.%lu"), getpid(), (unsigned long)random());
|
2006-12-21 10:47:05 +01:00
|
|
|
if (!messageThreadPortName)
|
2006-05-24 12:43:14 +02:00
|
|
|
{
|
|
|
|
ERR("Can't create message thread port name\n");
|
2008-03-12 08:06:17 +01:00
|
|
|
return DRV_FAILURE;
|
2006-05-24 12:43:14 +02:00
|
|
|
}
|
|
|
|
|
2006-12-21 10:47:05 +01:00
|
|
|
port_ReceiveInMessageThread = CFMessagePortCreateLocal(kCFAllocatorDefault, messageThreadPortName,
|
|
|
|
&wodMessageHandler, NULL, NULL);
|
|
|
|
if (!port_ReceiveInMessageThread)
|
|
|
|
{
|
|
|
|
ERR("Can't create message thread local port\n");
|
|
|
|
CFRelease(messageThreadPortName);
|
2008-03-12 08:06:17 +01:00
|
|
|
return DRV_FAILURE;
|
2006-12-21 10:47:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Port_SendToMessageThread = CFMessagePortCreateRemote(kCFAllocatorDefault, messageThreadPortName);
|
|
|
|
CFRelease(messageThreadPortName);
|
|
|
|
if (!Port_SendToMessageThread)
|
|
|
|
{
|
|
|
|
ERR("Can't create port for sending to message thread\n");
|
|
|
|
CFRelease(port_ReceiveInMessageThread);
|
2008-03-12 08:06:17 +01:00
|
|
|
return DRV_FAILURE;
|
2006-12-21 10:47:05 +01:00
|
|
|
}
|
|
|
|
|
2007-01-01 11:22:58 +01:00
|
|
|
/* Cannot WAIT for any events because we are called from the loader (which has a lock on loading stuff) */
|
|
|
|
/* We might want to wait for this thread to be created -- but we cannot -- not here at least */
|
|
|
|
/* Instead track the thread so we can clean it up later */
|
|
|
|
if ( hThread )
|
|
|
|
{
|
|
|
|
ERR("Message thread already started -- expect problems\n");
|
|
|
|
}
|
2006-12-21 10:47:05 +01:00
|
|
|
hThread = CreateThread(NULL, 0, messageThread, (LPVOID)port_ReceiveInMessageThread, 0, NULL);
|
2006-05-28 22:46:23 +02:00
|
|
|
if ( !hThread )
|
|
|
|
{
|
|
|
|
ERR("Can't create message thread\n");
|
2006-12-21 10:47:05 +01:00
|
|
|
CFRelease(port_ReceiveInMessageThread);
|
|
|
|
CFRelease(Port_SendToMessageThread);
|
|
|
|
Port_SendToMessageThread = NULL;
|
2008-03-12 08:06:17 +01:00
|
|
|
return DRV_FAILURE;
|
2006-05-28 22:46:23 +02:00
|
|
|
}
|
2006-12-21 10:47:05 +01:00
|
|
|
|
|
|
|
/* The message thread is responsible for releasing port_ReceiveInMessageThread. */
|
|
|
|
|
2008-03-12 08:06:17 +01:00
|
|
|
return DRV_SUCCESS;
|
2006-05-28 22:46:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CoreAudio_WaveRelease(void)
|
|
|
|
{
|
|
|
|
/* Stop CFRunLoop in messageThread */
|
2006-05-31 14:52:58 +02:00
|
|
|
TRACE("()\n");
|
|
|
|
|
2008-07-10 04:28:56 +02:00
|
|
|
if (!Port_SendToMessageThread)
|
|
|
|
return;
|
|
|
|
|
2006-12-21 10:47:05 +01:00
|
|
|
CFMessagePortSendRequest(Port_SendToMessageThread, kStopLoopMessage, NULL, 0.0, 0.0, NULL, NULL);
|
|
|
|
CFRelease(Port_SendToMessageThread);
|
|
|
|
Port_SendToMessageThread = NULL;
|
2007-01-01 11:22:58 +01:00
|
|
|
|
|
|
|
/* Wait for the thread to finish and clean it up */
|
|
|
|
/* This rids us of any quick start/shutdown driver crashes */
|
|
|
|
WaitForSingleObject(hThread, INFINITE);
|
|
|
|
CloseHandle(hThread);
|
|
|
|
hThread = NULL;
|
2006-05-28 22:46:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*======================================================================*
|
|
|
|
* Low level WAVE OUT implementation *
|
|
|
|
*======================================================================*/
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* wodNotifyClient [internal]
|
|
|
|
*/
|
2009-10-11 21:12:01 +02:00
|
|
|
static DWORD wodNotifyClient(WINE_WAVEOUT_INSTANCE* wwo, WORD wMsg, DWORD dwParam1, DWORD dwParam2)
|
2006-05-28 22:46:23 +02:00
|
|
|
{
|
2009-10-11 21:11:37 +02:00
|
|
|
TRACE_(coreaudio)("wMsg = 0x%04x dwParm1 = %04x dwParam2 = %04x\n", wMsg, dwParam1, dwParam2);
|
|
|
|
|
2006-05-28 22:46:23 +02:00
|
|
|
switch (wMsg) {
|
|
|
|
case WOM_OPEN:
|
|
|
|
case WOM_CLOSE:
|
2006-12-21 10:49:43 +01:00
|
|
|
case WOM_DONE:
|
2006-05-28 22:46:23 +02:00
|
|
|
if (wwo->wFlags != DCB_NULL &&
|
|
|
|
!DriverCallback(wwo->waveDesc.dwCallback, wwo->wFlags,
|
|
|
|
(HDRVR)wwo->waveDesc.hWave, wMsg, wwo->waveDesc.dwInstance,
|
|
|
|
dwParam1, dwParam2))
|
|
|
|
{
|
2009-10-11 21:11:37 +02:00
|
|
|
ERR("can't notify client !\n");
|
2006-05-28 22:46:23 +02:00
|
|
|
return MMSYSERR_ERROR;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2009-10-11 21:11:37 +02:00
|
|
|
ERR("Unknown callback message %u\n", wMsg);
|
2006-05-28 22:46:23 +02:00
|
|
|
return MMSYSERR_INVALPARAM;
|
|
|
|
}
|
|
|
|
return MMSYSERR_NOERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* wodGetDevCaps [internal]
|
|
|
|
*/
|
|
|
|
static DWORD wodGetDevCaps(WORD wDevID, LPWAVEOUTCAPSW lpCaps, DWORD dwSize)
|
|
|
|
{
|
2006-10-20 12:36:38 +02:00
|
|
|
TRACE("(%u, %p, %u);\n", wDevID, lpCaps, dwSize);
|
2006-05-28 22:46:23 +02:00
|
|
|
|
|
|
|
if (lpCaps == NULL) return MMSYSERR_NOTENABLED;
|
|
|
|
|
|
|
|
if (wDevID >= MAX_WAVEOUTDRV)
|
|
|
|
{
|
|
|
|
TRACE("MAX_WAVOUTDRV reached !\n");
|
|
|
|
return MMSYSERR_BADDEVICEID;
|
|
|
|
}
|
|
|
|
|
2006-10-20 12:36:38 +02:00
|
|
|
TRACE("dwSupport=(0x%x), dwFormats=(0x%x)\n", WOutDev[wDevID].caps.dwSupport, WOutDev[wDevID].caps.dwFormats);
|
2006-05-28 22:46:23 +02:00
|
|
|
memcpy(lpCaps, &WOutDev[wDevID].caps, min(dwSize, sizeof(*lpCaps)));
|
|
|
|
return MMSYSERR_NOERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* wodOpen [internal]
|
|
|
|
*/
|
2009-10-11 21:12:48 +02:00
|
|
|
static DWORD wodOpen(WORD wDevID, WINE_WAVEOUT_INSTANCE** pInstance, LPWAVEOPENDESC lpDesc, DWORD dwFlags)
|
2006-05-28 22:46:23 +02:00
|
|
|
{
|
2009-10-11 21:12:01 +02:00
|
|
|
WINE_WAVEOUT_INSTANCE* wwo;
|
2006-05-28 22:46:23 +02:00
|
|
|
DWORD ret;
|
2006-05-31 14:52:58 +02:00
|
|
|
AudioStreamBasicDescription streamFormat;
|
2009-04-11 14:18:18 +02:00
|
|
|
AudioUnit audioUnit = NULL;
|
|
|
|
BOOL auInited = FALSE;
|
2006-05-31 14:52:58 +02:00
|
|
|
|
2009-10-11 21:12:48 +02:00
|
|
|
TRACE("(%u, %p, %p, %08x);\n", wDevID, pInstance, lpDesc, dwFlags);
|
2006-05-28 22:46:23 +02:00
|
|
|
if (lpDesc == NULL)
|
|
|
|
{
|
|
|
|
WARN("Invalid Parameter !\n");
|
|
|
|
return MMSYSERR_INVALPARAM;
|
|
|
|
}
|
|
|
|
if (wDevID >= MAX_WAVEOUTDRV) {
|
|
|
|
TRACE("MAX_WAVOUTDRV reached !\n");
|
|
|
|
return MMSYSERR_BADDEVICEID;
|
|
|
|
}
|
|
|
|
|
2006-10-20 12:36:38 +02:00
|
|
|
TRACE("Format: tag=%04X nChannels=%d nSamplesPerSec=%d wBitsPerSample=%d !\n",
|
2006-05-28 22:46:23 +02:00
|
|
|
lpDesc->lpFormat->wFormatTag, lpDesc->lpFormat->nChannels,
|
|
|
|
lpDesc->lpFormat->nSamplesPerSec, lpDesc->lpFormat->wBitsPerSample);
|
|
|
|
|
2009-09-11 07:43:45 +02:00
|
|
|
if (!supportedFormat(lpDesc->lpFormat))
|
2006-05-28 22:46:23 +02:00
|
|
|
{
|
2006-10-20 12:36:38 +02:00
|
|
|
WARN("Bad format: tag=%04X nChannels=%d nSamplesPerSec=%d wBitsPerSample=%d !\n",
|
2006-05-28 22:46:23 +02:00
|
|
|
lpDesc->lpFormat->wFormatTag, lpDesc->lpFormat->nChannels,
|
|
|
|
lpDesc->lpFormat->nSamplesPerSec, lpDesc->lpFormat->wBitsPerSample);
|
|
|
|
return WAVERR_BADFORMAT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dwFlags & WAVE_FORMAT_QUERY)
|
|
|
|
{
|
2006-10-20 12:36:38 +02:00
|
|
|
TRACE("Query format: tag=%04X nChannels=%d nSamplesPerSec=%d !\n",
|
2006-05-28 22:46:23 +02:00
|
|
|
lpDesc->lpFormat->wFormatTag, lpDesc->lpFormat->nChannels,
|
|
|
|
lpDesc->lpFormat->nSamplesPerSec);
|
|
|
|
return MMSYSERR_NOERROR;
|
|
|
|
}
|
2009-04-11 14:18:18 +02:00
|
|
|
|
2009-09-11 07:46:43 +02:00
|
|
|
/* nBlockAlign and nAvgBytesPerSec are output variables for dsound */
|
|
|
|
if (lpDesc->lpFormat->nBlockAlign != lpDesc->lpFormat->nChannels*lpDesc->lpFormat->wBitsPerSample/8) {
|
|
|
|
lpDesc->lpFormat->nBlockAlign = lpDesc->lpFormat->nChannels*lpDesc->lpFormat->wBitsPerSample/8;
|
|
|
|
WARN("Fixing nBlockAlign\n");
|
|
|
|
}
|
|
|
|
if (lpDesc->lpFormat->nAvgBytesPerSec!= lpDesc->lpFormat->nSamplesPerSec*lpDesc->lpFormat->nBlockAlign) {
|
|
|
|
lpDesc->lpFormat->nAvgBytesPerSec = lpDesc->lpFormat->nSamplesPerSec*lpDesc->lpFormat->nBlockAlign;
|
|
|
|
WARN("Fixing nAvgBytesPerSec\n");
|
|
|
|
}
|
|
|
|
|
2009-04-11 14:18:18 +02:00
|
|
|
/* We proceed in three phases:
|
2009-10-11 21:13:23 +02:00
|
|
|
* o Allocate the device instance, marking it as opening
|
2009-04-11 14:18:18 +02:00
|
|
|
* o Create, configure, and start the Audio Unit. To avoid deadlock,
|
|
|
|
* this has to be done without holding wwo->lock.
|
2009-10-11 21:13:23 +02:00
|
|
|
* o If that was successful, finish setting up our instance and add it
|
|
|
|
* to the device's list.
|
|
|
|
* Otherwise, clean up and deallocate the instance.
|
2009-04-11 14:18:18 +02:00
|
|
|
*/
|
2009-10-11 21:13:23 +02:00
|
|
|
wwo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*wwo));
|
|
|
|
if (!wwo)
|
|
|
|
return MMSYSERR_NOMEM;
|
2006-05-24 12:27:24 +02:00
|
|
|
|
2009-10-11 21:13:23 +02:00
|
|
|
wwo->woID = wDevID;
|
2009-04-11 14:18:18 +02:00
|
|
|
wwo->state = WINE_WS_OPENING;
|
|
|
|
|
|
|
|
if (!AudioUnit_CreateDefaultAudioUnit((void *) wwo, &audioUnit))
|
2006-05-28 22:46:23 +02:00
|
|
|
{
|
2009-10-11 21:13:23 +02:00
|
|
|
ERR("CoreAudio_CreateDefaultAudioUnit(0x%04x) failed\n", wDevID);
|
2009-04-11 14:18:18 +02:00
|
|
|
ret = MMSYSERR_ERROR;
|
|
|
|
goto error;
|
2006-05-28 22:46:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
streamFormat.mFormatID = kAudioFormatLinearPCM;
|
2006-05-24 12:41:28 +02:00
|
|
|
streamFormat.mFormatFlags = kLinearPCMFormatFlagIsPacked;
|
2006-05-28 22:46:23 +02:00
|
|
|
/* FIXME check for 32bits float -> kLinearPCMFormatFlagIsFloat */
|
2006-05-24 12:41:28 +02:00
|
|
|
if (lpDesc->lpFormat->wBitsPerSample != 8)
|
|
|
|
streamFormat.mFormatFlags |= kLinearPCMFormatFlagIsSignedInteger;
|
2006-05-31 14:52:58 +02:00
|
|
|
# ifdef WORDS_BIGENDIAN
|
2006-05-24 12:41:28 +02:00
|
|
|
streamFormat.mFormatFlags |= kLinearPCMFormatFlagIsBigEndian; /* FIXME Wave format is little endian */
|
2006-05-28 22:46:23 +02:00
|
|
|
# endif
|
|
|
|
|
|
|
|
streamFormat.mSampleRate = lpDesc->lpFormat->nSamplesPerSec;
|
|
|
|
streamFormat.mChannelsPerFrame = lpDesc->lpFormat->nChannels;
|
|
|
|
streamFormat.mFramesPerPacket = 1;
|
|
|
|
streamFormat.mBitsPerChannel = lpDesc->lpFormat->wBitsPerSample;
|
|
|
|
streamFormat.mBytesPerFrame = streamFormat.mBitsPerChannel * streamFormat.mChannelsPerFrame / 8;
|
|
|
|
streamFormat.mBytesPerPacket = streamFormat.mBytesPerFrame * streamFormat.mFramesPerPacket;
|
2006-05-31 14:52:58 +02:00
|
|
|
|
2009-04-11 14:18:18 +02:00
|
|
|
ret = AudioUnit_InitializeWithStreamDescription(audioUnit, &streamFormat);
|
2006-05-28 22:46:23 +02:00
|
|
|
if (!ret)
|
|
|
|
{
|
2009-04-11 14:18:18 +02:00
|
|
|
ret = WAVERR_BADFORMAT; /* FIXME return an error based on the OSStatus */
|
|
|
|
goto error;
|
2006-05-28 22:46:23 +02:00
|
|
|
}
|
2009-04-11 14:18:18 +02:00
|
|
|
auInited = TRUE;
|
|
|
|
|
2009-10-23 02:36:24 +02:00
|
|
|
AudioUnit_SetVolume(audioUnit, LOWORD(WOutDev[wDevID].device_volume) / 65535.0f,
|
|
|
|
HIWORD(WOutDev[wDevID].device_volume) / 65535.0f);
|
|
|
|
|
2009-04-11 14:18:18 +02:00
|
|
|
/* Our render callback CoreAudio_woAudioUnitIOProc may be called before
|
|
|
|
* AudioOutputUnitStart returns. Core Audio will grab its own internal
|
|
|
|
* lock before calling it and the callback grabs wwo->lock. This would
|
|
|
|
* deadlock if we were holding wwo->lock.
|
|
|
|
* Also, the callback has to safely do nothing in that case, because
|
2009-10-11 21:13:23 +02:00
|
|
|
* wwo hasn't been completely filled out, yet. This is assured by state
|
|
|
|
* being WINE_WS_OPENING. */
|
2009-04-11 14:18:18 +02:00
|
|
|
ret = AudioOutputUnitStart(audioUnit);
|
2006-12-21 10:48:59 +01:00
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
ERR("AudioOutputUnitStart failed: %08x\n", ret);
|
2009-04-11 14:18:18 +02:00
|
|
|
ret = MMSYSERR_ERROR; /* FIXME return an error based on the OSStatus */
|
|
|
|
goto error;
|
2006-12-21 10:48:59 +01:00
|
|
|
}
|
|
|
|
|
2009-04-11 14:18:18 +02:00
|
|
|
|
|
|
|
OSSpinLockLock(&wwo->lock);
|
|
|
|
assert(wwo->state == WINE_WS_OPENING);
|
|
|
|
|
|
|
|
wwo->audioUnit = audioUnit;
|
|
|
|
wwo->streamDescription = streamFormat;
|
|
|
|
|
2009-04-11 14:18:27 +02:00
|
|
|
wwo->state = WINE_WS_PLAYING;
|
2008-03-25 23:22:16 +01:00
|
|
|
|
2006-05-28 22:46:23 +02:00
|
|
|
wwo->wFlags = HIWORD(dwFlags & CALLBACK_TYPEMASK);
|
2008-03-25 23:22:16 +01:00
|
|
|
|
|
|
|
wwo->waveDesc = *lpDesc;
|
2009-09-11 08:12:53 +02:00
|
|
|
copyFormat(lpDesc->lpFormat, &wwo->format);
|
2006-12-21 10:46:55 +01:00
|
|
|
|
2009-10-11 21:12:01 +02:00
|
|
|
WOutDev[wDevID].trace_on = TRACE_ON(wave);
|
|
|
|
WOutDev[wDevID].warn_on = WARN_ON(wave);
|
|
|
|
WOutDev[wDevID].err_on = ERR_ON(wave);
|
2006-12-21 10:46:55 +01:00
|
|
|
|
2006-12-21 10:50:18 +01:00
|
|
|
OSSpinLockUnlock(&wwo->lock);
|
2009-10-11 21:12:48 +02:00
|
|
|
|
2009-10-11 21:13:23 +02:00
|
|
|
OSSpinLockLock(&WOutDev[wDevID].lock);
|
|
|
|
list_add_head(&WOutDev[wDevID].instances, &wwo->entry);
|
|
|
|
OSSpinLockUnlock(&WOutDev[wDevID].lock);
|
|
|
|
|
2009-10-11 21:12:48 +02:00
|
|
|
*pInstance = wwo;
|
|
|
|
TRACE("opened instance %p\n", wwo);
|
|
|
|
|
2009-04-11 14:18:18 +02:00
|
|
|
ret = wodNotifyClient(wwo, WOM_OPEN, 0L, 0L);
|
2006-05-28 22:46:23 +02:00
|
|
|
|
2009-04-11 14:18:18 +02:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
error:
|
|
|
|
if (audioUnit)
|
|
|
|
{
|
|
|
|
if (auInited)
|
|
|
|
AudioUnitUninitialize(audioUnit);
|
|
|
|
AudioUnit_CloseAudioUnit(audioUnit);
|
|
|
|
}
|
|
|
|
|
|
|
|
OSSpinLockLock(&wwo->lock);
|
|
|
|
assert(wwo->state == WINE_WS_OPENING);
|
2009-10-11 21:13:23 +02:00
|
|
|
/* OSSpinLockUnlock(&wwo->lock); *//* No need, about to free */
|
|
|
|
HeapFree(GetProcessHeap(), 0, wwo);
|
2009-04-11 14:18:18 +02:00
|
|
|
|
|
|
|
return ret;
|
2006-05-28 22:46:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* wodClose [internal]
|
|
|
|
*/
|
2009-10-11 21:12:48 +02:00
|
|
|
static DWORD wodClose(WORD wDevID, WINE_WAVEOUT_INSTANCE* wwo)
|
2006-05-28 22:46:23 +02:00
|
|
|
{
|
|
|
|
DWORD ret = MMSYSERR_NOERROR;
|
|
|
|
|
2009-10-11 21:12:48 +02:00
|
|
|
TRACE("(%u, %p);\n", wDevID, wwo);
|
2006-05-28 22:46:23 +02:00
|
|
|
|
|
|
|
if (wDevID >= MAX_WAVEOUTDRV)
|
|
|
|
{
|
|
|
|
WARN("bad device ID !\n");
|
|
|
|
return MMSYSERR_BADDEVICEID;
|
|
|
|
}
|
|
|
|
|
2006-12-21 10:50:18 +01:00
|
|
|
OSSpinLockLock(&wwo->lock);
|
2006-05-28 22:46:23 +02:00
|
|
|
if (wwo->lpQueuePtr)
|
|
|
|
{
|
2006-12-21 10:50:18 +01:00
|
|
|
OSSpinLockUnlock(&wwo->lock);
|
2009-10-17 15:25:51 +02:00
|
|
|
WARN("buffers still playing !\n");
|
2006-05-28 22:46:23 +02:00
|
|
|
ret = WAVERR_STILLPLAYING;
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
OSStatus err;
|
2009-04-11 14:18:23 +02:00
|
|
|
AudioUnit audioUnit = wwo->audioUnit;
|
|
|
|
|
2006-05-28 22:46:23 +02:00
|
|
|
/* sanity check: this should not happen since the device must have been reset before */
|
|
|
|
if (wwo->lpQueuePtr || wwo->lpPlayPtr) ERR("out of sync\n");
|
|
|
|
|
2009-04-11 14:18:23 +02:00
|
|
|
wwo->state = WINE_WS_CLOSING; /* mark the device as closing */
|
|
|
|
wwo->audioUnit = NULL;
|
2006-05-28 22:46:23 +02:00
|
|
|
|
2006-12-21 10:50:18 +01:00
|
|
|
OSSpinLockUnlock(&wwo->lock);
|
2006-12-21 10:49:35 +01:00
|
|
|
|
2009-04-11 14:18:23 +02:00
|
|
|
err = AudioUnitUninitialize(audioUnit);
|
2006-05-28 22:46:23 +02:00
|
|
|
if (err) {
|
2009-10-11 21:11:19 +02:00
|
|
|
ERR("AudioUnitUninitialize return %s\n", wine_dbgstr_fourcc(err));
|
2006-05-28 22:46:23 +02:00
|
|
|
return MMSYSERR_ERROR; /* FIXME return an error based on the OSStatus */
|
|
|
|
}
|
|
|
|
|
2009-04-11 14:18:23 +02:00
|
|
|
if ( !AudioUnit_CloseAudioUnit(audioUnit) )
|
2006-05-28 22:46:23 +02:00
|
|
|
{
|
|
|
|
ERR("Can't close AudioUnit\n");
|
|
|
|
return MMSYSERR_ERROR; /* FIXME return an error based on the OSStatus */
|
|
|
|
}
|
|
|
|
|
2009-10-11 21:13:23 +02:00
|
|
|
OSSpinLockLock(&WOutDev[wDevID].lock);
|
|
|
|
list_remove(&wwo->entry);
|
|
|
|
OSSpinLockUnlock(&WOutDev[wDevID].lock);
|
2009-04-11 14:18:23 +02:00
|
|
|
|
2006-05-28 22:46:23 +02:00
|
|
|
ret = wodNotifyClient(wwo, WOM_CLOSE, 0L, 0L);
|
2009-10-11 21:13:23 +02:00
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, wwo);
|
2006-05-28 22:46:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* wodPrepare [internal]
|
|
|
|
*/
|
2009-10-11 21:12:48 +02:00
|
|
|
static DWORD wodPrepare(WORD wDevID, WINE_WAVEOUT_INSTANCE* wwo, LPWAVEHDR lpWaveHdr, DWORD dwSize)
|
2006-05-28 22:46:23 +02:00
|
|
|
{
|
2009-10-11 21:12:48 +02:00
|
|
|
TRACE("(%u, %p, %p, %08x);\n", wDevID, wwo, lpWaveHdr, dwSize);
|
2006-05-28 22:46:23 +02:00
|
|
|
|
|
|
|
if (wDevID >= MAX_WAVEOUTDRV) {
|
|
|
|
WARN("bad device ID !\n");
|
|
|
|
return MMSYSERR_BADDEVICEID;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lpWaveHdr->dwFlags & WHDR_INQUEUE)
|
|
|
|
return WAVERR_STILLPLAYING;
|
|
|
|
|
|
|
|
lpWaveHdr->dwFlags |= WHDR_PREPARED;
|
|
|
|
lpWaveHdr->dwFlags &= ~WHDR_DONE;
|
2006-05-24 12:34:04 +02:00
|
|
|
|
2006-05-28 22:46:23 +02:00
|
|
|
return MMSYSERR_NOERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* wodUnprepare [internal]
|
|
|
|
*/
|
2009-10-11 21:12:48 +02:00
|
|
|
static DWORD wodUnprepare(WORD wDevID, WINE_WAVEOUT_INSTANCE* wwo, LPWAVEHDR lpWaveHdr, DWORD dwSize)
|
2006-05-28 22:46:23 +02:00
|
|
|
{
|
2009-10-11 21:12:48 +02:00
|
|
|
TRACE("(%u, %p, %p, %08x);\n", wDevID, wwo, lpWaveHdr, dwSize);
|
2006-05-28 22:46:23 +02:00
|
|
|
|
|
|
|
if (wDevID >= MAX_WAVEOUTDRV) {
|
|
|
|
WARN("bad device ID !\n");
|
|
|
|
return MMSYSERR_BADDEVICEID;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lpWaveHdr->dwFlags & WHDR_INQUEUE)
|
|
|
|
return WAVERR_STILLPLAYING;
|
|
|
|
|
|
|
|
lpWaveHdr->dwFlags &= ~WHDR_PREPARED;
|
|
|
|
lpWaveHdr->dwFlags |= WHDR_DONE;
|
|
|
|
|
|
|
|
return MMSYSERR_NOERROR;
|
|
|
|
}
|
|
|
|
|
2006-12-21 10:47:19 +01:00
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* wodHelper_CheckForLoopBegin [internal]
|
|
|
|
*
|
|
|
|
* Check if the new waveheader is the beginning of a loop, and set up
|
|
|
|
* state if so.
|
2009-10-11 21:12:01 +02:00
|
|
|
* This is called with the WAVEOUT_INSTANCE lock held.
|
2006-12-21 10:47:19 +01:00
|
|
|
* Call from AudioUnit IO thread can't use Wine debug channels.
|
|
|
|
*/
|
2009-10-11 21:12:01 +02:00
|
|
|
static void wodHelper_CheckForLoopBegin(WINE_WAVEOUT_INSTANCE* wwo)
|
2006-12-21 10:47:19 +01:00
|
|
|
{
|
|
|
|
LPWAVEHDR lpWaveHdr = wwo->lpPlayPtr;
|
|
|
|
|
|
|
|
if (lpWaveHdr->dwFlags & WHDR_BEGINLOOP)
|
|
|
|
{
|
|
|
|
if (wwo->lpLoopPtr)
|
|
|
|
{
|
2009-10-11 21:12:01 +02:00
|
|
|
if (WOutDev[wwo->woID].warn_on)
|
2006-12-21 10:47:19 +01:00
|
|
|
fprintf(stderr, "warn:winecoreaudio:wodHelper_CheckForLoopBegin Already in a loop. Discarding loop on this header (%p)\n", lpWaveHdr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-10-11 21:12:01 +02:00
|
|
|
if (WOutDev[wwo->woID].trace_on)
|
2006-12-21 10:47:19 +01:00
|
|
|
fprintf(stderr, "trace:winecoreaudio:wodHelper_CheckForLoopBegin Starting loop (%dx) with %p\n", lpWaveHdr->dwLoops, lpWaveHdr);
|
|
|
|
|
|
|
|
wwo->lpLoopPtr = lpWaveHdr;
|
|
|
|
/* Windows does not touch WAVEHDR.dwLoops,
|
|
|
|
* so we need to make an internal copy */
|
|
|
|
wwo->dwLoops = lpWaveHdr->dwLoops;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-28 22:46:23 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* wodHelper_PlayPtrNext [internal]
|
|
|
|
*
|
|
|
|
* Advance the play pointer to the next waveheader, looping if required.
|
2009-10-11 21:12:01 +02:00
|
|
|
* This is called with the WAVEOUT_INSTANCE lock held.
|
2006-05-28 22:46:23 +02:00
|
|
|
* Call from AudioUnit IO thread can't use Wine debug channels.
|
|
|
|
*/
|
2009-10-11 21:12:01 +02:00
|
|
|
static void wodHelper_PlayPtrNext(WINE_WAVEOUT_INSTANCE* wwo)
|
2006-05-28 22:46:23 +02:00
|
|
|
{
|
2006-12-21 10:48:23 +01:00
|
|
|
BOOL didLoopBack = FALSE;
|
2006-05-28 22:46:23 +02:00
|
|
|
|
|
|
|
wwo->dwPartialOffset = 0;
|
2006-12-21 10:48:52 +01:00
|
|
|
if ((wwo->lpPlayPtr->dwFlags & WHDR_ENDLOOP) && wwo->lpLoopPtr)
|
2006-05-28 22:46:23 +02:00
|
|
|
{
|
|
|
|
/* We're at the end of a loop, loop if required */
|
2006-05-24 12:28:18 +02:00
|
|
|
if (wwo->dwLoops > 1)
|
2006-05-28 22:46:23 +02:00
|
|
|
{
|
2006-05-24 12:28:18 +02:00
|
|
|
wwo->dwLoops--;
|
2006-05-28 22:46:23 +02:00
|
|
|
wwo->lpPlayPtr = wwo->lpLoopPtr;
|
2006-12-21 10:48:23 +01:00
|
|
|
didLoopBack = TRUE;
|
|
|
|
}
|
|
|
|
else
|
2006-05-28 22:46:23 +02:00
|
|
|
{
|
|
|
|
wwo->lpLoopPtr = NULL;
|
|
|
|
}
|
2006-12-21 10:48:23 +01:00
|
|
|
}
|
|
|
|
if (!didLoopBack)
|
2006-05-28 22:46:23 +02:00
|
|
|
{
|
2006-12-21 10:48:23 +01:00
|
|
|
/* We didn't loop back. Advance to the next wave header */
|
2006-12-21 10:48:52 +01:00
|
|
|
wwo->lpPlayPtr = wwo->lpPlayPtr->lpNext;
|
2006-12-21 10:48:45 +01:00
|
|
|
|
2009-04-11 14:18:27 +02:00
|
|
|
if (wwo->lpPlayPtr)
|
2006-12-21 10:48:45 +01:00
|
|
|
wodHelper_CheckForLoopBegin(wwo);
|
|
|
|
}
|
2006-05-28 22:46:23 +02:00
|
|
|
}
|
|
|
|
|
2007-06-20 14:00:55 +02:00
|
|
|
/* Send the "done" notification for each WAVEHDR in a list. The list must be
|
2009-10-11 21:12:01 +02:00
|
|
|
* free-standing. It should not be part of a device instance's queue.
|
|
|
|
* This function must be called with the WAVEOUT_INSTANCE lock *not* held.
|
|
|
|
* Furthermore, it does not lock it, itself. That's because the callback to the
|
|
|
|
* application may prompt the application to operate on the device, and we don't
|
|
|
|
* want to deadlock.
|
2007-06-20 14:00:55 +02:00
|
|
|
*/
|
2009-10-11 21:12:01 +02:00
|
|
|
static void wodHelper_NotifyDoneForList(WINE_WAVEOUT_INSTANCE* wwo, LPWAVEHDR lpWaveHdr)
|
2007-06-20 14:00:55 +02:00
|
|
|
{
|
2007-07-12 03:34:45 +02:00
|
|
|
while (lpWaveHdr)
|
2007-06-20 14:00:55 +02:00
|
|
|
{
|
2007-07-12 03:34:45 +02:00
|
|
|
LPWAVEHDR lpNext = lpWaveHdr->lpNext;
|
|
|
|
|
|
|
|
lpWaveHdr->lpNext = NULL;
|
2007-06-20 14:00:55 +02:00
|
|
|
lpWaveHdr->dwFlags &= ~WHDR_INQUEUE;
|
|
|
|
lpWaveHdr->dwFlags |= WHDR_DONE;
|
|
|
|
wodNotifyClient(wwo, WOM_DONE, (DWORD)lpWaveHdr, 0);
|
2007-07-12 03:34:45 +02:00
|
|
|
|
|
|
|
lpWaveHdr = lpNext;
|
2007-06-20 14:00:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-28 22:46:23 +02:00
|
|
|
/* if force is TRUE then notify the client that all the headers were completed
|
|
|
|
*/
|
2009-10-11 21:12:01 +02:00
|
|
|
static void wodHelper_NotifyCompletions(WINE_WAVEOUT_INSTANCE* wwo, BOOL force)
|
2006-05-28 22:46:23 +02:00
|
|
|
{
|
2007-06-20 14:01:04 +02:00
|
|
|
LPWAVEHDR lpFirstDoneWaveHdr = NULL;
|
2006-05-28 22:46:23 +02:00
|
|
|
|
2006-12-21 10:50:18 +01:00
|
|
|
OSSpinLockLock(&wwo->lock);
|
2006-05-28 22:46:23 +02:00
|
|
|
|
2006-12-21 10:49:43 +01:00
|
|
|
/* First, excise all of the done headers from the queue into
|
|
|
|
* a free-standing list. */
|
|
|
|
if (force)
|
|
|
|
{
|
|
|
|
lpFirstDoneWaveHdr = wwo->lpQueuePtr;
|
|
|
|
wwo->lpQueuePtr = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-06-20 14:01:04 +02:00
|
|
|
LPWAVEHDR lpWaveHdr;
|
2006-12-21 10:49:43 +01:00
|
|
|
LPWAVEHDR lpLastDoneWaveHdr = NULL;
|
|
|
|
|
|
|
|
/* Start from lpQueuePtr and keep notifying until:
|
|
|
|
* - we hit an unwritten wavehdr
|
|
|
|
* - we hit the beginning of a running loop
|
|
|
|
* - we hit a wavehdr which hasn't finished playing
|
|
|
|
*/
|
|
|
|
for (
|
|
|
|
lpWaveHdr = wwo->lpQueuePtr;
|
|
|
|
lpWaveHdr &&
|
|
|
|
lpWaveHdr != wwo->lpPlayPtr &&
|
|
|
|
lpWaveHdr != wwo->lpLoopPtr;
|
|
|
|
lpWaveHdr = lpWaveHdr->lpNext
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if (!lpFirstDoneWaveHdr)
|
|
|
|
lpFirstDoneWaveHdr = lpWaveHdr;
|
|
|
|
lpLastDoneWaveHdr = lpWaveHdr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lpLastDoneWaveHdr)
|
|
|
|
{
|
|
|
|
wwo->lpQueuePtr = lpLastDoneWaveHdr->lpNext;
|
|
|
|
lpLastDoneWaveHdr->lpNext = NULL;
|
|
|
|
}
|
|
|
|
}
|
2006-12-21 10:50:18 +01:00
|
|
|
|
|
|
|
OSSpinLockUnlock(&wwo->lock);
|
2006-12-21 10:49:43 +01:00
|
|
|
|
|
|
|
/* Now, send the "done" notification for each header in our list. */
|
2007-06-20 14:00:55 +02:00
|
|
|
wodHelper_NotifyDoneForList(wwo, lpFirstDoneWaveHdr);
|
2006-05-28 22:46:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* wodWrite [internal]
|
|
|
|
*
|
|
|
|
*/
|
2009-10-11 21:12:48 +02:00
|
|
|
static DWORD wodWrite(WORD wDevID, WINE_WAVEOUT_INSTANCE* wwo, LPWAVEHDR lpWaveHdr, DWORD dwSize)
|
2006-05-28 22:46:23 +02:00
|
|
|
{
|
|
|
|
LPWAVEHDR*wh;
|
|
|
|
|
2009-10-11 21:12:48 +02:00
|
|
|
TRACE("(%u, %p, %p, %lu, %08X);\n", wDevID, wwo, lpWaveHdr, (unsigned long)lpWaveHdr->dwBufferLength, dwSize);
|
2006-05-28 22:46:23 +02:00
|
|
|
|
|
|
|
/* first, do the sanity checks... */
|
|
|
|
if (wDevID >= MAX_WAVEOUTDRV)
|
|
|
|
{
|
|
|
|
WARN("bad dev ID !\n");
|
|
|
|
return MMSYSERR_BADDEVICEID;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lpWaveHdr->lpData == NULL || !(lpWaveHdr->dwFlags & WHDR_PREPARED))
|
|
|
|
{
|
|
|
|
TRACE("unprepared\n");
|
|
|
|
return WAVERR_UNPREPARED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lpWaveHdr->dwFlags & WHDR_INQUEUE)
|
|
|
|
{
|
|
|
|
TRACE("still playing\n");
|
|
|
|
return WAVERR_STILLPLAYING;
|
|
|
|
}
|
|
|
|
|
|
|
|
lpWaveHdr->dwFlags &= ~WHDR_DONE;
|
|
|
|
lpWaveHdr->dwFlags |= WHDR_INQUEUE;
|
|
|
|
lpWaveHdr->lpNext = 0;
|
|
|
|
|
2006-12-21 10:50:18 +01:00
|
|
|
OSSpinLockLock(&wwo->lock);
|
2006-05-28 22:46:23 +02:00
|
|
|
/* insert buffer at the end of queue */
|
2006-05-24 12:28:18 +02:00
|
|
|
for (wh = &(wwo->lpQueuePtr); *wh; wh = &((*wh)->lpNext))
|
|
|
|
/* Do nothing */;
|
2006-05-28 22:46:23 +02:00
|
|
|
*wh = lpWaveHdr;
|
2006-12-21 10:48:45 +01:00
|
|
|
|
2006-05-28 22:46:23 +02:00
|
|
|
if (!wwo->lpPlayPtr)
|
2006-12-21 10:48:45 +01:00
|
|
|
{
|
|
|
|
wwo->lpPlayPtr = lpWaveHdr;
|
|
|
|
|
|
|
|
wodHelper_CheckForLoopBegin(wwo);
|
2006-12-21 10:48:38 +01:00
|
|
|
|
2006-12-21 10:48:45 +01:00
|
|
|
wwo->dwPartialOffset = 0;
|
|
|
|
}
|
2006-12-21 10:50:18 +01:00
|
|
|
OSSpinLockUnlock(&wwo->lock);
|
|
|
|
|
2006-05-28 22:46:23 +02:00
|
|
|
return MMSYSERR_NOERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* wodPause [internal]
|
|
|
|
*/
|
2009-10-11 21:12:48 +02:00
|
|
|
static DWORD wodPause(WORD wDevID, WINE_WAVEOUT_INSTANCE* wwo)
|
2006-05-28 22:46:23 +02:00
|
|
|
{
|
2006-05-24 12:34:04 +02:00
|
|
|
OSStatus status;
|
|
|
|
|
2009-10-11 21:12:48 +02:00
|
|
|
TRACE("(%u, %p);!\n", wDevID, wwo);
|
2006-05-28 22:46:23 +02:00
|
|
|
|
|
|
|
if (wDevID >= MAX_WAVEOUTDRV)
|
|
|
|
{
|
|
|
|
WARN("bad device ID !\n");
|
|
|
|
return MMSYSERR_BADDEVICEID;
|
|
|
|
}
|
2006-12-21 10:48:59 +01:00
|
|
|
|
|
|
|
/* The order of the following operations is important since we can't hold
|
|
|
|
* the mutex while we make an Audio Unit call. Stop the Audio Unit before
|
|
|
|
* setting the PAUSED state. In wodRestart, the order is reversed. This
|
|
|
|
* guarantees that we can't get into a situation where the state is
|
2009-04-11 14:18:27 +02:00
|
|
|
* PLAYING but the Audio Unit isn't running. Although we can be in PAUSED
|
|
|
|
* state with the Audio Unit still running, that's harmless because the
|
|
|
|
* render callback will just produce silence.
|
2006-12-21 10:48:59 +01:00
|
|
|
*/
|
2009-10-11 21:12:48 +02:00
|
|
|
status = AudioOutputUnitStop(wwo->audioUnit);
|
2009-10-11 21:11:19 +02:00
|
|
|
if (status)
|
|
|
|
WARN("AudioOutputUnitStop return %s\n", wine_dbgstr_fourcc(status));
|
2006-12-21 10:48:59 +01:00
|
|
|
|
2009-10-11 21:12:48 +02:00
|
|
|
OSSpinLockLock(&wwo->lock);
|
|
|
|
if (wwo->state == WINE_WS_PLAYING)
|
|
|
|
wwo->state = WINE_WS_PAUSED;
|
|
|
|
OSSpinLockUnlock(&wwo->lock);
|
2006-12-21 10:48:59 +01:00
|
|
|
|
2006-05-28 22:46:23 +02:00
|
|
|
return MMSYSERR_NOERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* wodRestart [internal]
|
|
|
|
*/
|
2009-10-11 21:12:48 +02:00
|
|
|
static DWORD wodRestart(WORD wDevID, WINE_WAVEOUT_INSTANCE* wwo)
|
2006-05-28 22:46:23 +02:00
|
|
|
{
|
2006-12-21 10:48:59 +01:00
|
|
|
OSStatus status;
|
|
|
|
|
2009-10-11 21:12:48 +02:00
|
|
|
TRACE("(%u, %p);\n", wDevID, wwo);
|
2006-05-28 22:46:23 +02:00
|
|
|
|
|
|
|
if (wDevID >= MAX_WAVEOUTDRV )
|
|
|
|
{
|
|
|
|
WARN("bad device ID !\n");
|
|
|
|
return MMSYSERR_BADDEVICEID;
|
|
|
|
}
|
2006-12-21 10:48:59 +01:00
|
|
|
|
|
|
|
/* The order of the following operations is important since we can't hold
|
2009-04-11 14:18:27 +02:00
|
|
|
* the mutex while we make an Audio Unit call. Set the PLAYING
|
2006-12-21 10:48:59 +01:00
|
|
|
* state before starting the Audio Unit. In wodPause, the order is
|
|
|
|
* reversed. This guarantees that we can't get into a situation where
|
2009-04-11 14:18:27 +02:00
|
|
|
* the state is PLAYING but the Audio Unit isn't running.
|
2006-12-21 10:48:59 +01:00
|
|
|
* Although we can be in PAUSED state with the Audio Unit still running,
|
|
|
|
* that's harmless because the render callback will just produce silence.
|
|
|
|
*/
|
2009-10-11 21:12:48 +02:00
|
|
|
OSSpinLockLock(&wwo->lock);
|
|
|
|
if (wwo->state == WINE_WS_PAUSED)
|
|
|
|
wwo->state = WINE_WS_PLAYING;
|
|
|
|
OSSpinLockUnlock(&wwo->lock);
|
2006-12-21 10:48:59 +01:00
|
|
|
|
2009-10-11 21:12:48 +02:00
|
|
|
status = AudioOutputUnitStart(wwo->audioUnit);
|
2006-12-21 10:48:59 +01:00
|
|
|
if (status) {
|
2009-10-11 21:11:19 +02:00
|
|
|
ERR("AudioOutputUnitStart return %s\n", wine_dbgstr_fourcc(status));
|
2006-12-21 10:48:59 +01:00
|
|
|
return MMSYSERR_ERROR; /* FIXME return an error based on the OSStatus */
|
|
|
|
}
|
|
|
|
|
2006-05-28 22:46:23 +02:00
|
|
|
return MMSYSERR_NOERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* wodReset [internal]
|
|
|
|
*/
|
2009-10-11 21:12:48 +02:00
|
|
|
static DWORD wodReset(WORD wDevID, WINE_WAVEOUT_INSTANCE* wwo)
|
2006-05-28 22:46:23 +02:00
|
|
|
{
|
2006-12-21 10:49:58 +01:00
|
|
|
OSStatus status;
|
2007-06-20 14:01:07 +02:00
|
|
|
LPWAVEHDR lpSavedQueuePtr;
|
2006-12-21 10:49:58 +01:00
|
|
|
|
2009-10-11 21:12:48 +02:00
|
|
|
TRACE("(%u, %p);\n", wDevID, wwo);
|
2006-12-21 10:49:58 +01:00
|
|
|
|
2006-05-28 22:46:23 +02:00
|
|
|
if (wDevID >= MAX_WAVEOUTDRV)
|
|
|
|
{
|
|
|
|
WARN("bad device ID !\n");
|
|
|
|
return MMSYSERR_BADDEVICEID;
|
|
|
|
}
|
2006-12-21 10:49:58 +01:00
|
|
|
|
2006-12-21 10:50:18 +01:00
|
|
|
OSSpinLockLock(&wwo->lock);
|
2007-06-20 14:01:11 +02:00
|
|
|
|
2009-10-11 21:13:23 +02:00
|
|
|
if (wwo->state == WINE_WS_CLOSING || wwo->state == WINE_WS_OPENING)
|
2007-06-20 14:01:11 +02:00
|
|
|
{
|
|
|
|
OSSpinLockUnlock(&wwo->lock);
|
|
|
|
WARN("resetting a closed device\n");
|
|
|
|
return MMSYSERR_INVALHANDLE;
|
|
|
|
}
|
|
|
|
|
2007-06-20 14:01:07 +02:00
|
|
|
lpSavedQueuePtr = wwo->lpQueuePtr;
|
2006-12-21 10:49:58 +01:00
|
|
|
wwo->lpPlayPtr = wwo->lpQueuePtr = wwo->lpLoopPtr = NULL;
|
2009-04-11 14:18:27 +02:00
|
|
|
wwo->state = WINE_WS_PLAYING;
|
2009-10-11 21:11:49 +02:00
|
|
|
wwo->dwPlayedTotal = 0;
|
2006-12-21 10:49:58 +01:00
|
|
|
|
|
|
|
wwo->dwPartialOffset = 0; /* Clear partial wavehdr */
|
|
|
|
|
2006-12-21 10:50:18 +01:00
|
|
|
OSSpinLockUnlock(&wwo->lock);
|
2006-12-21 10:49:58 +01:00
|
|
|
|
|
|
|
status = AudioOutputUnitStart(wwo->audioUnit);
|
|
|
|
|
|
|
|
if (status) {
|
2009-10-11 21:11:19 +02:00
|
|
|
ERR( "AudioOutputUnitStart return %s\n", wine_dbgstr_fourcc(status));
|
2006-12-21 10:49:58 +01:00
|
|
|
return MMSYSERR_ERROR; /* FIXME return an error based on the OSStatus */
|
|
|
|
}
|
|
|
|
|
2007-06-20 14:01:07 +02:00
|
|
|
/* Now, send the "done" notification for each header in our list. */
|
|
|
|
/* Do this last so the reset operation is effectively complete before the
|
|
|
|
* app does whatever it's going to do in response to these notifications. */
|
|
|
|
wodHelper_NotifyDoneForList(wwo, lpSavedQueuePtr);
|
|
|
|
|
2006-12-21 10:49:58 +01:00
|
|
|
return MMSYSERR_NOERROR;
|
2006-05-28 22:46:23 +02:00
|
|
|
}
|
|
|
|
|
2009-02-05 22:49:04 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* wodBreakLoop [internal]
|
|
|
|
*/
|
2009-10-11 21:12:48 +02:00
|
|
|
static DWORD wodBreakLoop(WORD wDevID, WINE_WAVEOUT_INSTANCE* wwo)
|
2009-02-05 22:49:04 +01:00
|
|
|
{
|
2009-10-11 21:12:48 +02:00
|
|
|
TRACE("(%u, %p);\n", wDevID, wwo);
|
2009-02-05 22:49:04 +01:00
|
|
|
|
|
|
|
if (wDevID >= MAX_WAVEOUTDRV)
|
|
|
|
{
|
|
|
|
WARN("bad device ID !\n");
|
|
|
|
return MMSYSERR_BADDEVICEID;
|
|
|
|
}
|
|
|
|
|
|
|
|
OSSpinLockLock(&wwo->lock);
|
|
|
|
|
|
|
|
if (wwo->lpLoopPtr != NULL)
|
|
|
|
{
|
|
|
|
/* ensure exit at end of current loop */
|
|
|
|
wwo->dwLoops = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
OSSpinLockUnlock(&wwo->lock);
|
|
|
|
|
|
|
|
return MMSYSERR_NOERROR;
|
|
|
|
}
|
|
|
|
|
2006-05-28 22:46:23 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* wodGetPosition [internal]
|
|
|
|
*/
|
2009-10-11 21:12:48 +02:00
|
|
|
static DWORD wodGetPosition(WORD wDevID, WINE_WAVEOUT_INSTANCE* wwo, LPMMTIME lpTime, DWORD uSize)
|
2006-05-28 22:46:23 +02:00
|
|
|
{
|
|
|
|
DWORD val;
|
2006-05-31 14:52:58 +02:00
|
|
|
|
2009-10-11 21:12:48 +02:00
|
|
|
TRACE("(%u, %p, %p, %u);\n", wDevID, wwo, lpTime, uSize);
|
2006-05-28 22:46:23 +02:00
|
|
|
|
|
|
|
if (wDevID >= MAX_WAVEOUTDRV)
|
|
|
|
{
|
|
|
|
WARN("bad device ID !\n");
|
|
|
|
return MMSYSERR_BADDEVICEID;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if null pointer to time structure return error */
|
|
|
|
if (lpTime == NULL) return MMSYSERR_INVALPARAM;
|
|
|
|
|
2009-10-11 21:12:01 +02:00
|
|
|
OSSpinLockLock(&wwo->lock);
|
2006-05-28 22:46:23 +02:00
|
|
|
val = wwo->dwPlayedTotal;
|
2009-10-11 21:12:01 +02:00
|
|
|
OSSpinLockUnlock(&wwo->lock);
|
2006-05-28 22:46:23 +02:00
|
|
|
|
|
|
|
return bytes_to_mmtime(lpTime, val, &wwo->format);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* wodGetVolume [internal]
|
|
|
|
*/
|
2009-10-11 21:12:48 +02:00
|
|
|
static DWORD wodGetVolume(WORD wDevID, WINE_WAVEOUT_INSTANCE* wwo, LPDWORD lpdwVol)
|
2006-05-28 22:46:23 +02:00
|
|
|
{
|
|
|
|
if (wDevID >= MAX_WAVEOUTDRV)
|
|
|
|
{
|
|
|
|
WARN("bad device ID !\n");
|
|
|
|
return MMSYSERR_BADDEVICEID;
|
|
|
|
}
|
|
|
|
|
2009-10-11 21:12:48 +02:00
|
|
|
TRACE("(%u, %p, %p);\n", wDevID, wwo, lpdwVol);
|
2006-12-21 10:49:35 +01:00
|
|
|
|
2009-10-23 02:36:24 +02:00
|
|
|
if (wwo)
|
|
|
|
{
|
|
|
|
float left;
|
|
|
|
float right;
|
|
|
|
|
|
|
|
AudioUnit_GetVolume(wwo->audioUnit, &left, &right);
|
|
|
|
*lpdwVol = (WORD)(left * 0xFFFFl) + ((WORD)(right * 0xFFFFl) << 16);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*lpdwVol = WOutDev[wDevID].device_volume;
|
2006-12-21 10:49:35 +01:00
|
|
|
|
2006-05-28 22:46:23 +02:00
|
|
|
return MMSYSERR_NOERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* wodSetVolume [internal]
|
|
|
|
*/
|
2009-10-11 21:12:48 +02:00
|
|
|
static DWORD wodSetVolume(WORD wDevID, WINE_WAVEOUT_INSTANCE* wwo, DWORD dwParam)
|
2006-05-28 22:46:23 +02:00
|
|
|
{
|
|
|
|
float left;
|
|
|
|
float right;
|
|
|
|
|
|
|
|
if (wDevID >= MAX_WAVEOUTDRV)
|
|
|
|
{
|
|
|
|
WARN("bad device ID !\n");
|
|
|
|
return MMSYSERR_BADDEVICEID;
|
|
|
|
}
|
|
|
|
|
|
|
|
left = LOWORD(dwParam) / 65535.0f;
|
|
|
|
right = HIWORD(dwParam) / 65535.0f;
|
|
|
|
|
2009-10-11 21:12:48 +02:00
|
|
|
TRACE("(%u, %p, %08x);\n", wDevID, wwo, dwParam);
|
2006-12-21 10:49:35 +01:00
|
|
|
|
2009-10-23 02:36:24 +02:00
|
|
|
if (wwo)
|
|
|
|
AudioUnit_SetVolume(wwo->audioUnit, left, right);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
OSSpinLockLock(&WOutDev[wDevID].lock);
|
|
|
|
LIST_FOR_EACH_ENTRY(wwo, &WOutDev[wDevID].instances, WINE_WAVEOUT_INSTANCE, entry)
|
|
|
|
AudioUnit_SetVolume(wwo->audioUnit, left, right);
|
|
|
|
OSSpinLockUnlock(&WOutDev[wDevID].lock);
|
|
|
|
|
|
|
|
WOutDev[wDevID].device_volume = dwParam;
|
|
|
|
}
|
2006-12-21 10:49:35 +01:00
|
|
|
|
2006-05-28 22:46:23 +02:00
|
|
|
return MMSYSERR_NOERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* wodGetNumDevs [internal]
|
|
|
|
*/
|
|
|
|
static DWORD wodGetNumDevs(void)
|
|
|
|
{
|
|
|
|
TRACE("\n");
|
|
|
|
return MAX_WAVEOUTDRV;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* wodDevInterfaceSize [internal]
|
|
|
|
*/
|
|
|
|
static DWORD wodDevInterfaceSize(UINT wDevID, LPDWORD dwParam1)
|
|
|
|
{
|
|
|
|
TRACE("(%u, %p)\n", wDevID, dwParam1);
|
|
|
|
|
2009-01-02 13:13:47 +01:00
|
|
|
*dwParam1 = MultiByteToWideChar(CP_UNIXCP, 0, WOutDev[wDevID].cadev->interface_name, -1,
|
2006-05-28 22:46:23 +02:00
|
|
|
NULL, 0 ) * sizeof(WCHAR);
|
|
|
|
return MMSYSERR_NOERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* wodDevInterface [internal]
|
|
|
|
*/
|
|
|
|
static DWORD wodDevInterface(UINT wDevID, PWCHAR dwParam1, DWORD dwParam2)
|
|
|
|
{
|
|
|
|
TRACE("\n");
|
2009-01-02 13:13:47 +01:00
|
|
|
if (dwParam2 >= MultiByteToWideChar(CP_UNIXCP, 0, WOutDev[wDevID].cadev->interface_name, -1,
|
2006-05-28 22:46:23 +02:00
|
|
|
NULL, 0 ) * sizeof(WCHAR))
|
|
|
|
{
|
2009-01-02 13:13:47 +01:00
|
|
|
MultiByteToWideChar(CP_UNIXCP, 0, WOutDev[wDevID].cadev->interface_name, -1,
|
2006-05-28 22:46:23 +02:00
|
|
|
dwParam1, dwParam2 / sizeof(WCHAR));
|
|
|
|
return MMSYSERR_NOERROR;
|
|
|
|
}
|
|
|
|
return MMSYSERR_INVALPARAM;
|
|
|
|
}
|
|
|
|
|
2007-07-12 03:34:34 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* widDsCreate [internal]
|
|
|
|
*/
|
|
|
|
static DWORD wodDsCreate(UINT wDevID, PIDSDRIVER* drv)
|
|
|
|
{
|
|
|
|
TRACE("(%d,%p)\n",wDevID,drv);
|
|
|
|
|
|
|
|
FIXME("DirectSound not implemented\n");
|
|
|
|
FIXME("The (slower) DirectSound HEL mode will be used instead.\n");
|
|
|
|
return MMSYSERR_NOTSUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* wodDsDesc [internal]
|
|
|
|
*/
|
|
|
|
static DWORD wodDsDesc(UINT wDevID, PDSDRIVERDESC desc)
|
|
|
|
{
|
|
|
|
/* The DirectSound HEL will automatically wrap a non-DirectSound-capable
|
|
|
|
* driver in a DirectSound adaptor, thus allowing the driver to be used by
|
|
|
|
* DirectSound clients. However, it only does this if we respond
|
|
|
|
* successfully to the DRV_QUERYDSOUNDDESC message. It's enough to fill in
|
|
|
|
* the driver and device names of the description output parameter. */
|
2008-03-25 23:22:16 +01:00
|
|
|
*desc = WOutDev[wDevID].cadev->ds_desc;
|
2007-07-12 03:34:34 +02:00
|
|
|
return MMSYSERR_NOERROR;
|
|
|
|
}
|
|
|
|
|
2006-05-28 22:46:23 +02:00
|
|
|
/**************************************************************************
|
2006-12-28 18:03:26 +01:00
|
|
|
* wodMessage (WINECOREAUDIO.7)
|
2006-05-28 22:46:23 +02:00
|
|
|
*/
|
2009-10-11 21:12:20 +02:00
|
|
|
DWORD WINAPI CoreAudio_wodMessage(UINT wDevID, UINT wMsg, DWORD_PTR dwUser,
|
|
|
|
DWORD_PTR dwParam1, DWORD_PTR dwParam2)
|
2006-05-28 22:46:23 +02:00
|
|
|
{
|
2009-10-11 21:12:48 +02:00
|
|
|
WINE_WAVEOUT_INSTANCE* wwo = (WINE_WAVEOUT_INSTANCE*)dwUser;
|
|
|
|
|
2009-10-11 21:12:20 +02:00
|
|
|
TRACE("(%u, %s, %p, %p, %p);\n",
|
|
|
|
wDevID, getMessage(wMsg), (void*)dwUser, (void*)dwParam1, (void*)dwParam2);
|
2006-05-28 22:46:23 +02:00
|
|
|
|
|
|
|
switch (wMsg) {
|
|
|
|
case DRVM_INIT:
|
|
|
|
case DRVM_EXIT:
|
|
|
|
case DRVM_ENABLE:
|
|
|
|
case DRVM_DISABLE:
|
|
|
|
|
2006-05-24 12:28:18 +02:00
|
|
|
/* FIXME: Pretend this is supported */
|
2006-05-28 22:46:23 +02:00
|
|
|
return 0;
|
2009-10-11 21:12:48 +02:00
|
|
|
case WODM_OPEN: return wodOpen(wDevID, (WINE_WAVEOUT_INSTANCE**)dwUser, (LPWAVEOPENDESC) dwParam1, dwParam2);
|
|
|
|
case WODM_CLOSE: return wodClose(wDevID, wwo);
|
|
|
|
case WODM_WRITE: return wodWrite(wDevID, wwo, (LPWAVEHDR) dwParam1, dwParam2);
|
|
|
|
case WODM_PAUSE: return wodPause(wDevID, wwo);
|
|
|
|
case WODM_GETPOS: return wodGetPosition(wDevID, wwo, (LPMMTIME) dwParam1, dwParam2);
|
|
|
|
case WODM_BREAKLOOP: return wodBreakLoop(wDevID, wwo);
|
|
|
|
case WODM_PREPARE: return wodPrepare(wDevID, wwo, (LPWAVEHDR)dwParam1, dwParam2);
|
|
|
|
case WODM_UNPREPARE: return wodUnprepare(wDevID, wwo, (LPWAVEHDR)dwParam1, dwParam2);
|
2006-05-28 22:46:23 +02:00
|
|
|
|
|
|
|
case WODM_GETDEVCAPS: return wodGetDevCaps(wDevID, (LPWAVEOUTCAPSW) dwParam1, dwParam2);
|
|
|
|
case WODM_GETNUMDEVS: return wodGetNumDevs();
|
|
|
|
|
|
|
|
case WODM_GETPITCH:
|
|
|
|
case WODM_SETPITCH:
|
|
|
|
case WODM_GETPLAYBACKRATE:
|
|
|
|
case WODM_SETPLAYBACKRATE: return MMSYSERR_NOTSUPPORTED;
|
2009-10-11 21:12:48 +02:00
|
|
|
case WODM_GETVOLUME: return wodGetVolume(wDevID, wwo, (LPDWORD)dwParam1);
|
|
|
|
case WODM_SETVOLUME: return wodSetVolume(wDevID, wwo, dwParam1);
|
|
|
|
case WODM_RESTART: return wodRestart(wDevID, wwo);
|
|
|
|
case WODM_RESET: return wodReset(wDevID, wwo);
|
2006-05-28 22:46:23 +02:00
|
|
|
|
|
|
|
case DRV_QUERYDEVICEINTERFACESIZE: return wodDevInterfaceSize (wDevID, (LPDWORD)dwParam1);
|
|
|
|
case DRV_QUERYDEVICEINTERFACE: return wodDevInterface (wDevID, (PWCHAR)dwParam1, dwParam2);
|
2007-07-12 03:34:34 +02:00
|
|
|
case DRV_QUERYDSOUNDIFACE: return wodDsCreate (wDevID, (PIDSDRIVER*)dwParam1);
|
|
|
|
case DRV_QUERYDSOUNDDESC: return wodDsDesc (wDevID, (PDSDRIVERDESC)dwParam1);
|
2006-05-28 22:46:23 +02:00
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("unknown message %d!\n", wMsg);
|
|
|
|
}
|
|
|
|
|
|
|
|
return MMSYSERR_NOTSUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*======================================================================*
|
|
|
|
* Low level DSOUND implementation *
|
|
|
|
*======================================================================*/
|
|
|
|
|
|
|
|
typedef struct IDsDriverImpl IDsDriverImpl;
|
|
|
|
typedef struct IDsDriverBufferImpl IDsDriverBufferImpl;
|
|
|
|
|
|
|
|
struct IDsDriverImpl
|
|
|
|
{
|
|
|
|
/* IUnknown fields */
|
|
|
|
const IDsDriverVtbl *lpVtbl;
|
|
|
|
DWORD ref;
|
|
|
|
/* IDsDriverImpl fields */
|
|
|
|
UINT wDevID;
|
|
|
|
IDsDriverBufferImpl*primary;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct IDsDriverBufferImpl
|
|
|
|
{
|
|
|
|
/* IUnknown fields */
|
|
|
|
const IDsDriverBufferVtbl *lpVtbl;
|
|
|
|
DWORD ref;
|
|
|
|
/* IDsDriverBufferImpl fields */
|
|
|
|
IDsDriverImpl* drv;
|
|
|
|
DWORD buflen;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
CoreAudio IO threaded callback,
|
|
|
|
we can't call Wine debug channels, critical section or anything using NtCurrentTeb here.
|
|
|
|
*/
|
|
|
|
OSStatus CoreAudio_woAudioUnitIOProc(void *inRefCon,
|
|
|
|
AudioUnitRenderActionFlags *ioActionFlags,
|
|
|
|
const AudioTimeStamp *inTimeStamp,
|
|
|
|
UInt32 inBusNumber,
|
|
|
|
UInt32 inNumberFrames,
|
|
|
|
AudioBufferList *ioData)
|
|
|
|
{
|
2006-05-24 12:38:16 +02:00
|
|
|
UInt32 buffer;
|
2009-10-11 21:12:01 +02:00
|
|
|
WINE_WAVEOUT_INSTANCE* wwo = (WINE_WAVEOUT_INSTANCE*)inRefCon;
|
2006-05-28 22:46:23 +02:00
|
|
|
int needNotify = 0;
|
2006-05-24 12:38:16 +02:00
|
|
|
|
|
|
|
unsigned int dataNeeded = ioData->mBuffers[0].mDataByteSize;
|
|
|
|
unsigned int dataProvided = 0;
|
|
|
|
|
2006-12-21 10:50:18 +01:00
|
|
|
OSSpinLockLock(&wwo->lock);
|
2006-12-21 10:49:07 +01:00
|
|
|
|
2009-04-11 14:18:18 +02:00
|
|
|
/* We might have been called before wwo has been completely filled out by
|
2009-04-11 14:18:23 +02:00
|
|
|
* wodOpen, or while it's being closed in wodClose. We have to do nothing
|
|
|
|
* in that case. The check of wwo->state below ensures that. */
|
2006-12-21 10:50:09 +01:00
|
|
|
while (dataNeeded > 0 && wwo->state == WINE_WS_PLAYING && wwo->lpPlayPtr)
|
2006-05-28 22:46:23 +02:00
|
|
|
{
|
2006-12-21 10:50:09 +01:00
|
|
|
unsigned int available = wwo->lpPlayPtr->dwBufferLength - wwo->dwPartialOffset;
|
|
|
|
unsigned int toCopy;
|
2006-05-24 12:38:16 +02:00
|
|
|
|
2006-12-21 10:50:09 +01:00
|
|
|
if (available >= dataNeeded)
|
|
|
|
toCopy = dataNeeded;
|
|
|
|
else
|
|
|
|
toCopy = available;
|
2006-05-24 12:38:16 +02:00
|
|
|
|
2006-12-21 10:50:09 +01:00
|
|
|
if (toCopy > 0)
|
|
|
|
{
|
|
|
|
memcpy((char*)ioData->mBuffers[0].mData + dataProvided,
|
|
|
|
wwo->lpPlayPtr->lpData + wwo->dwPartialOffset, toCopy);
|
|
|
|
wwo->dwPartialOffset += toCopy;
|
|
|
|
wwo->dwPlayedTotal += toCopy;
|
|
|
|
dataProvided += toCopy;
|
|
|
|
dataNeeded -= toCopy;
|
|
|
|
available -= toCopy;
|
2006-05-24 12:38:16 +02:00
|
|
|
}
|
2006-12-21 10:50:09 +01:00
|
|
|
|
|
|
|
if (available == 0)
|
2006-05-24 12:38:16 +02:00
|
|
|
{
|
2006-12-21 10:50:09 +01:00
|
|
|
wodHelper_PlayPtrNext(wwo);
|
|
|
|
needNotify = 1;
|
2006-05-24 12:38:16 +02:00
|
|
|
}
|
2006-05-28 22:46:23 +02:00
|
|
|
}
|
2008-02-21 18:15:53 +01:00
|
|
|
ioData->mBuffers[0].mDataByteSize = dataProvided;
|
2006-05-24 12:38:16 +02:00
|
|
|
|
2006-12-21 10:50:18 +01:00
|
|
|
OSSpinLockUnlock(&wwo->lock);
|
2006-12-21 10:49:07 +01:00
|
|
|
|
2006-12-21 10:50:09 +01:00
|
|
|
/* We can't provide any more wave data. Fill the rest with silence. */
|
|
|
|
if (dataNeeded > 0)
|
|
|
|
{
|
|
|
|
if (!dataProvided)
|
|
|
|
*ioActionFlags |= kAudioUnitRenderAction_OutputIsSilence;
|
|
|
|
memset((char*)ioData->mBuffers[0].mData + dataProvided, 0, dataNeeded);
|
|
|
|
dataProvided += dataNeeded;
|
|
|
|
dataNeeded = 0;
|
|
|
|
}
|
|
|
|
|
2006-05-24 12:38:16 +02:00
|
|
|
/* We only fill buffer 0. Set any others that might be requested to 0. */
|
|
|
|
for (buffer = 1; buffer < ioData->mNumberBuffers; buffer++)
|
2006-05-28 22:46:23 +02:00
|
|
|
{
|
2006-05-24 12:38:16 +02:00
|
|
|
memset(ioData->mBuffers[buffer].mData, 0, ioData->mBuffers[buffer].mDataByteSize);
|
2006-05-28 22:46:23 +02:00
|
|
|
}
|
|
|
|
|
2006-12-21 10:49:43 +01:00
|
|
|
if (needNotify) wodSendNotifyCompletionsMessage(wwo);
|
2006-05-28 22:46:23 +02:00
|
|
|
return noErr;
|
|
|
|
}
|
2006-12-28 18:03:26 +01:00
|
|
|
|
|
|
|
|
|
|
|
/*======================================================================*
|
|
|
|
* Low level WAVE IN implementation *
|
|
|
|
*======================================================================*/
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* widNotifyClient [internal]
|
|
|
|
*/
|
|
|
|
static DWORD widNotifyClient(WINE_WAVEIN* wwi, WORD wMsg, DWORD dwParam1, DWORD dwParam2)
|
|
|
|
{
|
|
|
|
TRACE("wMsg = 0x%04x dwParm1 = %04X dwParam2 = %04X\n", wMsg, dwParam1, dwParam2);
|
|
|
|
|
|
|
|
switch (wMsg)
|
|
|
|
{
|
|
|
|
case WIM_OPEN:
|
|
|
|
case WIM_CLOSE:
|
|
|
|
case WIM_DATA:
|
|
|
|
if (wwi->wFlags != DCB_NULL &&
|
|
|
|
!DriverCallback(wwi->waveDesc.dwCallback, wwi->wFlags,
|
|
|
|
(HDRVR)wwi->waveDesc.hWave, wMsg, wwi->waveDesc.dwInstance,
|
|
|
|
dwParam1, dwParam2))
|
|
|
|
{
|
|
|
|
WARN("can't notify client !\n");
|
|
|
|
return MMSYSERR_ERROR;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("Unknown callback message %u\n", wMsg);
|
|
|
|
return MMSYSERR_INVALPARAM;
|
|
|
|
}
|
|
|
|
return MMSYSERR_NOERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-28 18:06:43 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* widHelper_NotifyCompletions [internal]
|
|
|
|
*/
|
|
|
|
static void widHelper_NotifyCompletions(WINE_WAVEIN* wwi)
|
|
|
|
{
|
|
|
|
LPWAVEHDR lpWaveHdr;
|
|
|
|
LPWAVEHDR lpFirstDoneWaveHdr = NULL;
|
|
|
|
LPWAVEHDR lpLastDoneWaveHdr = NULL;
|
|
|
|
|
|
|
|
OSSpinLockLock(&wwi->lock);
|
|
|
|
|
|
|
|
/* First, excise all of the done headers from the queue into
|
|
|
|
* a free-standing list. */
|
|
|
|
|
|
|
|
/* Start from lpQueuePtr and keep notifying until:
|
|
|
|
* - we hit an unfilled wavehdr
|
|
|
|
* - we hit the end of the list
|
|
|
|
*/
|
|
|
|
for (
|
|
|
|
lpWaveHdr = wwi->lpQueuePtr;
|
|
|
|
lpWaveHdr &&
|
|
|
|
lpWaveHdr->dwBytesRecorded >= lpWaveHdr->dwBufferLength;
|
|
|
|
lpWaveHdr = lpWaveHdr->lpNext
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if (!lpFirstDoneWaveHdr)
|
|
|
|
lpFirstDoneWaveHdr = lpWaveHdr;
|
|
|
|
lpLastDoneWaveHdr = lpWaveHdr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lpLastDoneWaveHdr)
|
|
|
|
{
|
|
|
|
wwi->lpQueuePtr = lpLastDoneWaveHdr->lpNext;
|
|
|
|
lpLastDoneWaveHdr->lpNext = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
OSSpinLockUnlock(&wwi->lock);
|
|
|
|
|
|
|
|
/* Now, send the "done" notification for each header in our list. */
|
2007-07-12 03:34:45 +02:00
|
|
|
lpWaveHdr = lpFirstDoneWaveHdr;
|
|
|
|
while (lpWaveHdr)
|
2006-12-28 18:06:43 +01:00
|
|
|
{
|
2007-07-12 03:34:45 +02:00
|
|
|
LPWAVEHDR lpNext = lpWaveHdr->lpNext;
|
|
|
|
|
|
|
|
lpWaveHdr->lpNext = NULL;
|
2006-12-28 18:06:43 +01:00
|
|
|
lpWaveHdr->dwFlags &= ~WHDR_INQUEUE;
|
|
|
|
lpWaveHdr->dwFlags |= WHDR_DONE;
|
|
|
|
widNotifyClient(wwi, WIM_DATA, (DWORD)lpWaveHdr, 0);
|
2007-07-12 03:34:45 +02:00
|
|
|
|
|
|
|
lpWaveHdr = lpNext;
|
2006-12-28 18:06:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-28 18:03:26 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* 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 >= MAX_WAVEINDRV)
|
|
|
|
{
|
|
|
|
TRACE("MAX_WAVEINDRV reached !\n");
|
|
|
|
return MMSYSERR_BADDEVICEID;
|
|
|
|
}
|
|
|
|
|
2006-12-28 18:03:50 +01:00
|
|
|
memcpy(lpCaps, &WInDev[wDevID].caps, min(dwSize, sizeof(*lpCaps)));
|
|
|
|
return MMSYSERR_NOERROR;
|
2006-12-28 18:03:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-28 18:06:29 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* widHelper_DestroyAudioBufferList [internal]
|
|
|
|
* Convenience function to dispose of our audio buffers
|
|
|
|
*/
|
|
|
|
static void widHelper_DestroyAudioBufferList(AudioBufferList* list)
|
|
|
|
{
|
|
|
|
if (list)
|
|
|
|
{
|
|
|
|
UInt32 i;
|
|
|
|
for (i = 0; i < list->mNumberBuffers; i++)
|
|
|
|
{
|
|
|
|
if (list->mBuffers[i].mData)
|
|
|
|
HeapFree(GetProcessHeap(), 0, list->mBuffers[i].mData);
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-13 14:21:36 +02:00
|
|
|
#define AUDIOBUFFERLISTSIZE(numBuffers) (offsetof(AudioBufferList, mBuffers) + (numBuffers) * sizeof(AudioBuffer))
|
|
|
|
|
2006-12-28 18:06:29 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* widHelper_AllocateAudioBufferList [internal]
|
|
|
|
* Convenience function to allocate our audio buffers
|
|
|
|
*/
|
2007-07-13 14:21:29 +02:00
|
|
|
static AudioBufferList* widHelper_AllocateAudioBufferList(UInt32 numChannels, UInt32 bitsPerChannel, UInt32 bufferFrames, BOOL interleaved)
|
2006-12-28 18:06:29 +01:00
|
|
|
{
|
2007-07-13 14:21:29 +02:00
|
|
|
UInt32 numBuffers;
|
|
|
|
UInt32 channelsPerFrame;
|
|
|
|
UInt32 bytesPerFrame;
|
|
|
|
UInt32 bytesPerBuffer;
|
2006-12-28 18:06:29 +01:00
|
|
|
AudioBufferList* list;
|
|
|
|
UInt32 i;
|
|
|
|
|
2007-07-13 14:21:29 +02:00
|
|
|
if (interleaved)
|
|
|
|
{
|
|
|
|
/* For interleaved audio, we allocate one buffer for all channels. */
|
|
|
|
numBuffers = 1;
|
|
|
|
channelsPerFrame = numChannels;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
numBuffers = numChannels;
|
|
|
|
channelsPerFrame = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bytesPerFrame = bitsPerChannel * channelsPerFrame / 8;
|
|
|
|
bytesPerBuffer = bytesPerFrame * bufferFrames;
|
|
|
|
|
2007-07-13 14:21:36 +02:00
|
|
|
list = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, AUDIOBUFFERLISTSIZE(numBuffers));
|
2006-12-28 18:06:29 +01:00
|
|
|
if (list == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2007-07-13 14:21:29 +02:00
|
|
|
list->mNumberBuffers = numBuffers;
|
|
|
|
for (i = 0; i < numBuffers; ++i)
|
2006-12-28 18:06:29 +01:00
|
|
|
{
|
2007-07-13 14:21:29 +02:00
|
|
|
list->mBuffers[i].mNumberChannels = channelsPerFrame;
|
|
|
|
list->mBuffers[i].mDataByteSize = bytesPerBuffer;
|
|
|
|
list->mBuffers[i].mData = HeapAlloc(GetProcessHeap(), 0, bytesPerBuffer);
|
2006-12-28 18:06:29 +01:00
|
|
|
if (list->mBuffers[i].mData == NULL)
|
|
|
|
{
|
|
|
|
widHelper_DestroyAudioBufferList(list);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-28 18:03:26 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* widOpen [internal]
|
|
|
|
*/
|
|
|
|
static DWORD widOpen(WORD wDevID, LPWAVEOPENDESC lpDesc, DWORD dwFlags)
|
|
|
|
{
|
2006-12-28 18:06:23 +01:00
|
|
|
WINE_WAVEIN* wwi;
|
|
|
|
UInt32 frameCount;
|
2006-12-28 18:05:31 +01:00
|
|
|
|
2006-12-28 18:03:26 +01:00
|
|
|
TRACE("(%u, %p, %08X);\n", wDevID, lpDesc, dwFlags);
|
|
|
|
if (lpDesc == NULL)
|
|
|
|
{
|
|
|
|
WARN("Invalid Parameter !\n");
|
|
|
|
return MMSYSERR_INVALPARAM;
|
|
|
|
}
|
|
|
|
if (wDevID >= MAX_WAVEINDRV)
|
|
|
|
{
|
|
|
|
TRACE ("MAX_WAVEINDRV reached !\n");
|
|
|
|
return MMSYSERR_BADDEVICEID;
|
|
|
|
}
|
|
|
|
|
2006-12-28 18:05:31 +01:00
|
|
|
TRACE("Format: tag=%04X nChannels=%d nSamplesPerSec=%d wBitsPerSample=%d !\n",
|
|
|
|
lpDesc->lpFormat->wFormatTag, lpDesc->lpFormat->nChannels,
|
|
|
|
lpDesc->lpFormat->nSamplesPerSec, lpDesc->lpFormat->wBitsPerSample);
|
|
|
|
|
2009-09-11 07:43:45 +02:00
|
|
|
if (!supportedFormat(lpDesc->lpFormat) ||
|
2007-07-13 14:21:49 +02:00
|
|
|
lpDesc->lpFormat->nSamplesPerSec != AudioUnit_GetInputDeviceSampleRate()
|
2006-12-28 18:05:31 +01:00
|
|
|
)
|
|
|
|
{
|
|
|
|
WARN("Bad format: tag=%04X nChannels=%d nSamplesPerSec=%d wBitsPerSample=%d !\n",
|
|
|
|
lpDesc->lpFormat->wFormatTag, lpDesc->lpFormat->nChannels,
|
|
|
|
lpDesc->lpFormat->nSamplesPerSec, lpDesc->lpFormat->wBitsPerSample);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-09-11 07:46:43 +02:00
|
|
|
/* nBlockAlign and nAvgBytesPerSec are output variables for dsound */
|
|
|
|
if (lpDesc->lpFormat->nBlockAlign != lpDesc->lpFormat->nChannels*lpDesc->lpFormat->wBitsPerSample/8) {
|
|
|
|
lpDesc->lpFormat->nBlockAlign = lpDesc->lpFormat->nChannels*lpDesc->lpFormat->wBitsPerSample/8;
|
|
|
|
WARN("Fixing nBlockAlign\n");
|
|
|
|
}
|
|
|
|
if (lpDesc->lpFormat->nAvgBytesPerSec!= lpDesc->lpFormat->nSamplesPerSec*lpDesc->lpFormat->nBlockAlign) {
|
|
|
|
lpDesc->lpFormat->nAvgBytesPerSec = lpDesc->lpFormat->nSamplesPerSec*lpDesc->lpFormat->nBlockAlign;
|
|
|
|
WARN("Fixing nAvgBytesPerSec\n");
|
|
|
|
}
|
|
|
|
|
2006-12-28 18:05:31 +01:00
|
|
|
wwi = &WInDev[wDevID];
|
|
|
|
if (!OSSpinLockTry(&wwi->lock))
|
|
|
|
return MMSYSERR_ALLOCATED;
|
|
|
|
|
|
|
|
if (wwi->state != WINE_WS_CLOSED)
|
|
|
|
{
|
|
|
|
OSSpinLockUnlock(&wwi->lock);
|
|
|
|
return MMSYSERR_ALLOCATED;
|
|
|
|
}
|
|
|
|
|
|
|
|
wwi->state = WINE_WS_STOPPED;
|
|
|
|
wwi->wFlags = HIWORD(dwFlags & CALLBACK_TYPEMASK);
|
|
|
|
|
2008-03-25 23:22:16 +01:00
|
|
|
wwi->waveDesc = *lpDesc;
|
2009-09-11 08:12:53 +02:00
|
|
|
copyFormat(lpDesc->lpFormat, &wwi->format);
|
2006-12-28 18:05:31 +01:00
|
|
|
|
|
|
|
wwi->dwTotalRecorded = 0;
|
|
|
|
|
|
|
|
wwi->trace_on = TRACE_ON(wave);
|
|
|
|
wwi->warn_on = WARN_ON(wave);
|
|
|
|
wwi->err_on = ERR_ON(wave);
|
|
|
|
|
|
|
|
if (!AudioUnit_CreateInputUnit(wwi, &wwi->audioUnit,
|
|
|
|
wwi->format.wf.nChannels, wwi->format.wf.nSamplesPerSec,
|
2006-12-28 18:06:23 +01:00
|
|
|
wwi->format.wBitsPerSample, &frameCount))
|
2006-12-28 18:05:31 +01:00
|
|
|
{
|
|
|
|
OSSpinLockUnlock(&wwi->lock);
|
2009-10-17 15:25:51 +02:00
|
|
|
ERR("AudioUnit_CreateInputUnit failed\n");
|
2006-12-28 18:05:31 +01:00
|
|
|
return MMSYSERR_ERROR;
|
|
|
|
}
|
|
|
|
|
2006-12-28 18:06:29 +01:00
|
|
|
/* Allocate our audio buffers */
|
2007-07-13 14:21:29 +02:00
|
|
|
wwi->bufferList = widHelper_AllocateAudioBufferList(wwi->format.wf.nChannels,
|
|
|
|
wwi->format.wBitsPerSample, frameCount, TRUE);
|
2006-12-28 18:06:29 +01:00
|
|
|
if (wwi->bufferList == NULL)
|
|
|
|
{
|
|
|
|
AudioUnitUninitialize(wwi->audioUnit);
|
|
|
|
AudioUnit_CloseAudioUnit(wwi->audioUnit);
|
|
|
|
OSSpinLockUnlock(&wwi->lock);
|
2009-10-17 15:25:51 +02:00
|
|
|
ERR("Failed to allocate buffer list\n");
|
2006-12-28 18:06:29 +01:00
|
|
|
return MMSYSERR_NOMEM;
|
|
|
|
}
|
|
|
|
|
2007-07-13 14:21:36 +02:00
|
|
|
/* Keep a copy of the buffer list structure (but not the buffers themselves)
|
2009-10-11 21:14:36 +02:00
|
|
|
* in case AudioUnitRender clobbers the original, as it tends to do. */
|
2007-07-13 14:21:36 +02:00
|
|
|
wwi->bufferListCopy = HeapAlloc(GetProcessHeap(), 0, AUDIOBUFFERLISTSIZE(wwi->bufferList->mNumberBuffers));
|
|
|
|
if (wwi->bufferListCopy == NULL)
|
|
|
|
{
|
|
|
|
widHelper_DestroyAudioBufferList(wwi->bufferList);
|
|
|
|
AudioUnitUninitialize(wwi->audioUnit);
|
|
|
|
AudioUnit_CloseAudioUnit(wwi->audioUnit);
|
|
|
|
OSSpinLockUnlock(&wwi->lock);
|
2009-10-17 15:25:51 +02:00
|
|
|
ERR("Failed to allocate buffer list copy\n");
|
2007-07-13 14:21:36 +02:00
|
|
|
return MMSYSERR_NOMEM;
|
|
|
|
}
|
|
|
|
memcpy(wwi->bufferListCopy, wwi->bufferList, AUDIOBUFFERLISTSIZE(wwi->bufferList->mNumberBuffers));
|
|
|
|
|
2006-12-28 18:05:31 +01:00
|
|
|
OSSpinLockUnlock(&wwi->lock);
|
|
|
|
|
|
|
|
return widNotifyClient(wwi, WIM_OPEN, 0L, 0L);
|
2006-12-28 18:03:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* widClose [internal]
|
|
|
|
*/
|
|
|
|
static DWORD widClose(WORD wDevID)
|
|
|
|
{
|
2006-12-28 18:05:31 +01:00
|
|
|
DWORD ret = MMSYSERR_NOERROR;
|
|
|
|
WINE_WAVEIN* wwi;
|
2009-04-11 14:18:30 +02:00
|
|
|
OSStatus err;
|
2006-12-28 18:05:31 +01:00
|
|
|
|
2006-12-28 18:03:26 +01:00
|
|
|
TRACE("(%u);\n", wDevID);
|
|
|
|
|
|
|
|
if (wDevID >= MAX_WAVEINDRV)
|
|
|
|
{
|
|
|
|
WARN("bad device ID !\n");
|
|
|
|
return MMSYSERR_BADDEVICEID;
|
|
|
|
}
|
|
|
|
|
2006-12-28 18:05:31 +01:00
|
|
|
wwi = &WInDev[wDevID];
|
|
|
|
OSSpinLockLock(&wwi->lock);
|
2009-04-11 14:18:30 +02:00
|
|
|
if (wwi->state == WINE_WS_CLOSED || wwi->state == WINE_WS_CLOSING)
|
2006-12-28 18:05:31 +01:00
|
|
|
{
|
|
|
|
WARN("Device already closed.\n");
|
|
|
|
ret = MMSYSERR_INVALHANDLE;
|
|
|
|
}
|
|
|
|
else if (wwi->lpQueuePtr)
|
|
|
|
{
|
|
|
|
WARN("Buffers in queue.\n");
|
|
|
|
ret = WAVERR_STILLPLAYING;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-04-11 14:18:30 +02:00
|
|
|
wwi->state = WINE_WS_CLOSING;
|
2006-12-28 18:05:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
OSSpinLockUnlock(&wwi->lock);
|
|
|
|
|
2009-04-11 14:18:30 +02:00
|
|
|
if (ret != MMSYSERR_NOERROR)
|
|
|
|
return ret;
|
2006-12-28 18:05:31 +01:00
|
|
|
|
|
|
|
|
2009-04-11 14:18:30 +02:00
|
|
|
/* Clean up and close the audio unit. This has to be done without
|
|
|
|
* wwi->lock being held to avoid deadlock. AudioUnitUninitialize will
|
|
|
|
* grab an internal Core Audio lock while waiting for the device work
|
|
|
|
* thread to exit. Meanwhile the device work thread may be holding
|
|
|
|
* that lock and trying to grab the wwi->lock in the callback. */
|
|
|
|
err = AudioUnitUninitialize(wwi->audioUnit);
|
|
|
|
if (err)
|
2009-10-11 21:11:19 +02:00
|
|
|
ERR("AudioUnitUninitialize return %s\n", wine_dbgstr_fourcc(err));
|
2006-12-28 18:06:29 +01:00
|
|
|
|
2009-04-11 14:18:30 +02:00
|
|
|
if (!AudioUnit_CloseAudioUnit(wwi->audioUnit))
|
|
|
|
ERR("Can't close AudioUnit\n");
|
2006-12-28 18:05:31 +01:00
|
|
|
|
2009-04-11 14:18:30 +02:00
|
|
|
|
|
|
|
OSSpinLockLock(&wwi->lock);
|
|
|
|
assert(wwi->state == WINE_WS_CLOSING);
|
|
|
|
|
|
|
|
/* Dellocate our audio buffers */
|
|
|
|
widHelper_DestroyAudioBufferList(wwi->bufferList);
|
|
|
|
wwi->bufferList = NULL;
|
|
|
|
HeapFree(GetProcessHeap(), 0, wwi->bufferListCopy);
|
|
|
|
wwi->bufferListCopy = NULL;
|
|
|
|
|
|
|
|
wwi->audioUnit = NULL;
|
|
|
|
wwi->state = WINE_WS_CLOSED;
|
|
|
|
OSSpinLockUnlock(&wwi->lock);
|
|
|
|
|
|
|
|
ret = widNotifyClient(wwi, WIM_CLOSE, 0L, 0L);
|
|
|
|
|
2006-12-28 18:05:31 +01:00
|
|
|
return ret;
|
2006-12-28 18:03:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* widAddBuffer [internal]
|
|
|
|
*/
|
|
|
|
static DWORD widAddBuffer(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize)
|
|
|
|
{
|
2006-12-28 18:06:02 +01:00
|
|
|
DWORD ret = MMSYSERR_NOERROR;
|
|
|
|
WINE_WAVEIN* wwi;
|
|
|
|
|
2006-12-28 18:03:26 +01:00
|
|
|
TRACE("(%u, %p, %08X);\n", wDevID, lpWaveHdr, dwSize);
|
|
|
|
|
|
|
|
if (wDevID >= MAX_WAVEINDRV)
|
|
|
|
{
|
|
|
|
WARN("invalid device ID\n");
|
|
|
|
return MMSYSERR_INVALHANDLE;
|
|
|
|
}
|
|
|
|
if (!(lpWaveHdr->dwFlags & WHDR_PREPARED))
|
|
|
|
{
|
|
|
|
TRACE("never been prepared !\n");
|
|
|
|
return WAVERR_UNPREPARED;
|
|
|
|
}
|
|
|
|
if (lpWaveHdr->dwFlags & WHDR_INQUEUE)
|
|
|
|
{
|
|
|
|
TRACE("header already in use !\n");
|
|
|
|
return WAVERR_STILLPLAYING;
|
|
|
|
}
|
|
|
|
|
2006-12-28 18:06:02 +01:00
|
|
|
wwi = &WInDev[wDevID];
|
|
|
|
OSSpinLockLock(&wwi->lock);
|
|
|
|
|
2009-04-11 14:18:30 +02:00
|
|
|
if (wwi->state == WINE_WS_CLOSED || wwi->state == WINE_WS_CLOSING)
|
2006-12-28 18:06:02 +01:00
|
|
|
{
|
|
|
|
WARN("Trying to add buffer to closed device.\n");
|
|
|
|
ret = MMSYSERR_INVALHANDLE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LPWAVEHDR* wh;
|
|
|
|
|
|
|
|
lpWaveHdr->dwFlags |= WHDR_INQUEUE;
|
|
|
|
lpWaveHdr->dwFlags &= ~WHDR_DONE;
|
|
|
|
lpWaveHdr->dwBytesRecorded = 0;
|
|
|
|
lpWaveHdr->lpNext = NULL;
|
|
|
|
|
|
|
|
/* insert buffer at end of queue */
|
|
|
|
for (wh = &(wwi->lpQueuePtr); *wh; wh = &((*wh)->lpNext))
|
|
|
|
/* Do nothing */;
|
|
|
|
*wh = lpWaveHdr;
|
|
|
|
}
|
|
|
|
|
|
|
|
OSSpinLockUnlock(&wwi->lock);
|
|
|
|
|
|
|
|
return ret;
|
2006-12-28 18:03:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* widStart [internal]
|
|
|
|
*/
|
|
|
|
static DWORD widStart(WORD wDevID)
|
|
|
|
{
|
2006-12-28 18:07:08 +01:00
|
|
|
DWORD ret = MMSYSERR_NOERROR;
|
|
|
|
WINE_WAVEIN* wwi;
|
|
|
|
|
2006-12-28 18:03:26 +01:00
|
|
|
TRACE("(%u);\n", wDevID);
|
|
|
|
if (wDevID >= MAX_WAVEINDRV)
|
|
|
|
{
|
|
|
|
WARN("invalid device ID\n");
|
|
|
|
return MMSYSERR_INVALHANDLE;
|
|
|
|
}
|
|
|
|
|
2006-12-28 18:07:08 +01:00
|
|
|
/* The order of the following operations is important since we can't hold
|
|
|
|
* the mutex while we make an Audio Unit call. Set the PLAYING state
|
|
|
|
* before starting the Audio Unit. In widStop, the order is reversed.
|
|
|
|
* This guarantees that we can't get into a situation where the state is
|
|
|
|
* PLAYING but the Audio Unit isn't running. Although we can be in STOPPED
|
|
|
|
* state with the Audio Unit still running, that's harmless because the
|
|
|
|
* input callback will just throw away the sound data.
|
|
|
|
*/
|
|
|
|
wwi = &WInDev[wDevID];
|
|
|
|
OSSpinLockLock(&wwi->lock);
|
|
|
|
|
2009-04-11 14:18:30 +02:00
|
|
|
if (wwi->state == WINE_WS_CLOSED || wwi->state == WINE_WS_CLOSING)
|
2006-12-28 18:07:08 +01:00
|
|
|
{
|
|
|
|
WARN("Trying to start closed device.\n");
|
|
|
|
ret = MMSYSERR_INVALHANDLE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
wwi->state = WINE_WS_PLAYING;
|
|
|
|
|
|
|
|
OSSpinLockUnlock(&wwi->lock);
|
|
|
|
|
|
|
|
if (ret == MMSYSERR_NOERROR)
|
|
|
|
{
|
|
|
|
/* Start pulling for audio data */
|
|
|
|
OSStatus err = AudioOutputUnitStart(wwi->audioUnit);
|
|
|
|
if (err != noErr)
|
|
|
|
ERR("Failed to start AU: %08lx\n", err);
|
|
|
|
|
|
|
|
TRACE("Recording started...\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2006-12-28 18:03:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* widStop [internal]
|
|
|
|
*/
|
|
|
|
static DWORD widStop(WORD wDevID)
|
|
|
|
{
|
2006-12-28 18:07:02 +01:00
|
|
|
DWORD ret = MMSYSERR_NOERROR;
|
|
|
|
WINE_WAVEIN* wwi;
|
|
|
|
WAVEHDR* lpWaveHdr = NULL;
|
|
|
|
OSStatus err;
|
|
|
|
|
2006-12-28 18:03:26 +01:00
|
|
|
TRACE("(%u);\n", wDevID);
|
|
|
|
if (wDevID >= MAX_WAVEINDRV)
|
|
|
|
{
|
|
|
|
WARN("invalid device ID\n");
|
|
|
|
return MMSYSERR_INVALHANDLE;
|
|
|
|
}
|
|
|
|
|
2006-12-28 18:07:02 +01:00
|
|
|
wwi = &WInDev[wDevID];
|
|
|
|
|
|
|
|
/* The order of the following operations is important since we can't hold
|
|
|
|
* the mutex while we make an Audio Unit call. Stop the Audio Unit before
|
|
|
|
* setting the STOPPED state. In widStart, the order is reversed. This
|
|
|
|
* guarantees that we can't get into a situation where the state is
|
|
|
|
* PLAYING but the Audio Unit isn't running. Although we can be in STOPPED
|
|
|
|
* state with the Audio Unit still running, that's harmless because the
|
|
|
|
* input callback will just throw away the sound data.
|
|
|
|
*/
|
|
|
|
err = AudioOutputUnitStop(wwi->audioUnit);
|
|
|
|
if (err != noErr)
|
|
|
|
WARN("Failed to stop AU: %08lx\n", err);
|
|
|
|
|
|
|
|
TRACE("Recording stopped.\n");
|
|
|
|
|
|
|
|
OSSpinLockLock(&wwi->lock);
|
|
|
|
|
2009-04-11 14:18:30 +02:00
|
|
|
if (wwi->state == WINE_WS_CLOSED || wwi->state == WINE_WS_CLOSING)
|
2006-12-28 18:07:02 +01:00
|
|
|
{
|
|
|
|
WARN("Trying to stop closed device.\n");
|
|
|
|
ret = MMSYSERR_INVALHANDLE;
|
|
|
|
}
|
|
|
|
else if (wwi->state != WINE_WS_STOPPED)
|
|
|
|
{
|
|
|
|
wwi->state = WINE_WS_STOPPED;
|
|
|
|
/* If there's a buffer in progress, it's done. Remove it from the
|
|
|
|
* queue so that we can return it to the app, below. */
|
|
|
|
if (wwi->lpQueuePtr)
|
|
|
|
{
|
|
|
|
lpWaveHdr = wwi->lpQueuePtr;
|
|
|
|
wwi->lpQueuePtr = lpWaveHdr->lpNext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
OSSpinLockUnlock(&wwi->lock);
|
|
|
|
|
|
|
|
if (lpWaveHdr)
|
|
|
|
{
|
2007-07-12 03:34:45 +02:00
|
|
|
lpWaveHdr->lpNext = NULL;
|
2006-12-28 18:07:02 +01:00
|
|
|
lpWaveHdr->dwFlags &= ~WHDR_INQUEUE;
|
|
|
|
lpWaveHdr->dwFlags |= WHDR_DONE;
|
|
|
|
widNotifyClient(wwi, WIM_DATA, (DWORD)lpWaveHdr, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2006-12-28 18:03:26 +01:00
|
|
|
}
|
|
|
|
|
2007-11-28 11:37:58 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* widGetPos [internal]
|
|
|
|
*/
|
|
|
|
static DWORD widGetPos(WORD wDevID, LPMMTIME lpTime, UINT size)
|
|
|
|
{
|
|
|
|
DWORD val;
|
|
|
|
WINE_WAVEIN* wwi;
|
|
|
|
|
|
|
|
TRACE("(%u);\n", wDevID);
|
|
|
|
if (wDevID >= MAX_WAVEINDRV)
|
|
|
|
{
|
|
|
|
WARN("invalid device ID\n");
|
|
|
|
return MMSYSERR_INVALHANDLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
wwi = &WInDev[wDevID];
|
|
|
|
|
|
|
|
OSSpinLockLock(&WInDev[wDevID].lock);
|
|
|
|
val = wwi->dwTotalRecorded;
|
|
|
|
OSSpinLockUnlock(&WInDev[wDevID].lock);
|
|
|
|
|
|
|
|
return bytes_to_mmtime(lpTime, val, &wwi->format);
|
|
|
|
}
|
2006-12-28 18:03:26 +01:00
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* widReset [internal]
|
|
|
|
*/
|
|
|
|
static DWORD widReset(WORD wDevID)
|
|
|
|
{
|
2006-12-28 18:06:09 +01:00
|
|
|
DWORD ret = MMSYSERR_NOERROR;
|
|
|
|
WINE_WAVEIN* wwi;
|
|
|
|
WAVEHDR* lpWaveHdr = NULL;
|
|
|
|
|
2006-12-28 18:03:26 +01:00
|
|
|
TRACE("(%u);\n", wDevID);
|
|
|
|
if (wDevID >= MAX_WAVEINDRV)
|
|
|
|
{
|
|
|
|
WARN("invalid device ID\n");
|
|
|
|
return MMSYSERR_INVALHANDLE;
|
|
|
|
}
|
|
|
|
|
2006-12-28 18:06:09 +01:00
|
|
|
wwi = &WInDev[wDevID];
|
|
|
|
OSSpinLockLock(&wwi->lock);
|
|
|
|
|
2009-04-11 14:18:30 +02:00
|
|
|
if (wwi->state == WINE_WS_CLOSED || wwi->state == WINE_WS_CLOSING)
|
2006-12-28 18:06:09 +01:00
|
|
|
{
|
|
|
|
WARN("Trying to reset a closed device.\n");
|
|
|
|
ret = MMSYSERR_INVALHANDLE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
lpWaveHdr = wwi->lpQueuePtr;
|
|
|
|
wwi->lpQueuePtr = NULL;
|
|
|
|
wwi->state = WINE_WS_STOPPED;
|
|
|
|
wwi->dwTotalRecorded = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
OSSpinLockUnlock(&wwi->lock);
|
|
|
|
|
2006-12-28 18:06:56 +01:00
|
|
|
if (ret == MMSYSERR_NOERROR)
|
|
|
|
{
|
|
|
|
OSStatus err = AudioOutputUnitStop(wwi->audioUnit);
|
|
|
|
if (err != noErr)
|
|
|
|
WARN("Failed to stop AU: %08lx\n", err);
|
|
|
|
|
|
|
|
TRACE("Recording stopped.\n");
|
|
|
|
}
|
|
|
|
|
2006-12-28 18:06:09 +01:00
|
|
|
while (lpWaveHdr)
|
|
|
|
{
|
|
|
|
WAVEHDR* lpNext = lpWaveHdr->lpNext;
|
|
|
|
|
2007-07-12 03:34:45 +02:00
|
|
|
lpWaveHdr->lpNext = NULL;
|
2006-12-28 18:06:09 +01:00
|
|
|
lpWaveHdr->dwFlags &= ~WHDR_INQUEUE;
|
|
|
|
lpWaveHdr->dwFlags |= WHDR_DONE;
|
|
|
|
widNotifyClient(wwi, WIM_DATA, (DWORD)lpWaveHdr, 0);
|
|
|
|
|
|
|
|
lpWaveHdr = lpNext;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2006-12-28 18:03:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* widGetNumDevs [internal]
|
|
|
|
*/
|
|
|
|
static DWORD widGetNumDevs(void)
|
|
|
|
{
|
|
|
|
return MAX_WAVEINDRV;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* widDevInterfaceSize [internal]
|
|
|
|
*/
|
|
|
|
static DWORD widDevInterfaceSize(UINT wDevID, LPDWORD dwParam1)
|
|
|
|
{
|
|
|
|
TRACE("(%u, %p)\n", wDevID, dwParam1);
|
|
|
|
|
2009-01-02 13:13:47 +01:00
|
|
|
*dwParam1 = MultiByteToWideChar(CP_UNIXCP, 0, WInDev[wDevID].interface_name, -1,
|
2006-12-28 18:06:16 +01:00
|
|
|
NULL, 0 ) * sizeof(WCHAR);
|
|
|
|
return MMSYSERR_NOERROR;
|
2006-12-28 18:03:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* widDevInterface [internal]
|
|
|
|
*/
|
|
|
|
static DWORD widDevInterface(UINT wDevID, PWCHAR dwParam1, DWORD dwParam2)
|
|
|
|
{
|
2009-01-02 13:13:47 +01:00
|
|
|
if (dwParam2 >= MultiByteToWideChar(CP_UNIXCP, 0, WInDev[wDevID].interface_name, -1,
|
2006-12-28 18:06:16 +01:00
|
|
|
NULL, 0 ) * sizeof(WCHAR))
|
|
|
|
{
|
2009-01-02 13:13:47 +01:00
|
|
|
MultiByteToWideChar(CP_UNIXCP, 0, WInDev[wDevID].interface_name, -1,
|
2006-12-28 18:06:16 +01:00
|
|
|
dwParam1, dwParam2 / sizeof(WCHAR));
|
|
|
|
return MMSYSERR_NOERROR;
|
|
|
|
}
|
|
|
|
return MMSYSERR_INVALPARAM;
|
2006-12-28 18:03:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-12 03:34:38 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* widDsCreate [internal]
|
|
|
|
*/
|
|
|
|
static DWORD widDsCreate(UINT wDevID, PIDSCDRIVER* drv)
|
|
|
|
{
|
|
|
|
TRACE("(%d,%p)\n",wDevID,drv);
|
|
|
|
|
|
|
|
FIXME("DirectSoundCapture not implemented\n");
|
|
|
|
FIXME("The (slower) DirectSound HEL mode will be used instead.\n");
|
|
|
|
return MMSYSERR_NOTSUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* widDsDesc [internal]
|
|
|
|
*/
|
|
|
|
static DWORD widDsDesc(UINT wDevID, PDSDRIVERDESC desc)
|
|
|
|
{
|
|
|
|
/* The DirectSound HEL will automatically wrap a non-DirectSound-capable
|
|
|
|
* driver in a DirectSound adaptor, thus allowing the driver to be used by
|
|
|
|
* DirectSound clients. However, it only does this if we respond
|
|
|
|
* successfully to the DRV_QUERYDSOUNDDESC message. It's enough to fill in
|
|
|
|
* the driver and device names of the description output parameter. */
|
|
|
|
memset(desc, 0, sizeof(*desc));
|
|
|
|
lstrcpynA(desc->szDrvname, "winecoreaudio.drv", sizeof(desc->szDrvname) - 1);
|
|
|
|
lstrcpynA(desc->szDesc, WInDev[wDevID].interface_name, sizeof(desc->szDesc) - 1);
|
|
|
|
return MMSYSERR_NOERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-28 18:03:26 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* widMessage (WINECOREAUDIO.6)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI CoreAudio_widMessage(WORD wDevID, WORD wMsg, DWORD dwUser,
|
|
|
|
DWORD dwParam1, DWORD dwParam2)
|
|
|
|
{
|
|
|
|
TRACE("(%u, %04X, %08X, %08X, %08X);\n",
|
|
|
|
wDevID, wMsg, dwUser, dwParam1, dwParam2);
|
|
|
|
|
|
|
|
switch (wMsg)
|
|
|
|
{
|
|
|
|
case DRVM_INIT:
|
|
|
|
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_RESET: return widReset (wDevID);
|
|
|
|
case WIDM_START: return widStart (wDevID);
|
|
|
|
case WIDM_STOP: return widStop (wDevID);
|
2007-11-28 11:37:58 +01:00
|
|
|
case WIDM_GETPOS: return widGetPos (wDevID, (LPMMTIME)dwParam1, (UINT)dwParam2 );
|
2006-12-28 18:03:26 +01:00
|
|
|
case DRV_QUERYDEVICEINTERFACESIZE: return widDevInterfaceSize (wDevID, (LPDWORD)dwParam1);
|
|
|
|
case DRV_QUERYDEVICEINTERFACE: return widDevInterface (wDevID, (PWCHAR)dwParam1, dwParam2);
|
2007-07-12 03:34:38 +02:00
|
|
|
case DRV_QUERYDSOUNDIFACE: return widDsCreate (wDevID, (PIDSCDRIVER*)dwParam1);
|
|
|
|
case DRV_QUERYDSOUNDDESC: return widDsDesc (wDevID, (PDSDRIVERDESC)dwParam1);
|
2006-12-28 18:03:26 +01:00
|
|
|
default:
|
|
|
|
FIXME("unknown message %d!\n", wMsg);
|
|
|
|
}
|
|
|
|
|
|
|
|
return MMSYSERR_NOTSUPPORTED;
|
|
|
|
}
|
|
|
|
|
2006-12-28 18:05:15 +01:00
|
|
|
|
|
|
|
OSStatus CoreAudio_wiAudioUnitIOProc(void *inRefCon,
|
|
|
|
AudioUnitRenderActionFlags *ioActionFlags,
|
|
|
|
const AudioTimeStamp *inTimeStamp,
|
|
|
|
UInt32 inBusNumber,
|
|
|
|
UInt32 inNumberFrames,
|
|
|
|
AudioBufferList *ioData)
|
|
|
|
{
|
2006-12-28 18:07:16 +01:00
|
|
|
WINE_WAVEIN* wwi = (WINE_WAVEIN*)inRefCon;
|
|
|
|
OSStatus err = noErr;
|
|
|
|
BOOL needNotify = FALSE;
|
|
|
|
WAVEHDR* lpStorePtr;
|
|
|
|
unsigned int dataToStore;
|
|
|
|
unsigned int dataStored = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (wwi->trace_on)
|
2007-01-17 23:05:50 +01:00
|
|
|
fprintf(stderr, "trace:wave:CoreAudio_wiAudioUnitIOProc (ioActionFlags = %08lx, "
|
2007-01-18 13:27:55 +01:00
|
|
|
"inTimeStamp = { %f, %x%08x, %f, %x%08x, %08lx }, inBusNumber = %lu, inNumberFrames = %lu)\n",
|
2007-01-17 23:05:50 +01:00
|
|
|
*ioActionFlags, inTimeStamp->mSampleTime, (DWORD)(inTimeStamp->mHostTime >>32),
|
|
|
|
(DWORD)inTimeStamp->mHostTime, inTimeStamp->mRateScalar, (DWORD)(inTimeStamp->mWordClockTime >> 32),
|
|
|
|
(DWORD)inTimeStamp->mWordClockTime, inTimeStamp->mFlags, inBusNumber, inNumberFrames);
|
2006-12-28 18:07:16 +01:00
|
|
|
|
|
|
|
/* Render into audio buffer */
|
2006-12-28 18:07:24 +01:00
|
|
|
/* FIXME: implement sample rate conversion on input. This will require
|
|
|
|
* a different render strategy. We'll need to buffer the sound data
|
|
|
|
* received here and pass it off to an AUConverter in another thread. */
|
2006-12-28 18:07:16 +01:00
|
|
|
err = AudioUnitRender(wwi->audioUnit, ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, wwi->bufferList);
|
|
|
|
if (err)
|
|
|
|
{
|
|
|
|
if (wwi->err_on)
|
|
|
|
fprintf(stderr, "err:wave:CoreAudio_wiAudioUnitIOProc AudioUnitRender failed with error %li\n", err);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy from audio buffer to the wavehdrs */
|
|
|
|
dataToStore = wwi->bufferList->mBuffers[0].mDataByteSize;
|
|
|
|
|
|
|
|
OSSpinLockLock(&wwi->lock);
|
|
|
|
|
|
|
|
lpStorePtr = wwi->lpQueuePtr;
|
|
|
|
|
2009-04-11 14:18:30 +02:00
|
|
|
/* We might have been called while the waveIn device is being closed in
|
|
|
|
* widClose. We have to do nothing in that case. The check of wwi->state
|
|
|
|
* below ensures that. */
|
2006-12-28 18:07:16 +01:00
|
|
|
while (dataToStore > 0 && wwi->state == WINE_WS_PLAYING && lpStorePtr)
|
|
|
|
{
|
|
|
|
unsigned int room = lpStorePtr->dwBufferLength - lpStorePtr->dwBytesRecorded;
|
|
|
|
unsigned int toCopy;
|
|
|
|
|
|
|
|
if (wwi->trace_on)
|
|
|
|
fprintf(stderr, "trace:wave:CoreAudio_wiAudioUnitIOProc Looking to store %u bytes to wavehdr %p, which has room for %u\n",
|
|
|
|
dataToStore, lpStorePtr, room);
|
|
|
|
|
|
|
|
if (room >= dataToStore)
|
|
|
|
toCopy = dataToStore;
|
|
|
|
else
|
|
|
|
toCopy = room;
|
|
|
|
|
|
|
|
if (toCopy > 0)
|
|
|
|
{
|
|
|
|
memcpy(lpStorePtr->lpData + lpStorePtr->dwBytesRecorded,
|
|
|
|
(char*)wwi->bufferList->mBuffers[0].mData + dataStored, toCopy);
|
|
|
|
lpStorePtr->dwBytesRecorded += toCopy;
|
|
|
|
wwi->dwTotalRecorded += toCopy;
|
|
|
|
dataStored += toCopy;
|
|
|
|
dataToStore -= toCopy;
|
|
|
|
room -= toCopy;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (room == 0)
|
|
|
|
{
|
|
|
|
lpStorePtr = lpStorePtr->lpNext;
|
|
|
|
needNotify = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
OSSpinLockUnlock(&wwi->lock);
|
|
|
|
|
2007-07-13 14:21:36 +02:00
|
|
|
/* Restore the audio buffer list structure from backup, in case
|
|
|
|
* AudioUnitRender clobbered it. (It modifies mDataByteSize and may even
|
|
|
|
* give us a different mData buffer to avoid a copy.) */
|
|
|
|
memcpy(wwi->bufferList, wwi->bufferListCopy, AUDIOBUFFERLISTSIZE(wwi->bufferList->mNumberBuffers));
|
|
|
|
|
2006-12-28 18:07:16 +01:00
|
|
|
if (needNotify) wodSendNotifyInputCompletionsMessage(wwi);
|
|
|
|
return err;
|
2006-12-28 18:05:15 +01:00
|
|
|
}
|
|
|
|
|
2006-05-28 22:46:23 +02:00
|
|
|
#else
|
|
|
|
|
2006-12-28 18:03:26 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* widMessage (WINECOREAUDIO.6)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI CoreAudio_widMessage(WORD wDevID, WORD wMsg, DWORD dwUser,
|
|
|
|
DWORD dwParam1, DWORD dwParam2)
|
|
|
|
{
|
|
|
|
FIXME("(%u, %04X, %08X, %08X, %08X): CoreAudio support not compiled into wine\n", wDevID, wMsg, dwUser, dwParam1, dwParam2);
|
|
|
|
return MMSYSERR_NOTENABLED;
|
|
|
|
}
|
|
|
|
|
2006-05-28 22:46:23 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* wodMessage (WINECOREAUDIO.7)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI CoreAudio_wodMessage(WORD wDevID, WORD wMsg, DWORD dwUser,
|
|
|
|
DWORD dwParam1, DWORD dwParam2)
|
|
|
|
{
|
2006-10-20 12:36:38 +02:00
|
|
|
FIXME("(%u, %04X, %08X, %08X, %08X): CoreAudio support not compiled into wine\n", wDevID, wMsg, dwUser, dwParam1, dwParam2);
|
2006-05-28 22:46:23 +02:00
|
|
|
return MMSYSERR_NOTENABLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|