Simplified and optimized FLV input and tag to DTSC conversion.
This commit is contained in:
parent
a1a195b1e7
commit
4b9c8cee74
3 changed files with 44 additions and 12 deletions
|
@ -1032,6 +1032,38 @@ bool FLV::Tag::FileLoader(FILE * f) {
|
||||||
return false;
|
return false;
|
||||||
} //FLV_GetPacket
|
} //FLV_GetPacket
|
||||||
|
|
||||||
|
/// Returns 1 for video, 2 for audio, 3 for meta, 0 otherwise.
|
||||||
|
unsigned int FLV::Tag::getTrackID(){
|
||||||
|
switch (data[0]){
|
||||||
|
case 0x08: return 2;//audio track
|
||||||
|
case 0x09: return 1;//video track
|
||||||
|
case 0x12: return 3;//meta track
|
||||||
|
default: return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns a pointer to the raw media data for this packet.
|
||||||
|
char * FLV::Tag::getData(){
|
||||||
|
if (data[0] == 0x08 && (data[11] & 0xF0) == 0xA0) {
|
||||||
|
return data+13;
|
||||||
|
}
|
||||||
|
if (data[0] == 0x09 && (data[11] & 0x0F) == 7) {
|
||||||
|
return data+16;
|
||||||
|
}
|
||||||
|
return data+12;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the length of the raw media data for this packet.
|
||||||
|
unsigned int FLV::Tag::getDataLen(){
|
||||||
|
if (data[0] == 0x08 && (data[11] & 0xF0) == 0xA0) {
|
||||||
|
return len - 17;
|
||||||
|
}
|
||||||
|
if (data[0] == 0x09 && (data[11] & 0x0F) == 7) {
|
||||||
|
return len - 20;
|
||||||
|
}
|
||||||
|
return len - 16;
|
||||||
|
}
|
||||||
|
|
||||||
JSON::Value FLV::Tag::toJSON(DTSC::Meta & metadata, AMF::Object & amf_storage, unsigned int reTrack) {
|
JSON::Value FLV::Tag::toJSON(DTSC::Meta & metadata, AMF::Object & amf_storage, unsigned int reTrack) {
|
||||||
JSON::Value pack_out; // Storage for outgoing metadata.
|
JSON::Value pack_out; // Storage for outgoing metadata.
|
||||||
|
|
||||||
|
|
|
@ -56,6 +56,9 @@ namespace FLV {
|
||||||
JSON::Value toJSON(DTSC::Meta & metadata, AMF::Object & amf_storage, unsigned int reTrack = 0);
|
JSON::Value toJSON(DTSC::Meta & metadata, AMF::Object & amf_storage, unsigned int reTrack = 0);
|
||||||
bool MemLoader(char * D, unsigned int S, unsigned int & P);
|
bool MemLoader(char * D, unsigned int S, unsigned int & P);
|
||||||
bool FileLoader(FILE * f);
|
bool FileLoader(FILE * f);
|
||||||
|
unsigned int getTrackID();
|
||||||
|
char * getData();
|
||||||
|
unsigned int getDataLen();
|
||||||
protected:
|
protected:
|
||||||
int buf; ///< Maximum length of buffer space.
|
int buf; ///< Maximum length of buffer space.
|
||||||
bool done; ///< Body reading done?
|
bool done; ///< Body reading done?
|
||||||
|
|
|
@ -89,29 +89,26 @@ namespace Mist {
|
||||||
}
|
}
|
||||||
|
|
||||||
void inputFLV::getNext(bool smart) {
|
void inputFLV::getNext(bool smart) {
|
||||||
static JSON::Value thisPack;
|
|
||||||
static AMF::Object amf_storage;
|
|
||||||
thisPack.null();
|
|
||||||
long long int lastBytePos = ftell(inFile);
|
long long int lastBytePos = ftell(inFile);
|
||||||
FLV::Tag tmpTag;
|
FLV::Tag tmpTag;
|
||||||
while (!feof(inFile) && !FLV::Parse_Error){
|
while (!feof(inFile) && !FLV::Parse_Error){
|
||||||
if (tmpTag.FileLoader(inFile)){
|
if (tmpTag.FileLoader(inFile)){
|
||||||
thisPack = tmpTag.toJSON(myMeta, amf_storage);
|
if ( !selectedTracks.count(tmpTag.getTrackID())){
|
||||||
thisPack["bpos"] = lastBytePos;
|
return getNext();
|
||||||
if ( !selectedTracks.count(thisPack["trackid"].asInt())){
|
|
||||||
getNext();
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (FLV::Parse_Error){
|
if (feof(inFile)){
|
||||||
FAIL_MSG("FLV error: %s", FLV::Error_Str.c_str());
|
|
||||||
thisPack.null();
|
|
||||||
thisPacket.null();
|
thisPacket.null();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
std::string tmpStr = thisPack.toNetPacked();
|
if (FLV::Parse_Error){
|
||||||
thisPacket.reInit(tmpStr.data(), tmpStr.size());
|
FAIL_MSG("FLV error: %s", FLV::Error_Str.c_str());
|
||||||
|
thisPacket.null();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
thisPacket.genericFill(tmpTag.tagTime(), tmpTag.offset(), tmpTag.getTrackID(), tmpTag.getData(), tmpTag.getDataLen(), lastBytePos, tmpTag.isKeyframe); //init packet from tmpTags data
|
||||||
}
|
}
|
||||||
|
|
||||||
void inputFLV::seek(int seekTime) {
|
void inputFLV::seek(int seekTime) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue