src/3rdparty/phonon/gstreamer/mediaobject.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
    85 
    85 
    86     static int count = 0;
    86     static int count = 0;
    87     m_name = "MediaObject" + QString::number(count++);
    87     m_name = "MediaObject" + QString::number(count++);
    88 
    88 
    89     if (!m_backend->isValid()) {
    89     if (!m_backend->isValid()) {
    90         setError(tr("Cannot start playback. \n\nCheck your Gstreamer installation and make sure you "
    90         setError(tr("Cannot start playback. \n\nCheck your GStreamer installation and make sure you "
    91                     "\nhave libgstreamer-plugins-base installed."), Phonon::FatalError);
    91                     "\nhave libgstreamer-plugins-base installed."), Phonon::FatalError);
    92     } else {
    92     } else {
    93         m_root = this;
    93         m_root = this;
    94         createPipeline();
    94         createPipeline();
    95         m_backend->addBusWatcher(this);
    95         m_backend->addBusWatcher(this);
    96         connect(m_tickTimer, SIGNAL(timeout()), SLOT(emitTick()));
    96         connect(m_tickTimer, SIGNAL(timeout()), SLOT(emitTick()));
    97     }
    97     }
    98     connect(this, SIGNAL(stateChanged(Phonon::State, Phonon::State)), 
    98     connect(this, SIGNAL(stateChanged(Phonon::State,Phonon::State)), 
    99             this, SLOT(notifyStateChange(Phonon::State, Phonon::State)));
    99             this, SLOT(notifyStateChange(Phonon::State,Phonon::State)));
   100 
   100 
   101 }
   101 }
   102 
   102 
   103 MediaObject::~MediaObject()
   103 MediaObject::~MediaObject()
   104 {
   104 {
   224     Q_ASSERT(media);
   224     Q_ASSERT(media);
   225 
   225 
   226     QString value = "unknown codec";
   226     QString value = "unknown codec";
   227 
   227 
   228     // These functions require GStreamer > 0.10.12
   228     // These functions require GStreamer > 0.10.12
       
   229 #ifndef QT_NO_LIBRARY
   229     static Ptr_gst_pb_utils_init p_gst_pb_utils_init = 0;
   230     static Ptr_gst_pb_utils_init p_gst_pb_utils_init = 0;
   230     static Ptr_gst_pb_utils_get_codec_description p_gst_pb_utils_get_codec_description = 0;
   231     static Ptr_gst_pb_utils_get_codec_description p_gst_pb_utils_get_codec_description = 0;
   231     if (!p_gst_pb_utils_init) {
   232     if (!p_gst_pb_utils_init) {
   232         p_gst_pb_utils_init =  (Ptr_gst_pb_utils_init)QLibrary::resolve(QLatin1String("gstpbutils-0.10"), 0, "gst_pb_utils_init");
   233         p_gst_pb_utils_init =  (Ptr_gst_pb_utils_init)QLibrary::resolve(QLatin1String("gstpbutils-0.10"), 0, "gst_pb_utils_init");
   233         p_gst_pb_utils_get_codec_description =  (Ptr_gst_pb_utils_get_codec_description)QLibrary::resolve(QLatin1String("gstpbutils-0.10"), 0, "gst_pb_utils_get_codec_description");
   234         p_gst_pb_utils_get_codec_description =  (Ptr_gst_pb_utils_get_codec_description)QLibrary::resolve(QLatin1String("gstpbutils-0.10"), 0, "gst_pb_utils_get_codec_description");
   237     if (p_gst_pb_utils_get_codec_description) {
   238     if (p_gst_pb_utils_get_codec_description) {
   238         gchar *codecName = NULL;
   239         gchar *codecName = NULL;
   239         codecName = p_gst_pb_utils_get_codec_description (caps);
   240         codecName = p_gst_pb_utils_get_codec_description (caps);
   240         value = QString::fromUtf8(codecName);
   241         value = QString::fromUtf8(codecName);
   241         g_free (codecName);
   242         g_free (codecName);
   242     } else {
   243     } else
       
   244 #endif //QT_NO_LIBRARY
       
   245     {
   243         // For GStreamer versions < 0.10.12
   246         // For GStreamer versions < 0.10.12
   244         GstStructure *str = gst_caps_get_structure (caps, 0);
   247         GstStructure *str = gst_caps_get_structure (caps, 0);
   245         value = QString::fromUtf8(gst_structure_get_name (str));
   248         value = QString::fromUtf8(gst_structure_get_name (str));
       
   249 
   246     }
   250     }
   247     media->addMissingCodecName(value);
   251     media->addMissingCodecName(value);
   248 }
   252 }
   249 
   253 
   250 static void notifyVideoCaps(GObject *obj, GParamSpec *, gpointer data)
   254 static void notifyVideoCaps(GObject *obj, GParamSpec *, gpointer data)
   338                                gpointer    data)
   342                                gpointer    data)
   339 {
   343 {
   340     Q_UNUSED(decodebin);
   344     Q_UNUSED(decodebin);
   341     GstPad *decodepad = static_cast<GstPad*>(data);
   345     GstPad *decodepad = static_cast<GstPad*>(data);
   342     gst_pad_link (pad, decodepad);
   346     gst_pad_link (pad, decodepad);
   343     gst_object_unref (decodepad);
   347     //gst_object_unref (decodepad);
   344 }
   348 }
   345 
   349 
   346 /**
   350 /**
   347  * Create a media source from a given URL.
   351  * Create a media source from a given URL.
   348  *
   352  *
   368     m_datasource = gst_element_make_from_uri(GST_URI_SRC, encoded_cstr_url.constData(), (const char*)NULL);
   372     m_datasource = gst_element_make_from_uri(GST_URI_SRC, encoded_cstr_url.constData(), (const char*)NULL);
   369     if (!m_datasource)
   373     if (!m_datasource)
   370         return false;
   374         return false;
   371 
   375 
   372     // Set the device for MediaSource::Disc
   376     // Set the device for MediaSource::Disc
   373     QByteArray mediaDevice = QFile::encodeName(m_source.deviceName());
   377     if (m_source.type() == MediaSource::Disc) {
   374     if (!mediaDevice.isEmpty())
   378 
   375         g_object_set (m_datasource, "device", mediaDevice.constData(), (const char*)NULL);
   379         if (g_object_class_find_property (G_OBJECT_GET_CLASS (m_datasource), "device")) {
       
   380             QByteArray mediaDevice = QFile::encodeName(m_source.deviceName());
       
   381             if (!mediaDevice.isEmpty())
       
   382                 g_object_set (G_OBJECT (m_datasource), "device", mediaDevice.constData(), (const char*)NULL);
       
   383         }
       
   384 
       
   385         // Also Set optical disc speed to 2X for Audio CD
       
   386         if (m_source.discType() == Phonon::Cd
       
   387             && (g_object_class_find_property (G_OBJECT_GET_CLASS (m_datasource), "read-speed"))) {
       
   388             g_object_set (G_OBJECT (m_datasource), "read-speed", 2, (const char*)NULL);
       
   389             m_backend->logMessage(QString("new device speed : 2X"), Backend::Info, this);
       
   390         }
       
   391     }
   376 
   392 
   377     // Link data source into pipeline
   393     // Link data source into pipeline
   378     gst_bin_add(GST_BIN(m_pipeline), m_datasource);
   394     gst_bin_add(GST_BIN(m_pipeline), m_datasource);
   379     if (!gst_element_link(m_datasource, m_decodebin)) {
   395     if (!gst_element_link(m_datasource, m_decodebin)) {
   380         // For sources with dynamic pads (such as RtspSrc) we need to connect dynamically
   396         // For sources with dynamic pads (such as RtspSrc) we need to connect dynamically
   390  *
   406  *
   391  * returns true if successful
   407  * returns true if successful
   392  */
   408  */
   393 bool MediaObject::createPipefromStream(const MediaSource &source)
   409 bool MediaObject::createPipefromStream(const MediaSource &source)
   394 {
   410 {
       
   411 #ifndef QT_NO_PHONON_ABSTRACTMEDIASTREAM
   395     // Remove any existing data source
   412     // Remove any existing data source
   396     if (m_datasource) {
   413     if (m_datasource) {
   397         gst_bin_remove(GST_BIN(m_pipeline), m_datasource);
   414         gst_bin_remove(GST_BIN(m_pipeline), m_datasource);
   398         // m_pipeline has the only ref to datasource
   415         // m_pipeline has the only ref to datasource
   399         m_datasource = 0;
   416         m_datasource = 0;
   411     if (!gst_element_link(m_datasource, m_decodebin)) {
   428     if (!gst_element_link(m_datasource, m_decodebin)) {
   412         gst_bin_remove(GST_BIN(m_pipeline), m_datasource);
   429         gst_bin_remove(GST_BIN(m_pipeline), m_datasource);
   413         return false;
   430         return false;
   414     }
   431     }
   415     return true;
   432     return true;
       
   433 #else //QT_NO_PHONON_ABSTRACTMEDIASTREAM
       
   434     Q_UNUSED(source);
       
   435     return false;
       
   436 #endif
   416 }
   437 }
   417 
   438 
   418 void MediaObject::createPipeline()
   439 void MediaObject::createPipeline()
   419 {
   440 {
   420     m_pipeline = gst_pipeline_new (NULL);
   441     m_pipeline = gst_pipeline_new (NULL);
   905             m_loading = true;
   926             m_loading = true;
   906         else
   927         else
   907             setError(tr("Could not open media source."));
   928             setError(tr("Could not open media source."));
   908         break;
   929         break;
   909 
   930 
   910     case MediaSource::Disc: // CD tracks can be specified by setting the url in the following way uri=cdda:4
   931     case MediaSource::Disc:
   911         {
   932         {
   912             QUrl url;
   933             QString mediaUrl;
   913             switch (source.discType()) {
   934             switch (source.discType()) {
   914                 case Phonon::Cd:
   935             case Phonon::NoDisc:
   915                     url = QUrl(QLatin1String("cdda://"));
   936                 qWarning() << "I should never get to see a MediaSource that is a disc but doesn't specify which one";
   916                     break;
   937                 return;
   917                 case Phonon::Dvd:
   938             case Phonon::Cd:  // CD tracks can be specified by setting the url in the following way uri=cdda:4
   918                     url = QUrl(QLatin1String("dvd://"));
   939                 mediaUrl = QLatin1String("cdda://");
   919                     break;
   940                 break;
   920                 case Phonon::Vcd:
   941             case Phonon::Dvd:
   921                     url = QUrl(QLatin1String("vcd://"));
   942                 mediaUrl = QLatin1String("dvd://");
   922                     break;
   943                 break;
   923                 default:
   944             case Phonon::Vcd:
   924                     break;
   945                 mediaUrl = QLatin1String("vcd://");
       
   946                 break;
       
   947             default:
       
   948                 qWarning() <<  "media " << source.discType() << " not implemented";
       
   949                 return;
   925             }
   950             }
   926             if (!url.isEmpty() && createPipefromURL(url))
   951             if (!mediaUrl.isEmpty() && createPipefromURL(QUrl(mediaUrl)))
   927                 m_loading = true;
   952                 m_loading = true;
   928             else
   953             else
   929                 setError(tr("Could not open media source."));
   954                 setError(tr("Could not open media source."));
   930         }
   955         }
   931         break;
   956         break;