Skip to content

Commit

Permalink
UI: PreStream Wizard add completion page
Browse files Browse the repository at this point in the history
Adds a completion page with content that depends on destinations. Back
button is disabled on the last page where application will take place
since updating settings is undoable. Various code fixes.
  • Loading branch information
JohannMG committed Sep 30, 2020
1 parent de747b5 commit 89eb3e2
Show file tree
Hide file tree
Showing 16 changed files with 153 additions and 46 deletions.
2 changes: 2 additions & 0 deletions UI/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ set(obs_SOURCES
pre-stream-wizard/page-input-display.cpp
pre-stream-wizard/page-start-prompt.cpp
pre-stream-wizard/page-select-settings.cpp
pre-stream-wizard/page-completed.cpp
pre-stream-wizard/setting-selection-row.cpp
pre-stream-wizard/encoder-settings-provider-facebook.cpp
obs-app.cpp
Expand Down Expand Up @@ -274,6 +275,7 @@ set(obs_HEADERS
pre-stream-wizard/page-input-display.hpp
pre-stream-wizard/page-start-prompt.hpp
pre-stream-wizard/page-select-settings.hpp
pre-stream-wizard/page-completed.hpp
pre-stream-wizard/setting-selection-row.hpp
pre-stream-wizard/encoder-settings-provider-facebook.hpp
obs-app.hpp
Expand Down
10 changes: 6 additions & 4 deletions UI/common-settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "audio-encoders.hpp"

bool IsAdvancedMode(config_t *config)
static bool IsAdvancedMode(config_t *config)
{
const char *outputMode = config_get_string(config, "Output", "Mode");
return (strcmp(outputMode, "Advanced") == 0);
Expand All @@ -16,7 +16,7 @@ OBSData CommonSettings::GetDataFromJsonFile(const char *jsonFile)
int ret = GetProfilePath(fullPath, sizeof(fullPath), jsonFile);
if (ret > 0) {
BPtr<char> jsonData = os_quick_read_utf8_file(fullPath);
if (!!jsonData) {
if (jsonData) {
data = obs_data_create_from_json(jsonData);
}
}
Expand Down Expand Up @@ -145,7 +145,7 @@ int CommonSettings::GetStreamingAudioBitrate(config_t *config)

int CommonSettings::GetSimpleAudioBitrate(config_t *config)
{
int bitrate = (int)config_get_uint(config, "SimpleOutput", "ABitrate");
int bitrate = config_get_uint(config, "SimpleOutput", "ABitrate");
return FindClosestAvailableAACBitrate(bitrate);
}

Expand All @@ -163,9 +163,11 @@ int CommonSettings::GetAdvancedAudioBitrateForTrack(config_t *config,
"Track4Bitrate", "Track5Bitrate", "Track6Bitrate",
};

// Sanity check for out of bounds
// Sanity check for out of bounds, clamp to bounds
if (trackIndex > 5)
trackIndex = 5;
if (trackIndex < 0)
trackIndex = 0;

int bitrate = (int)config_get_uint(config, "AdvOut", names[trackIndex]);
return FindClosestAvailableAACBitrate(bitrate);
Expand Down
4 changes: 3 additions & 1 deletion UI/data/locale/en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,9 @@ PreLiveWizard.Configure.Error.JsonParse="Problem with server response"
PreLiveWizard.Configure.Error.JsonParse.Description="Wizard is unavailble at the moment."
PreLiveWizard.Selection.Title="Settings Suggested"
PreLiveWizard.Selection.Description="Suggested video settings for your best stream."

PreLiveWizard.Completed.Title="Encoder configured"
PreLiveWizard.Completed.BodyText="Applied suggested settings and encoder is setup to stream. You can now close the wizard."
PreLiveWizard.Completed.FacebookOnly="To finish going live go to Facebook Live:"

# basic mode 'output' settings
Basic.Settings.Output="Output"
Expand Down
21 changes: 18 additions & 3 deletions UI/pre-stream-wizard/encoder-settings-provider-facebook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include <QJsonObject>
#include <QJsonArray>
#include <QMap>
#include <QDebug>

#include "obs-app.hpp"
#include "obs-config.h"
Expand Down Expand Up @@ -57,7 +56,7 @@ void FacebookEncoderSettingsProvider::makeRequest(QUrl &url)
"application/json");

// GET is made async
settingsReply_ = restclient_->get(request);
restclient_->get(request);
// This is the callback when data is ready
connect(restclient_, &QNetworkAccessManager::finished, this,
&FacebookEncoderSettingsProvider::handleResponse);
Expand All @@ -66,7 +65,7 @@ void FacebookEncoderSettingsProvider::makeRequest(QUrl &url)
QUrlQuery FacebookEncoderSettingsProvider::inputVideoQueryFromCurrentSettings()
{
// Get input settings, shorten name
EncoderSettingsRequest *input = currentSettings_.get();
EncoderSettingsRequest *input = currentSettings_.data();

QUrlQuery inputVideoSettingsQuery;
inputVideoSettingsQuery.addQueryItem("video_type", "live");
Expand Down Expand Up @@ -126,6 +125,10 @@ void addInt(const QJsonObject &json, const char *jsonKey, SettingsMap *map,
if (json[jsonKey].isDouble()) {
map->insert(mapKey,
QPair(QVariant(json[jsonKey].toInt()), true));
} else {
blog(LOG_WARNING,
"FacebookEncoderSettingsProvider could not parse %s to Int",
jsonKey);
}
}

Expand All @@ -140,6 +143,10 @@ void addStringDouble(const QJsonObject &json, const char *jsonKey,
double numberValue = valueString.toDouble(&converted);
if (converted) {
map->insert(mapKey, QPair(QVariant(numberValue), true));
} else {
blog(LOG_WARNING,
"FacebookEncoderSettingsProvider couldn't parse %s to Double from String",
jsonKey);
}
}

Expand All @@ -149,6 +156,10 @@ void addQString(const QJsonObject &json, const char *jsonKey, SettingsMap *map,
if (json[jsonKey].isString()) {
map->insert(mapKey,
QPair(QVariant(json[jsonKey].toString()), true));
} else {
blog(LOG_WARNING,
"FacebookEncoderSettingsProvider could not parse %s to Strng",
jsonKey);
}
}

Expand All @@ -158,6 +169,10 @@ void addBool(const QJsonObject &json, const char *jsonKey, SettingsMap *map,
if (json[jsonKey].isBool()) {
map->insert(mapKey,
QPair(QVariant(json[jsonKey].toBool()), true));
} else {
blog(LOG_WARNING,
"FacebookEncoderSettingsProvider could not parse %s to Bool",
jsonKey);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class FacebookEncoderSettingsProvider : public QObject {
private:
QSharedPointer<EncoderSettingsRequest> currentSettings_;
QNetworkAccessManager *restclient_;
QNetworkReply *settingsReply_;

void makeRequest(QUrl &url);
QUrlQuery inputVideoQueryFromCurrentSettings();
Expand Down
69 changes: 69 additions & 0 deletions UI/pre-stream-wizard/page-completed.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#include "page-completed.hpp"

#include <QVBoxLayout>
#include <QLabel>
#include <QPushButton>
#include <QUrl>
#include <QSpacerItem>
#include <QDesktopServices>

#include "obs-app.hpp"

namespace StreamWizard {

CompletedPage::CompletedPage(Destination destination,
LaunchContext launchContext, QWidget *parent)
: QWizardPage(parent)
{
destination_ = destination;
launchContext_ = launchContext;

setTitle(QTStr("PreLiveWizard.Completed.Title"));

QVBoxLayout *mainlayout = new QVBoxLayout(this);
setLayout(mainlayout);

// Later will suggest starting stream if launchContext is PreStream
QLabel *closeLabel =
new QLabel(QTStr("PreLiveWizard.Completed.BodyText"), this);
closeLabel->setWordWrap(true);
mainlayout->addWidget(closeLabel);

if (destination_ == Destination::Facebook) {
mainlayout->addSpacerItem(new QSpacerItem(12, 12));

QLabel *facebookGoLiveLabel = new QLabel(
QTStr("PreLiveWizard.Completed.FacebookOnly"), this);
facebookGoLiveLabel->setWordWrap(true);
QPushButton *launchButton = new QPushButton(
QTStr("PreLiveWizard.Prompt.FBResolutionHelpButton.FB"),
this);
launchButton->setToolTip(QTStr(
"PreLiveWizard.Prompt.FBResolutionHelpButton.FB.ToolTip"));
connect(launchButton, &QPushButton::clicked, this,
&CompletedPage::didPushOpenWebsite);

mainlayout->addWidget(facebookGoLiveLabel);
mainlayout->addWidget(launchButton);
}
}

void CompletedPage::didPushOpenWebsite()
{
QUrl helpUrl;

// Prepare per-destination
if (destination_ == Destination::Facebook) {
helpUrl = QUrl(
"https://www.facebook.com/live/producer/?ref=OBS_Wizard",
QUrl::TolerantMode);
} else {
return;
}
// Launch
if (helpUrl.isValid()) {
QDesktopServices::openUrl(helpUrl);
}
}

} // namespace StreamWizard
26 changes: 26 additions & 0 deletions UI/pre-stream-wizard/page-completed.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

#include <QWizardPage>

#include "pre-stream-current-settings.hpp"

namespace StreamWizard {

// Last Page
class CompletedPage : public QWizardPage {
Q_OBJECT

public:
CompletedPage(Destination destination, LaunchContext launchContext,
QWidget *parent = nullptr);

private:
Destination destination_;
LaunchContext launchContext_;

private slots:
void didPushOpenWebsite();

}; // class CompletedPage

} // namespace StreamWizard
13 changes: 7 additions & 6 deletions UI/pre-stream-wizard/page-select-settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ SelectionPage::SelectionPage(QWidget *parent) : QWizardPage(parent)
{
this->setTitle(QTStr("PreLiveWizard.Selection.Title"));
setupLayout();
}

SelectionPage::~SelectionPage()
{
// nop
setButtonText(QWizard::WizardButton::NextButton,
QTStr("Basic.AutoConfig.ApplySettings"));
setButtonText(QWizard::WizardButton::CommitButton,
QTStr("Basic.AutoConfig.ApplySettings"));
setCommitPage(true);
}

void SelectionPage::setupLayout()
Expand Down Expand Up @@ -58,7 +59,7 @@ void SelectionPage::setSettingsMap(QSharedPointer<SettingsMap> settingsMap)
return;
}
settingsMap_ = settingsMap;
SettingsMap *mapInfo = settingsMap_.get();
SettingsMap *mapInfo = settingsMap_.data();

if (mapInfo->contains(SettingsResponseKeys.videoBitrate)) {
QVariant data =
Expand Down Expand Up @@ -190,7 +191,7 @@ void SelectionPage::checkboxRowChanged(const char *propertyKey, bool selected)
return;
}

SettingsMap *mapInfo = settingsMap_.get();
SettingsMap *mapInfo = settingsMap_.data();

if (mapInfo == nullptr || !mapInfo->contains(propertyKey)) {
return;
Expand Down
1 change: 0 additions & 1 deletion UI/pre-stream-wizard/page-select-settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class SelectionPage : public QWizardPage {

public:
SelectionPage(QWidget *parent = nullptr);
~SelectionPage();

// Sets data to layout scrollbox
void setSettingsMap(QSharedPointer<SettingsMap> settingsMap);
Expand Down
6 changes: 0 additions & 6 deletions UI/pre-stream-wizard/page-start-prompt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ StartPage::StartPage(Destination dest, LaunchContext launchContext,
resCurrentButton_->setChecked(true);
}
}

StartPage::~StartPage()
{
// nop
}

void StartPage::createLayout()
{
QVBoxLayout *mainlayout = new QVBoxLayout(this);
Expand Down
1 change: 0 additions & 1 deletion UI/pre-stream-wizard/page-start-prompt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class StartPage : public QWizardPage {
public:
StartPage(Destination dest, LaunchContext launchContext,
QSize videoSize, QWidget *parent = nullptr);
~StartPage();

signals:
// emitted selected resolution from start page radio buttons
Expand Down
23 changes: 8 additions & 15 deletions UI/pre-stream-wizard/pre-stream-current-settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,13 @@ static const struct {
const char *streamRateControlMode; // string "CBR"
const char *streamBufferSize; // int (5000 kb)
} SettingsResponseKeys = {
.videoWidth = "videoWidth",
.videoHeight = "videoHeight",
.framerate = "framerate",
.videoBitrate = "videoBitrate",
.protocol = "protocol",
.videoCodec = "videoCodec",
.h264Profile = "h264Profile",
.h264Level = "h264Level",
.gopSizeInFrames = "gopSizeInFrames",
.gopType = "gopType",
.gopClosed = "gopClosed",
.gopBFrames = "gopBFrames",
.gopRefFrames = "gopRefFrames",
.streamRateControlMode = "streamRateControlMode",
.streamBufferSize = "streamBufferSize",
"videoWidth", "videoHeight",
"framerate", "videoBitrate",
"protocol", "videoCodec",
"h264Profile", "h264Level",
"gopSizeInFrames", "gopType",
"gopClosed", "gopBFrames",
"gopRefFrames", "streamRateControlMode",
"streamBufferSize",
};
}
15 changes: 13 additions & 2 deletions UI/pre-stream-wizard/pre-stream-wizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@
#include "page-input-display.hpp"
#include "page-start-prompt.hpp"
#include "page-select-settings.hpp"
#include "page-completed.hpp"

namespace StreamWizard {

enum PSW_Page { Page_StartPrompt, Page_Loading, Page_Selections };
enum PSW_Page {
Page_StartPrompt,
Page_Loading,
Page_Selections,
Page_Complete,
};

PreStreamWizard::PreStreamWizard(
Destination dest, LaunchContext launchContext,
Expand Down Expand Up @@ -45,6 +51,11 @@ PreStreamWizard::PreStreamWizard(
// Suggestion Selection Page
selectionPage_ = new SelectionPage();
setPage(Page_Selections, selectionPage_);

// Ending + Confirmation Page
CompletedPage *completedPage =
new CompletedPage(destination_, launchContext_, this);
setPage(Page_Complete, completedPage);
}

void PreStreamWizard::requestSettings()
Expand Down Expand Up @@ -106,7 +117,7 @@ void PreStreamWizard::onUserSelectResolution(QSize newSize)
{
blog(LOG_INFO, "Selected res %d x %d", newSize.width(),
newSize.height());
EncoderSettingsRequest *req = currentSettings_.get();
EncoderSettingsRequest *req = currentSettings_.data();
req->userSelectedResolution = QVariant(newSize);
}

Expand Down
4 changes: 0 additions & 4 deletions UI/pre-stream-wizard/setting-selection-row.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ SelectionRow::SelectionRow(QWidget *parent) : QWidget(parent)
{
createLayout();
}
SelectionRow::~SelectionRow()
{
// nop
}

void SelectionRow::createLayout()
{
Expand Down
1 change: 0 additions & 1 deletion UI/pre-stream-wizard/setting-selection-row.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class SelectionRow : public QWidget {

public:
SelectionRow(QWidget *parent = nullptr);
~SelectionRow();

// User facing name to be shown to the user. ("Resolution")
void setName(QString newName);
Expand Down
Loading

0 comments on commit 89eb3e2

Please sign in to comment.