OSCL_EXPORT_REF void* _oscl_audit_realloc(void* in_ptr, size_t nBytes, OsclAuditCB & auditCB, const char * file_name, const int line_num) { if (nBytes > 0) { //allocate new space void* ptr = _oscl_audit_malloc(nBytes, auditCB, file_name, line_num); if (in_ptr && ptr) { //copy current contents to new space. //note: the getSize call leaves if it's a bad pointer. //just propagate the leave to the caller. if (MM_Audit_Imp::getSize(in_ptr) > MM_Audit_Imp::getSize(ptr)) { oscl_memcpy(ptr, in_ptr, MM_Audit_Imp::getSize(ptr)); } else { oscl_memcpy(ptr, in_ptr, MM_Audit_Imp::getSize(in_ptr)); } //free original space. _oscl_audit_free(in_ptr); } else if (in_ptr) { return in_ptr; } //note: return pointer can be null. return ptr; } else { _oscl_audit_free(in_ptr); return NULL; } }
bool AVCSampleEntry::createDecoderSpecificInfo(MP4_FF_FILE *fp) { uint32 numSPS = getNumSequenceParamSets(); uint32 numPPS = getNumPictureParamSets(); uint32 totalSPSLen = getTotalSeqParameterSetLength(); uint32 totalPPSLen = getTotalPictureParameterSetLength(); uint32 len = (numSPS * 2) + (numPPS * 2) + totalSPSLen + totalPPSLen; if ((int32)len > 0) { PV_MP4_FF_NEW(fp->auditCB, DecoderSpecificInfo, (fp, true), _decoderSpecificInfo); uint8* info = (uint8*)(oscl_malloc(sizeof(uint8) * len)); if (!info) return false; // malloc failed (unlikely) uint8* destPtr = info; if (numSPS > 0) { for (uint32 i = 0; i < numSPS; i++) { uint16 len = 0; uint8* ptr = NULL; if (getSequenceParamSet(i, len, ptr) == false) { OSCL_FREE(info); return false; } oscl_memcpy(destPtr, &len, sizeof(uint16)); destPtr += sizeof(uint16); oscl_memcpy(destPtr, ptr, len); destPtr += len; } } if (numPPS > 0) { for (uint32 i = 0; i < numPPS; i++) { uint16 len = 0; uint8* ptr = NULL; if (getPictureParamSet(i, len, ptr) == false) { OSCL_FREE(info); return false; } oscl_memcpy(destPtr, &len, sizeof(uint16)); destPtr += sizeof(uint16); oscl_memcpy(destPtr, ptr, len); destPtr += len; } } _decoderSpecificInfo->setInfoSize(len); _decoderSpecificInfo->setInfo(info); } return true; }
// given sample is added to interleave buffer and // sample parameters stored in parameter vectors bool PVA_FF_InterLeaveBuffer::addSampleToInterLeaveBuffer( Oscl_Vector < OsclMemoryFragment, OsclMemAllocator > & fragmentList, uint32 size, uint32 ts, uint8 flags, int32 index) { // temporary variables uint32 bytesWritten = 0; uint32 length = 0; uint32 ii = 0; OsclBinIStreamBigEndian stream; if (_interLeaveBuffer != NULL) { uint8* currPtr = _interLeaveBuffer + _currInterLeaveBufferSize; if (checkInterLeaveBufferSpace(size)) { if (_mediaType == MEDIA_TYPE_VISUAL && _codecType == CODEC_TYPE_AVC_VIDEO) { for (ii = 0; ii < fragmentList.size(); ii++) { // read NAL length in Big Endian format stream.Attach((OsclAny*) &(fragmentList[ii].len), 4); stream >> length; // compose nal length in two bytes oscl_memcpy((OsclAny*)(currPtr + bytesWritten), ((uint8*)&length), 4); // write NAL uint oscl_memcpy((OsclAny*)(currPtr + bytesWritten + 4), (OsclAny*)fragmentList[ii].ptr, fragmentList[ii].len); bytesWritten += (fragmentList[ii].len + 4); } } else { for (ii = 0; ii < fragmentList.size(); ii++) { oscl_memcpy(currPtr + bytesWritten, fragmentList[ii].ptr, fragmentList[ii].len); bytesWritten += fragmentList[ii].len; } } _currInterLeaveBufferSize += size; _lastInterLeaveBufferTS = ts; //Store meta data params _pTimeStampVec->push_back(ts); _pSampleSizeVec->push_back(size); _pSampleFlagsVec->push_back(flags); _pIndexVec->push_back(index); return true; }
Word16 dtx_enc_reset(dtx_encState *st) { Word16 i; if (st == (dtx_encState *) NULL) { return(-1); } st->hist_ptr = 0; st->log_en_index = 0; st->init_lsf_vq_index = 0; st->lsp_index[0] = 0; st->lsp_index[1] = 0; st->lsp_index[2] = 0; /* Init lsp_hist[] */ for (i = 0; i < DTX_HIST_SIZE; i++) { oscl_memcpy(&st->lsp_hist[i * M], lsp_init_data, M*sizeof(Word16)); } /* Reset energy history */ oscl_memset(st->log_en_hist, 0, sizeof(Word16)*M); st->dtxHangoverCount = DTX_HANG_CONST; st->decAnaElapsedCount = 32767; return(1); }
void TSC_324m::Tsc_UII_Alphanumeric(const uint8* str, uint16 str_len) { S_ControlMsgHeader infHeader; PS_UserInputIndication pUserInputIndication; PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "TSC_324m:Tsc_UII_Alphanumeric - len(%d)", str_len)); // Allocate the UII structure pUserInputIndication = (PS_UserInputIndication)OSCL_DEFAULT_MALLOC(sizeof(S_UserInputIndication)); // Fill in the 'signal' pUserInputIndication->index = 1; /* alphanumeric */ pUserInputIndication->alphanumeric = (PS_int8STRING) OSCL_DEFAULT_MALLOC(sizeof(S_int8STRING)); pUserInputIndication->alphanumeric->size = str_len; pUserInputIndication->alphanumeric->data = (uint8*) OSCL_DEFAULT_MALLOC(str_len * sizeof(uint8)); oscl_memcpy(pUserInputIndication->alphanumeric->data, str, str_len); // Send the message Tsc_SendDataSet(&infHeader, H245_PRIMITIVE, E_PtvId_Idc_Ui, 0, 0, (uint8*)pUserInputIndication, sizeof(S_UserInputIndication)); iH245->DispatchControlMessage(&infHeader); Delete_UserInputIndication(pUserInputIndication); OSCL_DEFAULT_FREE(pUserInputIndication); return; }
Bool AvcDecoder_OMX::FlushOutput_OMX(uint8* aOutBuffer, uint32* aOutputLength, OMX_TICKS* aOutTimestamp, uint32 OldWidth, uint32 OldHeight) { AVCFrameIO Output; AVCDec_Status Status; int32 Index, Release, FrameSize; uint32 OldFrameSize = ((OldWidth + 15) & (~15)) * ((OldHeight + 15) & (~15)); ////char szLog[300] = {0}; Output.YCbCr[0] = Output.YCbCr[1] = Output.YCbCr[2] = NULL; // sprintf(szLog, "FlushOutput_OMX step 1"); ////__android_log_write(ANDROID_LOG_ERROR, "up_audio_play", szLog); Status = PVAVCDecGetOutput(&(AvcHandle), &Index, &Release, &Output); //sprintf(szLog, "*****************get output status=%d******************",Status); ////__android_log_write(ANDROID_LOG_ERROR, "up_audio_play", szLog); if (Status == AVCDEC_FAIL) { return 0; } *aOutTimestamp = DisplayTimestampArray[Index]; *aOutputLength = 0; // init to 0 if (Output.YCbCr[0]) { // sprintf(szLog, "FlushOutput_OMX step 2"); // //__android_log_write(ANDROID_LOG_ERROR, "up_audio_play", szLog); FrameSize = Output.pitch * Output.height; // it should not happen that the frame size is smaller than available buffer size, but check just in case if (FrameSize <= OldFrameSize) { *aOutputLength = (Output.pitch * Output.height * 3) >> 1; oscl_memcpy(aOutBuffer, Output.YCbCr[0], FrameSize); oscl_memcpy(aOutBuffer + FrameSize, Output.YCbCr[1], FrameSize >> 2); oscl_memcpy(aOutBuffer + FrameSize + FrameSize / 4, Output.YCbCr[2], FrameSize >> 2); }
int32 CDecoderVideo::GetVideoHeader(int32 aLayer, uint8* aBuf, int32 aMaxSize) { OSCL_UNUSED_ARG(aLayer); int32 count = 0; char my_sc[4]; uint8 *tmp_bs = aBuf; oscl_memcpy(my_sc, tmp_bs, 4); my_sc[3] &= 0xf0; oscl_memcpy(VOSH_START_CODE1, aBuf, 4); return count ; if (aMaxSize >= 4) { /*__android_log_write(ANDROID_LOG_DEBUG, "CDecoderVideo::GetVideoHeader", "passo 1"); if (oscl_memcmp(my_sc, VOSH_START_CODE1, 4) && oscl_memcmp(my_sc, VO_START_CODE1, 4)) {__android_log_write(ANDROID_LOG_DEBUG, "CDecoderVideo::GetVideoHeader", "passo 2"); count = 0; } else {__android_log_write(ANDROID_LOG_DEBUG, "CDecoderVideo::GetVideoHeader", "passo 3");*/ count = 0; bool bShortHeader=false; while (oscl_memcmp(tmp_bs + count, VOP_START_CODE1, 4)) {__android_log_write(ANDROID_LOG_DEBUG, "CDecoderVideo::GetVideoHeader", "passo 4"); count++; if (count > 1000) {__android_log_write(ANDROID_LOG_DEBUG, "CDecoderVideo::GetVideoHeader", "passo 5"); bShortHeader = true; break; } } if (bShortHeader == true) {__android_log_write(ANDROID_LOG_DEBUG, "CDecoderVideo::GetVideoHeader", "passo 6"); count = 0; while (oscl_memcmp(tmp_bs + count, H263_START_CODE1, 3)) {__android_log_write(ANDROID_LOG_DEBUG, "CDecoderVideo::GetVideoHeader", "passo 7"); count++; } } //} } return count; }
void PVA_FF_DecoderSpecificInfo::addInfo(uint8 *info, uint32 size) { _infoSize = size; _pinfo = (uint8 *)oscl_malloc(_infoSize); oscl_memcpy(_pinfo, info, _infoSize); }
// Read in byte data and take most significant byte first bool AtomUtils::readByteData(uint8 *&buf, uint32 length, uint8 *data) { oscl_memcpy(data, buf, length); buf += length; return true; }
OSCL_EXPORT_REF void PVMp4FFComposerPort::setParametersSync(PvmiMIOSession session, PvmiKvp* parameters, int num_elements, PvmiKvp*& ret_kvp) { OSCL_UNUSED_ARG(session); ret_kvp = NULL; if (iFormat == PVMF_MIME_H264_VIDEO_MP4) { //this code is specific to H264 file format for (int32 i = 0; i < num_elements; i++)//assuming the memory is allocated for key { if (pv_mime_strcmp(parameters->key, VIDEO_AVC_OUTPUT_SPS_CUR_VALUE) == 0) { memfrag_sps = (OsclMemoryFragment *)(OSCL_MALLOC(sizeof(OsclMemoryFragment))); memfrag_sps->len = parameters->capacity; memfrag_sps->ptr = (uint8*)(OSCL_MALLOC(sizeof(uint8) * memfrag_sps->len)); oscl_memcpy((void*)memfrag_sps->ptr, (const void*)parameters->value.key_specific_value, memfrag_sps->len); iNode->memvector_sps.push_back(memfrag_sps); //storing SPS in the vector iNode->iNum_SPS_Set += 1; } if (pv_mime_strcmp(parameters->key, VIDEO_AVC_OUTPUT_PPS_CUR_VALUE) == 0) { memfrag_pps = (OsclMemoryFragment *)(OSCL_MALLOC(sizeof(OsclMemoryFragment))); memfrag_pps->len = parameters->capacity; memfrag_pps->ptr = (uint8*)(OSCL_MALLOC(sizeof(uint8) * memfrag_pps->len)); oscl_memcpy((void*)memfrag_pps->ptr, (const void*)parameters->value.key_specific_value, memfrag_pps->len); iNode->memvector_pps.push_back(memfrag_pps); //storing PPS in the vector iNode->iNum_PPS_Set += 1; } } } if (iFormat == PVMF_MIME_3GPP_TIMEDTEXT) { for (int32 i = 0; i < num_elements; i++)//assuming the memory is allocated for keys { if (pv_mime_strcmp(parameters->key, TIMED_TEXT_OUTPUT_CONFIG_INFO_CUR_VALUE) == 0) { PVA_FF_TextSampleDescInfo* ptempDecoderinfo = OSCL_STATIC_CAST(PVA_FF_TextSampleDescInfo*, parameters->value.key_specific_value); PVA_FF_TextSampleDescInfo* pDecoderinfo = OSCL_NEW(PVA_FF_TextSampleDescInfo, (*ptempDecoderinfo)); iNode->textdecodervector.push_back(pDecoderinfo); } } }
// Constructor PVA_FF_DecoderSpecificInfo::PVA_FF_DecoderSpecificInfo(PVA_FF_TextSampleDescInfo *pdata, uint32 size) : PVA_FF_BaseDescriptor(0x05) { _infoSize = size; _pinfo = (uint8 *)OSCL_MALLOC(_infoSize); oscl_memcpy(_pinfo, pdata, _infoSize); recomputeSize(); }
OSCL_EXPORT_REF PVMFStatus PvmfPortBaseImpl::GetStats(PvmfPortBaseImplStats& aStats) { #if PVMF_PORT_BASE_IMPL_STATS oscl_memcpy(&aStats, &iStats, sizeof(PvmfPortBaseImplStats)); return PVMFSuccess; #else OSCL_UNUSED_ARG(aStats); return PVMFErrNotSupported; #endif }
bool PVAviFileStreamlist::GetHandlerType(uint8* aHdlr, uint32& aSize) { if (aSize < CHUNK_SIZE) { return false; } oscl_memcpy(aHdlr, iStreamHdr.iStreamHandler, CHUNK_SIZE); aSize = CHUNK_SIZE; return true; }
void ML::MsgLoopReqSend(PS_MlRequestType pLoop_Type) { S_MaintenanceLoopRequest maintenanceLoopRequest ; S_H245Msg h245Msg ; oscl_memcpy((int8*)&maintenanceLoopRequest.mlRequestType, (int8*)pLoop_Type, sizeof(S_MlRequestType)) ; h245Msg.Type1 = H245_MSG_REQ ; h245Msg.Type2 = MSGTYP_ML_REQ ; h245Msg.pData = (uint8*) & maintenanceLoopRequest ; MessageSend(&h245Msg) ; }
void RTPPacket::SetMBit(const bool flag) { BufferFragment * hdrFrag = GetRTPHeader(); uint8 tmpOctet = *(((uint8 *) hdrFrag->ptr) + 1); if (flag && hdrFrag->ptr) { tmpOctet |= RTP_MBIT_MASK; } else { tmpOctet &= (~RTP_MBIT_MASK); } oscl_memcpy(((uint8 *) hdrFrag->ptr) + 1, &tmpOctet, sizeof(uint8)); }
void PVMFBufferDataSource::TimeoutOccurred(int32 timerID, int32 timeoutInfo) { OSCL_UNUSED_ARG(timerID); unsigned bytesToSend = timeoutInfo; if (bytesToSend <= 0) return; if (!IsConnected()) return; // Create new media data buffer OsclSharedPtr<PVMFMediaDataImpl> mediaDataImpl = iMediaDataAlloc->allocate(bytesToSend); PVMFSharedMediaDataPtr mediaData; int leavecode = 0; OSCL_TRY(leavecode, mediaData = PVMFMediaData::createMediaData(mediaDataImpl)); OSCL_FIRST_CATCH_ANY(leavecode, return); // Send FSI if available if (iFsi) { OsclSharedPtr<PVMFMediaDataImpl> fsiMediaDataImpl = iMediaDataAlloc->allocate(iFsiLen); PVMFSharedMediaDataPtr fsiMediaData; OSCL_TRY(leavecode, fsiMediaData = PVMFMediaData::createMediaData(fsiMediaDataImpl)); OSCL_FIRST_CATCH_ANY(leavecode, return); OsclRefCounterMemFrag fsi_frag; fsiMediaData->getMediaFragment(0, fsi_frag); oscl_memcpy((uint8*)fsi_frag.getMemFragPtr(), iFsi, iFsiLen); fsi_frag.getMemFrag().len = iFsiLen; mediaData->setFormatSpecificInfo(fsi_frag); OSCL_DEFAULT_FREE(iFsi); iFsi = NULL; iFsiLen = 0; } // Retrieve memory fragment to write to OsclRefCounterMemFrag refCtrMemFrag; mediaData->getMediaFragment(0, refCtrMemFrag); if (refCtrMemFrag.getCapacity() < bytesToSend) return; oscl_memset((uint8*)refCtrMemFrag.getMemFragPtr(), 7, bytesToSend); mediaDataImpl->setMediaFragFilledLen(0, bytesToSend); mediaData->setTimestamp(iTimestamp); iTimestamp += iSampleInterval; // Send frame to downstream node PVMFSharedMediaMsgPtr mediaMsg; convertToPVMFMediaMsg(mediaMsg, mediaData); QueueOutgoingMsg(mediaMsg); }
void ML::MsgLoopRjtSend(PS_MlRejectCause pCause) { S_MaintenanceLoopReject maintenanceLoopReject ; S_H245Msg h245Msg ; PS_MlRejectType temp = &(maintenanceLoopReject.mlRejectType); LoopTypeRead(OSCL_STATIC_CAST(PS_MlRequestType, temp)); oscl_memcpy((int8*)&maintenanceLoopReject.mlRejectCause , (int8*)pCause , sizeof(S_MlRejectCause)) ; h245Msg.Type1 = H245_MSG_RPS ; h245Msg.Type2 = MSGTYP_ML_RJT ; h245Msg.pData = (uint8*) & maintenanceLoopReject ; MessageSend(&h245Msg) ; }
void ML::PtvLoopIdcSend(PS_MaintenanceLoopRequest pMaintenanceLoopRequest) { S_InfHeader header ; S_MlRequestType loop_Type ; oscl_memcpy((int8*)&loop_Type, (int8*)&pMaintenanceLoopRequest->mlRequestType, sizeof(S_MlRequestType)) ; header.InfType = H245_PRIMITIVE ; header.InfId = E_PtvId_Ml_Loop_Idc ; header.InfSupplement1 = 0 ; header.InfSupplement2 = 0 ; header.pParameter = (uint8*) & loop_Type ; header.Size = sizeof(S_MlRequestType) ; PrimitiveSend(&header) ; }
void ML::PtvRlsIdcSend(int32 Source , PS_MlRejectCause pCause) { S_InfHeader header ; S_SourceCause_Ml sourceCause_Ml ; sourceCause_Ml.Source = (ENUM_Source)Source ; oscl_memcpy((int8*)&sourceCause_Ml.Cause , (int8*)pCause , sizeof(S_MlRejectCause)) ; header.InfType = H245_PRIMITIVE ; header.InfId = E_PtvId_Ml_Rls_Idc ; header.InfSupplement1 = 0 ; header.InfSupplement2 = 0 ; header.pParameter = (uint8*) & sourceCause_Ml ; header.Size = sizeof(S_SourceCause_Ml) ; PrimitiveSend(&header) ; }
OSCL_EXPORT_REF bool compose_RTSP_string(char *str, unsigned int max_len, const RtspRangeType& range, int& len_used) { len_used = 0; // first verify that there is something to do if (range.format == RtspRangeType::UNKNOWN_RANGE || range.format == RtspRangeType::INVALID_RANGE) { // nothing to output but it is not an error return true; } const char *range_str = "Range: "; int length = oscl_strlen(range_str); // output the "Range: " string if ((int)max_len < length) { return false; } oscl_memcpy(str, range_str, length); str += length; len_used += length; max_len -= length; if (compose_range_string(str, max_len, range, length) != true) { len_used += length; return false; } len_used += length; return true; }
OSCL_EXPORT_REF PVMFBufferDataSource::PVMFBufferDataSource(int32 aPortTag, unsigned bitrate, unsigned min_sample_sz, unsigned max_sample_sz, uint8* fsi, unsigned fsi_len): PvmfPortBaseImpl(aPortTag, this), iTimer("PVMFBufferDataSource"), iMediaDataAlloc(NULL), iFsi(NULL), iFsiLen(0) { iBitrate = bitrate; iMinSampleSz = min_sample_sz; iMaxSampleSz = max_sample_sz; iTimestamp = 0; iSampleInterval = 0; if (fsi && fsi_len) { iFsi = (uint8*)OSCL_DEFAULT_MALLOC(fsi_len); oscl_memcpy(iFsi, fsi, fsi_len); iFsiLen = fsi_len; } }
/** * Write * Writes data from the input buffer into * the buffer supplied (inputBuffer) * * @param inputBuffer pointer to buffer of type void * @param size element size in bytes * @param numelements * number of elements to write * * @return returns the number of elements written */ uint32 OsclFileCache::Write(const void* inputBuffer, uint32 size, uint32 numelements) { if (inputBuffer == NULL) { PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OsclFileCache(0x%x)::Write ERROR invalid arg ", this)); return 0; } //write the data only in the mode we are permitted to write if ((_mode & Oscl_File::MODE_READWRITE) || (_mode & Oscl_File::MODE_APPEND) || (_mode & Oscl_File::MODE_READ_PLUS)) { ;//ok to write } else { PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OsclFileCache(0x%x)::Write ERROR invalid mode for writing ", this)); return 0;//invalid mode. } //In Append mode, write always happens at the end of file, //so relocate the cache now if needed. if ((_mode & Oscl_File::MODE_APPEND) && (Tell() != FileSize())) { int32 result = SetCachePosition(FileSize()); if (result != 0) { PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OsclFileCache(0x%x)::Write ERROR SetCachePosition failed. ", this)); return 0; } } //prep current cache for writing int32 result = _curCache->PrepWrite(); if (result != 0) { PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OsclFileCache(0x%x)::Write ERROR PrepWrite failed. ", this)); return 0; } uint8* srcBuf = (uint8*)(inputBuffer); uint32 bytesToWrite = size * numelements; //write into cache, flushing as needed when it fills up. while (bytesToWrite > 0) { OSCL_ASSERT(_curCache->usableSize >= _curCache->currentPos); uint32 spaceInCache = _curCache->usableSize - _curCache->currentPos; if (spaceInCache > 0) { //write to cache uint32 thisWrite = (spaceInCache > bytesToWrite) ? bytesToWrite : spaceInCache; oscl_memcpy((_curCache->pBuffer + _curCache->currentPos), srcBuf, thisWrite); bytesToWrite -= thisWrite; srcBuf += thisWrite; //keep track of the range of data in the cache that has been updated. if (_curCache->updateEnd == _curCache->updateStart) { //first update in this cache _curCache->updateStart = _curCache->currentPos; _curCache->updateEnd = _curCache->currentPos + thisWrite; } else { //cache has already been updated. Expand the updated range //to include this update. if (_curCache->currentPos < _curCache->updateStart) _curCache->updateStart = _curCache->currentPos; if ((_curCache->currentPos + thisWrite) > _curCache->updateEnd) _curCache->updateEnd = _curCache->currentPos + thisWrite; } //update the virtual position. _curCache->currentPos += thisWrite; //extend the end of cache data if needed if (_curCache->endPos < _curCache->currentPos) _curCache->endPos = _curCache->currentPos; //extend the virtual file size if needed. if (_fileSize < (TOsclFileOffset)(_curCache->filePosition + _curCache->endPos)) _fileSize = _curCache->filePosition + _curCache->endPos; //consistency checks. if these asserts fire, there is //a logic error. OSCL_ASSERT(_curCache->updateEnd >= _curCache->updateStart); OSCL_ASSERT(_curCache->endPos >= _curCache->currentPos); } else { //entire cache is full-- re-set cache to current vpos and prep //for write int32 retval = SetCachePosition(Tell()); if (retval != 0) { PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OsclFileCache(0x%x)::Write ERROR SetCachePosition failed ", this)); break;//error! } retval = _curCache->PrepWrite(); if (retval != 0) { PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OsclFileCache(0x%x)::Write ERROR PrepWrite failed ", this)); break;//error! } } } //return number of whole elements written. return (size) ? ((size*numelements - bytesToWrite) / size) : 0; }
OSCL_EXPORT_REF bool RTSPOutgoingMessage::addField( StrCSumPtrLen * newFieldName, const StrPtrLen * newFieldValue ) { StrPtrLen * fieldVal = const_cast<StrPtrLen *>(queryField(* newFieldName)); uint32 extraSize; // check if this field already exists in the message // if (NULL == fieldVal) { // this field is new to the message // check that there are enough pointers if (RTSP_MAX_NUMBER_OF_FIELDS == numPtrFields) { return false; } // check for the extra size extraSize = newFieldName->length() + newFieldValue->length() + 2; if (RTSP_MAX_FULL_REQUEST_SIZE < secondaryBufferSizeUsed + extraSize) { return false; } // oscl_memcpy is unsafe for overlaps, but source and target memory come from // different sources // oscl_memcpy(secondaryBufferSpace, newFieldName->c_str(), newFieldName->length() + 1); oscl_memcpy(secondaryBufferSpace + newFieldName->length() + 1, newFieldValue->c_str(), newFieldValue->length() + 1); // save the incoming structures, but reset pointers to their new home in the // secondary buffer fieldKeys[ numPtrFields ].setPtrLen(secondaryBufferSpace, newFieldName->length()); fieldVals[ numPtrFields ].setPtrLen( secondaryBufferSpace + newFieldName->length() + 1, newFieldValue->length() ); // pop up the number of used pointers // ++ numPtrFields; // do buffer accounting // } else { // this field is known to the message, we just have to replace its value // check for the extra size extraSize = newFieldValue->length() + 1; if (RTSP_MAX_FULL_REQUEST_SIZE < secondaryBufferSizeUsed + extraSize) { return false; } // oscl_memcpy is unsafe for overlaps, but source and target memory come from // different sources // oscl_memcpy(secondaryBufferSpace, newFieldValue->c_str(), newFieldValue->length() + 1); // save the incoming structures, but reset pointers to their new home in the // secondary buffer fieldVal->setPtrLen(secondaryBufferSpace, newFieldValue->length()); } secondaryBufferSizeUsed += extraSize; secondaryBufferSpace = secondaryBuffer + secondaryBufferSizeUsed; return true; }
OSCL_EXPORT_REF bool RTSPOutgoingMessage::compose() { // compose the first line // switch (msgType) { case RTSPResponseMsg: { // RTSP version // oscl_memcpy(fullRequestBuffer, RTSPVersionString, RTSPVersionString_len); fullRequestBufferSpace += RTSPVersionString_len; *(fullRequestBufferSpace++) = ' '; // Status code // oscl_snprintf(fullRequestBufferSpace, RTSP_MAX_FULL_REQUEST_SIZE - 1, "%d", statusCode); // resync the pointer and size used fullRequestBufferSizeUsed = oscl_strlen(fullRequestBufferSpace); fullRequestBufferSpace += fullRequestBufferSizeUsed; *(fullRequestBufferSpace++) = ' '; fullRequestBufferSizeUsed += 1 + RTSPVersionString_len + 1; if (0 != reasonString.length()) { // user specified his own string // oscl_memcpy(fullRequestBufferSpace, reasonString.c_str(), reasonString.length()); fullRequestBufferSpace += reasonString.length(); fullRequestBufferSizeUsed += reasonString.length(); } else { StrPtrLen realReasonString ; // user wants the built-in default // switch (statusCode) { case CodeContinue: realReasonString = RtspReasonStringContinue; break; case CodeOK: realReasonString = RtspReasonStringOK; break; case CodeCreated: realReasonString = RtspReasonStringCreated; break; case CodeLowOnStorageSpace: realReasonString = RtspReasonStringLowOnStorageSpace; break; case CodeMultipleChoices: realReasonString = RtspReasonStringMultipleChoices; break; case CodeMovedPermanently: realReasonString = RtspReasonStringMovedPermanently; break; case CodeMovedTemporarily: realReasonString = RtspReasonStringMovedTemporarily; break; case CodeSeeOther: realReasonString = RtspReasonStringSeeOther; break; case CodeNotModified: realReasonString = RtspReasonStringNotModified; break; case CodeUseProxy: realReasonString = RtspReasonStringUseProxy; break; case CodeBadRequest: realReasonString = RtspReasonStringBadRequest; break; case CodeUnauthorized: realReasonString = RtspReasonStringUnauthorized; break; case CodePaymentRequired: realReasonString = RtspReasonStringPaymentRequired; break; case CodeForbidden: realReasonString = RtspReasonStringForbidden; break; case CodeNotFound: realReasonString = RtspReasonStringNotFound; break; case CodeMethodNotAllowed: realReasonString = RtspReasonStringMethodNotAllowed; break; case CodeNotAcceptable: realReasonString = RtspReasonStringNotAcceptable; break; case CodeProxyAuthenticationRequired: realReasonString = RtspReasonStringProxyAuthenticationRequired; break; case CodeRequestTimeOut: realReasonString = RtspReasonStringRequestTimeOut; break; case CodeGone: realReasonString = RtspReasonStringGone; break; case CodeLengthRequired: realReasonString = RtspReasonStringLengthRequired; break; case CodePreconditionFailed: realReasonString = RtspReasonStringPreconditionFailed; break; case CodeRequestEntityTooLarge: realReasonString = RtspReasonStringRequestEntityTooLarge; break; case CodeRequestURITooLarge: realReasonString = RtspReasonStringRequestURITooLarge; break; case CodeUnsupportedMediaType: realReasonString = RtspReasonStringUnsupportedMediaType; break; case CodeSessionNotFound: realReasonString = RtspReasonStringSessionNotFound; break; case CodeMethodNotValidInThisState: realReasonString = RtspReasonStringMethodNotValidInThisState; break; case CodeHeaderFieldNotValidForResource: realReasonString = RtspReasonStringHeaderFieldNotValidForResource; break; case CodeInvalidRange: realReasonString = RtspReasonStringInvalidRange; break; case CodeParameterIsReadOnly: realReasonString = RtspReasonStringParameterIsReadOnly; break; case CodeAggregateOperationNotAllowed: realReasonString = RtspReasonStringAggregateOperationNotAllowed; break; case CodeOnlyAggregateOperationAllowed: realReasonString = RtspReasonStringOnlyAggregateOperationAllowed; break; case CodeUnsupportedTransport: realReasonString = RtspReasonStringUnsupportedTransport; break; case CodeDestinationUnreachable: realReasonString = RtspReasonStringDestinationUnreachable; break; case CodeUnsupportedClient: realReasonString = RtspReasonStringUnsupportedClient; break; case CodeInternalServerError: realReasonString = RtspReasonStringInternalServerError; break; case CodeNotImplemented: realReasonString = RtspReasonStringNotImplemented; break; case CodeBadGateway: realReasonString = RtspReasonStringBadGateway; break; case CodeServiceUnavailable: realReasonString = RtspReasonStringServiceUnavailable; break; case CodeGatewayTimeout: realReasonString = RtspReasonStringGatewayTimeout; break; case CodeRTSPVersionNotSupported: realReasonString = RtspReasonStringRTSPVersionNotSupported; break; case CodeOptionNotSupported: realReasonString = RtspReasonStringOptionNotSupported; break; case CodeParameterNotUnderstood: realReasonString = RtspReasonStringParameterNotUnderstood; break; default: // no string was found, since code is unknown... ;;; } if (realReasonString.length()) { oscl_memcpy(fullRequestBufferSpace, realReasonString.c_str(), realReasonString.length()); fullRequestBufferSpace += realReasonString.length(); fullRequestBufferSizeUsed += realReasonString.length(); } } break; } case RTSPRequestMsg: { if (METHOD_BINARY_DATA == method) { // it's interleaved stuff // leading dollar *(fullRequestBufferSpace++) = CHAR_DOLLAR; // 8-bit channel-id from the content-type *(fullRequestBufferSpace++) = contentType.c_str()[0]; // 16-bit content length, in network byte order *(fullRequestBufferSpace++) = char((contentLength & 0xFF00) >> 8); *(fullRequestBufferSpace++) = char((contentLength & 0xFF)); *fullRequestBufferSpace = CHAR_NULL; fullRequestBufferSizeUsed = 4; fullRequestPLS = fullRequestBuffer; return true; } // okay, it's a normal request // do the method if (method < 0 || method >= METHOD_NUM_ENTRIES) { // method unknown return false; } uint32 method_strlen = oscl_strlen(RtspMethodStringPLSS[method]); oscl_memcpy(fullRequestBufferSpace, RtspMethodStringPLSS[method], method_strlen ); fullRequestBufferSpace += method_strlen; *(fullRequestBufferSpace++) = CHAR_SPACE; fullRequestBufferSizeUsed += method_strlen + 1; // do the URI oscl_memcpy(fullRequestBufferSpace, originalURI.c_str(), originalURI.length() ); fullRequestBufferSpace += originalURI.length(); *(fullRequestBufferSpace++) = CHAR_SPACE; fullRequestBufferSizeUsed += originalURI.length() + 1; // do the RTSP version #ifdef SIMPLE_HTTP_SUPPORT if ((method == METHOD_GET) || (method == METHOD_POST)) { oscl_memcpy(fullRequestBufferSpace, HTTPVersion_1_0_String, HTTPVersionString_len ); } else #endif oscl_memcpy(fullRequestBufferSpace, RTSPVersionString, RTSPVersionString_len ); fullRequestBufferSpace += RTSPVersionString_len; fullRequestBufferSizeUsed += RTSPVersionString_len; break; } default: { // cannot encode an unknown type of message return false; } }
Int OmxAacDecoder::AacDecodeFrames(OMX_S16* aOutputBuffer, OMX_U32* aOutputLength, OMX_U8** aInBuffer, OMX_U32* aInBufSize, OMX_S32* aIsFirstBuffer, OMX_AUDIO_PARAM_PCMMODETYPE* aAudioPcmParam, OMX_AUDIO_PARAM_AACPROFILETYPE* aAudioAacParam, OMX_U32* aSamplesPerFrame, OMX_BOOL* aResizeFlag) { Int Status; Int32 StreamType; *aResizeFlag = OMX_FALSE; if (0 == iAacInitFlag) { //Initialization is required again when the client inbetween rewinds the input bitstream //Added to pass khronous conformance tests if (*aIsFirstBuffer != 0) { /* When the input file is reset to the begining by the client, * this module should again be called. */ oscl_memset(ipMem, 0, iMemReq); oscl_memset(&iExt, 0, sizeof(tPVMP4AudioDecoderExternal)); iExt.inputBufferCurrentLength = 0; iExt.remainderBits = 0; iExt.inputBufferMaxLength = PVMP4AUDIODECODER_INBUFSIZE; iExt.outputFormat = OUTPUTFORMAT_16PCM_INTERLEAVED; iExt.desiredChannels = iNumOfChannels; iExt.aacPlusEnabled = TRUE; iInputUsedLength = 0; PVMP4AudioDecoderInitLibrary(&iExt, ipMem); } } iExt.pInputBuffer = *aInBuffer + iInputUsedLength; iExt.pOutputBuffer = &aOutputBuffer[0]; #ifdef AAC_PLUS iExt.pOutputBuffer_plus = &aOutputBuffer[2048]; #endif iExt.inputBufferCurrentLength = *aInBufSize; //Decode the config buffer if (0 == iAacInitFlag) { #if PROFILING_ON OMX_U32 StartTime = OsclTickCount::TickCount(); #endif Status = PVMP4AudioDecoderConfig(&iExt, ipMem); #if PROFILING_ON OMX_U32 EndTime = OsclTickCount::TickCount(); iTotalTicks += (EndTime - StartTime); #endif if (MP4AUDEC_SUCCESS == Status) { iAacInitFlag = 1; } iConfigUpSamplingFactor = iExt.aacPlusUpsamplingFactor; if (2 == iExt.aacPlusUpsamplingFactor) { *aSamplesPerFrame = 2 * AACDEC_PCM_FRAME_SAMPLE_SIZE; } else { *aSamplesPerFrame = AACDEC_PCM_FRAME_SAMPLE_SIZE; } /* * *aInBufSize -= iExt.inputBufferUsedLength; should render *aInBufSize == 0, * If the size of the audio config buffer exceeds the size of the audio config data * the excess bits could be taken as part of next raw aac stream. To avoid that * we force to consume all bits of the audio config buffer, by making *aInBufSize == 0 */ *aInBufSize = 0; iInputUsedLength = 0; return Status; } iExt.inputBufferUsedLength = 0; #if PROFILING_ON OMX_U32 StartTime = OsclTickCount::TickCount(); #endif Status = PVMP4AudioDecodeFrame(&iExt, ipMem); #if PROFILING_ON OMX_U32 EndTime = OsclTickCount::TickCount(); iTotalTicks += (EndTime - StartTime); #endif if (MP4AUDEC_SUCCESS == Status || SUCCESS == Status) { *aInBufSize -= iExt.inputBufferUsedLength; if (0 == *aInBufSize) { iInputUsedLength = 0; } else { iInputUsedLength += iExt.inputBufferUsedLength; } *aOutputLength = iExt.frameLength * iExt.desiredChannels; #ifdef AAC_PLUS if (2 == iExt.aacPlusUpsamplingFactor) { if (1 == iExt.desiredChannels) { oscl_memcpy(&aOutputBuffer[1024], &aOutputBuffer[2048], (*aOutputLength * 2)); } *aOutputLength *= 2; } #endif (*aIsFirstBuffer)++; //After decoding the first frame, modify all the input & output port settings if (1 == *aIsFirstBuffer) { StreamType = (Int32) RetrieveDecodedStreamType(); if ((0 == StreamType) && (2 == iConfigUpSamplingFactor)) { PVMP4AudioDecoderDisableAacPlus(&iExt, &ipMem); *aSamplesPerFrame = AACDEC_PCM_FRAME_SAMPLE_SIZE; aAudioAacParam->eAACProfile = OMX_AUDIO_AACObjectMain; aAudioAacParam->nFrameLength = AACDEC_PCM_FRAME_SAMPLE_SIZE; } //Output Port Parameters aAudioPcmParam->nSamplingRate = iExt.samplingRate; aAudioPcmParam->nChannels = iExt.desiredChannels; //Input Port Parameters aAudioAacParam->nSampleRate = iExt.samplingRate; //Set the Resize flag to send the port settings changed callback *aResizeFlag = OMX_TRUE; } #if PROFILING_ON iNumOutputSamples += *aSamplesPerFrame; #endif return Status; } else if (MP4AUDEC_INCOMPLETE_FRAME == Status) { *aInBuffer += iInputUsedLength; iInputUsedLength = 0; } else { *aInBufSize = 0; iInputUsedLength = 0; } return Status; }
OSCL_EXPORT_REF bool parseRtspRange(const char *rangeString, int length, RtspRangeType& range) { const char *end = rangeString + length; const char* sptr, *eptr; // initialize range to invalid format range.format = RtspRangeType::INVALID_RANGE; // find the first word before the "=" sptr = skip_whitespace_and_line_term(rangeString, end); if (sptr >= end) { return false; } for (eptr = sptr; eptr < end && (*eptr != '=' && *eptr != ':' && *eptr != ' ' && *eptr != '\t'); ++eptr); StrPtrLen smpte_type("smpte"); StrPtrLen smpte25_type("smpte-25"); StrPtrLen smpte30_type("smpte-30-drop"); StrPtrLen npt_type("npt"); StrPtrLen abs_type("clock"); //#ifdef RTSP_PLAYLIST_SUPPORT StrPtrLen playlist_play_time_type("playlist_play_time"); //#endif //#ifdef RTSP_PLAYLIST_SUPPORT if (!oscl_strncmp(sptr, smpte_type.c_str(), eptr - sptr) || !oscl_strncmp(sptr, smpte25_type.c_str(), eptr - sptr) || !oscl_strncmp(sptr, smpte30_type.c_str(), eptr - sptr)) { // Parsing one of the SMPTE time formats // save the exact format temporarily RtspRangeType::RtspRangeFormat tmp_format; if (!oscl_strncmp(sptr, smpte30_type.c_str(), smpte30_type.length())) { tmp_format = RtspRangeType::SMPTE_30_RANGE; } else if (!oscl_strncmp(sptr, smpte25_type.c_str(), smpte25_type.length())) { tmp_format = RtspRangeType::SMPTE_25_RANGE; } else { tmp_format = RtspRangeType::SMPTE_RANGE; } // skip ahead to beyond the "=" if (*eptr != '=') { for (; eptr < end && *eptr != '='; ++eptr); } sptr = skip_whitespace(eptr + 1, end); if (sptr >= end) { return false; } // find the start/end separator for (eptr = sptr; eptr < end && (*eptr != '-'); ++eptr); if (*eptr != '-') { return false; } range.start_is_set = false; if (eptr > sptr) { // there is a start time if (parse_smpte_format(sptr, eptr, tmp_format, range.smpte_start) == false) { return false; } // now set the appropriate flags range.start_is_set = true; } // see if there is a stop time sptr = skip_whitespace_and_line_term(eptr + 1, end); range.end_is_set = false; if (sptr < end) { // there is a stop time specification eptr = skip_to_whitespace(sptr, end); if (parse_smpte_format(sptr, eptr, tmp_format, range.smpte_end) == false) { return false; } // now set the appropriate flags range.end_is_set = true; } // now set the appropriate range format range.format = tmp_format; } // end if this is an SMPTE time format else if (!oscl_strncmp(sptr, npt_type.c_str(), eptr - sptr)) { // skip ahead to beyond the "=" or ":" if (*eptr != '=') { for (; eptr < end && *eptr != '=' && *eptr != ':'; ++eptr); } sptr = skip_whitespace(eptr + 1, end); if (sptr >= end) { return false; } // find the start/end separator for (eptr = sptr; eptr < end && (*eptr != '-'); ++eptr); if (*eptr != '-') { return false; } range.start_is_set = false; if (eptr > sptr) { // there is a start time if (parse_npt_format(sptr, eptr, range.npt_start) == false) { return false; } // now set the appropriate flags range.start_is_set = true; } // see if there is a stop time range.end_is_set = false; sptr = skip_whitespace_and_line_term(eptr + 1, end); if (sptr < end) { // there is a stop time specification eptr = skip_to_whitespace(sptr, end); if (parse_npt_format(sptr, eptr, range.npt_end) == false) { return false; } // now set the appropriate flags range.end_is_set = true; } // now set the appropriate range format range.format = RtspRangeType::NPT_RANGE; } // end if this is an NPT time format else if (!oscl_strncmp(sptr, abs_type.c_str(), eptr - sptr)) { // skip ahead to beyond the "=" if (*eptr != '=') { for (; eptr < end && *eptr != '='; ++eptr); } sptr = skip_whitespace(eptr + 1, end); if (sptr >= end) { return false; } // find the start/end separator for (eptr = sptr; eptr < end && (*eptr != '-'); ++eptr); if (*eptr != '-') { return false; } range.start_is_set = false; if (eptr > sptr) { // there is a start time if (parse_abs_format(sptr, eptr, range.abs_start) == false) { return false; } // now set the appropriate flags range.start_is_set = true; } // see if there is a stop time sptr = skip_whitespace_and_line_term(eptr + 1, end); range.end_is_set = true; if (sptr < end) { // there is a stop time specification eptr = skip_to_whitespace(sptr, end); if (parse_abs_format(sptr, eptr, range.abs_end) == false) { return false; } // now set the appropriate flags range.end_is_set = true; } // now set the appropriate range format range.format = RtspRangeType::ABS_RANGE; } // end if this is an ABS time format //#ifdef RTSP_PLAYLIST_SUPPORT // for Range:playlist_play_time=<URN,clipIndex,clipOffset> //playlist_play_time=</public/playlist/va_playlists/test.ply,3,0.0>;npt=194.81542 else if (!oscl_strncmp(sptr, playlist_play_time_type.c_str(), eptr - sptr)) { // store the whole string since we may not need the parsed version of things //oscl_memcpy(range.iPlaylistPlayStr,rangeString,length); //range.iPlaylistPlayStr[length] = '\0'; range.format = RtspRangeType::PLAYLIST_TIME_RANGE; range.start_is_set = range.end_is_set = false; // now set the appropriate flags range.start_is_set = true; // skip ahead to beyond the "=" if (*eptr != '=') { for (; eptr < end && *eptr != '='; ++eptr); } sptr = skip_whitespace(eptr + 1, end); if (sptr >= end) { return false; } // next should be the opening "<" // skip ahead to beyond the "<" if (*eptr != '<') { for (; eptr < end && *eptr != '<'; ++eptr); } sptr = skip_whitespace(eptr + 1, end); if (sptr >= end) { return false; } // find the comma separator for (eptr = sptr; eptr < end && (*eptr != ','); ++eptr); if (*eptr != ',') { return false; } // first the urn if (eptr > sptr) { // there is a urn if (oscl_memcpy(range.iPlaylistUrl, sptr, eptr - sptr) == false) { return false; } //range.iUrn[(eptr-sptr)+1] = '\0'; range.iPlaylistUrl[eptr-sptr] = '\0'; } // now the clipIndex sptr = skip_whitespace(eptr + 1, end); if (sptr >= end) { return false; } // find the next comma separator for (eptr = sptr; eptr < end && (*eptr != ','); ++eptr); if (*eptr != ',') { return false; } // now the clipIndex if (eptr > sptr) { // there is a clipIndex uint32 tmp; if (PV_atoi(sptr, 'd', eptr - sptr, tmp) == false) { return false; } range.playlist_start.iClipIndex = (int32)tmp; } // now the clipOffset sptr = skip_whitespace(eptr + 1, end); if (sptr >= end) { return false; } // find the final '>' separator or the final possible '.' in offset //<sec>.<frac> for (eptr = sptr; eptr < end && (*eptr != '>') && (*eptr != '.'); ++eptr); if (eptr >= end) { return false; } // @todo ignore the factional part for now // now the clipOffset if (eptr > sptr) { // there is a clipOffset uint32 tmp; if (PV_atoi(sptr, 'd', eptr - sptr, tmp) == false) { return false; } range.playlist_start.sec = (int32)tmp; { range.playlist_start.milli_sec = 0; if (*eptr == '.') { // there is an optional fractional seconds field // get the fractional seconds const int MAX_TMP_BUFSIZE = 12; char tmpbuf[MAX_TMP_BUFSIZE]; int copy_size; eptr = skip_to_whitespace(sptr, end); copy_size = eptr - sptr; if (copy_size > MAX_TMP_BUFSIZE - 1) { copy_size = MAX_TMP_BUFSIZE - 1; } oscl_strncpy(tmpbuf, sptr, copy_size); tmpbuf[copy_size] = '\0'; OsclFloat tmp_fnum; if (!PV_atof(tmpbuf, tmp_fnum)) return false; range.playlist_start.milli_sec = (uint32)(1000.0 * tmp_fnum + 0.5); } } } } // end if this is a playlist_play_time format, for response to playlist_play commands //#endif //#ifdef RTSP_PLAYLIST_SUPPORT else { /*Unsupported time format*/ range.format = RtspRangeType::UNKNOWN_RANGE; range.start_is_set = false; range.end_is_set = false; return false; } return true; }
OSCL_EXPORT_REF bool compose_range_string(char *str, unsigned int max_len, const RtspRangeType& range, int& len_used) { len_used = 0; int length; if (!range.start_is_set && !range.end_is_set) { return false; } switch (range.format) { case RtspRangeType::NPT_RANGE: { StrPtrLen npt_str("npt="); if (max_len < (unsigned int)npt_str.length()) { return false; } oscl_memcpy(str, npt_str.c_str(), npt_str.length()); str += npt_str.length(); max_len -= npt_str.length(); len_used += npt_str.length(); if (range.start_is_set) { if (compose_range_string(str, max_len, range.npt_start, length) != true) { return false; } len_used += length; max_len -= length; str += length; } if (max_len < 1) { return false; } *str++ = '-'; --max_len; ++len_used; if (range.end_is_set) { if (compose_range_string(str, max_len, range.npt_end, length) != true) { return false; } len_used += length; max_len -= length; str += length; } break; } case RtspRangeType::SMPTE_RANGE: case RtspRangeType::SMPTE_25_RANGE: case RtspRangeType::SMPTE_30_RANGE: { StrPtrLen smpte30_str("smpte-30-drop="); StrPtrLen smpte25_str("smpte-25="); StrPtrLen smpte_str("smpte="); if (range.format == RtspRangeType::SMPTE_30_RANGE) { if (max_len < (unsigned int)smpte30_str.length()) { return false; } oscl_memcpy(str, smpte30_str.c_str(), smpte30_str.length()); str += smpte30_str.length(); max_len -= smpte30_str.length(); len_used += smpte30_str.length(); } else if (range.format == RtspRangeType::SMPTE_25_RANGE) { if (max_len < (unsigned int)smpte25_str.length()) { return false; } oscl_memcpy(str, smpte25_str.c_str(), smpte25_str.length()); str += smpte25_str.length(); max_len -= smpte25_str.length(); len_used += smpte25_str.length(); } else { if (max_len < (unsigned int)smpte_str.length()) { return false; } oscl_memcpy(str, smpte_str.c_str(), smpte_str.length()); str += smpte_str.length(); max_len -= smpte_str.length(); len_used += smpte_str.length(); } if (range.start_is_set) { if (compose_range_string(str, max_len, range.smpte_start, length) != true) { return false; } len_used += length; max_len -= length; str += length; } if (max_len < 1) { return false; } *str++ = '-'; --max_len; ++len_used; if (range.end_is_set) { if (compose_range_string(str, max_len, range.smpte_end, length) != true) { return false; } len_used += length; max_len -= length; str += length; } break; } case RtspRangeType::ABS_RANGE: { StrPtrLen abs_str("clock="); if (max_len < (unsigned int)abs_str.length()) { return false; } oscl_memcpy(str, abs_str.c_str(), abs_str.length()); str += abs_str.length(); max_len -= abs_str.length(); len_used += abs_str.length(); if (range.start_is_set) { if (compose_range_string(str, max_len, range.abs_start, length) != true) { return false; } len_used += length; max_len -= length; str += length; } if (max_len < 1) { return false; } *str++ = '-'; --max_len; ++len_used; if (range.end_is_set) { if (compose_range_string(str, max_len, range.abs_end, length) != true) { return false; } len_used += length; max_len -= length; str += length; } break; } default: return false; } if (max_len < 2) { // can't add line terminator return false; } // add the line terminator *str++ = '\r'; *str++ = '\n'; len_used += 2; return true; }
OSCL_EXPORT_REF bool compose_range_string(char *str, unsigned int max_len, const AbsTimeFormat& abs_range, int& len_used) { len_used = 0; int length; char tmp[17]; if (max_len < 16) { return false; } length = oscl_snprintf(tmp, 17, "%04d%02d%02dT%02d%02d%02d", abs_range.year, abs_range.month, abs_range.day, abs_range.hours, abs_range.min, abs_range.sec); if (length != 15) { return false; } oscl_memcpy(str, tmp , length); str += length; len_used += length; max_len -= length; if (abs_range.frac_sec > 0.0) { if (abs_range.frac_sec >= 1.0) { return false; } char tmpstr[MAX_RANGE_FLOAT_SIZE + 2]; length = oscl_snprintf(tmpstr, MAX_RANGE_FLOAT_SIZE + 2, RANGE_FLOAT_FORMAT, abs_range.frac_sec); if (length < 0 || length > MAX_RANGE_FLOAT_SIZE + 1) { return false; } if (length > (int)max_len || tmp[1] != '.') { return false; } oscl_memcpy(str, tmp + 1, length - 1); str += length - 1; len_used += length - 1; max_len -= (length - 1); } if (max_len < 1) { return false; } *str = 'Z'; len_used++; return true; }
OSCL_EXPORT_REF bool compose_range_string(char *str, unsigned int max_len, const SmpteTimeFormat& smpte_range, int& len_used) { len_used = 0; int length; char tmp[10]; if (max_len < 8) { return false; } length = oscl_snprintf(tmp, 9, "%02d:%02d:%02d", smpte_range.hours, smpte_range.minutes, smpte_range.seconds); if (length != 8) { return false; } oscl_memcpy(str, tmp , length); str += length; len_used += length; max_len -= length; if (smpte_range.frames) { if (max_len < 3) { return 0; } length = oscl_snprintf(tmp, 4, ":%02d", smpte_range.frames); if (length != 3) { return false; } oscl_memcpy(str, tmp , length); str += length; len_used += length; max_len -= length; } if (smpte_range.subframes) { if (max_len < 3) { return 0; } length = oscl_snprintf(tmp, 4, ".%02d", smpte_range.subframes); if (length != 3) { return false; } oscl_memcpy(str, tmp , length); str += length; len_used += length; max_len -= length; } return true; }
OSCL_EXPORT_REF bool compose_range_string(char *str, unsigned int max_len, const NptTimeFormat& npt_range, int& len_used) { len_used = 0; int length; switch (npt_range.npt_format) { case NptTimeFormat::NOW: { StrPtrLen now_str("now"); if ((int)max_len < now_str.length()) { return false; } oscl_memcpy(str, now_str.c_str(), now_str.length()); str += now_str.length(); len_used += now_str.length(); max_len -= now_str.length(); break; } case NptTimeFormat::NPT_SEC: { char tmpstr[MAX_RANGE_INT_SIZE + 1]; length = oscl_snprintf(tmpstr, MAX_RANGE_INT_SIZE + 1, "%d", npt_range.npt_sec.sec); if (length < 0 || length > MAX_RANGE_INT_SIZE) { return false; } if (length > (int) max_len) { return false; } oscl_memcpy(str, tmpstr, length); str += length; len_used += length; max_len -= length; if (npt_range.npt_sec.milli_sec > 0.0) { if (npt_range.npt_sec.milli_sec >= 1.0) { return false; } char tmp[MAX_RANGE_FLOAT_SIZE + 2]; length = oscl_snprintf(tmp, MAX_RANGE_FLOAT_SIZE + 2, RANGE_FLOAT_FORMAT, npt_range.npt_sec.milli_sec); if (length < 0 || length > MAX_RANGE_FLOAT_SIZE + 1) { return false; } if (length > (int)max_len || tmp[1] != '.') { return false; } oscl_memcpy(str, tmp + 1, length - 1); str += length - 1; len_used += length - 1; max_len -= (length - 1); } break; } case NptTimeFormat::NPT_HHMMSS: { char tmpstr[MAX_RANGE_INT_SIZE + 1]; length = oscl_snprintf(tmpstr, MAX_RANGE_INT_SIZE + 1, "%d", npt_range.npt_hhmmss.hours); if (length < 0 || length >= MAX_RANGE_INT_SIZE) { return false; } if (length > (int) max_len) { return false; } oscl_memcpy(str, tmpstr, length); str += length; len_used += length; max_len -= length; if (max_len < 6) { return false; } length = oscl_snprintf(tmpstr, MAX_RANGE_INT_SIZE + 1, ":%02d:%02d", npt_range.npt_hhmmss.min, npt_range.npt_hhmmss.sec); if (length != 6) { return false; } oscl_memcpy(str, tmpstr, length); str += length; len_used += length; max_len -= length; if (npt_range.npt_hhmmss.frac_sec > 0.0) { if (npt_range.npt_hhmmss.frac_sec >= 1.0) { return false; } char tmp[MAX_RANGE_FLOAT_SIZE + 2]; length = oscl_snprintf(tmp, MAX_RANGE_FLOAT_SIZE + 2, RANGE_FLOAT_FORMAT, npt_range.npt_hhmmss.frac_sec); if (length < 0 || length > MAX_RANGE_FLOAT_SIZE + 1) { return false; } if (length > (int) max_len || tmp[1] != '.') { return false; } oscl_memcpy(str, tmp + 1, length - 1); str += length - 1; len_used += length - 1; max_len -= (length - 1); } break; } } return true; }