2012-04-03 17:51:07 +02:00
|
|
|
/*
|
|
|
|
* Implementation of IAudioData Interface
|
|
|
|
*
|
|
|
|
* Copyright 2012 Christian Costa
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "amstream_private.h"
|
|
|
|
|
2021-07-10 05:14:42 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(quartz);
|
2012-04-03 17:51:07 +02:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
IAudioData IAudioData_iface;
|
|
|
|
LONG ref;
|
2016-07-28 17:59:52 +02:00
|
|
|
DWORD size;
|
|
|
|
BYTE *data;
|
2016-07-28 17:59:53 +02:00
|
|
|
BOOL data_owned;
|
2016-07-28 17:59:52 +02:00
|
|
|
DWORD actual_data;
|
2016-07-28 17:59:55 +02:00
|
|
|
WAVEFORMATEX wave_format;
|
2012-04-03 17:51:07 +02:00
|
|
|
} AMAudioDataImpl;
|
|
|
|
|
|
|
|
static inline AMAudioDataImpl *impl_from_IAudioData(IAudioData *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, AMAudioDataImpl, IAudioData_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*** IUnknown methods ***/
|
|
|
|
static HRESULT WINAPI IAudioDataImpl_QueryInterface(IAudioData *iface, REFIID riid, void **ret_iface)
|
|
|
|
{
|
|
|
|
TRACE("(%p)->(%s,%p)\n", iface, debugstr_guid(riid), ret_iface);
|
|
|
|
|
|
|
|
if (IsEqualGUID(riid, &IID_IUnknown) ||
|
|
|
|
IsEqualGUID(riid, &IID_IAudioData))
|
|
|
|
{
|
2012-08-19 17:11:05 +02:00
|
|
|
IAudioData_AddRef(iface);
|
2012-04-03 17:51:07 +02:00
|
|
|
*ret_iface = iface;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
ERR("(%p)->(%s,%p),not found\n", iface, debugstr_guid(riid), ret_iface);
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI IAudioDataImpl_AddRef(IAudioData* iface)
|
|
|
|
{
|
|
|
|
AMAudioDataImpl *This = impl_from_IAudioData(iface);
|
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
|
2022-02-07 23:10:45 +01:00
|
|
|
TRACE("(%p)->(): new ref = %lu\n", iface, This->ref);
|
2012-04-03 17:51:07 +02:00
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI IAudioDataImpl_Release(IAudioData* iface)
|
|
|
|
{
|
|
|
|
AMAudioDataImpl *This = impl_from_IAudioData(iface);
|
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
2022-02-07 23:10:45 +01:00
|
|
|
TRACE("(%p)->(): new ref = %lu\n", iface, This->ref);
|
2012-04-03 17:51:07 +02:00
|
|
|
|
|
|
|
if (!ref)
|
2016-07-28 17:59:53 +02:00
|
|
|
{
|
|
|
|
if (This->data_owned)
|
|
|
|
{
|
|
|
|
CoTaskMemFree(This->data);
|
|
|
|
}
|
|
|
|
|
2012-04-03 17:51:07 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
2016-07-28 17:59:53 +02:00
|
|
|
}
|
2012-04-03 17:51:07 +02:00
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*** IMemoryData methods ***/
|
|
|
|
static HRESULT WINAPI IAudioDataImpl_SetBuffer(IAudioData* iface, DWORD size, BYTE *data, DWORD flags)
|
|
|
|
{
|
2016-07-28 17:59:53 +02:00
|
|
|
AMAudioDataImpl *This = impl_from_IAudioData(iface);
|
2012-04-03 17:51:07 +02:00
|
|
|
|
2022-02-07 23:10:45 +01:00
|
|
|
TRACE("(%p)->(%lu,%p,%lx)\n", iface, size, data, flags);
|
2016-07-28 17:59:53 +02:00
|
|
|
|
|
|
|
if (!size)
|
|
|
|
{
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (This->data_owned)
|
|
|
|
{
|
|
|
|
CoTaskMemFree(This->data);
|
|
|
|
This->data_owned = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
This->size = size;
|
|
|
|
This->data = data;
|
|
|
|
|
|
|
|
if (!This->data)
|
|
|
|
{
|
|
|
|
This->data = CoTaskMemAlloc(This->size);
|
|
|
|
This->data_owned = TRUE;
|
|
|
|
if (!This->data)
|
|
|
|
{
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
2012-04-03 17:51:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IAudioDataImpl_GetInfo(IAudioData* iface, DWORD *length, BYTE **data, DWORD *actual_data)
|
|
|
|
{
|
2016-07-28 17:59:52 +02:00
|
|
|
AMAudioDataImpl *This = impl_from_IAudioData(iface);
|
2012-04-03 17:51:07 +02:00
|
|
|
|
2016-07-28 17:59:52 +02:00
|
|
|
TRACE("(%p)->(%p,%p,%p)\n", iface, length, data, actual_data);
|
|
|
|
|
|
|
|
if (!This->data)
|
|
|
|
{
|
|
|
|
return MS_E_NOTINIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (length)
|
|
|
|
{
|
|
|
|
*length = This->size;
|
|
|
|
}
|
|
|
|
if (data)
|
|
|
|
{
|
|
|
|
*data = This->data;
|
|
|
|
}
|
|
|
|
if (actual_data)
|
|
|
|
{
|
|
|
|
*actual_data = This->actual_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
2012-04-03 17:51:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IAudioDataImpl_SetActual(IAudioData* iface, DWORD data_valid)
|
|
|
|
{
|
2016-07-28 17:59:54 +02:00
|
|
|
AMAudioDataImpl *This = impl_from_IAudioData(iface);
|
2012-04-03 17:51:07 +02:00
|
|
|
|
2022-02-07 23:10:45 +01:00
|
|
|
TRACE("(%p)->(%lu)\n", iface, data_valid);
|
2016-07-28 17:59:54 +02:00
|
|
|
|
|
|
|
if (data_valid > This->size)
|
|
|
|
{
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
This->actual_data = data_valid;
|
|
|
|
|
|
|
|
return S_OK;
|
2012-04-03 17:51:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*** IAudioData methods ***/
|
|
|
|
static HRESULT WINAPI IAudioDataImpl_GetFormat(IAudioData* iface, WAVEFORMATEX *wave_format_current)
|
|
|
|
{
|
2016-07-28 17:59:55 +02:00
|
|
|
AMAudioDataImpl *This = impl_from_IAudioData(iface);
|
2012-04-03 17:51:07 +02:00
|
|
|
|
2016-07-28 17:59:55 +02:00
|
|
|
TRACE("(%p)->(%p)\n", iface, wave_format_current);
|
|
|
|
|
|
|
|
if (!wave_format_current)
|
|
|
|
{
|
|
|
|
return E_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
*wave_format_current = This->wave_format;
|
|
|
|
|
|
|
|
return S_OK;
|
2012-04-03 17:51:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IAudioDataImpl_SetFormat(IAudioData* iface, const WAVEFORMATEX *wave_format)
|
|
|
|
{
|
2016-07-28 17:59:56 +02:00
|
|
|
AMAudioDataImpl *This = impl_from_IAudioData(iface);
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", iface, wave_format);
|
|
|
|
|
|
|
|
if (!wave_format)
|
|
|
|
{
|
|
|
|
return E_POINTER;
|
|
|
|
}
|
2012-04-03 17:51:07 +02:00
|
|
|
|
2016-07-28 17:59:56 +02:00
|
|
|
if (WAVE_FORMAT_PCM != wave_format->wFormatTag)
|
|
|
|
{
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
This->wave_format = *wave_format;
|
|
|
|
|
|
|
|
return S_OK;
|
2012-04-03 17:51:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct IAudioDataVtbl AudioData_Vtbl =
|
|
|
|
{
|
|
|
|
/*** IUnknown methods ***/
|
|
|
|
IAudioDataImpl_QueryInterface,
|
|
|
|
IAudioDataImpl_AddRef,
|
|
|
|
IAudioDataImpl_Release,
|
|
|
|
/*** IMemoryData methods ***/
|
|
|
|
IAudioDataImpl_SetBuffer,
|
|
|
|
IAudioDataImpl_GetInfo,
|
|
|
|
IAudioDataImpl_SetActual,
|
|
|
|
/*** IAudioData methods ***/
|
|
|
|
IAudioDataImpl_GetFormat,
|
|
|
|
IAudioDataImpl_SetFormat
|
|
|
|
};
|
|
|
|
|
|
|
|
HRESULT AMAudioData_create(IUnknown *pUnkOuter, LPVOID *ppObj)
|
|
|
|
{
|
|
|
|
AMAudioDataImpl *object;
|
|
|
|
|
|
|
|
TRACE("(%p,%p)\n", pUnkOuter, ppObj);
|
|
|
|
|
|
|
|
if (pUnkOuter)
|
|
|
|
return CLASS_E_NOAGGREGATION;
|
|
|
|
|
|
|
|
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(AMAudioDataImpl));
|
|
|
|
if (!object)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
object->IAudioData_iface.lpVtbl = &AudioData_Vtbl;
|
|
|
|
object->ref = 1;
|
|
|
|
|
2016-07-28 17:59:55 +02:00
|
|
|
object->wave_format.wFormatTag = WAVE_FORMAT_PCM;
|
|
|
|
object->wave_format.nChannels = 1;
|
|
|
|
object->wave_format.nSamplesPerSec = 11025;
|
|
|
|
object->wave_format.wBitsPerSample = 16;
|
|
|
|
object->wave_format.nBlockAlign = object->wave_format.wBitsPerSample * object->wave_format.nChannels / 8;
|
|
|
|
object->wave_format.nAvgBytesPerSec = object->wave_format.nBlockAlign * object->wave_format.nSamplesPerSec;
|
|
|
|
|
2012-04-03 17:51:07 +02:00
|
|
|
*ppObj = &object->IAudioData_iface;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|