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