Skip to content

Commit

Permalink
Improve error handling when sending broadcasting metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
daschuer committed Mar 14, 2019
1 parent e2aa34d commit 9921c2e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
35 changes: 24 additions & 11 deletions src/engine/sidechain/shoutconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,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 @@ -705,8 +712,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 +755,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 +788,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 +804,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 9921c2e

Please sign in to comment.