diff --git a/src/ogg.cc b/src/ogg.cc index d60413a..cc00ced 100644 --- a/src/ogg.cc +++ b/src/ogg.cc @@ -270,5 +270,24 @@ void ogg::Encoder::write_tags(int streamno, const Tags &tags) std::string ogg::Encoder::render_opustags(const Tags &tags) { std::stringbuf s; + uint32_t length; + s.sputn("OpusTags", 8); + length = htole32(tags.vendor.size()); + s.sputn(reinterpret_cast(&length), 4); + s.sputn(tags.vendor.data(), tags.vendor.size()); + + auto assocs = tags.get_all(); + length = htole32(assocs.size()); + s.sputn(reinterpret_cast(&length), 4); + + for (auto assoc : assocs) { + length = htole32(assoc.first.size() + 1 + assoc.second.size()); + s.sputn(reinterpret_cast(&length), 4); + s.sputn(assoc.first.data(), assoc.first.size()); + s.sputc('='); + s.sputn(assoc.second.data(), assoc.second.size()); + } + + s.sputn(tags.extra.data(), tags.extra.size()); return s.str(); } diff --git a/src/tags.cc b/src/tags.cc index 421c84d..d9f14e9 100644 --- a/src/tags.cc +++ b/src/tags.cc @@ -7,7 +7,7 @@ Tags::Tags() : max_index(0) { } -const std::vector> Tags::get_all() const +const std::vector> Tags::get_all() const { std::vector keys; for (const auto &kv : key_to_value) @@ -21,10 +21,10 @@ const std::vector> Tags::get_all() const return key_to_index.at(a) < key_to_index.at(b); }); - std::vector> result; + std::vector> result; for (const auto &key : keys) { result.push_back( - std::make_tuple( + std::make_pair( key, key_to_value.at(key))); } diff --git a/src/tags.h b/src/tags.h index 58d0371..ed51987 100644 --- a/src/tags.h +++ b/src/tags.h @@ -2,7 +2,7 @@ #include #include -#include +#include namespace opustags { @@ -12,7 +12,7 @@ namespace opustags { public: Tags(); - const std::vector> get_all() const; + const std::vector> get_all() const; std::string get(const std::string &key) const; void set(const std::string &key, const std::string &value);