chxsymclipinfo.cpp

来自「symbian 下的helix player源代码」· C++ 代码 · 共 409 行

CPP
409
字号
/************************************************************************
 * CHXSymClipInfo.cpp
 * ---------------
 *
 *
 *
 * (c) 1995-2003 RealNetworks, Inc. Patents pending. All rights reserved.
 *
 *****************************************************************************/
  

#include "hxtypes.h"


#include "hxsym_debug.h"
#include "hxsym_leaveutil.h"
#include "hxdebug_hxapi.h"
#include "hxapihelp_player.h"
#include "hxapihelp.h"
#include "chxavplayer.h"
#include "chxavcleanstring.h"
#include "chxavconfignames.h"
#include "chxavcleanupstack.h"
#include "comptr.h"
#include "comptr_traits.h"
#include "chxavutil.h"

#include "chxsymclipinfo.h"


/*
 * CHXSymClipInfo
 * -----------
 *
 */
CHXSymClipInfo::CHXSymClipInfo() 
: m_bHasVideo(false)
, m_bIsLive(false)
{
}



/*
 * ~CHXSymClipInfo
 * -------------
 * Destructor.
 *
 */
CHXSymClipInfo::~CHXSymClipInfo()
{
    Reset();
}

void CHXSymClipInfo::Reset()
{
    CleanupHeaders();
    CleanupBitrateInfo();
    CleanupURLs();
    m_bHasVideo = false;
    m_bIsLive = false;
    m_strServer = "";
}


/*
 * Release file and stream headers for all sources
 */
void CHXSymClipInfo::CleanupHeaders()
{
    TInt count = m_sourceHeaders.GetSize();
    for(TInt idx = 0; idx < count; ++idx)
    {
        CHXPtrArray* pSourceHeaders = reinterpret_cast<CHXPtrArray*>(m_sourceHeaders[idx]);
        CleanupHeaders(pSourceHeaders);
        delete pSourceHeaders;
    }

    m_sourceHeaders.RemoveAll();
}


/*
 * Release file and stream headers for the given source
 */
void CHXSymClipInfo::CleanupHeaders(CHXPtrArray* pSourceHeaders)
{
    HX_ASSERT(pSourceHeaders);
    TInt count = pSourceHeaders->GetSize();
    for(TInt idx = 0; idx < count; ++idx)
    {
        delete reinterpret_cast<comptr<IHXValues>*>((*pSourceHeaders)[idx]);
    }

    pSourceHeaders->RemoveAll();
}

/*
 * delete and clear bitrate value info
 */
void CHXSymClipInfo::CleanupBitrateInfo()
{
    TInt count = m_bitrateInfo.GetSize();
    for(TInt idx = 0; idx < count; ++idx)
    {
        CHXPtrArray* pBitrateValues = reinterpret_cast<CHXPtrArray*>(m_bitrateInfo[idx]);
        delete pBitrateValues;
    }

    m_bitrateInfo.RemoveAll();
}

/*
 * delete source URLs
 */
void CHXSymClipInfo::CleanupURLs()
{
    TInt count = m_sourceURLs.GetSize();
    for(TInt idx = 0; idx < count; ++idx)
    {
        CHXString* pStr = reinterpret_cast<CHXString*>(m_sourceURLs[idx]);
        delete pStr;
    }

    m_sourceURLs.RemoveAll();
}

/*
 * Collect source URLs from active player.
 */
void CHXSymClipInfo::CacheURLsL(IHXPlayer* pPlayer)
{
    CleanupURLs();

    UINT32 sourceCount = pPlayer->GetSourceCount();
    m_sourceURLs.SetSize(sourceCount);
    for(UINT32 idxSource = 0; idxSource < sourceCount; ++idxSource)
    {
        comptr<IHXStreamSource> streamSource = player::GetSource(pPlayer, idxSource);
        CHXString* pStr = new CHXString(streamSource->GetURL());

        DPRINTF(SYMP_INFO, ("CHXSymClipInfo::CacheURLsL(): src %lu url is '%.*s'\n", idxSource, 300, static_cast<const char*>(*pStr)));
        m_sourceURLs[idxSource] = pStr;
    }
}

/*
 * Collect file and stream headers from active player. 
 */
