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;
|
bool meta_sent = false;
|
||||||
int playUntil = -1;
|
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
|
long long bench = 0; //for benchmarking
|
||||||
std::set<int> newSelect;
|
std::set<int> newSelect;
|
||||||
Stats sts;
|
Stats sts;
|
||||||
CYG_DEFI
|
CYG_DEFI
|
||||||
|
|
||||||
while (in_out.connected() && (Util::epoch() - lasttime < 60)){
|
while (in_out.connected() && (Util::epoch() - lasttime < 60) && conf.is_active){
|
||||||
CYG_INCR
|
CYG_INCR
|
||||||
if (CYG_LOOP in_out.spool()){
|
if (CYG_LOOP in_out.spool()){
|
||||||
while (in_out.Received().size()){
|
while (in_out.Received().size()){
|
||||||
|
@ -170,19 +170,10 @@ int main(int argc, char** argv){
|
||||||
case 's': { //second-seek
|
case 's': { //second-seek
|
||||||
int ms = JSON::Value(in_out.Received().get().substr(2)).asInt();
|
int ms = JSON::Value(in_out.Received().get().substr(2)).asInt();
|
||||||
bool ret = source.seek_time(ms);
|
bool ret = source.seek_time(ms);
|
||||||
lastTime = 0;
|
|
||||||
break;
|
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
|
case 'p': { //play
|
||||||
playing = -1;
|
playing = -1;
|
||||||
lastTime = 0;
|
|
||||||
in_out.setBlocking(false);
|
in_out.setBlocking(false);
|
||||||
if (in_out.Received().get().size() >= 2){
|
if (in_out.Received().get().size() >= 2){
|
||||||
playUntil = atoi(in_out.Received().get().substr(2).c_str());
|
playUntil = atoi(in_out.Received().get().substr(2).c_str());
|
||||||
|
@ -237,16 +228,11 @@ int main(int argc, char** argv){
|
||||||
playing = 0;
|
playing = 0;
|
||||||
}
|
}
|
||||||
if (source.atKeyframe()){
|
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){
|
if (playing > 0){
|
||||||
--playing;
|
--playing;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( playUntil && playUntil < source.getJSON()["time"].asInt()){
|
if ( playUntil && playUntil <= source.getJSON()["time"].asInt()){
|
||||||
playing = 0;
|
playing = 0;
|
||||||
}
|
}
|
||||||
if (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;
|
std::cerr << "Completed VoD request in MistPlayer (" << (Util::getMS() - bench) << "ms)" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
pausemark["time"] = source.getJSON()["time"];
|
pausemark["time"] = source.getJSON()["time"];
|
||||||
pausemark.toPacked();
|
pausemark.netPrepare();
|
||||||
in_out.SendNow(pausemark.toNetPacked());
|
in_out.SendNow(pausemark.toNetPacked());
|
||||||
in_out.setBlocking(true);
|
in_out.setBlocking(true);
|
||||||
}else{
|
}else{
|
||||||
|
|
|
@ -48,7 +48,7 @@ namespace Connector_HTTP {
|
||||||
if (audioId != -1){
|
if (audioId != -1){
|
||||||
bWidth += (metadata["tracks"][audioName]["maxbps"].asInt() * 2);
|
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();
|
result << trackIt->second["trackid"].asInt();
|
||||||
if (audioId != -1){
|
if (audioId != -1){
|
||||||
result << "_" << audioId;
|
result << "_" << audioId;
|
||||||
|
@ -66,9 +66,9 @@ namespace Connector_HTTP {
|
||||||
}
|
}
|
||||||
result << "#EXTM3U\r\n"
|
result << "#EXTM3U\r\n"
|
||||||
"#EXT-X-TARGETDURATION:" << (longestFragment / 1000) + 1 << "\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++){
|
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";
|
<< 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";
|
result << "#EXT-X-ENDLIST";
|
||||||
|
@ -100,6 +100,7 @@ namespace Connector_HTTP {
|
||||||
int ThisNaluSize;
|
int ThisNaluSize;
|
||||||
char VideoCounter = 0;
|
char VideoCounter = 0;
|
||||||
char AudioCounter = 0;
|
char AudioCounter = 0;
|
||||||
|
long long unsigned int lastVid = 0;
|
||||||
bool IsKeyFrame;
|
bool IsKeyFrame;
|
||||||
MP4::AVCC avccbox;
|
MP4::AVCC avccbox;
|
||||||
bool haveAvcc = false;
|
bool haveAvcc = false;
|
||||||
|
@ -162,6 +163,7 @@ namespace Connector_HTTP {
|
||||||
audioTrackID = atoi(allTracks.substr(allTracks.find("_")+1).c_str());
|
audioTrackID = atoi(allTracks.substr(allTracks.find("_")+1).c_str());
|
||||||
temp = HTTP_R.url.find("/", temp) + 1;
|
temp = HTTP_R.url.find("/", temp) + 1;
|
||||||
Segment = atoi(HTTP_R.url.substr(temp, HTTP_R.url.find("_", temp) - temp).c_str());
|
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;
|
temp = HTTP_R.url.find("_", temp) + 1;
|
||||||
int frameCount = atoi(HTTP_R.url.substr(temp, HTTP_R.url.find(".ts", temp) - temp).c_str());
|
int frameCount = atoi(HTTP_R.url.substr(temp, HTTP_R.url.find(".ts", temp) - temp).c_str());
|
||||||
if (Strm.metadata.isMember("live")){
|
if (Strm.metadata.isMember("live")){
|
||||||
|
@ -252,7 +254,7 @@ namespace Connector_HTTP {
|
||||||
if (Strm.lastType() == DTSC::VIDEO || Strm.lastType() == DTSC::AUDIO){
|
if (Strm.lastType() == DTSC::VIDEO || Strm.lastType() == DTSC::AUDIO){
|
||||||
Socket::Buffer ToPack;
|
Socket::Buffer ToPack;
|
||||||
//write PAT and PMT TS packets
|
//write PAT and PMT TS packets
|
||||||
if (PacketNumber == 0){
|
if (PacketNumber % 42 == 0){
|
||||||
PackData.DefaultPAT();
|
PackData.DefaultPAT();
|
||||||
TSBuf.write(PackData.ToString(), 188);
|
TSBuf.write(PackData.ToString(), 188);
|
||||||
PackData.DefaultPMT();
|
PackData.DefaultPMT();
|
||||||
|
@ -268,7 +270,7 @@ namespace Connector_HTTP {
|
||||||
TimeStamp = (Strm.getPacket()["time"].asInt() * 27000);
|
TimeStamp = (Strm.getPacket()["time"].asInt() * 27000);
|
||||||
}
|
}
|
||||||
ToPack.append(avccbox.asAnnexB());
|
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];
|
ThisNaluSize = (Strm.lastData()[0] << 24) + (Strm.lastData()[1] << 16) + (Strm.lastData()[2] << 8) + Strm.lastData()[3];
|
||||||
Strm.lastData().replace(0, 4, TS::NalHeader, 4);
|
Strm.lastData().replace(0, 4, TS::NalHeader, 4);
|
||||||
if (ThisNaluSize + 4 == Strm.lastData().size()){
|
if (ThisNaluSize + 4 == Strm.lastData().size()){
|
||||||
|
@ -279,15 +281,16 @@ namespace Connector_HTTP {
|
||||||
Strm.lastData().erase(0, ThisNaluSize + 4);
|
Strm.lastData().erase(0, ThisNaluSize + 4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ToPack.prepend(TS::Packet::getPESVideoLeadIn(0ul, Strm.getPacket()["time"].asInt() * 90));
|
ToPack.prepend(TS::Packet::getPESVideoLeadIn(0ul, Strm.getPacket()["time"].asInt() * 90));
|
||||||
PIDno = 0x100;
|
PIDno = 0x100;
|
||||||
ContCounter = &VideoCounter;
|
ContCounter = &VideoCounter;
|
||||||
}else if (Strm.lastType() == DTSC::AUDIO){
|
}else if (Strm.lastType() == DTSC::AUDIO){
|
||||||
ToPack.append(TS::GetAudioHeader(Strm.lastData().size(), Strm.getTrackById(audioTrackID)["init"].asString()));
|
ToPack.append(TS::GetAudioHeader(Strm.lastData().size(), Strm.getTrackById(audioTrackID)["init"].asString()));
|
||||||
ToPack.append(Strm.lastData());
|
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;
|
PIDno = 0x101;
|
||||||
ContCounter = &AudioCounter;
|
ContCounter = &AudioCounter;
|
||||||
|
IsKeyFrame = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//initial packet
|
//initial packet
|
||||||
|
|
|
@ -120,7 +120,7 @@ namespace Converters {
|
||||||
}
|
}
|
||||||
if( currentID == "" ) {
|
if( currentID == "" ) {
|
||||||
fprintf(stderr, "Found an unknown v2 packet with id %d\n", F.getJSON()["trackid"].asInt());
|
fprintf(stderr, "Found an unknown v2 packet with id %d\n", F.getJSON()["trackid"].asInt());
|
||||||
F.seekNext();
|
F.parseNext();
|
||||||
continue;
|
continue;
|
||||||
//should create new track but this shouldnt be needed...
|
//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]["len"] = it->second.lastms - meta["tracks"][it->first]["keys"][tmp - 2]["time"].asInt();
|
||||||
meta["tracks"][it->first]["keys"][tmp - 1]["size"] = it->second.totalSize;
|
meta["tracks"][it->first]["keys"][tmp - 1]["size"] = it->second.totalSize;
|
||||||
for (int i = 0; i < trackData[it->first].parts.size(); i++){
|
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{
|
}else{
|
||||||
meta["tracks"][it->first]["keys"][tmp]["len"] = it->second.lastms;
|
meta["tracks"][it->first]["keys"][tmp]["len"] = it->second.lastms;
|
||||||
meta["tracks"][it->first]["keys"][tmp]["size"] = it->second.totalSize;
|
meta["tracks"][it->first]["keys"][tmp]["size"] = it->second.totalSize;
|
||||||
for (int i = 0; i < trackData[it->first].parts.size(); i++){
|
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
|
//calculate fragments
|
||||||
|
|
Loading…
Add table
Reference in a new issue