From 46fed13161fdd0419b343f11a047cf27adcaf469 Mon Sep 17 00:00:00 2001 From: Erik Zandvliet Date: Thu, 30 May 2013 11:47:51 +0200 Subject: [PATCH] Made single bitrate files in DTSCv2 style work on HTTP Smooth. --- src/connectors/conn_http_smooth.cpp | 23 +++++++++++++++++++---- src/converters/dtscfix.cpp | 5 +++-- src/converters/dtscmerge.cpp | 19 +++++++++---------- 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/src/connectors/conn_http_smooth.cpp b/src/connectors/conn_http_smooth.cpp index ba488a42..7d3cea3b 100644 --- a/src/connectors/conn_http_smooth.cpp +++ b/src/connectors/conn_http_smooth.cpp @@ -75,9 +75,10 @@ namespace Connector_HTTP { "Name=\"audio\" " "Chunks=\"" << allAudio.ObjBegin()->second["keytime"].size() << "\" " "Url=\"Q({bitrate})/A({start time})\">\n"; + int index = 1; for (JSON::ObjIter oIt = allAudio.ObjBegin(); oIt != allAudio.ObjEnd(); oIt++){ Result << "second["trackid"].asInt() << "\" " + "Index=\"" << index << "\" " "Bitrate=\"" << oIt->second["bps"].asInt() * 8 << "\" " "CodecPrivateData=\"" << std::hex; for (int i = 0; i < oIt->second["init"].asString().size(); i++){ @@ -90,6 +91,7 @@ namespace Connector_HTTP { "PacketSize=\"4\" " "AudioTag=\"255\" " "FourCC=\"AACL\" />\n"; + index++; } for (unsigned int i = 0; i < allAudio.ObjBegin()->second["keylen"].size(); i++){ Result << "\n"; + int index = 1; for (JSON::ObjIter oIt = allVideo.ObjBegin(); oIt != allVideo.ObjEnd(); oIt++){ //Add video qualities Result << "second["trackid"].asInt() << "\" " + "Index=\"" << index << "\" " "Bitrate=\"" << oIt->second["bps"].asInt() * 8 << "\" " "CodecPrivateData=\"" << std::hex; MP4::AVCC avccbox; @@ -128,6 +131,7 @@ namespace Connector_HTTP { "MaxWidth=\"" << oIt->second["width"].asInt() << "\" " "MaxHeight=\"" << oIt->second["height"].asInt() << "\" " "FourCC=\"AVC1\" />\n"; + index++; } for (unsigned int i = 0; i < allVideo.ObjBegin()->second["keylen"].size(); i++){ Result << "second["trackid"].asInt() << "\n"; + //Select the correct track ID + for (JSON::ObjIter vIt = allVideo.ObjBegin(); vIt != allVideo.ObjEnd(); vIt++){ + if (vIt->second["bps"].asInt() == selectedQuality){ + sstream << "t " << vIt->second["trackid"].asInt() << "\n"; + } + } } if (wantsAudio){ - sstream << "t " << allAudio.ObjBegin()->second["trackid"].asInt() << "\n"; + //Select the correct track ID + for (JSON::ObjIter aIt = allAudio.ObjBegin(); aIt != allAudio.ObjEnd(); aIt++){ + if (aIt->second["bps"].asInt() == selectedQuality){ + sstream << "t " << aIt->second["trackid"].asInt() << "\n"; + } + } } sstream << "s " << (requestedTime / 10000) << "\no \n"; ss.SendNow(sstream.str().c_str()); diff --git a/src/converters/dtscfix.cpp b/src/converters/dtscfix.cpp index a6e4fa93..0d22336b 100644 --- a/src/converters/dtscfix.cpp +++ b/src/converters/dtscfix.cpp @@ -10,7 +10,7 @@ namespace Converters { class HeaderEntryDTSC { public: - HeaderEntryDTSC() : totalSize(0), lastKeyTime(-1000), trackID(0), firstms(-1), lastms(0), keynum(0) {} + HeaderEntryDTSC() : totalSize(0), lastKeyTime(-5000), trackID(0), firstms(-1), lastms(0), keynum(0) {} long long unsigned int totalSize; long long int lastKeyTime; long long int trackID; @@ -68,6 +68,7 @@ namespace Converters { trackIDs.insert(std::pair(it->first,it->second["trackid"].asInt())); trackData[it->first].type = it->second["type"].asString(); trackData[it->first].trackID = it->second["trackid"].asInt(); + trackData[it->first].type = it->second["type"].asString(); if (it->second["trackid"].asInt() >= nextFreeID){ nextFreeID = it->second["trackid"].asInt() + 1; } @@ -120,7 +121,7 @@ namespace Converters { } } if( currentID == "" ) { - fprintf(stderr, "Found a v2 packet with id %d\n", F.getJSON()["trackid"].asInt()); + fprintf(stderr, "Found an unknown v2 packet with id %d\n", F.getJSON()["trackid"].asInt()); F.seekNext(); continue; //should create new track but this shouldnt be needed... diff --git a/src/converters/dtscmerge.cpp b/src/converters/dtscmerge.cpp index 867a9045..1b54ea35 100644 --- a/src/converters/dtscmerge.cpp +++ b/src/converters/dtscmerge.cpp @@ -117,23 +117,22 @@ namespace Converters { outFile.writeHeader(tmpWrite,true); } + std::set trackSelector; for (std::multimap::iterator sortIt = allSorted.begin(); sortIt != allSorted.end(); sortIt++){ - inFiles[sortIt->second.fileName].seek_bpos(sortIt->second.keyBPos); - while (inFiles[sortIt->second.fileName].getBytePos() < sortIt->second.endBPos){ - JSON::Value translate = inFiles[sortIt->second.fileName].getJSON(); - if (translate["trackid"].asInt() == sortIt->second.trackID){ - translate["trackid"] = trackMapping[sortIt->second.fileName][translate["trackid"].asInt()]; - outFile.writePacket(translate); - } + trackSelector.clear(); + trackSelector.insert(sortIt->second.trackID); + inFiles[sortIt->second.fileName].selectTracks(trackSelector); + inFiles[sortIt->second.fileName].seek_time(sortIt->second.keyTime); + inFiles[sortIt->second.fileName].seekNext(); + while (inFiles[sortIt->second.fileName].getJSON() && inFiles[sortIt->second.fileName].getBytePos() < sortIt->second.endBPos && !inFiles[sortIt->second.fileName].reachedEOF()){ + inFiles[sortIt->second.fileName].getJSON()["trackid"] = trackMapping[sortIt->second.fileName][inFiles[sortIt->second.fileName].getJSON()["trackid"].asInt()]; + outFile.writePacket(inFiles[sortIt->second.fileName].getJSON()); inFiles[sortIt->second.fileName].seekNext(); } } - fprintf(stderr, "%s\n", newMeta.toPrettyString().c_str()); - fprintf(stderr, "Oldheader (%d):\n%s\n", meta.toPacked().size(), meta.toPrettyString().c_str()); std::string writeMeta = newMeta.toPacked(); meta["moreheader"] = outFile.addHeader(writeMeta); - fprintf(stderr, "Newheader (%d):\n%s\n", meta.toPacked().size(), meta.toPrettyString().c_str()); writeMeta = meta.toPacked(); outFile.writeHeader(writeMeta);