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