From 9921c2e5e166c83de2c87ccb140c167cbb3d123e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Thu, 14 Mar 2019 07:04:37 +0100 Subject: [PATCH] Improve error handling when sending broadcasting metadata --- src/engine/sidechain/shoutconnection.cpp | 35 ++++++++++++++++-------- src/engine/sidechain/shoutconnection.h | 1 + 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/engine/sidechain/shoutconnection.cpp b/src/engine/sidechain/shoutconnection.cpp index b72b9dda6da..9c272c69128 100644 --- a/src/engine/sidechain/shoutconnection.cpp +++ b/src/engine/sidechain/shoutconnection.cpp @@ -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"; @@ -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 @@ -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 @@ -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 @@ -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); diff --git a/src/engine/sidechain/shoutconnection.h b/src/engine/sidechain/shoutconnection.h index 225fdef9b8e..d771a0871d8 100644 --- a/src/engine/sidechain/shoutconnection.h +++ b/src/engine/sidechain/shoutconnection.h @@ -116,6 +116,7 @@ class ShoutConnection bool waitForRetry(); void tryReconnect(); + void insertMetaData(const char *name, const char *value); QTextCodec* m_pTextCodec; TrackPointer m_pMetaData;