qtmobility/src/multimedia/audio/qaudiodeviceinfo_symbian_p.cpp
changeset 14 6fbed849b4f4
equal deleted inserted replaced
11:06b8e2af4411 14:6fbed849b4f4
       
     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 Qt Mobility Components.
       
     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 QString QAudioDeviceInfoInternal::deviceName() const
       
   119 {
       
   120     return m_deviceName;
       
   121 }
       
   122 
       
   123 QStringList QAudioDeviceInfoInternal::supportedCodecs()
       
   124 {
       
   125     getSupportedFormats();
       
   126     return m_codecs;
       
   127 }
       
   128 
       
   129 QList<int> QAudioDeviceInfoInternal::supportedSampleRates()
       
   130 {
       
   131     getSupportedFormats();
       
   132     return m_frequencies;
       
   133 }
       
   134 
       
   135 QList<int> QAudioDeviceInfoInternal::supportedChannelCounts()
       
   136 {
       
   137     getSupportedFormats();
       
   138     return m_channels;
       
   139 }
       
   140 
       
   141 QList<int> QAudioDeviceInfoInternal::supportedSampleSizes()
       
   142 {
       
   143     getSupportedFormats();
       
   144     return m_sampleSizes;
       
   145 }
       
   146 
       
   147 QList<QAudioFormat::Endian> QAudioDeviceInfoInternal::supportedByteOrders()
       
   148 {
       
   149     getSupportedFormats();
       
   150     return m_byteOrders;
       
   151 }
       
   152 
       
   153 QList<QAudioFormat::SampleType> QAudioDeviceInfoInternal::supportedSampleTypes()
       
   154 {
       
   155     getSupportedFormats();
       
   156     return m_sampleTypes;
       
   157 }
       
   158 
       
   159 QByteArray QAudioDeviceInfoInternal::defaultInputDevice()
       
   160 {
       
   161     return QByteArray("default");
       
   162 }
       
   163 
       
   164 QByteArray QAudioDeviceInfoInternal::defaultOutputDevice()
       
   165 {
       
   166     return QByteArray("default");
       
   167 }
       
   168 
       
   169 QList<QByteArray> QAudioDeviceInfoInternal::availableDevices(QAudio::Mode)
       
   170 {
       
   171     QList<QByteArray> result;
       
   172     result += QByteArray("default");
       
   173     return result;
       
   174 }
       
   175 
       
   176 void QAudioDeviceInfoInternal::getSupportedFormats() const
       
   177 {
       
   178     if (!m_updated) {
       
   179         QScopedPointer<SymbianAudio::DevSoundCapabilities> caps(
       
   180             new SymbianAudio::DevSoundCapabilities(*m_devsound, m_mode));
       
   181 
       
   182         SymbianAudio::Utils::capabilitiesNativeToQt(*caps,
       
   183             m_frequencies, m_channels, m_sampleSizes,
       
   184             m_byteOrders, m_sampleTypes);
       
   185 
       
   186         m_codecs.append(QLatin1String("audio/pcm"));
       
   187 
       
   188         m_updated = true;
       
   189     }
       
   190 }
       
   191 
       
   192 QT_END_NAMESPACE