Simplified and optimized FLV input and tag to DTSC conversion.

This commit is contained in:
Thulinma 2015-07-22 12:37:09 +02:00
parent a1a195b1e7
commit 4b9c8cee74
3 changed files with 44 additions and 12 deletions

View file

@ -1032,6 +1032,38 @@ bool FLV::Tag::FileLoader(FILE * f) {
return false;
} //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 pack_out; // Storage for outgoing metadata.

View file

@ -56,6 +56,9 @@ namespace FLV {
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 FileLoader(FILE * f);
unsigned int getTrackID();
char * getData();
unsigned int getDataLen();
protected:
int buf; ///< Maximum length of buffer space.
bool done; ///< Body reading done?

View file

@ -89,29 +89,26 @@ namespace Mist {
}
void inputFLV::getNext(bool smart) {
static JSON::Value thisPack;
static AMF::Object amf_storage;
thisPack.null();
long long int lastBytePos = ftell(inFile);
FLV::Tag tmpTag;
while (!feof(inFile) && !FLV::Parse_Error){
if (tmpTag.FileLoader(inFile)){
thisPack = tmpTag.toJSON(myMeta, amf_storage);
thisPack["bpos"] = lastBytePos;
if ( !selectedTracks.count(thisPack["trackid"].asInt())){
getNext();
if ( !selectedTracks.count(tmpTag.getTrackID())){
return getNext();
}
break;
}
}
if (FLV::Parse_Error){
FAIL_MSG("FLV error: %s", FLV::Error_Str.c_str());
thisPack.null();
if (feof(inFile)){
thisPacket.null();
return;
}
std::string tmpStr = thisPack.toNetPacked();
thisPacket.reInit(tmpStr.data(), tmpStr.size());
if (FLV::Parse_Error){
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) {