diff --git a/src/output/output_hls.cpp b/src/output/output_hls.cpp index 78a3f37e..185a6b02 100644 --- a/src/output/output_hls.cpp +++ b/src/output/output_hls.cpp @@ -112,8 +112,37 @@ namespace Mist { cfg->addBasicConnectorOptions(capa); config = cfg; } - //HIER + ///this function generates the PMT packet + std::string OutHLS::createPMT(){ + TS::ProgramMappingTable PMT; + PMT.PID(4096); + PMT.setTableId(2); + PMT.setSectionLength(0xB017); + PMT.setProgramNumber(1); + PMT.setVersionNumber(0); + PMT.setCurrentNextIndicator(0); + PMT.setSectionNumber(0); + PMT.setLastSectionNumber(0); + PMT.setPCRPID(0x100 + (*(selectedTracks.begin())) - 1); + PMT.setProgramInfoLength(0); + short id = 0; + //for all selected tracks + for (std::set::iterator it = selectedTracks.begin(); it != selectedTracks.end(); it++){ + if (myMeta.tracks[*it].codec == "H264"){ + PMT.setStreamType(0x1B,id); + }else if (myMeta.tracks[*it].codec == "AAC"){ + PMT.setStreamType(0x0F,id); + }else if (myMeta.tracks[*it].codec == "MP3"){ + PMT.setStreamType(0x03,id); + } + PMT.setElementaryPID(0x100 + (*it) - 1, id); + PMT.setESInfoLength(0,id); + id++; + } + PMT.calcCRC(); + return PMT.getStrBuf(); + } void OutHLS::fillPacket(bool & first, const char * data, size_t dataLen, char & ContCounter){ @@ -123,7 +152,8 @@ namespace Mist { PackData.Clear(); if (PacketNumber % 42 == 0){ HTTP_S.Chunkify(TS::PAT, 188, myConn); - HTTP_S.Chunkify(TS::PMT, 188, myConn); + std::string PMT = createPMT(); + HTTP_S.Chunkify(PMT, myConn); PacketNumber += 2; } } @@ -131,11 +161,7 @@ namespace Mist { if (!dataLen){return;} if (PackData.BytesFree() == 184){ - if (myMeta.tracks[currentPacket.getTrackId()].type == "video"){ - PackData.PID(0x100); - }else{ - PackData.PID(0x101); - } + PackData.PID(0x100 - 1 + currentPacket.getTrackId()); PackData.ContinuityCounter(ContCounter++); if (first){ PackData.UnitStart(1); diff --git a/src/output/output_hls.h b/src/output/output_hls.h index 42358ad6..900f3fd3 100644 --- a/src/output/output_hls.h +++ b/src/output/output_hls.h @@ -10,13 +10,13 @@ namespace Mist { OutHLS(Socket::Connection & conn); ~OutHLS(); static void init(Util::Config * cfg); - void onRequest(); void onFail(); void sendNext(); protected: HTTP::Parser HTTP_S; - HTTP::Parser HTTP_R; + HTTP::Parser HTTP_R; + std::string createPMT(); void fillPacket(bool & first, const char * data, size_t dataLen, char & ContCounter); std::string liveIndex(); std::string liveIndex(int tid); diff --git a/src/output/output_ts.cpp b/src/output/output_ts.cpp index 074c7213..7656d4ec 100644 --- a/src/output/output_ts.cpp +++ b/src/output/output_ts.cpp @@ -67,11 +67,7 @@ namespace Mist { if (!dataLen){return;} if (PackData.BytesFree() == 184){ - if (myMeta.tracks[currentPacket.getTrackId()].type == "video"){ - PackData.PID(0x100); - }else{ - PackData.PID(0x101); - } + PackData.PID(0x100 - 1 + currentPacket.getTrackId()); PackData.ContinuityCounter(ContCounter++); if (first){ PackData.UnitStart(1); @@ -138,21 +134,6 @@ namespace Mist { ///this function generates the PMT packet std::string OutTS::createPMT(){ - //0x02 = table ID = 2 = PMT - //0xB017 = section syntax(1) = 1, 0(1)=0, reserved(2) = 3, section_len(12) = 23 - //0x0001 = ProgNo = 1 - //0xC1 = reserved(2) = 3, version(5)=0, curr_next_indi(1) = 1 - //0x00 = section_number = 0 - //0x00 = last_section_no = 0 - //0xE100 = reserved(3) = 7, PCR_PID(13) = 0x100 - //0xF000 = reserved(4) = 15, proginfolen = 0 - //0x1B = streamtype = 27 = H264 - //0xE100 = reserved(3) = 7, elem_ID(13) = 0x100 - //0xF000 = reserved(4) = 15, es_info_len = 0 - //0x0F = streamtype = 15 = audio with ADTS transport syntax - //0xE101 = reserved(3) = 7, elem_ID(13) = 0x101 - //0xF000 = reserved(4) = 15, es_info_len = 0 - //0x2F44B99B = CRC32 TS::ProgramMappingTable PMT; PMT.PID(4096); PMT.setTableId(2); @@ -179,7 +160,6 @@ namespace Mist { id++; } PMT.calcCRC(); - INFO_MSG("stringsize: %d %s", PMT.getStrBuf().size(), PMT.toPrettyString(0).c_str()); return PMT.getStrBuf(); }