Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Broadcasting profiles #1278

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build/depends.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,7 @@ def sources(self, build):
"preferences/settingsmanager.cpp",
"preferences/replaygainsettings.cpp",
"preferences/broadcastsettings.cpp",
"preferences/broadcastprofile.cpp",
"preferences/upgrade.cpp",
"preferences/dlgpreferencepage.cpp",

Expand Down
49 changes: 25 additions & 24 deletions src/encoder/encoderbroadcastsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@

#define DEFAULT_BITRATE 128

EncoderBroadcastSettings::EncoderBroadcastSettings(BroadcastSettings settings) :
m_settings(settings)
{
EncoderBroadcastSettings::EncoderBroadcastSettings(BroadcastSettings* settings) :
m_pSettings(settings) {
m_qualList.append(32);
m_qualList.append(48);
m_qualList.append(64);
Expand All @@ -26,41 +25,40 @@ m_settings(settings)
m_qualList.append(256);
m_qualList.append(320);
}
EncoderBroadcastSettings::~EncoderBroadcastSettings()
{

EncoderBroadcastSettings::~EncoderBroadcastSettings() {
}


QList<int> EncoderBroadcastSettings::getQualityValues() const
{
QList<int> EncoderBroadcastSettings::getQualityValues() const {
return m_qualList;
}

// Sets the value
void EncoderBroadcastSettings::setQualityByValue(int qualityValue)
{
void EncoderBroadcastSettings::setQualityByValue(int qualityValue) {
BroadcastProfile* profile = m_pSettings->getCurrentProfile();

if (m_qualList.contains(qualityValue)) {
m_settings.setBitrate(qualityValue);
profile->setBitrate(qualityValue);
} else {
qWarning() << "Invalid qualityValue given to EncoderBroadcastSettings: "
<< qualityValue << ". Ignoring it";
}
}

void EncoderBroadcastSettings::setQualityByIndex(int qualityIndex)
{
void EncoderBroadcastSettings::setQualityByIndex(int qualityIndex) {
BroadcastProfile* profile = m_pSettings->getCurrentProfile();

if (qualityIndex >= 0 && qualityIndex < m_qualList.size()) {
m_settings.setBitrate(m_qualList.at(qualityIndex));
profile->setBitrate(m_qualList.at(qualityIndex));
} else {
qWarning() << "Invalid qualityIndex given to EncoderBroadcastSettings: "
<< qualityIndex << ". Ignoring it";
}
}

int EncoderBroadcastSettings::getQuality() const
{
int bitrate = m_settings.getBitrate();
int EncoderBroadcastSettings::getQuality() const {
BroadcastProfile* profile = m_pSettings->getCurrentProfile();

int bitrate = profile->getBitrate();
if (m_qualList.contains(bitrate)) {
return bitrate;
}
Expand All @@ -70,18 +68,21 @@ int EncoderBroadcastSettings::getQuality() const
}
return DEFAULT_BITRATE;
}
int EncoderBroadcastSettings::getQualityIndex() const
{

int EncoderBroadcastSettings::getQualityIndex() const {
return m_qualList.indexOf(getQuality());
}

void EncoderBroadcastSettings::setChannelMode(EncoderSettings::ChannelMode mode)
{
m_settings.setChannels(static_cast<int>(mode));
BroadcastProfile* profile = m_pSettings->getCurrentProfile();
profile->setChannels(static_cast<int>(mode));
}
EncoderSettings::ChannelMode EncoderBroadcastSettings::getChannelMode() const
{
switch(m_settings.getChannels()) {

EncoderSettings::ChannelMode EncoderBroadcastSettings::getChannelMode() const {
BroadcastProfile* profile = m_pSettings->getCurrentProfile();

switch(profile->getChannels()) {
case 1: return EncoderSettings::ChannelMode::MONO;
case 2: return EncoderSettings::ChannelMode::STEREO;
case 0: // fallthrough
Expand Down
4 changes: 2 additions & 2 deletions src/encoder/encoderbroadcastsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

class EncoderBroadcastSettings : public EncoderSettings {
public:
EncoderBroadcastSettings(BroadcastSettings settings);
EncoderBroadcastSettings(BroadcastSettings* settings);
virtual ~EncoderBroadcastSettings();

// Indicates that it uses the quality slider section of the preferences
Expand All @@ -39,7 +39,7 @@ class EncoderBroadcastSettings : public EncoderSettings {

private:
QList<int> m_qualList;
BroadcastSettings m_settings;
BroadcastSettings* m_pSettings;
};


Expand Down
54 changes: 28 additions & 26 deletions src/engine/sidechain/enginebroadcast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ QByteArray EngineBroadcast::encodeString(const QString& string) {
}

void EngineBroadcast::updateFromPreferences() {
BroadcastProfile* profile = m_settings.getCurrentProfile();

qDebug() << "EngineBroadcast: updating from preferences";
NetworkStreamWorker::debugState();

Expand Down Expand Up @@ -164,7 +166,7 @@ void EngineBroadcast::updateFromPreferences() {
// Convert a bunch of QStrings to QByteArrays so we can get regular C char*
// strings to pass to libshout.

QString codec = m_settings.getMetadataCharset();
QString codec = profile->getMetadataCharset();
QByteArray baCodec = codec.toLatin1();
m_pTextCodec = QTextCodec::codecForName(baCodec);
if (!m_pTextCodec) {
Expand All @@ -175,9 +177,9 @@ void EngineBroadcast::updateFromPreferences() {
// Indicates our metadata is in the provided charset.
shout_metadata_add(m_pShoutMetaData, "charset", baCodec.constData());

QString serverType = m_settings.getServertype();
QString serverType = profile->getServertype();

QString host = m_settings.getHost();
QString host = profile->getHost();
int start = host.indexOf(QLatin1String("//"));
if (start == -1) {
// the host part requires preceding //.
Expand All @@ -187,54 +189,54 @@ void EngineBroadcast::updateFromPreferences() {
}
QUrl serverUrl = host;

int port = m_settings.getPort();
int port = profile->getPort();
serverUrl.setPort(port);

QString mountPoint = m_settings.getMountpoint();
QString mountPoint = profile->getMountpoint();
if (!mountPoint.isEmpty()) {
if (!mountPoint.startsWith('/')) {
mountPoint.prepend('/');
}
serverUrl.setPath(mountPoint);
}

QString login = m_settings.getLogin();
QString login = profile->getLogin();
if (!login.isEmpty()) {
serverUrl.setUserName(login);
}

qDebug() << "Using server URL:" << serverUrl;

QByteArray baPassword = m_settings.getPassword().toLatin1();
QByteArray baFormat = m_settings.getFormat().toLatin1();
int iBitrate = m_settings.getBitrate();
QByteArray baPassword = profile->getPassword().toLatin1();
QByteArray baFormat = profile->getFormat().toLatin1();
int iBitrate = profile->getBitrate();

// Encode metadata like stream name, website, desc, genre, title/author with
// the chosen TextCodec.
QByteArray baStreamName = encodeString(m_settings.getStreamName());
QByteArray baStreamWebsite = encodeString(m_settings.getStreamWebsite());
QByteArray baStreamDesc = encodeString(m_settings.getStreamDesc());
QByteArray baStreamGenre = encodeString(m_settings.getStreamGenre());
QByteArray baStreamName = encodeString(profile->getStreamName());
QByteArray baStreamWebsite = encodeString(profile->getStreamWebsite());
QByteArray baStreamDesc = encodeString(profile->getStreamDesc());
QByteArray baStreamGenre = encodeString(profile->getStreamGenre());

// Whether the stream is public.
bool streamPublic = m_settings.getStreamPublic();
bool streamPublic = profile->getStreamPublic();

// Dynamic Ogg metadata update
m_ogg_dynamic_update = m_settings.getOggDynamicUpdate();
m_ogg_dynamic_update = profile->getOggDynamicUpdate();

m_custom_metadata = m_settings.getEnableMetadata();
m_customTitle = m_settings.getCustomTitle();
m_customArtist = m_settings.getCustomArtist();
m_custom_metadata = profile->getEnableMetadata();
m_customTitle = profile->getCustomTitle();
m_customArtist = profile->getCustomArtist();

m_metadataFormat = m_settings.getMetadataFormat();
m_metadataFormat = profile->getMetadataFormat();

bool enableReconnect = m_settings.getEnableReconnect();
bool enableReconnect = profile->getEnableReconnect();
if (enableReconnect) {
m_reconnectFirstDelay = m_settings.getReconnectFirstDelay();
m_reconnectPeriod = m_settings.getReconnectPeriod();
m_noDelayFirstReconnect = m_settings.getNoDelayFirstReconnect();
m_limitReconnects = m_settings.getLimitReconnects();
m_maximumRetries = m_settings.getMaximumRetries();
m_reconnectFirstDelay = profile->getReconnectFirstDelay();
m_reconnectPeriod = profile->getReconnectPeriod();
m_noDelayFirstReconnect = profile->getNoDelayFirstReconnect();
m_limitReconnects = profile->getLimitReconnects();
m_maximumRetries = profile->getMaximumRetries();
} else {
m_limitReconnects = true;
m_maximumRetries = 0;
Expand Down Expand Up @@ -364,7 +366,7 @@ void EngineBroadcast::updateFromPreferences() {
}

// Initialize m_encoder
EncoderBroadcastSettings broadcastSettings(m_settings);
EncoderBroadcastSettings broadcastSettings(&m_settings);
if (m_format_is_mp3) {
m_encoder = EncoderFactory::getFactory().getNewEncoder(
EncoderFactory::getFactory().getFormatFor(ENCODING_MP3), m_pConfig, this);
Expand Down
Loading