HLS working, dunno why, but it works.

This commit is contained in:
Erik Zandvliet 2013-07-10 11:27:26 +02:00 committed by Thulinma
parent 768282866e
commit db2e630436
5 changed files with 50 additions and 16 deletions

View file

@ -81,6 +81,7 @@ bool DTSC::Stream::parsePacket(std::string & buffer){
if (version == 2){ if (version == 2){
newPack = JSON::fromDTMI2((unsigned char*)buffer.c_str() + 8, len, i); newPack = JSON::fromDTMI2((unsigned char*)buffer.c_str() + 8, len, i);
} }
buffer.erase(0, len + 8);
addPacket(newPack); addPacket(newPack);
syncing = false; syncing = false;
return true; return true;
@ -173,6 +174,7 @@ bool DTSC::Stream::parsePacket(Socket::Buffer & buffer){
} }
void DTSC::Stream::addPacket(JSON::Value & newPack){ void DTSC::Stream::addPacket(JSON::Value & newPack){
long long unsigned int now = Util::getMS();
livePos newPos; livePos newPos;
newPos.trackID = newPack["trackid"].asInt(); newPos.trackID = newPack["trackid"].asInt();
newPos.seekTime = newPack["time"].asInt(); newPos.seekTime = newPack["time"].asInt();
@ -614,7 +616,6 @@ void DTSC::File::seekNext(){
return; return;
} }
clearerr(F); clearerr(F);
seek_time(currentPositions.begin()->seekTime + 1, currentPositions.begin()->trackID);
fseek(F,currentPositions.begin()->seekPos, SEEK_SET); fseek(F,currentPositions.begin()->seekPos, SEEK_SET);
currentPositions.erase(currentPositions.begin()); currentPositions.erase(currentPositions.begin());
lastreadpos = ftell(F); lastreadpos = ftell(F);
@ -668,10 +669,33 @@ void DTSC::File::seekNext(){
}else{ }else{
jsonbuffer = JSON::fromDTMI(strbuffer); jsonbuffer = JSON::fromDTMI(strbuffer);
} }
int tempLoc = getBytePos();
char newHeader[20];
if (fread((void*)newHeader, 20, 1, F) == 1){
if (memcmp(newHeader, DTSC::Magic_Packet2, 4) == 0){
seekPos tmpPos;
tmpPos.seekPos = tempLoc;
tmpPos.trackID = ntohl(((int*)newHeader)[2]);
if (selectedTracks.find(tmpPos.trackID) != selectedTracks.end()){
tmpPos.seekTime = ((long long unsigned int)ntohl(((int*)newHeader)[3])) << 32;
tmpPos.seekTime += ntohl(((int*)newHeader)[4]);
}else{
for (JSON::ArrIter it = getTrackById(jsonbuffer["trackid"].asInt())["keys"].ArrBegin(); it != getTrackById(jsonbuffer["trackid"].asInt())["keys"].ArrEnd(); it++){
if ((*it)["time"].asInt() > jsonbuffer["time"].asInt()){
tmpPos.seekTime = (*it)["time"].asInt();
tmpPos.seekPos = (*it)["bpos"].asInt();
break;
}
}
}
currentPositions.insert(tmpPos);
}
}
} }
void DTSC::File::parseNext(){ void DTSC::File::parseNext(){
lastreadpos = ftell(F);
if (fread(buffer, 4, 1, F) != 1){ if (fread(buffer, 4, 1, F) != 1){
if (feof(F)){ if (feof(F)){
#if DEBUG >= 4 #if DEBUG >= 4
@ -769,6 +793,7 @@ bool DTSC::File::seek_time(int ms, int trackNo){
} }
bool foundPacket = false; bool foundPacket = false;
while ( !foundPacket){ while ( !foundPacket){
lastreadpos = ftell(F);
if (reachedEOF()){ if (reachedEOF()){
return false; return false;
} }
@ -787,8 +812,8 @@ bool DTSC::File::seek_time(int ms, int trackNo){
//get timestamp of packet, if too large, break, if not, skip size bytes. //get timestamp of packet, if too large, break, if not, skip size bytes.
long long unsigned int myTime = ((long long unsigned int)ntohl(((int*)header)[3]) << 32); long long unsigned int myTime = ((long long unsigned int)ntohl(((int*)header)[3]) << 32);
myTime += ntohl(((int*)header)[4]); myTime += ntohl(((int*)header)[4]);
tmpPos.seekTime = myTime;
if (myTime >= ms){ if (myTime >= ms){
tmpPos.seekTime = myTime;
foundPacket = true; foundPacket = true;
}else{ }else{
tmpPos.seekPos += 8 + packSize; tmpPos.seekPos += 8 + packSize;

View file

@ -11,6 +11,7 @@
#include <stdio.h> //for FILE #include <stdio.h> //for FILE
#include "json.h" #include "json.h"
#include "socket.h" #include "socket.h"
#include "timing.h"
/// Holds all DDVTECH Stream Container classes and parsers. /// Holds all DDVTECH Stream Container classes and parsers.
///length (int, length in seconds, if available) ///length (int, length in seconds, if available)

View file

@ -1071,6 +1071,7 @@ JSON::Value FLV::Tag::toJSON(JSON::Value & metadata){
} }
pack_out["datatype"] = "audio"; pack_out["datatype"] = "audio";
pack_out["time"] = tagTime(); pack_out["time"] = tagTime();
pack_out["trackid"] = 2;
metadata["tracks"]["track2"]["trackid"] = 2; metadata["tracks"]["track2"]["trackid"] = 2;
metadata["tracks"]["track2"]["type"] = "audio"; metadata["tracks"]["track2"]["type"] = "audio";
if ( !metadata["tracks"]["track2"].isMember("codec") || metadata["tracks"]["track2"]["codec"].asString() == "?" || metadata["tracks"]["track2"]["codec"].asString() == ""){ if ( !metadata["tracks"]["track2"].isMember("codec") || metadata["tracks"]["track2"]["codec"].asString() == "?" || metadata["tracks"]["track2"]["codec"].asString() == ""){
@ -1145,6 +1146,7 @@ JSON::Value FLV::Tag::toJSON(JSON::Value & metadata){
metadata["tracks"]["track1"]["codec"] = getVideoCodec(); metadata["tracks"]["track1"]["codec"] = getVideoCodec();
} }
pack_out["datatype"] = "video"; pack_out["datatype"] = "video";
pack_out["trackid"] = 1;
switch (videodata & 0xF0){ switch (videodata & 0xF0){
case 0x10: case 0x10:
pack_out["keyframe"] = 1; pack_out["keyframe"] = 1;

View file

@ -1,6 +1,7 @@
/// \file ts_packet.cpp /// \file ts_packet.cpp
/// Holds all code for the TS namespace. /// Holds all code for the TS namespace.
#include <sstream>
#include "ts_packet.h" #include "ts_packet.h"
#ifndef FILLER_DATA #ifndef FILLER_DATA
@ -142,18 +143,23 @@ int TS::Packet::AdaptationFieldLen(){
} }
/// Prints a packet to stdout, for analyser purposes. /// Prints a packet to stdout, for analyser purposes.
void TS::Packet::Print(){ std::string TS::Packet::toPrettyString(size_t indent){
std::cout << "TS Packet: " << (strBuf[0] == 0x47) << "\n\tNewUnit: " << UnitStart() << "\n\tPID: " << PID() << "\n\tContinuity Counter: " std::stringstream output;
<< ContinuityCounter() << "\n\tAdaption Field: " << AdaptationField() << "\n"; output << std::string(indent,' ') << "TS Packet: " << (strBuf[0] == 0x47) << std::endl;
output << std::string(indent+2,' ') << "NewUnit: " << UnitStart() << std::endl;
output << std::string(indent+2,' ') << "PID: " << PID() << std::endl;
output << std::string(indent+2,' ') << "Continuity Counter: " << ContinuityCounter() << std::endl;
output << std::string(indent+2,' ') << "Adaption Field: " << AdaptationField() << std::endl;
if (AdaptationField()){ if (AdaptationField()){
std::cout << "\t\tAdaption Field Length: " << AdaptationFieldLen() << "\n"; output << std::string(indent+4,' ') << "Adaptation Length: " << AdaptationFieldLen() << std::endl;;
if (AdaptationFieldLen()){ if (AdaptationFieldLen()){
std::cout << "\t\tRandom Access: " << RandomAccess() << "\n"; output << std::string(indent+4,' ') << "Random Access: " << RandomAccess() << std::endl;
} }
if (PCR() != -1){ if (PCR() != -1){
std::cout << "\t\tPCR: " << PCR() << "( " << (double)PCR() / 27000000 << " s )\n"; output << std::string(indent+4,' ') << "PCR: " << PCR() << "( " << (double)PCR() / 27000000 << " s )" << std::endl;
} }
} }
return output.str();
} }
/// Gets whether a new unit starts in this TS::Packet. /// Gets whether a new unit starts in this TS::Packet.
@ -275,17 +281,17 @@ void TS::Packet::PESVideoLeadIn(unsigned int NewLen, long long unsigned int PTS)
/// \param NewLen The length of this frame. /// \param NewLen The length of this frame.
/// \param PTS The timestamp of the frame. /// \param PTS The timestamp of the frame.
void TS::Packet::PESAudioLeadIn(unsigned int NewLen, uint64_t PTS){ void TS::Packet::PESAudioLeadIn(unsigned int NewLen, uint64_t PTS){
NewLen += 8; NewLen += 5;
strBuf += (char)0x00; //PacketStartCodePrefix strBuf += (char)0x00; //PacketStartCodePrefix
strBuf += (char)0x00; //PacketStartCodePrefix (Cont) strBuf += (char)0x00; //PacketStartCodePrefix (Cont)
strBuf += (char)0x01; //PacketStartCodePrefix (Cont) strBuf += (char)0x01; //PacketStartCodePrefix (Cont)
strBuf += (char)0xc0; //StreamType Audio strBuf += (char)0xc0; //StreamType Audio
strBuf += (char)((NewLen & 0xFF00) >> 8); //PES PacketLength strBuf += (char)((NewLen & 0xFF00) >> 8); //PES PacketLength
strBuf += (char)(NewLen & 0x00FF); //PES PacketLength (Cont) strBuf += (char)(NewLen & 0x00FF); //PES PacketLength (Cont)
strBuf += (char)0x80; //Reserved + Flags strBuf += (char)0x84; //Reserved + Flags
strBuf += (char)0x80; //PTSOnlyFlag + Flags strBuf += (char)0x80; //PTSOnlyFlag + Flags
strBuf += (char)0x05; //PESHeaderDataLength strBuf += (char)0x05; //PESHeaderDataLength
strBuf += (char)(0x20 + ((PTS & 0x1C0000000LL) >> 29) + 1); //PTS strBuf += (char)(0x30 + ((PTS & 0x1C0000000LL) >> 29) + 1); //PTS
strBuf += (char)((PTS & 0x03FC00000LL) >> 22); //PTS (Cont) strBuf += (char)((PTS & 0x03FC00000LL) >> 22); //PTS (Cont)
strBuf += (char)(((PTS & 0x0003F8000LL) >> 14) + 1); //PTS (Cont) strBuf += (char)(((PTS & 0x0003F8000LL) >> 14) + 1); //PTS (Cont)
strBuf += (char)((PTS & 0x000007F80LL) >> 7); //PTS (Cont) strBuf += (char)((PTS & 0x000007F80LL) >> 7); //PTS (Cont)
@ -321,12 +327,12 @@ void TS::Packet::PESVideoLeadIn(std::string & toSend, long long unsigned int PTS
void TS::Packet::PESAudioLeadIn(std::string & toSend, long long unsigned int PTS){ void TS::Packet::PESAudioLeadIn(std::string & toSend, long long unsigned int PTS){
std::string tmpStr; std::string tmpStr;
tmpStr.reserve(14); tmpStr.reserve(14);
unsigned int NewLen = toSend.size() + 8; unsigned int NewLen = toSend.size() + 5;
tmpStr.append("\000\000\001\300", 4); tmpStr.append("\000\000\001\300", 4);
tmpStr += (char)((NewLen & 0xFF00) >> 8); //PES PacketLength tmpStr += (char)((NewLen & 0xFF00) >> 8); //PES PacketLength
tmpStr += (char)(NewLen & 0x00FF); //PES PacketLength (Cont) tmpStr += (char)(NewLen & 0x00FF); //PES PacketLength (Cont)
tmpStr.append("\200\200\005", 3); tmpStr.append("\204\200\005", 3);
tmpStr += (char)(0x20 + ((PTS & 0x1C0000000LL) >> 29) + 1); //PTS tmpStr += (char)(0x30 + ((PTS & 0x1C0000000LL) >> 29) + 1); //PTS
tmpStr += (char)((PTS & 0x03FC00000LL) >> 22); //PTS (Cont) tmpStr += (char)((PTS & 0x03FC00000LL) >> 22); //PTS (Cont)
tmpStr += (char)(((PTS & 0x0003F8000LL) >> 14) + 1); //PTS (Cont) tmpStr += (char)(((PTS & 0x0003F8000LL) >> 14) + 1); //PTS (Cont)
tmpStr += (char)((PTS & 0x000007F80LL) >> 7); //PTS (Cont) tmpStr += (char)((PTS & 0x000007F80LL) >> 7); //PTS (Cont)
@ -369,7 +375,7 @@ std::string & TS::Packet::getPESAudioLeadIn(unsigned int NewLen, long long unsig
tmpStr.append("\000\000\001\300", 4); tmpStr.append("\000\000\001\300", 4);
tmpStr += (char)((NewLen & 0xFF00) >> 8); //PES PacketLength tmpStr += (char)((NewLen & 0xFF00) >> 8); //PES PacketLength
tmpStr += (char)(NewLen & 0x00FF); //PES PacketLength (Cont) tmpStr += (char)(NewLen & 0x00FF); //PES PacketLength (Cont)
tmpStr.append("\200\200\005", 3); tmpStr.append("\204\200\005", 3);
tmpStr += (char)(0x20 + ((PTS & 0x1C0000000LL) >> 29) + 1); //PTS tmpStr += (char)(0x20 + ((PTS & 0x1C0000000LL) >> 29) + 1); //PTS
tmpStr += (char)((PTS & 0x03FC00000LL) >> 22); //PTS (Cont) tmpStr += (char)((PTS & 0x03FC00000LL) >> 22); //PTS (Cont)
tmpStr += (char)(((PTS & 0x0003F8000LL) >> 14) + 1); //PTS (Cont) tmpStr += (char)(((PTS & 0x0003F8000LL) >> 14) + 1); //PTS (Cont)

View file

@ -38,7 +38,7 @@ namespace TS {
void RandomAccess(int NewVal); void RandomAccess(int NewVal);
int BytesFree(); int BytesFree();
void Print(); std::string toPrettyString(size_t indent = 0);
const char* ToString(); const char* ToString();
void PESVideoLeadIn(unsigned int NewLen, long long unsigned int PTS = 1); void PESVideoLeadIn(unsigned int NewLen, long long unsigned int PTS = 1);
void PESAudioLeadIn(unsigned int NewLen, uint64_t PTS = 0); void PESAudioLeadIn(unsigned int NewLen, uint64_t PTS = 0);