2 * Modified for use with MPlayer, detailed changelog at
3 * http://svn.mplayerhq.hu/mplayer/trunk/
6 #include "cmediasample.h"
8 #include "loader/wine/winerror.h"
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
18 static const int SAFETY_ACEL
= 1024;
21 * \brief IPin::QueryInternalConnections (retries pin's internal connections)
23 * \param[in] This pointer to IPin interface
24 * \param[out] apPin Array that receives pins, internally connected to this
25 * \param[in,out] nPint Size of an array
27 * \return S_OK - success
28 * \return S_FALSE - pin rejects media type
29 * \return E_NOTIMPL - not implemented
32 static long STDCALL
CMediaSample_QueryInterface(IUnknown
* This
,
33 /* [in] */ const GUID
* iid
,
34 /* [iid_is][out] */ void **ppv
)
36 Debug
printf("CMediaSample_QueryInterface(%p) called\n", This
);
39 if (memcmp(iid
, &IID_IUnknown
, sizeof(*iid
)) == 0)
42 ((IMediaSample
*) This
)->vt
->AddRef(This
);
45 if (memcmp(iid
, &IID_IMediaSample
, sizeof(*iid
)) == 0)
48 ((IMediaSample
*) This
)->vt
->AddRef(This
);
55 * \brief IUnknown::AddRef (increases reference counter for interface)
57 * \param[in] This pointer to IUnknown class
59 * \return new value of reference counter
62 * Return value should be used only for debug purposes
65 static long STDCALL
CMediaSample_AddRef(IUnknown
* This
)
67 Debug
printf("CMediaSample_AddRef(%p) called\n", This
);
68 ((CMediaSample
*)This
)->refcount
++;
73 * \brief CMediaSample destructor
75 * \param[in] This pointer to CMediaSample object
78 void CMediaSample_Destroy(CMediaSample
* This
)
81 Debug
printf("CMediaSample_Destroy(%p) called (ref:%d)\n", This
, This
->refcount
);
83 free(This
->own_block
);
84 if(((CMediaSample
*)This
)->type_valid
)
85 FreeMediaType(&(This
->media_type
));
90 * \brief IUnknown::Release (desreases reference counter for interface)
92 * \param[in] This pointer to IUnknown class
94 * \return new value of reference counter
97 * When reference counter reaches zero calls destructor
98 * Return value should be used only for debug purposes
101 static long STDCALL
CMediaSample_Release(IUnknown
* This
)
103 CMediaSample
* parent
= (CMediaSample
*)This
;
104 Debug
printf("CMediaSample_Release(%p) called (new ref:%d)\n",
105 This
, ((CMediaSample
*)This
)->refcount
-1);
107 if (--((CMediaSample
*) This
)->refcount
== 0)
109 parent
->all
->vt
->ReleaseBuffer((IMemAllocator
*)(parent
->all
),
110 (IMediaSample
*)This
);
116 * \brief IMediaSample::GetPointer (retrieves a read/write pointer to the media sample's buffer)
118 * \param[in] This pointer to CMediaSample object
119 * \param[out] address of variable that receives pointer to sample's buffer
121 * \return S_OK success
122 * \return apropriate error otherwise
124 * \note The calles should not free or reallocate buffer
127 static HRESULT STDCALL
CMediaSample_GetPointer(IMediaSample
* This
,
128 /* [out] */ BYTE
** ppBuffer
)
130 Debug
printf("CMediaSample_GetPointer(%p) called -> %p, size: %d %d\n", This
, ((CMediaSample
*) This
)->block
, ((CMediaSample
*)This
)->actual_size
, ((CMediaSample
*)This
)->size
);
133 *ppBuffer
= (BYTE
*) ((CMediaSample
*) This
)->block
;
138 * \brief IMediaSample::GetSize (retrieves a size of buffer in bytes)
140 * \param[in] This pointer to CMediaSample object
142 * \return size of buffer in bytes
145 static long STDCALL
CMediaSample_GetSize(IMediaSample
* This
)
147 Debug
printf("CMediaSample_GetSize(%p) called -> %d\n", This
, ((CMediaSample
*) This
)->size
);
148 return ((CMediaSample
*) This
)->size
;
152 * \brief IMediaSample::GetTime (retrieves a stream time at wich sample sould start and finish)
154 * \param[in] This pointer to CMediaSample object
155 * \param[out] pTimeStart pointer to variable that receives start time
156 * \param[out] pTimeEnd pointer to variable that receives end time
158 * \return S_OK success
159 * \return VFW_E_NO_STOP_TIME The sample has valid start time, but no stop time
160 * \return VFW_E_SAMPLE_TIME_NOT_SET The sample is not time-stamped
163 * Both values are relative to stream time
166 static HRESULT STDCALL
CMediaSample_GetTime(IMediaSample
* This
,
167 /* [out] */ REFERENCE_TIME
*pTimeStart
,
168 /* [out] */ REFERENCE_TIME
*pTimeEnd
)
170 Debug
printf("CMediaSample_GetTime(%p) called (UNIMPLEMENTED)\n", This
);
175 * \brief IMediaSample::SetTime (sets a stream time at wich sample sould start and finish)
177 * \param[in] This pointer to CMediaSample object
178 * \param[out] pTimeStart pointer to variable that contains start time
179 * \param[out] pTimeEnd pointer to variable that contains end time
181 * \return S_OK success
182 * \return apropriate error otherwise
185 * Both values are relative to stream time
186 * To invalidate the stream times set pTimeStart and pTimeEnd to NULL. this will cause
187 * IMEdiaSample::GetTime to return VFW_E_SAMPLE_TIME_NOT_SET
190 static HRESULT STDCALL
CMediaSample_SetTime(IMediaSample
* This
,
191 /* [in] */ REFERENCE_TIME
*pTimeStart
,
192 /* [in] */ REFERENCE_TIME
*pTimeEnd
)
194 Debug
printf("CMediaSample_SetTime(%p) called (UNIMPLEMENTED)\n", This
);
199 * \brief IMediaSample::IsSyncPoint (determines if start of this sample is sync point)
201 * \param[in] This pointer to CMediaSample object
203 * \return S_OK start of this sample is sync point
204 * \return S_FALSE start of this sample is not sync point
207 * If bTemporalCompression of AM_MEDIA_TYPE is FALSE, all samples are sync points.
210 static HRESULT STDCALL
CMediaSample_IsSyncPoint(IMediaSample
* This
)
212 Debug
printf("CMediaSample_IsSyncPoint(%p) called\n", This
);
213 if (((CMediaSample
*)This
)->isSyncPoint
)
219 * \brief IMediaSample::SetSyncPoint (specifies if start of this sample is sync point)
221 * \param[in] This pointer to CMediaSample object
222 * \param[in] bIsSyncPoint specifies whether this is sync point or not
224 * \return S_OK success
225 * \return apropriate error code otherwise
228 static HRESULT STDCALL
CMediaSample_SetSyncPoint(IMediaSample
* This
,
231 Debug
printf("CMediaSample_SetSyncPoint(%p) called\n", This
);
232 ((CMediaSample
*)This
)->isSyncPoint
= bIsSyncPoint
;
237 * \brief IMediaSample::IsPreroll (determines if this sample is preroll sample)
239 * \param[in] This pointer to CMediaSample object
241 * \return S_OK if this sample is preroll sample
242 * \return S_FALSE if this sample is not preroll sample
245 * Preroll samples are processed but not displayed. They are lokated in media stream
246 * before displayable samples.
249 static HRESULT STDCALL
CMediaSample_IsPreroll(IMediaSample
* This
)
251 Debug
printf("CMediaSample_IsPreroll(%p) called\n", This
);
253 if (((CMediaSample
*)This
)->isPreroll
)
260 * \brief IMediaSample::SetPreroll (specifies if this sample is preroll sample)
262 * \param[in] This pointer to CMediaSample object
263 * \param[in] bIsPreroll specifies whether this sample is preroll sample or not
265 * \return S_OK success
266 * \return apropriate error code otherwise
269 * Preroll samples are processed but not displayed. They are lokated in media stream
270 * before displayable samples.
273 static HRESULT STDCALL
CMediaSample_SetPreroll(IMediaSample
* This
,
276 Debug
printf("CMediaSample_SetPreroll(%p) called\n", This
);
277 ((CMediaSample
*)This
)->isPreroll
=bIsPreroll
;
282 * \brief IMediaSample::GetActualDataLength (retrieves the length of valid data in the buffer)
284 * \param[in] This pointer to CMediaSample object
286 * \return length of valid data in buffer in bytes
289 static long STDCALL
CMediaSample_GetActualDataLength(IMediaSample
* This
)
291 Debug
printf("CMediaSample_GetActualDataLength(%p) called -> %d\n", This
, ((CMediaSample
*)This
)->actual_size
);
292 return ((CMediaSample
*)This
)->actual_size
;
296 * \brief IMediaSample::SetActualDataLength (specifies the length of valid data in the buffer)
298 * \param[in] This pointer to CMediaSample object
299 * \param[in] __MIDL_0010 length of data in sample in bytes
301 * \return S_OK success
302 * \return VFW_E_BUFFER_OVERFLOW length specified by parameter is larger than buffer size
305 static HRESULT STDCALL
CMediaSample_SetActualDataLength(IMediaSample
* This
,
308 CMediaSample
* cms
= (CMediaSample
*)This
;
309 Debug
printf("CMediaSample_SetActualDataLength(%p, %ld) called\n", This
, __MIDL_0010
);
311 if (__MIDL_0010
> cms
->size
)
313 char* c
= cms
->own_block
;
314 Debug
printf("CMediaSample - buffer overflow %ld %d %p %p\n",
315 __MIDL_0010
, ((CMediaSample
*)This
)->size
, cms
->own_block
, cms
->block
);
316 cms
->own_block
= realloc(cms
->own_block
, (size_t) __MIDL_0010
+ SAFETY_ACEL
);
318 cms
->block
= cms
->own_block
;
319 cms
->size
= __MIDL_0010
;
321 cms
->actual_size
= __MIDL_0010
;
326 * \brief IMediaSample::GetMediaType (retrieves media type, if it changed from previous sample)
328 * \param[in] This pointer to CMediaSample object
329 * \param[out] ppMediaType address of variable that receives pointer to AM_MEDIA_TYPE.
331 * \return S_OK success
332 * \return S_FALSE Media type was not changed from previous sample
333 * \return E_OUTOFMEMORY Insufficient memory
336 * If media type is not changed from previous sample, ppMediaType is null
337 * If method returns S_OK caller should free memory allocated for structure
338 * including pbFormat block
340 static HRESULT STDCALL
CMediaSample_GetMediaType(IMediaSample
* This
,
341 AM_MEDIA_TYPE
** ppMediaType
)
344 Debug
printf("CMediaSample_GetMediaType(%p) called\n", This
);
347 if(!((CMediaSample
*)This
)->type_valid
)
353 t
= &((CMediaSample
*)This
)->media_type
;
355 *ppMediaType
=CreateMediaType(t
);
356 // *ppMediaType=0; //media type was not changed
361 * \brief IMediaType::SetMediaType (specifies media type for sample)
363 * \param[in] This pointer to CMediaSample object
364 * \param[in] pMediaType pointer to AM_MEDIA_TYPE specifies new media type
366 * \return S_OK success
367 * \return E_OUTOFMEMORY insufficient memory
370 static HRESULT STDCALL
CMediaSample_SetMediaType(IMediaSample
* This
,
371 AM_MEDIA_TYPE
*pMediaType
)
374 Debug
printf("CMediaSample_SetMediaType(%p) called\n", This
);
377 t
= &((CMediaSample
*)This
)->media_type
;
378 if(((CMediaSample
*)This
)->type_valid
)
380 CopyMediaType(t
,pMediaType
);
381 ((CMediaSample
*) This
)->type_valid
=1;
387 * \brief IMediaSample::IsDiscontinuity (determines if this sample represents data break
390 * \param[in] This pointer to CMediaSample object
392 * \return S_OK if this sample is break in data stream
393 * \return S_FALSE otherwise
396 * Discontinuity occures when filter seeks to different place in the stream or when drops
400 static HRESULT STDCALL
CMediaSample_IsDiscontinuity(IMediaSample
* This
)
402 Debug
printf("CMediaSample_IsDiscontinuity(%p) called\n", This
);
403 return ((CMediaSample
*) This
)->isDiscontinuity
;
407 * \brief IMediaSample::IsDiscontinuity (specifies whether this sample represents data break
410 * \param[in] This pointer to CMediaSample object
411 * \param[in] bDiscontinuity if TRUE this sample represents discontinuity with previous sample
413 * \return S_OK success
414 * \return apropriate error code otherwise
417 static HRESULT STDCALL
CMediaSample_SetDiscontinuity(IMediaSample
* This
,
420 Debug
printf("CMediaSample_SetDiscontinuity(%p) called (%ld)\n", This
, bDiscontinuity
);
421 ((CMediaSample
*) This
)->isDiscontinuity
= bDiscontinuity
;
426 * \brief IMediaSample::GetMediaTime (retrieves the media times of this sample)
428 * \param[in] This pointer to CMediaSample object
429 * \param[out] pTimeStart pointer to variable that receives start time
430 * \param[out] pTimeEnd pointer to variable that receives end time
432 * \return S_OK success
433 * \return VFW_E_MEDIA_TIME_NOT_SET The sample is not time-stamped
436 static HRESULT STDCALL
CMediaSample_GetMediaTime(IMediaSample
* This
,
437 /* [out] */ LONGLONG
*pTimeStart
,
438 /* [out] */ LONGLONG
*pTimeEnd
)
440 Debug
printf("CMediaSample_GetMediaTime(%p) called\n", This
);
442 *pTimeStart
= ((CMediaSample
*) This
)->time_start
;
444 *pTimeEnd
= ((CMediaSample
*) This
)->time_end
;
449 * \brief IMediaSample::GetMediaTime (retrieves the media times of this sample)
451 * \param[in] This pointer to CMediaSample object
452 * \param[out] pTimeStart pointer to variable that specifies start time
453 * \param[out] pTimeEnd pointer to variable that specifies end time
455 * \return S_OK success
456 * \return apropriate error code otherwise
459 * To invalidate the media times set pTimeStart and pTimeEnd to NULL. this will cause
460 * IMEdiaSample::GetTime to return VFW_E_MEDIA_TIME_NOT_SET
462 static HRESULT STDCALL
CMediaSample_SetMediaTime(IMediaSample
* This
,
463 /* [in] */ LONGLONG
*pTimeStart
,
464 /* [in] */ LONGLONG
*pTimeEnd
)
466 Debug
printf("CMediaSample_SetMediaTime(%p) called\n", This
);
468 ((CMediaSample
*) This
)->time_start
= *pTimeStart
;
470 ((CMediaSample
*) This
)->time_end
= *pTimeEnd
;
475 * \brief CMediaSample::SetPointer (extension for direct memory write of decompressed data)
477 * \param[in] This pointer to CMediaSample object
478 * \param[in] pointer pointer to an external buffer to store data to
481 static void CMediaSample_SetPointer(CMediaSample
* This
, char* pointer
)
483 Debug
printf("CMediaSample_SetPointer(%p) called -> %p\n", This
, pointer
);
485 This
->block
= pointer
;
487 This
->block
= This
->own_block
;
491 * \brief CMediaSample::SetPointer (resets pointer to external buffer with internal one)
493 * \param[in] This pointer to CMediaSample object
496 static void CMediaSample_ResetPointer(CMediaSample
* This
)
498 Debug
printf("CMediaSample_ResetPointer(%p) called\n", This
);
499 This
->block
= This
->own_block
;
503 * \brief CMediaSample constructor
505 * \param[in] allocator IMemallocator interface of allocator to use
506 * \param[in] size size of internal buffer
508 * \return pointer to CMediaSample object of NULL if error occured
511 CMediaSample
* CMediaSampleCreate(IMemAllocator
* allocator
, int size
)
513 CMediaSample
* This
= malloc(sizeof(CMediaSample
));
518 // it looks like Acelp decoder is actually accessing
519 // the allocated memory before it sets the new size for it ???
520 // -- maybe it's being initialized with wrong parameters
521 // anyway this is fixes the problem somehow with some reserves
523 // using different trick for now - in DS_Audio modify sample size
525 // size = (size + 0xfff) & ~0xfff;
527 This
->vt
= malloc(sizeof(IMediaSample_vt
));
528 This
->own_block
= malloc((size_t)size
+ SAFETY_ACEL
);
529 This
->media_type
.pbFormat
= 0;
530 This
->media_type
.pUnk
= 0;
532 if (!This
->vt
|| !This
->own_block
)
534 CMediaSample_Destroy(This
);
538 This
->vt
->QueryInterface
= CMediaSample_QueryInterface
;
539 This
->vt
->AddRef
= CMediaSample_AddRef
;
540 This
->vt
->Release
= CMediaSample_Release
;
541 This
->vt
->GetPointer
= CMediaSample_GetPointer
;
542 This
->vt
->GetSize
= CMediaSample_GetSize
;
543 This
->vt
->GetTime
= CMediaSample_GetTime
;
544 This
->vt
->SetTime
= CMediaSample_SetTime
;
545 This
->vt
->IsSyncPoint
= CMediaSample_IsSyncPoint
;
546 This
->vt
->SetSyncPoint
= CMediaSample_SetSyncPoint
;
547 This
->vt
->IsPreroll
= CMediaSample_IsPreroll
;
548 This
->vt
->SetPreroll
= CMediaSample_SetPreroll
;
549 This
->vt
->GetActualDataLength
= CMediaSample_GetActualDataLength
;
550 This
->vt
->SetActualDataLength
= CMediaSample_SetActualDataLength
;
551 This
->vt
->GetMediaType
= CMediaSample_GetMediaType
;
552 This
->vt
->SetMediaType
= CMediaSample_SetMediaType
;
553 This
->vt
->IsDiscontinuity
= CMediaSample_IsDiscontinuity
;
554 This
->vt
->SetDiscontinuity
= CMediaSample_SetDiscontinuity
;
555 This
->vt
->GetMediaTime
= CMediaSample_GetMediaTime
;
556 This
->vt
->SetMediaTime
= CMediaSample_SetMediaTime
;
558 This
->all
= allocator
;
560 This
->refcount
= 0; // increased by MemAllocator
561 This
->actual_size
= 0;
563 This
->isDiscontinuity
= 1;
564 This
->time_start
= 0;
566 This
->type_valid
= 0;
567 This
->block
= This
->own_block
;
569 This
->SetPointer
= CMediaSample_SetPointer
;
570 This
->ResetPointer
= CMediaSample_ResetPointer
;
572 Debug
printf("CMediaSample_Create(%p) called - sample size %d, buffer %p\n",
573 This
, This
->size
, This
->block
);