diff --git a/src/engines/enginebase.h b/src/engines/enginebase.h index 0255fc872..b9accc84f 100644 --- a/src/engines/enginebase.h +++ b/src/engines/enginebase.h @@ -43,7 +43,6 @@ class Base : public QObject, boost::noncopyable { virtual ~Base(); virtual bool Init() = 0; - virtual bool CanDecode(const QUrl &url) = 0; virtual void StartPreloading(const QUrl&, qint64, qint64) {} virtual bool Play(quint64 offset_nanosec) = 0; diff --git a/src/engines/gstengine.cpp b/src/engines/gstengine.cpp index c6afc90a6..b1ad7aeab 100644 --- a/src/engines/gstengine.cpp +++ b/src/engines/gstengine.cpp @@ -169,97 +169,6 @@ void GstEngine::ReloadSettings() { } -bool GstEngine::CanDecode(const QUrl &url) { - EnsureInitialised(); - - // We had some bug reports claiming that video files cause crashes in canDecode(), - // so don't try to decode them - if ( url.path().toLower().endsWith( ".mov" ) || - url.path().toLower().endsWith( ".avi" ) || - url.path().toLower().endsWith( ".wmv" ) ) - return false; - - can_decode_success_ = false; - can_decode_last_ = false; - - // Create the pipeline - shared_ptr pipeline(gst_pipeline_new("pipeline"), - boost::bind(gst_object_unref, _1)); - if (!pipeline) return false; - GstElement* src = CreateElement("giosrc", pipeline.get()); if (!src) return false; - GstElement* bin = CreateElement("decodebin2", pipeline.get()); if (!bin) return false; - - gst_element_link(src, bin); - g_signal_connect(G_OBJECT(bin), "new-decoded-pad", G_CALLBACK(CanDecodeNewPadCallback), this); - g_signal_connect(G_OBJECT(bin), "no-more-pads", G_CALLBACK(CanDecodeLastCallback), this); - - // These handlers just print out errors to stderr - gst_bus_set_sync_handler(gst_pipeline_get_bus(GST_PIPELINE(pipeline.get())), CanDecodeBusCallbackSync, 0); - gst_bus_add_watch(gst_pipeline_get_bus(GST_PIPELINE(pipeline.get())), CanDecodeBusCallback, 0); - - // Set the file we're testing - g_object_set(G_OBJECT(src), "location", url.toEncoded().constData(), NULL); - - // Start the pipeline playing - gst_element_set_state(pipeline.get(), GST_STATE_PLAYING); - - // Wait until found audio stream - int count = 0; - while (!can_decode_success_ && !can_decode_last_ && count < 100) { - count++; - usleep(1000); - } - - // Stop playing - gst_element_set_state(pipeline.get(), GST_STATE_NULL); - - return can_decode_success_; -} - - - -void GstEngine::CanDecodeNewPadCallback(GstElement*, GstPad* pad, gboolean, gpointer self) { - GstEngine* instance = reinterpret_cast(self); - - GstCaps* caps = gst_pad_get_caps(pad); - if (gst_caps_get_size(caps) > 0) { - GstStructure* str = gst_caps_get_structure(caps, 0); - if (g_strrstr(gst_structure_get_name( str ), "audio" )) - instance->can_decode_success_ = true; - } - gst_caps_unref(caps); -} - -void GstEngine::CanDecodeLastCallback(GstElement*, gpointer self) { - GstEngine* instance = reinterpret_cast(self); - instance->can_decode_last_ = true; -} - -void GstEngine::PrintGstError(GstMessage *msg) { - GError* error; - gchar* debugs; - - gst_message_parse_error(msg, &error, &debugs); - qDebug() << error->message; - qDebug() << debugs; - - g_error_free(error); - free(debugs); -} - -GstBusSyncReply GstEngine::CanDecodeBusCallbackSync(GstBus*, GstMessage* msg, gpointer) { - if (GST_MESSAGE_TYPE(msg) == GST_MESSAGE_ERROR) - PrintGstError(msg); - return GST_BUS_PASS; -} - -gboolean GstEngine::CanDecodeBusCallback(GstBus*, GstMessage* msg, gpointer) { - if (GST_MESSAGE_TYPE(msg) == GST_MESSAGE_ERROR) - PrintGstError(msg); - return GST_BUS_DROP; -} - - qint64 GstEngine::position_nanosec() const { if (!current_pipeline_) return 0; diff --git a/src/engines/gstengine.h b/src/engines/gstengine.h index 983cf0988..0c18e2a3a 100644 --- a/src/engines/gstengine.h +++ b/src/engines/gstengine.h @@ -68,8 +68,6 @@ class GstEngine : public Engine::Base, public BufferConsumer { bool Init(); void EnsureInitialised() { initialising_.waitForFinished(); } - bool CanDecode(const QUrl& url); - int AddBackgroundStream(const QUrl& url); void StopBackgroundStream(int id); void SetBackgroundStreamVolume(int id, int volume); @@ -129,13 +127,6 @@ class GstEngine : public Engine::Base, public BufferConsumer { typedef QPair PlayFutureWatcherArg; typedef BoundFutureWatcher PlayFutureWatcher; - // Callbacks - static void CanDecodeNewPadCallback(GstElement*, GstPad*, gboolean, gpointer); - static void CanDecodeLastCallback(GstElement*, gpointer); - static GstBusSyncReply CanDecodeBusCallbackSync(GstBus*, GstMessage*, gpointer); - static gboolean CanDecodeBusCallback(GstBus*, GstMessage*, gpointer); - static void PrintGstError(GstMessage* msg); - static void SetEnv(const char* key, const QString& value); PluginDetailsList GetPluginList(const QString& classname) const; void InitialiseGstreamer(); diff --git a/tests/fileformats_test.cpp b/tests/fileformats_test.cpp index 01ff2bb99..209ce94b6 100644 --- a/tests/fileformats_test.cpp +++ b/tests/fileformats_test.cpp @@ -94,21 +94,4 @@ TEST_P(FileformatsTest, LoadsTags) { } } -TEST_P(FileformatsTest, GstCanDecode) { - QTemporaryFile temp(temp_filetemplate_); - SaveToTempFile(&temp); - - QSignalSpy spy(sGstEngine, SIGNAL(Error(QString))); - - EXPECT_TRUE(sGstEngine->CanDecode(QUrl::fromLocalFile(temp.fileName()))); - - QList > calls(spy); - foreach (const QList& call, calls) { - qDebug() << "GstEngine::Error emitted:" << call[0].toString(); - } -} - -INSTANTIATE_TEST_CASE_P(Formats, FileformatsTest, ::testing::Values( - "flac", "mp3", "ogg", "spx", "wav", "wma", "m4a")); - } // namespace