aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils.h
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2020-03-31 17:07:38 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2020-03-31 17:07:38 +0200
commitec75b9e317baf249d67295300bc5308b7c33f4ac (patch)
tree6f43693530b463fc913f7c7153a3f54a43ebd04b /src/utils.h
parenta1eb6cf861d3c1cbd4e6c016be3cbd2a1e3d797d (diff)
downloadODR-AudioEnc-ec75b9e317baf249d67295300bc5308b7c33f4ac.tar.gz
ODR-AudioEnc-ec75b9e317baf249d67295300bc5308b7c33f4ac.tar.bz2
ODR-AudioEnc-ec75b9e317baf249d67295300bc5308b7c33f4ac.zip
Fix GStreamer input, rework ICY-Text write
Diffstat (limited to 'src/utils.h')
-rw-r--r--src/utils.h45
1 files changed, 42 insertions, 3 deletions
diff --git a/src/utils.h b/src/utils.h
index ca77a53..2f6b639 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -1,8 +1,9 @@
#pragma once
-#include <math.h>
-#include <stdint.h>
-#include <stddef.h>
+#include <string>
+#include <cmath>
+#include <cstdint>
+#include <cstddef>
#define NUMOF(l) (sizeof(l) / sizeof(*l))
@@ -15,3 +16,41 @@ const char* level(int channel, int peak);
size_t strlen_utf8(const char *s);
+struct ICY_TEXT_t {
+ std::string artist;
+ std::string title;
+ std::string now_playing;
+
+ operator bool() const {
+ return not (artist.empty() and title.empty() and now_playing.empty());
+ }
+
+ bool operator==(const ICY_TEXT_t& other) const {
+ return
+ artist == other.artist and
+ title == other.title and
+ now_playing == other.now_playing;
+ }
+ bool operator!=(const ICY_TEXT_t& other) const {
+ return !(*this == other);
+ }
+ void useArtistTitle(const std::string& artist, const std::string& title) {
+ this->artist = artist;
+ this->title = title;
+ now_playing = "";
+ }
+ void useNowPlaying(const std::string& now_playing) {
+ artist = "";
+ title = "";
+ this->now_playing = now_playing;
+ }
+};
+
+/*! Write the corresponding text to a file readable by ODR-PadEnc, with optional
+ * DL+ information. The text is passed as a copy because we actually use the
+ * m_nowplaying variable which is also accessed in another thread, so better
+ * make a copy.
+ *
+ * \return false on failure
+ */
+bool write_icy_to_file(const ICY_TEXT_t text, const std::string& filename, bool dl_plus);