Working HLS, dunno how, but it works.
This commit is contained in:
parent
863cd6c8b6
commit
85e9416b02
3 changed files with 17 additions and 28 deletions
|
@ -112,13 +112,13 @@ int main(int argc, char** argv){
|
|||
|
||||
bool meta_sent = false;
|
||||
int playUntil = -1;
|
||||
long long now, lastTime = 0; //for timing of sending packets
|
||||
long long now = 0; //for timing of sending packets
|
||||
long long bench = 0; //for benchmarking
|
||||
std::set<int> newSelect;
|
||||
Stats sts;
|
||||
CYG_DEFI
|
||||
|
||||
while (in_out.connected() && (Util::epoch() - lasttime < 60)){
|
||||
while (in_out.connected() && (Util::epoch() - lasttime < 60) && conf.is_active){
|
||||
CYG_INCR
|
||||
if (CYG_LOOP in_out.spool()){
|
||||
while (in_out.Received().size()){
|
||||
|
@ -170,19 +170,10 @@ int main(int argc, char** argv){
|
|||
case 's': { //second-seek
|
||||
int ms = JSON::Value(in_out.Received().get().substr(2)).asInt();
|
||||
bool ret = source.seek_time(ms);
|
||||
lastTime = 0;
|
||||
break;
|
||||
}
|
||||
/*
|
||||
case 'f': { //frame-seek
|
||||
bool ret = source.seek_frame(JSON::Value(in_out.Received().get().substr(2)).asInt());
|
||||
lastTime = 0;
|
||||
break;
|
||||
}
|
||||
*/
|
||||
case 'p': { //play
|
||||
playing = -1;
|
||||
lastTime = 0;
|
||||
in_out.setBlocking(false);
|
||||
if (in_out.Received().get().size() >= 2){
|
||||
playUntil = atoi(in_out.Received().get().substr(2).c_str());
|
||||
|
@ -237,16 +228,11 @@ int main(int argc, char** argv){
|
|||
playing = 0;
|
||||
}
|
||||
if (source.atKeyframe()){
|
||||
///\todo Fix auto-delay on playing == -1.
|
||||
if (playing == -1 && meta["video"]["keyms"].asInt() > now - lastTime){
|
||||
Util::sleep(meta["video"]["keyms"].asInt() - (now - lastTime));
|
||||
}
|
||||
lastTime = now;
|
||||
if (playing > 0){
|
||||
--playing;
|
||||
}
|
||||
}
|
||||
if ( playUntil && playUntil < source.getJSON()["time"].asInt()){
|
||||
if ( playUntil && playUntil <= source.getJSON()["time"].asInt()){
|
||||
playing = 0;
|
||||
}
|
||||
if (playing == 0){
|
||||
|
@ -254,7 +240,7 @@ int main(int argc, char** argv){
|
|||
std::cerr << "Completed VoD request in MistPlayer (" << (Util::getMS() - bench) << "ms)" << std::endl;
|
||||
#endif
|
||||
pausemark["time"] = source.getJSON()["time"];
|
||||
pausemark.toPacked();
|
||||
pausemark.netPrepare();
|
||||
in_out.SendNow(pausemark.toNetPacked());
|
||||
in_out.setBlocking(true);
|
||||
}else{
|
||||
|
|
|
@ -48,7 +48,7 @@ namespace Connector_HTTP {
|
|||
if (audioId != -1){
|
||||
bWidth += (metadata["tracks"][audioName]["maxbps"].asInt() * 2);
|
||||
}
|
||||
result << "#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=" << bWidth * 8 << "\r\n";
|
||||
result << "#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=" << bWidth * 10 << "\r\n";
|
||||
result << trackIt->second["trackid"].asInt();
|
||||
if (audioId != -1){
|
||||
result << "_" << audioId;
|
||||
|
@ -66,9 +66,9 @@ namespace Connector_HTTP {
|
|||
}
|
||||
result << "#EXTM3U\r\n"
|
||||
"#EXT-X-TARGETDURATION:" << (longestFragment / 1000) + 1 << "\r\n"
|
||||
"#EXT-X-MEDIA-SEQUENCE:" << metadata["trackid"].asInt() << "\r\n";
|
||||
"#EXT-X-MEDIA-SEQUENCE:0\r\n";
|
||||
for (JSON::ArrIter ai = metadata["frags"].ArrBegin(); ai != metadata["frags"].ArrEnd(); ai++){
|
||||
result << "#EXTINF:" << (*ai)["dur"].asInt() / 1000 << ", no desc\r\n"
|
||||
result << "#EXTINF:" << (((*ai)["dur"].asInt() + 500) / 1000) << ", no desc\r\n"
|
||||
<< metadata["keys"][(*ai)["num"].asInt() - 1]["time"].asInt() << "_" << (*ai)["dur"].asInt() + metadata["keys"][(*ai)["num"].asInt() - 1]["time"].asInt() << ".ts\r\n";
|
||||
}
|
||||
result << "#EXT-X-ENDLIST";
|
||||
|
@ -100,6 +100,7 @@ namespace Connector_HTTP {
|
|||
int ThisNaluSize;
|
||||
char VideoCounter = 0;
|
||||
char AudioCounter = 0;
|
||||
long long unsigned int lastVid = 0;
|
||||
bool IsKeyFrame;
|
||||
MP4::AVCC avccbox;
|
||||
bool haveAvcc = false;
|
||||
|
@ -162,6 +163,7 @@ namespace Connector_HTTP {
|
|||
audioTrackID = atoi(allTracks.substr(allTracks.find("_")+1).c_str());
|
||||
temp = HTTP_R.url.find("/", temp) + 1;
|
||||
Segment = atoi(HTTP_R.url.substr(temp, HTTP_R.url.find("_", temp) - temp).c_str());
|
||||
lastVid = Segment * 90;
|
||||
temp = HTTP_R.url.find("_", temp) + 1;
|
||||
int frameCount = atoi(HTTP_R.url.substr(temp, HTTP_R.url.find(".ts", temp) - temp).c_str());
|
||||
if (Strm.metadata.isMember("live")){
|
||||
|
@ -252,7 +254,7 @@ namespace Connector_HTTP {
|
|||
if (Strm.lastType() == DTSC::VIDEO || Strm.lastType() == DTSC::AUDIO){
|
||||
Socket::Buffer ToPack;
|
||||
//write PAT and PMT TS packets
|
||||
if (PacketNumber == 0){
|
||||
if (PacketNumber % 42 == 0){
|
||||
PackData.DefaultPAT();
|
||||
TSBuf.write(PackData.ToString(), 188);
|
||||
PackData.DefaultPMT();
|
||||
|
@ -268,7 +270,7 @@ namespace Connector_HTTP {
|
|||
TimeStamp = (Strm.getPacket()["time"].asInt() * 27000);
|
||||
}
|
||||
ToPack.append(avccbox.asAnnexB());
|
||||
while (Strm.lastData().size()){
|
||||
while (Strm.lastData().size() > 4){
|
||||
ThisNaluSize = (Strm.lastData()[0] << 24) + (Strm.lastData()[1] << 16) + (Strm.lastData()[2] << 8) + Strm.lastData()[3];
|
||||
Strm.lastData().replace(0, 4, TS::NalHeader, 4);
|
||||
if (ThisNaluSize + 4 == Strm.lastData().size()){
|
||||
|
@ -285,9 +287,10 @@ namespace Connector_HTTP {
|
|||
}else if (Strm.lastType() == DTSC::AUDIO){
|
||||
ToPack.append(TS::GetAudioHeader(Strm.lastData().size(), Strm.getTrackById(audioTrackID)["init"].asString()));
|
||||
ToPack.append(Strm.lastData());
|
||||
ToPack.prepend(TS::Packet::getPESAudioLeadIn(ToPack.bytes(1073741824ul), Strm.getPacket()["time"].asInt() * 90));
|
||||
ToPack.prepend(TS::Packet::getPESAudioLeadIn(ToPack.bytes(1073741824ul), lastVid));
|
||||
PIDno = 0x101;
|
||||
ContCounter = &AudioCounter;
|
||||
IsKeyFrame = false;
|
||||
}
|
||||
|
||||
//initial packet
|
||||
|
|
|
@ -120,7 +120,7 @@ namespace Converters {
|
|||
}
|
||||
if( currentID == "" ) {
|
||||
fprintf(stderr, "Found an unknown v2 packet with id %d\n", F.getJSON()["trackid"].asInt());
|
||||
F.seekNext();
|
||||
F.parseNext();
|
||||
continue;
|
||||
//should create new track but this shouldnt be needed...
|
||||
}
|
||||
|
@ -198,13 +198,13 @@ namespace Converters {
|
|||
meta["tracks"][it->first]["keys"][tmp - 1]["len"] = it->second.lastms - meta["tracks"][it->first]["keys"][tmp - 2]["time"].asInt();
|
||||
meta["tracks"][it->first]["keys"][tmp - 1]["size"] = it->second.totalSize;
|
||||
for (int i = 0; i < trackData[it->first].parts.size(); i++){
|
||||
meta["tracks"][it->first]["keys"][tmp - 1]["parts"].append(trackData[currentID].parts[i]);
|
||||
meta["tracks"][it->first]["keys"][tmp - 1]["parts"].append(trackData[it->first].parts[i]);
|
||||
}
|
||||
}else{
|
||||
meta["tracks"][it->first]["keys"][tmp]["len"] = it->second.lastms;
|
||||
meta["tracks"][it->first]["keys"][tmp]["size"] = it->second.totalSize;
|
||||
for (int i = 0; i < trackData[it->first].parts.size(); i++){
|
||||
meta["tracks"][it->first]["keys"][tmp]["parts"].append(trackData[currentID].parts[i]);
|
||||
meta["tracks"][it->first]["keys"][tmp]["parts"].append(trackData[it->first].parts[i]);
|
||||
}
|
||||
}
|
||||
//calculate fragments
|
||||
|
|
Loading…
Add table
Reference in a new issue