src/3rdparty/phonon/gstreamer/backend.cpp
changeset 30 5dc02b23752f
parent 3 41300fa6a67c
equal deleted inserted replaced
29:b72c6db6890b 30:5dc02b23752f
    16 */
    16 */
    17 
    17 
    18 #include "common.h"
    18 #include "common.h"
    19 #include "backend.h"
    19 #include "backend.h"
    20 #include "audiooutput.h"
    20 #include "audiooutput.h"
       
    21 #include "audiodataoutput.h"
    21 #include "audioeffect.h"
    22 #include "audioeffect.h"
    22 #include "mediaobject.h"
    23 #include "mediaobject.h"
    23 #include "videowidget.h"
    24 #include "videowidget.h"
    24 #include "devicemanager.h"
    25 #include "devicemanager.h"
    25 #include "effectmanager.h"
    26 #include "effectmanager.h"
    26 #include "message.h"
    27 #include "message.h"
    27 #include "volumefadereffect.h"
    28 #include "volumefadereffect.h"
    28 #include <gst/interfaces/propertyprobe.h>
    29 #include <gst/interfaces/propertyprobe.h>
       
    30 #include <phonon/pulsesupport.h>
    29 
    31 
    30 #include <QtCore/QSet>
    32 #include <QtCore/QSet>
    31 #include <QtCore/QVariant>
    33 #include <QtCore/QVariant>
    32 #include <QtCore/QtPlugin>
    34 #include <QtCore/QtPlugin>
    33 
    35 
    47         , m_deviceManager(0)
    49         , m_deviceManager(0)
    48         , m_effectManager(0)
    50         , m_effectManager(0)
    49         , m_debugLevel(Warning)
    51         , m_debugLevel(Warning)
    50         , m_isValid(false)
    52         , m_isValid(false)
    51 {
    53 {
       
    54     // Initialise PulseAudio support
       
    55     PulseSupport *pulse = PulseSupport::getInstance();
       
    56     pulse->enable();
       
    57     connect(pulse, SIGNAL(objectDescriptionChanged(ObjectDescriptionType)), SIGNAL(objectDescriptionChanged(ObjectDescriptionType)));
       
    58 
    52     // In order to support reloading, we only set the app name once...
    59     // In order to support reloading, we only set the app name once...
    53     static bool first = true;
    60     static bool first = true;
    54     if (first) {
    61     if (first) {
    55         first = false;
    62         first = false;
    56         g_set_application_name(qApp->applicationName().toUtf8());
    63         g_set_application_name(qApp->applicationName().toUtf8());
    57     }
    64     }
    58 
       
    59     GError *err = 0;
    65     GError *err = 0;
    60     bool wasInit = gst_init_check(0, 0, &err);  //init gstreamer: must be called before any gst-related functions
    66     bool wasInit = gst_init_check(0, 0, &err);  //init gstreamer: must be called before any gst-related functions
    61     if (err)
    67     if (err)
    62         g_error_free(err);
    68         g_error_free(err);
    63 
    69 
    90     m_effectManager = new EffectManager(this);
    96     m_effectManager = new EffectManager(this);
    91 }
    97 }
    92 
    98 
    93 Backend::~Backend() 
    99 Backend::~Backend() 
    94 {
   100 {
       
   101     delete m_effectManager;
       
   102     delete m_deviceManager;
       
   103     PulseSupport::shutdown();
    95 }
   104 }
    96 
   105 
    97 gboolean Backend::busCall(GstBus *bus, GstMessage *msg, gpointer data)
   106 gboolean Backend::busCall(GstBus *bus, GstMessage *msg, gpointer data)
    98 {
   107 {
    99     Q_UNUSED(bus);
   108     Q_UNUSED(bus);
   117 
   126 
   118     switch (c) {
   127     switch (c) {
   119     case MediaObjectClass:
   128     case MediaObjectClass:
   120         return new MediaObject(this, parent);
   129         return new MediaObject(this, parent);
   121 
   130 
   122     case AudioOutputClass: {
   131     case AudioOutputClass:
   123             AudioOutput *ao = new AudioOutput(this, parent);
   132         return new AudioOutput(this, parent);
   124             m_audioOutputs.append(ao);
   133 
   125             return ao;
       
   126         }
       
   127 #ifndef QT_NO_PHONON_EFFECT
   134 #ifndef QT_NO_PHONON_EFFECT
   128     case EffectClass:
   135     case EffectClass:
   129         return new AudioEffect(this, args[0].toInt(), parent);
   136         return new AudioEffect(this, args[0].toInt(), parent);
   130 #endif //QT_NO_PHONON_EFFECT
   137 #endif //QT_NO_PHONON_EFFECT
   131     case AudioDataOutputClass:
   138     case AudioDataOutputClass:
   132         logMessage("createObject() : AudioDataOutput not implemented");
   139         return new AudioDataOutput(this, parent);
   133         break;
       
   134 
   140 
   135 #ifndef QT_NO_PHONON_VIDEO
   141 #ifndef QT_NO_PHONON_VIDEO
   136     case VideoDataOutputClass:
   142     case VideoDataOutputClass:
   137         logMessage("createObject() : VideoDataOutput not implemented");
   143         logMessage("createObject() : VideoDataOutput not implemented");
   138         break;
   144         break;
   212     GList* factoryList = gst_registry_get_feature_list(gst_registry_get_default (), GST_TYPE_ELEMENT_FACTORY);
   218     GList* factoryList = gst_registry_get_feature_list(gst_registry_get_default (), GST_TYPE_ELEMENT_FACTORY);
   213     for (GList* iter = g_list_first(factoryList) ; iter != NULL ; iter = g_list_next(iter)) {
   219     for (GList* iter = g_list_first(factoryList) ; iter != NULL ; iter = g_list_next(iter)) {
   214         GstPluginFeature *feature = GST_PLUGIN_FEATURE(iter->data);
   220         GstPluginFeature *feature = GST_PLUGIN_FEATURE(iter->data);
   215         QString klass = gst_element_factory_get_klass(GST_ELEMENT_FACTORY(feature));
   221         QString klass = gst_element_factory_get_klass(GST_ELEMENT_FACTORY(feature));
   216 
   222 
   217         if (klass == QLatin1String("Codec/Decoder") ||
   223         if (klass == QLatin1String("Codec/Decoder") || 
   218             klass == QLatin1String("Codec/Decoder/Audio") ||
   224             klass == QLatin1String("Codec/Decoder/Audio") || 
   219             klass == QLatin1String("Codec/Decoder/Video") ||
   225             klass == QLatin1String("Codec/Decoder/Video") || 
   220             klass == QLatin1String("Codec/Demuxer") ||
   226             klass == QLatin1String("Codec/Demuxer") || 
   221             klass == QLatin1String("Codec/Demuxer/Audio") ||
   227             klass == QLatin1String("Codec/Demuxer/Audio") || 
   222             klass == QLatin1String("Codec/Demuxer/Video") ||
   228             klass == QLatin1String("Codec/Demuxer/Video") || 
   223             klass == QLatin1String("Codec/Parser") ||
   229             klass == QLatin1String("Codec/Parser") || 
   224             klass == QLatin1String("Codec/Parser/Audio") ||
   230             klass == QLatin1String("Codec/Parser/Audio") || 
   225             klass == QLatin1String("Codec/Parser/Video")) {
   231             klass == QLatin1String("Codec/Parser/Video")) {
   226 
   232 
   227             const GList *static_templates;
   233             const GList *static_templates;
   228             GstElementFactory *factory = GST_ELEMENT_FACTORY(feature);
   234             GstElementFactory *factory = GST_ELEMENT_FACTORY(feature);
   229             static_templates = gst_element_factory_get_static_pad_templates(factory);
   235             static_templates = gst_element_factory_get_static_pad_templates(factory);
   232                 GstStaticPadTemplate *padTemplate = (GstStaticPadTemplate *) static_templates->data;
   238                 GstStaticPadTemplate *padTemplate = (GstStaticPadTemplate *) static_templates->data;
   233                 if (padTemplate && padTemplate->direction == GST_PAD_SINK) {
   239                 if (padTemplate && padTemplate->direction == GST_PAD_SINK) {
   234                     GstCaps *caps = gst_static_pad_template_get_caps (padTemplate);
   240                     GstCaps *caps = gst_static_pad_template_get_caps (padTemplate);
   235 
   241 
   236                     if (caps) {
   242                     if (caps) {
   237                         const GstStructure* capsStruct = gst_caps_get_structure (caps, 0);
   243                         for (unsigned int struct_idx = 0; struct_idx < gst_caps_get_size (caps); struct_idx++) {
   238                         QString mime = QString::fromUtf8(gst_structure_get_name (capsStruct));
   244 
   239                         if (!availableMimeTypes.contains(mime))
   245                             const GstStructure* capsStruct = gst_caps_get_structure (caps, struct_idx);
   240                               availableMimeTypes.append(mime);
   246                             QString mime = QString::fromUtf8(gst_structure_get_name (capsStruct));
       
   247                             if (!availableMimeTypes.contains(mime))
       
   248                                 availableMimeTypes.append(mime);
       
   249                         }
   241                     }
   250                     }
   242                 }
   251                 }
   243             }
   252             }
   244         }
   253         }
   245     }
   254     }
   246     g_list_free(factoryList);
   255     g_list_free(factoryList);
       
   256     if (availableMimeTypes.contains("audio/x-vorbis")
       
   257         && availableMimeTypes.contains("application/x-ogm-audio")) {
       
   258         if (!availableMimeTypes.contains("audio/x-vorbis+ogg"))
       
   259             availableMimeTypes.append("audio/x-vorbis+ogg");
       
   260         if (!availableMimeTypes.contains("application/ogg"))  /* *.ogg */
       
   261             availableMimeTypes.append("application/ogg");
       
   262         if (!availableMimeTypes.contains("audio/ogg")) /* *.oga */
       
   263             availableMimeTypes.append("audio/ogg");
       
   264     }
   247     availableMimeTypes.sort();
   265     availableMimeTypes.sort();
   248     return availableMimeTypes;
   266     return availableMimeTypes;
   249 }
   267 }
   250 
   268 
   251 /***
   269 /***
   291     if (!isValid())
   309     if (!isValid())
   292         return ret;
   310         return ret;
   293 
   311 
   294     switch (type) {
   312     switch (type) {
   295     case Phonon::AudioOutputDeviceType: {
   313     case Phonon::AudioOutputDeviceType: {
   296             QList<AudioDevice> audioDevices = deviceManager()->audioOutputDevices();
   314             AudioDevice* ad;
   297             foreach(const AudioDevice &device, audioDevices) {
   315             if ((ad = deviceManager()->audioDevice(index))) {
   298                 if (device.id == index) {
   316                 ret.insert("name", ad->gstId);
   299                     ret.insert("name", device.gstId);
   317                 ret.insert("description", ad->description);
   300                     ret.insert("description", device.description);
   318                 ret.insert("icon", ad->icon);
   301                     ret.insert("icon", QLatin1String("audio-card"));
       
   302                     break;
       
   303                 }
       
   304             }
   319             }
   305         }
   320         }
   306         break;
   321         break;
   307 
   322 
   308     case Phonon::EffectType: {
   323     case Phonon::EffectType: {
   427     return m_effectManager;
   442     return m_effectManager;
   428 }
   443 }
   429 
   444 
   430 /**
   445 /**
   431  * Returns a debuglevel that is determined by the
   446  * Returns a debuglevel that is determined by the
   432  * PHONON_GSTREAMER_DEBUG environment variable.
   447  * PHONON_GST_DEBUG environment variable.
   433  *
   448  *
   434  *  Warning - important warnings
   449  *  Warning - important warnings
   435  *  Info    - general info
   450  *  Info    - general info
   436  *  Debug   - gives extra info
   451  *  Debug   - gives extra info
   437  */
   452  */