⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 oggfformat.cpp

📁 linux下的一款播放器
💻 CPP
📖 第 1 页 / 共 4 页
字号:
                    if (HXR_OK == res)                    {                        if ((pCodecInfo->Type() == ctVorbis) ||                            (pCodecInfo->Type() == ctSpeex))                        {                            uGroupAudioCount++;                        }                        else if (pCodecInfo->Type() == ctTheora)                        {                            uGroupVideoCount++;                        }                    }                }            }            if (HXR_OK == res)            {                DPRINTF(D_OGG_FF, ("COFF::gSTFFI : group %u audio %u video %u\n",                                    i, uGroupAudioCount, uGroupVideoCount));                                if (uGroupAudioCount > uNumAudioStreams)                {                    uNumAudioStreams = uGroupAudioCount;                }                                if (uGroupVideoCount > uNumVideoStreams)                {                    uNumVideoStreams = uGroupVideoCount;                }            }        }    }    return res;}HX_RESULT COggFileFormat::getStreamTypeCountFromStreamInfo(UINT16& uNumAudioStreams,                                                UINT16& uNumVideoStreams) const{    HX_RESULT res = HXR_OK;    uNumAudioStreams = 0;    uNumVideoStreams = 0;    for (UINT16 i = 0; ((HXR_OK == res) &&                        (i < m_streamInfoStrategy.StreamCount())); i++)    {        int serialNum;        res = m_streamInfoStrategy.GetStreamSerialNum(i, serialNum);        if (HXR_OK == res)        {            const COggCodecInfo* pCodecInfo = NULL;                        res = m_streamInfoStrategy.GetCodecInfo(serialNum, pCodecInfo);                        if (HXR_OK == res)            {                if ((pCodecInfo->Type() == ctVorbis) ||                    (pCodecInfo->Type() == ctSpeex))                {                    uNumAudioStreams++;                }                else if (pCodecInfo->Type() == ctTheora)                {                    uNumVideoStreams++;                }            }        }    }    return res;}HX_RESULT COggFileFormat::setupStreamHandlerFromGroupInfo(UINT32 uGroupIndex){    const COggGroupInfo* pGroupInfo = NULL;        HX_RESULT res = m_fileInfo.GetGroupInfo(uGroupIndex, pGroupInfo);    if (HXR_OK == res)    {        for (UINT32 i = 0; ((HXR_OK == res) &&                            (i < pGroupInfo->StreamCount())); i++)        {            int serialNum;            const COggCodecInfo* pCodecInfo = NULL;                        res = pGroupInfo->GetStreamSerialNum(i, serialNum);                        if (HXR_OK == res)            {                res = pGroupInfo->GetCodecInfo(serialNum, pCodecInfo);            }                        if (HXR_OK == res)            {                res = m_streamHdlr.AddCodecInfo(serialNum, pCodecInfo);            }        }        if (HXR_OK == res)        {            m_uCurrentGroup = uGroupIndex;        }    }    return res;}HX_RESULT COggFileFormat::setupStreamHandlerFromStreamInfo(){    HX_RESULT res = HXR_OK;    for (UINT32 i = 0; ((HXR_OK == res) &&                        (i < m_streamInfoStrategy.StreamCount())); i++)    {        int serialNum;        const COggCodecInfo* pCodecInfo = NULL;                res = m_streamInfoStrategy.GetStreamSerialNum(i, serialNum);                    if (HXR_OK == res)        {            res = m_streamInfoStrategy.GetCodecInfo(serialNum, pCodecInfo);        }                    if (HXR_OK == res)        {            COggCodecInfo* pCodecInfo2 = pCodecInfo->Clone();            if (pCodecInfo2)            {                res = pCodecInfo2->SetStartTimestamp(m_liveNextGroupStartTime);                                if (HXR_OK == res)                {                    res = m_streamHdlr.AddCodecInfo(serialNum, pCodecInfo2);                }            }            HX_DELETE(pCodecInfo2);        }    }    return res;}HX_RESULT COggFileFormat::handleFileGroupChange(ogg_page* pPage){    HX_RESULT res = HXR_OK;    UINT32 uNextGroup = m_uCurrentGroup + 1;    if (uNextGroup < m_fileInfo.GroupCount())    {        // The current group was not the last group.        const COggGroupInfo* pGroupInfo = NULL;                // Get the group info for the next group        res = m_fileInfo.GetGroupInfo(uNextGroup, pGroupInfo);                if (HXR_OK == res)        {            const COggCodecInfo* pCodecInfo = NULL;                        // See if there is any codec info for the serial number on            // this page.            res = pGroupInfo->GetCodecInfo(ogg_page_serialno(pPage),                                           pCodecInfo);                        if (HXR_OK == res)            {                // This page is part of the next group.                                 // Tell the stream handler that the current                // group has ended.                res = m_streamHdlr.OnEndOfGroup();            }                        if (HXR_OK == res)            {                // setup the stream handler with the info for                 // the next group                res = setupStreamHandlerFromGroupInfo(uNextGroup);            }                        if (HXR_OK == res)            {                // Send this page to the appropriate stream                                COggStream* pStream =                     m_streamHdlr.GetStream(ogg_page_serialno(pPage));                                if (pStream)                {                    res = pStream->OnPage(pPage);                }                else                {                    res = HXR_UNEXPECTED;                }            }        }    }    else    {        // The current group is the last group in the file        HX_ASSERT(FALSE);    }    return res;}HX_RESULT COggFileFormat::createAndSendFileHeader(){        HX_RESULT res = HXR_OK;    HX_VECTOR_DELETE(m_pGetPacketPending);    m_pGetPacketPending = new BOOL[m_streamHdlr.StreamCount()];        if (m_pGetPacketPending)    {        memset(m_pGetPacketPending, 0,                sizeof(BOOL) * m_streamHdlr.StreamCount());    }    else    {        res = HXR_OUTOFMEMORY;    }    if (HXR_OK == res)    {        IHXValues* pFileHdr = NULL;        res = m_streamHdlr.CreateFileHeader(pFileHdr);        if (HXR_OK == res)        {            if (m_bIsLive)            {                pFileHdr->SetPropertyULONG32("LiveStream", 1);            }            changeState(Ready);            m_pResponse->FileHeaderReady(HX_STATUS_OK, pFileHdr);        }        HX_RELEASE(pFileHdr);    }    return res;}HX_RESULT COggFileFormat::dispatchPendingRequests(){    HX_RESULT res = HXR_OK;    DPRINTF(D_OGG_FF,             ("COFF::dPR()\n"));    if (m_pResponse && m_pGetPacketPending)    {        if (!m_bInDispatchPendingRequest)        {            BOOL bDone = FALSE;            m_bInDispatchPendingRequest = TRUE;            while (!bDone)            {                UINT16 uNextStreamID;                // Assume this will be the last loop                bDone = TRUE;                res = m_streamHdlr.NextPacketStreamID(uNextStreamID);                if ((HXR_OK == res) && m_pGetPacketPending[uNextStreamID])                {                    // We got the streamID for the next packet                    // and we have a GetPacket() request pending.                    IHXPacket* pPkt = NULL;                                        // Get the next packet                    res = m_streamHdlr.GetNextPacket(pPkt);                                        if (HXR_OK == res)                    {                        m_pGetPacketPending[uNextStreamID] = FALSE;                                                DPRINTF(D_OGG_FF,                                 ("COFF::dPR() : PacketReady(%u, %u)\n",                                 pPkt->GetStreamNumber(),                                 pPkt->GetTime()));                        m_pResponse->PacketReady(HXR_OK, pPkt);                        HX_RELEASE(pPkt);                                                // We dispatched a packet so                        // we should loop again                        bDone = FALSE;                    }                }            }                    if (HXR_STREAM_DONE == res)            {                UINT32 uStreamCount = m_streamHdlr.StreamCount();                // All the streams are done.                // Handle any pending GetPacket() requests                for (UINT32 i = 0; i < uStreamCount; i++)                {                    if (m_pGetPacketPending[i])                    {                        m_pGetPacketPending[i] = FALSE;                        DPRINTF(D_OGG_FF,                                 ("COFF::dPR() : StreamDone(%u)\n",                                 i));                        m_pResponse->StreamDone(i);                    }                }                                res = HXR_OK;            }            m_bInDispatchPendingRequest = FALSE;        }        else        {            // We are already in a dispatchPendingRequests() call            // so we don't want to do anything here            DPRINTF(D_OGG_FF,                     ("COFF::dPR() : deferred\n", res));        }    }    else    {        res = HXR_FAILED;    }    DPRINTF(D_OGG_FF,             ("COFF::dPR() : res %08x\n", res));    return res;}HX_RESULT COggFileFormat::cachePage(ogg_page* pPage){    HX_RESULT res = HXR_INVALID_PARAMETER;    if (pPage)    {        ogg_page* pNewPage = OggUtil::CopyPage(pPage);                if (pNewPage && m_pageCache.AddTail(pNewPage))        {            res = HXR_OK;        }        else        {            OggUtil::DestroyPage(pNewPage);            res = HXR_OUTOFMEMORY;        }    }    return res;}void COggFileFormat::flushPageCache(){    while(!m_pageCache.IsEmpty())    {        ogg_page* pPage = (ogg_page*)m_pageCache.RemoveHead();        OggUtil::DestroyPage(pPage);    }}HX_RESULT COggFileFormat::sendCachedPagesToStreamHandler(){    HX_RESULT res = HXR_OK;    while(!m_pageCache.IsEmpty() && (HXR_OK == res))    {        ogg_page* pPage = (ogg_page*)m_pageCache.RemoveHead();        if (pPage)        {            int serialNum = ogg_page_serialno(pPage);            COggStream* pStream = m_streamHdlr.GetStream(serialNum);            if (pStream)            {                res = pStream->OnPage(pPage);            }            else            {                res = HXR_UNEXPECTED;            }            OggUtil::DestroyPage(pPage);        }        else        {            res = HXR_UNEXPECTED;        }    }    return res;}

⌨️ 快捷键说明

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