UI: Implement stream delay

When stream delay is active, the "Start/Stop Streaming" button is
changed in to a menu button, which allows the user to select either the
option to stop the stream (which causes it to count down), or forcibly
stop the stream (which immediately stops the stream and cuts off all
delayed data).

If the user decides they want to start the stream again while in the
process of counting down, they can safely do so without having to wait
for it to stop, and it will schedule it to start up again with the same
delay after the stop.

On the status bar, it will now show whether delay is active, and its
duration.  If the stream is in the process of stopping/starting, it will
count down to the stop/start.

If the option to preserve stream cutoff point on unexpected
disconnections/reconnections is enabled, it will update the current
delay duration accordingly.
This commit is contained in:
jp9000
2015-09-10 12:13:40 -07:00
parent d1293b2b8a
commit f592c33eec
7 changed files with 274 additions and 18 deletions
+92 -8
View File
@@ -2,9 +2,11 @@
#include "obs-app.hpp"
#include "window-basic-main.hpp"
#include "window-basic-status-bar.hpp"
#include "window-basic-main-outputs.hpp"
OBSBasicStatusBar::OBSBasicStatusBar(QWidget *parent)
: QStatusBar (parent),
delayInfo (new QLabel),
droppedFrames (new QLabel),
sessionTime (new QLabel),
cpuUsage (new QLabel),
@@ -13,11 +15,13 @@ OBSBasicStatusBar::OBSBasicStatusBar(QWidget *parent)
sessionTime->setText(QString("00:00:00"));
cpuUsage->setText(QString("CPU: 0.0%"));
delayInfo->setAlignment(Qt::AlignRight);
droppedFrames->setAlignment(Qt::AlignRight);
sessionTime->setAlignment(Qt::AlignRight);
cpuUsage->setAlignment(Qt::AlignRight);
kbps->setAlignment(Qt::AlignRight);
delayInfo->setIndent(20);
droppedFrames->setIndent(20);
sessionTime->setIndent(20);
cpuUsage->setIndent(20);
@@ -26,30 +30,69 @@ OBSBasicStatusBar::OBSBasicStatusBar(QWidget *parent)
addPermanentWidget(droppedFrames);
addPermanentWidget(sessionTime);
addPermanentWidget(cpuUsage);
addPermanentWidget(delayInfo);
addPermanentWidget(kbps);
}
void OBSBasicStatusBar::IncRef()
void OBSBasicStatusBar::Activate()
{
if (activeRefs++ == 0) {
if (!active) {
refreshTimer = new QTimer(this);
connect(refreshTimer, SIGNAL(timeout()),
this, SLOT(UpdateStatusBar()));
totalSeconds = 0;
refreshTimer->start(1000);
active = true;
}
}
void OBSBasicStatusBar::DecRef()
void OBSBasicStatusBar::Deactivate()
{
if (--activeRefs == 0) {
OBSBasic *main = qobject_cast<OBSBasic*>(parent());
if (!main)
return;
if (!main->outputHandler->Active()) {
delete refreshTimer;
sessionTime->setText(QString("00:00:00"));
delayInfo->setText("");
droppedFrames->setText("");
kbps->setText("");
delaySecTotal = 0;
delaySecStarting = 0;
delaySecStopping = 0;
active = false;
}
}
void OBSBasicStatusBar::UpdateDelayMsg()
{
QString msg;
if (delaySecTotal) {
if (delaySecStarting && !delaySecStopping) {
msg = QTStr("Basic.StatusBar.DelayStartingIn");
msg = msg.arg(QString::number(delaySecStarting));
} else if (!delaySecStarting && delaySecStopping) {
msg = QTStr("Basic.StatusBar.DelayStoppingIn");
msg = msg.arg(QString::number(delaySecStopping));
} else if (delaySecStarting && delaySecStopping) {
msg = QTStr("Basic.StatusBar.DelayStartingStoppingIn");
msg = msg.arg(QString::number(delaySecStopping),
QString::number(delaySecStarting));
} else {
msg = QTStr("Basic.StatusBar.Delay");
msg = msg.arg(QString::number(delaySecTotal));
}
}
delayInfo->setText(msg);
}
#define BITRATE_UPDATE_SECONDS 2
void OBSBasicStatusBar::UpdateBandwidth()
@@ -62,6 +105,10 @@ void OBSBasicStatusBar::UpdateBandwidth()
uint64_t bytesSent = obs_output_get_total_bytes(streamOutput);
uint64_t bytesSentTime = os_gettime_ns();
if (bytesSent == 0)
lastBytesSent = 0;
uint64_t bitsBetween = (bytesSent - lastBytesSent) * 8;
double timePassed = double(bytesSentTime - lastBytesSentTime) /
@@ -117,6 +164,14 @@ void OBSBasicStatusBar::UpdateSessionTime()
QString msg = QTStr("Basic.StatusBar.AttemptingReconnect");
showMessage(msg.arg(QString::number(retries)));
}
if (delaySecStopping > 0 || delaySecStarting > 0) {
if (delaySecStopping > 0)
--delaySecStopping;
if (delaySecStarting > 0)
--delaySecStarting;
UpdateDelayMsg();
}
}
void OBSBasicStatusBar::UpdateDroppedFrames()
@@ -161,6 +216,11 @@ void OBSBasicStatusBar::Reconnect(int seconds)
{
retries++;
reconnectTimeout = seconds;
if (streamOutput) {
delaySecTotal = obs_output_get_active_delay(streamOutput);
UpdateDelayMsg();
}
}
void OBSBasicStatusBar::ReconnectSuccess()
@@ -171,6 +231,11 @@ void OBSBasicStatusBar::ReconnectSuccess()
bitrateUpdateSeconds = -1;
lastBytesSent = 0;
lastBytesSentTime = os_gettime_ns();
if (streamOutput) {
delaySecTotal = obs_output_get_active_delay(streamOutput);
UpdateDelayMsg();
}
}
void OBSBasicStatusBar::UpdateStatusBar()
@@ -180,6 +245,25 @@ void OBSBasicStatusBar::UpdateStatusBar()
UpdateDroppedFrames();
}
void OBSBasicStatusBar::StreamDelayStarting(int sec)
{
OBSBasic *main = qobject_cast<OBSBasic*>(parent());
if (!main || !main->outputHandler)
return;
streamOutput = main->outputHandler->streamOutput;
delaySecTotal = delaySecStarting = sec;
UpdateDelayMsg();
Activate();
}
void OBSBasicStatusBar::StreamDelayStopping(int sec)
{
delaySecTotal = delaySecStopping = sec;
UpdateDelayMsg();
}
void OBSBasicStatusBar::StreamStarted(obs_output_t *output)
{
streamOutput = output;
@@ -192,7 +276,7 @@ void OBSBasicStatusBar::StreamStarted(obs_output_t *output)
retries = 0;
lastBytesSent = 0;
lastBytesSentTime = os_gettime_ns();
IncRef();
Activate();
}
void OBSBasicStatusBar::StreamStopped()
@@ -208,18 +292,18 @@ void OBSBasicStatusBar::StreamStopped()
streamOutput = nullptr;
clearMessage();
DecRef();
Deactivate();
}
}
void OBSBasicStatusBar::RecordingStarted(obs_output_t *output)
{
recordOutput = output;
IncRef();
Activate();
}
void OBSBasicStatusBar::RecordingStopped()
{
recordOutput = nullptr;
DecRef();
Deactivate();
}