rvxvdfmt.cpp
上传用户:dangjiwu
上传日期:2013-07-19
资源大小:42019k
文件大小:26k
- /* ***** BEGIN LICENSE BLOCK *****
- * Version: RCSL 1.0/RPSL 1.0
- *
- * Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved.
- *
- * The contents of this file, and the files included with this file, are
- * subject to the current version of the RealNetworks Public Source License
- * Version 1.0 (the "RPSL") available at
- * http://www.helixcommunity.org/content/rpsl unless you have licensed
- * the file under the RealNetworks Community Source License Version 1.0
- * (the "RCSL") available at http://www.helixcommunity.org/content/rcsl,
- * in which case the RCSL will apply. You may also obtain the license terms
- * directly from RealNetworks. You may not use this file except in
- * compliance with the RPSL or, if you have a valid RCSL with RealNetworks
- * applicable to this file, the RCSL. Please see the applicable RPSL or
- * RCSL for the rights, obligations and limitations governing use of the
- * contents of the file.
- *
- * This file is part of the Helix DNA Technology. RealNetworks is the
- * developer of the Original Code and owns the copyrights in the portions
- * it created.
- *
- * This file, and the files included with this file, is distributed and made
- * available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS
- * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- *
- * Technology Compatibility Kit Test Suite(s) Location:
- * http://www.helixcommunity.org/content/tck
- *
- * Contributor(s):
- *
- * ***** END LICENSE BLOCK ***** */
- /****************************************************************************
- * Defines
- */
- #define _IGNORE_UNSUPPORTED
- #if !defined(HELIX_FEATURE_MIN_HEAP)
- #define MAX_BUFFERED_DECODED_RV_FRAMES 15
- #else // HELIX_FEATURE_MIN_HEAP
- #define MAX_BUFFERED_DECODED_RV_FRAMES 2
- #endif // HELIX_FEATURE_MIN_HEAP
- #define NON_KEYFRM_DCDE_FALLBEHIND_THRSHLD 66 // in milliseconds
- #if defined(HELIX_FEATURE_MIN_HEAP)
- #define RVXV_DEFAULT_PREROLL 2000 // in milliseconds
- #else
- #define RVXV_DEFAULT_PREROLL 3500 // in milliseconds
- #endif
- #define IMG_FORMAT_POSSIBLE_CHANGE 1
- #define IMG_FORMAT_FORCED_CHANGE 2
- #define DECODE_CALLBACK_RNGBUF_SIZE 10
- #define UNINITIALIZED_SEQ_NUMBER 0xFFFFFFFF
- #define MAX_KEY_CODED_FRAME_FALLBEHIND -1200
- #define MAX_NONKEY_CODED_FRAME_FALLBEHIND -800
- /****************************************************************************
- * Includes
- */
- #include "rvxvdfmt.h"
- #include "hxasm.h"
- #include "hxwin.h"
- #include "hxvsurf.h"
- #include "hxvctrl.h"
- #include "hxsite2.h"
- #include "hxthread.h"
- #include "hxtick.h"
- #include "hxassert.h"
- #include "hxstrutl.h"
- #include "unkimp.h"
- #include "timeval.h"
- #include "cttime.h"
- #include "hxcodec.h"
- #include "hxmtypes.h"
- #include "rvxvideo.h"
- /****************************************************************************
- * Locals
- */
- /****************************************************************************
- * Method:
- * CRVXVideoFormat::CQTVideoFormat
- *
- */
- CRVXVideoFormat::CRVXVideoFormat(IHXCommonClassFactory* pCommonClassFactory,
- CRVXVideoRenderer* pRVXVideoRenderer)
- : CVideoFormat(pCommonClassFactory, pRVXVideoRenderer)
- , m_pRVXVideoRenderer(pRVXVideoRenderer)
- , m_pRssm(NULL)
- , m_pDecoder(NULL)
- , m_pInputAllocator(NULL)
- , m_ulMaxDecodedFrames(0)
- , m_ulWidthContainedInSegment(0)
- , m_ulHeightContainedInSegment(0)
- , m_pCodecOutputBIH(NULL)
- , m_pDecodedRngBuf(NULL)
- , m_bFirstDecode(TRUE)
- , m_ulLastSequenceNumber(UNINITIALIZED_SEQ_NUMBER)
- , m_bFlushingToKeyFrame(FALSE)
- {
- HX_ASSERT(m_pCommonClassFactory);
- HX_ASSERT(pRVXVideoRenderer);
- m_sMediaSize.cx = 0;
- m_sMediaSize.cy = 0;
- m_pRVXVideoRenderer->AddRef();
- }
- /****************************************************************************
- * Method:
- * CRVXVideoFormat::~CQTVideoFormat
- *
- */
- CRVXVideoFormat::~CRVXVideoFormat()
- {
- CVideoFormat::Reset();
- HX_RELEASE(m_pRVXVideoRenderer);
- if (m_pRssm)
- {
- m_pRssm->Close();
- m_pRssm->Release();
- m_pRssm = NULL;
- }
- FlushDecodedRngBuf();
- HX_DELETE(m_pDecodedRngBuf);
- HX_DELETE(m_pDecoder);
- _Reset();
- if (m_pInputAllocator)
- {
- m_pInputAllocator->Release();
- m_pInputAllocator = NULL;
- }
- HX_DELETE(m_pCodecOutputBIH);
- }
- /****************************************************************************
- * Method:
- * CRVXVideoFormat::Init
- */
- HX_RESULT CRVXVideoFormat::Init(IHXValues* pHeader)
- {
- HX_RESULT retVal = CVideoFormat::Init(pHeader);
- m_bFlushingToKeyFrame = FALSE;
- // Create Decode callback to caller ring buffer
- if (SUCCEEDED(retVal))
- {
- m_pDecodedRngBuf = new CRingBuffer(DECODE_CALLBACK_RNGBUF_SIZE);
- retVal = HXR_OUTOFMEMORY;
- if (m_pDecodedRngBuf)
- {
- retVal = HXR_OK;
- }
- }
- // Create memory allocators
- if (SUCCEEDED(retVal))
- {
- retVal = CreateAllocators();
- }
- // Create Packet Assembler
- if (SUCCEEDED(retVal))
- {
- retVal = HXR_OUTOFMEMORY;
- m_pRssm = new RVXPayloadFormat(m_pInputAllocator);
- if (m_pRssm)
- {
- m_pRssm->AddRef();
- retVal = HXR_OK;
- }
- }
-
- // Create Decoder
- if (SUCCEEDED(retVal))
- {
- retVal = HXR_OUTOFMEMORY;
- m_pDecoder = CreateDecoder();
- if (m_pDecoder)
- {
- retVal = HXR_OK;
- }
- }
- // Initialize Assembler
- if (SUCCEEDED(retVal) && m_pRssm)
- {
- retVal = m_pRssm->Init(m_pRVXVideoRenderer->GetContext(),
- FALSE);
- }
-
- if (SUCCEEDED(retVal) && m_pRssm)
- {
- retVal = m_pRssm->SetStreamHeader(pHeader);
- if (retVal == HXR_NO_DATA)
- {
- retVal = HXR_OK;
- }
- #ifdef _IGNORE_UNSUPPORTED
- if (FAILED(retVal))
- {
- HXxSize nullViewFrame = {1, 1};
- m_pRVXVideoRenderer->ResizeViewFrame(nullViewFrame);
- HX_RELEASE(m_pRssm);
- retVal = HXR_OK;
- }
- #endif // _IGNORE_UNSUPPORTED
- }
- // Initialize Decoder
- if (SUCCEEDED(retVal) && m_pRssm)
- {
- retVal = m_pDecoder->Init(m_pRVXVideoRenderer->GetContext(),
- this,
- NULL,
- m_pInputAllocator,
- m_pRVXVideoRenderer->m_pOutputAllocator);
- if (SUCCEEDED(retVal))
- {
- HX_MOF* pImageInfo;
-
- if (m_pDecoder->GetImageInfo(pImageInfo) == HXR_OK)
- {
- retVal = SetupOutputFormat(pImageInfo, m_pDecoder->GetMofTagIn());
- if (SUCCEEDED(retVal))
- {
- if ((m_sMediaSize.cx != 0) && (m_sMediaSize.cy != 0))
- {
- m_pRVXVideoRenderer->ResizeViewFrame(m_sMediaSize);
- }
- }
- }
- }
-
- #ifdef _IGNORE_UNSUPPORTED
- if (FAILED(retVal))
- {
- HXxSize nullViewFrame = {1, 1};
- m_pRVXVideoRenderer->ResizeViewFrame(nullViewFrame);
- HX_RELEASE(m_pRssm);
- retVal = HXR_OK;
- }
- #endif // _IGNORE_UNSUPPORTED
- }
- m_bFirstDecode = TRUE;
- m_ulMaxDecodedFrames = GetMaxDecodedFrames();
- return retVal;
- }
- /****************************************************************************
- * Method:
- * CRVXVideoFormat::SetupOutputFormat
- *
- */
- HX_RESULT
- CRVXVideoFormat::SetupOutputFormat(HX_MOF* pMof, HX_MOFTAG moftagIn)
- {
- HX_RESULT pnr = HXR_OK;
- HX_FORMAT_IMAGE* pMofOutI = (HX_FORMAT_IMAGE*) pMof;
- if (!m_pCodecOutputBIH)
- {
- m_pCodecOutputBIH = new HXBitmapInfoHeader;
- if (!m_pCodecOutputBIH)
- {
- return HXR_OUTOFMEMORY;
- }
- }
- m_pRVXVideoRenderer->m_ulPadWidthLeft = 0;
- m_pRVXVideoRenderer->m_ulPadWidthRight = 0;
- m_pRVXVideoRenderer->m_ulPadHeightTop = 0;
- m_pRVXVideoRenderer->m_ulPadHeightBottom = 0;
- m_sMediaSize.cy = pMofOutI->uiHeight;
- m_sMediaSize.cx = pMofOutI->uiWidth;
- m_pCodecOutputBIH->biWidth = pMofOutI->uiWidth;
- m_pCodecOutputBIH->biHeight = pMofOutI->uiHeight;
- m_pCodecOutputBIH->biPlanes = 1;
-
- switch(pMofOutI->submoftag)
- {
- case HX_RGB3_ID:
- {
- m_pCodecOutputBIH->biBitCount = pMofOutI->uiBitCount;
- m_pCodecOutputBIH->biCompression = BI_RGB;
- }
- break;
- case HX_YUV420_ID:
- {
- // fix up CLV1 screwed up bitcount
- if (moftagIn == HX_CLEARVIDEO_ID)
- {
- pMofOutI->uiBitCount = 12;
- }
- HX_ASSERT(pMofOutI->uiBitCount == 12);
- m_pCodecOutputBIH->biBitCount = pMofOutI->uiBitCount;
- m_pCodecOutputBIH->biCompression = HX_I420;
-
- if (pMofOutI->moftag == HX_MEDIA_IMAGE2)
- {
- HX_FORMAT_IMAGE2* pMofOutI2 = (HX_FORMAT_IMAGE2*)pMof;
- // if we are getting YUV out, it is a format image 2 struct
- // and we need to include padding in this width and height
- m_pRVXVideoRenderer->m_ulPadWidthLeft = pMofOutI2->uiPadWidthLeft;
- m_pRVXVideoRenderer->m_ulPadWidthRight = pMofOutI2->uiPadWidthRight;
- m_pRVXVideoRenderer->m_ulPadHeightTop = pMofOutI2->uiPadHeightTop;
- m_pRVXVideoRenderer->m_ulPadHeightBottom = pMofOutI2->uiPadHeightBottom;
- }
- }
- break;
- #ifdef _WINDOWS
- case HX_RGB555_ID:
- {
- HX_ASSERT(pMofOutI->uiBitCount == 16);
- m_pCodecOutputBIH->biBitCount = pMofOutI->uiBitCount;
- m_pCodecOutputBIH->biCompression = BI_BITFIELDS;
- m_pCodecOutputBIH->rcolor = 0x00007C00; // red
- m_pCodecOutputBIH->gcolor = 0x000003E0; // green
- m_pCodecOutputBIH->bcolor = 0x0000001F; // blue
- }
- break;
- case HX_RGB565_ID:
- {
- HX_ASSERT(pMofOutI->uiBitCount == 16);
- m_pCodecOutputBIH->biBitCount = pMofOutI->uiBitCount;
- m_pCodecOutputBIH->biCompression = BI_BITFIELDS;
- m_pCodecOutputBIH->rcolor = 0x0000F800; // red
- m_pCodecOutputBIH->gcolor = 0x000007E0; // green
- m_pCodecOutputBIH->bcolor = 0x0000001F; // blue
- }
- break;
- #endif
- default:
- pnr = HXR_DEC_TYPE_MISMATCH;
- }
- m_pCodecOutputBIH->biWidth += (m_pRVXVideoRenderer->m_ulPadWidthLeft +
- m_pRVXVideoRenderer->m_ulPadWidthRight);
- m_pCodecOutputBIH->biHeight += (m_pRVXVideoRenderer->m_ulPadHeightTop +
- m_pRVXVideoRenderer->m_ulPadHeightBottom);
- m_pCodecOutputBIH->biSizeImage =
- m_pCodecOutputBIH->biWidth * m_pCodecOutputBIH->biBitCount *
- m_pCodecOutputBIH->biHeight / 8;
- return pnr;
- }
- /****************************************************************************
- * Method:
- * CRVXVideoFormat::GetDefaultPreroll
- *
- */
- ULONG32 CRVXVideoFormat::GetDefaultPreroll(IHXValues* pValues)
- {
- return RVXV_DEFAULT_PREROLL;
- }
- /****************************************************************************
- * Method:
- * CRVXVideoFormat::GetBitstreamHeaderSize
- */
- ULONG32 CRVXVideoFormat::GetBitstreamHeaderSize(void)
- {
- ULONG32 ulSize = 0;
- if (m_pRssm)
- {
- ulSize = m_pRssm->GetBitstreamHeaderSize();
- }
- return ulSize;
- }
- /****************************************************************************
- * Method:
- * CRVXVideoFormat::GetBitstreamHeader
- */
- const HX_MOF* CRVXVideoFormat::GetBitstreamHeader(void)
- {
- const HX_MOF* pHeader = NULL;
- if (m_pRssm)
- {
- pHeader = m_pRssm->GetBitstreamHeader();
- }
- return pHeader;
- }
- /****************************************************************************
- * Method:
- * CVideoFormat::GetMaxDecodedFrames
- *
- */
- ULONG32 CRVXVideoFormat::GetMaxDecodedFrames(void)
- {
- return MAX_BUFFERED_DECODED_RV_FRAMES;
- }
- /****************************************************************************
- * Method:
- * CRVXVideoFormat::CreateAssembledPacket
- */
- CMediaPacket* CRVXVideoFormat::CreateAssembledPacket(IHXPacket* pCodecData)
- {
- HXCODEC_DATA* pCodecPacket = NULL;
- CMediaPacket* pFramePacket = NULL;
- IHXPacket* pPacket = NULL;
- HX_RESULT retVal = HXR_OK;
- #ifdef _IGNORE_UNSUPPORTED
- if (!m_pRssm)
- {
- return NULL;
- }
- #endif // _IGNORE_UNSUPPORTED
- m_pRVXVideoRenderer->BltIfNeeded();
- retVal = m_pRssm->SetPacket(pCodecData);
- if( retVal == HXR_OUTOFMEMORY )
- {
- m_LastError = HXR_OUTOFMEMORY;
- return NULL;
- }
- m_pRssm->CreateHXCodecPacket(pCodecPacket);
-
- while (pCodecPacket)
- {
- CheckPacketBuffer(pCodecPacket);
- pFramePacket = new CMediaPacket(
- pCodecPacket,
- (UINT8*) pCodecPacket,
- pCodecPacket->dataLength,
- pCodecPacket->dataLength,
- pCodecPacket->timestamp,
- pCodecPacket->flags, //0,
- NULL);
-
- if (pFramePacket == NULL)
- {
- HX_ASSERT(HXR_OUTOFMEMORY == HXR_OK);
- KillInputBuffer(pCodecPacket, this);
- m_LastError = HXR_OUTOFMEMORY;
- return NULL;
- }
- else
- {
- pFramePacket->SetBufferKiller(KillInputBuffer);
- pFramePacket->m_pUserData = this;
- // Report missing frames as dropped
- if (m_ulLastSequenceNumber != UNINITIALIZED_SEQ_NUMBER)
- {
- UINT16 uFramesDropped = pCodecPacket->sequenceNum -
- ((UINT16) m_ulLastSequenceNumber) - 1;
- if (uFramesDropped != 0)
- {
- if (m_pRVXVideoRenderer->IsActive() ||
- (((LONG32) (pCodecPacket->timestamp - GetStartTime())) > 0))
- {
- m_pRVXVideoRenderer->ReportDroppedFrame(uFramesDropped);
- }
- }
- }
-
- m_ulLastSequenceNumber = (ULONG32) pCodecPacket->sequenceNum;
- }
-
- m_pRVXVideoRenderer->BltIfNeeded();
- pCodecPacket = NULL;
- m_pRssm->CreateHXCodecPacket(pCodecPacket);
- if (pCodecPacket)
- {
- ReturnAssembledPacket(pFramePacket);
- pFramePacket = NULL;
- }
- }
-
- return pFramePacket;
- }
- /****************************************************************************
- * Method:
- * CRVXVideoFormat::Reset
- */
- void CRVXVideoFormat::Reset()
- {
- _Reset();
- CVideoFormat::Reset();
- }
- void CRVXVideoFormat::_Reset(void)
- {
- if (m_pRssm)
- {
- m_pRssm->Reset();
- }
- m_bFirstDecode = TRUE;
- m_ulWidthContainedInSegment = 0;
- m_ulHeightContainedInSegment = 0;
- m_ulLastSequenceNumber = UNINITIALIZED_SEQ_NUMBER;
- }
- void CRVXVideoFormat::FlushDecodedRngBuf(void)
- {
- if (m_pDecodedRngBuf)
- {
- HXCODEC_DATA* pFrame;
-
- while (pFrame = ((HXCODEC_DATA*) m_pDecodedRngBuf->Get()))
- {
- ReleaseDecodedPacket(pFrame);
- }
- }
- }
- void CRVXVideoFormat::ReleaseDecodedPacket(HXCODEC_DATA* &pDecodedPacket)
- {
- HX_ASSERT(pDecodedPacket);
- if (pDecodedPacket)
- {
- ULONG32* pFrameData = (ULONG32*) pDecodedPacket;
- if (pDecodedPacket->data &&
- m_pRVXVideoRenderer &&
- m_pRVXVideoRenderer->m_pOutputAllocator)
- {
- m_pRVXVideoRenderer->m_pOutputAllocator->ReleasePacketPtr(pDecodedPacket->data);
- }
- delete [] pFrameData;
- pDecodedPacket = NULL;
- }
- }
- /****************************************************************************
- * Method:
- * CRVXVideoFormat::CreateDecodedPacket
- *
- */
- CMediaPacket* CRVXVideoFormat::CreateDecodedPacket(CMediaPacket* pFrameToDecode)
- {
- HXCODEC_DATA* pDecodedPacket = NULL;
- CMediaPacket* pDecodedFrame = NULL;
- UINT8* pData = NULL;
- BOOL bFrameDecoded = FALSE;
- HX_ASSERT(pFrameToDecode);
- #if defined(HELIX_FEATURE_VIDEO_REAL_DISCARD_LATE_ENCODED_FRAMES)
- // discard late frames before they are decoded
- BOOL bDecodeThisOne = TRUE;
- if (m_pRVXVideoRenderer->IsActive()) // if playing
- {
- LONG32 lTimeAhead = m_pRVXVideoRenderer->ComputeTimeAhead(
- pFrameToDecode->m_ulTime, 0);
- if (pFrameToDecode->m_ulFlags & HX_KEYFRAME_FLAG)
- {
- if (lTimeAhead < MAX_KEY_CODED_FRAME_FALLBEHIND)
- {
- // Treat it as non key-frame: drop it
- bDecodeThisOne = FALSE;
- m_bFlushingToKeyFrame = TRUE;
- }
- else
- { // we're going to display this key frame, so stop flushing
- m_bFlushingToKeyFrame = FALSE;
- }
- }
- else
- {
- if (lTimeAhead < MAX_NONKEY_CODED_FRAME_FALLBEHIND)
- { // discard this frame and all frames to the next key frame
- bDecodeThisOne = FALSE;
- m_bFlushingToKeyFrame = TRUE;
- }
- else
- {
- }
- }
- }
- else
- { // we're not playing, so decode when we start playing
- m_bFlushingToKeyFrame = FALSE;
- }
- if (bDecodeThisOne && !m_bFlushingToKeyFrame)
- { // decode and display this frame
- ;
- }
- else
- { // discard this frame before decode
- pFrameToDecode->Clear();
- delete pFrameToDecode;
- m_pRVXVideoRenderer->ReportDroppedFrame();
- return NULL;
- }
- #endif // HELIX_FEATURE_VIDEO_REAL_DISCARD_LATE_ENCODED_FRAMES
- if (m_bFirstDecode)
- {
- m_bFirstDecode = FALSE;
- FlushDecodedRngBuf();
- m_pDecoder->ResetSequence(GetStartTime());
- }
- pDecodedPacket = (HXCODEC_DATA*) m_pDecodedRngBuf->Get();
- m_pRVXVideoRenderer->BltIfNeeded();
- HX_RESULT retVal = m_pDecoder->Decode(pFrameToDecode, MAX_DECODE_QUALITY);
- if( retVal == HXR_OUTOFMEMORY )
- {
- m_LastError = HXR_OUTOFMEMORY;
- return NULL;
- }
- else
- {
- do
- {
- if (pDecodedPacket == NULL)
- {
- pDecodedPacket = (HXCODEC_DATA*) m_pDecodedRngBuf->Get();
- }
- bFrameDecoded = (pDecodedPacket != NULL);
- #if !defined(HELIX_FEATURE_VIDEO_REAL_DISCARD_LATE_ENCODED_FRAMES)
- // don't discard decoded frames
- if (pDecodedPacket)
- {
- if (m_pRVXVideoRenderer->IsActive() &&
- (m_pRVXVideoRenderer->ComputeTimeAhead(
- pDecodedPacket->timestamp,
- 0)
- < -NON_KEYFRM_DCDE_FALLBEHIND_THRSHLD))
- {
- ReleaseDecodedPacket(pDecodedPacket);
- m_pRVXVideoRenderer->ReportDroppedFrame();
- }
- }
- #endif // HELIX_FEATURE_VIDEO_REAL_DISCARD_LATE_ENCODED_FRAMES
- } while ((!pDecodedPacket) && bFrameDecoded);
- if (pDecodedPacket)
- {
- CMediaPacket* pVideoPacket = NULL;
- pVideoPacket = (CMediaPacket*) m_pFramePool->Get(0);
- if (pVideoPacket == NULL)
- {
- pVideoPacket = pFrameToDecode;
- pFrameToDecode = NULL;
- }
- if (pVideoPacket)
- {
- pVideoPacket->SetBuffer(pDecodedPacket->data,
- pDecodedPacket->data,
- pDecodedPacket->dataLength,
- pDecodedPacket->dataLength,
- FALSE);
- pVideoPacket->Init(pDecodedPacket->data,
- pDecodedPacket->dataLength,
- pDecodedPacket->timestamp,
- pDecodedPacket->flags,
- pDecodedPacket); // sample description
- // Data is now linked through VideoPacket
- pDecodedPacket->data = NULL;
- pDecodedPacket->dataLength = 0;
- pVideoPacket->SetBufferKiller(KillOutputBuffer);
- pVideoPacket->SetSampleDescKiller(KillRVXSampleDesc);
- pVideoPacket->m_pUserData = m_pRVXVideoRenderer;
- pDecodedPacket = NULL;
- pDecodedFrame = pVideoPacket;
- pVideoPacket = NULL;
- }
- if (pVideoPacket)
- {
- delete pVideoPacket;
- }
- }
- }
- if (pFrameToDecode != NULL)
- {
- pFrameToDecode->Clear();
- delete pFrameToDecode;
- }
- if (pDecodedPacket)
- {
- ReleaseDecodedPacket(pDecodedPacket);
- }
- return pDecodedFrame;
- }
- CRVXVDecoder* CRVXVideoFormat::CreateDecoder()
- {
- return new CRVXVDecoder();
- }
- /****************************************************************************
- * Method:
- * CRVXVideoFormat::DecodeDone
- */
- HX_RESULT CRVXVideoFormat::DecodeDone(HXCODEC_DATA* pData)
- {
- HX_RESULT retVal = HXR_OK;
- m_pRVXVideoRenderer->BltIfNeeded();
- if (pData)
- {
- ULONG32 ulFrameSize = HXCODEC_PTR_POPULATED_SIZE(pData);
- HXCODEC_DATA* pFrame = (HXCODEC_DATA*) new ULONG32[ulFrameSize / 4 + 1];
- if (pFrame)
- {
- memcpy(pFrame, pData, ulFrameSize); /* Flawfinder: ignore */
- if (!m_pDecodedRngBuf->Put(pFrame))
- {
- ReleaseDecodedPacket(pFrame);
- m_pRVXVideoRenderer->ReportDroppedFrame();
- }
- }
- else
- {
- if (pData->data)
- {
- m_pRVXVideoRenderer->m_pOutputAllocator->ReleasePacketPtr(
- pData->data);
- m_pRVXVideoRenderer->ReportDroppedFrame();
- }
- }
- }
- return retVal;
- }
- /****************************************************************************
- * Method:
- * CRVXVideoFormat::IsBitmapFormatChanged
- *
- */
- BOOL CRVXVideoFormat::IsBitmapFormatChanged(
- HXBitmapInfoHeader &BitmapInfoHeader,
- CMediaPacket* pVideoPacket)
- {
- BOOL bRetVal = (m_ulWidthContainedInSegment == 0);
- HXCODEC_DATA* pData = (HXCODEC_DATA*) pVideoPacket->m_pSampleDesc;
-
- if (pData &&
- (pData->flags & HX_SEGMENT_CONTAINS_OUTPUT_SIZE_FLAG))
- {
- bRetVal = (bRetVal ||
- ((m_ulWidthContainedInSegment != pData->Segments[1].ulSegmentOffset) ||
- (m_ulHeightContainedInSegment != ((ULONG32) pData->Segments[1].bIsValid))));
- }
- return bRetVal;
- }
- /****************************************************************************
- * Method:
- * CRVXVideoFormat::InitBitmapInfoHeader
- */
- HX_RESULT CRVXVideoFormat::InitBitmapInfoHeader(
- HXBitmapInfoHeader &bitmapInfoHeader,
- CMediaPacket* pVideoPacket)
- {
- if (m_pCodecOutputBIH)
- {
- HXCODEC_DATA* pData = (HXCODEC_DATA*) pVideoPacket->m_pSampleDesc;
- if (pData && (pData->flags & HX_SEGMENT_CONTAINS_OUTPUT_SIZE_FLAG))
- {
- if ((m_ulWidthContainedInSegment != pData->Segments[1].ulSegmentOffset) ||
- (m_ulHeightContainedInSegment != ((ULONG32) pData->Segments[1].bIsValid)))
- {
- m_pCodecOutputBIH->biWidth = m_ulWidthContainedInSegment =
- pData->Segments[1].ulSegmentOffset;
- m_pCodecOutputBIH->biHeight = m_ulHeightContainedInSegment =
- ((ULONG32) pData->Segments[1].bIsValid);
- m_pCodecOutputBIH->biWidth += (m_pRVXVideoRenderer->m_ulPadWidthLeft +
- m_pRVXVideoRenderer->m_ulPadWidthRight);
- m_pCodecOutputBIH->biHeight += (m_pRVXVideoRenderer->m_ulPadHeightTop +
- m_pRVXVideoRenderer->m_ulPadHeightBottom);
- m_pCodecOutputBIH->biSizeImage =
- m_pCodecOutputBIH->biWidth * m_pCodecOutputBIH->biBitCount *
- m_pCodecOutputBIH->biHeight / 8;
- }
- }
- else
- {
- m_ulWidthContainedInSegment = m_pCodecOutputBIH->biWidth;
- m_ulHeightContainedInSegment = m_pCodecOutputBIH->biHeight;
- }
-
- bitmapInfoHeader = *m_pCodecOutputBIH;
- }
- return HXR_OK;
- }
- /****************************************************************************
- * Method:
- * CRVXVideoFormat::CreateAllocators()
- */
- HX_RESULT CRVXVideoFormat::CreateAllocators(void)
- {
- HX_RESULT retVal = HXR_OK;
- HX20ALLOCPROPS allocRequest, allocActual;
- if (m_pInputAllocator)
- {
- m_pInputAllocator->Release();
- m_pInputAllocator = NULL;
- }
- if (m_pRVXVideoRenderer->m_pOutputAllocator)
- {
- m_pRVXVideoRenderer->m_pOutputAllocator->Release();
- m_pRVXVideoRenderer->m_pOutputAllocator = NULL;
- }
-
- // setup the input allocator for the codec
- if (retVal == HXR_OK)
- {
- m_pInputAllocator = new CHXMemoryAllocator(TRUE);
- retVal = HXR_OUTOFMEMORY;
- if (m_pInputAllocator)
- {
- m_pInputAllocator->AddRef();
- m_pInputAllocator->GetProperties(&allocRequest);
- allocRequest.nNumBuffers = 0; // No retention
- m_pInputAllocator->SetProperties(&allocRequest,
- &allocActual);
- retVal = HXR_OK;
- }
- }
- // setup the output allocator for the codec
- if (retVal == HXR_OK)
- {
- m_pRVXVideoRenderer->m_pOutputAllocator = new CHXMemoryAllocator(TRUE);
- retVal = HXR_OUTOFMEMORY;
- if (m_pRVXVideoRenderer->m_pOutputAllocator)
- {
- m_pRVXVideoRenderer->m_pOutputAllocator->AddRef();
- m_pRVXVideoRenderer->m_pOutputAllocator->GetProperties(&allocRequest);
- allocRequest.nNumBuffers = GetMaxDecodedFrames() * 2;
- m_pRVXVideoRenderer->m_pOutputAllocator->SetProperties(&allocRequest,
- &allocActual);
- retVal = HXR_OK;
- }
- }
- #if _MACINTOSH
- // TODO: we want to pre-allocate the output buffers here so they come
- // from the standard memory pools instead of the interrupt memory
- // pools.
- #endif // _MACINTOSH
- return retVal;
- }
- /****************************************************************************
- * Method:
- * CMP4VideoFormat::KillRVXSampleDesc
- *
- */
- void CRVXVideoFormat::KillRVXSampleDesc(void* pSampleDesc, void* pUserData)
- {
- if (pSampleDesc)
- {
- HXCODEC_DATA* pFrame = (HXCODEC_DATA*) pSampleDesc;
- ULONG32* pFrameData = (ULONG32*) pFrame;
- if (pFrame->data)
- {
- KillOutputBuffer(pFrame->data, pUserData);
- }
- delete [] pFrameData;
- }
- }
- /****************************************************************************
- * Method:
- * CRVXVideoFormat::KillInputBuffer
- *
- */
- void CRVXVideoFormat::KillInputBuffer(void* pBuffer, void* pUserData)
- {
- if (pBuffer)
- {
- HXCODEC_DATA* pDeadData = (HXCODEC_DATA*) pBuffer;
- CRVXVideoFormat* pVidFmt = (CRVXVideoFormat*) pUserData;
- HX_ASSERT(pUserData);
- if (pDeadData->data)
- {
- pVidFmt->m_pInputAllocator->ReleasePacketPtr(pDeadData->data);
- pDeadData->data = NULL;
- }
- if (pVidFmt->m_pRssm)
- {
- pVidFmt->m_pRssm->DisposeHXCodecPacket(pDeadData);
- }
- }
- }
- /****************************************************************************
- * Method:
- * CRVXVideoFormat::KillOutputBuffer
- *
- */
- void CRVXVideoFormat::KillOutputBuffer(void* pBuffer, void* pUserData)
- {
- if (pBuffer)
- {
- CRVXVideoRenderer* pVidRnd = (CRVXVideoRenderer*) pUserData;
- HX_ASSERT(pUserData);
- if (NULL == pVidRnd || NULL == pVidRnd->m_pOutputAllocator)
- return;
- pVidRnd->m_pOutputAllocator->ReleasePacketPtr((UINT8*) pBuffer);
- }
- }