void PV2WayUtil::FindTestRange(cmd_line* command_line, uint32 &aFirstTest, uint32 &aLastTest, int32 aTestLimit) { //default is to run all tests. aFirstTest = 0; if (aTestLimit == 0) { aLastTest = MAX_324_TEST; } else { aLastTest = aTestLimit; } int testArgument = 0; char *iTestArgStr1 = NULL; char *iTestArgStr2 = NULL; bool cmdline_iswchar = command_line->is_wchar(); //-test //if (iTestFound) OSCL_HeapString<OsclMemAllocator> argument = "-test"; if (FindCmdArg(command_line, argument, testArgument)) { // Convert to UTF8 if necessary if (cmdline_iswchar) { iTestArgStr1 = OSCL_ARRAY_NEW(char, 256); OSCL_TCHAR* cmd; command_line->get_arg(testArgument, cmd); if (cmd) { oscl_UnicodeToUTF8(cmd, oscl_strlen(cmd), iTestArgStr1, 256); } iTestArgStr2 = OSCL_ARRAY_NEW(char, 256); command_line->get_arg(testArgument + 1, cmd); if (cmd) { oscl_UnicodeToUTF8(cmd, oscl_strlen(cmd), iTestArgStr2, 256); } } else { command_line->get_arg(testArgument, iTestArgStr1); command_line->get_arg(testArgument + 1, iTestArgStr2); } //Pull out 2 integers... PV_atoi(iTestArgStr1, 'd', aFirstTest); PV_atoi(iTestArgStr2, 'd', aLastTest); }
OSCL_EXPORT_REF const char * parse_range_integer(const char *start, const char *end, int max_digits, char *sep, uint32& value) { const char *sptr, *eptr; const char *endpoint; if (max_digits > 0 && ((end - start) > max_digits)) { endpoint = start + max_digits; } else { endpoint = end; } sptr = start; if (sep) { for (eptr = sptr; eptr < endpoint && *eptr != *sep ; ++eptr); } else { eptr = endpoint; } // get the hours uint32 tmp; if (PV_atoi(sptr, 'd', eptr - sptr, tmp) == false) { return NULL; } value = tmp; return eptr; }
bool INetURI::parseURL(OSCL_String &aUrl8, OSCL_String &aSerAdd, int32 &aSerPort) { OSCL_HeapString<OsclMemAllocator> tmpUrl8(aUrl8); typedef char mbchar; mbchar* aUrl = tmpUrl8.get_str(); mbchar *server_ip_ptr = oscl_strstr(((mbchar*)aUrl), "//"); if (server_ip_ptr == NULL) return false; server_ip_ptr += 2; /* Locate the IP address. */ mbchar *server_port_ptr = oscl_strstr(server_ip_ptr, ":"); mbchar *tmp_ptr = server_port_ptr; if (tmp_ptr == NULL) tmp_ptr = server_ip_ptr; mbchar *clip_name = oscl_strstr(tmp_ptr, "/"); if (clip_name != NULL) *clip_name++ = '\0'; /* Locate the port number if provided. */ aSerPort = DEFAULT_HTTP_PORT_NUMBER; if ((server_port_ptr != NULL) && (*(server_port_ptr + 1) != '/')) { *(server_port_ptr++) = '\0'; uint32 atoi_tmp; if (PV_atoi(server_port_ptr, 'd', atoi_tmp)) aSerPort = atoi_tmp; else return false; } /* relocate the server IP address, either stop at ':' or '/' */ mbchar *server_end_ptr = oscl_strstr(server_ip_ptr, "/"); if (server_end_ptr) *server_end_ptr = '\0'; OSCL_HeapString<OsclMemAllocator> tmpServerName(server_ip_ptr, oscl_strlen(server_ip_ptr)); aSerAdd = tmpServerName; return true; }
/* ======================================================================== * Function : oscl_str_unescape_uri * Date : 11/04/2002 * Purpose : see oscl_string_uri.h * Modified : * ======================================================================== */ OSCL_EXPORT_REF bool oscl_str_unescape_uri(const char *str_buf_in, char *str_buf_out, uint32 max_out_buf_bytes, uint32 max_bytes, uint32& out_buf_len) { const char *src = str_buf_in; char *dest = str_buf_out; uint32 srcStrLen = max_bytes, destStrLen = max_out_buf_bytes ; uint32 val = 0; int32 i = 0; bool result = false; out_buf_len = 0; if ((srcStrLen <= 0) || (src == NULL)) return (false); while (srcStrLen > 0) { if (src[i] == '%') { i++; srcStrLen--; if (srcStrLen >= 2) { if (PV_atoi(&src[i], 'x', 2, val) == false) { if (destStrLen > 0) *dest = (char)'\0'; return false; } i += 2; if (destStrLen > 0) { *dest++ = (char)val; destStrLen--; } out_buf_len += 1; srcStrLen -= 2; } else { if (destStrLen > 0) *dest = (char)'\0'; return false; } } else { if (src[i] == (char)'\0') break; if (destStrLen > 0) { *dest++ = src[i]; destStrLen--; } out_buf_len += 1; i++; srcStrLen--; } } if (destStrLen > 0) { *dest = (char)'\0'; result = true; } else out_buf_len += 1; //needed size return result; }
/* ======================================================================== * Function : oscl_str_unescape_uri * Date : 11/04/2002 * Purpose : see oscl_string_uri.h * Modified : * ======================================================================== */ OSCL_EXPORT_REF bool oscl_str_unescape_uri(const OSCL_String& srcString, OSCL_String& destString, uint32& out_buf_len) { const char *src = srcString.get_cstr(); int srcStrLen = srcString.get_size(); destString = ""; out_buf_len = 0; if ((srcStrLen <= 0) || (src == NULL)) { return false; } char buf[2]; buf[1] = '\0'; for (int32 i = 0; srcStrLen > 0;) { if (src[i] == '%') { i++; srcStrLen--; if ((srcStrLen >= 2)) { uint32 val; if (PV_atoi(&src[i], 'x', 2, val) == false) { return false; } //check capacity before appending to avoid any leave. if (destString.get_size() == destString.get_maxsize()) return false; buf[0] = (char)val; destString += buf; out_buf_len++; i += 2; srcStrLen -= 2; } else { return false; } } else { if (src[i] == (char)'\0') break; //check capacity before appending to avoid any leave. if (destString.get_size() == destString.get_maxsize()) return false; buf[0] = src[i]; destString += buf; out_buf_len++; i++; srcStrLen--; } } return true; }
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 PV_atoi(const char *buf, const char new_format, uint32& value) { return PV_atoi(buf, new_format, oscl_strlen(buf), value); }
void RTSPParser::lookForEndOfRequest() { // eorptr = mainBufferEntry; uint32 newMessageSize; *mainBufferSpace = CHAR_NULL; bool shouldMoveOverToBeginning = false; // now, it's either a binary data thing, or a regular message thing if (CHAR_DOLLAR == *mainBufferEntry) { // interesting, could be it if (mainBufferSpace - mainBufferEntry < 4) { // not a complete message shouldMoveOverToBeginning = true; } else { // it is a complete thing! requestStruct->msgType = RTSPRequestMsg; requestStruct->method = METHOD_BINARY_DATA; requestStruct->contentLength = ((static_cast<uint16>( (*(reinterpret_cast<unsigned char*>(mainBufferEntry + 2)) ))) << 8) + static_cast<uint16>( *(reinterpret_cast<unsigned char*>(mainBufferEntry + 3)) ); requestStruct->contentLengthIsSet = true; *(mainBufferEntry + 2) = CHAR_NULL; requestStruct->contentType = mainBufferEntry + 1; requestStruct->contentTypeIsSet = true; requestStruct->channelID = static_cast<uint8>( *(reinterpret_cast<unsigned char*>(mainBufferEntry + 1))); mainBufferEntry += 4; eorptr = mainBufferEntry; ebFullSizeExpected = requestStruct->contentLength; internalState = IS_REQUEST_IS_READY; return; } } else { // it's a normal message bool found = false; for (/*eorptr = mainBufferEntry*/; eorptr < mainBufferSpace - 1; ++eorptr) { if (CHAR_LF == *eorptr || CHAR_CR == *eorptr) { // it's a possible // is it two newlines? if (*eorptr == *(eorptr + 1)) { // yes, CR-CR or LF-LF format found = true; eorptr += 2; break; } else if ((eorptr <= mainBufferSpace - 4) && (CHAR_CR == *(eorptr)) && (CHAR_LF == *(eorptr + 1)) && (CHAR_CR == *(eorptr + 2)) && (CHAR_LF == *(eorptr + 3)) ) { // yes, MS-WINDOWS format found = true; eorptr += 4; break; } // else, continue on } } if (found) { // transfer the buffer, if necessary newMessageSize = eorptr - mainBufferEntry; // quickly take a peek at content-length char * cl = ci_local_strstr(mainBufferEntry, newMessageSize, RtspRecognizedFieldContentLength); if (NULL == cl) { // nothing visible ebFullSizeExpected = 0; } else if (cl >= mainBufferEntry + newMessageSize) { // it's not part of this particular message ebFullSizeExpected = 0; } else { cl += oscl_strlen(RtspRecognizedFieldContentLength); while (cl < eorptr && (isspaceNotNL(*cl) || (CHAR_COLON == *cl))) { ++cl; } uint32 atoi_tmp; PV_atoi(cl, 'd', atoi_tmp); ebFullSizeExpected = atoi_tmp; // fflush(stdout); } // now, on with the moving around ... if (RTSP_MAX_FULL_REQUEST_SIZE < newMessageSize) { // request too big oscl_memcpy(requestStruct->secondaryBuffer, mainBufferEntry, RTSP_MAX_FULL_REQUEST_SIZE); requestStruct->secondaryBuffer[RTSP_MAX_FULL_REQUEST_SIZE] = CHAR_NULL; requestStruct->secondaryBufferSizeUsed = newMessageSize; requestStruct->amMalformed = RTSPErrorTooBig; mainBufferEntry += newMessageSize; eorptr = mainBufferEntry; internalState = IS_ERROR_REQUEST_TOO_BIG; } else { // everything is peachy oscl_memcpy(requestStruct->secondaryBuffer, mainBufferEntry, newMessageSize); requestStruct->secondaryBuffer[ newMessageSize ] = CHAR_NULL; requestStruct->secondaryBufferSizeUsed = newMessageSize; mainBufferEntry += newMessageSize; eorptr = mainBufferEntry; internalState = IS_REQUEST_IS_READY; } dealWithLineContinuations(requestStruct); requestStruct->parseFirstFields(); } else { shouldMoveOverToBeginning = true; } } if (shouldMoveOverToBeginning) { // i.e. end of request was not found int sizeUsedSoFar = mainBufferSpace - mainBufferEntry; if (RTSP_PARSER_BUFFER_SIZE == sizeUsedSoFar) { // we hit the parser's buffer size internalState = IS_START_LOOKING_FOR_RESYNC; continueProcessing(); // xxx return; } if (mainBufferEntry != mainBuffer) { oscl_memmove(mainBuffer, mainBufferEntry, sizeUsedSoFar); mainBufferEntry = mainBuffer; eorptr = mainBufferEntry; mainBufferSpace = mainBufferEntry + sizeUsedSoFar; } else { // rewind eorptr eorptr -= 4; eorptr = (eorptr < mainBufferEntry) ? mainBufferEntry : eorptr; } } }
/* ======================================================================== */ SDP_ERROR_CODE SDPMPEG4MediaInfoParser::parseMediaInfo(const char *buff, const int index, SDPInfo *sdp, payloadVector payload_vec, bool isSipSdp, int alt_id, bool alt_def_id) { const char *current_start = buff; //Pointer to the beginning of the media text const char *end = buff + index; //Pointer to the end of the media text const char *line_start_ptr, *line_end_ptr; int VOLLength = 0; int fmtp_cnt = 0 ; bool framesize_found_in_fmtp = false; SDPAllocDestructDealloc<uint8> SDP_alloc; while (get_next_line(current_start, end, line_start_ptr, line_end_ptr)) { if ((!oscl_strncmp(line_start_ptr, "a=alt:", oscl_strlen("a=alt:"))) && (alt_def_id == false)) { line_start_ptr += oscl_strlen("a=alt:"); for (; *line_start_ptr != ':'; line_start_ptr++); line_start_ptr = line_start_ptr + 1; } if (!oscl_strncmp(line_start_ptr, "a=fmtp:", oscl_strlen("a=fmtp:"))) { char *tmp_start_line, *tmp_end_line; fmtp_cnt++ ; tmp_start_line = (char *)line_start_ptr + oscl_strlen("a=fmtp:"); tmp_start_line = (char *)skip_whitespace(tmp_start_line, line_end_ptr); if (tmp_start_line >= line_end_ptr) { break; } tmp_end_line = (char *)skip_to_whitespace(tmp_start_line, line_end_ptr); if (tmp_end_line < tmp_start_line) { break; } tmp_start_line = tmp_end_line + 1; tmp_start_line = (char *)skip_whitespace(tmp_start_line, line_end_ptr); if (tmp_start_line >= line_end_ptr) { break; } int ii = 0; const char *temp = tmp_start_line; for (ii = 0; ii < (line_end_ptr - tmp_start_line) ; ii++) { if ((tmp_start_line[ii] == ';') || (ii == (line_end_ptr - tmp_start_line - 1))) { tmp_end_line = tmp_start_line + ii; if ((line_end_ptr - tmp_start_line - 1) == ii) { tmp_end_line++; } if (!oscl_strncmp(temp, "config=", oscl_strlen("config="))) { int currentVOLLength; temp += oscl_strlen("config="); temp = skip_whitespace(temp, line_end_ptr); if (temp >= line_end_ptr) { PVMF_SDP_PARSER_LOGERROR((0, "SDPM4VMediaInfoParser::parseMediaInfo - Bad a=fmtp line format - Bad config field")); return SDP_BAD_MEDIA_FMTP; } currentVOLLength = (int)(tmp_end_line - temp) / 2; if (VOLLength < currentVOLLength) VOLLength = currentVOLLength; } if (tmp_end_line != line_end_ptr) temp = tmp_end_line + 1; temp = skip_whitespace(temp, line_end_ptr); if (temp >= line_end_ptr) { PVMF_SDP_PARSER_LOGERROR((0, "SDPM4VMediaInfoParser::parseMediaInfo - Bad a=fmtp line format")); return SDP_BAD_MEDIA_FMTP; } } } } current_start = line_end_ptr + 1; } if (fmtp_cnt == 0 && isSipSdp == false) { PVMF_SDP_PARSER_LOGERROR((0, "SDPM4VMediaInfoParser::parseMediaInfo - No fmtp line found")); return SDP_BAD_MEDIA_FORMAT; } if (VOLLength < 0) { VOLLength = 0; } bool altMedia = false; if (!alt_id || (alt_def_id == true)) altMedia = false; else altMedia = true; void *memory = sdp->alloc(sizeof(m4v_mediaInfo), altMedia); if (NULL == memory) { PVMF_SDP_PARSER_LOGERROR((0, "SDPM4VMediaInfoParser::parseMediaInfo - memory allocation failure")); return SDP_NO_MEMORY; } else { m4v_mediaInfo *m4Video = OSCL_PLACEMENT_NEW(memory, m4v_mediaInfo()); m4Video->setMediaInfoID(sdp->getMediaObjectIndex()); // Allocate memory to the payload specific objects for (uint32 ii = 0; ii < payload_vec.size(); ii++) { void* mem = m4Video->alloc(sizeof(M4vPayloadSpecificInfoType)); if (mem == NULL) { PVMF_SDP_PARSER_LOGERROR((0, "SDPM4VMediaInfoParser::parseMediaInfo - Memory allocation failure")); return SDP_NO_MEMORY; } else { M4vPayloadSpecificInfoType* payload = OSCL_PLACEMENT_NEW(mem, M4vPayloadSpecificInfoType(payload_vec[ii])); (void) payload; } } if (alt_id && !alt_def_id) { sdp->copyFmDefMedia(m4Video); //empty alternate & default track ID vectors. m4Video->resetAlternateTrackId(); m4Video->resetDependentTrackId(); } SDP_ERROR_CODE status = baseMediaInfoParser(buff, m4Video, index, alt_id, alt_def_id, isSipSdp); if (status != SDP_SUCCESS) { return status; } current_start = buff; while (get_next_line(current_start, end, line_start_ptr, line_end_ptr)) { switch (*line_start_ptr) { case 'a': { const char *sptr; if ((!oscl_strncmp(line_start_ptr, "a=alt:", oscl_strlen("a=alt:"))) && (alt_def_id == false)) { line_start_ptr += oscl_strlen("a=alt:"); for (; *line_start_ptr != ':'; line_start_ptr++); line_start_ptr = line_start_ptr + 1; } if (!oscl_strncmp(line_start_ptr, "a=framerate:", oscl_strlen("a=framerate:"))) { sptr = line_start_ptr + oscl_strlen("a=framerate:"); sptr = skip_whitespace(sptr, line_end_ptr); if (sptr >= line_end_ptr) { PVMF_SDP_PARSER_LOGERROR((0, "SDPM4VMediaInfoParser::parseMediaInfo - Bad a=framerate line format")); return SDP_BAD_MEDIA_FRAME_RATE; } OsclFloat rate; if (!PV_atof(sptr, line_end_ptr - sptr, rate)) return SDP_BAD_MEDIA_FORMAT; ((m4v_mediaInfo *)m4Video)->setFrameRate(rate); } if (!oscl_strncmp(line_start_ptr, "a=I_frame_interval:", oscl_strlen("a=I_frame_interval:"))) { sptr = line_start_ptr + oscl_strlen("a=I_frame_interval:"); sptr = skip_whitespace(sptr, line_end_ptr); if (sptr >= line_end_ptr) { PVMF_SDP_PARSER_LOGERROR((0, "SDPM4VMediaInfoParser::parseMediaInfo - Bad a=I_frame_interval line format")); return SDP_BAD_MEDIA_FRAME_INTERVAL; } uint32 ifi; if (PV_atoi(sptr, 'd', (line_end_ptr - sptr), ifi) == true)((m4v_mediaInfo *)m4Video)->setIFrameInterval(ifi); } if (!oscl_strncmp(line_start_ptr, "a=fmtp:", oscl_strlen("a=fmtp:"))) { const char *tmp_start_line, *tmp_end_line; tmp_start_line = line_start_ptr + oscl_strlen("a=fmtp:"); tmp_start_line = skip_whitespace(tmp_start_line, line_end_ptr); if (tmp_start_line >= line_end_ptr) { break; } tmp_end_line = skip_to_whitespace(tmp_start_line, line_end_ptr); if (tmp_end_line < tmp_start_line) { break; } uint32 payloadNumber; if (PV_atoi(tmp_start_line, 'd', (tmp_end_line - tmp_start_line), payloadNumber) == false) { PVMF_SDP_PARSER_LOGERROR((0, "SDPM4VMediaInfoParser::parseMediaInfo - Bad a=fmtp line format - Bad payload number")); return SDP_BAD_MEDIA_FMTP; } else { int p; if (!m4Video->lookupPayloadNumber(payloadNumber, p)) { fmtp_cnt--; break; } } M4vPayloadSpecificInfoType* payloadPtr = (M4vPayloadSpecificInfoType*)m4Video->getPayloadSpecificInfoTypePtr(payloadNumber); if (payloadPtr == NULL) { PVMF_SDP_PARSER_LOGERROR((0, "SDPM4VMediaInfoParser::parseMediaInfo - Bad a=fmtp line format - payload pointer not found for payload")); return SDP_PAYLOAD_MISMATCH; } PVMF_SDP_PARSER_LOGINFO((0, "SDPM4VMediaInfoParser::parseMediaInfo - processing payload number : %d", payloadNumber)); tmp_start_line = tmp_end_line + 1; tmp_start_line = skip_whitespace(tmp_start_line, line_end_ptr); if (tmp_start_line >= line_end_ptr) { break; } int ii = 0; const char *temp = tmp_start_line; for (ii = 0; ii < (line_end_ptr - tmp_start_line) ; ii++) { if ((tmp_start_line[ii] == ';') || (ii == (line_end_ptr - tmp_start_line - 1))) { tmp_end_line = tmp_start_line + ii; if (ii == (line_end_ptr - tmp_start_line - 1)) { tmp_end_line += 1; } if (!oscl_strncmp(temp, "config=", oscl_strlen("config="))) { uint8 *mptr = SDP_alloc.allocate(VOLLength); OsclRefCounterSA< SDPAllocDestructDealloc<uint8> > *refcnt = new OsclRefCounterSA< SDPAllocDestructDealloc<uint8> >(mptr); OsclSharedPtr<uint8> VOLPtr(mptr, refcnt); temp += oscl_strlen("config="); temp = skip_whitespace(temp, line_end_ptr); if (temp >= line_end_ptr) { PVMF_SDP_PARSER_LOGERROR((0, "SDPM4VMediaInfoParser::parseMediaInfo - Bad a=fmtp line format - Bad config field")); return SDP_BAD_MEDIA_FMTP; } VOLLength = (int)(tmp_end_line - temp) / 2; int idx = 0; for (idx = 0; idx < VOLLength; idx++) { uint32 val; //Set this value in the vol header array if (PV_atoi((temp + 2*idx), 'x', 2 , val) == false) { PVMF_SDP_PARSER_LOGERROR((0, "SDPM4VMediaInfoParser::parseMediaInfo - Bad a=fmtp line format - Bad config field")); return SDP_BAD_MEDIA_FMTP; } *(VOLPtr + idx) = (uint8)val; } payloadPtr->setVOLHeader(VOLPtr); payloadPtr->setVOLHeaderSize(VOLLength); payloadPtr->setDecoderSpecificInfo(VOLPtr); payloadPtr->setDecoderSpecificInfoSize(VOLLength); } if (!oscl_strncmp(temp, "profile-level-id=", oscl_strlen("profile-level-id="))) { temp += oscl_strlen("profile-level-id="); temp = skip_whitespace(temp, line_end_ptr); if (temp > line_end_ptr) { PVMF_SDP_PARSER_LOGERROR((0, "SDPM4VMediaInfoParser::parseMediaInfo - Bad a=fmtp line format - Bad profile-level-id field")); return SDP_BAD_MEDIA_FMTP; } uint32 pl; if (PV_atoi(temp, 'd', tmp_end_line - temp , pl) == true) payloadPtr->setProfileLevelID(pl); } if (!oscl_strncmp(temp, "framesize=", oscl_strlen("framesize="))) { temp += oscl_strlen("framesize="); temp = skip_whitespace(temp, tmp_end_line); framesize_found_in_fmtp = true; if (temp > tmp_end_line) { PVMF_SDP_PARSER_LOGERROR((0, "SDPM4VMediaInfoParser::parseMediaInfo - Bad a=fmtp line format - Bad framesize field")); return SDP_BAD_MEDIA_FMTP; } const char *end = NULL; int idx = 0; for (idx = 0; idx < (tmp_end_line - temp); idx++) { if (temp[idx] == '-') { end = temp + idx; } } if (end == NULL) { PVMF_SDP_PARSER_LOGERROR((0, "SDPM4VMediaInfoParser::parseMediaInfo - Bad a=fmtp line format - framesize width info missing")); return SDP_MISSING_MEDIA_DESCRIPTION; } uint32 width; if (PV_atoi(temp, 'd', (end - temp), width) == true) payloadPtr->setFrameWidth(width); temp = end + 1; temp = skip_whitespace(temp, tmp_end_line); if (temp > tmp_end_line) { PVMF_SDP_PARSER_LOGERROR((0, "SDPM4VMediaInfoParser::parseMediaInfo - Bad a=fmtp line format - framesize height info missing")); return SDP_BAD_MEDIA_FMTP; } uint32 height; if (PV_atoi(temp, 'd', tmp_end_line - temp, height) == true) payloadPtr->setFrameHeight(height); } if (!oscl_strncmp(temp, "decode_buf=", oscl_strlen("decode_buf="))) { temp += oscl_strlen("decode_buf="); temp = skip_whitespace(temp, tmp_end_line); if (temp > tmp_end_line) { PVMF_SDP_PARSER_LOGERROR((0, "SDPM4VMediaInfoParser::parseMediaInfo - Bad a=fmtp line format - Bad decode_buf field")); return SDP_BAD_MEDIA_FMTP; } uint32 dec; if (PV_atoi(temp, 'd', tmp_end_line - temp, dec) == true) payloadPtr->setMaxBufferSize(dec); } if (tmp_end_line != line_end_ptr) temp = tmp_end_line + 1; temp = skip_whitespace(temp, line_end_ptr); if (temp >= line_end_ptr) { PVMF_SDP_PARSER_LOGERROR((0, "SDPM4VMediaInfoParser::parseMediaInfo - Bad a=fmtp line format")); return SDP_BAD_MEDIA_FMTP; } } } } StrPtrLen fmsize("a=framesize:"); if (!oscl_strncmp(line_start_ptr, fmsize.c_str(), fmsize.length())) { uint32 width, height; const char *sptr = line_start_ptr + fmsize.length(); const char *eptr = skip_to_whitespace(sptr, line_end_ptr); if (sptr > eptr) { PVMF_SDP_PARSER_LOGERROR((0, "SDPM4VMediaInfoParser::parseMediaInfo - Bad a=framesize line format")); return SDP_BAD_MEDIA_FRAMESIZE; } uint32 payloadNo; if (PV_atoi(sptr, 'd', (eptr - sptr), payloadNo)) { int p; if (!((m4v_mediaInfo *)m4Video)->lookupPayloadNumber(payloadNo, p)) break; } else { PVMF_SDP_PARSER_LOGERROR((0, "SDPM4VMediaInfoParser::parseMediaInfo - Bad a=framesize line format - Bad payload number")); return SDP_BAD_MEDIA_FRAMESIZE; } M4vPayloadSpecificInfoType* payloadPtr2 = (M4vPayloadSpecificInfoType*)m4Video->getPayloadSpecificInfoTypePtr(payloadNo); if (payloadPtr2 == NULL) { PVMF_SDP_PARSER_LOGERROR((0, "SDPM4VMediaInfoParser::parseMediaInfo - Bad a=framesize line format - payload pointer not found for payload")); return SDP_PAYLOAD_MISMATCH; } sptr = eptr; sptr = skip_whitespace(sptr , line_end_ptr); for (;*eptr != '-' ; ++eptr); if (!PV_atoi(sptr, 'd', eptr - sptr, width)) { PVMF_SDP_PARSER_LOGERROR((0, "SDPM4VMediaInfoParser::parseMediaInfo - Bad a=framesize line format")); return SDP_BAD_MEDIA_FRAMESIZE; } eptr = eptr + 1; sptr = eptr; if (sptr > line_end_ptr) return SDP_BAD_MEDIA_FRAMESIZE; eptr = skip_to_line_term(sptr, line_end_ptr); if (!PV_atoi(sptr, 'd', eptr - sptr, height)) return SDP_BAD_MEDIA_FRAMESIZE; if (framesize_found_in_fmtp) { if ((int)width != payloadPtr2->getFrameWidth() || (int)height != payloadPtr2->getFrameHeight()) { return SDP_BAD_MEDIA_FRAMESIZE; } } else { payloadPtr2->setFrameWidth(width); payloadPtr2->setFrameHeight(height); } } } break; default: break; } current_start = line_end_ptr; } sessionDescription *session = sdp->getSessionInfo(); const char *altGroupBW = session->getAltGroupBW(); int length = session->getAltGroupBWLength(); if (length > 0) { status = setDependentMediaId(altGroupBW, length, m4Video, alt_id); if (status != SDP_SUCCESS) return SDP_BAD_MEDIA_ALT_ID; } const char *altGroupLANG = session->getAltGroupLANG(); length = session->getAltGroupLANGLength(); if (length > 0) { status = setDependentMediaId(altGroupLANG, length, m4Video, alt_id); if (status != SDP_SUCCESS) return SDP_BAD_MEDIA_ALT_ID; } if (m4Video->getCFieldStatus() || session->getCFieldStatus()) { //if sample rate is zero override with defaults Oscl_Vector<PayloadSpecificInfoTypeBase*, SDPParserAlloc> payloadSpecificInfoVector = m4Video->getPayloadSpecificInfoVector(); for (int ii = 0; ii < (int)payloadSpecificInfoVector.size();ii++) { if (payloadSpecificInfoVector[ii]->getSampleRate() == 0) { payloadSpecificInfoVector[ii]->sampleRate = PVMF_SDP_DEFAULT_MPEG4_VIDEO_SAMPLE_RATE; } } return SDP_SUCCESS; } else { PVMF_SDP_PARSER_LOGERROR((0, "SDPM4VMediaInfoParser::parseMediaInfo - No C field present")); return SDP_FAILURE_NO_C_FIELD; } } }
//Read and parse the config file //retval = -1 if the config file doesnt exist int8 ReadAndParseLoggerConfigFile() { int8 retval = 1; if (0 != iLogFile.Open(iLogFileName, Oscl_File::MODE_READ, iFileServer)) { retval = -1; } else { if (!iLogFileRead) { int32 nCharRead = iLogFile.Read(ibuffer, 1, sizeof(ibuffer)); //Parse the buffer for \n chars Oscl_Vector<char*, OsclMemAllocator> LogConfigStrings; const char *end_ptr = ibuffer + oscl_strlen(ibuffer) ; // Point just beyond the end const char *section_start_ptr; const char *line_start_ptr, *line_end_ptr; char* end_temp_ptr; int16 offset = 0; section_start_ptr = skip_whitespace_and_line_term(ibuffer, end_ptr); while (section_start_ptr < end_ptr) { if (!get_next_line(section_start_ptr, end_ptr, line_start_ptr, line_end_ptr)) { break; } section_start_ptr = line_end_ptr + 1; end_temp_ptr = (char*)line_end_ptr; *end_temp_ptr = '\0'; LogConfigStrings.push_back((char*)line_start_ptr); } //Populate the LoggerConfigElements vector { if (!LogConfigStrings.empty()) { Oscl_Vector<char*, OsclMemAllocator>::iterator it; it = LogConfigStrings.begin(); uint32 appenderType; PV_atoi(*it, 'd', oscl_strlen(*it), appenderType); iAppenderType = appenderType; if (LogConfigStrings.size() > 1) { for (it = LogConfigStrings.begin() + 1; it != LogConfigStrings.end(); it++) { char* CommaIndex = (char*)oscl_strstr(*it, ","); if (CommaIndex != NULL) { *CommaIndex = '\0'; LoggerConfigElement obj; uint32 logLevel; PV_atoi(*it, 'd', oscl_strlen(*it), logLevel); obj.iLogLevel = logLevel; obj.iLoggerString = CommaIndex + 1; iLoggerConfigElements.push_back(obj); } } } else { //Add the config element for complete logging fo all the modules LoggerConfigElement obj; obj.iLoggerString = ""; obj.iLogLevel = 8; iLoggerConfigElements.push_back(obj); } } } iLogFile.Close(); iLogFileRead = true; } } return retval; }