Compatibility improvements as well as simplification to RTMP push input.

This commit is contained in:
Thulinma 2015-05-21 19:10:05 +02:00
parent 7e2c4a8318
commit 17aa6bbbb6
5 changed files with 90 additions and 147 deletions

View file

@ -67,11 +67,12 @@ namespace Mist {
//Create header file from FLV data
fseek(inFile, 13, SEEK_SET);
FLV::Tag tmpTag;
AMF::Object amf_storage;
long long int lastBytePos = 13;
while (!feof(inFile) && !FLV::Parse_Error){
if (tmpTag.FileLoader(inFile)){
lastPack.null();
lastPack = tmpTag.toJSON(myMeta);
lastPack = tmpTag.toJSON(myMeta, amf_storage);
lastPack["bpos"] = lastBytePos;
myMeta.update(lastPack);
lastBytePos = ftell(inFile);
@ -89,12 +90,13 @@ 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);
thisPack = tmpTag.toJSON(myMeta, amf_storage);
thisPack["bpos"] = lastBytePos;
if ( !selectedTracks.count(thisPack["trackid"].asInt())){
getNext();

View file

@ -792,60 +792,28 @@ namespace Mist {
case 8: //audio data
case 9: //video data
case 18: {//meta data
pushData & p = pushes[next.cs_id];
static std::map<unsigned int, AMF::Object> pushMeta;
if (!isInitialized) {
DEBUG_MSG(DLVL_MEDIUM, "Received useless media data\n");
myConn.close();
break;
}
F.ChunkLoader(next);
JSON::Value pack_out = F.toJSON(p.meta);
AMF::Object * amf_storage = 0;
if (F.data[0] == 0x12 || pushMeta.count(next.cs_id) || !pushMeta.size()){
amf_storage = &(pushMeta[next.cs_id]);
}else{
amf_storage = &(pushMeta.begin()->second);
}
JSON::Value pack_out = F.toJSON(myMeta, *amf_storage, next.cs_id*3 + (F.data[0] == 0x09 ? 0 : (F.data[0] == 0x08 ? 1 : 2) ));
if ( !pack_out.isNull()){
//Check for backwards timestamps
if (pack_out["time"].asInt() < p.meta.tracks[pack_out["trackid"].asInt()].lastms){
///Reset all internals
p.sending = false;
p.counter = 0;
p.preBuf.clear();
p.meta = DTSC::Meta();
pack_out = F.toJSON(p.meta);//Reinitialize the metadata with this packet.
///Reset negotiation with buffer
userClient.finish();
userClient = IPC::sharedClient(streamName + "_users", PLAY_EX_SIZE, true);
}
pack_out["trackid"] = pack_out["trackid"].asInt() + next.cs_id * 3;
if ( !p.sending){
p.counter++;
if (p.counter > 8){
p.sending = true;
if (myMeta.tracks.count(1)){
myMeta = DTSC::Meta();
}
for (unsigned int i = 1; i < 4; ++i){
if (p.meta.tracks.count(i)){
myMeta.tracks[next.cs_id*3+i] = p.meta.tracks[i];
}
}
if (!userClient.getData()){
char userPageName[NAME_BUFFER_SIZE];
snprintf(userPageName, NAME_BUFFER_SIZE, SHM_USERS, streamName.c_str());
userClient = IPC::sharedClient(userPageName, 30, true);
}
for (std::map<unsigned int,DTSC::Track>::iterator it = myMeta.tracks.begin(); it != myMeta.tracks.end(); it++){
DEBUG_MSG(DLVL_MEDIUM, "Starting negotiation for track %d", it->first);
continueNegotiate(it->first);
}
for (std::deque<JSON::Value>::iterator it = p.preBuf.begin(); it != p.preBuf.end(); it++){
bufferLivePacket((*it));
}
p.preBuf.clear(); //clear buffer
bufferLivePacket(pack_out);
}else{
p.preBuf.push_back(pack_out);
}
}else{
bufferLivePacket(pack_out);
if (!userClient.getData()){
char userPageName[NAME_BUFFER_SIZE];
snprintf(userPageName, NAME_BUFFER_SIZE, SHM_USERS, streamName.c_str());
userClient = IPC::sharedClient(userPageName, 30, true);
}
continueNegotiate(pack_out["trackid"].asInt());
bufferLivePacket(pack_out);
}
break;
}

View file

@ -6,19 +6,6 @@
namespace Mist {
class pushData {
public:
DTSC::Meta meta;
bool sending;
int counter;
std::deque<JSON::Value> preBuf;
pushData(){
sending = false;
counter = 0;
}
};
class OutRTMP : public Output {
public:
OutRTMP(Socket::Connection & conn);
@ -33,7 +20,6 @@ namespace Mist {
void parseChunk(Socket::Buffer & inputBuffer);
void parseAMFCommand(AMF::Object & amfData, int messageType, int streamId);
void sendCommand(AMF::Object & amfReply, int messageType, int streamId);
std::map<unsigned int, pushData> pushes;
};
}