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>
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winnls.h"
|
|
|
|
#include "wingdi.h"
|
|
|
|
#include "winerror.h"
|
|
|
|
#include "mmddk.h"
|
|
|
|
#include "dsound.h"
|
|
|
|
#include "dsdriver.h"
|
|
|
|
#include "coreaudio.h"
|
|
|
|
#include "wine/unicode.h"
|
|
|
|
#include "wine/library.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
/*
|
|
|
|
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 |
|
|
|
|
* +---------+-------------+---------------+---------------------------------+
|
|
|
|
* | | open() | | STOPPED |
|
|
|
|
* | PAUSED | write() | | PAUSED |
|
|
|
|
* | STOPPED | write() | <thrd create> | PLAYING |
|
|
|
|
* | PLAYING | write() | HEADER | PLAYING |
|
|
|
|
* | (other) | write() | <error> | |
|
|
|
|
* | (any) | pause() | PAUSING | PAUSED |
|
|
|
|
* | PAUSED | restart() | RESTARTING | PLAYING (if no thrd => STOPPED) |
|
|
|
|
* | (any) | reset() | RESETTING | STOPPED |
|
|
|
|
* | (any) | close() | CLOSING | CLOSED |
|
|
|
|
* +---------+-------------+---------------+---------------------------------+
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* states of the playing device */
|
|
|
|
#define WINE_WS_PLAYING 0
|
|
|
|
#define WINE_WS_PAUSED 1
|
|
|
|
#define WINE_WS_STOPPED 2
|
|
|
|
#define WINE_WS_CLOSED 3
|
|
|
|
|
|
|
|
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 {
|
|
|
|
volatile int state; /* one of the WINE_WS_ manifest constants */
|
|
|
|
CoreAudio_Device *cadev;
|
|
|
|
WAVEOPENDESC waveDesc;
|
|
|
|
WORD wFlags;
|
|
|
|
PCMWAVEFORMAT format;
|
|
|
|
DWORD woID;
|
|
|
|
AudioUnit audioUnit;
|
|
|
|
AudioStreamBasicDescription streamDescription;
|
|
|
|
|
|
|
|
WAVEOUTCAPSW caps;
|
|
|
|
char interface_name[32];
|
|
|
|
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 */
|
|
|
|
DWORD dwWrittenTotal; /* number of bytes written to OSS buffer since opening */
|
|
|
|
|
|
|
|
DWORD tickCountMS; /* time in MS of last AudioUnit callback */
|
|
|
|
|
2006-12-21 10:50:18 +01:00
|
|
|
OSSpinLock lock; /* synchronization stuff */
|
2006-12-21 10:46:55 +01:00
|
|
|
|
|
|
|
BOOL trace_on;
|
|
|
|
BOOL warn_on;
|
|
|
|
BOOL err_on;
|
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;
|
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
|
|
|
|
2006-12-21 10:48:52 +01:00
|
|
|
static void wodHelper_PlayPtrNext(WINE_WAVEOUT* wwo);
|
2006-12-21 10:49:43 +01:00
|
|
|
static void wodHelper_NotifyCompletions(WINE_WAVEOUT* 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:
|
2006-05-28 22:46:23 +02:00
|
|
|
buffer = (UInt32 *) CFDataGetBytePtr(data);
|
2006-12-21 10:49:43 +01:00
|
|
|
wodHelper_NotifyCompletions(&WOutDev[buffer[0]], 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.
|
|
|
|
*/
|
|
|
|
static void wodSendNotifyCompletionsMessage(WINE_WAVEOUT* wwo)
|
2006-05-28 22:46:23 +02:00
|
|
|
{
|
|
|
|
CFDataRef data;
|
2006-12-21 10:49:43 +01:00
|
|
|
UInt32 buffer;
|
|
|
|
|
|
|
|
buffer = (UInt32) wwo->woID;
|
2006-05-24 12:45:14 +02:00
|
|
|
|
2006-12-21 10:49:43 +01:00
|
|
|
data = CFDataCreate(kCFAllocatorDefault, (UInt8 *)&buffer, sizeof(buffer));
|
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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* 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) {
|
|
|
|
ERR("AudioHardwareGetProperty for kAudioDevicePropertyDeviceName return %c%c%c%c\n", (char) (status >> 24),
|
|
|
|
(char) (status >> 16),
|
|
|
|
(char) (status >> 8),
|
|
|
|
(char) status);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(CoreAudio_DefaultDevice.ds_desc.szDesc, name, sizeof(name));
|
|
|
|
strcpy(CoreAudio_DefaultDevice.ds_desc.szDrvname, "winecoreaudio.drv");
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, name, sizeof(name),
|
|
|
|
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) {
|
|
|
|
ERR("AudioHardwareGetProperty for kAudioDevicePropertyStreamFormat return %c%c%c%c\n", (char) (status >> 24),
|
|
|
|
(char) (status >> 16),
|
|
|
|
(char) (status >> 8),
|
|
|
|
(char) status);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Device Stream Description mSampleRate : %f\n mFormatID : %c%c%c%c\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,
|
|
|
|
(char) (CoreAudio_DefaultDevice.streamDescription.mFormatID >> 24),
|
|
|
|
(char) (CoreAudio_DefaultDevice.streamDescription.mFormatID >> 16),
|
|
|
|
(char) (CoreAudio_DefaultDevice.streamDescription.mFormatID >> 8),
|
|
|
|
(char) CoreAudio_DefaultDevice.streamDescription.mFormatID,
|
|
|
|
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;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* CoreAudio_WaveInit
|
|
|
|
*
|
|
|
|
* Initialize CoreAudio_DefaultDevice
|
|
|
|
*/
|
|
|
|
LONG CoreAudio_WaveInit(void)
|
|
|
|
{
|
|
|
|
OSStatus status;
|
|
|
|
UInt32 propertySize;
|
|
|
|
CHAR szPname[MAXPNAMELEN];
|
|
|
|
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) {
|
|
|
|
ERR("AudioHardwareGetProperty return %c%c%c%c for kAudioHardwarePropertyDefaultOutputDevice\n", (char) (status >> 24),
|
|
|
|
(char) (status >> 16),
|
|
|
|
(char) (status >> 8),
|
|
|
|
(char) status);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (CoreAudio_DefaultDevice.outputDeviceID == kAudioDeviceUnknown) {
|
|
|
|
ERR("AudioHardwareGetProperty: CoreAudio_DefaultDevice.outputDeviceID == kAudioDeviceUnknown\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! CoreAudio_GetDevCaps() )
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
CoreAudio_DefaultDevice.interface_name=HeapAlloc(GetProcessHeap(),0,strlen(CoreAudio_DefaultDevice.dev_name)+1);
|
|
|
|
sprintf(CoreAudio_DefaultDevice.interface_name, "%s", CoreAudio_DefaultDevice.dev_name);
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_WAVEOUTDRV; ++i)
|
|
|
|
{
|
|
|
|
WOutDev[i].state = WINE_WS_CLOSED;
|
|
|
|
WOutDev[i].cadev = &CoreAudio_DefaultDevice;
|
|
|
|
WOutDev[i].woID = i;
|
|
|
|
|
|
|
|
memset(&WOutDev[i].caps, 0, sizeof(WOutDev[i].caps));
|
|
|
|
|
|
|
|
WOutDev[i].caps.wMid = 0xcafe; /* Manufac ID */
|
|
|
|
WOutDev[i].caps.wPid = 0x0001; /* Product ID */
|
|
|
|
snprintf(szPname, sizeof(szPname), "CoreAudio WaveOut %d", i);
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, szPname, -1, WOutDev[i].caps.szPname, sizeof(WOutDev[i].caps.szPname)/sizeof(WCHAR));
|
|
|
|
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
|
|
|
|
2006-12-21 10:50:18 +01: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)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
|
|
|
snprintf(szPname, sizeof(szPname), "CoreAudio WaveIn %d", i);
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, szPname, -1, WInDev[i].caps.szPname, sizeof(WInDev[i].caps.szPname)/sizeof(WCHAR));
|
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");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
Port_SendToMessageThread = CFMessagePortCreateRemote(kCFAllocatorDefault, messageThreadPortName);
|
|
|
|
CFRelease(messageThreadPortName);
|
|
|
|
if (!Port_SendToMessageThread)
|
|
|
|
{
|
|
|
|
ERR("Can't create port for sending to message thread\n");
|
|
|
|
CFRelease(port_ReceiveInMessageThread);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
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;
|
2006-05-28 22:46:23 +02:00
|
|
|
return 1;
|
|
|
|
}
|
2006-12-21 10:47:05 +01:00
|
|
|
|
|
|
|
/* The message thread is responsible for releasing port_ReceiveInMessageThread. */
|
|
|
|
|
2006-05-28 22:46:23 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CoreAudio_WaveRelease(void)
|
|
|
|
{
|
|
|
|
/* Stop CFRunLoop in messageThread */
|
2006-05-31 14:52:58 +02:00
|
|
|
TRACE("()\n");
|
|
|
|
|
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]
|
|
|
|
*/
|
|
|
|
static DWORD wodNotifyClient(WINE_WAVEOUT* wwo, WORD wMsg, DWORD dwParam1, DWORD dwParam2)
|
|
|
|
{
|
|
|
|
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))
|
|
|
|
{
|
|
|
|
return MMSYSERR_ERROR;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
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]
|
|
|
|
*/
|
|
|
|
static DWORD wodOpen(WORD wDevID, LPWAVEOPENDESC lpDesc, DWORD dwFlags)
|
|
|
|
{
|
|
|
|
WINE_WAVEOUT* wwo;
|
|
|
|
DWORD retval;
|
|
|
|
DWORD ret;
|
2006-05-31 14:52:58 +02:00
|
|
|
AudioStreamBasicDescription streamFormat;
|
|
|
|
|
2006-10-20 12:36:38 +02:00
|
|
|
TRACE("(%u, %p, %08x);\n", wDevID, 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);
|
|
|
|
|
|
|
|
if (lpDesc->lpFormat->wFormatTag != WAVE_FORMAT_PCM ||
|
|
|
|
lpDesc->lpFormat->nChannels == 0 ||
|
|
|
|
lpDesc->lpFormat->nSamplesPerSec == 0
|
|
|
|
)
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
wwo = &WOutDev[wDevID];
|
2006-12-21 10:50:18 +01:00
|
|
|
if (!OSSpinLockTry(&wwo->lock))
|
|
|
|
return MMSYSERR_ALLOCATED;
|
2006-05-24 12:27:24 +02:00
|
|
|
|
|
|
|
if (wwo->state != WINE_WS_CLOSED)
|
|
|
|
{
|
2006-12-21 10:50:18 +01:00
|
|
|
OSSpinLockUnlock(&wwo->lock);
|
2006-05-24 12:27:24 +02:00
|
|
|
return MMSYSERR_ALLOCATED;
|
|
|
|
}
|
|
|
|
|
2006-05-28 22:46:23 +02:00
|
|
|
if (!AudioUnit_CreateDefaultAudioUnit((void *) wwo, &wwo->audioUnit))
|
|
|
|
{
|
|
|
|
ERR("CoreAudio_CreateDefaultAudioUnit(%p) failed\n", wwo);
|
2006-12-21 10:50:18 +01:00
|
|
|
OSSpinLockUnlock(&wwo->lock);
|
2006-05-28 22:46:23 +02:00
|
|
|
return MMSYSERR_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((dwFlags & WAVE_DIRECTSOUND) &&
|
|
|
|
!(wwo->caps.dwSupport & WAVECAPS_DIRECTSOUND))
|
|
|
|
/* not supported, ignore it */
|
|
|
|
dwFlags &= ~WAVE_DIRECTSOUND;
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
ret = AudioUnit_InitializeWithStreamDescription(wwo->audioUnit, &streamFormat);
|
2006-05-28 22:46:23 +02:00
|
|
|
if (!ret)
|
|
|
|
{
|
2006-05-24 12:28:18 +02:00
|
|
|
AudioUnit_CloseAudioUnit(wwo->audioUnit);
|
2006-12-21 10:50:18 +01:00
|
|
|
OSSpinLockUnlock(&wwo->lock);
|
2006-05-28 22:46:23 +02:00
|
|
|
return WAVERR_BADFORMAT; /* FIXME return an error based on the OSStatus */
|
|
|
|
}
|
|
|
|
wwo->streamDescription = streamFormat;
|
2006-12-21 10:48:59 +01:00
|
|
|
|
|
|
|
ret = AudioOutputUnitStart(wwo->audioUnit);
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
ERR("AudioOutputUnitStart failed: %08x\n", ret);
|
|
|
|
AudioUnitUninitialize(wwo->audioUnit);
|
|
|
|
AudioUnit_CloseAudioUnit(wwo->audioUnit);
|
2006-12-21 10:50:18 +01:00
|
|
|
OSSpinLockUnlock(&wwo->lock);
|
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
|
|
|
wwo->state = WINE_WS_STOPPED;
|
|
|
|
|
|
|
|
wwo->wFlags = HIWORD(dwFlags & CALLBACK_TYPEMASK);
|
|
|
|
|
|
|
|
memcpy(&wwo->waveDesc, lpDesc, sizeof(WAVEOPENDESC));
|
|
|
|
memcpy(&wwo->format, lpDesc->lpFormat, sizeof(PCMWAVEFORMAT));
|
|
|
|
|
|
|
|
if (wwo->format.wBitsPerSample == 0) {
|
|
|
|
WARN("Resetting zeroed wBitsPerSample\n");
|
|
|
|
wwo->format.wBitsPerSample = 8 *
|
|
|
|
(wwo->format.wf.nAvgBytesPerSec /
|
|
|
|
wwo->format.wf.nSamplesPerSec) /
|
|
|
|
wwo->format.wf.nChannels;
|
|
|
|
}
|
|
|
|
|
|
|
|
wwo->dwPlayedTotal = 0;
|
|
|
|
wwo->dwWrittenTotal = 0;
|
2006-12-21 10:46:55 +01:00
|
|
|
|
|
|
|
wwo->trace_on = TRACE_ON(wave);
|
|
|
|
wwo->warn_on = WARN_ON(wave);
|
|
|
|
wwo->err_on = ERR_ON(wave);
|
|
|
|
|
2006-12-21 10:50:18 +01:00
|
|
|
OSSpinLockUnlock(&wwo->lock);
|
2006-05-28 22:46:23 +02:00
|
|
|
|
|
|
|
retval = wodNotifyClient(wwo, WOM_OPEN, 0L, 0L);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* wodClose [internal]
|
|
|
|
*/
|
|
|
|
static DWORD wodClose(WORD wDevID)
|
|
|
|
{
|
|
|
|
DWORD ret = MMSYSERR_NOERROR;
|
|
|
|
WINE_WAVEOUT* wwo;
|
|
|
|
|
|
|
|
TRACE("(%u);\n", wDevID);
|
|
|
|
|
|
|
|
if (wDevID >= MAX_WAVEOUTDRV)
|
|
|
|
{
|
|
|
|
WARN("bad device ID !\n");
|
|
|
|
return MMSYSERR_BADDEVICEID;
|
|
|
|
}
|
|
|
|
|
|
|
|
wwo = &WOutDev[wDevID];
|
2006-12-21 10:50:18 +01:00
|
|
|
OSSpinLockLock(&wwo->lock);
|
2006-05-28 22:46:23 +02:00
|
|
|
if (wwo->lpQueuePtr)
|
|
|
|
{
|
|
|
|
WARN("buffers still playing !\n");
|
2006-12-21 10:50:18 +01:00
|
|
|
OSSpinLockUnlock(&wwo->lock);
|
2006-05-28 22:46:23 +02:00
|
|
|
ret = WAVERR_STILLPLAYING;
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
OSStatus err;
|
|
|
|
/* sanity check: this should not happen since the device must have been reset before */
|
|
|
|
if (wwo->lpQueuePtr || wwo->lpPlayPtr) ERR("out of sync\n");
|
|
|
|
|
|
|
|
wwo->state = WINE_WS_CLOSED; /* mark the device as closed */
|
|
|
|
|
2006-12-21 10:50:18 +01:00
|
|
|
OSSpinLockUnlock(&wwo->lock);
|
2006-12-21 10:49:35 +01:00
|
|
|
|
2006-05-28 22:46:23 +02:00
|
|
|
err = AudioUnitUninitialize(wwo->audioUnit);
|
|
|
|
if (err) {
|
|
|
|
ERR("AudioUnitUninitialize return %c%c%c%c\n", (char) (err >> 24),
|
|
|
|
(char) (err >> 16),
|
|
|
|
(char) (err >> 8),
|
|
|
|
(char) err);
|
|
|
|
return MMSYSERR_ERROR; /* FIXME return an error based on the OSStatus */
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !AudioUnit_CloseAudioUnit(wwo->audioUnit) )
|
|
|
|
{
|
|
|
|
ERR("Can't close AudioUnit\n");
|
|
|
|
return MMSYSERR_ERROR; /* FIXME return an error based on the OSStatus */
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = wodNotifyClient(wwo, WOM_CLOSE, 0L, 0L);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* wodPrepare [internal]
|
|
|
|
*/
|
|
|
|
static DWORD wodPrepare(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize)
|
|
|
|
{
|
2006-10-20 12:36:38 +02:00
|
|
|
TRACE("(%u, %p, %08x);\n", wDevID, 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]
|
|
|
|
*/
|
|
|
|
static DWORD wodUnprepare(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize)
|
|
|
|
{
|
2006-10-20 12:36:38 +02:00
|
|
|
TRACE("(%u, %p, %08x);\n", wDevID, 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.
|
|
|
|
* This is called with the WAVEOUT lock held.
|
|
|
|
* Call from AudioUnit IO thread can't use Wine debug channels.
|
|
|
|
*/
|
|
|
|
static void wodHelper_CheckForLoopBegin(WINE_WAVEOUT* wwo)
|
|
|
|
{
|
|
|
|
LPWAVEHDR lpWaveHdr = wwo->lpPlayPtr;
|
|
|
|
|
|
|
|
if (lpWaveHdr->dwFlags & WHDR_BEGINLOOP)
|
|
|
|
{
|
|
|
|
if (wwo->lpLoopPtr)
|
|
|
|
{
|
|
|
|
if (wwo->warn_on)
|
|
|
|
fprintf(stderr, "warn:winecoreaudio:wodHelper_CheckForLoopBegin Already in a loop. Discarding loop on this header (%p)\n", lpWaveHdr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (wwo->trace_on)
|
|
|
|
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.
|
2006-12-21 10:49:07 +01:00
|
|
|
* This is called with the WAVEOUT lock held.
|
2006-05-28 22:46:23 +02:00
|
|
|
* Call from AudioUnit IO thread can't use Wine debug channels.
|
|
|
|
*/
|
2006-12-21 10:48:52 +01:00
|
|
|
static void wodHelper_PlayPtrNext(WINE_WAVEOUT* 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
|
|
|
|
2006-12-21 10:48:52 +01:00
|
|
|
if (!wwo->lpPlayPtr)
|
2006-12-21 10:48:45 +01:00
|
|
|
wwo->state = WINE_WS_STOPPED;
|
|
|
|
else
|
|
|
|
wodHelper_CheckForLoopBegin(wwo);
|
|
|
|
}
|
2006-05-28 22:46:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* if force is TRUE then notify the client that all the headers were completed
|
|
|
|
*/
|
2006-12-21 10:49:43 +01:00
|
|
|
static void wodHelper_NotifyCompletions(WINE_WAVEOUT* wwo, BOOL force)
|
2006-05-28 22:46:23 +02:00
|
|
|
{
|
|
|
|
LPWAVEHDR lpWaveHdr;
|
2006-12-21 10:49:43 +01: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
|
|
|
|
{
|
|
|
|
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. */
|
|
|
|
for (lpWaveHdr = lpFirstDoneWaveHdr; lpWaveHdr; lpWaveHdr = lpWaveHdr->lpNext)
|
2006-05-28 22:46:23 +02:00
|
|
|
{
|
|
|
|
lpWaveHdr->dwFlags &= ~WHDR_INQUEUE;
|
|
|
|
lpWaveHdr->dwFlags |= WHDR_DONE;
|
2006-12-21 10:49:43 +01:00
|
|
|
|
2006-05-28 22:46:23 +02:00
|
|
|
wodNotifyClient(wwo, WOM_DONE, (DWORD)lpWaveHdr, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* wodWrite [internal]
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static DWORD wodWrite(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize)
|
|
|
|
{
|
|
|
|
LPWAVEHDR*wh;
|
|
|
|
WINE_WAVEOUT *wwo;
|
|
|
|
|
2006-10-20 12:36:38 +02:00
|
|
|
TRACE("(%u, %p, %08X);\n", wDevID, lpWaveHdr, 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
wwo = &WOutDev[wDevID];
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (wwo->state == WINE_WS_STOPPED)
|
2006-12-21 10:48:59 +01:00
|
|
|
wwo->state = WINE_WS_PLAYING;
|
2006-12-21 10:48:45 +01:00
|
|
|
|
|
|
|
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]
|
|
|
|
*/
|
|
|
|
static DWORD wodPause(WORD wDevID)
|
|
|
|
{
|
2006-05-24 12:34:04 +02:00
|
|
|
OSStatus status;
|
|
|
|
|
2006-05-28 22:46:23 +02:00
|
|
|
TRACE("(%u);!\n", wDevID);
|
|
|
|
|
|
|
|
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
|
|
|
|
* PLAYING or STOPPED 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.
|
|
|
|
*/
|
|
|
|
status = AudioOutputUnitStop(WOutDev[wDevID].audioUnit);
|
|
|
|
if (status) {
|
|
|
|
WARN("AudioOutputUnitStop return %c%c%c%c\n",
|
|
|
|
(char) (status >> 24), (char) (status >> 16), (char) (status >> 8), (char) status);
|
|
|
|
}
|
|
|
|
|
2006-12-21 10:50:18 +01:00
|
|
|
OSSpinLockLock(&WOutDev[wDevID].lock);
|
2006-05-24 12:34:04 +02:00
|
|
|
if (WOutDev[wDevID].state == WINE_WS_PLAYING || WOutDev[wDevID].state == WINE_WS_STOPPED)
|
2006-05-28 22:46:23 +02:00
|
|
|
WOutDev[wDevID].state = WINE_WS_PAUSED;
|
2006-12-21 10:50:18 +01:00
|
|
|
OSSpinLockUnlock(&WOutDev[wDevID].lock);
|
2006-12-21 10:48:59 +01:00
|
|
|
|
2006-05-28 22:46:23 +02:00
|
|
|
return MMSYSERR_NOERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* wodRestart [internal]
|
|
|
|
*/
|
|
|
|
static DWORD wodRestart(WORD wDevID)
|
|
|
|
{
|
2006-12-21 10:48:59 +01:00
|
|
|
OSStatus status;
|
|
|
|
|
2006-05-28 22:46:23 +02:00
|
|
|
TRACE("(%u);\n", wDevID);
|
|
|
|
|
|
|
|
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. Set the PLAYING/STOPPED
|
|
|
|
* state before starting the Audio Unit. In wodPause, the order is
|
|
|
|
* reversed. This guarantees that we can't get into a situation where
|
|
|
|
* the state is PLAYING or STOPPED 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:50:18 +01:00
|
|
|
OSSpinLockLock(&WOutDev[wDevID].lock);
|
2006-05-28 22:46:23 +02:00
|
|
|
if (WOutDev[wDevID].state == WINE_WS_PAUSED)
|
|
|
|
{
|
2006-05-24 12:34:04 +02:00
|
|
|
if (WOutDev[wDevID].lpPlayPtr)
|
|
|
|
WOutDev[wDevID].state = WINE_WS_PLAYING;
|
|
|
|
else
|
|
|
|
WOutDev[wDevID].state = WINE_WS_STOPPED;
|
2006-05-28 22:46:23 +02:00
|
|
|
}
|
2006-12-21 10:50:18 +01:00
|
|
|
OSSpinLockUnlock(&WOutDev[wDevID].lock);
|
2006-12-21 10:48:59 +01:00
|
|
|
|
|
|
|
status = AudioOutputUnitStart(WOutDev[wDevID].audioUnit);
|
|
|
|
if (status) {
|
|
|
|
ERR("AudioOutputUnitStart return %c%c%c%c\n",
|
|
|
|
(char) (status >> 24), (char) (status >> 16), (char) (status >> 8), (char) status);
|
|
|
|
return MMSYSERR_ERROR; /* FIXME return an error based on the OSStatus */
|
|
|
|
}
|
|
|
|
|
2006-05-28 22:46:23 +02:00
|
|
|
return MMSYSERR_NOERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* wodReset [internal]
|
|
|
|
*/
|
|
|
|
static DWORD wodReset(WORD wDevID)
|
|
|
|
{
|
2006-12-21 10:49:58 +01:00
|
|
|
WINE_WAVEOUT* wwo;
|
|
|
|
OSStatus status;
|
|
|
|
|
2006-05-28 22:46:23 +02:00
|
|
|
TRACE("(%u);\n", wDevID);
|
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
|
|
|
|
|
|
|
wwo = &WOutDev[wDevID];
|
|
|
|
|
|
|
|
/* updates current notify list */
|
|
|
|
/* if resetting, remove all wave headers and notify client that all headers were completed */
|
|
|
|
wodHelper_NotifyCompletions(wwo, TRUE);
|
2006-12-21 10:50:18 +01:00
|
|
|
|
|
|
|
OSSpinLockLock(&wwo->lock);
|
|
|
|
|
2006-12-21 10:49:58 +01:00
|
|
|
wwo->lpPlayPtr = wwo->lpQueuePtr = wwo->lpLoopPtr = NULL;
|
|
|
|
wwo->state = WINE_WS_STOPPED;
|
|
|
|
wwo->dwPlayedTotal = wwo->dwWrittenTotal = 0;
|
|
|
|
|
|
|
|
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) {
|
|
|
|
ERR( "AudioOutputUnitStart return %c%c%c%c\n",
|
|
|
|
(char) (status >> 24), (char) (status >> 16), (char) (status >> 8), (char) status);
|
|
|
|
return MMSYSERR_ERROR; /* FIXME return an error based on the OSStatus */
|
|
|
|
}
|
|
|
|
|
|
|
|
return MMSYSERR_NOERROR;
|
2006-05-28 22:46:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* wodGetPosition [internal]
|
|
|
|
*/
|
|
|
|
static DWORD wodGetPosition(WORD wDevID, LPMMTIME lpTime, DWORD uSize)
|
|
|
|
{
|
|
|
|
DWORD val;
|
|
|
|
WINE_WAVEOUT* wwo;
|
2006-05-31 14:52:58 +02:00
|
|
|
|
2006-10-20 12:36:38 +02:00
|
|
|
TRACE("(%u, %p, %u);\n", wDevID, 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;
|
|
|
|
|
|
|
|
wwo = &WOutDev[wDevID];
|
|
|
|
|
2006-12-21 10:50:18 +01:00
|
|
|
OSSpinLockLock(&WOutDev[wDevID].lock);
|
2006-05-28 22:46:23 +02:00
|
|
|
val = wwo->dwPlayedTotal;
|
2006-12-21 10:50:18 +01:00
|
|
|
OSSpinLockUnlock(&WOutDev[wDevID].lock);
|
2006-05-28 22:46:23 +02:00
|
|
|
|
|
|
|
return bytes_to_mmtime(lpTime, val, &wwo->format);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* wodGetVolume [internal]
|
|
|
|
*/
|
|
|
|
static DWORD wodGetVolume(WORD wDevID, LPDWORD lpdwVol)
|
|
|
|
{
|
|
|
|
float left;
|
|
|
|
float right;
|
|
|
|
|
|
|
|
if (wDevID >= MAX_WAVEOUTDRV)
|
|
|
|
{
|
|
|
|
WARN("bad device ID !\n");
|
|
|
|
return MMSYSERR_BADDEVICEID;
|
|
|
|
}
|
|
|
|
|
2006-05-31 14:52:58 +02:00
|
|
|
TRACE("(%u, %p);\n", wDevID, lpdwVol);
|
2006-12-21 10:49:35 +01:00
|
|
|
|
2006-05-28 22:46:23 +02:00
|
|
|
AudioUnit_GetVolume(WOutDev[wDevID].audioUnit, &left, &right);
|
2006-12-21 10:49:35 +01:00
|
|
|
|
2006-05-28 22:46:23 +02:00
|
|
|
*lpdwVol = ((WORD) left * 0xFFFFl) + (((WORD) right * 0xFFFFl) << 16);
|
|
|
|
|
|
|
|
return MMSYSERR_NOERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* wodSetVolume [internal]
|
|
|
|
*/
|
|
|
|
static DWORD wodSetVolume(WORD wDevID, DWORD dwParam)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
2006-10-20 12:36:38 +02:00
|
|
|
TRACE("(%u, %08x);\n", wDevID, dwParam);
|
2006-12-21 10:49:35 +01:00
|
|
|
|
2006-05-28 22:46:23 +02:00
|
|
|
AudioUnit_SetVolume(WOutDev[wDevID].audioUnit, left, right);
|
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);
|
|
|
|
|
|
|
|
*dwParam1 = MultiByteToWideChar(CP_ACP, 0, WOutDev[wDevID].cadev->interface_name, -1,
|
|
|
|
NULL, 0 ) * sizeof(WCHAR);
|
|
|
|
return MMSYSERR_NOERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* wodDevInterface [internal]
|
|
|
|
*/
|
|
|
|
static DWORD wodDevInterface(UINT wDevID, PWCHAR dwParam1, DWORD dwParam2)
|
|
|
|
{
|
|
|
|
TRACE("\n");
|
|
|
|
if (dwParam2 >= MultiByteToWideChar(CP_ACP, 0, WOutDev[wDevID].cadev->interface_name, -1,
|
|
|
|
NULL, 0 ) * sizeof(WCHAR))
|
|
|
|
{
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, WOutDev[wDevID].cadev->interface_name, -1,
|
|
|
|
dwParam1, dwParam2 / sizeof(WCHAR));
|
|
|
|
return MMSYSERR_NOERROR;
|
|
|
|
}
|
|
|
|
return MMSYSERR_INVALPARAM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
2006-12-28 18:03:26 +01:00
|
|
|
* wodMessage (WINECOREAUDIO.7)
|
2006-05-28 22:46:23 +02:00
|
|
|
*/
|
|
|
|
DWORD WINAPI CoreAudio_wodMessage(UINT wDevID, UINT wMsg, DWORD dwUser,
|
|
|
|
DWORD dwParam1, DWORD dwParam2)
|
|
|
|
{
|
2006-10-20 12:36:38 +02:00
|
|
|
TRACE("(%u, %s, %08x, %08x, %08x);\n",
|
2006-05-28 22:46:23 +02:00
|
|
|
wDevID, getMessage(wMsg), dwUser, dwParam1, dwParam2);
|
|
|
|
|
|
|
|
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;
|
|
|
|
case WODM_OPEN: return wodOpen(wDevID, (LPWAVEOPENDESC) dwParam1, dwParam2);
|
|
|
|
case WODM_CLOSE: return wodClose(wDevID);
|
|
|
|
case WODM_WRITE: return wodWrite(wDevID, (LPWAVEHDR) dwParam1, dwParam2);
|
|
|
|
case WODM_PAUSE: return wodPause(wDevID);
|
|
|
|
case WODM_GETPOS: return wodGetPosition(wDevID, (LPMMTIME) dwParam1, dwParam2);
|
|
|
|
case WODM_BREAKLOOP: return MMSYSERR_NOTSUPPORTED;
|
|
|
|
case WODM_PREPARE: return wodPrepare(wDevID, (LPWAVEHDR)dwParam1, dwParam2);
|
|
|
|
case WODM_UNPREPARE: return wodUnprepare(wDevID, (LPWAVEHDR)dwParam1, dwParam2);
|
|
|
|
|
|
|
|
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;
|
|
|
|
case WODM_GETVOLUME: return wodGetVolume(wDevID, (LPDWORD)dwParam1);
|
|
|
|
case WODM_SETVOLUME: return wodSetVolume(wDevID, dwParam1);
|
|
|
|
case WODM_RESTART: return wodRestart(wDevID);
|
|
|
|
case WODM_RESET: return wodReset(wDevID);
|
|
|
|
|
|
|
|
case DRV_QUERYDEVICEINTERFACESIZE: return wodDevInterfaceSize (wDevID, (LPDWORD)dwParam1);
|
|
|
|
case DRV_QUERYDEVICEINTERFACE: return wodDevInterface (wDevID, (PWCHAR)dwParam1, dwParam2);
|
|
|
|
case DRV_QUERYDSOUNDIFACE:
|
|
|
|
case DRV_QUERYDSOUNDDESC:
|
|
|
|
return MMSYSERR_NOTSUPPORTED;
|
|
|
|
|
|
|
|
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;
|
2006-05-28 22:46:23 +02:00
|
|
|
WINE_WAVEOUT *wwo = (WINE_WAVEOUT *) inRefCon;
|
|
|
|
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
|
|
|
|
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
|
|
|
}
|
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. */
|
|
|
|
for (lpWaveHdr = lpFirstDoneWaveHdr; lpWaveHdr; lpWaveHdr = lpWaveHdr->lpNext)
|
|
|
|
{
|
|
|
|
lpWaveHdr->dwFlags &= ~WHDR_INQUEUE;
|
|
|
|
lpWaveHdr->dwFlags |= WHDR_DONE;
|
|
|
|
|
|
|
|
widNotifyClient(wwi, WIM_DATA, (DWORD)lpWaveHdr, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* widHelper_AllocateAudioBufferList [internal]
|
|
|
|
* Convenience function to allocate our audio buffers
|
|
|
|
*/
|
|
|
|
static AudioBufferList* widHelper_AllocateAudioBufferList(UInt32 numChannels, UInt32 size)
|
|
|
|
{
|
|
|
|
AudioBufferList* list;
|
|
|
|
UInt32 i;
|
|
|
|
|
|
|
|
list = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(AudioBufferList) + numChannels * sizeof(AudioBuffer));
|
|
|
|
if (list == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
list->mNumberBuffers = numChannels;
|
|
|
|
for (i = 0; i < numChannels; ++i)
|
|
|
|
{
|
|
|
|
list->mBuffers[i].mNumberChannels = 1;
|
|
|
|
list->mBuffers[i].mDataByteSize = size;
|
|
|
|
list->mBuffers[i].mData = HeapAlloc(GetProcessHeap(), 0, size);
|
|
|
|
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:06:29 +01:00
|
|
|
UInt32 bytesPerFrame;
|
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);
|
|
|
|
|
|
|
|
if (lpDesc->lpFormat->wFormatTag != WAVE_FORMAT_PCM ||
|
|
|
|
lpDesc->lpFormat->nChannels == 0 ||
|
|
|
|
lpDesc->lpFormat->nSamplesPerSec == 0
|
|
|
|
)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
memcpy(&wwi->waveDesc, lpDesc, sizeof(WAVEOPENDESC));
|
|
|
|
memcpy(&wwi->format, lpDesc->lpFormat, sizeof(PCMWAVEFORMAT));
|
|
|
|
|
|
|
|
if (wwi->format.wBitsPerSample == 0)
|
|
|
|
{
|
|
|
|
WARN("Resetting zeroed wBitsPerSample\n");
|
|
|
|
wwi->format.wBitsPerSample = 8 *
|
|
|
|
(wwi->format.wf.nAvgBytesPerSec /
|
|
|
|
wwi->format.wf.nSamplesPerSec) /
|
|
|
|
wwi->format.wf.nChannels;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
ERR("AudioUnit_CreateInputUnit failed\n");
|
|
|
|
OSSpinLockUnlock(&wwi->lock);
|
|
|
|
return MMSYSERR_ERROR;
|
|
|
|
}
|
|
|
|
|
2006-12-28 18:06:29 +01:00
|
|
|
/* Allocate our audio buffers */
|
|
|
|
/* For interleaved audio, we allocate one buffer for all channels. */
|
|
|
|
bytesPerFrame = wwi->format.wBitsPerSample * wwi->format.wf.nChannels / 8;
|
|
|
|
wwi->bufferList = widHelper_AllocateAudioBufferList(1, wwi->format.wf.nChannels * frameCount * bytesPerFrame);
|
|
|
|
if (wwi->bufferList == NULL)
|
|
|
|
{
|
|
|
|
ERR("Failed to allocate buffer list\n");
|
|
|
|
AudioUnitUninitialize(wwi->audioUnit);
|
|
|
|
AudioUnit_CloseAudioUnit(wwi->audioUnit);
|
|
|
|
OSSpinLockUnlock(&wwi->lock);
|
|
|
|
return MMSYSERR_NOMEM;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
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);
|
|
|
|
if (wwi->state == WINE_WS_CLOSED)
|
|
|
|
{
|
|
|
|
WARN("Device already closed.\n");
|
|
|
|
ret = MMSYSERR_INVALHANDLE;
|
|
|
|
}
|
|
|
|
else if (wwi->lpQueuePtr)
|
|
|
|
{
|
|
|
|
WARN("Buffers in queue.\n");
|
|
|
|
ret = WAVERR_STILLPLAYING;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wwi->state = WINE_WS_CLOSED;
|
|
|
|
}
|
|
|
|
|
|
|
|
OSSpinLockUnlock(&wwi->lock);
|
|
|
|
|
|
|
|
if (ret == MMSYSERR_NOERROR)
|
|
|
|
{
|
|
|
|
OSStatus err = AudioUnitUninitialize(wwi->audioUnit);
|
|
|
|
if (err)
|
|
|
|
{
|
|
|
|
ERR("AudioUnitUninitialize return %c%c%c%c\n", (char) (err >> 24),
|
|
|
|
(char) (err >> 16),
|
|
|
|
(char) (err >> 8),
|
|
|
|
(char) err);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!AudioUnit_CloseAudioUnit(wwi->audioUnit))
|
|
|
|
{
|
|
|
|
ERR("Can't close AudioUnit\n");
|
|
|
|
}
|
|
|
|
|
2006-12-28 18:06:29 +01:00
|
|
|
/* Dellocate our audio buffers */
|
|
|
|
widHelper_DestroyAudioBufferList(wwi->bufferList);
|
|
|
|
wwi->bufferList = NULL;
|
|
|
|
|
2006-12-28 18:05:31 +01:00
|
|
|
ret = widNotifyClient(wwi, WIM_CLOSE, 0L, 0L);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (wwi->state == WINE_WS_CLOSED)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (wwi->state == WINE_WS_CLOSED)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (wwi->state == WINE_WS_CLOSED)
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* 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);
|
|
|
|
|
|
|
|
if (wwi->state == WINE_WS_CLOSED)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2006-12-28 18:06:16 +01:00
|
|
|
*dwParam1 = MultiByteToWideChar(CP_ACP, 0, WInDev[wDevID].interface_name, -1,
|
|
|
|
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)
|
|
|
|
{
|
2006-12-28 18:06:16 +01:00
|
|
|
if (dwParam2 >= MultiByteToWideChar(CP_ACP, 0, WInDev[wDevID].interface_name, -1,
|
|
|
|
NULL, 0 ) * sizeof(WCHAR))
|
|
|
|
{
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, WInDev[wDevID].interface_name, -1,
|
|
|
|
dwParam1, dwParam2 / sizeof(WCHAR));
|
|
|
|
return MMSYSERR_NOERROR;
|
|
|
|
}
|
|
|
|
return MMSYSERR_INVALPARAM;
|
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);
|
|
|
|
case DRV_QUERYDEVICEINTERFACESIZE: return widDevInterfaceSize (wDevID, (LPDWORD)dwParam1);
|
|
|
|
case DRV_QUERYDEVICEINTERFACE: return widDevInterface (wDevID, (PWCHAR)dwParam1, dwParam2);
|
|
|
|
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;
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
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
|