[AMSTREAM]
[reactos.git] / reactos / dll / directx / wine / amstream / audiodata.c
1 /*
2 * Implementation of IAudioData Interface
3 *
4 * Copyright 2012 Christian Costa
5 *
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.
10 *
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.
15 *
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
19 */
20
21 #include "amstream_private.h"
22
23 typedef struct {
24 IAudioData IAudioData_iface;
25 LONG ref;
26 } AMAudioDataImpl;
27
28 static inline AMAudioDataImpl *impl_from_IAudioData(IAudioData *iface)
29 {
30 return CONTAINING_RECORD(iface, AMAudioDataImpl, IAudioData_iface);
31 }
32
33 /*** IUnknown methods ***/
34 static HRESULT WINAPI IAudioDataImpl_QueryInterface(IAudioData *iface, REFIID riid, void **ret_iface)
35 {
36 TRACE("(%p)->(%s,%p)\n", iface, debugstr_guid(riid), ret_iface);
37
38 if (IsEqualGUID(riid, &IID_IUnknown) ||
39 IsEqualGUID(riid, &IID_IMemoryData) ||
40 IsEqualGUID(riid, &IID_IAudioData))
41 {
42 IAudioData_AddRef(iface);
43 *ret_iface = iface;
44 return S_OK;
45 }
46
47 ERR("(%p)->(%s,%p),not found\n", iface, debugstr_guid(riid), ret_iface);
48 return E_NOINTERFACE;
49 }
50
51 static ULONG WINAPI IAudioDataImpl_AddRef(IAudioData* iface)
52 {
53 AMAudioDataImpl *This = impl_from_IAudioData(iface);
54 ULONG ref = InterlockedIncrement(&This->ref);
55
56 TRACE("(%p)->(): new ref = %u\n", iface, This->ref);
57
58 return ref;
59 }
60
61 static ULONG WINAPI IAudioDataImpl_Release(IAudioData* iface)
62 {
63 AMAudioDataImpl *This = impl_from_IAudioData(iface);
64 ULONG ref = InterlockedDecrement(&This->ref);
65
66 TRACE("(%p)->(): new ref = %u\n", iface, This->ref);
67
68 if (!ref)
69 HeapFree(GetProcessHeap(), 0, This);
70
71 return ref;
72 }
73
74 /*** IMemoryData methods ***/
75 static HRESULT WINAPI IAudioDataImpl_SetBuffer(IAudioData* iface, DWORD size, BYTE *data, DWORD flags)
76 {
77 FIXME("(%p)->(%u,%p,%x): stub\n", iface, size, data, flags);
78
79 return E_NOTIMPL;
80 }
81
82 static HRESULT WINAPI IAudioDataImpl_GetInfo(IAudioData* iface, DWORD *length, BYTE **data, DWORD *actual_data)
83 {
84 FIXME("(%p)->(%p,%p,%p): stub\n", iface, length, data, actual_data);
85
86 return E_NOTIMPL;
87 }
88
89 static HRESULT WINAPI IAudioDataImpl_SetActual(IAudioData* iface, DWORD data_valid)
90 {
91 FIXME("(%p)->(%u): stub\n", iface, data_valid);
92
93 return E_NOTIMPL;
94 }
95
96 /*** IAudioData methods ***/
97 static HRESULT WINAPI IAudioDataImpl_GetFormat(IAudioData* iface, WAVEFORMATEX *wave_format_current)
98 {
99 FIXME("(%p)->(%p): stub\n", iface, wave_format_current);
100
101 return E_NOTIMPL;
102 }
103
104 static HRESULT WINAPI IAudioDataImpl_SetFormat(IAudioData* iface, const WAVEFORMATEX *wave_format)
105 {
106 FIXME("(%p)->(%p): stub\n", iface, wave_format);
107
108 return E_NOTIMPL;
109 }
110
111 static const struct IAudioDataVtbl AudioData_Vtbl =
112 {
113 /*** IUnknown methods ***/
114 IAudioDataImpl_QueryInterface,
115 IAudioDataImpl_AddRef,
116 IAudioDataImpl_Release,
117 /*** IMemoryData methods ***/
118 IAudioDataImpl_SetBuffer,
119 IAudioDataImpl_GetInfo,
120 IAudioDataImpl_SetActual,
121 /*** IAudioData methods ***/
122 IAudioDataImpl_GetFormat,
123 IAudioDataImpl_SetFormat
124 };
125
126 HRESULT AMAudioData_create(IUnknown *pUnkOuter, LPVOID *ppObj)
127 {
128 AMAudioDataImpl *object;
129
130 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
131
132 if (pUnkOuter)
133 return CLASS_E_NOAGGREGATION;
134
135 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(AMAudioDataImpl));
136 if (!object)
137 return E_OUTOFMEMORY;
138
139 object->IAudioData_iface.lpVtbl = &AudioData_Vtbl;
140 object->ref = 1;
141
142 *ppObj = &object->IAudioData_iface;
143
144 return S_OK;
145 }