Skip to content

Commit

Permalink
Merge pull request #2055 from daschuer/metadata_tls_fix
Browse files Browse the repository at this point in the history
Metadata tls fix
  • Loading branch information
uklotzde authored Mar 23, 2019
2 parents 47708af + e2c0fae commit 6905ff0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 20 deletions.
65 changes: 45 additions & 20 deletions src/engine/sidechain/shoutconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ ShoutConnection::ShoutConnection(BroadcastProfilePtr profile,
errorDialog(tr("Error setting non-blocking mode:"),
shout_get_error(m_pShout));
}

#ifdef SHOUT_TLS
// Libshout defaults to SHOUT_TLS_AUTO if build with SHOUT_TLS
// Sometimes autodetection fails, resulting into no metadata send
// https://bugs.launchpad.net/mixxx/+bug/1817395
if (shout_set_tls(m_pShout, SHOUT_TLS_DISABLED) != SHOUTERR_SUCCESS) {
errorDialog(tr("Error setting tls mode:"),
shout_get_error(m_pShout));
}
#endif
}

ShoutConnection::~ShoutConnection() {
Expand Down Expand Up @@ -147,6 +157,13 @@ QByteArray ShoutConnection::encodeString(const QString& string) {
return string.toLatin1();
}

void ShoutConnection::insertMetaData(const char *pName, const char *pValue) {
int ret = shout_metadata_add(m_pShoutMetaData, pName, pValue);
if (ret != SHOUTERR_SUCCESS) {
kLogger.warning() << "shout_metadata_add" << pName << "fails with error code" << ret;
}
}

void ShoutConnection::updateFromPreferences() {
kLogger.debug() << m_pProfile->getProfileName()
<< ": updating from preferences";
Expand Down Expand Up @@ -179,17 +196,19 @@ void ShoutConnection::updateFromPreferences() {
// strings to pass to libshout.

QString codec = m_pProfile->getMetadataCharset();
QByteArray baCodec = codec.toLatin1();
m_pTextCodec = QTextCodec::codecForName(baCodec);
if (!m_pTextCodec) {
kLogger.warning()
<< "Couldn't find broadcast metadata codec for codec:" << codec
<< " defaulting to ISO-8859-1.";
if (!codec.isEmpty()) {
QByteArray baCodec = codec.toLatin1();
m_pTextCodec = QTextCodec::codecForName(baCodec);
if (!m_pTextCodec) {
kLogger.warning()
<< "Couldn't find broadcast metadata codec for codec:" << codec
<< " defaulting to ISO-8859-1.";
} else {
// Indicates our metadata is in the provided charset.
insertMetaData("charset", baCodec.constData());
}
}

// Indicates our metadata is in the provided charset.
shout_metadata_add(m_pShoutMetaData, "charset", baCodec.constData());

QString serverType = m_pProfile->getServertype();

QString host = m_pProfile->getHost();
Expand Down Expand Up @@ -705,8 +724,14 @@ bool ShoutConnection::metaDataHasChanged() {

void ShoutConnection::updateMetaData() {
setFunctionCode(5);
if (!m_pShout || !m_pShoutMetaData)
if (!m_pShout) {
kLogger.debug() << "updateMetaData failed, invalid m_pShout";
return;
}
if (!m_pShoutMetaData) {
kLogger.debug() << "updateMetaData failed, invalid m_pShoutMetaData";
return;
}

/**
* If track has changed and static metadata is disabled
Expand Down Expand Up @@ -742,8 +767,8 @@ void ShoutConnection::updateMetaData() {
// old way for those use cases.
if (!m_format_is_mp3 && m_protocol_is_icecast2) {
setFunctionCode(9);
shout_metadata_add(m_pShoutMetaData, "artist", encodeString(artist).constData());
shout_metadata_add(m_pShoutMetaData, "title", encodeString(title).constData());
insertMetaData("artist", encodeString(artist).constData());
insertMetaData("title", encodeString(title).constData());
} else {
// we are going to take the metadata format and replace all
// the references to $title and $artist by doing a single
Expand Down Expand Up @@ -775,10 +800,13 @@ void ShoutConnection::updateMetaData() {

QByteArray baSong = encodeString(metadataFinal);
setFunctionCode(10);
shout_metadata_add(m_pShoutMetaData, "song", baSong.constData());
insertMetaData("song", baSong.constData());
}
setFunctionCode(11);
shout_set_metadata(m_pShout, m_pShoutMetaData);
int ret = shout_set_metadata(m_pShout, m_pShoutMetaData);
if (ret != SHOUTERR_SUCCESS) {
kLogger.warning() << "shout_set_metadata fails with error code" << ret;
}
}
} else {
// Otherwise we might use static metadata
Expand All @@ -788,14 +816,11 @@ void ShoutConnection::updateMetaData() {
// see comment above...
if (!m_format_is_mp3 && m_protocol_is_icecast2) {
setFunctionCode(12);
shout_metadata_add(
m_pShoutMetaData,"artist",encodeString(m_customArtist).constData());

shout_metadata_add(
m_pShoutMetaData,"title",encodeString(m_customTitle).constData());
insertMetaData("artist", encodeString(m_customArtist).constData());
insertMetaData("title", encodeString(m_customTitle).constData());
} else {
QByteArray baCustomSong = encodeString(m_customArtist.isEmpty() ? m_customTitle : m_customArtist + " - " + m_customTitle);
shout_metadata_add(m_pShoutMetaData, "song", baCustomSong.constData());
insertMetaData("song", baCustomSong.constData());
}

setFunctionCode(13);
Expand Down
1 change: 1 addition & 0 deletions src/engine/sidechain/shoutconnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class ShoutConnection
bool waitForRetry();

void tryReconnect();
void insertMetaData(const char *name, const char *value);

QTextCodec* m_pTextCodec;
TrackPointer m_pMetaData;
Expand Down

0 comments on commit 6905ff0

Please sign in to comment.