on xenial help sign in
Eradicate gstreamer.
commit4b4fada8a781f49546e0c07e7e2d6ea78eb6a7c0 authorJussi Pakkanen <jussi.pakkanen@canonical.com> dateTue 8 Oct 2013, 12:41 (13 years ago) parent5ea16e0
3 files changed+5−109
plugins/Utils/CMakeLists.txt−5 plugins/Utils/albumartprovider.cpp+4−101 plugins/Utils/albumartprovider.h+1−3
plugins/Utils/CMakeLists.txt−5
@@ -1,12 +1,10 @@
11# Dependencies
22include(FindPkgConfig)
3−pkg_search_module(GST gstreamer-1.0 REQUIRED)
43
54include_directories(
65 ${CMAKE_CURRENT_SOURCE_DIR}
76 ${CMAKE_CURRENT_BINARY_DIR}
87 ${Qt5Gui_PRIVATE_INCLUDE_DIRS}
9− ${GST_INCLUDE_DIRS}
108)
119
1210set(QMLPLUGIN_SRC
@@ -24,9 +22,6 @@ add_library(Utils-qml SHARED
2422 ${QMLPLUGIN_SRC}
2523 )
2624
27−target_link_libraries(Utils-qml
28− ${GST_LDFLAGS}
29− )
3025# Because this is an internal support library, we want
3126# to expose all symbols in it. Consider changing this
3227# either to a static library or just using the
plugins/Utils/albumartprovider.cpp+4−101
@@ -29,107 +29,13 @@
2929#include<QDebug>
3030#include<QFile>
3131#include<QByteArray>
32−#include<gst/gst.h>
3332#include<unistd.h>
3433#include<memory>
3534#include<QImage>
3635
3736using namespace std;
3837
39−static void on_new_pad (GstElement * /*dec*/, GstPad * pad, GstElement * fakesink) {
40− GstPad *sinkpad;
4138
42− sinkpad = gst_element_get_static_pad (fakesink, "sink");
43− if (!gst_pad_is_linked (sinkpad)) {
44− if (gst_pad_link (pad, sinkpad) != GST_PAD_LINK_OK)
45− g_error ("Failed to link pads!");
46− }
47− gst_object_unref (sinkpad);
48−}
49−
50−static void process_one_tag (const GstTagList * list, const gchar * tag, gpointer user_data) {
51− struct albuminfo *md = (struct albuminfo*) user_data;
52− int i, num;
53− string tagname(tag);
54−
55− num = gst_tag_list_get_tag_size (list, tag);
56− for (i = 0; i < num; ++i) {
57− gchar *val;
58− if (gst_tag_get_type(tag) == G_TYPE_STRING) {
59− if (gst_tag_list_get_string_index (list, tag, i, &val)) {
60− if(tagname == "artist")
61− md->artist = std::string(val);
62− if(tagname == "album")
63− md->album = std::string(val);
64− }}
65− }
66−}
67−
68−albuminfo AlbumArtProvider::get_album_info(const std::string &filename) throw (runtime_error)
69−{
70− albuminfo ai;
71− // FIXME: Need to do quoting. Files with %'s in their names seem to confuse gstreamer.
72−
73− const string uri = "file://" + filename;
74−
75− GstElement *dec = gst_element_factory_make ("uridecodebin", NULL);
76− if (dec == nullptr)
77− throw runtime_error("Failed to create uridecodebin element");
78−
79− GstElement *pipe = gst_pipeline_new ("pipeline");
80−
81− g_object_set (dec, "uri", uri.c_str(), NULL);
82− gst_bin_add (GST_BIN (pipe), dec);
83−
84− GstElement *sink = gst_element_factory_make ("fakesink", NULL);
85− gst_bin_add (GST_BIN (pipe), sink);
86− g_signal_connect (dec, "pad-added", G_CALLBACK (on_new_pad), sink);
87−
88− gst_element_set_state (pipe, GST_STATE_PAUSED);
89−
90− GstMessage *msg;
91− while (true) {
92− GstTagList *tags = NULL;
93−
94− msg = gst_bus_timed_pop_filtered(GST_ELEMENT_BUS (pipe),
95− GST_CLOCK_TIME_NONE, (GstMessageType) (GST_MESSAGE_ASYNC_DONE | GST_MESSAGE_TAG | GST_MESSAGE_ERROR));
96−
97− if (GST_MESSAGE_TYPE (msg) != GST_MESSAGE_TAG) /* error or async_done */
98− break;
99−
100− gst_message_parse_tag (msg, &tags);
101− gst_tag_list_foreach (tags, process_one_tag, &ai);
102− gst_tag_list_unref (tags);
103−
104− gst_message_unref (msg);
105− };
106−
107− gst_element_set_state (pipe, GST_STATE_NULL);
108− gst_object_unref (pipe);
109−
110− if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR) {
111− GError *err;
112− gchar *dbg_info;
113− gst_message_parse_error(msg, &err, &dbg_info);
114− string errortxt(err->message);
115− string dbtxt(dbg_info);
116− g_error_free(err);
117− g_free(dbg_info);
118−
119− gst_message_unref (msg);
120− string msg = "Extracting metadata of file ";
121− msg += filename;
122− msg += " failed: ";
123− msg += errortxt;
124− msg += " ";
125− msg += dbg_info;
126− throw runtime_error(msg);
127− }
128−
129− gst_message_unref (msg);
130−
131− return ai;
132−}
13339
13440std::string AlbumArtProvider::get_lastfm_url(const albuminfo &ai) {
13541 QString artist = QString::fromStdString(ai.artist);
@@ -208,14 +114,11 @@ void AlbumArtProvider::fix_format(const std::string &fname) {
208114 im.save(fname.c_str(), "JPEG");
209115}
210116
211−std::string AlbumArtProvider::get_image(const std::string &filename) {
117+std::string AlbumArtProvider::get_image(const std::string &artist, const std::string &album) {
212118 albuminfo info;
213− try {
214− info = get_album_info(filename);
215− } catch(std::exception &e) {
216− qDebug() << "Could not determine album info: " << e.what();
217− return "";
218− }
119+ info.artist = artist;
120+ info.album = album;
121+
219122 if(info.album.empty() || info.artist.empty()) {
220123 return "";
221124 }
plugins/Utils/albumartprovider.h+1−3
@@ -36,15 +36,13 @@ public:
3636 AlbumArtProvider() : QQuickImageProvider(QQmlImageProviderBase::Image, QQmlImageProviderBase::ForceAsynchronousImageLoading) {}
3737 QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize);
3838
39− std::string get_image(const std::string &filename);
39+ std::string get_image(const std::string &artist, const std::string &album);
4040
4141private:
4242 MediaArtCache cache;
4343
4444 void fix_format(const std::string &fname);
4545
46− albuminfo get_album_info(const std::string &filename) throw (std::runtime_error);
47−
4846 std::string get_lastfm_url(const albuminfo &ai);
4947
5048 bool download_and_store(const std::string &image_url, const std::string &output_file);