ReactOS 0.4.17-dev-966-gf06eace
audiodata.c
Go to the documentation of this file.
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
29
30typedef struct {
39
41{
42 return CONTAINING_RECORD(iface, AMAudioDataImpl, IAudioData_iface);
43}
44
45/*** IUnknown methods ***/
47{
48 TRACE("(%p)->(%s,%p)\n", iface, debugstr_guid(riid), ret_iface);
49
51 IsEqualGUID(riid, &IID_IAudioData))
52 {
53 IAudioData_AddRef(iface);
54 *ret_iface = iface;
55 return S_OK;
56 }
57
58 ERR("(%p)->(%s,%p),not found\n", iface, debugstr_guid(riid), ret_iface);
59 return E_NOINTERFACE;
60}
61
63{
66
67 TRACE("(%p)->(): new ref = %lu\n", iface, This->ref);
68
69 return ref;
70}
71
73{
74 AMAudioDataImpl *audiodata = impl_from_IAudioData(iface);
75 ULONG ref = InterlockedDecrement(&audiodata->ref);
76
77 TRACE("%p decreasing refcount to %lu.\n", audiodata, ref);
78
79 if (!ref)
80 {
81 if (audiodata->data_owned)
82 free(audiodata->data);
83 free(audiodata);
84 }
85
86 return ref;
87}
88
89/*** IMemoryData methods ***/
91{
93
94 TRACE("(%p)->(%lu,%p,%lx)\n", iface, size, data, flags);
95
96 if (!size)
97 {
98 return E_INVALIDARG;
99 }
100
101 if (This->data_owned)
102 {
103 free(This->data);
104 This->data_owned = FALSE;
105 }
106
107 This->size = size;
108 This->data = data;
109
110 if (!This->data)
111 {
112 This->data = malloc(This->size);
113 This->data_owned = TRUE;
114 if (!This->data)
115 {
116 return E_OUTOFMEMORY;
117 }
118 }
119
120 return S_OK;
121}
122
124{
126
127 TRACE("(%p)->(%p,%p,%p)\n", iface, length, data, actual_data);
128
129 if (!This->data)
130 {
131 return MS_E_NOTINIT;
132 }
133
134 if (length)
135 {
136 *length = This->size;
137 }
138 if (data)
139 {
140 *data = This->data;
141 }
142 if (actual_data)
143 {
144 *actual_data = This->actual_data;
145 }
146
147 return S_OK;
148}
149
151{
153
154 TRACE("(%p)->(%lu)\n", iface, data_valid);
155
156 if (data_valid > This->size)
157 {
158 return E_INVALIDARG;
159 }
160
161 This->actual_data = data_valid;
162
163 return S_OK;
164}
165
166/*** IAudioData methods ***/
168{
170
171 TRACE("(%p)->(%p)\n", iface, wave_format_current);
172
173 if (!wave_format_current)
174 {
175 return E_POINTER;
176 }
177
178 *wave_format_current = This->wave_format;
179
180 return S_OK;
181}
182
184{
186
187 TRACE("(%p)->(%p)\n", iface, wave_format);
188
189 if (!wave_format)
190 {
191 return E_POINTER;
192 }
193
194 if (WAVE_FORMAT_PCM != wave_format->wFormatTag)
195 {
196 return E_INVALIDARG;
197 }
198
199 This->wave_format = *wave_format;
200
201 return S_OK;
202}
203
204static const struct IAudioDataVtbl AudioData_Vtbl =
205{
206 /*** IUnknown methods ***/
210 /*** IMemoryData methods ***/
214 /*** IAudioData methods ***/
217};
218
220{
222
223 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
224
225 if (pUnkOuter)
227
228 if (!(object = calloc(1, sizeof(*object))))
229 return E_OUTOFMEMORY;
230
231 object->IAudioData_iface.lpVtbl = &AudioData_Vtbl;
232 object->ref = 1;
233
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;
240
241 *ppObj = &object->IAudioData_iface;
242
243 return S_OK;
244}
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
static HRESULT WINAPI IAudioDataImpl_GetFormat(IAudioData *iface, WAVEFORMATEX *wave_format_current)
Definition: audiodata.c:167
static ULONG WINAPI IAudioDataImpl_AddRef(IAudioData *iface)
Definition: audiodata.c:62
static HRESULT WINAPI IAudioDataImpl_SetBuffer(IAudioData *iface, DWORD size, BYTE *data, DWORD flags)
Definition: audiodata.c:90
static HRESULT WINAPI IAudioDataImpl_SetFormat(IAudioData *iface, const WAVEFORMATEX *wave_format)
Definition: audiodata.c:183
static const struct IAudioDataVtbl AudioData_Vtbl
Definition: audiodata.c:204
static HRESULT WINAPI IAudioDataImpl_QueryInterface(IAudioData *iface, REFIID riid, void **ret_iface)
Definition: audiodata.c:46
static AMAudioDataImpl * impl_from_IAudioData(IAudioData *iface)
Definition: audiodata.c:40
static HRESULT WINAPI IAudioDataImpl_SetActual(IAudioData *iface, DWORD data_valid)
Definition: audiodata.c:150
static ULONG WINAPI IAudioDataImpl_Release(IAudioData *iface)
Definition: audiodata.c:72
HRESULT AMAudioData_create(IUnknown *pUnkOuter, LPVOID *ppObj)
Definition: audiodata.c:219
static HRESULT WINAPI IAudioDataImpl_GetInfo(IAudioData *iface, DWORD *length, BYTE **data, DWORD *actual_data)
Definition: audiodata.c:123
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define WAVE_FORMAT_PCM
Definition: constants.h:425
#define ERR(fmt,...)
Definition: precomp.h:57
const GUID IID_IUnknown
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_INVALIDARG
Definition: ddrawi.h:101
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLsizeiptr size
Definition: glext.h:5919
GLbitfield flags
Definition: glext.h:7161
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
REFIID riid
Definition: atlbase.h:39
#define S_OK
Definition: intsafe.h:52
#define debugstr_guid
Definition: kernel32.h:35
long LONG
Definition: pedump.c:60
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
#define REFIID
Definition: guiddef.h:118
#define calloc
Definition: rosglue.h:14
#define TRACE(s)
Definition: solgame.cpp:4
WAVEFORMATEX wave_format
Definition: audiodata.c:37
DWORD actual_data
Definition: audiodata.c:36
IAudioData IAudioData_iface
Definition: audiodata.c:31
Definition: send.c:48
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
#define WINAPI
Definition: msvc.h:6
#define E_NOINTERFACE
Definition: winerror.h:3479
#define CLASS_E_NOAGGREGATION
Definition: winerror.h:3771
#define E_POINTER
Definition: winerror.h:3480
unsigned char BYTE
Definition: xxhash.c:193