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