📄 sdpmdgen.cpp
字号:
mDesc += psz256; } SafeSprintf(psz256,256, "a=length:npt=%s%s", (const char*)npTime,pszEOL); mDesc += psz256; } else { // if we put ntp=0-, old sdpplin is gonna freak out. if (bUseOldSdp) { if (!bIsLive) { SafeSprintf(psz256, 256,"a=range:npt=0-0%s", pszEOL); mDesc += psz256; } SafeSprintf(psz256, 256,"a=length:npt=0%s", pszEOL); mDesc += psz256; } else { if (!bIsLive) { SafeSprintf(psz256, 256,"a=range:npt=0-%s", pszEOL); mDesc += psz256; } SafeSprintf(psz256, 256,"a=length:npt=0%s", pszEOL); mDesc += psz256; } } // a=rtpmap: if (!pszMimeLast) { goto bail; } SafeSprintf(psz256, 256, "a=rtpmap:%d %s", ulPayloadType, pszMimeLast); mDesc += psz256; if (SDPIsStaticPayload(ulPayloadType)) { if (!bSamplesPerSecondFound) { samplesPerSecond = SDPMapPayloadToSamplesPerSecond(ulPayloadType); if (samplesPerSecond) { bSamplesPerSecondFound = TRUE; } } if (!bChannelsFound) { nChannels = SDPMapPayloadToChannels(ulPayloadType); if (nChannels) { bChannelsFound = TRUE; } } } if (bSamplesPerSecondFound) { SafeSprintf(psz256, 256,"/%d", samplesPerSecond); mDesc += psz256; } else { mDesc += "/1000"; } if (bChannelsFound) { SafeSprintf(psz256, 256,"/%d", nChannels); mDesc += psz256; } mDesc += pszEOL; // a=fmtp if (pszFmtp) { SafeSprintf(psz256, 256, "a=fmtp:%d %s%s", ulPayloadType, pszFmtp, pszEOL); mDesc += psz256; HX_VECTOR_DELETE(pszFmtp); } else if (!bUseOldSdp) { // 3GPP requires an fmtp field in every SDP file // Include this only if the client supports interop SDP // and SDPData doesn't already contain a=fmtp: SafeSprintf(psz256, 256,"a=fmtp:%d ", ulPayloadType); if (!pszSDPData || !strstr(pszSDPData, psz256)) { SafeSprintf(psz256,256, "a=fmtp:%d %s", ulPayloadType, pszEOL); mDesc += psz256; } } // a=ptime if (bPtimeFound) { SafeSprintf(psz256,256, "a=ptime:%d%s", ptime, pszEOL); mDesc += psz256; } if (pszMimeType) { // a=mimetype:string;xxx NEW_FAST_TEMP_STR(pszTmpStr, 256, strlen(pszMimeType) + 128); SafeSprintf(pszTmpString, 256, "a=mimetype:string;\"%s\"%s", pszMimeType, pszEOL); mDesc += pszTmpString; DELETE_FAST_TEMP_STR(pszTmpStr); HX_VECTOR_DELETE(pszMimeType); } // 3GPP AnnexG values if (bFoundPreDecBufSize) { SafeSprintf(psz256, 256, "a=X-predecbufsize:%u%s", ulPreDecBufSize, pszEOL); mDesc += psz256; } if (bFoundPreDecBufPeriod) { SafeSprintf(psz256, 256, "a=X-initpredecbufperiod:%u%s", ulPreDecBufPeriod, pszEOL); mDesc += psz256; } if (bFoundPostDecBufPeriod) { SafeSprintf(psz256, 256, "a=X-initpostdecbufperiod:%u%s", ulPostDecBufPeriod, pszEOL); mDesc += psz256; } if (bFoundDecByteRate) { SafeSprintf(psz256, 256, "a=X-decbyterate:%u%s", ulDecByteRate, pszEOL); mDesc += psz256; } if (pszMimeFirst) { HX_VECTOR_DELETE(pszMimeFirst); } mDesc += streamAttributes; // expand SDPData if it's there... if (pszSDPData) { mDesc += pszSDPData; HX_VECTOR_DELETE(pszSDPData); pszSDPData = NULL; } } }bail: if (pszConnAddr) HX_VECTOR_DELETE(pszConnAddr); HX_RELEASE(pControlStringBuff); HX_RELEASE(pContentBase); HX_RELEASE(pQueryParams); if (mDesc.IsEmpty()) { pDescription = NULL; return HXR_FAIL; } IHXBuffer* pBuffer = NULL; m_pCCF->CreateInstance(CLSID_IHXBuffer, (void**)&pBuffer); pBuffer->Set((BYTE*)(const char*)mDesc, mDesc.GetLength()); pDescription = pBuffer; return HXR_OK;}BOOL SDPMediaDescGenerator::GetUseOldEOL() const{ return m_bUseOldEOL;}void SDPMediaDescGenerator::SetUseOldEOL(BOOL bUseOldEOL){ m_bUseOldEOL = bUseOldEOL;}/* * If there is no Duration in a file header and all streams have the same * duration, put it in a file header. * If live, it is 0. */HX_RESULTSDPMediaDescGenerator::SpecComplianceCheck(UINT16 nValues, IHXValues** ppValueArray){ HX_RESULT theErr; UINT32 ulDuration; // sanity check if (nValues < 3 || !ppValueArray) { HX_ASSERT(!"unexpected headers"); return HXR_UNEXPECTED; } theErr = ppValueArray[0]->GetPropertyULONG32("Duration", ulDuration); if (SUCCEEDED(theErr)) { return HXR_OK; } UINT32 ulTmp = 0; ulDuration = 0; /* find out if this is a live session */ theErr = ppValueArray[0]->GetPropertyULONG32("LiveStream", ulTmp); if (SUCCEEDED(theErr) && 1 == ulTmp) { ppValueArray[0]->SetPropertyULONG32("Duration", 0); return HXR_OK; } for (UINT16 i = 2; i < nValues; ++i) { theErr = ppValueArray[i]->GetPropertyULONG32("Duration", ulTmp); if (SUCCEEDED(theErr)) { // take the largest if (ulDuration < ulTmp) { ulDuration = ulTmp; } } } if (ulDuration) { ppValueArray[0]->SetPropertyULONG32("Duration", ulDuration); } return HXR_OK;}char*SDPMediaDescGenerator::EscapeBuffer(const char* pBuffer, UINT32 len){ UCHAR* buf; UINT32 newlen; UINT32 i = 0; UCHAR* tmp; UCHAR* newbuf; if(!pBuffer) { return 0; } buf = (UCHAR*)pBuffer; newlen = len; /* * We have to do this in two passes. One to alloc new mem to * copy into, and the next to do the escape/ copy. * First, count unescaped quotes and alloc. */ tmp = buf; while(i < len) { if(*tmp == '\"') { newlen++; } if(*tmp == '\\') { tmp++; i++; } tmp++; i++; } newbuf = new UCHAR[newlen]; tmp = newbuf; /* * Now copy into the new buffer and unescape as you go along. */ i = 0; while(i < len) { if(*buf == '\"') { *tmp++ = '\\'; } if(*buf == '\\') { *tmp++ = *buf++; i++; } *tmp++ = *buf++; i++; } /* * Set the buffer and return. */ return (char*)newbuf;}voidSDPMediaDescGenerator::RemoveASLine(char* pSDPData, UINT32 len){ /* * This method removes an extraneous b=AS line in place. */ if (!pSDPData) { return; } char* pWriteCursor = (char*)strstr((const char*)pSDPData, "b=AS"); if (!pWriteCursor) { return; } char* pReadCursor = pWriteCursor; UINT32 ulLength = (len - (pWriteCursor - pSDPData)); //Find the end of the field while((ulLength != 0) && (*pReadCursor != 0x0a) && (*pReadCursor != 0x0d) && (*pReadCursor != ' ')) { pReadCursor++; ulLength--; } //Skip over the end of the field while((ulLength > 0) && ((*pReadCursor == 0x0a) || (*pReadCursor == 0x0d) || (*pReadCursor == ' '))) { pReadCursor++; ulLength--; } if (!pReadCursor) { return; } if (ulLength == 0) { /* * There's no more data beyond the b=AS line. * Terminate the SDPData after previous line */ *pWriteCursor = '\0'; } else { memmove(pWriteCursor, pReadCursor, len - (pReadCursor - pSDPData)); }}BOOL SDPMediaDescGenerator::GetUseSessionGUID() const{ return m_bUseSessionGUID;}BOOL SDPMediaDescGenerator::GetUseAbsoluteURL() const{ return m_bUseAbsoluteURL;}void SDPMediaDescGenerator::SetUseSessionGUID(BOOL bOption){ m_bUseSessionGUID = bOption;}void SDPMediaDescGenerator::SetUseAbsoluteURL(BOOL bOption){ m_bUseAbsoluteURL= bOption;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -