src/multimedia/audio/qaudiodeviceinfo_symbian_p.cpp
changeset 19 fcece45ef507
child 25 e24348a560a6
equal deleted inserted replaced
18:2f34d5167611 19:fcece45ef507
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the QtMultimedia module of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #include "qaudiodeviceinfo_symbian_p.h"
       
    43 #include "qaudio_symbian_p.h"
       
    44 
       
    45 QT_BEGIN_NAMESPACE
       
    46 
       
    47 QAudioDeviceInfoInternal::QAudioDeviceInfoInternal(QByteArray device,
       
    48                                                QAudio::Mode mode)
       
    49     :   m_deviceName(QLatin1String(device))
       
    50     ,   m_mode(mode)
       
    51     ,   m_updated(false)
       
    52 {
       
    53     QT_TRAP_THROWING(m_devsound.reset(CMMFDevSound::NewL()));
       
    54 }
       
    55 
       
    56 QAudioDeviceInfoInternal::~QAudioDeviceInfoInternal()
       
    57 {
       
    58 
       
    59 }
       
    60 
       
    61 QAudioFormat QAudioDeviceInfoInternal::preferredFormat() const
       
    62 {
       
    63     QAudioFormat format;
       
    64     switch (m_mode) {
       
    65     case QAudio::AudioOutput:
       
    66         format.setFrequency(44100);
       
    67         format.setChannels(2);
       
    68         format.setSampleSize(16);
       
    69         format.setByteOrder(QAudioFormat::LittleEndian);
       
    70         format.setSampleType(QAudioFormat::SignedInt);
       
    71         format.setCodec(QLatin1String("audio/pcm"));
       
    72         break;
       
    73 
       
    74     case QAudio::AudioInput:
       
    75         format.setFrequency(8000);
       
    76         format.setChannels(1);
       
    77         format.setSampleSize(16);
       
    78         format.setByteOrder(QAudioFormat::LittleEndian);
       
    79         format.setSampleType(QAudioFormat::SignedInt);
       
    80         format.setCodec(QLatin1String("audio/pcm"));
       
    81         break;
       
    82 
       
    83     default:
       
    84         Q_ASSERT_X(false, Q_FUNC_INFO, "Invalid mode");
       
    85     }
       
    86 
       
    87     if (!isFormatSupported(format)) {
       
    88         if (m_frequencies.size())
       
    89             format.setFrequency(m_frequencies[0]);
       
    90         if (m_channels.size())
       
    91             format.setChannels(m_channels[0]);
       
    92         if (m_sampleSizes.size())
       
    93             format.setSampleSize(m_sampleSizes[0]);
       
    94         if (m_byteOrders.size())
       
    95             format.setByteOrder(m_byteOrders[0]);
       
    96         if (m_sampleTypes.size())
       
    97             format.setSampleType(m_sampleTypes[0]);
       
    98     }
       
    99 
       
   100     return format;
       
   101 }
       
   102 
       
   103 bool QAudioDeviceInfoInternal::isFormatSupported(
       
   104                                  const QAudioFormat &format) const
       
   105 {
       
   106     getSupportedFormats();
       
   107     const bool supported =
       
   108             m_codecs.contains(format.codec())
       
   109         &&  m_frequencies.contains(format.frequency())
       
   110         &&  m_channels.contains(format.channels())
       
   111         &&  m_sampleSizes.contains(format.sampleSize())
       
   112         &&  m_byteOrders.contains(format.byteOrder())
       
   113         &&  m_sampleTypes.contains(format.sampleType());
       
   114 
       
   115     return supported;
       
   116 }
       
   117 
       
   118 QAudioFormat QAudioDeviceInfoInternal::nearestFormat(const QAudioFormat &format) const
       
   119 {
       
   120     if (isFormatSupported(format))
       
   121         return format;
       
   122     else
       
   123         return preferredFormat();
       
   124 }
       
   125 
       
   126 QString QAudioDeviceInfoInternal::deviceName() const
       
   127 {
       
   128     return m_deviceName;
       
   129 }
       
   130 
       
   131 QStringList QAudioDeviceInfoInternal::codecList()
       
   132 {
       
   133     getSupportedFormats();
       
   134     return m_codecs;
       
   135 }
       
   136 
       
   137 QList<int> QAudioDeviceInfoInternal::frequencyList()
       
   138 {
       
   139     getSupportedFormats();
       
   140     return m_frequencies;
       
   141 }
       
   142 
       
   143 QList<int> QAudioDeviceInfoInternal::channelsList()
       
   144 {
       
   145     getSupportedFormats();
       
   146     return m_channels;
       
   147 }
       
   148 
       
   149 QList<int> QAudioDeviceInfoInternal::sampleSizeList()
       
   150 {
       
   151     getSupportedFormats();
       
   152     return m_sampleSizes;
       
   153 }
       
   154 
       
   155 QList<QAudioFormat::Endian> QAudioDeviceInfoInternal::byteOrderList()
       
   156 {
       
   157     getSupportedFormats();
       
   158     return m_byteOrders;
       
   159 }
       
   160 
       
   161 QList<QAudioFormat::SampleType> QAudioDeviceInfoInternal::sampleTypeList()
       
   162 {
       
   163     getSupportedFormats();
       
   164     return m_sampleTypes;
       
   165 }
       
   166 
       
   167 QByteArray QAudioDeviceInfoInternal::defaultInputDevice()
       
   168 {
       
   169     return QByteArray("default");
       
   170 }
       
   171 
       
   172 QByteArray QAudioDeviceInfoInternal::defaultOutputDevice()
       
   173 {
       
   174     return QByteArray("default");
       
   175 }
       
   176 
       
   177 QList<QByteArray> QAudioDeviceInfoInternal::availableDevices(QAudio::Mode)
       
   178 {
       
   179     QList<QByteArray> result;
       
   180     result += QByteArray("default");
       
   181     return result;
       
   182 }
       
   183 
       
   184 void QAudioDeviceInfoInternal::getSupportedFormats() const
       
   185 {
       
   186     if (!m_updated) {
       
   187         QScopedPointer<SymbianAudio::DevSoundCapabilities> caps(
       
   188             new SymbianAudio::DevSoundCapabilities(*m_devsound, m_mode));
       
   189 
       
   190         SymbianAudio::Utils::capabilitiesNativeToQt(*caps,
       
   191             m_frequencies, m_channels, m_sampleSizes,
       
   192             m_byteOrders, m_sampleTypes);
       
   193 
       
   194         m_codecs.append(QLatin1String("audio/pcm"));
       
   195 
       
   196         m_updated = true;
       
   197     }
       
   198 }
       
   199 
       
   200 QT_END_NAMESPACE