[Merge] lp:~phablet-team/media-hub/fix-1498962 into lp:media-hub
Jim Hodapp
jim.hodapp at canonical.com
Thu Jun 9 16:42:42 UTC 2016
Diff comments:
>
> === modified file 'src/core/media/codec.h'
> --- src/core/media/codec.h 2015-04-14 19:11:15 +0000
> +++ src/core/media/codec.h 2016-06-08 21:03:16 +0000
> @@ -60,16 +68,72 @@
> template<>
> struct Codec<core::ubuntu::media::Track::MetaData>
> {
> - static void encode_argument(core::dbus::Message::Writer& out, const core::ubuntu::media::Track::MetaData& in)
> + static void encode_argument(core::dbus::Message::Writer& writer, const core::ubuntu::media::Track::MetaData& md)
> {
> - (void) out;
> - (void) in;
> + typedef std::pair<std::string, dbus::types::Variant> Pair;
> + auto dict = writer.open_array(dbus::types::Signature{dbus::helper::TypeMapper<Pair>::signature()});
> +
> + for (const auto& pair : *md)
> + {
> + auto de = dict.open_dict_entry();
> + {
> + if (pair.first == "mpris:length" and not pair.second.empty())
It can yes, I'll change to using a constant instead of the string literal.
> + {
> + Codec<Pair>::encode_argument(de, std::make_pair(pair.first, dbus::types::Variant::encode(boost::lexical_cast<std::int64_t>(pair.second))));
> + }
> + else if (pair.first == xesam::Album::name and not pair.second.empty())
> + {
> + Codec<Pair>::encode_argument(de, std::make_pair(pair.first, dbus::types::Variant::encode(pair.second)));
> + }
> + else if (pair.first == xesam::AlbumArtist::name and not pair.second.empty())
> + {
> +#if 0
> + // TODO: This code doesn't work but will be needed for full MPRIS compliance. Technically
> + // there can be more than one album artist stuffed into an array.
Yeah I'll add some more to the comment. Basically though it's just figuring out how to express it in a way that makes dbus-cpp happy. It's very difficult to work with and to know why it's not working right.
> + auto array = de.open_array(dbus::types::Signature{dbus::helper::TypeMapper<Pair>::signature()});
> + {
> + // TODO: this should really iterate over all artists, but seems we only extract one artist from playbin
> + Codec<Pair>::encode_argument(array, std::make_pair(pair.first, dbus::types::Variant::encode(pair.second)));
> + }
> + de.close_array(std::move(array));
> +#else
> + Codec<Pair>::encode_argument(de, std::make_pair(pair.first, dbus::types::Variant::encode(pair.second)));
> +#endif
> + }
> + else
> + {
> + Codec<Pair>::encode_argument(de, std::make_pair(pair.first, dbus::types::Variant::encode(pair.second)));
> + }
> + }
> + dict.close_dict_entry(std::move(de));
> + }
> + writer.close_array(std::move(dict));
> }
>
> - static void decode_argument(core::dbus::Message::Reader& out, core::ubuntu::media::Track::MetaData& in)
> + static void decode_argument(core::dbus::Message::Reader& reader, core::ubuntu::media::Track::MetaData& md)
> {
> - (void) out;
> - (void) in;
> + auto array = reader.pop_array();
> +
> + while (array.type() != dbus::ArgumentType::invalid)
> + {
> + auto entry = array.pop_dict_entry();
> + {
> + std::string key {entry.pop_string()};
> + auto variant = entry.pop_variant();
> + {
> + if (key == xesam::Album::name)
> + {
> + const std::string album = variant.pop_string();
> + MH_DEBUG("Getting key \"%s\" and value \"%s\"", key, album);
> + md.set_album(album);
> + }
> + else
> + {
> + MH_WARNING("Unknown metadata key \"%s\" while decoding dbus message", key);
> + }
> + }
> + }
> + }
> }
> };
>
--
https://code.launchpad.net/~phablet-team/media-hub/fix-1498962/+merge/296604
Your team Ubuntu Phablet Team is subscribed to branch lp:media-hub.
More information about the Ubuntu-reviews
mailing list