src/3rdparty/phonon/gstreamer/devicemanager.cpp
changeset 30 5dc02b23752f
parent 3 41300fa6a67c
equal deleted inserted replaced
29:b72c6db6890b 30:5dc02b23752f
    22 #include "videowidget.h"
    22 #include "videowidget.h"
    23 #include "glrenderer.h"
    23 #include "glrenderer.h"
    24 #include "widgetrenderer.h"
    24 #include "widgetrenderer.h"
    25 #include "x11renderer.h"
    25 #include "x11renderer.h"
    26 #include "artssink.h"
    26 #include "artssink.h"
       
    27 #include "pulsesupport.h"
    27 
    28 
    28 #ifdef USE_ALSASINK2
    29 #ifdef USE_ALSASINK2
    29 #include "alsasink2.h"
    30 #include "alsasink2.h"
    30 #endif
    31 #endif
    31 
    32 
    42 {
    43 {
    43 
    44 
    44 AudioDevice::AudioDevice(DeviceManager *manager, const QByteArray &gstId)
    45 AudioDevice::AudioDevice(DeviceManager *manager, const QByteArray &gstId)
    45         : gstId(gstId)
    46         : gstId(gstId)
    46 {
    47 {
    47     //get an id
    48     // This should never be called when PulseAudio is active.
    48     static int counter = 0;
    49     Q_ASSERT(!PulseSupport::getInstance()->isActive());
    49     id = counter++;
    50 
       
    51     id = manager->allocateDeviceId();
       
    52     icon = "audio-card";
       
    53 
    50     //get name from device
    54     //get name from device
    51     if (gstId == "default") {
    55     if (gstId == "default") {
    52         description = "Default audio device";
    56         description = "Default audio device";
    53     } else {
    57     } else {
    54         GstElement *aSink= manager->createAudioSink();
    58         GstElement *aSink= manager->createAudioSink();
    69 }
    73 }
    70 
    74 
    71 DeviceManager::DeviceManager(Backend *backend)
    75 DeviceManager::DeviceManager(Backend *backend)
    72         : QObject(backend)
    76         : QObject(backend)
    73         , m_backend(backend)
    77         , m_backend(backend)
    74 {
    78         , m_audioDeviceCounter(0)
    75     m_audioSink = qgetenv("PHONON_GST_AUDIOSINK");
    79 {
    76     m_videoSinkWidget = qgetenv("PHONON_GST_VIDEOMODE");
       
    77 
       
    78 #ifndef QT_NO_SETTINGS
       
    79     QSettings settings(QLatin1String("Trolltech"));
    80     QSettings settings(QLatin1String("Trolltech"));
    80     settings.beginGroup(QLatin1String("Qt"));
    81     settings.beginGroup(QLatin1String("Qt"));
    81 
    82 
       
    83     PulseSupport *pulse = PulseSupport::getInstance();
       
    84     m_audioSink = qgetenv("PHONON_GST_AUDIOSINK");
    82     if (m_audioSink.isEmpty()) {
    85     if (m_audioSink.isEmpty()) {
    83         m_audioSink = settings.value(QLatin1String("audiosink"), "Auto").toByteArray().toLower();
    86         m_audioSink = settings.value(QLatin1String("audiosink"), "Auto").toByteArray().toLower();
    84     }
    87         if (m_audioSink == "auto" && pulse->isActive())
    85 
    88             m_audioSink = "pulsesink";
       
    89     }
       
    90     if ("pulsesink" != m_audioSink)
       
    91         pulse->enable(false);
       
    92 
       
    93     m_videoSinkWidget = qgetenv("PHONON_GST_VIDEOMODE");
    86     if (m_videoSinkWidget.isEmpty()) {
    94     if (m_videoSinkWidget.isEmpty()) {
    87         m_videoSinkWidget = settings.value(QLatin1String("videomode"), "Auto").toByteArray().toLower();
    95         m_videoSinkWidget = settings.value(QLatin1String("videomode"), "Auto").toByteArray().toLower();
    88     }
    96     }
    89 #endif //QT_NO_SETTINGS
       
    90 
    97 
    91     if (m_backend->isValid())
    98     if (m_backend->isValid())
    92         updateDeviceList();
    99         updateDeviceList();
    93 }
   100 }
    94 
   101 
   269 #endif
   276 #endif
   270     return new WidgetRenderer(parent);
   277     return new WidgetRenderer(parent);
   271 }
   278 }
   272 #endif //QT_NO_PHONON_VIDEO
   279 #endif //QT_NO_PHONON_VIDEO
   273 
   280 
   274 /*
   281 /**
   275  * Returns a positive device id or -1 if device
   282  * Allocate a device id for a new audio device
   276  * does not exist
   283  */
       
   284 int DeviceManager::allocateDeviceId()
       
   285 {
       
   286     return m_audioDeviceCounter++;
       
   287 }
       
   288 
       
   289 
       
   290 /**
       
   291  * Returns a positive device id or -1 if device does not exist
   277  *
   292  *
   278  * The gstId is typically in the format hw:1,0
   293  * The gstId is typically in the format hw:1,0
   279  */
   294  */
   280 int DeviceManager::deviceId(const QByteArray &gstId) const
   295 int DeviceManager::deviceId(const QByteArray &gstId) const
   281 {
   296 {
   286     }
   301     }
   287     return -1;
   302     return -1;
   288 }
   303 }
   289 
   304 
   290 /**
   305 /**
   291  * Get a human-readable description from a device id
   306  * Returns a gstId or "default" if device does not exist
   292  */
   307  *
   293 QByteArray DeviceManager::deviceDescription(int id) const
   308  * The gstId is typically in the format hw:1,0
       
   309  */
       
   310 const QByteArray DeviceManager::gstId(int deviceId)
       
   311 {
       
   312     if (!PulseSupport::getInstance()->isActive()) {
       
   313         AudioDevice *ad = audioDevice(deviceId);
       
   314         if (ad)
       
   315             return QByteArray(ad->gstId);
       
   316     }
       
   317     return QByteArray("default");
       
   318 }
       
   319 
       
   320 /**
       
   321 * Get the AudioDevice for a given device id
       
   322 */
       
   323 AudioDevice* DeviceManager::audioDevice(int id)
   294 {
   324 {
   295     for (int i = 0 ; i < m_audioDeviceList.size() ; ++i) {
   325     for (int i = 0 ; i < m_audioDeviceList.size() ; ++i) {
   296         if (m_audioDeviceList[i].id == id) {
   326         if (m_audioDeviceList[i].id == id)
   297             return m_audioDeviceList[i].description;
   327             return &m_audioDeviceList[i];
   298         }
   328     }
   299     }
   329     return NULL;
   300     return QByteArray();
       
   301 }
   330 }
   302 
   331 
   303 /**
   332 /**
   304  * Updates the current list of active devices
   333  * Updates the current list of active devices
   305  */
   334  */
   309     GstElement *audioSink= createAudioSink();
   338     GstElement *audioSink= createAudioSink();
   310 
   339 
   311     QList<QByteArray> list;
   340     QList<QByteArray> list;
   312 
   341 
   313     if (audioSink) {
   342     if (audioSink) {
   314         list = GstHelper::extractProperties(audioSink, "device");
   343         if (!PulseSupport::getInstance()->isActive()) {
   315         list.prepend("default");
   344             // If we're using pulse, the PulseSupport class takes care of things for us.
       
   345             list = GstHelper::extractProperties(audioSink, "device");
       
   346             list.prepend("default");
       
   347         }
   316 
   348 
   317         for (int i = 0 ; i < list.size() ; ++i) {
   349         for (int i = 0 ; i < list.size() ; ++i) {
   318             QByteArray gstId = list.at(i);
   350             QByteArray gstId = list.at(i);
   319             if (deviceId(gstId) == -1) {
   351             if (deviceId(gstId) == -1) {
   320                 // This is a new device, add it
   352                 // This is a new device, add it