src/multimedia/audio/qaudiodeviceinfo_symbian_p.cpp
changeset 25 e24348a560a6
parent 19 fcece45ef507
equal deleted inserted replaced
23:89e065397ea6 25:e24348a560a6
    37 **
    37 **
    38 ** $QT_END_LICENSE$
    38 ** $QT_END_LICENSE$
    39 **
    39 **
    40 ****************************************************************************/
    40 ****************************************************************************/
    41 
    41 
       
    42 #include <QtCore/QCoreApplication>
    42 #include "qaudiodeviceinfo_symbian_p.h"
    43 #include "qaudiodeviceinfo_symbian_p.h"
    43 #include "qaudio_symbian_p.h"
    44 #include "qaudio_symbian_p.h"
    44 
    45 
    45 QT_BEGIN_NAMESPACE
    46 QT_BEGIN_NAMESPACE
    46 
    47 
    48                                                QAudio::Mode mode)
    49                                                QAudio::Mode mode)
    49     :   m_deviceName(QLatin1String(device))
    50     :   m_deviceName(QLatin1String(device))
    50     ,   m_mode(mode)
    51     ,   m_mode(mode)
    51     ,   m_updated(false)
    52     ,   m_updated(false)
    52 {
    53 {
    53     QT_TRAP_THROWING(m_devsound.reset(CMMFDevSound::NewL()));
    54 
    54 }
    55 }
    55 
    56 
    56 QAudioDeviceInfoInternal::~QAudioDeviceInfoInternal()
    57 QAudioDeviceInfoInternal::~QAudioDeviceInfoInternal()
    57 {
    58 {
    58 
    59 
    83     default:
    84     default:
    84         Q_ASSERT_X(false, Q_FUNC_INFO, "Invalid mode");
    85         Q_ASSERT_X(false, Q_FUNC_INFO, "Invalid mode");
    85     }
    86     }
    86 
    87 
    87     if (!isFormatSupported(format)) {
    88     if (!isFormatSupported(format)) {
    88         if (m_frequencies.size())
    89         format = QAudioFormat();
    89             format.setFrequency(m_frequencies[0]);
    90         format.setCodec(QLatin1String("audio/pcm"));
    90         if (m_channels.size())
    91         if (m_capabilities.contains(format.codec())) {
    91             format.setChannels(m_channels[0]);
    92             const Capabilities &codecCaps = m_capabilities[format.codec()];
    92         if (m_sampleSizes.size())
    93             if (codecCaps.m_frequencies.size())
    93             format.setSampleSize(m_sampleSizes[0]);
    94                 format.setFrequency(codecCaps.m_frequencies[0]);
    94         if (m_byteOrders.size())
    95             if (codecCaps.m_channels.size())
    95             format.setByteOrder(m_byteOrders[0]);
    96                 format.setChannels(codecCaps.m_channels[0]);
    96         if (m_sampleTypes.size())
    97             if (codecCaps.m_sampleSizes.size())
    97             format.setSampleType(m_sampleTypes[0]);
    98                 format.setSampleSize(codecCaps.m_sampleSizes[0]);
       
    99             if (codecCaps.m_byteOrders.size())
       
   100                 format.setByteOrder(codecCaps.m_byteOrders[0]);
       
   101             if (codecCaps.m_sampleTypes.size())
       
   102                 format.setSampleType(codecCaps.m_sampleTypes[0]);
       
   103         }
    98     }
   104     }
    99 
   105 
   100     return format;
   106     return format;
   101 }
   107 }
   102 
   108 
   103 bool QAudioDeviceInfoInternal::isFormatSupported(
   109 bool QAudioDeviceInfoInternal::isFormatSupported(
   104                                  const QAudioFormat &format) const
   110                                  const QAudioFormat &format) const
   105 {
   111 {
   106     getSupportedFormats();
   112     getSupportedFormats();
   107     const bool supported =
   113     bool supported = false;
   108             m_codecs.contains(format.codec())
   114     if (m_capabilities.contains(format.codec())) {
   109         &&  m_frequencies.contains(format.frequency())
   115         const Capabilities &codecCaps = m_capabilities[format.codec()];
   110         &&  m_channels.contains(format.channels())
   116         supported = codecCaps.m_frequencies.contains(format.frequency())
   111         &&  m_sampleSizes.contains(format.sampleSize())
   117                 &&  codecCaps.m_channels.contains(format.channels())
   112         &&  m_byteOrders.contains(format.byteOrder())
   118                 &&  codecCaps.m_sampleSizes.contains(format.sampleSize())
   113         &&  m_sampleTypes.contains(format.sampleType());
   119                 &&  codecCaps.m_byteOrders.contains(format.byteOrder())
   114 
   120                 &&  codecCaps.m_sampleTypes.contains(format.sampleType());
       
   121     }
   115     return supported;
   122     return supported;
   116 }
   123 }
   117 
   124 
   118 QAudioFormat QAudioDeviceInfoInternal::nearestFormat(const QAudioFormat &format) const
   125 QAudioFormat QAudioDeviceInfoInternal::nearestFormat(const QAudioFormat &format) const
   119 {
   126 {
   129 }
   136 }
   130 
   137 
   131 QStringList QAudioDeviceInfoInternal::codecList()
   138 QStringList QAudioDeviceInfoInternal::codecList()
   132 {
   139 {
   133     getSupportedFormats();
   140     getSupportedFormats();
   134     return m_codecs;
   141     return m_capabilities.keys();
   135 }
   142 }
   136 
   143 
   137 QList<int> QAudioDeviceInfoInternal::frequencyList()
   144 QList<int> QAudioDeviceInfoInternal::frequencyList()
   138 {
   145 {
   139     getSupportedFormats();
   146     getSupportedFormats();
   140     return m_frequencies;
   147     return m_unionCapabilities.m_frequencies;
   141 }
   148 }
   142 
   149 
   143 QList<int> QAudioDeviceInfoInternal::channelsList()
   150 QList<int> QAudioDeviceInfoInternal::channelsList()
   144 {
   151 {
   145     getSupportedFormats();
   152     getSupportedFormats();
   146     return m_channels;
   153     return m_unionCapabilities.m_channels;
   147 }
   154 }
   148 
   155 
   149 QList<int> QAudioDeviceInfoInternal::sampleSizeList()
   156 QList<int> QAudioDeviceInfoInternal::sampleSizeList()
   150 {
   157 {
   151     getSupportedFormats();
   158     getSupportedFormats();
   152     return m_sampleSizes;
   159     return m_unionCapabilities.m_sampleSizes;
   153 }
   160 }
   154 
   161 
   155 QList<QAudioFormat::Endian> QAudioDeviceInfoInternal::byteOrderList()
   162 QList<QAudioFormat::Endian> QAudioDeviceInfoInternal::byteOrderList()
   156 {
   163 {
   157     getSupportedFormats();
   164     getSupportedFormats();
   158     return m_byteOrders;
   165     return m_unionCapabilities.m_byteOrders;
   159 }
   166 }
   160 
   167 
   161 QList<QAudioFormat::SampleType> QAudioDeviceInfoInternal::sampleTypeList()
   168 QList<QAudioFormat::SampleType> QAudioDeviceInfoInternal::sampleTypeList()
   162 {
   169 {
   163     getSupportedFormats();
   170     getSupportedFormats();
   164     return m_sampleTypes;
   171     return m_unionCapabilities.m_sampleTypes;
   165 }
   172 }
   166 
   173 
   167 QByteArray QAudioDeviceInfoInternal::defaultInputDevice()
   174 QByteArray QAudioDeviceInfoInternal::defaultInputDevice()
   168 {
   175 {
   169     return QByteArray("default");
   176     return QByteArray("default");
   179     QList<QByteArray> result;
   186     QList<QByteArray> result;
   180     result += QByteArray("default");
   187     result += QByteArray("default");
   181     return result;
   188     return result;
   182 }
   189 }
   183 
   190 
       
   191 void QAudioDeviceInfoInternal::devsoundInitializeComplete(int err)
       
   192 {
       
   193     m_intializationResult = err;
       
   194     m_initializing = false;
       
   195 }
       
   196 
       
   197 // Helper function
       
   198 template<typename T>
       
   199 void appendUnique(QList<T> &left, const QList<T> &right)
       
   200 {
       
   201     foreach (const T &value, right)
       
   202         if (!left.contains(value))
       
   203             left += value;
       
   204 }
       
   205 
   184 void QAudioDeviceInfoInternal::getSupportedFormats() const
   206 void QAudioDeviceInfoInternal::getSupportedFormats() const
   185 {
   207 {
   186     if (!m_updated) {
   208     if (!m_updated) {
   187         QScopedPointer<SymbianAudio::DevSoundCapabilities> caps(
   209         QScopedPointer<SymbianAudio::DevSoundWrapper> devsound(new SymbianAudio::DevSoundWrapper(m_mode));
   188             new SymbianAudio::DevSoundCapabilities(*m_devsound, m_mode));
   210         connect(devsound.data(), SIGNAL(initializeComplete(int)),
   189 
   211                 this, SLOT(devsoundInitializeComplete(int)));
   190         SymbianAudio::Utils::capabilitiesNativeToQt(*caps,
   212 
   191             m_frequencies, m_channels, m_sampleSizes,
   213         foreach (const QString& codec, devsound->supportedCodecs()) {
   192             m_byteOrders, m_sampleTypes);
   214             m_initializing = true;
   193 
   215             devsound->initialize(codec);
   194         m_codecs.append(QLatin1String("audio/pcm"));
   216             while (m_initializing)
       
   217                 QCoreApplication::instance()->processEvents(QEventLoop::WaitForMoreEvents);
       
   218             if (KErrNone == m_intializationResult) {
       
   219                 m_capabilities[codec].m_frequencies = devsound->supportedFrequencies();
       
   220                 appendUnique(m_unionCapabilities.m_frequencies, devsound->supportedFrequencies());
       
   221 
       
   222                 m_capabilities[codec].m_channels = devsound->supportedChannels();
       
   223                 appendUnique(m_unionCapabilities.m_channels, devsound->supportedChannels());
       
   224 
       
   225                 m_capabilities[codec].m_sampleSizes = devsound->supportedSampleSizes();
       
   226                 appendUnique(m_unionCapabilities.m_sampleSizes, devsound->supportedSampleSizes());
       
   227 
       
   228                 m_capabilities[codec].m_byteOrders = devsound->supportedByteOrders();
       
   229                 appendUnique(m_unionCapabilities.m_byteOrders, devsound->supportedByteOrders());
       
   230 
       
   231                 m_capabilities[codec].m_sampleTypes = devsound->supportedSampleTypes();
       
   232                 appendUnique(m_unionCapabilities.m_sampleTypes, devsound->supportedSampleTypes());
       
   233             }
       
   234         }
   195 
   235 
   196         m_updated = true;
   236         m_updated = true;
   197     }
   237     }
   198 }
   238 }
   199 
   239