2005-04-15 20:17:14 +00:00
|
|
|
/*
|
2006-06-22 13:34:00 +00:00
|
|
|
* Modified for use with MPlayer, detailed changelog at
|
|
|
|
* http://svn.mplayerhq.hu/mplayer/trunk/
|
2005-04-15 20:17:14 +00:00
|
|
|
*/
|
|
|
|
|
2001-08-16 00:50:02 +00:00
|
|
|
#include "cmediasample.h"
|
2007-02-23 09:58:01 +00:00
|
|
|
#include "mediatype.h"
|
2001-10-04 02:21:47 +00:00
|
|
|
#include "wine/winerror.h"
|
2001-03-20 00:05:27 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2002-09-13 19:43:17 +00:00
|
|
|
#include <stdlib.h>
|
2001-03-20 00:05:27 +00:00
|
|
|
|
2002-11-26 21:00:20 +00:00
|
|
|
/*
|
|
|
|
* currently hack to make some extra room for DS Acel codec which
|
|
|
|
* seems to overwrite allocated memory - FIXME better later
|
|
|
|
* check the buffer allocation
|
|
|
|
*/
|
|
|
|
static const int SAFETY_ACEL = 1024;
|
|
|
|
|
2007-01-28 16:53:33 +00:00
|
|
|
/**
|
|
|
|
* \brief IPin::QueryInternalConnections (retries pin's internal connections)
|
|
|
|
*
|
|
|
|
* \param[in] This pointer to IPin interface
|
|
|
|
* \param[out] apPin Array that receives pins, internally connected to this
|
|
|
|
* \param[in,out] nPint Size of an array
|
|
|
|
*
|
|
|
|
* \return S_OK - success
|
|
|
|
* \return S_FALSE - pin rejects media type
|
|
|
|
* \return E_NOTIMPL - not implemented
|
|
|
|
*
|
|
|
|
*/
|
2001-11-21 19:12:39 +00:00
|
|
|
static long STDCALL CMediaSample_QueryInterface(IUnknown* This,
|
2002-09-13 19:43:17 +00:00
|
|
|
/* [in] */ const GUID* iid,
|
2001-08-16 00:50:02 +00:00
|
|
|
/* [iid_is][out] */ void **ppv)
|
2001-03-20 00:05:27 +00:00
|
|
|
{
|
2001-11-21 19:12:39 +00:00
|
|
|
Debug printf("CMediaSample_QueryInterface(%p) called\n", This);
|
2001-08-16 00:50:02 +00:00
|
|
|
if (!ppv)
|
|
|
|
return E_INVALIDARG;
|
2001-11-21 19:12:39 +00:00
|
|
|
if (memcmp(iid, &IID_IUnknown, sizeof(*iid)) == 0)
|
2001-03-20 00:05:27 +00:00
|
|
|
{
|
2001-11-21 19:12:39 +00:00
|
|
|
*ppv = (void*)This;
|
|
|
|
((IMediaSample*) This)->vt->AddRef(This);
|
2001-03-20 00:05:27 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2001-11-21 19:12:39 +00:00
|
|
|
if (memcmp(iid, &IID_IMediaSample, sizeof(*iid)) == 0)
|
2001-03-20 00:05:27 +00:00
|
|
|
{
|
2001-11-21 19:12:39 +00:00
|
|
|
*ppv = (void*)This;
|
|
|
|
((IMediaSample*) This)->vt->AddRef(This);
|
2001-03-20 00:05:27 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2001-08-16 00:50:02 +00:00
|
|
|
return E_NOINTERFACE;
|
2001-03-20 00:05:27 +00:00
|
|
|
}
|
|
|
|
|
2007-01-28 16:53:33 +00:00
|
|
|
/**
|
|
|
|
* \brief IUnknown::AddRef (increases reference counter for interface)
|
|
|
|
*
|
|
|
|
* \param[in] This pointer to IUnknown class
|
|
|
|
*
|
|
|
|
* \return new value of reference counter
|
|
|
|
*
|
|
|
|
* \remarks
|
|
|
|
* Return value should be used only for debug purposes
|
|
|
|
*
|
|
|
|
*/
|
2001-08-16 00:50:02 +00:00
|
|
|
static long STDCALL CMediaSample_AddRef(IUnknown* This)
|
2001-03-20 00:05:27 +00:00
|
|
|
{
|
2001-11-21 19:12:39 +00:00
|
|
|
Debug printf("CMediaSample_AddRef(%p) called\n", This);
|
2001-03-20 00:05:27 +00:00
|
|
|
((CMediaSample*)This)->refcount++;
|
|
|
|
return 0;
|
|
|
|
}
|
2001-08-16 00:50:02 +00:00
|
|
|
|
2007-01-28 16:53:33 +00:00
|
|
|
/**
|
|
|
|
* \brief CMediaSample destructor
|
|
|
|
*
|
|
|
|
* \param[in] This pointer to CMediaSample object
|
|
|
|
*
|
|
|
|
*/
|
2001-11-21 19:12:39 +00:00
|
|
|
void CMediaSample_Destroy(CMediaSample* This)
|
|
|
|
{
|
|
|
|
|
|
|
|
Debug printf("CMediaSample_Destroy(%p) called (ref:%d)\n", This, This->refcount);
|
|
|
|
free(This->vt);
|
|
|
|
free(This->own_block);
|
2007-09-08 12:15:15 +00:00
|
|
|
if(((CMediaSample*)This)->type_valid)
|
2007-09-10 23:14:17 +00:00
|
|
|
FreeMediaType(&(This->media_type));
|
2001-11-21 19:12:39 +00:00
|
|
|
free(This);
|
|
|
|
}
|
|
|
|
|
2007-01-28 16:53:33 +00:00
|
|
|
/**
|
|
|
|
* \brief IUnknown::Release (desreases reference counter for interface)
|
|
|
|
*
|
|
|
|
* \param[in] This pointer to IUnknown class
|
|
|
|
*
|
|
|
|
* \return new value of reference counter
|
|
|
|
*
|
|
|
|
* \remarks
|
|
|
|
* When reference counter reaches zero calls destructor
|
|
|
|
* Return value should be used only for debug purposes
|
|
|
|
*
|
|
|
|
*/
|
2001-08-16 00:50:02 +00:00
|
|
|
static long STDCALL CMediaSample_Release(IUnknown* This)
|
2001-03-20 00:05:27 +00:00
|
|
|
{
|
2001-12-11 23:29:24 +00:00
|
|
|
CMediaSample* parent = (CMediaSample*)This;
|
2001-11-21 19:12:39 +00:00
|
|
|
Debug printf("CMediaSample_Release(%p) called (new ref:%d)\n",
|
|
|
|
This, ((CMediaSample*)This)->refcount-1);
|
2001-12-11 23:29:24 +00:00
|
|
|
|
|
|
|
if (--((CMediaSample*) This)->refcount == 0)
|
2001-11-21 19:12:39 +00:00
|
|
|
{
|
2001-08-16 00:50:02 +00:00
|
|
|
parent->all->vt->ReleaseBuffer((IMemAllocator*)(parent->all),
|
|
|
|
(IMediaSample*)This);
|
2001-11-21 19:12:39 +00:00
|
|
|
}
|
2001-03-20 00:05:27 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2001-08-16 00:50:02 +00:00
|
|
|
|
2007-01-28 16:53:33 +00:00
|
|
|
/**
|
|
|
|
* \brief IMediaSample::GetPointer (retrieves a read/write pointer to the media sample's buffer)
|
|
|
|
*
|
|
|
|
* \param[in] This pointer to CMediaSample object
|
|
|
|
* \param[out] address of variable that receives pointer to sample's buffer
|
|
|
|
*
|
|
|
|
* \return S_OK success
|
|
|
|
* \return apropriate error otherwise
|
|
|
|
*
|
|
|
|
* \note The calles should not free or reallocate buffer
|
|
|
|
*
|
|
|
|
*/
|
2001-12-11 23:29:24 +00:00
|
|
|
static HRESULT STDCALL CMediaSample_GetPointer(IMediaSample* This,
|
|
|
|
/* [out] */ BYTE** ppBuffer)
|
2001-03-20 00:05:27 +00:00
|
|
|
{
|
2001-12-11 23:29:24 +00:00
|
|
|
Debug printf("CMediaSample_GetPointer(%p) called -> %p, size: %d %d\n", This, ((CMediaSample*) This)->block, ((CMediaSample*)This)->actual_size, ((CMediaSample*)This)->size);
|
2001-08-16 00:50:02 +00:00
|
|
|
if (!ppBuffer)
|
|
|
|
return E_INVALIDARG;
|
2001-12-11 23:29:24 +00:00
|
|
|
*ppBuffer = (BYTE*) ((CMediaSample*) This)->block;
|
2001-03-20 00:05:27 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-01-28 16:53:33 +00:00
|
|
|
/**
|
|
|
|
* \brief IMediaSample::GetSize (retrieves a size of buffer in bytes)
|
|
|
|
*
|
|
|
|
* \param[in] This pointer to CMediaSample object
|
|
|
|
*
|
|
|
|
* \return size of buffer in bytes
|
|
|
|
*
|
|
|
|
*/
|
2001-08-16 00:50:02 +00:00
|
|
|
static long STDCALL CMediaSample_GetSize(IMediaSample * This)
|
2001-03-20 00:05:27 +00:00
|
|
|
{
|
2001-12-11 23:29:24 +00:00
|
|
|
Debug printf("CMediaSample_GetSize(%p) called -> %d\n", This, ((CMediaSample*) This)->size);
|
|
|
|
return ((CMediaSample*) This)->size;
|
2001-03-20 00:05:27 +00:00
|
|
|
}
|
|
|
|
|
2007-01-28 16:53:33 +00:00
|
|
|
/**
|
|
|
|
* \brief IMediaSample::GetTime (retrieves a stream time at wich sample sould start and finish)
|
|
|
|
*
|
|
|
|
* \param[in] This pointer to CMediaSample object
|
|
|
|
* \param[out] pTimeStart pointer to variable that receives start time
|
|
|
|
* \param[out] pTimeEnd pointer to variable that receives end time
|
|
|
|
*
|
|
|
|
* \return S_OK success
|
|
|
|
* \return VFW_E_NO_STOP_TIME The sample has valid start time, but no stop time
|
|
|
|
* \return VFW_E_SAMPLE_TIME_NOT_SET The sample is not time-stamped
|
|
|
|
*
|
|
|
|
* \remarks
|
|
|
|
* Both values are relative to stream time
|
|
|
|
*
|
|
|
|
*/
|
2001-08-16 00:50:02 +00:00
|
|
|
static HRESULT STDCALL CMediaSample_GetTime(IMediaSample * This,
|
|
|
|
/* [out] */ REFERENCE_TIME *pTimeStart,
|
|
|
|
/* [out] */ REFERENCE_TIME *pTimeEnd)
|
2001-03-20 00:05:27 +00:00
|
|
|
{
|
2002-11-26 21:00:20 +00:00
|
|
|
Debug printf("CMediaSample_GetTime(%p) called (UNIMPLEMENTED)\n", This);
|
2001-03-20 00:05:27 +00:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2007-01-28 16:53:33 +00:00
|
|
|
/**
|
|
|
|
* \brief IMediaSample::SetTime (sets a stream time at wich sample sould start and finish)
|
|
|
|
*
|
|
|
|
* \param[in] This pointer to CMediaSample object
|
|
|
|
* \param[out] pTimeStart pointer to variable that contains start time
|
|
|
|
* \param[out] pTimeEnd pointer to variable that contains end time
|
|
|
|
*
|
|
|
|
* \return S_OK success
|
|
|
|
* \return apropriate error otherwise
|
|
|
|
*
|
|
|
|
* \remarks
|
|
|
|
* Both values are relative to stream time
|
|
|
|
* To invalidate the stream times set pTimeStart and pTimeEnd to NULL. this will cause
|
|
|
|
* IMEdiaSample::GetTime to return VFW_E_SAMPLE_TIME_NOT_SET
|
|
|
|
*
|
|
|
|
*/
|
2001-08-16 00:50:02 +00:00
|
|
|
static HRESULT STDCALL CMediaSample_SetTime(IMediaSample * This,
|
|
|
|
/* [in] */ REFERENCE_TIME *pTimeStart,
|
|
|
|
/* [in] */ REFERENCE_TIME *pTimeEnd)
|
2001-03-20 00:05:27 +00:00
|
|
|
{
|
2002-11-26 21:00:20 +00:00
|
|
|
Debug printf("CMediaSample_SetTime(%p) called (UNIMPLEMENTED)\n", This);
|
2001-03-20 00:05:27 +00:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2007-01-28 16:53:33 +00:00
|
|
|
/**
|
|
|
|
* \brief IMediaSample::IsSyncPoint (determines if start of this sample is sync point)
|
|
|
|
*
|
|
|
|
* \param[in] This pointer to CMediaSample object
|
|
|
|
*
|
|
|
|
* \return S_OK start of this sample is sync point
|
|
|
|
* \return S_FALSE start of this sample is not sync point
|
|
|
|
*
|
|
|
|
* \remarks
|
|
|
|
* If bTemporalCompression of AM_MEDIA_TYPE is FALSE, all samples are sync points.
|
|
|
|
*
|
|
|
|
*/
|
2001-08-16 00:50:02 +00:00
|
|
|
static HRESULT STDCALL CMediaSample_IsSyncPoint(IMediaSample * This)
|
2001-03-20 00:05:27 +00:00
|
|
|
{
|
2001-11-21 19:12:39 +00:00
|
|
|
Debug printf("CMediaSample_IsSyncPoint(%p) called\n", This);
|
2001-08-16 00:50:02 +00:00
|
|
|
if (((CMediaSample*)This)->isSyncPoint)
|
|
|
|
return 0;
|
2001-03-20 00:05:27 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2007-01-28 16:53:33 +00:00
|
|
|
/**
|
|
|
|
* \brief IMediaSample::SetSyncPoint (specifies if start of this sample is sync point)
|
|
|
|
*
|
|
|
|
* \param[in] This pointer to CMediaSample object
|
|
|
|
* \param[in] bIsSyncPoint specifies whether this is sync point or not
|
|
|
|
*
|
|
|
|
* \return S_OK success
|
|
|
|
* \return apropriate error code otherwise
|
|
|
|
*
|
|
|
|
*/
|
2001-08-16 00:50:02 +00:00
|
|
|
static HRESULT STDCALL CMediaSample_SetSyncPoint(IMediaSample * This,
|
|
|
|
long bIsSyncPoint)
|
2001-03-20 00:05:27 +00:00
|
|
|
{
|
2001-11-21 19:12:39 +00:00
|
|
|
Debug printf("CMediaSample_SetSyncPoint(%p) called\n", This);
|
2001-12-11 23:29:24 +00:00
|
|
|
((CMediaSample*)This)->isSyncPoint = bIsSyncPoint;
|
2001-03-20 00:05:27 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-01-28 16:53:33 +00:00
|
|
|
/**
|
|
|
|
* \brief IMediaSample::IsPreroll (determines if this sample is preroll sample)
|
|
|
|
*
|
|
|
|
* \param[in] This pointer to CMediaSample object
|
|
|
|
*
|
|
|
|
* \return S_OK if this sample is preroll sample
|
|
|
|
* \return S_FALSE if this sample is not preroll sample
|
|
|
|
*
|
|
|
|
* \remarks
|
|
|
|
* Preroll samples are processed but not displayed. They are lokated in media stream
|
|
|
|
* before displayable samples.
|
|
|
|
*
|
|
|
|
*/
|
2001-08-16 00:50:02 +00:00
|
|
|
static HRESULT STDCALL CMediaSample_IsPreroll(IMediaSample * This)
|
2001-03-20 00:05:27 +00:00
|
|
|
{
|
2001-11-21 19:12:39 +00:00
|
|
|
Debug printf("CMediaSample_IsPreroll(%p) called\n", This);
|
2001-08-16 00:50:02 +00:00
|
|
|
|
|
|
|
if (((CMediaSample*)This)->isPreroll)
|
2001-03-20 00:05:27 +00:00
|
|
|
return 0;//S_OK
|
2001-08-16 00:50:02 +00:00
|
|
|
|
|
|
|
return 1;//S_FALSE
|
2001-03-20 00:05:27 +00:00
|
|
|
}
|
|
|
|
|
2007-01-28 16:53:33 +00:00
|
|
|
/**
|
|
|
|
* \brief IMediaSample::SetPreroll (specifies if this sample is preroll sample)
|
|
|
|
*
|
|
|
|
* \param[in] This pointer to CMediaSample object
|
|
|
|
* \param[in] bIsPreroll specifies whether this sample is preroll sample or not
|
|
|
|
*
|
|
|
|
* \return S_OK success
|
|
|
|
* \return apropriate error code otherwise
|
|
|
|
*
|
|
|
|
* \remarks
|
|
|
|
* Preroll samples are processed but not displayed. They are lokated in media stream
|
|
|
|
* before displayable samples.
|
|
|
|
*
|
|
|
|
*/
|
2001-08-16 00:50:02 +00:00
|
|
|
static HRESULT STDCALL CMediaSample_SetPreroll(IMediaSample * This,
|
|
|
|
long bIsPreroll)
|
2001-03-20 00:05:27 +00:00
|
|
|
{
|
2001-11-21 19:12:39 +00:00
|
|
|
Debug printf("CMediaSample_SetPreroll(%p) called\n", This);
|
2001-03-20 00:05:27 +00:00
|
|
|
((CMediaSample*)This)->isPreroll=bIsPreroll;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-01-28 16:53:33 +00:00
|
|
|
/**
|
|
|
|
* \brief IMediaSample::GetActualDataLength (retrieves the length of valid data in the buffer)
|
|
|
|
*
|
|
|
|
* \param[in] This pointer to CMediaSample object
|
|
|
|
*
|
|
|
|
* \return length of valid data in buffer in bytes
|
|
|
|
*
|
|
|
|
*/
|
2001-11-21 19:12:39 +00:00
|
|
|
static long STDCALL CMediaSample_GetActualDataLength(IMediaSample* This)
|
2001-03-20 00:05:27 +00:00
|
|
|
{
|
2001-11-21 19:12:39 +00:00
|
|
|
Debug printf("CMediaSample_GetActualDataLength(%p) called -> %d\n", This, ((CMediaSample*)This)->actual_size);
|
2001-03-20 00:05:27 +00:00
|
|
|
return ((CMediaSample*)This)->actual_size;
|
|
|
|
}
|
|
|
|
|
2007-01-28 16:53:33 +00:00
|
|
|
/**
|
|
|
|
* \brief IMediaSample::SetActualDataLength (specifies the length of valid data in the buffer)
|
|
|
|
*
|
|
|
|
* \param[in] This pointer to CMediaSample object
|
|
|
|
* \param[in] __MIDL_0010 length of data in sample in bytes
|
|
|
|
*
|
|
|
|
* \return S_OK success
|
|
|
|
* \return VFW_E_BUFFER_OVERFLOW length specified by parameter is larger than buffer size
|
|
|
|
*
|
|
|
|
*/
|
2001-11-21 19:12:39 +00:00
|
|
|
static HRESULT STDCALL CMediaSample_SetActualDataLength(IMediaSample* This,
|
2001-08-16 00:50:02 +00:00
|
|
|
long __MIDL_0010)
|
2001-03-20 00:05:27 +00:00
|
|
|
{
|
2001-12-11 23:29:24 +00:00
|
|
|
CMediaSample* cms = (CMediaSample*)This;
|
2001-11-21 19:12:39 +00:00
|
|
|
Debug printf("CMediaSample_SetActualDataLength(%p, %ld) called\n", This, __MIDL_0010);
|
2002-11-26 21:00:20 +00:00
|
|
|
|
2001-12-11 23:29:24 +00:00
|
|
|
if (__MIDL_0010 > cms->size)
|
2001-03-20 00:05:27 +00:00
|
|
|
{
|
2001-12-11 23:29:24 +00:00
|
|
|
char* c = cms->own_block;
|
2002-11-26 21:00:20 +00:00
|
|
|
Debug printf("CMediaSample - buffer overflow %ld %d %p %p\n",
|
2001-12-11 23:29:24 +00:00
|
|
|
__MIDL_0010, ((CMediaSample*)This)->size, cms->own_block, cms->block);
|
2002-11-26 21:00:20 +00:00
|
|
|
cms->own_block = (char*) realloc(cms->own_block, (size_t) __MIDL_0010 + SAFETY_ACEL);
|
2001-12-11 23:29:24 +00:00
|
|
|
if (c == cms->block)
|
|
|
|
cms->block = cms->own_block;
|
|
|
|
cms->size = __MIDL_0010;
|
2001-03-20 00:05:27 +00:00
|
|
|
}
|
2001-12-11 23:29:24 +00:00
|
|
|
cms->actual_size = __MIDL_0010;
|
2001-03-20 00:05:27 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-01-28 16:53:33 +00:00
|
|
|
/**
|
|
|
|
* \brief IMediaSample::GetMediaType (retrieves media type, if it changed from previous sample)
|
|
|
|
*
|
|
|
|
* \param[in] This pointer to CMediaSample object
|
|
|
|
* \param[out] ppMediaType address of variable that receives pointer to AM_MEDIA_TYPE.
|
|
|
|
*
|
|
|
|
* \return S_OK success
|
|
|
|
* \return S_FALSE Media type was not changed from previous sample
|
|
|
|
* \return E_OUTOFMEMORY Insufficient memory
|
|
|
|
*
|
|
|
|
* \remarks
|
|
|
|
* If media type is not changed from previous sample, ppMediaType is null
|
|
|
|
* If method returns S_OK caller should free memory allocated for structure
|
|
|
|
* including pbFormat block
|
|
|
|
*/
|
2001-11-21 19:12:39 +00:00
|
|
|
static HRESULT STDCALL CMediaSample_GetMediaType(IMediaSample* This,
|
|
|
|
AM_MEDIA_TYPE** ppMediaType)
|
2001-03-20 00:05:27 +00:00
|
|
|
{
|
2001-11-21 19:12:39 +00:00
|
|
|
AM_MEDIA_TYPE* t;
|
|
|
|
Debug printf("CMediaSample_GetMediaType(%p) called\n", This);
|
2001-03-20 00:05:27 +00:00
|
|
|
if(!ppMediaType)
|
2001-08-16 00:50:02 +00:00
|
|
|
return E_INVALIDARG;
|
2001-03-20 00:05:27 +00:00
|
|
|
if(!((CMediaSample*)This)->type_valid)
|
|
|
|
{
|
|
|
|
*ppMediaType=0;
|
|
|
|
return 1;
|
|
|
|
}
|
2001-11-21 19:12:39 +00:00
|
|
|
|
|
|
|
t = &((CMediaSample*)This)->media_type;
|
2003-04-21 20:12:43 +00:00
|
|
|
// if(t.pbFormat)free(t.pbFormat);
|
2007-02-23 09:58:01 +00:00
|
|
|
*ppMediaType=CreateMediaType(t);
|
2001-11-21 19:12:39 +00:00
|
|
|
// *ppMediaType=0; //media type was not changed
|
2001-08-16 00:50:02 +00:00
|
|
|
return 0;
|
2001-03-20 00:05:27 +00:00
|
|
|
}
|
|
|
|
|
2007-01-28 16:53:33 +00:00
|
|
|
/**
|
|
|
|
* \brief IMediaType::SetMediaType (specifies media type for sample)
|
|
|
|
*
|
|
|
|
* \param[in] This pointer to CMediaSample object
|
|
|
|
* \param[in] pMediaType pointer to AM_MEDIA_TYPE specifies new media type
|
|
|
|
*
|
|
|
|
* \return S_OK success
|
|
|
|
* \return E_OUTOFMEMORY insufficient memory
|
|
|
|
*
|
|
|
|
*/
|
2001-08-16 00:50:02 +00:00
|
|
|
static HRESULT STDCALL CMediaSample_SetMediaType(IMediaSample * This,
|
|
|
|
AM_MEDIA_TYPE *pMediaType)
|
2001-03-20 00:05:27 +00:00
|
|
|
{
|
2001-11-21 19:12:39 +00:00
|
|
|
AM_MEDIA_TYPE* t;
|
|
|
|
Debug printf("CMediaSample_SetMediaType(%p) called\n", This);
|
2001-08-16 00:50:02 +00:00
|
|
|
if (!pMediaType)
|
|
|
|
return E_INVALIDARG;
|
2001-11-21 19:12:39 +00:00
|
|
|
t = &((CMediaSample*)This)->media_type;
|
2007-09-08 12:15:15 +00:00
|
|
|
if(((CMediaSample*)This)->type_valid)
|
2007-09-10 23:14:17 +00:00
|
|
|
FreeMediaType(t);
|
2007-02-23 09:58:01 +00:00
|
|
|
CopyMediaType(t,pMediaType);
|
2001-12-11 23:29:24 +00:00
|
|
|
((CMediaSample*) This)->type_valid=1;
|
2001-08-16 00:50:02 +00:00
|
|
|
|
2001-03-20 00:05:27 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-01-28 16:53:33 +00:00
|
|
|
/**
|
|
|
|
* \brief IMediaSample::IsDiscontinuity (determines if this sample represents data break
|
|
|
|
* in stream)
|
|
|
|
*
|
|
|
|
* \param[in] This pointer to CMediaSample object
|
|
|
|
*
|
|
|
|
* \return S_OK if this sample is break in data stream
|
|
|
|
* \return S_FALSE otherwise
|
|
|
|
*
|
|
|
|
* \remarks
|
|
|
|
* Discontinuity occures when filter seeks to different place in the stream or when drops
|
|
|
|
* samples.
|
|
|
|
*
|
|
|
|
*/
|
2001-08-16 00:50:02 +00:00
|
|
|
static HRESULT STDCALL CMediaSample_IsDiscontinuity(IMediaSample * This)
|
2001-03-20 00:05:27 +00:00
|
|
|
{
|
2001-11-21 19:12:39 +00:00
|
|
|
Debug printf("CMediaSample_IsDiscontinuity(%p) called\n", This);
|
2001-12-11 23:29:24 +00:00
|
|
|
return ((CMediaSample*) This)->isDiscontinuity;
|
2001-03-20 00:05:27 +00:00
|
|
|
}
|
|
|
|
|
2007-01-28 16:53:33 +00:00
|
|
|
/**
|
|
|
|
* \brief IMediaSample::IsDiscontinuity (specifies whether this sample represents data break
|
|
|
|
* in stream)
|
|
|
|
*
|
|
|
|
* \param[in] This pointer to CMediaSample object
|
|
|
|
* \param[in] bDiscontinuity if TRUE this sample represents discontinuity with previous sample
|
|
|
|
*
|
|
|
|
* \return S_OK success
|
|
|
|
* \return apropriate error code otherwise
|
|
|
|
*
|
|
|
|
*/
|
2001-08-16 00:50:02 +00:00
|
|
|
static HRESULT STDCALL CMediaSample_SetDiscontinuity(IMediaSample * This,
|
|
|
|
long bDiscontinuity)
|
2001-03-20 00:05:27 +00:00
|
|
|
{
|
2001-12-11 23:29:24 +00:00
|
|
|
Debug printf("CMediaSample_SetDiscontinuity(%p) called (%ld)\n", This, bDiscontinuity);
|
|
|
|
((CMediaSample*) This)->isDiscontinuity = bDiscontinuity;
|
|
|
|
return 0;
|
2001-03-20 00:05:27 +00:00
|
|
|
}
|
|
|
|
|
2007-01-28 16:53:33 +00:00
|
|
|
/**
|
|
|
|
* \brief IMediaSample::GetMediaTime (retrieves the media times of this sample)
|
|
|
|
*
|
|
|
|
* \param[in] This pointer to CMediaSample object
|
|
|
|
* \param[out] pTimeStart pointer to variable that receives start time
|
|
|
|
* \param[out] pTimeEnd pointer to variable that receives end time
|
|
|
|
*
|
|
|
|
* \return S_OK success
|
|
|
|
* \return VFW_E_MEDIA_TIME_NOT_SET The sample is not time-stamped
|
|
|
|
*
|
|
|
|
*/
|
2001-08-16 00:50:02 +00:00
|
|
|
static HRESULT STDCALL CMediaSample_GetMediaTime(IMediaSample * This,
|
|
|
|
/* [out] */ LONGLONG *pTimeStart,
|
|
|
|
/* [out] */ LONGLONG *pTimeEnd)
|
2001-03-20 00:05:27 +00:00
|
|
|
{
|
2001-11-21 19:12:39 +00:00
|
|
|
Debug printf("CMediaSample_GetMediaTime(%p) called\n", This);
|
2001-12-11 23:29:24 +00:00
|
|
|
if (pTimeStart)
|
|
|
|
*pTimeStart = ((CMediaSample*) This)->time_start;
|
|
|
|
if (pTimeEnd)
|
|
|
|
*pTimeEnd = ((CMediaSample*) This)->time_end;
|
|
|
|
return 0;
|
2001-03-20 00:05:27 +00:00
|
|
|
}
|
|
|
|
|
2007-01-28 16:53:33 +00:00
|
|
|
/**
|
|
|
|
* \brief IMediaSample::GetMediaTime (retrieves the media times of this sample)
|
|
|
|
*
|
|
|
|
* \param[in] This pointer to CMediaSample object
|
|
|
|
* \param[out] pTimeStart pointer to variable that specifies start time
|
|
|
|
* \param[out] pTimeEnd pointer to variable that specifies end time
|
|
|
|
*
|
|
|
|
* \return S_OK success
|
|
|
|
* \return apropriate error code otherwise
|
|
|
|
*
|
|
|
|
* \remarks
|
|
|
|
* To invalidate the media times set pTimeStart and pTimeEnd to NULL. this will cause
|
|
|
|
* IMEdiaSample::GetTime to return VFW_E_MEDIA_TIME_NOT_SET
|
|
|
|
*/
|
2001-08-16 00:50:02 +00:00
|
|
|
static HRESULT STDCALL CMediaSample_SetMediaTime(IMediaSample * This,
|
|
|
|
/* [in] */ LONGLONG *pTimeStart,
|
|
|
|
/* [in] */ LONGLONG *pTimeEnd)
|
2001-03-20 00:05:27 +00:00
|
|
|
{
|
2001-11-21 19:12:39 +00:00
|
|
|
Debug printf("CMediaSample_SetMediaTime(%p) called\n", This);
|
2001-12-11 23:29:24 +00:00
|
|
|
if (pTimeStart)
|
|
|
|
((CMediaSample*) This)->time_start = *pTimeStart;
|
|
|
|
if (pTimeEnd)
|
|
|
|
((CMediaSample*) This)->time_end = *pTimeEnd;
|
|
|
|
return 0;
|
2001-03-20 00:05:27 +00:00
|
|
|
}
|
2001-08-16 00:50:02 +00:00
|
|
|
|
2007-01-28 16:53:33 +00:00
|
|
|
/**
|
|
|
|
* \brief CMediaSample::SetPointer (extension for direct memory write of decompressed data)
|
|
|
|
*
|
|
|
|
* \param[in] This pointer to CMediaSample object
|
|
|
|
* \param[in] pointer pointer to an external buffer to store data to
|
|
|
|
*
|
|
|
|
*/
|
2001-11-21 19:12:39 +00:00
|
|
|
static void CMediaSample_SetPointer(CMediaSample* This, char* pointer)
|
|
|
|
{
|
|
|
|
Debug printf("CMediaSample_SetPointer(%p) called -> %p\n", This, pointer);
|
|
|
|
if (pointer)
|
|
|
|
This->block = pointer;
|
|
|
|
else
|
|
|
|
This->block = This->own_block;
|
|
|
|
}
|
|
|
|
|
2007-01-28 16:53:33 +00:00
|
|
|
/**
|
|
|
|
* \brief CMediaSample::SetPointer (resets pointer to external buffer with internal one)
|
|
|
|
*
|
|
|
|
* \param[in] This pointer to CMediaSample object
|
|
|
|
*
|
|
|
|
*/
|
2001-11-21 19:12:39 +00:00
|
|
|
static void CMediaSample_ResetPointer(CMediaSample* This)
|
|
|
|
{
|
|
|
|
Debug printf("CMediaSample_ResetPointer(%p) called\n", This);
|
|
|
|
This->block = This->own_block;
|
|
|
|
}
|
|
|
|
|
2007-01-28 16:53:33 +00:00
|
|
|
/**
|
|
|
|
* \brief CMediaSample constructor
|
|
|
|
*
|
|
|
|
* \param[in] allocator IMemallocator interface of allocator to use
|
2008-01-20 17:16:39 +00:00
|
|
|
* \param[in] size size of internal buffer
|
2007-01-28 16:53:33 +00:00
|
|
|
*
|
|
|
|
* \return pointer to CMediaSample object of NULL if error occured
|
|
|
|
*
|
|
|
|
*/
|
2008-01-20 17:16:39 +00:00
|
|
|
CMediaSample* CMediaSampleCreate(IMemAllocator* allocator, int size)
|
2001-11-21 19:12:39 +00:00
|
|
|
{
|
2001-12-11 23:29:24 +00:00
|
|
|
CMediaSample* This = (CMediaSample*) malloc(sizeof(CMediaSample));
|
|
|
|
if (!This)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
// some hack here!
|
|
|
|
// it looks like Acelp decoder is actually accessing
|
|
|
|
// the allocated memory before it sets the new size for it ???
|
|
|
|
// -- maybe it's being initialized with wrong parameters
|
|
|
|
// anyway this is fixes the problem somehow with some reserves
|
|
|
|
//
|
|
|
|
// using different trick for now - in DS_Audio modify sample size
|
2008-01-20 17:16:39 +00:00
|
|
|
//if (size < 0x1000)
|
|
|
|
// size = (size + 0xfff) & ~0xfff;
|
2001-12-11 23:29:24 +00:00
|
|
|
|
2001-11-21 19:12:39 +00:00
|
|
|
This->vt = (IMediaSample_vt*) malloc(sizeof(IMediaSample_vt));
|
2008-01-20 17:16:39 +00:00
|
|
|
This->own_block = (char*) malloc((size_t)size + SAFETY_ACEL);
|
2001-12-11 23:29:24 +00:00
|
|
|
This->media_type.pbFormat = 0;
|
2007-09-08 06:01:43 +00:00
|
|
|
This->media_type.pUnk = 0;
|
2001-12-11 23:29:24 +00:00
|
|
|
|
|
|
|
if (!This->vt || !This->own_block)
|
|
|
|
{
|
|
|
|
CMediaSample_Destroy(This);
|
|
|
|
return NULL;
|
|
|
|
}
|
2001-11-21 19:12:39 +00:00
|
|
|
|
|
|
|
This->vt->QueryInterface = CMediaSample_QueryInterface;
|
|
|
|
This->vt->AddRef = CMediaSample_AddRef;
|
|
|
|
This->vt->Release = CMediaSample_Release;
|
|
|
|
This->vt->GetPointer = CMediaSample_GetPointer;
|
|
|
|
This->vt->GetSize = CMediaSample_GetSize;
|
|
|
|
This->vt->GetTime = CMediaSample_GetTime;
|
|
|
|
This->vt->SetTime = CMediaSample_SetTime;
|
|
|
|
This->vt->IsSyncPoint = CMediaSample_IsSyncPoint;
|
|
|
|
This->vt->SetSyncPoint = CMediaSample_SetSyncPoint;
|
|
|
|
This->vt->IsPreroll = CMediaSample_IsPreroll;
|
|
|
|
This->vt->SetPreroll = CMediaSample_SetPreroll;
|
|
|
|
This->vt->GetActualDataLength = CMediaSample_GetActualDataLength;
|
|
|
|
This->vt->SetActualDataLength = CMediaSample_SetActualDataLength;
|
|
|
|
This->vt->GetMediaType = CMediaSample_GetMediaType;
|
|
|
|
This->vt->SetMediaType = CMediaSample_SetMediaType;
|
|
|
|
This->vt->IsDiscontinuity = CMediaSample_IsDiscontinuity;
|
|
|
|
This->vt->SetDiscontinuity = CMediaSample_SetDiscontinuity;
|
|
|
|
This->vt->GetMediaTime = CMediaSample_GetMediaTime;
|
|
|
|
This->vt->SetMediaTime = CMediaSample_SetMediaTime;
|
|
|
|
|
|
|
|
This->all = allocator;
|
2008-01-20 17:16:39 +00:00
|
|
|
This->size = size;
|
2001-11-21 19:12:39 +00:00
|
|
|
This->refcount = 0; // increased by MemAllocator
|
|
|
|
This->actual_size = 0;
|
|
|
|
This->isPreroll = 0;
|
2001-12-11 23:29:24 +00:00
|
|
|
This->isDiscontinuity = 1;
|
|
|
|
This->time_start = 0;
|
|
|
|
This->time_end = 0;
|
2001-11-21 19:12:39 +00:00
|
|
|
This->type_valid = 0;
|
|
|
|
This->block = This->own_block;
|
|
|
|
|
|
|
|
This->SetPointer = CMediaSample_SetPointer;
|
|
|
|
This->ResetPointer = CMediaSample_ResetPointer;
|
|
|
|
|
|
|
|
Debug printf("CMediaSample_Create(%p) called - sample size %d, buffer %p\n",
|
|
|
|
This, This->size, This->block);
|
|
|
|
|
|
|
|
return This;
|
2001-08-16 00:50:02 +00:00
|
|
|
}
|