Finally fixed long standing RTMP sync issue. Also added support for getting/setting FLV tag offsets.
This commit is contained in:
parent
01d008a56c
commit
b78e9bc562
3 changed files with 29 additions and 10 deletions
|
@ -262,6 +262,25 @@ std::string FLV::Tag::tagType(){
|
||||||
return R.str();
|
return R.str();
|
||||||
} //FLV::Tag::tagtype
|
} //FLV::Tag::tagtype
|
||||||
|
|
||||||
|
/// Returns the 24-bit offset of this tag.
|
||||||
|
/// Returns 0 if the tag isn't H264
|
||||||
|
int FLV::Tag::offset(){
|
||||||
|
if (data[11] & 0x0F == 7){
|
||||||
|
return (((data[13] << 16) + (data[14] << 8) + data[15]) << 8) >> 8;
|
||||||
|
}else{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
} //offset getter
|
||||||
|
|
||||||
|
/// Sets the 24-bit offset of this tag.
|
||||||
|
/// Ignored if the tag isn't H264
|
||||||
|
void FLV::Tag::offset(int o){
|
||||||
|
if (data[11] & 0x0F != 7){return;}
|
||||||
|
data[13] = (o >> 16) & 0xFF;
|
||||||
|
data[14] = (o >> 8) & 0XFF;
|
||||||
|
data[15] = o & 0xFF;
|
||||||
|
} //offset setter
|
||||||
|
|
||||||
/// Returns the 32-bit timestamp of this tag.
|
/// Returns the 32-bit timestamp of this tag.
|
||||||
unsigned int FLV::Tag::tagTime(){
|
unsigned int FLV::Tag::tagTime(){
|
||||||
return (data[4] << 16) + (data[5] << 8) + data[6] + (data[7] << 24);
|
return (data[4] << 16) + (data[5] << 8) + data[6] + (data[7] << 24);
|
||||||
|
@ -401,10 +420,7 @@ bool FLV::Tag::DTSCLoader(DTSC::Stream & S){
|
||||||
}else{
|
}else{
|
||||||
data[12] = 2;
|
data[12] = 2;
|
||||||
}
|
}
|
||||||
int offset = S.getPacket()["offset"].asInt();
|
offset(S.getPacket()["offset"].asInt());
|
||||||
data[13] = (offset >> 16) & 0xFF;
|
|
||||||
data[14] = (offset >> 8) & 0XFF;
|
|
||||||
data[15] = offset & 0xFF;
|
|
||||||
}
|
}
|
||||||
data[11] = 0;
|
data[11] = 0;
|
||||||
if (track.isMember("codec") && track["codec"].asStringRef() == "H264"){
|
if (track.isMember("codec") && track["codec"].asStringRef() == "H264"){
|
||||||
|
@ -1174,9 +1190,7 @@ JSON::Value FLV::Tag::toJSON(JSON::Value & metadata){
|
||||||
pack_out["nalu_end"] = 1;
|
pack_out["nalu_end"] = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
int offset = (data[13] << 16) + (data[14] << 8) + data[15];
|
pack_out["offset"] = offset();
|
||||||
offset = (offset << 8) >> 8;
|
|
||||||
pack_out["offset"] = offset;
|
|
||||||
if (len < 21){
|
if (len < 21){
|
||||||
return JSON::Value();
|
return JSON::Value();
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,8 +35,10 @@ namespace FLV {
|
||||||
const char * getAudioCodec(); ///< Returns a c-string with the audio codec name.
|
const char * getAudioCodec(); ///< Returns a c-string with the audio codec name.
|
||||||
const char * getVideoCodec(); ///< Returns a c-string with the video codec name.
|
const char * getVideoCodec(); ///< Returns a c-string with the video codec name.
|
||||||
std::string tagType(); ///< Returns a std::string describing the tag in detail.
|
std::string tagType(); ///< Returns a std::string describing the tag in detail.
|
||||||
unsigned int tagTime(); ///< Returns the 32-bit timestamp of this tag.
|
unsigned int tagTime();
|
||||||
void tagTime(unsigned int T); ///< Sets the 32-bit timestamp of this tag.
|
void tagTime(unsigned int T);
|
||||||
|
int offset();
|
||||||
|
void offset(int o);
|
||||||
Tag(); ///< Constructor for a new, empty, tag.
|
Tag(); ///< Constructor for a new, empty, tag.
|
||||||
Tag(const Tag& O); ///< Copy constructor, copies the contents of an existing tag.
|
Tag(const Tag& O); ///< Copy constructor, copies the contents of an existing tag.
|
||||||
Tag & operator=(const Tag& O); ///< Assignment operator - works exactly like the copy constructor.
|
Tag & operator=(const Tag& O); ///< Assignment operator - works exactly like the copy constructor.
|
||||||
|
|
|
@ -423,7 +423,10 @@ std::string & RTMPStream::SendMedia(unsigned char msg_type_id, unsigned char * d
|
||||||
/// \param tag FLV::Tag with media to send.
|
/// \param tag FLV::Tag with media to send.
|
||||||
std::string & RTMPStream::SendMedia(FLV::Tag & tag){
|
std::string & RTMPStream::SendMedia(FLV::Tag & tag){
|
||||||
static RTMPStream::Chunk ch;
|
static RTMPStream::Chunk ch;
|
||||||
ch.cs_id = ((unsigned char)tag.data[0]);
|
//Commented bit is more efficient and correct according to RTMP spec.
|
||||||
|
//Simply passing "4" is the only thing that actually plays correctly, though.
|
||||||
|
//Adobe, if you're ever reading this... wtf? Seriously.
|
||||||
|
ch.cs_id = 4;//((unsigned char)tag.data[0]);
|
||||||
ch.timestamp = tag.tagTime();
|
ch.timestamp = tag.tagTime();
|
||||||
ch.len = tag.len - 15;
|
ch.len = tag.len - 15;
|
||||||
ch.real_len = tag.len - 15;
|
ch.real_len = tag.len - 15;
|
||||||
|
|
Loading…
Add table
Reference in a new issue