Ignore:
Timestamp:
May 5, 2011, 5:36:53 AM (14 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

Location:
trunk
Files:
46 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/multimedia/audio/audio.pri

    r769 r846  
    4343
    4444} else:symbian {
    45     INCLUDEPATH += /epoc32/include/mmf/common
    46     INCLUDEPATH += /epoc32/include/mmf/server
     45    INCLUDEPATH += $${EPOCROOT}epoc32/include/mmf/common
     46    INCLUDEPATH += $${EPOCROOT}epoc32/include/mmf/server
    4747
    4848    HEADERS += $$PWD/qaudio_symbian_p.h \
  • trunk/src/multimedia/audio/qaudio.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/multimedia/audio/qaudio.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/multimedia/audio/qaudio_mac.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    6969    audioFormat.setSampleSize(sf.mBitsPerChannel);
    7070    audioFormat.setCodec(QString::fromLatin1("audio/pcm"));
    71     audioFormat.setByteOrder(sf.mFormatFlags & kLinearPCMFormatFlagIsBigEndian != 0 ? QAudioFormat::BigEndian : QAudioFormat::LittleEndian);
     71    audioFormat.setByteOrder((sf.mFormatFlags & kAudioFormatFlagIsBigEndian) != 0 ? QAudioFormat::BigEndian : QAudioFormat::LittleEndian);
    7272    QAudioFormat::SampleType type = QAudioFormat::UnSignedInt;
    73     if ((sf.mFormatFlags & kLinearPCMFormatFlagIsSignedInteger) != 0)
     73    if ((sf.mFormatFlags & kAudioFormatFlagIsSignedInteger) != 0)
    7474        type = QAudioFormat::SignedInt;
    75     else if ((sf.mFormatFlags & kLinearPCMFormatFlagIsFloat) != 0)
     75    else if ((sf.mFormatFlags & kAudioFormatFlagIsFloat) != 0)
    7676        type = QAudioFormat::Float;
    7777    audioFormat.setSampleType(type);
     
    9999    case QAudioFormat::Unknown:  default: break;
    100100    }
     101
     102    if (audioFormat.byteOrder() == QAudioFormat::BigEndian)
     103        sf.mFormatFlags |= kAudioFormatFlagIsBigEndian;
    101104
    102105    return sf;
  • trunk/src/multimedia/audio/qaudio_mac_p.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/multimedia/audio/qaudio_symbian_p.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    314314    case IdleState:
    315315        return QAudio::IdleState;
    316     case SuspendedState:
     316    case SuspendedPausedState:
     317    case SuspendedStoppedState:
    317318        return QAudio::SuspendedState;
    318319    default:
     
    433434int DevSoundWrapper::samplesProcessed() const
    434435{
    435     Q_ASSERT(StateInitialized == m_state);
    436436    int result = 0;
    437     switch (m_mode) {
    438     case QAudio::AudioInput:
    439         result = m_devsound->SamplesRecorded();
    440         break;
    441     case QAudio::AudioOutput:
    442         result = m_devsound->SamplesPlayed();
    443         break;
     437    if (StateInitialized == m_state) {
     438        switch (m_mode) {
     439        case QAudio::AudioInput:
     440            result = m_devsound->SamplesRecorded();
     441            break;
     442        case QAudio::AudioOutput:
     443            result = m_devsound->SamplesPlayed();
     444            break;
     445        }
    444446    }
    445447    return result;
     
    476478}
    477479
    478 void DevSoundWrapper::pause()
    479 {
    480     Q_ASSERT(StateInitialized == m_state);
    481     m_devsound->Pause();
     480bool DevSoundWrapper::pause()
     481{
     482    Q_ASSERT(StateInitialized == m_state);
     483    const bool canPause = isResumeSupported();
     484    if (canPause)
     485        m_devsound->Pause();
     486    else
     487        stop();
     488    return canPause;
     489}
     490
     491void DevSoundWrapper::resume()
     492{
     493    Q_ASSERT(StateInitialized == m_state);
     494    Q_ASSERT(isResumeSupported());
     495    // TODO: QTBUG-13625
    482496}
    483497
     
    558572}
    559573
     574bool DevSoundWrapper::isResumeSupported() const
     575{
     576    // TODO: QTBUG-13625
     577    return false;
     578}
     579
    560580void DevSoundWrapper::InitializeComplete(TInt aError)
    561581{
  • trunk/src/multimedia/audio/qaudio_symbian_p.h

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    8282    ,   ActiveState
    8383    ,   IdleState
    84     ,   SuspendedState
     84    // QAudio is suspended; DevSound is paused
     85    ,   SuspendedPausedState
     86    // QAudio is suspended; DevSound is stopped
     87    ,   SuspendedStoppedState
    8588};
    8689
     
    118121    bool setFormat(const QAudioFormat &format);
    119122    bool start();
    120     void pause();
     123
     124    // If DevSound implementation supports pause, calls pause and returns true.
     125    // Otherwise calls stop and returns false.  In this case, all DevSound buffers
     126    // currently held by the backend must be discarded.
     127    bool pause();
     128
     129    void resume();
     130
    121131    void stop();
    122132    void bufferProcessed();
     
    141151    void getSupportedCodecs();
    142152    void populateCapabilities();
     153    bool isResumeSupported() const;
    143154
    144155private:
  • trunk/src/multimedia/audio/qaudiodevicefactory.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    6868QT_BEGIN_NAMESPACE
    6969
     70
     71#if !defined(QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
    7072Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,
    7173        (QAudioEngineFactoryInterface_iid, QLatin1String("/audio"), Qt::CaseInsensitive))
    72 
     74#endif
    7375
    7476class QNullDeviceInfo : public QAbstractAudioDeviceInfo
     
    138140#endif
    139141#endif
     142#if !defined(QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
    140143    QFactoryLoader* l = loader();
    141144
     
    149152        delete plugin;
    150153    }
    151 
     154#endif
    152155    return devices;
    153156}
     
    155158QAudioDeviceInfo QAudioDeviceFactory::defaultInputDevice()
    156159{
     160#if !defined(QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
    157161    QAudioEngineFactoryInterface* plugin = qobject_cast<QAudioEngineFactoryInterface*>(loader()->instance(QLatin1String("default")));
    158162
     
    162166            return QAudioDeviceInfo(QLatin1String("default"), list.at(0), QAudio::AudioInput);
    163167    }
     168#endif
     169
    164170#ifndef QT_NO_AUDIO_BACKEND
    165171#if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(HAS_ALSA) || defined(Q_OS_SYMBIAN))
     
    172178QAudioDeviceInfo QAudioDeviceFactory::defaultOutputDevice()
    173179{
     180#if !defined(QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
    174181    QAudioEngineFactoryInterface* plugin = qobject_cast<QAudioEngineFactoryInterface*>(loader()->instance(QLatin1String("default")));
    175182
     
    179186            return QAudioDeviceInfo(QLatin1String("default"), list.at(0), QAudio::AudioOutput);
    180187    }
     188#endif
     189
    181190#ifndef QT_NO_AUDIO_BACKEND
    182191#if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(HAS_ALSA) || defined(Q_OS_SYMBIAN))
     
    197206#endif
    198207#endif
     208#if !defined(QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
    199209    QAudioEngineFactoryInterface* plugin =
    200210        qobject_cast<QAudioEngineFactoryInterface*>(loader()->instance(realm));
     
    202212    if (plugin)
    203213        rc = plugin->createDeviceInfo(handle, mode);
    204 
     214#endif
    205215    return rc == 0 ? new QNullDeviceInfo() : rc;
    206216}
     
    226236#endif
    227237#endif
     238#if !defined(QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
    228239    QAudioEngineFactoryInterface* plugin =
    229240        qobject_cast<QAudioEngineFactoryInterface*>(loader()->instance(deviceInfo.realm()));
     
    231242    if (plugin)
    232243        return plugin->createInput(deviceInfo.handle(), format);
    233 
     244#endif
    234245    return new QNullInputDevice();
    235246}
     
    245256#endif
    246257#endif
     258#if !defined(QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
    247259    QAudioEngineFactoryInterface* plugin =
    248260        qobject_cast<QAudioEngineFactoryInterface*>(loader()->instance(deviceInfo.realm()));
     
    250262    if (plugin)
    251263        return plugin->createOutput(deviceInfo.handle(), format);
    252 
     264#endif
    253265    return new QNullOutputDevice();
    254266}
  • trunk/src/multimedia/audio/qaudiodevicefactory_p.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/multimedia/audio/qaudiodeviceinfo.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    107107    The values supported by the the device for each of these
    108108    parameters can be fetched with
    109     supportedByteOrders(), supportedChannels(), supportedCodecs(),
    110     supportedFrequencies(), supportedSampleSizes(), and
     109    supportedByteOrders(), supportedChannelCounts(), supportedCodecs(),
     110    supportedSampleRates(), supportedSampleSizes(), and
    111111    supportedSampleTypes(). The combinations supported are dependent on the platform,
    112112    audio plugins installed and the audio device capabilities. If you need a specific format, you can check if
     
    320320
    321321/*!
    322     Returns a list of supported frequencies.
     322    Returns a list of supported sample rates.
     323
     324    \since 4.7
     325*/
     326
     327QList<int> QAudioDeviceInfo::supportedSampleRates() const
     328{
     329    return supportedFrequencies();
     330}
     331
     332/*!
     333    \obsolete
     334
     335    Use supportedSampleRates() instead.
    323336*/
    324337
     
    329342
    330343/*!
    331     Returns a list of supported channels.
     344    Returns a list of supported channel counts.
     345
     346    \since 4.7
     347*/
     348
     349QList<int> QAudioDeviceInfo::supportedChannelCounts() const
     350{
     351    return supportedChannels();
     352}
     353
     354/*!
     355    \obsolete
     356
     357    Use supportedChannelCount() instead.
    332358*/
    333359
  • trunk/src/multimedia/audio/qaudiodeviceinfo.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    8585    QStringList supportedCodecs() const;
    8686    QList<int> supportedFrequencies() const;
     87    QList<int> supportedSampleRates() const;
    8788    QList<int> supportedChannels() const;
     89    QList<int> supportedChannelCounts() const;
    8890    QList<int> supportedSampleSizes() const;
    8991    QList<QAudioFormat::Endian> supportedByteOrders() const;
  • trunk/src/multimedia/audio/qaudiodeviceinfo_alsa_p.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    6363    device = QLatin1String(dev);
    6464    this->mode = mode;
     65
     66#if (SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
     67    checkSurround();
     68#endif
    6569}
    6670
     
    256260    snd_pcm_hw_params_set_channels(handle,params,format.channels());
    257261    snd_pcm_hw_params_set_rate(handle,params,format.frequency(),dir);
     262
     263    err = -1;
     264
    258265    switch(format.sampleSize()) {
    259266        case 8:
    260267            if(format.sampleType() == QAudioFormat::SignedInt)
    261                 snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S8);
     268                err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S8);
    262269            else if(format.sampleType() == QAudioFormat::UnSignedInt)
    263                 snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U8);
     270                err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U8);
    264271            break;
    265272        case 16:
    266273            if(format.sampleType() == QAudioFormat::SignedInt) {
    267274                if(format.byteOrder() == QAudioFormat::LittleEndian)
    268                     snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S16_LE);
     275                    err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S16_LE);
    269276                else if(format.byteOrder() == QAudioFormat::BigEndian)
    270                     snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S16_BE);
     277                    err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S16_BE);
    271278            } else if(format.sampleType() == QAudioFormat::UnSignedInt) {
    272279                if(format.byteOrder() == QAudioFormat::LittleEndian)
    273                     snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U16_LE);
     280                    err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U16_LE);
    274281                else if(format.byteOrder() == QAudioFormat::BigEndian)
    275                     snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U16_BE);
     282                    err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U16_BE);
    276283            }
    277284            break;
     
    279286            if(format.sampleType() == QAudioFormat::SignedInt) {
    280287                if(format.byteOrder() == QAudioFormat::LittleEndian)
    281                     snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S32_LE);
     288                    err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S32_LE);
    282289                else if(format.byteOrder() == QAudioFormat::BigEndian)
    283                     snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S32_BE);
     290                    err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S32_BE);
    284291            } else if(format.sampleType() == QAudioFormat::UnSignedInt) {
    285292                if(format.byteOrder() == QAudioFormat::LittleEndian)
    286                     snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U32_LE);
     293                    err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U32_LE);
    287294                else if(format.byteOrder() == QAudioFormat::BigEndian)
    288                     snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U32_BE);
     295                    err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U32_BE);
    289296            }
    290297    }
     
    390397    channelz.append(1);
    391398    channelz.append(2);
     399#if (SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
     400    if (surround40) channelz.append(4);
     401    if (surround51) channelz.append(6);
     402    if (surround71) channelz.append(8);
     403#endif
    392404    sizez.append(8);
    393405    sizez.append(16);
     
    427439    while (*n != NULL) {
    428440        name = snd_device_name_get_hint(*n, "NAME");
     441        if (name != 0 && qstrcmp(name, "null") != 0) {
     442            descr = snd_device_name_get_hint(*n, "DESC");
     443            io = snd_device_name_get_hint(*n, "IOID");
     444
     445            if ((descr != NULL) && ((io == NULL) || (io == filter))) {
     446                QString deviceName = QLatin1String(name);
     447                QString deviceDescription = QLatin1String(descr);
     448                allDevices.append(deviceName.toLocal8Bit().constData());
     449                if (deviceDescription.contains(QLatin1String("Default Audio Device")))
     450                    devices.append(deviceName.toLocal8Bit().constData());
     451            }
     452
     453            free(name);
     454            if (descr != NULL)
     455                free(descr);
     456            if (io != NULL)
     457                free(io);
     458        }
     459        ++n;
     460    }
     461    snd_device_name_free_hint(hints);
     462
     463    if(devices.size() > 0) {
     464        devices.append("default");
     465    }
     466#else
     467    int idx = 0;
     468    char* name;
     469
     470    while(snd_card_get_name(idx,&name) == 0) {
     471        devices.append(name);
     472        idx++;
     473    }
     474    if (idx > 0)
     475        devices.append("default");
     476#endif
     477    if (devices.size() == 0 && allDevices.size() > 0)
     478        return allDevices;
     479
     480    return devices;
     481}
     482
     483QByteArray QAudioDeviceInfoInternal::defaultInputDevice()
     484{
     485    QList<QByteArray> devices = availableDevices(QAudio::AudioInput);
     486    if(devices.size() == 0)
     487        return QByteArray();
     488
     489    return devices.first();
     490}
     491
     492QByteArray QAudioDeviceInfoInternal::defaultOutputDevice()
     493{
     494    QList<QByteArray> devices = availableDevices(QAudio::AudioOutput);
     495    if(devices.size() == 0)
     496        return QByteArray();
     497
     498    return devices.first();
     499}
     500
     501#if (SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
     502void QAudioDeviceInfoInternal::checkSurround()
     503{
     504    QList<QByteArray> devices;
     505    surround40 = false;
     506    surround51 = false;
     507    surround71 = false;
     508
     509    void **hints, **n;
     510    char *name, *descr, *io;
     511
     512    if(snd_device_name_hint(-1, "pcm", &hints) < 0)
     513        return;
     514
     515    n = hints;
     516
     517    while (*n != NULL) {
     518        name = snd_device_name_get_hint(*n, "NAME");
    429519        descr = snd_device_name_get_hint(*n, "DESC");
    430520        io = snd_device_name_get_hint(*n, "IOID");
    431         if((name != NULL) && (descr != NULL) && ((io == NULL) || (io == filter))) {
     521        if((name != NULL) && (descr != NULL)) {
    432522            QString deviceName = QLatin1String(name);
    433             QString deviceDescription = QLatin1String(descr);
    434             allDevices.append(deviceName.toLocal8Bit().constData());
    435             if(deviceDescription.contains(QLatin1String("Default Audio Device")))
    436                 devices.append(deviceName.toLocal8Bit().constData());
     523            if (mode == QAudio::AudioOutput) {
     524                if(deviceName.contains(QLatin1String("surround40")))
     525                    surround40 = true;
     526                if(deviceName.contains(QLatin1String("surround51")))
     527                    surround51 = true;
     528                if(deviceName.contains(QLatin1String("surround71")))
     529                    surround71 = true;
     530            }
    437531        }
    438532        if(name != NULL)
     
    445539    }
    446540    snd_device_name_free_hint(hints);
    447 
    448     if(devices.size() > 0) {
    449         devices.append("default");
    450     }
    451 #else
    452     int idx = 0;
    453     char* name;
    454 
    455     while(snd_card_get_name(idx,&name) == 0) {
    456         devices.append(name);
    457         idx++;
    458     }
    459     if (idx > 0)
    460         devices.append("default");
    461 #endif
    462     if (devices.size() == 0 && allDevices.size() > 0)
    463         return allDevices;
    464 
    465     return devices;
    466 }
    467 
    468 QByteArray QAudioDeviceInfoInternal::defaultInputDevice()
    469 {
    470     QList<QByteArray> devices = availableDevices(QAudio::AudioInput);
    471     if(devices.size() == 0)
    472         return QByteArray();
    473 
    474     return devices.first();
    475 }
    476 
    477 QByteArray QAudioDeviceInfoInternal::defaultOutputDevice()
    478 {
    479     QList<QByteArray> devices = availableDevices(QAudio::AudioOutput);
    480     if(devices.size() == 0)
    481         return QByteArray();
    482 
    483     return devices.first();
    484 }
     541}
     542#endif
    485543
    486544QT_END_NAMESPACE
  • trunk/src/multimedia/audio/qaudiodeviceinfo_alsa_p.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    9999    void close();
    100100
     101#if (SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
     102    void checkSurround();
     103    bool surround40;
     104    bool surround51;
     105    bool surround71;
     106#endif
     107
    101108    QString device;
    102109    QAudio::Mode mode;
  • trunk/src/multimedia/audio/qaudiodeviceinfo_mac_p.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    7979bool QAudioDeviceInfoInternal::isFormatSupported(const QAudioFormat& format) const
    8080{
    81     return format.codec() == QString::fromLatin1("audio/pcm");
     81    QAudioDeviceInfoInternal *self = const_cast<QAudioDeviceInfoInternal*>(this);
     82
     83    return format.isValid()
     84            && format.codec() == QString::fromLatin1("audio/pcm")
     85            && self->frequencyList().contains(format.frequency())
     86            && self->channelsList().contains(format.channels())
     87            && self->sampleSizeList().contains(format.sampleSize());
    8288}
    8389
  • trunk/src/multimedia/audio/qaudiodeviceinfo_mac_p.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/multimedia/audio/qaudiodeviceinfo_symbian_p.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/multimedia/audio/qaudiodeviceinfo_symbian_p.h

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/multimedia/audio/qaudiodeviceinfo_win32_p.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    9898    if(mode == QAudio::AudioOutput) {
    9999        nearest.setFrequency(44100);
    100         nearest.setChannels(2);
     100        nearest.setChannelCount(2);
    101101        nearest.setByteOrder(QAudioFormat::LittleEndian);
    102102        nearest.setSampleType(QAudioFormat::SignedInt);
     
    105105    } else {
    106106        nearest.setFrequency(11025);
    107         nearest.setChannels(1);
     107        nearest.setChannelCount(1);
    108108        nearest.setByteOrder(QAudioFormat::LittleEndian);
    109109        nearest.setSampleType(QAudioFormat::SignedInt);
     
    197197            }
    198198        }
    199     }
    200     if (!match) failed = true;
     199        if (!match)
     200            failed = true;
     201    }
    201202
    202203    // check frequency
     
    209210            }
    210211        }
     212        if (!match)
     213            failed = true;
    211214    }
    212215
     
    220223            }
    221224        }
     225        if (!match)
     226            failed = true;
    222227    }
    223228
     
    231236            }
    232237        }
     238        if (!match)
     239            failed = true;
    233240    }
    234241
     
    242249            }
    243250        }
     251        if (!match)
     252            failed = true;
    244253    }
    245254
     
    269278            if(waveOutGetDevCaps(i, &woc, sizeof(WAVEOUTCAPS))
    270279                == MMSYSERR_NOERROR) {
    271                 tmp = QString::fromUtf16((const unsigned short*)woc.szPname);
     280                tmp = QString((const QChar *)woc.szPname);
    272281                if(tmp.compare(device) == 0) {
    273282                    match = true;
     
    289298            if(waveInGetDevCaps(i, &woc, sizeof(WAVEINCAPS))
    290299                == MMSYSERR_NOERROR) {
    291                 tmp = QString::fromUtf16((const unsigned short*)woc.szPname);
     300                tmp = QString((const QChar *)woc.szPname);
    292301                if(tmp.compare(device) == 0) {
    293302                    match = true;
     
    375384        channelz.append(1);
    376385        channelz.append(2);
     386        if (mode == QAudio::AudioOutput) {
     387            channelz.append(4);
     388            channelz.append(6);
     389            channelz.append(8);
     390        }
    377391
    378392        byteOrderz.append(QAudioFormat::LittleEndian);
     
    400414            if(waveOutGetDevCaps(i, &woc, sizeof(WAVEOUTCAPS))
    401415                == MMSYSERR_NOERROR) {
    402                 devices.append(QString::fromUtf16((const unsigned short*)woc.szPname).toLocal8Bit().constData());
     416                devices.append(QString((const QChar *)woc.szPname).toLocal8Bit().constData());
    403417            }
    404418        }
     
    410424            if(waveInGetDevCaps(i, &woc, sizeof(WAVEINCAPS))
    411425                == MMSYSERR_NOERROR) {
    412                 devices.append(QString::fromUtf16((const unsigned short*)woc.szPname).toLocal8Bit().constData());
     426                devices.append(QString((const QChar *)woc.szPname).toLocal8Bit().constData());
    413427            }
    414428        }
  • trunk/src/multimedia/audio/qaudiodeviceinfo_win32_p.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/multimedia/audio/qaudioengine.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    134134    creates an internal QIODevice. Returns a pointer to the QIODevice being used to handle
    135135    the data transfer. This QIODevice can be used to write() audio data directly. Passing a
    136     QIODevice allows the data to be transfered without any extra code.
     136    QIODevice allows the data to be transferred without any extra code.
    137137*/
    138138
     
    248248    then the class creates an internal QIODevice. Returns a pointer to the
    249249    QIODevice being used to handle the data transfer. This QIODevice can be used to
    250     read() audio data directly. Passing a QIODevice allows the data to be transfered
     250    read() audio data directly. Passing a QIODevice allows the data to be transferred
    251251    without any extra code.
    252252*/
  • trunk/src/multimedia/audio/qaudioengine.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/multimedia/audio/qaudioengineplugin.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/multimedia/audio/qaudioengineplugin.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/multimedia/audio/qaudioformat.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    112112            \o Description
    113113        \row
    114             \o Frequency
     114            \o Sample Rate
    115115            \o Samples per second of audio data in Hertz.
    116116        \row
     
    144144    Values are initialized as follows:
    145145    \list
    146     \o frequency()  = -1
    147     \o channels()  = -1
     146    \o sampleRate()  = -1
     147    \o channelCount() = -1
    148148    \o sampleSize() = -1
    149149    \o byteOrder()  = QAudioFormat::Endian(QSysInfo::ByteOrder)
     
    225225
    226226/*!
    227    Sets the frequency to \a frequency.
     227   Sets the sample rate to \a samplerate Hertz.
     228
     229   \since 4.7
     230*/
     231
     232void QAudioFormat::setSampleRate(int samplerate)
     233{
     234    d->frequency = samplerate;
     235}
     236
     237/*!
     238   \obsolete
     239
     240   Use setSampleRate() instead.
    228241*/
    229242
     
    234247
    235248/*!
    236     Returns the current frequency value.
     249    Returns the current sample rate in Hertz.
     250
     251    \since 4.7
     252*/
     253
     254int QAudioFormat::sampleRate() const
     255{
     256    return d->frequency;
     257}
     258
     259/*!
     260   \obsolete
     261
     262   Use sampleRate() instead.
    237263*/
    238264
     
    243269
    244270/*!
    245    Sets the channels to \a channels.
     271   Sets the channel count to \a channels.
     272
     273   \since 4.7
     274*/
     275
     276void QAudioFormat::setChannelCount(int channels)
     277{
     278    d->channels = channels;
     279}
     280
     281/*!
     282   \obsolete
     283
     284   Use setChannelCount() instead.
    246285*/
    247286
     
    252291
    253292/*!
    254     Returns the current channel value.
     293    Returns the current channel count value.
     294
     295    \since 4.7
     296*/
     297
     298int QAudioFormat::channelCount() const
     299{
     300    return d->channels;
     301}
     302
     303/*!
     304    \obsolete
     305
     306    Use channelCount() instead.
    255307*/
    256308
  • trunk/src/multimedia/audio/qaudioformat.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    7676    void setFrequency(int frequency);
    7777    int frequency() const;
     78    void setSampleRate(int sampleRate);
     79    int sampleRate() const;
    7880
    7981    void setChannels(int channels);
    8082    int channels() const;
     83    void setChannelCount(int channelCount);
     84    int channelCount() const;
    8185
    8286    void setSampleSize(int sampleSize);
  • trunk/src/multimedia/audio/qaudioinput.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    202202/*!
    203203     Uses the \a device as the QIODevice to transfer data.
    204      Passing a QIODevice allows the data to be transfered without any extra code.
     204     Passing a QIODevice allows the data to be transferred without any extra code.
    205205     All that is required is to open the QIODevice.
    206206
     
    212212     state() is set to QAudio::StoppedState and stateChanged() signal is emitted.
    213213
    214     In either case, the stateChanged() signal may be emitted either synchronously
    215     during execution of the start() function or asynchronously after start() has
    216     returned to the caller.
    217 
    218      \sa {Symbian Platform Security Requirements}
     214     \l{QAudioInput#Symbian Platform Security Requirements}
    219215
    220216     \sa QIODevice
     
    238234    state() is set to QAudio::StoppedState and stateChanged() signal is emitted.
    239235
    240     In either case, the stateChanged() signal may be emitted either synchronously
    241     during execution of the start() function or asynchronously after start() has
    242     returned to the caller.
    243 
    244     \sa {Symbian Platform Security Requirements}
     236    \l{QAudioInput#Symbian Platform Security Requirements}
    245237
    246238    \sa QIODevice
     
    287279    Sets error() to QAudio::NoError, state() to QAudio::SuspendedState and
    288280    emit stateChanged() signal.
    289 
    290     Note: signal will always be emitted during execution of the resume() function.
    291281*/
    292282
     
    311301
    312302/*!
    313     Sets the audio buffer size to \a value bytes.
     303    Sets the audio buffer size to \a value milliseconds.
    314304
    315305    Note: This function can be called anytime before start(), calls to this
     
    326316
    327317/*!
    328     Returns the audio buffer size in bytes.
     318    Returns the audio buffer size in milliseconds.
    329319
    330320    If called before start(), returns platform default value.
  • trunk/src/multimedia/audio/qaudioinput.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/multimedia/audio/qaudioinput_alsa_p.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    121121            reset = true;
    122122        else {
    123             bytesAvailable = bytesReady();
     123            bytesAvailable = checkBytesReady();
    124124            if (bytesAvailable <= 0)
    125125                reset = true;
     
    153153int QAudioInputPrivate::setFormat()
    154154{
    155     snd_pcm_format_t format = SND_PCM_FORMAT_S16;
     155    snd_pcm_format_t format = SND_PCM_FORMAT_UNKNOWN;
    156156
    157157    if(settings.sampleSize() == 8) {
     
    205205    }
    206206
    207     return snd_pcm_hw_params_set_format( handle, hwparams, format);
     207    return format != SND_PCM_FORMAT_UNKNOWN
     208            ? snd_pcm_hw_params_set_format( handle, hwparams, format)
     209            : -1;
    208210}
    209211
     
    260262
    261263    int dir;
    262     int err=-1;
     264    int err = 0;
    263265    int count=0;
    264266    unsigned int freakuency=settings.frequency();
     267
     268    if (!settings.isValid()) {
     269        qWarning("QAudioOutput: open error, invalid format.");
     270    } else if (settings.frequency() <= 0) {
     271        qWarning("QAudioOutput: open error, invalid sample rate (%d).",
     272                 settings.frequency());
     273    } else {
     274        err = -1;
     275    }
     276
     277    if (err == 0) {
     278        errorState = QAudio::OpenError;
     279        deviceState = QAudio::StoppedState;
     280        return false;
     281    }
     282
    265283
    266284    QString dev = QString(QLatin1String(m_device.constData()));
     
    409427
    410428    // Step 5: Setup timer
    411     bytesAvailable = bytesReady();
     429    bytesAvailable = checkBytesReady();
    412430
    413431    if(pullMode)
     
    438456}
    439457
     458int QAudioInputPrivate::checkBytesReady()
     459{
     460    if(resuming)
     461        bytesAvailable = period_size;
     462    else if(deviceState != QAudio::ActiveState
     463            && deviceState != QAudio::IdleState)
     464        bytesAvailable = 0;
     465    else {
     466        int frames = snd_pcm_avail_update(handle);
     467        if (frames < 0) {
     468            bytesAvailable = frames;
     469        } else {
     470            if((int)frames > (int)buffer_frames)
     471                frames = buffer_frames;
     472            bytesAvailable = snd_pcm_frames_to_bytes(handle, frames);
     473        }
     474    }
     475    return bytesAvailable;
     476}
     477
    440478int QAudioInputPrivate::bytesReady() const
    441479{
    442     if(resuming)
    443         return period_size;
    444 
    445     if(deviceState != QAudio::ActiveState && deviceState != QAudio::IdleState)
    446         return 0;
    447     int frames = snd_pcm_avail_update(handle);
    448     if (frames < 0) return frames;
    449     if((int)frames > (int)buffer_frames)
    450         frames = buffer_frames;
    451 
    452     return snd_pcm_frames_to_bytes(handle, frames);
     480    return qMax(bytesAvailable, 0);
    453481}
    454482
    455483qint64 QAudioInputPrivate::read(char* data, qint64 len)
    456484{
    457     Q_UNUSED(len)
    458 
    459485    // Read in some audio data and write it to QIODevice, pull mode
    460486    if ( !handle )
    461487        return 0;
    462488
    463     bytesAvailable = bytesReady();
    464 
    465     if (bytesAvailable < 0) {
     489    // bytesAvaiable is saved as a side effect of checkBytesReady().
     490    int bytesToRead = checkBytesReady();
     491
     492    if (bytesToRead < 0) {
    466493        // bytesAvailable as negative is error code, try to recover from it.
    467         xrun_recovery(bytesAvailable);
    468         bytesAvailable = bytesReady();
    469         if (bytesAvailable < 0) {
     494        xrun_recovery(bytesToRead);
     495        bytesToRead = checkBytesReady();
     496        if (bytesToRead < 0) {
    470497            // recovery failed must stop and set error.
    471498            close();
     
    477504    }
    478505
     506    bytesToRead = qMin<qint64>(len, bytesToRead);
     507    bytesToRead -= bytesToRead % period_size;
    479508    int count=0, err = 0;
    480509    while(count < 5) {
    481         int chunks = bytesAvailable/period_size;
     510        int chunks = bytesToRead/period_size;
    482511        int frames = chunks*period_frames;
    483512        if(frames > (int)buffer_frames)
     
    527556                }
    528557            } else {
     558                bytesAvailable -= err;
    529559                totalTimeValue += err;
    530560                resuming = false;
     
    539569        } else {
    540570            memcpy(data,audioBuffer,err);
     571            bytesAvailable -= err;
    541572            totalTimeValue += err;
    542573            resuming = false;
     
    634665    if(pullMode) {
    635666        // reads some audio data and writes it to QIODevice
    636         read(0,0);
     667        read(0, buffer_size);
    637668    } else {
    638669        // emits readyRead() so user will call read() on QIODevice to get some audio data
     
    640671        a->trigger();
    641672    }
    642     bytesAvailable = bytesReady();
     673    bytesAvailable = checkBytesReady();
    643674
    644675    if(deviceState != QAudio::ActiveState)
    645676        return true;
     677
     678    if (bytesAvailable < 0) {
     679        // bytesAvailable as negative is error code, try to recover from it.
     680        xrun_recovery(bytesAvailable);
     681        bytesAvailable = checkBytesReady();
     682        if (bytesAvailable < 0) {
     683            // recovery failed must stop and set error.
     684            close();
     685            errorState = QAudio::IOError;
     686            deviceState = QAudio::StoppedState;
     687            emit stateChanged(deviceState);
     688            return 0;
     689        }
     690    }
    646691
    647692    if(intervalTime && (timeStamp.elapsed() + elapsedTimeOffset) > intervalTime) {
  • trunk/src/multimedia/audio/qaudioinput_alsa_p.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    6262#include <QtCore/qstring.h>
    6363#include <QtCore/qstringlist.h>
     64#include <QtCore/qelapsedtimer.h>
    6465#include <QtCore/qdatetime.h>
    6566
     
    110111
    111112private:
     113    int checkBytesReady();
    112114    int xrun_recovery(int err);
    113115    int setFormat();
     
    117119
    118120    QTimer* timer;
    119     QTime timeStamp;
    120     QTime clockStamp;
     121    QElapsedTimer timeStamp;
     122    QElapsedTimer clockStamp;
    121123    qint64 elapsedTimeOffset;
    122124    int intervalTime;
  • trunk/src/multimedia/audio/qaudioinput_mac_p.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    211211    }
    212212
     213    bool empty() const
     214    {
     215        return position == totalPackets;
     216    }
     217
    213218private:
    214219    UInt32 totalPackets;
     
    260265                             UInt32 inNumberFrames)
    261266    {
    262         const bool  wasEmpty = m_buffer->used() == 0;
     267        const bool  pullMode = m_device == 0;
    263268
    264269        OSStatus    err;
     
    276281            QAudioPacketFeeder  feeder(m_inputBufferList);
    277282
    278             bool    wecan = true;
    279283            int     copied = 0;
    280 
    281284            const int available = m_buffer->free();
    282285
    283             while (err == noErr && wecan) {
     286            while (err == noErr && !feeder.empty()) {
    284287                QAudioRingBuffer::Region region = m_buffer->acquireWriteRegion(available);
    285288
    286                 if (region.second > 0) {
    287                     AudioBufferList     output;
    288                     output.mNumberBuffers = 1;
    289                     output.mBuffers[0].mNumberChannels = 1;
    290                     output.mBuffers[0].mDataByteSize = region.second;
    291                     output.mBuffers[0].mData = region.first;
    292 
    293                     UInt32  packetSize = region.second / m_outputFormat.mBytesPerPacket;
    294                     err = AudioConverterFillComplexBuffer(m_audioConverter,
    295                                                           converterCallback,
    296                                                           &feeder,
    297                                                           &packetSize,
    298                                                           &output,
    299                                                           0);
    300 
    301                     region.second = output.mBuffers[0].mDataByteSize;
    302                     copied += region.second;
    303 
    304                     m_buffer->releaseWriteRegion(region);
    305                 }
    306                 else
    307                     wecan = false;
     289                if (region.second == 0)
     290                    break;
     291
     292                AudioBufferList     output;
     293                output.mNumberBuffers = 1;
     294                output.mBuffers[0].mNumberChannels = 1;
     295                output.mBuffers[0].mDataByteSize = region.second;
     296                output.mBuffers[0].mData = region.first;
     297
     298                UInt32  packetSize = region.second / m_outputFormat.mBytesPerPacket;
     299                err = AudioConverterFillComplexBuffer(m_audioConverter,
     300                                                      converterCallback,
     301                                                      &feeder,
     302                                                      &packetSize,
     303                                                      &output,
     304                                                      0);
     305                region.second = output.mBuffers[0].mDataByteSize;
     306                copied += region.second;
     307
     308                m_buffer->releaseWriteRegion(region);
    308309            }
    309310
     
    331332        }
    332333
    333         if (wasEmpty && framesRendered > 0)
     334        if (pullMode && framesRendered > 0)
    334335            emit readyRead();
    335336
     
    717718    QIODevice*  op = device;
    718719
    719     if (!audioFormat.isValid() || !open()) {
     720    if (!audioDeviceInfo->isFormatSupported(audioFormat) || !open()) {
    720721        stateCode = QAudio::StoppedState;
    721722        errorCode = QAudio::OpenError;
  • trunk/src/multimedia/audio/qaudioinput_mac_p.h

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/multimedia/audio/qaudioinput_symbian_p.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    175175        m_notifyTimer->stop();
    176176        m_pullTimer->stop();
    177         m_devSound->pause();
    178177        const qint64 samplesRecorded = getSamplesRecorded();
    179178        m_totalSamplesRecorded += samplesRecorded;
    180179
    181         if (m_devSoundBuffer) {
    182             m_devSoundBufferQ.append(m_devSoundBuffer);
     180        const bool paused = m_devSound->pause();
     181        if (paused) {
     182            if (m_devSoundBuffer)
     183                m_devSoundBufferQ.append(m_devSoundBuffer);
    183184            m_devSoundBuffer = 0;
     185            setState(SymbianAudio::SuspendedPausedState);
     186        } else {
     187            m_devSoundBuffer = 0;
     188            m_devSoundBufferQ.clear();
     189            m_devSoundBufferPos = 0;
     190            setState(SymbianAudio::SuspendedStoppedState);
    184191        }
    185 
    186         setState(SymbianAudio::SuspendedState);
    187192    }
    188193}
     
    190195void QAudioInputPrivate::resume()
    191196{
    192     if (SymbianAudio::SuspendedState == m_internalState) {
    193         if (!m_pullMode && !bytesReady())
     197    if (QAudio::SuspendedState == m_externalState) {
     198        if (SymbianAudio::SuspendedPausedState == m_internalState)
     199            m_devSound->resume();
     200        else
    194201            m_devSound->start();
    195202        startDataTransfer();
     
    247254{
    248255    int samplesPlayed = 0;
    249     if (m_devSound && SymbianAudio::SuspendedState != m_internalState)
     256    if (m_devSound && QAudio::SuspendedState != m_externalState)
    250257        samplesPlayed = getSamplesRecorded();
    251258
     
    336343            pushData();
    337344    } else {
    338         if (SymbianAudio::SuspendedState == m_internalState)
     345        if (QAudio::SuspendedState == m_externalState)
    339346            setState(SymbianAudio::ActiveState);
    340347        else
     
    374381        TDesC8 &inputBuffer = buffer->Data();
    375382
    376         const qint64 inputBytes = bytesReady();
     383        Q_ASSERT(inputBuffer.Length() >= m_devSoundBufferPos);
     384        const qint64 inputBytes = inputBuffer.Length() - m_devSoundBufferPos;
    377385        const qint64 outputBytes = len - bytesRead;
    378386        const qint64 copyBytes = outputBytes < inputBytes ?
     
    385393        bytesRead += copyBytes;
    386394
    387         if (!bytesReady())
     395        if (inputBytes == copyBytes)
    388396            bufferEmptied();
    389397    }
     
    404412        TDesC8 &inputBuffer = buffer->Data();
    405413
    406         const qint64 inputBytes = bytesReady();
     414        Q_ASSERT(inputBuffer.Length() >= m_devSoundBufferPos);
     415        const qint64 inputBytes = inputBuffer.Length() - m_devSoundBufferPos;
    407416        const qint64 bytesPushed = m_sink->write(
    408417            (char*)inputBuffer.Ptr() + m_devSoundBufferPos, inputBytes);
     
    410419        m_devSoundBufferPos += bytesPushed;
    411420
    412         if (!bytesReady())
     421        if (inputBytes == bytesPushed)
    413422            bufferEmptied();
    414423
     
    442451    m_totalBytesReady += buffer->Data().Length();
    443452
    444     if (SymbianAudio::SuspendedState == m_internalState) {
     453    if (SymbianAudio::SuspendedPausedState == m_internalState) {
    445454        m_devSoundBufferQ.append(buffer);
    446455    } else {
  • trunk/src/multimedia/audio/qaudioinput_symbian_p.h

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/multimedia/audio/qaudioinput_win32_p.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    8080}
    8181
    82 void CALLBACK QAudioInputPrivate::waveInProc( HWAVEIN hWaveIn, UINT uMsg,
     82void QT_WIN_CALLBACK QAudioInputPrivate::waveInProc( HWAVEIN hWaveIn, UINT uMsg,
    8383        DWORD dwInstance, DWORD dwParam1, DWORD dwParam2 )
    8484{
     
    149149    for(int i = 0; i < count; i++) {
    150150        waveInUnprepareHeader(hWaveIn,blocks, sizeof(WAVEHDR));
    151         blocks+=sizeof(WAVEHDR);
     151        blocks++;
    152152    }
    153153    HeapFree(GetProcessHeap(), 0, blockArray);
     
    215215#endif
    216216    header = 0;
    217     if(buffer_size == 0) {
    218         // Default buffer size, 200ms, default period size is 40ms
    219         buffer_size = settings.frequency()*settings.channels()*(settings.sampleSize()/8)*0.2;
    220         period_size = buffer_size/5;
     217    period_size = 0;
     218
     219    if (!settings.isValid()) {
     220        qWarning("QAudioInput: open error, invalid format.");
     221    } else if (settings.channels() <= 0) {
     222        qWarning("QAudioInput: open error, invalid number of channels (%d).",
     223                 settings.channels());
     224    } else if (settings.sampleSize() <= 0) {
     225        qWarning("QAudioInput: open error, invalid sample size (%d).",
     226                 settings.sampleSize());
     227    } else if (settings.frequency() < 8000 || settings.frequency() > 48000) {
     228        qWarning("QAudioInput: open error, frequency out of range (%d).", settings.frequency());
     229    } else if (buffer_size == 0) {
     230
     231        buffer_size
     232                = (settings.frequency()
     233                * settings.channels()
     234                * settings.sampleSize()
     235#ifndef Q_OS_WINCE  // Default buffer size, 200ms, default period size is 40ms
     236                + 39) / 40;
     237        period_size = buffer_size / 5;
    221238    } else {
    222         period_size = buffer_size/5;
    223     }
     239        period_size = buffer_size / 5;
     240#else               // For wince reduce size to 40ms for buffer size and 20ms period
     241                + 199) / 200;
     242        period_size = buffer_size / 2;
     243    } else {
     244        period_size = buffer_size / 2;
     245#endif
     246    }
     247
     248    if (period_size == 0) {
     249        errorState = QAudio::OpenError;
     250        deviceState = QAudio::StoppedState;
     251        emit stateChanged(deviceState);
     252        return false;
     253    }
     254
    224255    timeStamp.restart();
    225256    elapsedTimeOffset = 0;
     
    242273            == MMSYSERR_NOERROR) {
    243274            QString tmp;
    244             tmp = QString::fromUtf16((const unsigned short*)wic.szPname);
     275            tmp = QString((const QChar *)wic.szPname);
    245276            if(tmp.compare(QLatin1String(m_device)) == 0) {
    246277                devId = ii;
     
    370401                }
    371402            } else {
     403                l = qMin<qint64>(len, waveBlocks[header].dwBytesRecorded);
    372404                // push mode
    373                 memcpy(p,waveBlocks[header].lpData,waveBlocks[header].dwBytesRecorded);
    374                 l = waveBlocks[header].dwBytesRecorded;
     405                memcpy(p, waveBlocks[header].lpData, l);
     406
     407                len -= l;
     408
    375409#ifdef DEBUG_AUDIO
    376410                qDebug()<<"IN: "<<waveBlocks[header].dwBytesRecorded<<", OUT: "<<l;
     
    427461        mutex.lock();
    428462        if(!pullMode) {
    429             if(l+period_size > len && waveFreeBlockCount == buffer_size/period_size)
     463            if(len < period_size || waveFreeBlockCount == buffer_size/period_size)
    430464                done = true;
    431465        } else {
     
    538572    if(pullMode) {
    539573        // reads some audio data and writes it to QIODevice
    540         read(0,0);
     574        read(0, buffer_size);
    541575    } else {
    542576        // emits readyRead() so user will call read() on QIODevice to get some audio data
  • trunk/src/multimedia/audio/qaudioinput_win32_p.h

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    125125
    126126    QMutex mutex;
    127 
    128     static void CALLBACK waveInProc( HWAVEIN hWaveIn, UINT uMsg,
     127    static void QT_WIN_CALLBACK waveInProc( HWAVEIN hWaveIn, UINT uMsg,
    129128            DWORD dwInstance, DWORD dwParam1, DWORD dwParam2 );
    130129
  • trunk/src/multimedia/audio/qaudiooutput.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    200200/*!
    201201    Uses the \a device as the QIODevice to transfer data.
    202     Passing a QIODevice allows the data to be transfered without any extra code.
     202    Passing a QIODevice allows the data to be transferred without any extra code.
    203203    All that is required is to open the QIODevice.
    204204
  • trunk/src/multimedia/audio/qaudiooutput.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/multimedia/audio/qaudiooutput_alsa_p.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    156156int QAudioOutputPrivate::setFormat()
    157157{
    158     snd_pcm_format_t pcmformat = SND_PCM_FORMAT_S16;
     158    snd_pcm_format_t pcmformat = SND_PCM_FORMAT_UNKNOWN;
    159159
    160160    if(settings.sampleSize() == 8) {
     
    209209    }
    210210
    211     return snd_pcm_hw_params_set_format( handle, hwparams, pcmformat);
     211    return pcmformat != SND_PCM_FORMAT_UNKNOWN
     212            ? snd_pcm_hw_params_set_format( handle, hwparams, pcmformat)
     213            : -1;
    212214}
    213215
     
    276278
    277279    int dir;
    278     int err=-1;
     280    int err = 0;
    279281    int count=0;
    280282    unsigned int freakuency=settings.frequency();
     283
     284    if (!settings.isValid()) {
     285        qWarning("QAudioOutput: open error, invalid format.");
     286    } else if (settings.frequency() <= 0) {
     287        qWarning("QAudioOutput: open error, invalid sample rate (%d).",
     288                 settings.frequency());
     289    } else {
     290        err = -1;
     291    }
     292
     293    if (err == 0) {
     294        errorState = QAudio::OpenError;
     295        deviceState = QAudio::StoppedState;
     296        return false;
     297    }
    281298
    282299    QString dev = QString(QLatin1String(m_device.constData()));
  • trunk/src/multimedia/audio/qaudiooutput_alsa_p.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    6161#include <QtCore/qstring.h>
    6262#include <QtCore/qstringlist.h>
     63#include <QtCore/qelapsedtimer.h>
    6364#include <QtCore/qdatetime.h>
    6465
     
    134135    QByteArray m_device;
    135136    int bytesAvailable;
    136     QTime timeStamp;
    137     QTime clockStamp;
     137    QElapsedTimer timeStamp;
     138    QElapsedTimer clockStamp;
    138139    qint64 elapsedTimeOffset;
    139140    char* audioBuffer;
  • trunk/src/multimedia/audio/qaudiooutput_mac_p.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    6161#include <QtCore/qdebug.h>
    6262
    63 #include <QtMultimedia/qaudiodeviceinfo.h>
    6463#include <QtMultimedia/qaudiooutput.h>
    6564
    6665#include "qaudio_mac_p.h"
    6766#include "qaudiooutput_mac_p.h"
     67#include "qaudiodeviceinfo_mac_p.h"
    6868
    6969
     
    279279        errorCode = QAudio::OpenError;
    280280    else {
     281        audioDeviceInfo = new QAudioDeviceInfoInternal(device, QAudio::AudioOutput);
    281282        isOpen = false;
    282283        audioDeviceId = AudioDeviceID(did);
     
    300301QAudioOutputPrivate::~QAudioOutputPrivate()
    301302{
     303    delete audioDeviceInfo;
    302304    close();
    303305}
     
    359361    streamFormat = toAudioStreamBasicDescription(audioFormat);
    360362
    361     UInt32 size = sizeof(deviceFormat);
    362     if (AudioUnitGetProperty(audioUnit,
    363                                 kAudioUnitProperty_StreamFormat,
    364                                 kAudioUnitScope_Input,
    365                                 0,
    366                                 &deviceFormat,
    367                                 &size) != noErr) {
    368         qWarning() << "QAudioOutput: Unable to retrieve device format";
    369         return false;
    370     }
    371 
     363    UInt32 size = sizeof(streamFormat);
    372364    if (AudioUnitSetProperty(audioUnit,
    373365                                kAudioUnitProperty_StreamFormat,
     
    393385    }
    394386
    395     periodSizeBytes = (numberOfFrames * streamFormat.mSampleRate / deviceFormat.mSampleRate) *
    396                         streamFormat.mBytesPerFrame;
     387    periodSizeBytes = numberOfFrames * streamFormat.mBytesPerFrame;
    397388    if (internalBufferSize < periodSizeBytes * 2)
    398389        internalBufferSize = periodSizeBytes * 2;
     
    436427    QIODevice*  op = device;
    437428
    438     if (!audioFormat.isValid() || !open()) {
     429    if (!audioDeviceInfo->isFormatSupported(audioFormat) || !open()) {
    439430        stateCode = QAudio::StoppedState;
    440431        errorCode = QAudio::OpenError;
  • trunk/src/multimedia/audio/qaudiooutput_mac_p.h

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    7474
    7575class QIODevice;
     76class QAbstractAudioDeviceInfo;
    7677
    7778namespace QtMultimediaInternal
     
    102103    QMutex          mutex;
    103104    QTimer*         intervalTimer;
     105    QAbstractAudioDeviceInfo *audioDeviceInfo;
    104106
    105107    QAudio::Error    errorCode;
  • trunk/src/multimedia/audio/qaudiooutput_symbian_p.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    181181        m_notifyTimer->stop();
    182182        m_underflowTimer->stop();
    183 
    184183        const qint64 samplesWritten = SymbianAudio::Utils::bytesToSamples(
    185184                                          m_format, m_bytesWritten);
    186 
    187185        const qint64 samplesPlayed = getSamplesPlayed();
    188 
     186        m_totalSamplesPlayed += samplesPlayed;
    189187        m_bytesWritten = 0;
    190 
    191         // CMMFDevSound::Pause() is not guaranteed to work correctly in all
    192         // implementations, for play-mode DevSound sessions.  We therefore
    193         // have to implement suspend() by calling CMMFDevSound::Stop().
    194         // Because this causes buffered data to be dropped, we replace the
    195         // lost data with silence following a call to resume(), in order to
    196         // ensure that processedUSecs() returns the correct value.
    197         m_devSound->stop();
    198         m_totalSamplesPlayed += samplesPlayed;
    199 
    200         // Calculate the amount of data dropped
    201         const qint64 paddingSamples = samplesWritten - samplesPlayed;
    202         Q_ASSERT(paddingSamples >= 0);
    203         m_bytesPadding = SymbianAudio::Utils::samplesToBytes(m_format,
    204                                                              paddingSamples);
    205 
    206         setState(SymbianAudio::SuspendedState);
     188        const bool paused = m_devSound->pause();
     189        if (paused) {
     190            setState(SymbianAudio::SuspendedPausedState);
     191        } else {
     192            m_devSoundBuffer = 0;
     193            // Calculate the amount of data dropped
     194            const qint64 paddingSamples = samplesWritten - samplesPlayed;
     195            Q_ASSERT(paddingSamples >= 0);
     196            m_bytesPadding = SymbianAudio::Utils::samplesToBytes(m_format,
     197                                                                 paddingSamples);
     198            setState(SymbianAudio::SuspendedStoppedState);
     199        }
    207200    }
    208201}
     
    210203void QAudioOutputPrivate::resume()
    211204{
    212     if (SymbianAudio::SuspendedState == m_internalState) {
    213         if (!m_pullMode && m_devSoundBuffer && m_devSoundBuffer->Data().Length())
    214             bufferFilled();
    215         startPlayback();
     205    if (QAudio::SuspendedState == m_externalState) {
     206        if (SymbianAudio::SuspendedPausedState == m_internalState)
     207            m_devSound->resume();
     208        else
     209            startPlayback();
    216210    }
    217211}
     
    271265{
    272266    int samplesPlayed = 0;
    273     if (m_devSound && SymbianAudio::SuspendedState != m_internalState)
     267    if (m_devSound && QAudio::SuspendedState != m_externalState)
    274268        samplesPlayed = getSamplesPlayed();
    275269
     
    371365        else
    372366            setState(SymbianAudio::IdleState);
     367        break;
     368    case KErrOverflow:
     369        // Silently consume this error when in playback mode
    373370        break;
    374371    default:
  • trunk/src/multimedia/audio/qaudiooutput_symbian_p.h

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/src/multimedia/audio/qaudiooutput_win32_p.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    5353#include "qaudiooutput_win32_p.h"
    5454
     55#ifndef SPEAKER_FRONT_LEFT
     56    #define SPEAKER_FRONT_LEFT            0x00000001
     57    #define SPEAKER_FRONT_RIGHT           0x00000002
     58    #define SPEAKER_FRONT_CENTER          0x00000004
     59    #define SPEAKER_LOW_FREQUENCY         0x00000008
     60    #define SPEAKER_BACK_LEFT             0x00000010
     61    #define SPEAKER_BACK_RIGHT            0x00000020
     62    #define SPEAKER_FRONT_LEFT_OF_CENTER  0x00000040
     63    #define SPEAKER_FRONT_RIGHT_OF_CENTER 0x00000080
     64    #define SPEAKER_BACK_CENTER           0x00000100
     65    #define SPEAKER_SIDE_LEFT             0x00000200
     66    #define SPEAKER_SIDE_RIGHT            0x00000400
     67    #define SPEAKER_TOP_CENTER            0x00000800
     68    #define SPEAKER_TOP_FRONT_LEFT        0x00001000
     69    #define SPEAKER_TOP_FRONT_CENTER      0x00002000
     70    #define SPEAKER_TOP_FRONT_RIGHT       0x00004000
     71    #define SPEAKER_TOP_BACK_LEFT         0x00008000
     72    #define SPEAKER_TOP_BACK_CENTER       0x00010000
     73    #define SPEAKER_TOP_BACK_RIGHT        0x00020000
     74    #define SPEAKER_RESERVED              0x7FFC0000
     75    #define SPEAKER_ALL                   0x80000000
     76#endif
     77
     78#ifndef _WAVEFORMATEXTENSIBLE_
     79
     80    #define _WAVEFORMATEXTENSIBLE_
     81    typedef struct
     82    {
     83        WAVEFORMATEX Format;          // Base WAVEFORMATEX data
     84        union
     85        {
     86            WORD wValidBitsPerSample; // Valid bits in each sample container
     87            WORD wSamplesPerBlock;    // Samples per block of audio data; valid
     88                                      // if wBitsPerSample=0 (but rarely used).
     89            WORD wReserved;           // Zero if neither case above applies.
     90        } Samples;
     91        DWORD dwChannelMask;          // Positions of the audio channels
     92        GUID SubFormat;               // Format identifier GUID
     93    } WAVEFORMATEXTENSIBLE, *PWAVEFORMATEXTENSIBLE, *LPPWAVEFORMATEXTENSIBLE;
     94    typedef const WAVEFORMATEXTENSIBLE* LPCWAVEFORMATEXTENSIBLE;
     95
     96#endif
     97
     98#if !defined(WAVE_FORMAT_EXTENSIBLE)
     99#define WAVE_FORMAT_EXTENSIBLE 0xFFFE
     100#endif
     101
    55102//#define DEBUG_AUDIO 1
    56103
     
    147194    for(int i = 0; i < count; i++) {
    148195        waveOutUnprepareHeader(hWaveOut,blocks, sizeof(WAVEHDR));
    149         blocks+=sizeof(WAVEHDR);
     196        blocks++;
    150197    }
    151198    HeapFree(GetProcessHeap(), 0, blockArray);
     
    205252    qDebug()<<now.second()<<"s "<<now.msec()<<"ms :open()";
    206253#endif
    207     if (!(settings.frequency() >= 8000 && settings.frequency() <= 48000)) {
     254
     255    period_size = 0;
     256
     257    if (!settings.isValid()) {
     258        qWarning("QAudioOutput: open error, invalid format.");
     259    } else if (settings.channels() <= 0) {
     260        qWarning("QAudioOutput: open error, invalid number of channels (%d).",
     261                 settings.channels());
     262    } else if (settings.sampleSize() <= 0) {
     263        qWarning("QAudioOutput: open error, invalid sample size (%d).",
     264                 settings.sampleSize());
     265    } else if (settings.frequency() < 8000 || settings.frequency() > 48000) {
     266        qWarning("QAudioOutput: open error, frequency out of range (%d).", settings.frequency());
     267    } else if (buffer_size == 0) {
     268        // Default buffer size, 200ms, default period size is 40ms
     269        buffer_size
     270                = (settings.frequency()
     271                * settings.channels()
     272                * settings.sampleSize()
     273                + 39) / 40;
     274        period_size = buffer_size / 5;
     275    } else {
     276        period_size = buffer_size / 5;
     277    }
     278
     279    if (period_size == 0) {
    208280        errorState = QAudio::OpenError;
    209281        deviceState = QAudio::StoppedState;
    210282        emit stateChanged(deviceState);
    211         qWarning("QAudioOutput: open error, frequency out of range.");
    212283        return false;
    213284    }
    214     if(buffer_size == 0) {
    215         // Default buffer size, 200ms, default period size is 40ms
    216         buffer_size = settings.frequency()*settings.channels()*(settings.sampleSize()/8)*0.2;
    217         period_size = buffer_size/5;
    218     } else {
    219         period_size = buffer_size/5;
    220     }
     285
    221286    waveBlocks = allocateBlocks(period_size, buffer_size/period_size);
    222287
     
    251316            == MMSYSERR_NOERROR) {
    252317            QString tmp;
    253             tmp = QString::fromUtf16((const unsigned short*)woc.szPname);
     318            tmp = QString((const QChar *)woc.szPname);
    254319            if(tmp.compare(QLatin1String(m_device)) == 0) {
    255320                devId = ii;
     
    259324    }
    260325
    261     if(waveOutOpen(&hWaveOut, devId, &wfx,
    262                 (DWORD_PTR)&waveOutProc,
    263                 (DWORD_PTR) this,
    264                 CALLBACK_FUNCTION) != MMSYSERR_NOERROR) {
    265         errorState = QAudio::OpenError;
    266         deviceState = QAudio::StoppedState;
    267         emit stateChanged(deviceState);
    268         qWarning("QAudioOutput: open error");
    269         return false;
     326    if ( settings.channels() <= 2) {
     327        if(waveOutOpen(&hWaveOut, devId, &wfx,
     328                    (DWORD_PTR)&waveOutProc,
     329                    (DWORD_PTR) this,
     330                    CALLBACK_FUNCTION) != MMSYSERR_NOERROR) {
     331            errorState = QAudio::OpenError;
     332            deviceState = QAudio::StoppedState;
     333            emit stateChanged(deviceState);
     334            qWarning("QAudioOutput: open error");
     335            return false;
     336        }
     337    } else {
     338        WAVEFORMATEXTENSIBLE wfex;
     339        wfex.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
     340        wfex.Format.nChannels = settings.channels();
     341        wfex.Format.wBitsPerSample = settings.sampleSize();
     342        wfex.Format.nSamplesPerSec = settings.frequency();
     343        wfex.Format.nBlockAlign = wfex.Format.nChannels*wfex.Format.wBitsPerSample/8;
     344        wfex.Format.nAvgBytesPerSec=wfex.Format.nSamplesPerSec*wfex.Format.nBlockAlign;
     345        wfex.Samples.wValidBitsPerSample=wfex.Format.wBitsPerSample;
     346        static const GUID _KSDATAFORMAT_SUBTYPE_PCM = {
     347             0x00000001, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
     348        wfex.SubFormat=_KSDATAFORMAT_SUBTYPE_PCM;
     349        wfex.Format.cbSize=22;
     350
     351        wfex.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT;
     352        if (settings.channels() >= 4)
     353            wfex.dwChannelMask |= SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT;
     354        if (settings.channels() >= 6)
     355            wfex.dwChannelMask |= SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY;
     356        if (settings.channels() == 8)
     357            wfex.dwChannelMask |= SPEAKER_SIDE_LEFT | SPEAKER_SIDE_RIGHT;
     358
     359        if(waveOutOpen(&hWaveOut, devId, &wfex.Format,
     360                    (DWORD_PTR)&waveOutProc,
     361                    (DWORD_PTR) this,
     362                    CALLBACK_FUNCTION) != MMSYSERR_NOERROR) {
     363            errorState = QAudio::OpenError;
     364            deviceState = QAudio::StoppedState;
     365            emit stateChanged(deviceState);
     366            qWarning("QAudioOutput: open error");
     367            return false;
     368        }
    270369    }
    271370
     
    488587            }
    489588            if ( out < l) {
    490                 // Didnt write all data
     589                // Didn't write all data
    491590                audioSource->seek(audioSource->pos()-(l-out));
    492591            }
  • trunk/src/multimedia/audio/qaudiooutput_win32_p.h

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    118118    bool pullMode;
    119119    int intervalTime;
    120     static void CALLBACK waveOutProc( HWAVEOUT hWaveOut, UINT uMsg,
     120    static void QT_WIN_CALLBACK waveOutProc( HWAVEOUT hWaveOut, UINT uMsg,
    121121            DWORD dwInstance, DWORD dwParam1, DWORD dwParam2 );
    122122
Note: See TracChangeset for help on using the changeset viewer.