diff --git a/util/flv_tag.cpp b/util/flv_tag.cpp index 140183f3..f595bbff 100644 --- a/util/flv_tag.cpp +++ b/util/flv_tag.cpp @@ -17,7 +17,7 @@ std::string FLV::Error_Str = ""; /// - Not starting with the string "FLV". /// - The DataOffset is not 9 bytes. /// - The PreviousTagSize is not 0 bytes. -/// +/// /// Note that we see PreviousTagSize as part of the FLV header, not part of the tag header! bool FLV::check_header(char * header){ if (header[0] != 'F') return false; @@ -43,6 +43,27 @@ bool FLV::is_header(char * header){ return true; }//FLV::is_header +/// True if current tag is init data for this media type. +bool FLV::Tag::isInitData(){ + switch (data[0]){ + case 0x09: + switch (data[11] & 0xF0){ + case 0x50: return true; break; + } + if ((data[11] & 0x0F) == 7){ + switch (data[12]){ + case 0: return true; break; + } + } + break; + case 0x08: + if ((data[12] == 0) && ((data[11] & 0xF0) == 0xA0)){ + return true; + } + break; + } + return false; +} /// Returns a std::string describing the tag in detail. /// The string includes information about whether the tag is @@ -355,7 +376,7 @@ bool FLV::Tag::FileLoader(FILE * f){ int postflags = preflags | O_NONBLOCK; fcntl(fileno(f), F_SETFL, postflags); if (buf < 15){data = (char*)realloc(data, 15); buf = 15;} - + if (done){ //read a header if (FileReadUntil(data, 11, sofar, f)){ diff --git a/util/flv_tag.h b/util/flv_tag.h index 74d0ffa7..2ad39673 100644 --- a/util/flv_tag.h +++ b/util/flv_tag.h @@ -11,7 +11,7 @@ namespace FLV { extern char Header[13]; ///< Holds the last FLV header parsed. extern bool Parse_Error; ///< This variable is set to true if a problem is encountered while parsing the FLV. extern std::string Error_Str; ///< This variable is set if a problem is encountered while parsing the FLV. - + //functions bool check_header(char * header); ///< Checks a FLV Header for validness. bool is_header(char * header); ///< Checks the first 3 bytes for the string "FLV". @@ -22,6 +22,7 @@ namespace FLV { int len; ///< Actual length of tag. bool isKeyframe; ///< True if current tag is a video keyframe. char * data; ///< Pointer to tag buffer. + bool isInitData(); ///< True if current tag is init data for this media type. std::string tagType(); ///< Returns a std::string describing the tag in detail. unsigned int tagTime(); ///< Returns the 32-bit timestamp of this tag. void tagTime(unsigned int T); ///< Sets the 32-bit timestamp of this tag.