More debug output in CanDecode, and set the gst path in GstEngine rather than main()
This commit is contained in:
parent
06aaaf15f5
commit
7263983e0c
@ -28,6 +28,9 @@
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include <boost/bind.hpp>
|
||||||
|
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QRegExp>
|
#include <QRegExp>
|
||||||
@ -38,7 +41,6 @@
|
|||||||
#include <QTimeLine>
|
#include <QTimeLine>
|
||||||
|
|
||||||
#include <gst/gst.h>
|
#include <gst/gst.h>
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
|
|
||||||
using std::vector;
|
using std::vector;
|
||||||
@ -70,6 +72,27 @@ GstEngine::~GstEngine() {
|
|||||||
|
|
||||||
|
|
||||||
bool GstEngine::Init() {
|
bool GstEngine::Init() {
|
||||||
|
QString scanner_path;
|
||||||
|
QString plugin_path;
|
||||||
|
|
||||||
|
#if defined(Q_OS_DARWIN)
|
||||||
|
scanner_path = QCoreApplication::applicationDirPath() + "/../PlugIns/gst-plugin-scanner";
|
||||||
|
plugin_path = QCoreApplication::applicationDirPath() + "/../PlugIns/gstreamer";
|
||||||
|
#elif defined(Q_OS_WIN32)
|
||||||
|
plugin_path = QCoreApplication::applicationDirPath() + "/gstreamer-plugins";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Use putenv instead of setenv because windows doesn't have setenv.
|
||||||
|
// Use data() instead of constData() because linux's putenv takes non-const char*.
|
||||||
|
// :-(
|
||||||
|
if (!scanner_path.isEmpty())
|
||||||
|
putenv(QString("GST_PLUGIN_SCANNER=%1").arg(scanner_path).toAscii().data());
|
||||||
|
if (!plugin_path.isEmpty()) {
|
||||||
|
putenv(QString("GST_PLUGIN_PATH=%1").arg(plugin_path).toAscii().data());
|
||||||
|
// Never load plugins from anywhere else.
|
||||||
|
putenv(QString("GST_PLUGIN_SYSTEM_PATH=%1").arg(plugin_path).toAscii().data());
|
||||||
|
}
|
||||||
|
|
||||||
// GStreamer initialization
|
// GStreamer initialization
|
||||||
GError *err;
|
GError *err;
|
||||||
if ( !gst_init_check( NULL, NULL, &err ) ) {
|
if ( !gst_init_check( NULL, NULL, &err ) ) {
|
||||||
@ -77,13 +100,6 @@ bool GstEngine::Init() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef Q_OS_WIN32
|
|
||||||
// Set the plugin path on windows
|
|
||||||
GstRegistry* registry = gst_registry_get_default();
|
|
||||||
gst_registry_add_path(registry, QString(
|
|
||||||
QCoreApplication::applicationDirPath() + "/gstreamer-plugins").toLocal8Bit().constData());
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,19 +126,25 @@ bool GstEngine::CanDecode(const QUrl &url) {
|
|||||||
can_decode_last_ = false;
|
can_decode_last_ = false;
|
||||||
|
|
||||||
// Create the pipeline
|
// Create the pipeline
|
||||||
GstElement* pipeline = CreateElement("pipeline");
|
shared_ptr<GstElement> pipeline(gst_pipeline_new("pipeline"),
|
||||||
GstElement* src = CreateElement("giosrc", pipeline);
|
boost::bind(gst_object_unref, _1));
|
||||||
GstElement* bin = CreateElement("decodebin", pipeline);
|
if (!pipeline) return false;
|
||||||
|
GstElement* src = CreateElement("giosrc", pipeline.get()); if (!src) return false;
|
||||||
|
GstElement* bin = CreateElement("decodebin", pipeline.get()); if (!bin) return false;
|
||||||
|
|
||||||
gst_element_link(src, bin);
|
gst_element_link(src, bin);
|
||||||
g_signal_connect(G_OBJECT(bin), "new-decoded-pad", G_CALLBACK(CanDecodeNewPadCallback), this);
|
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);
|
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
|
// Set the file we're testing
|
||||||
g_object_set(G_OBJECT(src), "location", url.toEncoded().constData(), NULL);
|
g_object_set(G_OBJECT(src), "location", url.toEncoded().constData(), NULL);
|
||||||
|
|
||||||
// Start the pipeline playing
|
// Start the pipeline playing
|
||||||
gst_element_set_state(pipeline, GST_STATE_PLAYING);
|
gst_element_set_state(pipeline.get(), GST_STATE_PLAYING);
|
||||||
|
|
||||||
// Wait until found audio stream
|
// Wait until found audio stream
|
||||||
int count = 0;
|
int count = 0;
|
||||||
@ -132,12 +154,13 @@ bool GstEngine::CanDecode(const QUrl &url) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Stop playing
|
// Stop playing
|
||||||
gst_element_set_state(pipeline, GST_STATE_NULL);
|
gst_element_set_state(pipeline.get(), GST_STATE_NULL);
|
||||||
gst_object_unref(pipeline);
|
|
||||||
|
|
||||||
return can_decode_success_;
|
return can_decode_success_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void GstEngine::CanDecodeNewPadCallback(GstElement*, GstPad* pad, gboolean, gpointer self) {
|
void GstEngine::CanDecodeNewPadCallback(GstElement*, GstPad* pad, gboolean, gpointer self) {
|
||||||
GstEngine* instance = reinterpret_cast<GstEngine*>(self);
|
GstEngine* instance = reinterpret_cast<GstEngine*>(self);
|
||||||
|
|
||||||
@ -155,6 +178,30 @@ void GstEngine::CanDecodeLastCallback(GstElement*, gpointer self) {
|
|||||||
instance->can_decode_last_ = true;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
uint GstEngine::position() const {
|
uint GstEngine::position() const {
|
||||||
if (!current_pipeline_)
|
if (!current_pipeline_)
|
||||||
|
@ -107,6 +107,9 @@ class GstEngine : public Engine::Base {
|
|||||||
// Callbacks
|
// Callbacks
|
||||||
static void CanDecodeNewPadCallback(GstElement*, GstPad*, gboolean, gpointer);
|
static void CanDecodeNewPadCallback(GstElement*, GstPad*, gboolean, gpointer);
|
||||||
static void CanDecodeLastCallback(GstElement*, gpointer);
|
static void CanDecodeLastCallback(GstElement*, gpointer);
|
||||||
|
static GstBusSyncReply CanDecodeBusCallbackSync(GstBus*, GstMessage*, gpointer);
|
||||||
|
static gboolean CanDecodeBusCallback(GstBus*, GstMessage*, gpointer);
|
||||||
|
static void PrintGstError(GstMessage* msg);
|
||||||
|
|
||||||
PluginDetailsList GetPluginList(const QString& classname) const;
|
PluginDetailsList GetPluginList(const QString& classname) const;
|
||||||
|
|
||||||
|
@ -133,15 +133,6 @@ int main(int argc, char *argv[]) {
|
|||||||
MPRIS mpris;
|
MPRIS mpris;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef Q_OS_DARWIN
|
|
||||||
QString scanner_path = QCoreApplication::applicationDirPath() + "/../PlugIns/gst-plugin-scanner";
|
|
||||||
QString plugin_path = QCoreApplication::applicationDirPath() + "/../PlugIns/gstreamer";
|
|
||||||
setenv("GST_PLUGIN_SCANNER", scanner_path.toAscii().constData(), 1);
|
|
||||||
setenv("GST_PLUGIN_PATH", plugin_path.toAscii().constData(), 1);
|
|
||||||
// Never load plugins from anywhere else.
|
|
||||||
setenv("GST_PLUGIN_SYSTEM_PATH", plugin_path.toAscii().constData(), 1);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Window
|
// Window
|
||||||
MainWindow w(&network, options.engine());
|
MainWindow w(&network, options.engine());
|
||||||
|
|
||||||
|
@ -26,6 +26,8 @@
|
|||||||
#include <QResource>
|
#include <QResource>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
|
#include <QSignalSpy>
|
||||||
|
#include <QtDebug>
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
@ -91,7 +93,14 @@ TEST_P(FileformatsTest, GstCanDecode) {
|
|||||||
QTemporaryFile temp(temp_filetemplate_);
|
QTemporaryFile temp(temp_filetemplate_);
|
||||||
SaveToTempFile(&temp);
|
SaveToTempFile(&temp);
|
||||||
|
|
||||||
|
QSignalSpy spy(sGstEngine, SIGNAL(Error(QString)));
|
||||||
|
|
||||||
EXPECT_TRUE(sGstEngine->CanDecode(QUrl::fromLocalFile(temp.fileName())));
|
EXPECT_TRUE(sGstEngine->CanDecode(QUrl::fromLocalFile(temp.fileName())));
|
||||||
|
|
||||||
|
QList<QList<QVariant> > calls(spy);
|
||||||
|
foreach (const QList<QVariant>& call, calls) {
|
||||||
|
qDebug() << "GstEngine::Error emitted:" << call[0].toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
INSTANTIATE_TEST_CASE_P(Formats, FileformatsTest, ::testing::Values(
|
INSTANTIATE_TEST_CASE_P(Formats, FileformatsTest, ::testing::Values(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user