void CHXSymClipInfo::CacheHeadersL(IHXPlayer* pPlayer)
{
    CleanupHeaders();

    UINT32 sourceCount = pPlayer->GetSourceCount();
    m_sourceHeaders.SetSize(sourceCount);

    for(UINT32 idxSource = 0; idxSource < sourceCount; ++idxSource)
    {
        m_sourceHeaders[idxSource] = new (ELeave) CHXPtrArray;
        CHXPtrArray* pHeaderArray = reinterpret_cast<CHXPtrArray*>(m_sourceHeaders[idxSource]);

        // set source header total count == one file header + stream headers
        UINT32 streamCount = player::GetStreamCount(pPlayer, idxSource);
        pHeaderArray->SetSize(streamCount + 1); 
    
        comptr<IHXValues> fileHeader = player::GetFileHeader(pPlayer, 0);
        
        // HX_ASSERT(fileHeader); // sourceCount > 0 and no file header; this is possible for SDP
        if(!fileHeader)
        {
            CleanupHeaders();
            break;
        }

        // assign file header
        comptr<IHXValues>* pHeader = new (ELeave) comptr<IHXValues>;
        *pHeader = fileHeader;
        
        // stick it in
        (*pHeaderArray)[0] = pHeader;
        
        // stream headers
        for(UINT32 idxStream = 0; idxStream < streamCount; ++idxStream)
        {
            UINT32 idxHeader = idxStream + 1;

            // assign stream header
            pHeader = new (ELeave) comptr<IHXValues>;
            *pHeader = player::GetStreamHeader(pPlayer, idxSource, idxStream);

            // stick it in
            (*pHeaderArray)[idxHeader] = pHeader;
           
        }
    }
}


/*
 * return header at given index within array of headers for given source index
 */
comptr<IHXValues> CHXSymClipInfo::GetHeaderHelper(UINT32 idxSource, UINT32 idxHeader) const
{
    comptr<IHXValues> header;

    if(idxSource < m_sourceHeaders.GetSize())
    {
        CHXPtrArray* pSourceHeaders = reinterpret_cast<CHXPtrArray*>(m_sourceHeaders[idxSource]);
        HX_ASSERT(pSourceHeaders);
        HX_ASSERT(!pSourceHeaders->IsEmpty());
    
        if(idxHeader < pSourceHeaders->GetSize())
        {
            header = *(reinterpret_cast<comptr<IHXValues>*>((*pSourceHeaders)[idxHeader]));
        }
    }
    
    return header;
}

/*
 * save live and video presentation info
 */
void CHXSymClipInfo::CachePresentationInfoL(IHXPlayer* pPlayer)
{
    m_bIsLive = pPlayer->IsLive();
    m_bHasVideo = DoCheckForNonAudioStreams();
}

void CHXSymClipInfo::CacheRequestInfo(IHXRequest* pRequest)
{
    HX_ASSERT(pRequest);
    dbg::DumpObject(pRequest);
    comptr<IHXValues> respHeaders;
    pRequest->GetResponseHeaders(respHeaders.AsRef());

    if( respHeaders )
    {
        // store server name (if present) for clip info
        val::GetString(respHeaders, "Server", m_strServer);
    }
}

    
// helper
bool CHXSymClipInfo::DoCheckForNonAudioStreams()
{
    // XXXLCM this won't work for smil with all audio streams (first source has smil mimetype)
    UINT32 sourceCount = GetSourceCount();
    for(UINT32 idxSource = 0; idxSource < sourceCount; ++idxSource)
    {
        UINT32 streamCount = GetStreamCount(idxSource);
        for(UINT32 idx = 0; idx < streamCount; ++idx)
        {
            comptr<IHXValues> header = GetStreamHeader(idx, idxSource);
            HX_ASSERT(header);

            CHXString strMimeType;
            val::GetString(header, "MimeType", strMimeType);
            HX_ASSERT(!strMimeType.IsEmpty());
            if( 0 != strMimeType.Left(5).CompareNoCase("audio"))
            {
                // non-audio stream found
                DPRINTF(SYMP_INFO, ("CHXSymClipInfo::DoCheckForNonAudioStreams(): found '%s' (non-audio)\n", static_cast<const char*>(strMimeType)));
                return true;
            }
        }
    }

    // everything is audio
    DPRINTF(SYMP_INFO, ("CHXAvPlayer::DoCheckForNonAudioStreams(): audio only\n"));
    return false;
}

