📄 lists.cpp
字号:
/***********************************************************************/
/* lists.cpp : Implementation of Memory Manager lists
* REALmagic Quasar Hardware Library
* Created by Kevin Vo
* Copyright 2000 Sigma Designs Inc.
* 355 Fairview Way, Milpitas, CA 95035-3024 USA. All Rights Reserved.
* Sigma Designs Proprietary and Confidential
* Created on 3/20/01
* Description:
/************************************************************************/
/****h* MMDemux/Lists
* NAME
* Lists
* DESCRIPTION
* Memory Manager implementation of buffer lists
* COPYRIGHT
* Copyright 2000 Sigma Designs Inc.
* 355 Fairview Way, Milpitas, CA 95035-3024 USA. All Rights Reserved.
* Sigma Designs Proprietary and Confidential
/*************************************************************************/
#include "pch.h"
#include "manager.h"
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
/****f* MMDemux/CBuffer::CBuffer
* USAGE
* CBuffer(PVOID pMem, DWORD dwBufferSize, unsigned char* buffer)
* DESCRIPTION
* Constructor of CBuffer.
* PARAMETERS
* PVOID pMemManager - A void pointer to Memory Manager that will be casted later.
* DWORD dwBufferSize - Size of the buffer.
* unsigned char* buffer - A pointer to the allocated buffer.
* RETURN VALUE
* None
/**********************************************************************/
CBuffer::CBuffer(void* pMemManager, unsigned long dwBufferSize, unsigned char* buffer)
{
m_ulSize = dwBufferSize;
m_ulActualSize = dwBufferSize;
m_pBuffer = buffer;
m_iRefCount = 0;
next = prior = 0;
m_pMemManager = pMemManager;
}
////////////////////////////////////////////////////////////////////
CBuffer::~CBuffer()
{
}
////////////////////////////////////////////////////////////////////
/****f* MMDemux/CBuffer::AddRef
* USAGE
* void AddRef()
* DESCRIPTION
* Increments the reference count for each MediaSample pointing to this buffer.
* Note that this function is called within the Memory Manager only.
* PARAMETERS
* None
* RETURN VALUE
* None
/**********************************************************************/
void CBuffer::AddRef(void)
{
++m_iRefCount;
}
////////////////////////////////////////////////////////////////////
/****f* MMDemux/CBuffer::Release
* USAGE
* void Release()
* DESCRIPTION
* Decrements the reference count for each MediaSample not pointing to this
* buffer anymore.
* Note that this function is called within the Memory Manager only.
* PARAMETERS
* None
* RETURN VALUE
* None
/**********************************************************************/
void CBuffer::Release(void)
{
--m_iRefCount;
if (m_iRefCount == 0)
{
MemManager *pMem = (MemManager*)m_pMemManager;
pMem->ReleaseBuffer(this);
}
else if (m_iRefCount < 0)
m_iRefCount = 0;
}
////////////////////////////////////////////////////////////////////
/****f* MMDemux/CBuffer::GetSize
* USAGE
* ULONG GetSize()
* DESCRIPTION
* Returns the size of this buffer.
* PARAMETERS
* None
* RETURN VALUE
* Size of buffer in bytes
/**********************************************************************/
unsigned long CBuffer::GetSize()
{
return m_ulSize;
}
////////////////////////////////////////////////////////////////////
/****f* MMDemux/CBuffer::GetActualSize
* USAGE
* ULONG GetActualSize()
* DESCRIPTION
* Returns the size of this buffer. The size can be smaller than the predefined buffer size.
* PARAMETERS
* None
* RETURN VALUE
* Size of buffer in bytes
/**********************************************************************/
unsigned long CBuffer::GetActualSize()
{
return m_ulActualSize;
}
////////////////////////////////////////////////////////////////////
/****f* MMDemux/CBuffer::SetActualSize
* USAGE
* ULONG SetActualSize(unsigned long ulSize)
* DESCRIPTION
* Sets the actual size of this buffer. The size can be smaller than the predefine buffer size.
* PARAMETERS
* unsigned long ulSize - The actual size of this buffer.
* RETURN VALUE
* None
/**********************************************************************/
void CBuffer::SetActualSize(unsigned long ulSize)
{
m_ulActualSize = ulSize;
}
////////////////////////////////////////////////////////////////////
/****f* MMDemux/CBuffer::GetBuffer
* USAGE
* PVOID GetBuffer()
* DESCRIPTION
* Returns a pointer to the buffer. The users need to cast the pointer to
* (BYTE*) since this function returns PVOID.
* PARAMETERS
* None
* RETURN VALUE
* A pointer to the buffer.
/**********************************************************************/
void* CBuffer::GetBuffer()
{
return m_pBuffer;
}
////////////////////////////////////////////////////////////////////
/****f* MMDemux/CBuffer::GetRefCount
* USAGE
* UINT GetRefCount()
* DESCRIPTION
* Returns the reference count of this buffer.
* Note that this function is called within the Memory Manager only.
* PARAMETERS
* None
* RETURN VALUE
* Reference count value.
/**********************************************************************/
int CBuffer::GetRefCount()
{
return m_iRefCount;
}
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// Implementation of CBufferList
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
/****f* MMDemux/CBufferList::CBufferList
* USAGE
* CBufferList()
* DESCRIPTION
* Default constructor.
* PARAMETERS
* None
* RETURN VALUE
* None
/**********************************************************************/
CBufferList::CBufferList()
{
start = last = current = NULL;
}
////////////////////////////////////////////////////////////////////
CBufferList::~CBufferList()
{
CBuffer *temp = NULL;
while (start != NULL)
{
temp = start;
start = start->next;
delete temp;
}
start = last = current = NULL;
}
////////////////////////////////////////////////////////////////////
void CBufferList::SetCBuffer(CBuffer *pBuff)
{
if (pBuff != NULL)
{
if (last == NULL) // first item in list
start = last = pBuff;
else // insert at the end
last->next = pBuff;
pBuff->next = NULL;
last = pBuff;
}
}
////////////////////////////////////////////////////////////////////
CBuffer *CBufferList::GetCBuffer()
{
CBuffer *temp = 0;
if (start) // delete the first entry
{
temp = start;
start = start->next;
if (start == NULL)
start = last = NULL;
}
return temp;
}
////////////////////////////////////////////////////////////////////
/****f* MMDemux/CBufferList::GetBuffer
* USAGE
* CBuffer *GetBuffer()
* DESCRIPTION
* Gets a CBuffer from the list.
* PARAMETERS
* None
* RETURN VALUE
* A pointer to the CBuffer.
* NULL if list is empty.
/**********************************************************************/
CBuffer *CBufferList::GetBuffer(void)
{
CBuffer *pBuffer = GetCBuffer();
return pBuffer;
}
////////////////////////////////////////////////////////////////////
/****f* MMDemux/CBufferList::SetBuffer
* USAGE
* void SetBuffer(CBuffer *pBuffer)
* DESCRIPTION
* Inserts a CBuffer into the list.
* PARAMETERS
* CBuffer *pBuffer - A pointer to the CBuffer.
* RETURN VALUE
* None
/**********************************************************************/
void CBufferList::SetBuffer(CBuffer *pBuffer)
{
SetCBuffer(pBuffer);
}
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// Implementation of IMediaSample interface
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
/****f* MMDemux/CIMediaSample::CIMediaSample
* USAGE
* CIMediaSample(PVOID pMemManager)
* DESCRIPTION
* Constructor of CIMediaSample.
* PARAMETERS
* PVOID pMemManager - A void pointer to the Memory Manager that will be
* casted later.
* RETURN VALUE
* None
/**********************************************************************/
CIMediaSample::CIMediaSample(void* pMemManager)
{
m_lSampleRate = 0;
m_iCount = 0;
m_pPayload = 0;
m_lPayloadLength = 0;
m_ullPts = 0;
m_ullCts = 0;
m_bPtsDtsFlag = FALSE;
m_dwFlags = 0;
m_pCBuffer = 0;
m_ullScr = 0;
m_bMediaType = MM_VIDEO;
m_bNFrameHeaders = 0;
m_iFirstAccessUnit = 0;
m_pMemManager = pMemManager;
}
////////////////////////////////////////////////////////////////////
CIMediaSample::~CIMediaSample()
{
}
////////////////////////////////////////////////////////////////////
/****f* MMDemux/CIMediaSample::GetCBuffer
* USAGE
* CBuffer* GetBuffer()
* DESCRIPTION
* Gets the buffer that this MediaSample is pointing to.
* PARAMETERS
* None
* RETURN VALUE
* A pointer to the CBuffer.
/**********************************************************************/
CBuffer *CIMediaSample::GetCBuffer(void)
{
return m_pCBuffer;
}
////////////////////////////////////////////////////////////////////
/****f* MMDemux/CIMediaSample::SetCBuffer
* USAGE
* void SetCBuffer(CBuffer *pBuffer)
* DESCRIPTION
* Sets the buffer that this MediaSample is pointing to.
* PARAMETERS
* CBuffer *pBuffer - A pointer to the CBuffer that this MediaSample is pointing to.
* RETURN VALUE
* None.
/**********************************************************************/
void CIMediaSample::SetCBuffer(CBuffer* pBuffer)
{
m_pCBuffer = pBuffer;
}
////////////////////////////////////////////////////////////////////
/****f* MMDemux/CIMediaSample::SetPayload
* USAGE
* void SetPayload(BYTE *pPayload)
* DESCRIPTION
* Sets the pointer to the payload of this packet.
* PARAMETERS
* BYTE *pPayload - A pointer to the payload of type BYTE. The payload is
* an array of bytes.
* RETURN VALUE
* None.
/**********************************************************************/
void CIMediaSample::SetPayload(UCHAR* pPayload)
{
m_pPayload = pPayload;
}
////////////////////////////////////////////////////////////////////
// Same as GetPointer
UCHAR* CIMediaSample::GetPayload()
{
return m_pPayload;
}
////////////////////////////////////////////////////////////////////
/****f* MMDemux/CIMediaSample::SetScr
* USAGE
* void SetScr(ULONGLONG scr)
* DESCRIPTION
* Sets the Scr value.
* PARAMETERS
* ULONGLONG scr - SCR value for this media sample
* RETURN VALUE
* None.
/**********************************************************************/
void CIMediaSample::SetScr(ULONGLONG scr)
{
m_ullScr = scr;
}
////////////////////////////////////////////////////////////////////
/****f* MMDemux/CIMediaSample::GetScr
* USAGE
* ULONGLONG GetScr()
* DESCRIPTION
* Gets the Scr value.
* PARAMETERS
* None
* RETURN VALUE
* The SCR value of this media sample.
**********************************************************************/
ULONGLONG CIMediaSample::GetScr(void)
{
return m_ullScr;
}
////////////////////////////////////////////////////////////////////
/****f* MMDemux/CIMediaSample::GetPtsFlag
* USAGE
* INT GetPtsFlag()
* DESCRIPTION
* Gets the PTS flag.
* PARAMETERS
* None
* RETURN VALUE
* 0 if no PTS.
* 2 if there's PTS.
**********************************************************************/
INT CIMediaSample::GetPtsFlag(void)
{
if (m_bPtsDtsFlag)
return 2;
else
return 0;
}
////////////////////////////////////////////////////////////////////
/****f* MMDemux/CIMediaSample::SetPtsDtsFlag
* USAGE
* void SetPtsDtsFlag(INT flag)
* DESCRIPTION
* Sets the Pts flag. If this packet has a PTS then the flag will be set
* to TRUE; otherwise, it is FALSE.
* PARAMETERS
* INT flag - Pts flag (TRUE/FALSE).
* RETURN VALUE
* None.
/**********************************************************************/
void CIMediaSample::SetPtsDtsFlag(INT flag)
{
m_bPtsDtsFlag = flag;
}
////////////////////////////////////////////////////////////////////
/****f* MMDemux/CIMediaSample::GetFlags
* USAGE
* DWORD SetFlags(void)
* DESCRIPTION
* get pts, pts discontinuity, dts, cts AND/OR dsi info flags
* PARAMETERS
* None.
* RETURN VALUE
* Any combinations of the followings:
* MM_DTS_AVAILABLE_FLAG
* MM_PTS_AVAILABLE_FLAG
* MM_PTS_DISCONTINUITY_FLAG
* MM_CTS_AVAILABLE_FLAG
* MM_DSI_INFO
/**********************************************************************/
DWORD CIMediaSample::GetFlags(void)
{
return m_dwFlags;
}
////////////////////////////////////////////////////////////////////
/****f* MMDemux/CIMediaSample::SetFlags
* USAGE
* void SetFlags(DWORD dwFlags)
* DESCRIPTION
* Set pts, pts discontinuity, dts, cts and dsi info flags
* PARAMETERS
* DWORD dwFlags - Can contain one more of the followings:
* MM_DTS_AVAILABLE_FLAG
* MM_PTS_AVAILABLE_FLAG
* MM_PTS_DISCONTINUITY_FLAG
* MM_CTS_AVAILABLE_FLAG
* MM_DSI_INFO
* RETURN VALUE
* None.
/**********************************************************************/
void CIMediaSample::SetFlags(DWORD dwFlags)
{
m_dwFlags = dwFlags;
}
////////////////////////////////////////////////////////////////////
ULONGLONG CIMediaSample::GetCts(void)
{
return m_ullCts;
}
////////////////////////////////////////////////////////////////////
void CIMediaSample::SetCts(ULONGLONG ullCts)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -