From 823b59e3a77daeb9b8b6157bcbd93bc479491d3b Mon Sep 17 00:00:00 2001 From: John Maguire Date: Mon, 28 May 2012 15:18:36 -0700 Subject: [PATCH] Use uridecodebin for Moodbar. --- src/moodbar/moodbarpipeline.cpp | 41 +++++++++++++++------------------ src/moodbar/moodbarpipeline.h | 23 ++++++++---------- 2 files changed, 29 insertions(+), 35 deletions(-) diff --git a/src/moodbar/moodbarpipeline.cpp b/src/moodbar/moodbarpipeline.cpp index 66cbea099..7bb78938e 100644 --- a/src/moodbar/moodbarpipeline.cpp +++ b/src/moodbar/moodbarpipeline.cpp @@ -20,9 +20,9 @@ #include #include +#include bool MoodbarPipeline::sIsAvailable = false; -QMutex MoodbarPipeline::sFftwMutex; MoodbarPipeline::MoodbarPipeline(const QString& local_filename) : QObject(NULL), @@ -44,22 +44,22 @@ bool MoodbarPipeline::IsAvailable() { return false; } gst_object_unref(factory); - + factory = gst_element_factory_find("moodbar"); if (!factory) { return false; } gst_object_unref(factory); - + sIsAvailable = true; } - + return sIsAvailable; } GstElement* MoodbarPipeline::CreateElement(const QString& factory_name) { GstElement* ret = gst_element_factory_make(factory_name.toAscii().constData(), NULL); - + if (ret) { gst_bin_add(GST_BIN(pipeline_), ret); } else { @@ -75,47 +75,44 @@ void MoodbarPipeline::Start() { if (pipeline_) { return; } - + pipeline_ = gst_pipeline_new("moodbar-pipeline"); - - GstElement* filesrc = CreateElement("filesrc"); - GstElement* decodebin = CreateElement("decodebin"); + + GstElement* decodebin = CreateElement("uridecodebin"); convert_element_ = CreateElement("audioconvert"); GstElement* fftwspectrum = CreateElement("fftwspectrum"); GstElement* moodbar = CreateElement("moodbar"); GstElement* appsink = CreateElement("appsink"); - - if (!filesrc || !convert_element_ || !fftwspectrum || !moodbar || !appsink) { + + if (!decodebin || !convert_element_ || !fftwspectrum || !moodbar || !appsink) { pipeline_ = NULL; emit Finished(false); return; } - QMutexLocker l(&sFftwMutex); - // Join them together - gst_element_link(filesrc, decodebin); gst_element_link_many(convert_element_, fftwspectrum, moodbar, appsink, NULL); - + + QUrl local_url = QUrl::fromLocalFile(local_filename_); // Set properties - g_object_set(filesrc, "location", local_filename_.toUtf8().constData(), NULL); + g_object_set(decodebin, "uri", local_url.toEncoded().constData(), NULL); g_object_set(fftwspectrum, "def-size", 2048, "def-step", 1024, "hiquality", true, NULL); g_object_set(moodbar, "height", 1, "max-width", 1000, NULL); - + // Connect signals - g_signal_connect(decodebin, "new-decoded-pad", G_CALLBACK(NewPadCallback), this); + g_signal_connect(decodebin, "pad-added", G_CALLBACK(NewPadCallback), this); gst_bus_set_sync_handler(gst_pipeline_get_bus(GST_PIPELINE(pipeline_)), BusCallbackSync, this); - + // Set appsink callbacks GstAppSinkCallbacks callbacks; memset(&callbacks, 0, sizeof(callbacks)); callbacks.new_buffer = NewBufferCallback; - + gst_app_sink_set_callbacks(reinterpret_cast(appsink), &callbacks, this, NULL); - + // Start playing gst_element_set_state(pipeline_, GST_STATE_PLAYING); } @@ -133,7 +130,7 @@ void MoodbarPipeline::ReportError(GstMessage* msg) { qLog(Error) << "Error processing" << local_filename_ << ":" << message; } -void MoodbarPipeline::NewPadCallback(GstElement*, GstPad* pad, gboolean, gpointer data) { +void MoodbarPipeline::NewPadCallback(GstElement*, GstPad* pad, gpointer data) { MoodbarPipeline* self = reinterpret_cast(data); GstPad* const audiopad = gst_element_get_pad(self->convert_element_, "sink"); diff --git a/src/moodbar/moodbarpipeline.h b/src/moodbar/moodbarpipeline.h index aafd4be7d..6a8384bb9 100644 --- a/src/moodbar/moodbarpipeline.h +++ b/src/moodbar/moodbarpipeline.h @@ -18,8 +18,6 @@ #ifndef MOODBARPIPELINE_H #define MOODBARPIPELINE_H -#include -#include #include #include @@ -28,13 +26,13 @@ // Creates moodbar data for a single local music file. class MoodbarPipeline : public QObject { Q_OBJECT - + public: MoodbarPipeline(const QString& local_filename); ~MoodbarPipeline(); - + static bool IsAvailable(); - + bool success() const { return success_; } const QByteArray& data() const { return data_; } @@ -43,27 +41,26 @@ public slots: signals: void Finished(bool success); - + private: GstElement* CreateElement(const QString& factory_name); - + void ReportError(GstMessage* message); void Stop(bool success); void Cleanup(); - - static void NewPadCallback(GstElement*, GstPad* pad, gboolean, gpointer data); + + static void NewPadCallback(GstElement*, GstPad* pad, gpointer data); static GstFlowReturn NewBufferCallback(GstAppSink* app_sink, gpointer self); static gboolean BusCallback(GstBus*, GstMessage* msg, gpointer data); static GstBusSyncReply BusCallbackSync(GstBus*, GstMessage* msg, gpointer data); - + private: static bool sIsAvailable; - static QMutex sFftwMutex; - + QString local_filename_; GstElement* pipeline_; GstElement* convert_element_; - + bool success_; QByteArray data_; };