From cddf0192f6a8fb985a700eb335b696444472c2eb Mon Sep 17 00:00:00 2001 From: Erik Zandvliet Date: Tue, 8 Jan 2013 14:27:13 +0100 Subject: [PATCH] Working HLS video (not audio) for bipbop video --- lib/mp4.cpp | 1 + lib/mp4.h | 1 + lib/ts_packet.cpp | 20 ++++++++++++++++---- lib/ts_packet.h | 1 + 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/mp4.cpp b/lib/mp4.cpp index e2681cac..94575003 100644 --- a/lib/mp4.cpp +++ b/lib/mp4.cpp @@ -2055,6 +2055,7 @@ namespace MP4 { void AVCC::setPayload(std::string newPayload){ if ( !reserve(0, payloadSize(), newPayload.size())){ + std::cerr << "Cannot allocate enough memory for payload" << std::endl; return; } memcpy((char*)payload(), (char*)newPayload.c_str(), newPayload.size()); diff --git a/lib/mp4.h b/lib/mp4.h index 032462ef..7f631dae 100644 --- a/lib/mp4.h +++ b/lib/mp4.h @@ -1,6 +1,7 @@ #pragma once #include #include +#include #include #include #include diff --git a/lib/ts_packet.cpp b/lib/ts_packet.cpp index 07792124..74b4e9b4 100644 --- a/lib/ts_packet.cpp +++ b/lib/ts_packet.cpp @@ -48,6 +48,9 @@ int TS::Packet::PID(){ /// Sets the Continuity Counter of a single TS::Packet. /// \param NewContinuity The new Continuity Counter of the packet. void TS::Packet::ContinuityCounter(int NewContinuity){ + if (strBuf.size() < 4){ + strBuf.resize(4); + } strBuf[3] = (strBuf[3] & 0xF0) + (NewContinuity & 0x0F); } @@ -211,16 +214,16 @@ void TS::Packet::RandomAccess(int NewVal){ void TS::Packet::DefaultPAT(){ static int MyCntr = 0; strBuf = std::string(TS::PAT, 188); - ContinuityCounter(MyCntr); - MyCntr = ((MyCntr + 1) % 0x10); + ContinuityCounter(MyCntr++); + MyCntr %= 0x10; } /// Transforms the TS::Packet into a standard Program Mapping Table void TS::Packet::DefaultPMT(){ static int MyCntr = 0; strBuf = std::string(TS::PMT, 188); - ContinuityCounter(MyCntr); - MyCntr = ((MyCntr + 1) % 0x10); + ContinuityCounter(MyCntr++); + MyCntr %= 0x10; } /// Generates a string from the contents of the TS::Packet @@ -298,6 +301,15 @@ void TS::Packet::FillFree(std::string & NewVal){ NewVal.erase(0, toWrite); } +/// Fills the free bytes of the TS::Packet. +/// Stores as many bytes from NewVal as possible in the packet. +/// \param NewVal The data to store in the packet. +int TS::Packet::FillFree(const char* NewVal, int maxLen){ + int toWrite = std::min((int)(188 - strBuf.size()), maxLen); + strBuf += std::string(NewVal, toWrite); + return toWrite; +} + /// Adds NumBytes of stuffing to the TS::Packet. /// \param NumBytes the amount of stuffing bytes. void TS::Packet::AddStuffing(int NumBytes){ diff --git a/lib/ts_packet.h b/lib/ts_packet.h index 5525958b..7ea77feb 100644 --- a/lib/ts_packet.h +++ b/lib/ts_packet.h @@ -43,6 +43,7 @@ namespace TS { void PESVideoLeadIn(int NewLen, long long unsigned int PTS = 1); void PESAudioLeadIn(int NewLen, uint64_t PTS = 0); void FillFree(std::string & PackageData); + int FillFree(const char* PackageData, int maxLen); void AddStuffing(int NumBytes); private: //int Free;