ppffplin.cpp
来自「linux下的一款播放器」· C++ 代码 · 共 2,561 行 · 第 1/5 页
CPP
2,561 行
/* * Try to map payload number to sampling rate */ if (ulRTPFactor == 0) { ulRTPFactor = SDPMapPayloadToSamplesPerSecond(ulRTPPayload); } if (ulRTPFactor == 0) { IHXBuffer* pMimeType = NULL; pSrcHeader->GetPropertyCString("MimeType", pMimeType); /* * Try to map mime type to sampling rate */ if (pMimeType) { ulRTPFactor = SDPMapMimeToSamplesPerSecond(pMimeType); } HX_RELEASE(pMimeType); } } if (ulRTPFactor == 0) { ulRTPFactor = ulHXFactor; } } pSrcHeader->GetPropertyULONG32("Preroll", ulPreroll); if (ulPreroll == 0) { pSrcHeader->GetPropertyULONG32("Predata", ulPreroll); } if (ulPreroll == 0) { IHXBuffer* pSDPData = NULL; if (SUCCEEDED(pSrcHeader->GetPropertyCString("SDPData", pSDPData))) { char *pData = (char*) pSDPData->GetBuffer(); IHXValues *pValues = NULL; if (pData && SUCCEEDED(SDPParseChunk(pData, strlen(pData), pValues, m_pClassFactory, SDPCTX_Renderer))) { pValues->GetPropertyULONG32("Preroll", ulPreroll); } HX_RELEASE(pValues); } if (ulPreroll != 0) { pSrcHeader->SetPropertyULONG32("Preroll", ulPreroll); } HX_RELEASE(pSDPData); } /* * take care of interfaces */ CHXPtrArray* prgStreams = NULL; for (UINT32 j = 0; j < m_pInterfaceMgr->m_ulNumInterfaces; ++j) { // only one interface to worry about... CPurePlaySource* pSrc = new CPurePlaySource(this, pSrcHeader, i, ulRTPFactor, ulHXFactor, m_bRMPresentation); pSrc->AddRef(); theErr = pSrc->Init(m_pContext, (char*)pSrcAddr->GetBuffer(), m_pInterfaceMgr->m_pulInterfaces[j], HX_SAFEUINT16(ulPort)); if (theErr != HXR_OK) goto bail; // get an array for this interface prgStreams = m_pInterfaceMgr->GetSession(j); if (!prgStreams) { HX_ASSERT(0 == i); prgStreams = new CHXPtrArray(); } // set a source for this interface prgStreams->SetAtGrow(i, pSrc); m_pInterfaceMgr->SetSession(j, prgStreams); } pSrcHeader->Release(); pSrcAddr->Release(); }bail: /* * We no longer need the file object so release it on CloseDone */ if (m_pFileObject) { m_pFileObject->Close(); HX_RELEASE(m_pFileObject); } HX_VECTOR_DELETE(pulSubscriptionBW); HX_RELEASE(pBandwidth); // release ppRealHeaders too if (NULL != ppRealHeaders) { for (int i = 0; i < (int)ulNumStreams; i++) { HX_RELEASE(ppRealHeaders[i]); } HX_VECTOR_DELETE(ppRealHeaders); } if (NULL != ppHeaders) { for (int i = 0; i < (int)cHeaders; i++) { // we didn't AddRef() those HX_RELEASE(ppHeaders[i]); } HX_VECTOR_DELETE(ppHeaders); } HX_RELEASE(pFileAddr); if ((NO_MULTICAST == m_tryUnicast) || (theErr != HXR_OK)) { Close(); theErr = HXR_CLOSED; } else { /* * Start listening */ CHXPtrArray* prgStreams = NULL; CPurePlaySource* pSrc = NULL; for (UINT32 j = 0; j < m_pInterfaceMgr->m_ulNumInterfaces; j++) { prgStreams =m_pInterfaceMgr->GetSession(j); for (i = 0; i < prgStreams->GetSize(); i++) { pSrc = (CPurePlaySource*)prgStreams->GetAt(i); pSrc->Begin(); } } } m_state = PendingFileHeader; if (theErr != HXR_CLOSED) { return MakeHeader(theErr); } return HXR_OK;}BOOLCPurePlayFileFormat::GetStreamCountNoTrust(IHXValues** ppHeaders, UINT16 unNumHeader, REF(ULONG32) ulNumStreams) { HX_ASSERT(NULL != ppHeaders); ULONG32 ulID; BOOL rgFound[256]; memset(rgFound, 0, 256); for (UINT16 i = 0; i < unNumHeader; i++) { HX_ASSERT(ppHeaders[i] != NULL); IHXValues* pSrcHeader; pSrcHeader = ppHeaders[i]; pSrcHeader->AddRef(); // "StreamId" is the field that ppfobj.cpp puts for a group of // streams if (HXR_OK == pSrcHeader->GetPropertyULONG32("StreamId", ulID)) { if (!rgFound[ulID]) { rgFound[ulID] = TRUE; ulNumStreams++; } } else { // OK, trust the "StreamCount". This is not a SDP file generated // by pplyfobj.cpp ulNumStreams = 0; HX_RELEASE(pSrcHeader); return FALSE; } HX_RELEASE(pSrcHeader); } return TRUE;}BOOL CPurePlayFileFormat::DetermineIfRMPresentation( IHXValues* pFileHeader, IHXValues** ppStrmHeaders, ULONG32 ulNumStreams){ BOOL bIsRMPresentation = FALSE; if (pFileHeader && ppStrmHeaders && ulNumStreams) { IHXValues* pStrmHdr = NULL; IHXBuffer* pASMRuleBook = NULL; IHXBuffer* pMimeType = NULL; ULONG32 ulRTPPayload = RTP_PAYLOAD_RTSP + 1; BOOL bIsRMStream = FALSE; ULONG32 ulIdx; bIsRMPresentation = TRUE; for (ulIdx = 0; bIsRMPresentation && (ulIdx < ulNumStreams); ulIdx++) { pStrmHdr = ppStrmHeaders[ulIdx]; bIsRMStream = FALSE; if (pStrmHdr) { pStrmHdr->GetPropertyULONG32(PROP_RTP_PAYLOAD, ulRTPPayload); if (ulRTPPayload == RTP_PAYLOAD_RTSP) { bIsRMStream = TRUE; } ulRTPPayload = RTP_PAYLOAD_RTSP + 1; if (bIsRMStream) { bIsRMStream = FALSE; pStrmHdr->GetPropertyCString("ASMRuleBook", pASMRuleBook); if (pASMRuleBook) { bIsRMStream = TRUE; } } HX_RELEASE(pASMRuleBook); if (bIsRMStream) { bIsRMStream = FALSE; pStrmHdr->GetPropertyCString("MimeType", pMimeType); if (pMimeType) { if (strstr((const char*) pMimeType->GetBuffer(), HX_COMMON_MIME_TYPE_FRAGMENT)) { bIsRMStream = TRUE; } } } HX_RELEASE(pMimeType); } bIsRMPresentation = (bIsRMStream && bIsRMPresentation); } } return bIsRMPresentation;}BOOLCPurePlayFileFormat::GetSubscriptionBW(IHXValues* pFileHeader, IHXValues** ppStrmHeaders, UINT16 unNumStrmHeaders, REF(UINT32*) pulSubscriptionBW, UINT32 ulNumStreams, IHXBuffer* pBandwidth) { HX_ASSERT(pFileHeader); HX_ASSERT(ppStrmHeaders); HX_ASSERT(unNumStrmHeaders >= 1); HX_ASSERT(pulSubscriptionBW); HX_ASSERT(ulNumStreams >= 1); HX_ASSERT(pBandwidth); pFileHeader->AddRef(); pBandwidth->AddRef(); IHXBuffer* pRuleBuf = NULL; if (HXR_OK != pFileHeader->GetPropertyCString("ASMRuleBook", pRuleBuf)) { // OK, this is a single stream presentation. Take an ASMRuleBook from // any of stream headers (they are all the same), and use it to decide // which stream header to use depending on bit rate HX_ASSERT(1 == ulNumStreams); // get ASMRuleBook HX_ASSERT(NULL != ppStrmHeaders[0]); IHXValues* pHeader = ppStrmHeaders[0]; pHeader->AddRef(); if (HXR_OK == pHeader->GetPropertyCString("ASMRuleBook", pRuleBuf)) { ASMRuleBook rules((char*)pRuleBuf->GetBuffer()); HX_RELEASE(pRuleBuf); IHXBuffer* pBuffer = NULL; UINT16 unRules; unRules = rules.GetNumRules(); // get subscriptions for this bandwidth BOOL bSubInfo[256]; UINT16 unRuleNum; IHXValues* pValues; pValues = new CHXHeader(); pValues->AddRef(); pValues->SetPropertyCString("Bandwidth", pBandwidth); rules.GetSubscription(bSubInfo, pValues); HX_RELEASE(pValues); // get a rule number that we are interested in int y; for (y = 0; y < (int)unRules; y++) { if (TRUE == bSubInfo[y]) { IHXBuffer* pBw = 0; unRuleNum = y; // make sure AverageBandwidth != 0 rules.GetProperties(y, pValues); if (HXR_OK == pValues->GetPropertyCString("AverageBandwidth", pBw)) { pulSubscriptionBW[0] += atol((const char*)pBw->GetBuffer()); HX_RELEASE(pBw); } else { // TimeStampDelivery only stream pulSubscriptionBW[0] = 0; } HX_RELEASE(pValues); } } } else { // There is no ASMRuleBook at all... // This should never happen. HX_RELEASE(pFileHeader); HX_RELEASE(pBandwidth); HX_RELEASE(pHeader); HX_ASSERT(FALSE); return FALSE; } HX_RELEASE(pHeader); } else // for if (HXR_OK == m_pFileHeader->GetPropertyCString("ASMRuleBook", pRuleBuf)) { // this is a multiple stream presentation. // take ASMRuleBook for a file and figure out BW to use for // each stream ASMRuleBook rules((char*)pRuleBuf->GetBuffer()); HX_RELEASE(pRuleBuf); IHXBuffer* pBuffer = NULL; UINT16 unRules; unRules = rules.GetNumRules(); // get subscriptions for this bandwidth BOOL bSubInfo[256]; UINT16 unRuleNum; IHXValues* pValues; pValues = new CHXHeader(); pValues->AddRef(); pValues->SetPropertyCString("Bandwidth", pBandwidth); rules.GetSubscription(bSubInfo, pValues); HX_RELEASE(pValues); // get a rule number that we are interested in // Assuming there is only one TRUE int y; for (y = 0; y < (int)unRules; y++) { if (TRUE == bSubInfo[y]) { // there should be only one unRuleNum = y; break; } }#ifdef BW_BASED // unRuleNum is the rule number that we are interested in m_lRuleNumber = (INT32)unRuleNum; #endif // Get a BW for each stream rules.GetProperties((int)unRuleNum, pValues); for (int i = 0; i < (int)ulNumStreams; i++) { char rgStreamBW[32]; /* Flawfinder: ignore */ sprintf(rgStreamBW, "Stream%dBandwidth", i); /* Flawfinder: ignore */ if (HXR_OK == pValues->GetPropertyCString((const char*)rgStreamBW, pBuffer)) { pulSubscriptionBW[i] = (UINT32)atol((const char*)pBuffer->GetBuffer()); HX_RELEASE(pBuffer); } } HX_RELEASE(pValues); } HX_RELEASE(pFileHeader); HX_RELEASE(pBandwidth); return TRUE;}BOOLCPurePlayFileFormat::GetRightHeaders(REF(IHXValues**) ppRealHeaders, // out UINT32 ulNumStreams, IHXValues** ppHeaders, UINT32 cHeaders, UINT32* pulSubscriptionBW){ HX_ASSERT(ulNumStreams >= 1); HX_ASSERT(ppHeaders); HX_ASSERT(pulSubscriptionBW); ppRealHeaders = new IHXValues*[ulNumStreams]; memset(ppRealHeaders, NULL, sizeof(IHXValues*) * ulNumStreams); for (int i = 0; i < (int)ulNumStreams; i++) { ULONG32 ulID = 0; ULONG32 ulBW = 0;; BOOL bFound = FALSE; for (int j = 0; j < (int)cHeaders; j++) { HX_ASSERT(NULL != ppHeaders[j]); IHXValues* pSrcH; pSrcH = ppHeaders[j]; pSrcH->AddRef(); if ((HXR_OK == pSrcH->GetPropertyULONG32("AvgBitRate", ulBW)) && (ulBW == pulSubscriptionBW[i])) { // this one has the right BW, how about stream number? if ((HXR_OK == pSrcH->GetPropertyULONG32("StreamId", ulID)) && ((int)ulID == i)) {#ifdef BW_BASED // if this is more than one stream presentation, // we have to make sure the rule number. // if "RuleNumber" does not exist, this is from the old // plugin, then, it should ignore this check. UINT32 ulRuleNum = 0; if ((-1 == m_lRuleNumber) || (HXR_OK != pSrcH->GetPropertyULONG32("RuleNumber", ulRuleNum)) || ((INT32)ulRuleNum == m_lRuleNumber)) {#endif bFound = TRUE; // This is the right heaader, ppRealHeaders[i] = pSrcH; ppRealHeaders[i]->AddRef(); HX_RELEASE(pSrcH); break; // we found for this stream, go to next one#ifdef BW_BASED }#endif } }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?