Merged in TS fixes/unification (and other small changes) by Wouter Spruit

This commit is contained in:
Thulinma 2015-03-05 12:13:23 +01:00
parent bd012b3b35
commit 6a6a8915d2
4 changed files with 362 additions and 453 deletions

View file

@ -561,6 +561,7 @@ void HTTP::Parser::Chunkify(const char * data, unsigned int size, Socket::Connec
}else{ }else{
SetHeader("Content-Length", body.length()); SetHeader("Content-Length", body.length());
SendResponse("200", "OK", conn); SendResponse("200", "OK", conn);
Clean();
} }
return; return;
} }
@ -587,6 +588,7 @@ void HTTP::Parser::Chunkify(const char * data, unsigned int size, Socket::Connec
//close the connection if this was the end of the file //close the connection if this was the end of the file
if (!size) { if (!size) {
conn.close(); conn.close();
Clean();
} }
} }
} }

View file

@ -961,6 +961,9 @@ namespace IPC {
///\brief Indicate that the process is done using this piece of memory, set the counter to finished ///\brief Indicate that the process is done using this piece of memory, set the counter to finished
void sharedClient::finish() { void sharedClient::finish() {
if (!myPage.mapped) {
return;
}
if (!hasCounter) { if (!hasCounter) {
DEBUG_MSG(DLVL_WARN, "Trying to time-out an element without counters"); DEBUG_MSG(DLVL_WARN, "Trying to time-out an element without counters");
return; return;

File diff suppressed because it is too large Load diff

View file

@ -16,97 +16,85 @@
/// Holds all TS processing related code. /// Holds all TS processing related code.
namespace TS { namespace TS {
///stores all the data of a pmt table. It must be mapped to a PID, and this is done in the function TS::getPMTTable(TS::Packet& packet)
///\todo Add more necessary variables, or find a more efficient way to store metadata
struct pmtinfo {
unsigned short streamtype;//the streamtype, 0x1b is h264, 0x0f is aac. These are used in aac, there may be (undiscovered) others
unsigned int trackid;//track id
std::string curPayload;//payload without PES/TS headers
long long int lastPEStime;//the pes time of the packet that was last seen
};
///Class for reading and writing TS Streams. The class is capable of analyzing a packet of 188 bytes ///Class for reading and writing TS Streams. The class is capable of analyzing a packet of 188 bytes
///and calculating key values ///and calculating key values
class Packet { class Packet {
public: public:
//Constructors and fillers //Constructors and fillers
Packet(); Packet();
~Packet(); ~Packet();
bool FromString(std::string & Data); bool FromPointer(const char * data);
bool FromPointer(const char * Data);
bool FromFile(FILE * data); bool FromFile(FILE * data);
//Base properties //Base properties
void PID(int NewPID); void setPID(int NewPID);
unsigned int PID(); unsigned int getPID() const;
void continuityCounter(int NewContinuity); void setContinuityCounter(int NewContinuity);
int continuityCounter(); int getContinuityCounter() const;
void PCR(int64_t NewVal); void setPCR(int64_t NewVal);
int64_t PCR(); int64_t getPCR() const;
int64_t OPCR(); int64_t getOPCR() const;
void AdaptationField(int NewVal); void setAdaptationField(int NewVal);
int AdaptationField(); int getAdaptationField() const;
int AdaptationFieldLen(); int getAdaptationFieldLen() const;
unsigned int getTransportScramblingControl(); unsigned int getTransportScramblingControl() const;
//Flags //Flags
bool unitStart(); void setUnitStart(bool newVal);
void unitStart(bool newVal); bool getUnitStart() const;
bool randomAccess(); void setRandomAccess(bool newVal);
void randomAccess(bool newVal); bool getRandomAccess() const;
bool discontinuity();
bool hasPCR();
bool hasOPCR();
bool splicingPoint();
bool transportError();
bool priority();
bool ESpriority();
bool hasDiscontinuity() const;
bool hasPCR() const;
bool hasOPCR() const;
bool hasSplicingPoint() const;
bool hasTransportError() const;
bool hasPriority() const;
bool hasESpriority() const;
//Helper functions //Helper functions
operator bool(); operator bool() const;
bool isPMT(); bool isPMT() const;
void Clear(); void clear();
void DefaultPAT(); void setDefaultPAT();
void DefaultPMT(); unsigned int getDataSize() const;
unsigned int dataSize();
char * dataPointer(); unsigned int getBytesFree() const;
int BytesFree(); int fillFree(const char * PackageData, int maxLen);
void FillFree(std::string & PackageData); void addStuffing();
int FillFree(const char * PackageData, int maxLen); void updPos(unsigned int newPos);
void AddStuffing();
//PES helpers
static std::string & getPESVideoLeadIn(unsigned int len, unsigned long long PTS, unsigned long long offset, bool isAligned);
static std::string & getPESAudioLeadIn(unsigned int len, unsigned long long PTS);
//Printers and writers //Printers and writers
std::string toPrettyString(size_t indent = 0, int detailLevel = 3); std::string toPrettyString(size_t indent = 0, int detailLevel = 3) const;
const std::string& getStrBuf(); const char * getPayload() const;
const char * getBuffer(); int getPayloadLength() const;
const char * getPayload(); const char * checkAndGetBuffer() const;
int getPayloadLength();
const char * ToString();
//PES helpers
static std::string & getPESVideoLeadIn(unsigned int len, unsigned long long PTS, unsigned long long offset);
static std::string & getPESAudioLeadIn(unsigned int len, unsigned long long PTS);
protected: protected:
std::string strBuf;///< Internal string buffer char strBuf[189];
unsigned int pos;
}; };
class ProgramAssociationTable : public Packet { class ProgramAssociationTable : public Packet {
public: public:
char getOffset(); char getOffset() const;
char getTableId(); char getTableId() const;
short getSectionLength(); short getSectionLength() const;
short getTransportStreamId(); short getTransportStreamId() const;
char getVersionNumber(); char getVersionNumber() const;
bool getCurrentNextIndicator(); bool getCurrentNextIndicator() const;
char getSectionNumber(); char getSectionNumber() const;
char getLastSectionNumber(); char getLastSectionNumber() const;
short getProgramCount(); short getProgramCount() const;
short getProgramNumber(short index); short getProgramNumber(short index) const;
short getProgramPID(short index); short getProgramPID(short index) const;
int getCRC(); int getCRC() const;
std::string toPrettyString(size_t indent); std::string toPrettyString(size_t indent) const;
}; };
class ProgramMappingEntry { class ProgramMappingEntry {
@ -115,12 +103,12 @@ namespace TS {
operator bool() const; operator bool() const;
int streamType(); int getStreamType() const;
std::string codec(); std::string getCodec() const;
std::string streamTypeString(); std::string getStreamTypeString() const;
int elementaryPid(); int getElementaryPid() const;
int ESInfoLength(); int getESInfoLength() const;
char * ESInfo(); char * getESInfo() const;
void advance(); void advance();
private: private:
char* data; char* data;
@ -130,38 +118,38 @@ namespace TS {
class ProgramMappingTable : public Packet { class ProgramMappingTable : public Packet {
public: public:
ProgramMappingTable(); ProgramMappingTable();
char getOffset(); char getOffset() const;
void setOffset(char newVal); void setOffset(char newVal);
char getTableId(); char getTableId() const;
void setTableId(char newVal); void setTableId(char newVal);
short getSectionLength(); short getSectionLength() const;
void setSectionLength(short newVal); void setSectionLength(short newVal);
short getProgramNumber(); short getProgramNumber() const;
void setProgramNumber(short newVal); void setProgramNumber(short newVal);
char getVersionNumber(); char getVersionNumber() const;
void setVersionNumber(char newVal); void setVersionNumber(char newVal);
bool getCurrentNextIndicator(); bool getCurrentNextIndicator() const;
void setCurrentNextIndicator(bool newVal); void setCurrentNextIndicator(bool newVal);
char getSectionNumber(); char getSectionNumber() const;
void setSectionNumber(char newVal); void setSectionNumber(char newVal);
char getLastSectionNumber(); char getLastSectionNumber() const;
void setLastSectionNumber(char newVal); void setLastSectionNumber(char newVal);
short getPCRPID(); short getPCRPID() const;
void setPCRPID(short newVal); void setPCRPID(short newVal);
short getProgramInfoLength(); short getProgramInfoLength() const;
void setProgramInfoLength(short newVal); void setProgramInfoLength(short newVal);
short getProgramCount(); short getProgramCount() const;
void setProgramCount(short newVal); void setProgramCount(short newVal);
ProgramMappingEntry getEntry(int index); ProgramMappingEntry getEntry(int index) const;
char getStreamType(short index);
void setStreamType(char newVal, short index); void setStreamType(char newVal, short index);
short getElementaryPID(short index); char getStreamType(short index) const;
void setElementaryPID(short newVal, short index); void setElementaryPID(short newVal, short index);
short getESInfoLength(short index); short getElementaryPID(short index) const;
void setESInfoLength(short newVal,short index); void setESInfoLength(short newVal,short index);
int getCRC(); short getESInfoLength(short index) const;
int getCRC() const;
void calcCRC(); void calcCRC();
std::string toPrettyString(size_t indent); std::string toPrettyString(size_t indent) const;
}; };
/// Constructs an audio header to be used on each audio frame. /// Constructs an audio header to be used on each audio frame.
@ -169,7 +157,7 @@ namespace TS {
/// prepended on each audio frame. /// prepended on each audio frame.
/// \param FrameLen the length of the current audio frame. /// \param FrameLen the length of the current audio frame.
/// \param initData A string containing the initalization data for this track's codec. /// \param initData A string containing the initalization data for this track's codec.
static inline std::string GetAudioHeader(int FrameLen, std::string initData) { static inline std::string getAudioHeader(int FrameLen, std::string initData) {
char StandardHeader[7] = {0xFF, 0xF1, 0x00, 0x00, 0x00, 0x1F, 0xFC}; char StandardHeader[7] = {0xFF, 0xF1, 0x00, 0x00, 0x00, 0x1F, 0xFC};
FrameLen += 7; FrameLen += 7;
StandardHeader[2] = ((((initData[0] >> 3) - 1) << 6) & 0xC0); //AAC Profile - 1 ( First two bits ) StandardHeader[2] = ((((initData[0] >> 3) - 1) << 6) & 0xC0); //AAC Profile - 1 ( First two bits )
@ -208,38 +196,7 @@ namespace TS {
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
}; };
/// A standard Program Mapping Table, as generated by FFMPEG. const char * createPMT(std::set<unsigned long>& selectedTracks, DTSC::Meta& myMeta, int contCounter=0);
/// Contains both Audio and Video mappings, works also on video- or audio-only streams.
//0x47 = sync byte
//0x5000 = transport error(1) = 0, payload unit start(1) = 1, priority(1) = 0, PID(13) = 4096
//0x10 = transportscrambling(2) = 0, adaptation(2) = 1, continuity(4) = 0
//0x00 = pointer = 0
//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
static char PMT[188]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