/*
 * return file header for current or most-recent playback
 */
comptr<IHXValues> CHXSymClipInfo::GetFileHeader(UINT32 idxSource) const
{
    // file header is always first header in source headers array
    return GetHeaderHelper(idxSource, 0);
    
}

/*
 * return url for current or most-recent playback
 */
const char* CHXSymClipInfo::GetURL(UINT32 idxSource) const
{
    const char* psz = 0;
    if(idxSource < m_sourceURLs.GetSize())
    {
        CHXString* pStr = reinterpret_cast<CHXString*>(m_sourceURLs[idxSource]);
        psz = *pStr;
    }
    return psz;
    
}

/*
 * return source count for current or most-recent playback
 */
UINT32 CHXSymClipInfo::GetSourceCount() const
{ 
    return m_sourceHeaders.GetSize(); 
}

/*
 * return stream count for current or most-recent playback
 */
UINT32  CHXSymClipInfo::GetStreamCount(UINT32 idxSource) const
{
    HX_ASSERT(idxSource < m_sourceHeaders.GetSize());

    CHXPtrArray* pSourceHeaders = reinterpret_cast<CHXPtrArray*>(m_sourceHeaders[idxSource]);
    HX_ASSERT(pSourceHeaders);

    UINT32 count = pSourceHeaders->GetSize();
    if( count > 0 )
    {
        --count; // minus one for file header
    }

    return count;
}

/*
 * return stream header for current or most-recent playback
 */
comptr<IHXValues> CHXSymClipInfo::GetStreamHeader(UINT32 idxStream, UINT32 idxSource) const
{
    UINT32 idxStreamHeader = idxStream + 1; // plus one accounts for file header at slot 0
    return GetHeaderHelper(idxSource, idxStreamHeader);
}



/*
 * return best-known stream bitrate value for given stream index
 */
UINT32 CHXSymClipInfo::GetStreamBitrate(UINT32 idxStream, UINT32 idxSource) const
{
    //HX_ASSERT(idxSource < m_bitrateInfo.GetSize()); // possible if file/stream headers gotten but bitrate values not determined yet
    UINT32 bitrate = 0;

    if( idxSource < m_bitrateInfo.GetSize() )
    {
        CHXPtrArray* pBitrateValues = reinterpret_cast<CHXPtrArray*>(m_bitrateInfo[idxSource]);
        HX_ASSERT(pBitrateValues);

        HX_ASSERT(idxStream < pBitrateValues->GetSize());
        if(idxStream < pBitrateValues->GetSize())
        {
            bitrate = reinterpret_cast<UINT32>((*pBitrateValues)[idxStream]);
        }
    }
    return bitrate;
}

/*
 * save best-known stream bitrate values
 */
void CHXSymClipInfo::SaveStreamBitrateValuesL(IHXPlayer* pPlayer)
{
    UINT32 sourceCount = pPlayer->GetSourceCount();
    m_bitrateInfo.SetSize(sourceCount);

    for(UINT32 idxSource = 0; idxSource < sourceCount; ++idxSource)
    {
        m_bitrateInfo[idxSource] = new (ELeave) CHXPtrArray;
        CHXPtrArray* pBitrateValues = reinterpret_cast<CHXPtrArray*>(m_bitrateInfo[idxSource]);

        UINT32 streamCount = player::GetStreamCount(pPlayer, idxSource);
        pBitrateValues->SetSize(streamCount);

        for(UINT32 idxStream = 0; idxStream < streamCount; ++idxStream)
        {
            // prefer asm bitrate connect value...
            comptr<IHXStream> stream = player::GetStream(pPlayer, idxSource, idxStream);

            void*& bitrate = (*pBitrateValues)[idxStream];
            bitrate = reinterpret_cast<void*>(player::GetStreamASMBandwidth(stream));

            // if no asm bitrate use header 'avgbitrate' value - this may be wrong value for streamed surestream case
            if(0 == bitrate)
            {
                UINT32 val = 0;
                comptr<IHXValues> streamHeader = GetStreamHeader(idxStream, idxSource);
                HX_ASSERT(streamHeader);
                if(streamHeader)
                {
                    val::GetUINT32(streamHeader, "AvgBitrate", val);
                    bitrate = reinterpret_cast<void*>(val);
                }
                
            }
    
        }
    }
}


    





⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?