1545
|
1 #include "cmediasample.h"
|
2069
|
2 #include "wine/winerror.h"
|
168
|
3 #include <stdio.h>
|
|
4 #include <string.h>
|
7386
|
5 #include <stdlib.h>
|
1545
|
6
|
8292
|
7 /*
|
|
8 * currently hack to make some extra room for DS Acel codec which
|
|
9 * seems to overwrite allocated memory - FIXME better later
|
|
10 * check the buffer allocation
|
|
11 */
|
|
12 static const int SAFETY_ACEL = 1024;
|
|
13
|
3056
|
14 static long STDCALL CMediaSample_QueryInterface(IUnknown* This,
|
7386
|
15 /* [in] */ const GUID* iid,
|
1545
|
16 /* [iid_is][out] */ void **ppv)
|
168
|
17 {
|
3056
|
18 Debug printf("CMediaSample_QueryInterface(%p) called\n", This);
|
1545
|
19 if (!ppv)
|
|
20 return E_INVALIDARG;
|
3056
|
21 if (memcmp(iid, &IID_IUnknown, sizeof(*iid)) == 0)
|
168
|
22 {
|
3056
|
23 *ppv = (void*)This;
|
|
24 ((IMediaSample*) This)->vt->AddRef(This);
|
168
|
25 return 0;
|
|
26 }
|
3056
|
27 if (memcmp(iid, &IID_IMediaSample, sizeof(*iid)) == 0)
|
168
|
28 {
|
3056
|
29 *ppv = (void*)This;
|
|
30 ((IMediaSample*) This)->vt->AddRef(This);
|
168
|
31 return 0;
|
|
32 }
|
1545
|
33 return E_NOINTERFACE;
|
168
|
34 }
|
|
35
|
1545
|
36 static long STDCALL CMediaSample_AddRef(IUnknown* This)
|
168
|
37 {
|
3056
|
38 Debug printf("CMediaSample_AddRef(%p) called\n", This);
|
168
|
39 ((CMediaSample*)This)->refcount++;
|
|
40 return 0;
|
|
41 }
|
1545
|
42
|
3056
|
43 void CMediaSample_Destroy(CMediaSample* This)
|
|
44 {
|
|
45
|
|
46 Debug printf("CMediaSample_Destroy(%p) called (ref:%d)\n", This, This->refcount);
|
|
47 free(This->vt);
|
|
48 free(This->own_block);
|
|
49 if (This->media_type.pbFormat)
|
|
50 CoTaskMemFree(This->media_type.pbFormat);
|
|
51 free(This);
|
|
52 }
|
|
53
|
1545
|
54 static long STDCALL CMediaSample_Release(IUnknown* This)
|
168
|
55 {
|
3467
|
56 CMediaSample* parent = (CMediaSample*)This;
|
3056
|
57 Debug printf("CMediaSample_Release(%p) called (new ref:%d)\n",
|
1545
|
58 This, ((CMediaSample*)This)->refcount-1);
|
3467
|
59
|
|
60 if (--((CMediaSample*) This)->refcount == 0)
|
3056
|
61 {
|
1545
|
62 parent->all->vt->ReleaseBuffer((IMemAllocator*)(parent->all),
|
|
63 (IMediaSample*)This);
|
3056
|
64 }
|
168
|
65 return 0;
|
|
66 }
|
1545
|
67
|
3467
|
68 static HRESULT STDCALL CMediaSample_GetPointer(IMediaSample* This,
|
|
69 /* [out] */ BYTE** ppBuffer)
|
168
|
70 {
|
3467
|
71 Debug printf("CMediaSample_GetPointer(%p) called -> %p, size: %d %d\n", This, ((CMediaSample*) This)->block, ((CMediaSample*)This)->actual_size, ((CMediaSample*)This)->size);
|
1545
|
72 if (!ppBuffer)
|
|
73 return E_INVALIDARG;
|
3467
|
74 *ppBuffer = (BYTE*) ((CMediaSample*) This)->block;
|
168
|
75 return 0;
|
|
76 }
|
|
77
|
1545
|
78 static long STDCALL CMediaSample_GetSize(IMediaSample * This)
|
168
|
79 {
|
3467
|
80 Debug printf("CMediaSample_GetSize(%p) called -> %d\n", This, ((CMediaSample*) This)->size);
|
|
81 return ((CMediaSample*) This)->size;
|
168
|
82 }
|
|
83
|
1545
|
84 static HRESULT STDCALL CMediaSample_GetTime(IMediaSample * This,
|
|
85 /* [out] */ REFERENCE_TIME *pTimeStart,
|
|
86 /* [out] */ REFERENCE_TIME *pTimeEnd)
|
168
|
87 {
|
8292
|
88 Debug printf("CMediaSample_GetTime(%p) called (UNIMPLEMENTED)\n", This);
|
168
|
89 return E_NOTIMPL;
|
|
90 }
|
|
91
|
1545
|
92 static HRESULT STDCALL CMediaSample_SetTime(IMediaSample * This,
|
|
93 /* [in] */ REFERENCE_TIME *pTimeStart,
|
|
94 /* [in] */ REFERENCE_TIME *pTimeEnd)
|
168
|
95 {
|
8292
|
96 Debug printf("CMediaSample_SetTime(%p) called (UNIMPLEMENTED)\n", This);
|
168
|
97 return E_NOTIMPL;
|
|
98 }
|
|
99
|
1545
|
100 static HRESULT STDCALL CMediaSample_IsSyncPoint(IMediaSample * This)
|
168
|
101 {
|
3056
|
102 Debug printf("CMediaSample_IsSyncPoint(%p) called\n", This);
|
1545
|
103 if (((CMediaSample*)This)->isSyncPoint)
|
|
104 return 0;
|
168
|
105 return 1;
|
|
106 }
|
|
107
|
1545
|
108 static HRESULT STDCALL CMediaSample_SetSyncPoint(IMediaSample * This,
|
|
109 long bIsSyncPoint)
|
168
|
110 {
|
3056
|
111 Debug printf("CMediaSample_SetSyncPoint(%p) called\n", This);
|
3467
|
112 ((CMediaSample*)This)->isSyncPoint = bIsSyncPoint;
|
168
|
113 return 0;
|
|
114 }
|
|
115
|
1545
|
116 static HRESULT STDCALL CMediaSample_IsPreroll(IMediaSample * This)
|
168
|
117 {
|
3056
|
118 Debug printf("CMediaSample_IsPreroll(%p) called\n", This);
|
1545
|
119
|
|
120 if (((CMediaSample*)This)->isPreroll)
|
168
|
121 return 0;//S_OK
|
1545
|
122
|
|
123 return 1;//S_FALSE
|
168
|
124 }
|
|
125
|
1545
|
126 static HRESULT STDCALL CMediaSample_SetPreroll(IMediaSample * This,
|
|
127 long bIsPreroll)
|
168
|
128 {
|
3056
|
129 Debug printf("CMediaSample_SetPreroll(%p) called\n", This);
|
168
|
130 ((CMediaSample*)This)->isPreroll=bIsPreroll;
|
|
131 return 0;
|
|
132 }
|
|
133
|
3056
|
134 static long STDCALL CMediaSample_GetActualDataLength(IMediaSample* This)
|
168
|
135 {
|
3056
|
136 Debug printf("CMediaSample_GetActualDataLength(%p) called -> %d\n", This, ((CMediaSample*)This)->actual_size);
|
168
|
137 return ((CMediaSample*)This)->actual_size;
|
|
138 }
|
|
139
|
3056
|
140 static HRESULT STDCALL CMediaSample_SetActualDataLength(IMediaSample* This,
|
1545
|
141 long __MIDL_0010)
|
168
|
142 {
|
3467
|
143 CMediaSample* cms = (CMediaSample*)This;
|
3056
|
144 Debug printf("CMediaSample_SetActualDataLength(%p, %ld) called\n", This, __MIDL_0010);
|
8292
|
145
|
3467
|
146 if (__MIDL_0010 > cms->size)
|
168
|
147 {
|
3467
|
148 char* c = cms->own_block;
|
8292
|
149 Debug printf("CMediaSample - buffer overflow %ld %d %p %p\n",
|
3467
|
150 __MIDL_0010, ((CMediaSample*)This)->size, cms->own_block, cms->block);
|
8292
|
151 cms->own_block = (char*) realloc(cms->own_block, (size_t) __MIDL_0010 + SAFETY_ACEL);
|
3467
|
152 if (c == cms->block)
|
|
153 cms->block = cms->own_block;
|
|
154 cms->size = __MIDL_0010;
|
168
|
155 }
|
3467
|
156 cms->actual_size = __MIDL_0010;
|
168
|
157 return 0;
|
|
158 }
|
|
159
|
3056
|
160 static HRESULT STDCALL CMediaSample_GetMediaType(IMediaSample* This,
|
|
161 AM_MEDIA_TYPE** ppMediaType)
|
168
|
162 {
|
3056
|
163 AM_MEDIA_TYPE* t;
|
|
164 Debug printf("CMediaSample_GetMediaType(%p) called\n", This);
|
168
|
165 if(!ppMediaType)
|
1545
|
166 return E_INVALIDARG;
|
168
|
167 if(!((CMediaSample*)This)->type_valid)
|
|
168 {
|
|
169 *ppMediaType=0;
|
|
170 return 1;
|
|
171 }
|
3056
|
172
|
|
173 t = &((CMediaSample*)This)->media_type;
|
|
174 // if(t.pbFormat)CoTaskMemFree(t.pbFormat);
|
|
175 (*ppMediaType) = (AM_MEDIA_TYPE*)CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE));
|
|
176 **ppMediaType = *t;
|
|
177 (*ppMediaType)->pbFormat = (char*)CoTaskMemAlloc(t->cbFormat);
|
|
178 memcpy((*ppMediaType)->pbFormat, t->pbFormat, t->cbFormat);
|
|
179 // *ppMediaType=0; //media type was not changed
|
1545
|
180 return 0;
|
168
|
181 }
|
|
182
|
1545
|
183 static HRESULT STDCALL CMediaSample_SetMediaType(IMediaSample * This,
|
|
184 AM_MEDIA_TYPE *pMediaType)
|
168
|
185 {
|
3056
|
186 AM_MEDIA_TYPE* t;
|
|
187 Debug printf("CMediaSample_SetMediaType(%p) called\n", This);
|
1545
|
188 if (!pMediaType)
|
|
189 return E_INVALIDARG;
|
3056
|
190 t = &((CMediaSample*)This)->media_type;
|
|
191 if (t->pbFormat)
|
|
192 CoTaskMemFree(t->pbFormat);
|
|
193 t = pMediaType;
|
3467
|
194 if (t->cbFormat)
|
|
195 {
|
|
196 t->pbFormat = (char*)CoTaskMemAlloc(t->cbFormat);
|
|
197 memcpy(t->pbFormat, pMediaType->pbFormat, t->cbFormat);
|
|
198 }
|
|
199 else
|
|
200 t->pbFormat = 0;
|
|
201 ((CMediaSample*) This)->type_valid=1;
|
1545
|
202
|
168
|
203 return 0;
|
|
204 }
|
|
205
|
1545
|
206 static HRESULT STDCALL CMediaSample_IsDiscontinuity(IMediaSample * This)
|
168
|
207 {
|
3056
|
208 Debug printf("CMediaSample_IsDiscontinuity(%p) called\n", This);
|
3467
|
209 return ((CMediaSample*) This)->isDiscontinuity;
|
168
|
210 }
|
|
211
|
1545
|
212 static HRESULT STDCALL CMediaSample_SetDiscontinuity(IMediaSample * This,
|
|
213 long bDiscontinuity)
|
168
|
214 {
|
3467
|
215 Debug printf("CMediaSample_SetDiscontinuity(%p) called (%ld)\n", This, bDiscontinuity);
|
|
216 ((CMediaSample*) This)->isDiscontinuity = bDiscontinuity;
|
|
217 return 0;
|
1545
|
218 }
|
|
219
|
|
220 static HRESULT STDCALL CMediaSample_GetMediaTime(IMediaSample * This,
|
|
221 /* [out] */ LONGLONG *pTimeStart,
|
|
222 /* [out] */ LONGLONG *pTimeEnd)
|
|
223 {
|
3056
|
224 Debug printf("CMediaSample_GetMediaTime(%p) called\n", This);
|
3467
|
225 if (pTimeStart)
|
|
226 *pTimeStart = ((CMediaSample*) This)->time_start;
|
|
227 if (pTimeEnd)
|
|
228 *pTimeEnd = ((CMediaSample*) This)->time_end;
|
|
229 return 0;
|
1545
|
230 }
|
|
231
|
|
232 static HRESULT STDCALL CMediaSample_SetMediaTime(IMediaSample * This,
|
|
233 /* [in] */ LONGLONG *pTimeStart,
|
|
234 /* [in] */ LONGLONG *pTimeEnd)
|
|
235 {
|
3056
|
236 Debug printf("CMediaSample_SetMediaTime(%p) called\n", This);
|
3467
|
237 if (pTimeStart)
|
|
238 ((CMediaSample*) This)->time_start = *pTimeStart;
|
|
239 if (pTimeEnd)
|
|
240 ((CMediaSample*) This)->time_end = *pTimeEnd;
|
|
241 return 0;
|
168
|
242 }
|
|
243
|
3467
|
244 // extension for direct memory write or decompressed data
|
3056
|
245 static void CMediaSample_SetPointer(CMediaSample* This, char* pointer)
|
168
|
246 {
|
3056
|
247 Debug printf("CMediaSample_SetPointer(%p) called -> %p\n", This, pointer);
|
|
248 if (pointer)
|
|
249 This->block = pointer;
|
|
250 else
|
|
251 This->block = This->own_block;
|
|
252 }
|
1545
|
253
|
3056
|
254 static void CMediaSample_ResetPointer(CMediaSample* This)
|
|
255 {
|
|
256 Debug printf("CMediaSample_ResetPointer(%p) called\n", This);
|
|
257 This->block = This->own_block;
|
168
|
258 }
|
|
259
|
3056
|
260 CMediaSample* CMediaSampleCreate(IMemAllocator* allocator, int _size)
|
168
|
261 {
|
3467
|
262 CMediaSample* This = (CMediaSample*) malloc(sizeof(CMediaSample));
|
|
263 if (!This)
|
|
264 return NULL;
|
|
265
|
|
266 // some hack here!
|
|
267 // it looks like Acelp decoder is actually accessing
|
|
268 // the allocated memory before it sets the new size for it ???
|
|
269 // -- maybe it's being initialized with wrong parameters
|
|
270 // anyway this is fixes the problem somehow with some reserves
|
|
271 //
|
|
272 // using different trick for now - in DS_Audio modify sample size
|
|
273 //if (_size < 0x1000)
|
|
274 // _size = (_size + 0xfff) & ~0xfff;
|
|
275
|
3056
|
276 This->vt = (IMediaSample_vt*) malloc(sizeof(IMediaSample_vt));
|
8292
|
277 This->own_block = (char*) malloc((size_t)_size + SAFETY_ACEL);
|
3467
|
278 This->media_type.pbFormat = 0;
|
|
279
|
|
280 if (!This->vt || !This->own_block)
|
|
281 {
|
|
282 CMediaSample_Destroy(This);
|
|
283 return NULL;
|
|
284 }
|
3056
|
285
|
|
286 This->vt->QueryInterface = CMediaSample_QueryInterface;
|
|
287 This->vt->AddRef = CMediaSample_AddRef;
|
|
288 This->vt->Release = CMediaSample_Release;
|
|
289 This->vt->GetPointer = CMediaSample_GetPointer;
|
|
290 This->vt->GetSize = CMediaSample_GetSize;
|
|
291 This->vt->GetTime = CMediaSample_GetTime;
|
|
292 This->vt->SetTime = CMediaSample_SetTime;
|
|
293 This->vt->IsSyncPoint = CMediaSample_IsSyncPoint;
|
|
294 This->vt->SetSyncPoint = CMediaSample_SetSyncPoint;
|
|
295 This->vt->IsPreroll = CMediaSample_IsPreroll;
|
|
296 This->vt->SetPreroll = CMediaSample_SetPreroll;
|
|
297 This->vt->GetActualDataLength = CMediaSample_GetActualDataLength;
|
|
298 This->vt->SetActualDataLength = CMediaSample_SetActualDataLength;
|
|
299 This->vt->GetMediaType = CMediaSample_GetMediaType;
|
|
300 This->vt->SetMediaType = CMediaSample_SetMediaType;
|
|
301 This->vt->IsDiscontinuity = CMediaSample_IsDiscontinuity;
|
|
302 This->vt->SetDiscontinuity = CMediaSample_SetDiscontinuity;
|
|
303 This->vt->GetMediaTime = CMediaSample_GetMediaTime;
|
|
304 This->vt->SetMediaTime = CMediaSample_SetMediaTime;
|
|
305
|
|
306 This->all = allocator;
|
|
307 This->size = _size;
|
|
308 This->refcount = 0; // increased by MemAllocator
|
|
309 This->actual_size = 0;
|
|
310 This->isPreroll = 0;
|
3467
|
311 This->isDiscontinuity = 1;
|
|
312 This->time_start = 0;
|
|
313 This->time_end = 0;
|
3056
|
314 This->type_valid = 0;
|
|
315 This->block = This->own_block;
|
|
316
|
|
317 This->SetPointer = CMediaSample_SetPointer;
|
|
318 This->ResetPointer = CMediaSample_ResetPointer;
|
|
319
|
|
320 Debug printf("CMediaSample_Create(%p) called - sample size %d, buffer %p\n",
|
|
321 This, This->size, This->block);
|
|
322
|
|
323 return This;
|
168
|
324 }
|