SVN commit 761634 by jbache: Improved mime-type support M +38 -30 backend.cpp M +3 -4 effectmanager.cpp --- trunk/kdereview/phonon/gstreamer/backend.cpp #761633:761634 @@ -162,42 +162,50 @@ */ QStringList Backend::availableMimeTypes() const { - QStringList availableMineTypes; + QStringList availableMimeTypes; - // I dont know a clean way to collect this info, so - // we will have to check for well-known decoder factories - if (isValid()) { - GstElementFactory *theoraFactory = gst_element_factory_find ("theoradec"); - if (theoraFactory) { - availableMineTypes << QLatin1String("video/x-theora"); - gst_object_unref(GST_OBJECT(theoraFactory)); - } + if (!isValid()) + return availableMimeTypes; - GstElementFactory *vorbisFactory = gst_element_factory_find ("vorbisdec"); - if (vorbisFactory) { - availableMineTypes << QLatin1String("audio/x-vorbis"); - gst_object_unref(GST_OBJECT(vorbisFactory)); - } + GstElementFactory *mpegFactory; + // Add mp3 as a separate mime type as people are likely to look for it. + if ((mpegFactory = gst_element_factory_find ("ffmpeg")) || + (mpegFactory = gst_element_factory_find ("mad"))) { + availableMimeTypes << QLatin1String("audio/x-mp3"); + gst_object_unref(GST_OBJECT(mpegFactory)); + } - GstElementFactory *flacFactory = gst_element_factory_find ("flacdec"); - if (flacFactory) { - availableMineTypes << QLatin1String("audio/x-flac"); - gst_object_unref(GST_OBJECT(flacFactory)); - } + // Iterate over all audio and video decoders and extract mime types from sink caps + GList* factoryList = gst_registry_get_feature_list(gst_registry_get_default (), GST_TYPE_ELEMENT_FACTORY); + for (GList* iter = g_list_first(factoryList) ; iter != NULL ; iter = g_list_next(iter)) { + GstPluginFeature *feature = GST_PLUGIN_FEATURE(iter->data); + QString klass = gst_element_factory_get_klass(GST_ELEMENT_FACTORY(feature)); - GstElementFactory *mpegFactory = gst_element_factory_find ("mpeg2dec"); - if (mpegFactory) { - availableMineTypes << QLatin1String("video/x-mpeg"); - gst_object_unref(GST_OBJECT(mpegFactory)); + if (klass == QLatin1String("Codec/Decoder/Audio") || + klass == QLatin1String("Codec/Decoder/Video")) { + + const GList *static_templates; + GstElementFactory *factory = GST_ELEMENT_FACTORY(feature); + static_templates = gst_element_factory_get_static_pad_templates(factory); + + for (; static_templates != NULL ; static_templates = static_templates->next) { + GstStaticPadTemplate *padTemplate = (GstStaticPadTemplate *) static_templates->data; + if (padTemplate && padTemplate->direction == GST_PAD_SINK) { + GstCaps *caps = gst_static_pad_template_get_caps (padTemplate); + + if (caps) { + const GstStructure* capsStruct = gst_caps_get_structure (caps, 0); + QString mime = QString::fromUtf8(gst_structure_get_name (capsStruct)); + if (!availableMimeTypes.contains(mime)) + availableMimeTypes.append(mime); + } + } + } } - if ((mpegFactory = gst_element_factory_find ("ffmpeg")) - || (mpegFactory = gst_element_factory_find ("mad"))) { - availableMineTypes << QLatin1String("audio/x-mpeg"); - gst_object_unref(GST_OBJECT(mpegFactory)); - } } - - return availableMineTypes; + g_list_free(factoryList); + availableMimeTypes.sort(); + return availableMimeTypes; } /*** --- trunk/kdereview/phonon/gstreamer/effectmanager.cpp #761633:761634 @@ -43,8 +43,8 @@ { GList* factoryList = gst_registry_get_feature_list(gst_registry_get_default (), GST_TYPE_ELEMENT_FACTORY); QString name, klass, description, author; - while (factoryList) { - GstPluginFeature *feature = GST_PLUGIN_FEATURE(factoryList->data); + for (GList* iter = g_list_first(factoryList) ; iter != NULL ; iter = g_list_next(iter)) { + GstPluginFeature *feature = GST_PLUGIN_FEATURE(iter->data); klass = gst_element_factory_get_klass(GST_ELEMENT_FACTORY(feature)); if ( klass == "Filter/Effect/Audio" ) { name = GST_PLUGIN_FEATURE_NAME(feature); @@ -53,9 +53,8 @@ EffectInfo *effect = new EffectInfo(name, description, author); m_audioEffectList.append(effect); } - factoryList = g_list_next(factoryList); } - g_list_free( factoryList); + g_list_free(factoryList); } EffectManager::~EffectManager()