Improve default seeking behaviour for websocket-based outputs

This commit is contained in:
Thulinma 2024-07-04 11:30:58 +02:00
parent bd238e367e
commit 56dc2db051
2 changed files with 23 additions and 12 deletions

View file

@ -200,8 +200,8 @@ namespace Mist{
JSON::Value r; JSON::Value r;
r["type"] = "on_stop"; r["type"] = "on_stop";
r["data"]["current"] = currentTime(); r["data"]["current"] = currentTime();
r["data"]["begin"] = Output::startTime(); r["data"]["begin"] = startTime();
r["data"]["end"] = Output::endTime(); r["data"]["end"] = endTime();
webSock->sendFrame(r.toString()); webSock->sendFrame(r.toString());
parseData = false; parseData = false;
return false; return false;
@ -574,15 +574,9 @@ namespace Mist{
//Play command, sets pause state off and optionally also seeks //Play command, sets pause state off and optionally also seeks
if (command["type"] == "play") { if (command["type"] == "play") {
bool wasPlaying = parseData;
parseData = true; parseData = true;
if (command.isMember("seek_time")){ if (command.isMember("seek_time")){
handleWebsocketSeek(command); handleWebsocketSeek(command);
}else{
if (!wasPlaying){
command["seek_time"] = 0;
handleWebsocketSeek(command);
}
} }
return true; return true;
} }
@ -591,6 +585,22 @@ namespace Mist{
return false; return false;
} }
void HTTPOutput::initialSeek(bool dryRun){
Output::initialSeek(dryRun);
if (!webSock){return;}
// For websockets, simulate seeking behaviour
if (M.getLive()){
// live streams fast-forward to the live point
stayLive = true;
forwardTo = endTime();
realTime = 0;
}
// No matter what, run the idle commands to print current time in the websocket
handleWebsocketIdle();
onIdle();
}
void HTTPOutput::handleWebsocketIdle(){ void HTTPOutput::handleWebsocketIdle(){
if (!webSock){return;} if (!webSock){return;}
if (!parseData){return;} if (!parseData){return;}
@ -624,9 +634,9 @@ namespace Mist{
r["type"] = "on_time"; r["type"] = "on_time";
r["data"]["current"] = targetTime(); r["data"]["current"] = targetTime();
r["data"]["next"] = currentTime(); r["data"]["next"] = currentTime();
r["data"]["begin"] = Output::startTime(); r["data"]["begin"] = startTime();
r["data"]["end"] = Output::endTime(); r["data"]["end"] = endTime();
if (realTime == 0){ if (realTime == 0){
r["data"]["play_rate_curr"] = "fast-forward"; r["data"]["play_rate_curr"] = "fast-forward";
}else{ }else{
@ -731,9 +741,9 @@ namespace Mist{
selectDefaultTracks(); selectDefaultTracks();
} }
stayLive = (target_rate == 0.0) && (Output::endTime() < seek_time + 5000); stayLive = (target_rate == 0.0) && (endTime() < seek_time + 5000);
if (command["seek_time"].asStringRef() == "live"){stayLive = true;} if (command["seek_time"].asStringRef() == "live"){stayLive = true;}
if (stayLive){seek_time = Output::endTime();} if (stayLive){seek_time = endTime();}
if (!seek(seek_time, true)) { if (!seek(seek_time, true)) {
r["error"] = "seek failed, continuing as-is"; r["error"] = "seek failed, continuing as-is";

View file

@ -19,6 +19,7 @@ namespace Mist{
virtual void preHTTP(); virtual void preHTTP();
virtual bool onFinish(); virtual bool onFinish();
virtual void sendNext(); virtual void sendNext();
virtual void initialSeek(bool dryRun = false);
static bool listenMode(){return false;} static bool listenMode(){return false;}
void reConnector(std::string &connector); void reConnector(std::string &connector);
std::string getHandler(); std::string getHandler();