qttrkmgr.cpp
上传用户:dangjiwu
上传日期:2013-07-19
资源大小:42019k
文件大小:24k
- /* ***** 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_HINTS
- #define INV_HINT_TRACK_IDX 0xFFFFFFFF
- #define INV_STREAM_NUM 0xFFFF
- /****************************************************************************
- * Includes
- */
- #include "qttrkmgr.h"
- #include "qttrack.h"
- /****************************************************************************
- * Class CTrackManager
- */
- /****************************************************************************
- * Constructor/Destructor
- */
- CQTTrackManager::CQTTrackManager(void)
- : m_uNumTracks(0)
- , m_uNumStreams(0)
- , m_pTrackTable(NULL)
- , m_pStreamToTrackMap(NULL)
- , m_pTrackAtomList(new CHXSimpleList)
- , m_pHintTrackIdxList(new CHXSimpleList)
- , m_bSubscriptionWindowClosed(FALSE)
- , m_bHintTracksActive(FALSE)
- , m_bHinted(FALSE)
- , m_pIodsAtom(NULL)
- , m_pFtypAtom(NULL)
- , m_FType(QT_FTYPE_UNKNOWN)
- , m_EType(QT_ETYPE_UNKNOWN)
- {
- HX_ASSERT(m_pTrackAtomList);
- HX_ASSERT(m_pHintTrackIdxList);
- }
- CQTTrackManager::~CQTTrackManager()
- {
- Clear();
- }
- /****************************************************************************
- * Main Interface
- */
- /****************************************************************************
- * ManageTracks
- */
- HX_RESULT CQTTrackManager::ManageTracks(CQTAtom *pRootAtom)
- {
- if ((m_pTrackAtomList == NULL) ||
- (m_pHintTrackIdxList == NULL))
- {
- HX_ASSERT(!"shouldn't happen");
- return HXR_UNEXPECTED;
- }
- AddTracks(pRootAtom);
- if (m_FType == QT_FTYPE_UNKNOWN)
- {
- m_FType = QT_FTYPE_QT;
- }
- return HXR_OK;
- }
- /****************************************************************************
- * ReadyTracks
- */
- HX_RESULT CQTTrackManager::ReadyTracks(BOOL bIgnoreHintTracks,
- BOOL bFallbackToTracks)
- {
- HX_RESULT retVal = HXR_OK;
- #ifdef _IGNORE_HINTS
- bIgnoreHintTracks = TRUE;
- #endif // _IGNORE_HINTS
- if ((m_pTrackAtomList == NULL) ||
- (m_pHintTrackIdxList == NULL) ||
- (m_pTrackAtomList->GetCount() == 0))
- {
- HX_ASSERT(!"shouldn't happen");
- retVal = HXR_CORRUPT_FILE;
- }
- if (SUCCEEDED(retVal))
- {
- m_uNumStreams = 0;
- m_uNumTracks = m_pTrackAtomList->GetCount();
- if (!bIgnoreHintTracks)
- {
- m_uNumStreams = m_pHintTrackIdxList->GetCount();
- }
- m_bHinted = (m_uNumStreams != 0);
- m_bHintTracksActive = m_bHinted;
- DecideHintTrackActivation(bFallbackToTracks);
- if (m_uNumStreams <= 0)
- {
- retVal = HXR_FAIL; // No Streamable Tracks
- }
- }
- // Allocate Tables
- if (SUCCEEDED(retVal))
- {
- HX_ASSERT(!m_pTrackTable);
- HX_ASSERT(!m_pStreamToTrackMap);
- m_pStreamToTrackMap = new CQTStream [m_uNumStreams];
- m_pTrackTable = new CQTTrackTable [m_uNumTracks];
- if ((m_pStreamToTrackMap == NULL) ||
- (m_pTrackTable == NULL))
- {
- retVal = HXR_OUTOFMEMORY;
- }
- }
- // Fill Tables with info.
- if (SUCCEEDED(retVal))
- {
- LISTPOSITION HintTrackIdxListPosition;
- LISTPOSITION TrackAtomListPosition;
- ULONG32 ulHintTrackIdx = INV_HINT_TRACK_IDX;
- UINT16 uStreamTrackCount = 0;
- UINT16 uHintTrackCount = 0;
- CQTAtom* pTrackAtom;
- UINT16 uTrackIdx = 0;
- HintTrackIdxListPosition = m_pHintTrackIdxList->GetHeadPosition();
- TrackAtomListPosition = m_pTrackAtomList->GetHeadPosition();
- if (HintTrackIdxListPosition)
- {
- ulHintTrackIdx = (UINT32) m_pHintTrackIdxList->GetNext(
- HintTrackIdxListPosition);
- }
- do
- {
- pTrackAtom = (CQTAtom*) m_pTrackAtomList->GetNext(
- TrackAtomListPosition);
- HX_ASSERT(pTrackAtom);
- if (uTrackIdx == ulHintTrackIdx)
- {
- // This is a hint track
- if (m_bHintTracksActive)
- {
- retVal = CreateHintTrack(pTrackAtom,
- uTrackIdx,
- uStreamTrackCount);
- if (retVal != HXR_OK)
- {
- break;
- }
- }
- uHintTrackCount++;
- if (uHintTrackCount < m_pHintTrackIdxList->GetCount())
- {
- ulHintTrackIdx = (UINT32) m_pHintTrackIdxList->GetNext(
- HintTrackIdxListPosition);
- }
- }
- else
- {
- // This a standard track
- m_pTrackTable[uTrackIdx].m_pTrack = new CQTTrack(pTrackAtom);
- if (m_pTrackTable[uTrackIdx].m_pTrack == NULL)
- {
- retVal = HXR_OUTOFMEMORY;
- break;
- }
- m_pTrackTable[uTrackIdx].m_pTrackAtom = pTrackAtom;
- pTrackAtom->AddRef();
- if (!m_bHintTracksActive)
- {
- HX_ASSERT(uStreamTrackCount < m_uNumStreams);
- if (uStreamTrackCount < m_uNumStreams)
- {
- m_pStreamToTrackMap[uStreamTrackCount].m_pQTTrack =
- m_pTrackTable[uTrackIdx].m_pTrack;
- uStreamTrackCount++;
- }
- }
- // For now keep references to all "standard" tracks.
- // To do : reference only "standard" tracks referenced
- // by hint tracks - when hint tracks are active
- m_pTrackTable[uTrackIdx].m_uRefCount++;
- }
- if (m_pTrackTable[uTrackIdx].m_pTrack)
- {
- m_pTrackTable[uTrackIdx].m_pTrack->AddRef();
- }
- uTrackIdx++;
- } while (uTrackIdx < m_uNumTracks);
- }
- // Free Unreferenced Standard Tracks
- if (SUCCEEDED(retVal))
- {
- UINT16 uTrackIdx;
- for (uTrackIdx = 0; uTrackIdx < m_uNumTracks; uTrackIdx++)
- {
- if (m_pTrackTable[uTrackIdx].m_uRefCount == 0)
- {
- HX_RELEASE(m_pTrackTable[uTrackIdx].m_pTrack);
- HX_RELEASE(m_pTrackTable[uTrackIdx].m_pTrackAtom);
- }
- }
- }
- if (FAILED(retVal))
- {
- Clear();
- }
- return retVal;
- }
- /****************************************************************************
- * CloseTracks
- */
- void CQTTrackManager::CloseTracks(void)
- {
- UINT16 uTrackIdx;
- if (m_pTrackTable)
- {
- for (uTrackIdx = 0; uTrackIdx < m_uNumTracks; uTrackIdx++)
- {
- if (m_pTrackTable[uTrackIdx].m_pTrack)
- {
- m_pTrackTable[uTrackIdx].m_pTrack->Close();
- m_pTrackTable[uTrackIdx].m_pTrack->Release();
- m_pTrackTable[uTrackIdx].m_pTrack = NULL;
- }
- HX_RELEASE(m_pTrackTable[uTrackIdx].m_pTrackAtom);
- }
- }
- Clear();
- }
- /****************************************************************************
- * ResetTracks - reset what's done in ReadyTracks()
- */
- void CQTTrackManager::ResetTracks(void)
- {
- if (m_pTrackTable)
- {
- for (UINT16 uTrackIdx = 0; uTrackIdx < m_uNumTracks; uTrackIdx++)
- {
- if (m_pTrackTable[uTrackIdx].m_pTrack)
- {
- m_pTrackTable[uTrackIdx].m_pTrack->Close();
- m_pTrackTable[uTrackIdx].m_pTrack->Release();
- m_pTrackTable[uTrackIdx].m_pTrack = NULL;
- }
- HX_RELEASE(m_pTrackTable[uTrackIdx].m_pTrackAtom);
- }
- }
- HX_VECTOR_DELETE(m_pTrackTable);
- HX_VECTOR_DELETE(m_pStreamToTrackMap);
- m_uNumTracks = 0;
- m_uNumStreams = 0;
- }
- /****************************************************************************
- * InitTracks
- */
- HX_RESULT CQTTrackManager::InitTracks(CQTFileFormat *pFileFormat,
- CQTPacketAssembler *pPacketAssembler,
- CQTPacketizerFactory* pPacketizerFactory,
- const char* pProtocol)
- {
- UINT16 uTrackIdx;
- HX_RESULT retVal = HXR_OK;
- if (m_pTrackTable)
- {
- UINT16 uStreamNum;
- BOOL bSomeStreamsDeactivated = FALSE;
- for (uTrackIdx = 0;
- SUCCEEDED(retVal) && (uTrackIdx < m_uNumTracks);
- uTrackIdx++)
- {
- if (m_pTrackTable[uTrackIdx].m_pTrack)
- {
- retVal = m_pTrackTable[uTrackIdx].m_pTrack->Init(pFileFormat,
- pPacketAssembler,
- pPacketizerFactory,
- pProtocol);
- uStreamNum = GetTrackStreamNum(m_pTrackTable[uTrackIdx].m_pTrack);
- if (uStreamNum < m_uNumStreams)
- {
- m_pStreamToTrackMap[uStreamNum].m_bActive = (retVal == HXR_OK);
- bSomeStreamsDeactivated = bSomeStreamsDeactivated ||
- (!m_pStreamToTrackMap[uStreamNum].m_bActive);
- if ((retVal == HXR_IGNORE) ||
- (retVal == HXR_NO_DATA))
- {
- retVal = HXR_OK;
- }
- }
- }
- }
- // Some streams could have been
- // disabled during initialization - remove the inactive ones
- if (SUCCEEDED(retVal) && bSomeStreamsDeactivated)
- {
- retVal = RemoveInactiveStreams();
- #ifdef QTCONFIG_ALTERNATE_STREAMS
- // Return remaining streams to inactive (unsubscribed) state
- if (SUCCEEDED(retVal))
- {
- for (uTrackIdx = 0; uTrackIdx < m_uNumStreams; uTrackIdx++)
- {
- m_pStreamToTrackMap[uTrackIdx].m_bActive = FALSE;
- }
- m_bSubscriptionWindowClosed = FALSE;
- }
- #endif // QTCONFIG_ALTERNATE_STREAMS
- }
- // After track initialization, release all Track Atoms from
- // the track manager
- for (uTrackIdx = 0;
- uTrackIdx < m_uNumTracks;
- uTrackIdx++)
- {
- HX_RELEASE(m_pTrackTable[uTrackIdx].m_pTrackAtom);
- }
- }
- else
- {
- retVal = HXR_UNEXPECTED;
- }
- if (SUCCEEDED(retVal))
- {
- // Release Lists
- DeleteTrackAtomList();
- HX_DELETE(m_pHintTrackIdxList);
- }
- return retVal;
- }
- #ifdef QTCONFIG_ALTERNATE_STREAMS
- /****************************************************************************
- * AddStreamToGroup
- */
- HX_RESULT CQTTrackManager::AddStreamToGroup(UINT16 uStreamNumber,
- UINT16 uGroup,
- ULONG32 ulBitrate)
- {
- HX_RESULT retVal = HXR_FAIL;
- HX_ASSERT(m_pStreamToTrackMap);
- HX_ASSERT(uStreamNumber < m_uNumStreams);
- if (uStreamNumber < m_uNumStreams)
- {
- m_pStreamToTrackMap[uStreamNumber].m_uGroup = uGroup;
- m_pStreamToTrackMap[uStreamNumber].m_ulBitrate = ulBitrate;
- m_pStreamToTrackMap[uStreamNumber].m_bGroupped = TRUE;
- retVal = HXR_OK;
- }
- return retVal;
- }
- /****************************************************************************
- * SubscribeDefault
- */
- HX_RESULT CQTTrackManager::SubscribeDefault(void)
- {
- UINT16 uStrmIdx;
- HX_RESULT retVal = HXR_OUTOFMEMORY;
- BOOL* pVisitedArray = new BOOL [m_uNumStreams];
- HX_ASSERT(m_pStreamToTrackMap);
- HX_ASSERT(pVisitedArray);
- if (pVisitedArray)
- {
- for (uStrmIdx = 0; uStrmIdx < m_uNumStreams; uStrmIdx++)
- {
- pVisitedArray[uStrmIdx] = FALSE;
- }
- retVal = HXR_OK;
- }
- if (SUCCEEDED(retVal))
- {
- for (uStrmIdx = 0; uStrmIdx < m_uNumStreams; uStrmIdx++)
- {
- if (!pVisitedArray[uStrmIdx])
- {
- if (m_pStreamToTrackMap[uStrmIdx].m_bGroupped)
- {
- // Activate the highest bitrate stream in the group
- UINT16 uSubIdx;
- UINT16 uGroup = m_pStreamToTrackMap[uStrmIdx].m_uGroup;
- ULONG32 ulHighBitrate = m_pStreamToTrackMap[uStrmIdx].m_ulBitrate;
- UINT16 uHighIdx = uStrmIdx;
- m_pStreamToTrackMap[uStrmIdx].m_bActive = FALSE;
- for (uSubIdx = uStrmIdx + 1; uSubIdx < m_uNumStreams; uSubIdx++)
- {
- if (m_pStreamToTrackMap[uStrmIdx].m_uGroup == uGroup)
- {
- m_pStreamToTrackMap[uSubIdx].m_bActive = FALSE;
- if (m_pStreamToTrackMap[uSubIdx].m_ulBitrate > ulHighBitrate)
- {
- ulHighBitrate = m_pStreamToTrackMap[uSubIdx].m_ulBitrate;
- uHighIdx = uSubIdx;
- }
- pVisitedArray[uSubIdx] = TRUE;
- }
- }
- m_pStreamToTrackMap[uHighIdx].m_bActive = TRUE;
- }
- else
- {
- m_pStreamToTrackMap[uStrmIdx].m_bActive = TRUE;
- }
- pVisitedArray[uStrmIdx] = TRUE;
- }
- }
- }
- HX_VECTOR_DELETE(pVisitedArray);
- return retVal;
- }
- /****************************************************************************
- * Subscribe
- */
- HX_RESULT CQTTrackManager::Subscribe(UINT16 uStreamNum)
- {
- HX_RESULT retVal = HXR_UNEXPECTED;
- if (!m_bSubscriptionWindowClosed)
- {
- HX_ASSERT(m_pStreamToTrackMap);
- HX_ASSERT(uStreamNum < m_uNumStreams);
- retVal = HXR_FAIL;
- if (uStreamNum < m_uNumStreams)
- {
- if (m_pStreamToTrackMap[uStreamNum].m_bGroupped)
- {
- UINT16 uStrmIdx;
- UINT16 uGroup = m_pStreamToTrackMap[uStreamNum].m_uGroup;
- // There can be only one stream subscribed in a group
- for (uStrmIdx = 0; uStrmIdx < m_uNumStreams; uStrmIdx++)
- {
- if (m_pStreamToTrackMap[uStrmIdx].m_uGroup == uGroup)
- {
- m_pStreamToTrackMap[uStrmIdx].m_bActive = FALSE;
- }
- }
- }
- m_pStreamToTrackMap[uStreamNum].m_bActive = TRUE;
- retVal = HXR_OK;
- }
- }
- return retVal;
- }
- /****************************************************************************
- * Unsubscribe
- */
- HX_RESULT CQTTrackManager::Unsubscribe(UINT16 uStreamNum)
- {
- HX_RESULT retVal = HXR_UNEXPECTED;
- if (!m_bSubscriptionWindowClosed)
- {
- HX_ASSERT(uStreamNum < m_uNumStreams);
- retVal = HXR_FAIL;
- if (uStreamNum < m_uNumStreams)
- {
- m_pStreamToTrackMap[uStreamNum].m_bActive = FALSE;
- retVal = HXR_OK;
- }
- }
- return retVal;
- }
- #else // QTCONFIG_ALTERNATE_STREAMS
- HX_RESULT CQTTrackManager::AddStreamToGroup(UINT16 uStreamNumber,
- UINT16 uGroup,
- ULONG32 ulBitrate)
- {
- return HXR_NOTIMPL;
- }
- HX_RESULT CQTTrackManager::SubscribeDefault(void)
- {
- return HXR_NOTIMPL;
- }
- HX_RESULT CQTTrackManager::Subscribe(UINT16 uStreamNum)
- {
- return HXR_NOTIMPL;
- }
- HX_RESULT CQTTrackManager::Unsubscribe(UINT16 uStreamNum)
- {
- return HXR_NOTIMPL;
- }
- #endif // QTCONFIG_ALTERNATE_STREAMS
- /****************************************************************************
- * RemoveInactiveStreams
- */
- HX_RESULT CQTTrackManager::RemoveInactiveStreams(BOOL bLeaveReferences)
- {
- HX_RESULT retVal = HXR_FAIL;
- HX_ASSERT(m_pStreamToTrackMap);
- UINT16 uActiveStreamCount = GetNumActiveStreams();
- if (uActiveStreamCount > 0)
- {
- CQTStream* pNewStreamToTrackMap = NULL;
- retVal = HXR_OK;
- if (!bLeaveReferences)
- {
- pNewStreamToTrackMap = new CQTStream [uActiveStreamCount];
- retVal = HXR_OUTOFMEMORY;
- if (pNewStreamToTrackMap)
- {
- retVal = HXR_OK;
- }
- }
- if (SUCCEEDED(retVal))
- {
- UINT16 uStrmIdx;
- UINT16 uNewStrmIdx = 0;
- for (uStrmIdx = 0; uStrmIdx < m_uNumStreams; uStrmIdx++)
- {
- if (m_pStreamToTrackMap[uStrmIdx].m_bActive)
- {
- if (!bLeaveReferences)
- {
- HX_ASSERT(uNewStrmIdx < uActiveStreamCount);
- pNewStreamToTrackMap[uNewStrmIdx] =
- m_pStreamToTrackMap[uStrmIdx];
- uNewStrmIdx++;
- }
- }
- else
- {
- ReleaseTrack(m_pStreamToTrackMap[uStrmIdx].m_pQTTrack);
- }
- }
- if (!bLeaveReferences)
- {
- delete [] m_pStreamToTrackMap;
- m_pStreamToTrackMap = pNewStreamToTrackMap;
- m_uNumStreams = uActiveStreamCount;
- }
- }
- m_bSubscriptionWindowClosed = TRUE;
- }
- return retVal;
- }
- /****************************************************************************
- * IsStreamTrack
- */
- BOOL CQTTrackManager::IsStreamTrack(CQTTrack* pTrack)
- {
- UINT16 uStreamCount = 0;
- CQTStream* pStreamTracer = m_pStreamToTrackMap;
- HX_ASSERT(pTrack);
- while (uStreamCount < m_uNumStreams)
- {
- if (pTrack == pStreamTracer->m_pQTTrack)
- {
- return TRUE;
- }
- pStreamTracer++;
- uStreamCount++;
- }
- return FALSE;
- }
- UINT16 CQTTrackManager::GetTrackStreamNum(CQTTrack* pTrack)
- {
- UINT16 uStreamCount = 0;
- CQTStream* pStreamTracer = m_pStreamToTrackMap;
- HX_ASSERT(pTrack);
- while (uStreamCount < m_uNumStreams)
- {
- if (pTrack == pStreamTracer->m_pQTTrack)
- {
- return uStreamCount;
- }
- pStreamTracer++;
- uStreamCount++;
- }
- return INV_STREAM_NUM;
- }
- /****************************************************************************
- * GetTrackById
- */
- CQTTrack* CQTTrackManager::GetTrackById(ULONG32 ulTrackID)
- {
- UINT16 uTrackCount = 0;
- CQTTrackTable* pTableTracer = m_pTrackTable;
- while (uTrackCount < m_uNumTracks)
- {
- if (pTableTracer->m_pTrack && (ulTrackID == pTableTracer->m_pTrack->GetID()))
- {
- return pTableTracer->m_pTrack;
- }
- uTrackCount++;
- pTableTracer++;
- }
- return NULL;
- }
- /****************************************************************************
- * GetAtomById
- */
- CQTAtom* CQTTrackManager::GetTrackAtomById(ULONG32 ulTrackID)
- {
- UINT16 uTrackCount = 0;
- CQTTrackTable* pTableTracer = m_pTrackTable;
- while (uTrackCount < m_uNumTracks)
- {
- if (ulTrackID == pTableTracer->m_pTrack->GetID())
- {
- return pTableTracer->m_pTrackAtom;
- }
- uTrackCount++;
- pTableTracer++;
- }
- return NULL;
- }
- /****************************************************************************
- * GetTrackAtomHdlr
- */
- CQT_hdlr_Atom* CQTTrackManager::GetTrackAtomHdlr(CQT_trak_Atom* pTrakAtom)
- {
- CQT_mdia_Atom* pMdiaAtom;
- CQT_hdlr_Atom* pHdlrAtom = NULL;
- pMdiaAtom = (CQT_mdia_Atom*) pTrakAtom->FindPresentChild(QT_mdia);
- if (pMdiaAtom)
- {
- pHdlrAtom = (CQT_hdlr_Atom*) pMdiaAtom->FindPresentChild(QT_hdlr);
- }
- return pHdlrAtom;
- }
- /****************************************************************************
- * GetTrackAtomStbl
- */
- CQT_stbl_Atom* CQTTrackManager::GetTrackAtomStbl(CQT_trak_Atom* pTrakAtom)
- {
- CQT_mdia_Atom* pMdiaAtom;
- CQT_hdlr_Atom* pMinfAtom;
- CQT_stbl_Atom* pStblAtom = NULL;
- pMdiaAtom = (CQT_mdia_Atom*) pTrakAtom->FindPresentChild(QT_mdia);
- if (pMdiaAtom)
- {
- pMinfAtom = (CQT_hdlr_Atom*) pMdiaAtom->FindPresentChild(QT_minf);
- if (pMinfAtom)
- {
- pStblAtom = (CQT_stbl_Atom*) pMinfAtom->FindPresentChild(QT_stbl);
- }
- }
- return pStblAtom;
- }
- /****************************************************************************
- * IsHintTrackAtom
- */
- BOOL CQTTrackManager::IsHintTrackAtom(CQT_trak_Atom* pTrakAtom)
- {
- CQT_hdlr_Atom* pHdlrAtom = GetTrackAtomHdlr(pTrakAtom);
- if (pHdlrAtom &&
- /*** MBO: To strict for some files
- (pHdlrAtom->Get_CompType() == QT_mhlr) &&
- ***/
- (pHdlrAtom->Get_CompSubtype() == QT_hint))
- {
- return TRUE;
- }
- return FALSE;
- }
- /****************************************************************************
- * IsNonEmptyTrackAtom
- */
- BOOL CQTTrackManager::IsNonEmptyTrackAtom(CQT_trak_Atom* pTrakAtom)
- {
- CQT_SampleSize_Manager sampleSize;
- CQT_stbl_Atom* pStblAtom = GetTrackAtomStbl(pTrakAtom);
- if (pStblAtom)
- {
- if (sampleSize.Init(pStblAtom) == HXR_OK)
- {
- return TRUE;
- }
- }
- return FALSE;
- }
- /****************************************************************************
- * Private Methods
- */
- /****************************************************************************
- * AddTracks
- */
- void CQTTrackManager::AddTracks(CQTAtom *pRootAtom)
- {
- UINT16 uChildCount;
- if (pRootAtom->GetType() == QT_trak)
- {
- BOOL bAdd = TRUE;
- if (IsHintTrackAtom((CQT_trak_Atom *) pRootAtom))
- {
- bAdd = IsNonEmptyTrackAtom((CQT_trak_Atom*) pRootAtom);
- if (bAdd)
- {
- m_pHintTrackIdxList->AddTail(
- (void *) m_pTrackAtomList->GetCount());
- }
- }
- if (bAdd)
- {
- m_pTrackAtomList->AddTail(pRootAtom);
- pRootAtom->AddRef();
- }
- }
- else if (((pRootAtom->GetType() == QT_HXROOT) ||
- (pRootAtom->GetType() == QT_moov)) &&
- (uChildCount = pRootAtom->GetPresentChildCount()))
- {
- CQTAtom::ChildIterator i = pRootAtom->BeginChildren();
- do
- {
- AddTracks(*i);
- if ((--uChildCount) == 0)
- {
- break;
- }
- ++i;
- } while (TRUE);
- }
- else if (pRootAtom->GetType() == QT_iods)
- {
- HX_ASSERT(m_pIodsAtom == NULL);
- if (m_pIodsAtom == NULL)
- {
- m_pIodsAtom = (CQT_iods_Atom*) pRootAtom;
- m_pIodsAtom->AddRef();
- m_FType = QT_FTYPE_MP4;
- }
- }
- else if (pRootAtom->GetType() == QT_ftyp)
- {
- HX_ASSERT(m_pFtypAtom == NULL);
- if (m_pFtypAtom == NULL)
- {
- UINT32 ulBrand;
- BOOL bKeepLooking;
- UINT32 ulCompBrandIdx = 0;
- UINT32 ulNumCompBrands = 0;
- m_pFtypAtom = (CQT_ftyp_Atom*) pRootAtom;
- m_pFtypAtom->AddRef();
- ulBrand = m_pFtypAtom->Get_MajorBrand();
- ulNumCompBrands = m_pFtypAtom->Get_NumCompatibleBrands();
- do
- {
- bKeepLooking = FALSE;
- switch (ulBrand)
- {
- case QT_isom:
- case QT_3gp4:
- case QT_3gp5:
- case QT_mp41:
- case QT_mp42:
- case QT_mmp4:
- case QT_m4a:
- m_FType = QT_FTYPE_MP4;
- break;
- default:
- if (ulCompBrandIdx < ulNumCompBrands)
- {
- ulBrand = m_pFtypAtom->Get_CompatibleBrand(ulCompBrandIdx);
- ulCompBrandIdx++;
- bKeepLooking = TRUE;
- }
- break;
- }
- } while (bKeepLooking);
- }
- }
- }
- /****************************************************************************
- * DeleteTrackAtomList
- */
- void CQTTrackManager::DeleteTrackAtomList(void)
- {
- if (m_pTrackAtomList)
- {
- CQTAtom *pAtom;
- while (!m_pTrackAtomList->IsEmpty())
- {
- pAtom = (CQTAtom*) m_pTrackAtomList->RemoveHead();
- HX_ASSERT(pAtom);
- pAtom->Release();
- }
- delete m_pTrackAtomList;
- m_pTrackAtomList = NULL;
- }
- }
- /****************************************************************************
- * Clear
- */
- void CQTTrackManager::Clear(void)
- {
- HX_VECTOR_DELETE(m_pTrackTable);
- HX_VECTOR_DELETE(m_pStreamToTrackMap);
- DeleteTrackAtomList();
- HX_DELETE(m_pHintTrackIdxList);
- HX_RELEASE(m_pIodsAtom);
- HX_RELEASE(m_pFtypAtom);
- m_uNumTracks = 0;
- m_uNumStreams = 0;
- }
- /****************************************************************************
- * GetNumActiveStreams
- */
- UINT16 CQTTrackManager::GetNumActiveStreams(void)
- {
- UINT16 uStrmIdx;
- UINT16 uActiveCount = 0;
- HX_ASSERT(m_pStreamToTrackMap);
- for (uStrmIdx = 0; uStrmIdx < m_uNumStreams; uStrmIdx++)
- {
- if (m_pStreamToTrackMap[uStrmIdx].m_bActive)
- {
- uActiveCount++;
- }
- }
- return uActiveCount;
- }
- /****************************************************************************
- * ReleaseTrack
- */
- void CQTTrackManager::ReleaseTrack(CQTTrack* pQTTrack)
- {
- // Remove Track from the Track Table
- if (m_pTrackTable)
- {
- UINT16 uTrackCount = 0;
- CQTTrackTable* pTableTracer = m_pTrackTable;
- while (uTrackCount < m_uNumTracks)
- {
- if (pTableTracer->m_pTrack == pQTTrack)
- {
- HX_RELEASE(pTableTracer->m_pTrack);
- HX_RELEASE(pTableTracer->m_pTrackAtom);
- break;
- }
- uTrackCount++;
- pTableTracer++;
- }
- }
- // Remove The track from the Stream Map (if there)
- if (m_pStreamToTrackMap)
- {
- UINT16 uStreamCount = 0;
- CQTStream* pStreamTracer = m_pStreamToTrackMap;
- while (uStreamCount < m_uNumStreams)
- {
- if (pStreamTracer->m_pQTTrack == pQTTrack)
- {
- pStreamTracer->m_pQTTrack = NULL;
- pStreamTracer->m_bActive = FALSE;
- pStreamTracer->m_bGroupped = FALSE;
- pStreamTracer->m_uGroup = 0;
- pStreamTracer->m_ulBitrate = 0;
- break;
- }
- uStreamCount++;
- pStreamTracer++;
- }
- }
- }
- /****************************************************************************
- * CQTTrackManager::CQTTrackTable
- */
- /****************************************************************************
- * Destructor
- */
- CQTTrackManager::CQTTrackTable::~CQTTrackTable()
- {
- if (m_pTrack)
- {
- m_pTrack->Release();
- }
- if (m_pTrackAtom)
- {
- m_pTrackAtom->Release();
- }
- }