dmime/tests: Check more notification / dirty messages fields.
[wine.git] / dlls / amstream / audiodata.c
blob752651b1afe943aa6017e394eaee06655a154bdd
1 /*
2 * Implementation of IAudioData Interface
4 * Copyright 2012 Christian Costa
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "wine/debug.h"
23 #define COBJMACROS
25 #include "winbase.h"
26 #include "amstream_private.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
30 typedef struct {
31 IAudioData IAudioData_iface;
32 LONG ref;
33 DWORD size;
34 BYTE *data;
35 BOOL data_owned;
36 DWORD actual_data;
37 WAVEFORMATEX wave_format;
38 } AMAudioDataImpl;
40 static inline AMAudioDataImpl *impl_from_IAudioData(IAudioData *iface)
42 return CONTAINING_RECORD(iface, AMAudioDataImpl, IAudioData_iface);
45 /*** IUnknown methods ***/
46 static HRESULT WINAPI IAudioDataImpl_QueryInterface(IAudioData *iface, REFIID riid, void **ret_iface)
48 TRACE("(%p)->(%s,%p)\n", iface, debugstr_guid(riid), ret_iface);
50 if (IsEqualGUID(riid, &IID_IUnknown) ||
51 IsEqualGUID(riid, &IID_IAudioData))
53 IAudioData_AddRef(iface);
54 *ret_iface = iface;
55 return S_OK;
58 ERR("(%p)->(%s,%p),not found\n", iface, debugstr_guid(riid), ret_iface);
59 return E_NOINTERFACE;
62 static ULONG WINAPI IAudioDataImpl_AddRef(IAudioData* iface)
64 AMAudioDataImpl *This = impl_from_IAudioData(iface);
65 ULONG ref = InterlockedIncrement(&This->ref);
67 TRACE("(%p)->(): new ref = %lu\n", iface, This->ref);
69 return ref;
72 static ULONG WINAPI IAudioDataImpl_Release(IAudioData* iface)
74 AMAudioDataImpl *audiodata = impl_from_IAudioData(iface);
75 ULONG ref = InterlockedDecrement(&audiodata->ref);
77 TRACE("%p decreasing refcount to %lu.\n", audiodata, ref);
79 if (!ref)
81 if (audiodata->data_owned)
82 free(audiodata->data);
83 free(audiodata);
86 return ref;
89 /*** IMemoryData methods ***/
90 static HRESULT WINAPI IAudioDataImpl_SetBuffer(IAudioData* iface, DWORD size, BYTE *data, DWORD flags)
92 AMAudioDataImpl *This = impl_from_IAudioData(iface);
94 TRACE("(%p)->(%lu,%p,%lx)\n", iface, size, data, flags);
96 if (!size)
98 return E_INVALIDARG;
101 if (This->data_owned)
103 free(This->data);
104 This->data_owned = FALSE;
107 This->size = size;
108 This->data = data;
110 if (!This->data)
112 This->data = malloc(This->size);
113 This->data_owned = TRUE;
114 if (!This->data)
116 return E_OUTOFMEMORY;
120 return S_OK;
123 static HRESULT WINAPI IAudioDataImpl_GetInfo(IAudioData* iface, DWORD *length, BYTE **data, DWORD *actual_data)
125 AMAudioDataImpl *This = impl_from_IAudioData(iface);
127 TRACE("(%p)->(%p,%p,%p)\n", iface, length, data, actual_data);
129 if (!This->data)
131 return MS_E_NOTINIT;
134 if (length)
136 *length = This->size;
138 if (data)
140 *data = This->data;
142 if (actual_data)
144 *actual_data = This->actual_data;
147 return S_OK;
150 static HRESULT WINAPI IAudioDataImpl_SetActual(IAudioData* iface, DWORD data_valid)
152 AMAudioDataImpl *This = impl_from_IAudioData(iface);
154 TRACE("(%p)->(%lu)\n", iface, data_valid);
156 if (data_valid > This->size)
158 return E_INVALIDARG;
161 This->actual_data = data_valid;
163 return S_OK;
166 /*** IAudioData methods ***/
167 static HRESULT WINAPI IAudioDataImpl_GetFormat(IAudioData* iface, WAVEFORMATEX *wave_format_current)
169 AMAudioDataImpl *This = impl_from_IAudioData(iface);
171 TRACE("(%p)->(%p)\n", iface, wave_format_current);
173 if (!wave_format_current)
175 return E_POINTER;
178 *wave_format_current = This->wave_format;
180 return S_OK;
183 static HRESULT WINAPI IAudioDataImpl_SetFormat(IAudioData* iface, const WAVEFORMATEX *wave_format)
185 AMAudioDataImpl *This = impl_from_IAudioData(iface);
187 TRACE("(%p)->(%p)\n", iface, wave_format);
189 if (!wave_format)
191 return E_POINTER;
194 if (WAVE_FORMAT_PCM != wave_format->wFormatTag)
196 return E_INVALIDARG;
199 This->wave_format = *wave_format;
201 return S_OK;
204 static const struct IAudioDataVtbl AudioData_Vtbl =
206 /*** IUnknown methods ***/
207 IAudioDataImpl_QueryInterface,
208 IAudioDataImpl_AddRef,
209 IAudioDataImpl_Release,
210 /*** IMemoryData methods ***/
211 IAudioDataImpl_SetBuffer,
212 IAudioDataImpl_GetInfo,
213 IAudioDataImpl_SetActual,
214 /*** IAudioData methods ***/
215 IAudioDataImpl_GetFormat,
216 IAudioDataImpl_SetFormat
219 HRESULT AMAudioData_create(IUnknown *pUnkOuter, LPVOID *ppObj)
221 AMAudioDataImpl *object;
223 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
225 if (pUnkOuter)
226 return CLASS_E_NOAGGREGATION;
228 if (!(object = calloc(1, sizeof(*object))))
229 return E_OUTOFMEMORY;
231 object->IAudioData_iface.lpVtbl = &AudioData_Vtbl;
232 object->ref = 1;
234 object->wave_format.wFormatTag = WAVE_FORMAT_PCM;
235 object->wave_format.nChannels = 1;
236 object->wave_format.nSamplesPerSec = 11025;
237 object->wave_format.wBitsPerSample = 16;
238 object->wave_format.nBlockAlign = object->wave_format.wBitsPerSample * object->wave_format.nChannels / 8;
239 object->wave_format.nAvgBytesPerSec = object->wave_format.nBlockAlign * object->wave_format.nSamplesPerSec;
241 *ppObj = &object->IAudioData_iface;
243 return S_OK;