Index: trunk/src/multimedia/audio/audio.pri
===================================================================
--- trunk/src/multimedia/audio/audio.pri	(revision 769)
+++ trunk/src/multimedia/audio/audio.pri	(revision 846)
@@ -43,6 +43,6 @@
 
 } else:symbian {
-    INCLUDEPATH += /epoc32/include/mmf/common
-    INCLUDEPATH += /epoc32/include/mmf/server
+    INCLUDEPATH += $${EPOCROOT}epoc32/include/mmf/common
+    INCLUDEPATH += $${EPOCROOT}epoc32/include/mmf/server
 
     HEADERS += $$PWD/qaudio_symbian_p.h \
Index: trunk/src/multimedia/audio/qaudio.cpp
===================================================================
--- trunk/src/multimedia/audio/qaudio.cpp	(revision 769)
+++ trunk/src/multimedia/audio/qaudio.cpp	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
Index: trunk/src/multimedia/audio/qaudio.h
===================================================================
--- trunk/src/multimedia/audio/qaudio.h	(revision 769)
+++ trunk/src/multimedia/audio/qaudio.h	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
Index: trunk/src/multimedia/audio/qaudio_mac.cpp
===================================================================
--- trunk/src/multimedia/audio/qaudio_mac.cpp	(revision 769)
+++ trunk/src/multimedia/audio/qaudio_mac.cpp	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
@@ -69,9 +69,9 @@
     audioFormat.setSampleSize(sf.mBitsPerChannel);
     audioFormat.setCodec(QString::fromLatin1("audio/pcm"));
-    audioFormat.setByteOrder(sf.mFormatFlags & kLinearPCMFormatFlagIsBigEndian != 0 ? QAudioFormat::BigEndian : QAudioFormat::LittleEndian);
+    audioFormat.setByteOrder((sf.mFormatFlags & kAudioFormatFlagIsBigEndian) != 0 ? QAudioFormat::BigEndian : QAudioFormat::LittleEndian);
     QAudioFormat::SampleType type = QAudioFormat::UnSignedInt;
-    if ((sf.mFormatFlags & kLinearPCMFormatFlagIsSignedInteger) != 0)
+    if ((sf.mFormatFlags & kAudioFormatFlagIsSignedInteger) != 0)
         type = QAudioFormat::SignedInt;
-    else if ((sf.mFormatFlags & kLinearPCMFormatFlagIsFloat) != 0)
+    else if ((sf.mFormatFlags & kAudioFormatFlagIsFloat) != 0)
         type = QAudioFormat::Float;
     audioFormat.setSampleType(type);
@@ -99,4 +99,7 @@
     case QAudioFormat::Unknown:  default: break;
     }
+
+    if (audioFormat.byteOrder() == QAudioFormat::BigEndian)
+        sf.mFormatFlags |= kAudioFormatFlagIsBigEndian;
 
     return sf;
Index: trunk/src/multimedia/audio/qaudio_mac_p.h
===================================================================
--- trunk/src/multimedia/audio/qaudio_mac_p.h	(revision 769)
+++ trunk/src/multimedia/audio/qaudio_mac_p.h	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
Index: trunk/src/multimedia/audio/qaudio_symbian_p.cpp
===================================================================
--- trunk/src/multimedia/audio/qaudio_symbian_p.cpp	(revision 769)
+++ trunk/src/multimedia/audio/qaudio_symbian_p.cpp	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
@@ -314,5 +314,6 @@
     case IdleState:
         return QAudio::IdleState;
-    case SuspendedState:
+    case SuspendedPausedState:
+    case SuspendedStoppedState:
         return QAudio::SuspendedState;
     default:
@@ -433,13 +434,14 @@
 int DevSoundWrapper::samplesProcessed() const
 {
-    Q_ASSERT(StateInitialized == m_state);
     int result = 0;
-    switch (m_mode) {
-    case QAudio::AudioInput:
-        result = m_devsound->SamplesRecorded();
-        break;
-    case QAudio::AudioOutput:
-        result = m_devsound->SamplesPlayed();
-        break;
+    if (StateInitialized == m_state) {
+        switch (m_mode) {
+        case QAudio::AudioInput:
+            result = m_devsound->SamplesRecorded();
+            break;
+        case QAudio::AudioOutput:
+            result = m_devsound->SamplesPlayed();
+            break;
+        }
     }
     return result;
@@ -476,8 +478,20 @@
 }
 
-void DevSoundWrapper::pause()
-{
-    Q_ASSERT(StateInitialized == m_state);
-    m_devsound->Pause();
+bool DevSoundWrapper::pause()
+{
+    Q_ASSERT(StateInitialized == m_state);
+    const bool canPause = isResumeSupported();
+    if (canPause)
+        m_devsound->Pause();
+    else
+        stop();
+    return canPause;
+}
+
+void DevSoundWrapper::resume()
+{
+    Q_ASSERT(StateInitialized == m_state);
+    Q_ASSERT(isResumeSupported());
+    // TODO: QTBUG-13625
 }
 
@@ -558,4 +572,10 @@
 }
 
+bool DevSoundWrapper::isResumeSupported() const
+{
+    // TODO: QTBUG-13625
+    return false;
+}
+
 void DevSoundWrapper::InitializeComplete(TInt aError)
 {
Index: trunk/src/multimedia/audio/qaudio_symbian_p.h
===================================================================
--- trunk/src/multimedia/audio/qaudio_symbian_p.h	(revision 769)
+++ trunk/src/multimedia/audio/qaudio_symbian_p.h	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
@@ -82,5 +82,8 @@
     ,   ActiveState
     ,   IdleState
-    ,   SuspendedState
+    // QAudio is suspended; DevSound is paused
+    ,   SuspendedPausedState
+    // QAudio is suspended; DevSound is stopped
+    ,   SuspendedStoppedState
 };
 
@@ -118,5 +121,12 @@
     bool setFormat(const QAudioFormat &format);
     bool start();
-    void pause();
+
+    // If DevSound implementation supports pause, calls pause and returns true.
+    // Otherwise calls stop and returns false.  In this case, all DevSound buffers
+    // currently held by the backend must be discarded.
+    bool pause();
+
+    void resume();
+
     void stop();
     void bufferProcessed();
@@ -141,4 +151,5 @@
     void getSupportedCodecs();
     void populateCapabilities();
+    bool isResumeSupported() const;
 
 private:
Index: trunk/src/multimedia/audio/qaudiodevicefactory.cpp
===================================================================
--- trunk/src/multimedia/audio/qaudiodevicefactory.cpp	(revision 769)
+++ trunk/src/multimedia/audio/qaudiodevicefactory.cpp	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
@@ -68,7 +68,9 @@
 QT_BEGIN_NAMESPACE
 
+
+#if !defined(QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
 Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,
         (QAudioEngineFactoryInterface_iid, QLatin1String("/audio"), Qt::CaseInsensitive))
-
+#endif
 
 class QNullDeviceInfo : public QAbstractAudioDeviceInfo
@@ -138,4 +140,5 @@
 #endif
 #endif
+#if !defined(QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
     QFactoryLoader* l = loader();
 
@@ -149,5 +152,5 @@
         delete plugin;
     }
-
+#endif
     return devices;
 }
@@ -155,4 +158,5 @@
 QAudioDeviceInfo QAudioDeviceFactory::defaultInputDevice()
 {
+#if !defined(QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
     QAudioEngineFactoryInterface* plugin = qobject_cast<QAudioEngineFactoryInterface*>(loader()->instance(QLatin1String("default")));
 
@@ -162,4 +166,6 @@
             return QAudioDeviceInfo(QLatin1String("default"), list.at(0), QAudio::AudioInput);
     }
+#endif
+
 #ifndef QT_NO_AUDIO_BACKEND
 #if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(HAS_ALSA) || defined(Q_OS_SYMBIAN))
@@ -172,4 +178,5 @@
 QAudioDeviceInfo QAudioDeviceFactory::defaultOutputDevice()
 {
+#if !defined(QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
     QAudioEngineFactoryInterface* plugin = qobject_cast<QAudioEngineFactoryInterface*>(loader()->instance(QLatin1String("default")));
 
@@ -179,4 +186,6 @@
             return QAudioDeviceInfo(QLatin1String("default"), list.at(0), QAudio::AudioOutput);
     }
+#endif
+
 #ifndef QT_NO_AUDIO_BACKEND
 #if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(HAS_ALSA) || defined(Q_OS_SYMBIAN))
@@ -197,4 +206,5 @@
 #endif
 #endif
+#if !defined(QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
     QAudioEngineFactoryInterface* plugin =
         qobject_cast<QAudioEngineFactoryInterface*>(loader()->instance(realm));
@@ -202,5 +212,5 @@
     if (plugin)
         rc = plugin->createDeviceInfo(handle, mode);
-
+#endif
     return rc == 0 ? new QNullDeviceInfo() : rc;
 }
@@ -226,4 +236,5 @@
 #endif
 #endif
+#if !defined(QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
     QAudioEngineFactoryInterface* plugin =
         qobject_cast<QAudioEngineFactoryInterface*>(loader()->instance(deviceInfo.realm()));
@@ -231,5 +242,5 @@
     if (plugin)
         return plugin->createInput(deviceInfo.handle(), format);
-
+#endif
     return new QNullInputDevice();
 }
@@ -245,4 +256,5 @@
 #endif
 #endif
+#if !defined(QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
     QAudioEngineFactoryInterface* plugin =
         qobject_cast<QAudioEngineFactoryInterface*>(loader()->instance(deviceInfo.realm()));
@@ -250,5 +262,5 @@
     if (plugin)
         return plugin->createOutput(deviceInfo.handle(), format);
-
+#endif
     return new QNullOutputDevice();
 }
Index: trunk/src/multimedia/audio/qaudiodevicefactory_p.h
===================================================================
--- trunk/src/multimedia/audio/qaudiodevicefactory_p.h	(revision 769)
+++ trunk/src/multimedia/audio/qaudiodevicefactory_p.h	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
Index: trunk/src/multimedia/audio/qaudiodeviceinfo.cpp
===================================================================
--- trunk/src/multimedia/audio/qaudiodeviceinfo.cpp	(revision 769)
+++ trunk/src/multimedia/audio/qaudiodeviceinfo.cpp	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
@@ -107,6 +107,6 @@
     The values supported by the the device for each of these
     parameters can be fetched with
-    supportedByteOrders(), supportedChannels(), supportedCodecs(),
-    supportedFrequencies(), supportedSampleSizes(), and
+    supportedByteOrders(), supportedChannelCounts(), supportedCodecs(),
+    supportedSampleRates(), supportedSampleSizes(), and
     supportedSampleTypes(). The combinations supported are dependent on the platform,
     audio plugins installed and the audio device capabilities. If you need a specific format, you can check if
@@ -320,5 +320,18 @@
 
 /*!
-    Returns a list of supported frequencies.
+    Returns a list of supported sample rates.
+
+    \since 4.7
+*/
+
+QList<int> QAudioDeviceInfo::supportedSampleRates() const
+{
+    return supportedFrequencies();
+}
+
+/*!
+    \obsolete
+
+    Use supportedSampleRates() instead.
 */
 
@@ -329,5 +342,18 @@
 
 /*!
-    Returns a list of supported channels.
+    Returns a list of supported channel counts.
+
+    \since 4.7
+*/
+
+QList<int> QAudioDeviceInfo::supportedChannelCounts() const
+{
+    return supportedChannels();
+}
+
+/*!
+    \obsolete
+
+    Use supportedChannelCount() instead.
 */
 
Index: trunk/src/multimedia/audio/qaudiodeviceinfo.h
===================================================================
--- trunk/src/multimedia/audio/qaudiodeviceinfo.h	(revision 769)
+++ trunk/src/multimedia/audio/qaudiodeviceinfo.h	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
@@ -85,5 +85,7 @@
     QStringList supportedCodecs() const;
     QList<int> supportedFrequencies() const;
+    QList<int> supportedSampleRates() const;
     QList<int> supportedChannels() const;
+    QList<int> supportedChannelCounts() const;
     QList<int> supportedSampleSizes() const;
     QList<QAudioFormat::Endian> supportedByteOrders() const;
Index: trunk/src/multimedia/audio/qaudiodeviceinfo_alsa_p.cpp
===================================================================
--- trunk/src/multimedia/audio/qaudiodeviceinfo_alsa_p.cpp	(revision 769)
+++ trunk/src/multimedia/audio/qaudiodeviceinfo_alsa_p.cpp	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
@@ -63,4 +63,8 @@
     device = QLatin1String(dev);
     this->mode = mode;
+
+#if (SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
+    checkSurround();
+#endif
 }
 
@@ -256,22 +260,25 @@
     snd_pcm_hw_params_set_channels(handle,params,format.channels());
     snd_pcm_hw_params_set_rate(handle,params,format.frequency(),dir);
+
+    err = -1;
+
     switch(format.sampleSize()) {
         case 8:
             if(format.sampleType() == QAudioFormat::SignedInt)
-                snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S8);
+                err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S8);
             else if(format.sampleType() == QAudioFormat::UnSignedInt)
-                snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U8);
+                err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U8);
             break;
         case 16:
             if(format.sampleType() == QAudioFormat::SignedInt) {
                 if(format.byteOrder() == QAudioFormat::LittleEndian)
-                    snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S16_LE);
+                    err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S16_LE);
                 else if(format.byteOrder() == QAudioFormat::BigEndian)
-                    snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S16_BE);
+                    err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S16_BE);
             } else if(format.sampleType() == QAudioFormat::UnSignedInt) {
                 if(format.byteOrder() == QAudioFormat::LittleEndian)
-                    snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U16_LE);
+                    err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U16_LE);
                 else if(format.byteOrder() == QAudioFormat::BigEndian)
-                    snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U16_BE);
+                    err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U16_BE);
             }
             break;
@@ -279,12 +286,12 @@
             if(format.sampleType() == QAudioFormat::SignedInt) {
                 if(format.byteOrder() == QAudioFormat::LittleEndian)
-                    snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S32_LE);
+                    err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S32_LE);
                 else if(format.byteOrder() == QAudioFormat::BigEndian)
-                    snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S32_BE);
+                    err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S32_BE);
             } else if(format.sampleType() == QAudioFormat::UnSignedInt) {
                 if(format.byteOrder() == QAudioFormat::LittleEndian)
-                    snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U32_LE);
+                    err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U32_LE);
                 else if(format.byteOrder() == QAudioFormat::BigEndian)
-                    snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U32_BE);
+                    err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U32_BE);
             }
     }
@@ -390,4 +397,9 @@
     channelz.append(1);
     channelz.append(2);
+#if (SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
+    if (surround40) channelz.append(4);
+    if (surround51) channelz.append(6);
+    if (surround71) channelz.append(8);
+#endif
     sizez.append(8);
     sizez.append(16);
@@ -427,12 +439,94 @@
     while (*n != NULL) {
         name = snd_device_name_get_hint(*n, "NAME");
+        if (name != 0 && qstrcmp(name, "null") != 0) {
+            descr = snd_device_name_get_hint(*n, "DESC");
+            io = snd_device_name_get_hint(*n, "IOID");
+
+            if ((descr != NULL) && ((io == NULL) || (io == filter))) {
+                QString deviceName = QLatin1String(name);
+                QString deviceDescription = QLatin1String(descr);
+                allDevices.append(deviceName.toLocal8Bit().constData());
+                if (deviceDescription.contains(QLatin1String("Default Audio Device")))
+                    devices.append(deviceName.toLocal8Bit().constData());
+            }
+
+            free(name);
+            if (descr != NULL)
+                free(descr);
+            if (io != NULL)
+                free(io);
+        }
+        ++n;
+    }
+    snd_device_name_free_hint(hints);
+
+    if(devices.size() > 0) {
+        devices.append("default");
+    }
+#else
+    int idx = 0;
+    char* name;
+
+    while(snd_card_get_name(idx,&name) == 0) {
+        devices.append(name);
+        idx++;
+    }
+    if (idx > 0)
+        devices.append("default");
+#endif
+    if (devices.size() == 0 && allDevices.size() > 0)
+        return allDevices;
+
+    return devices;
+}
+
+QByteArray QAudioDeviceInfoInternal::defaultInputDevice()
+{
+    QList<QByteArray> devices = availableDevices(QAudio::AudioInput);
+    if(devices.size() == 0)
+        return QByteArray();
+
+    return devices.first();
+}
+
+QByteArray QAudioDeviceInfoInternal::defaultOutputDevice()
+{
+    QList<QByteArray> devices = availableDevices(QAudio::AudioOutput);
+    if(devices.size() == 0)
+        return QByteArray();
+
+    return devices.first();
+}
+
+#if (SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
+void QAudioDeviceInfoInternal::checkSurround()
+{
+    QList<QByteArray> devices;
+    surround40 = false;
+    surround51 = false;
+    surround71 = false;
+
+    void **hints, **n;
+    char *name, *descr, *io;
+
+    if(snd_device_name_hint(-1, "pcm", &hints) < 0)
+        return;
+
+    n = hints;
+
+    while (*n != NULL) {
+        name = snd_device_name_get_hint(*n, "NAME");
         descr = snd_device_name_get_hint(*n, "DESC");
         io = snd_device_name_get_hint(*n, "IOID");
-        if((name != NULL) && (descr != NULL) && ((io == NULL) || (io == filter))) {
+        if((name != NULL) && (descr != NULL)) {
             QString deviceName = QLatin1String(name);
-            QString deviceDescription = QLatin1String(descr);
-            allDevices.append(deviceName.toLocal8Bit().constData());
-            if(deviceDescription.contains(QLatin1String("Default Audio Device")))
-                devices.append(deviceName.toLocal8Bit().constData());
+            if (mode == QAudio::AudioOutput) {
+                if(deviceName.contains(QLatin1String("surround40")))
+                    surround40 = true;
+                if(deviceName.contains(QLatin1String("surround51")))
+                    surround51 = true;
+                if(deviceName.contains(QLatin1String("surround71")))
+                    surround71 = true;
+            }
         }
         if(name != NULL)
@@ -445,42 +539,6 @@
     }
     snd_device_name_free_hint(hints);
-
-    if(devices.size() > 0) {
-        devices.append("default");
-    }
-#else
-    int idx = 0;
-    char* name;
-
-    while(snd_card_get_name(idx,&name) == 0) {
-        devices.append(name);
-        idx++;
-    }
-    if (idx > 0)
-        devices.append("default");
-#endif
-    if (devices.size() == 0 && allDevices.size() > 0)
-        return allDevices;
-
-    return devices;
-}
-
-QByteArray QAudioDeviceInfoInternal::defaultInputDevice()
-{
-    QList<QByteArray> devices = availableDevices(QAudio::AudioInput);
-    if(devices.size() == 0)
-        return QByteArray();
-
-    return devices.first();
-}
-
-QByteArray QAudioDeviceInfoInternal::defaultOutputDevice()
-{
-    QList<QByteArray> devices = availableDevices(QAudio::AudioOutput);
-    if(devices.size() == 0)
-        return QByteArray();
-
-    return devices.first();
-}
+}
+#endif
 
 QT_END_NAMESPACE
Index: trunk/src/multimedia/audio/qaudiodeviceinfo_alsa_p.h
===================================================================
--- trunk/src/multimedia/audio/qaudiodeviceinfo_alsa_p.h	(revision 769)
+++ trunk/src/multimedia/audio/qaudiodeviceinfo_alsa_p.h	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
@@ -99,4 +99,11 @@
     void close();
 
+#if (SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
+    void checkSurround();
+    bool surround40;
+    bool surround51;
+    bool surround71;
+#endif
+
     QString device;
     QAudio::Mode mode;
Index: trunk/src/multimedia/audio/qaudiodeviceinfo_mac_p.cpp
===================================================================
--- trunk/src/multimedia/audio/qaudiodeviceinfo_mac_p.cpp	(revision 769)
+++ trunk/src/multimedia/audio/qaudiodeviceinfo_mac_p.cpp	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
@@ -79,5 +79,11 @@
 bool QAudioDeviceInfoInternal::isFormatSupported(const QAudioFormat& format) const
 {
-    return format.codec() == QString::fromLatin1("audio/pcm");
+    QAudioDeviceInfoInternal *self = const_cast<QAudioDeviceInfoInternal*>(this);
+
+    return format.isValid()
+            && format.codec() == QString::fromLatin1("audio/pcm")
+            && self->frequencyList().contains(format.frequency())
+            && self->channelsList().contains(format.channels())
+            && self->sampleSizeList().contains(format.sampleSize());
 }
 
Index: trunk/src/multimedia/audio/qaudiodeviceinfo_mac_p.h
===================================================================
--- trunk/src/multimedia/audio/qaudiodeviceinfo_mac_p.h	(revision 769)
+++ trunk/src/multimedia/audio/qaudiodeviceinfo_mac_p.h	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
Index: trunk/src/multimedia/audio/qaudiodeviceinfo_symbian_p.cpp
===================================================================
--- trunk/src/multimedia/audio/qaudiodeviceinfo_symbian_p.cpp	(revision 769)
+++ trunk/src/multimedia/audio/qaudiodeviceinfo_symbian_p.cpp	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
Index: trunk/src/multimedia/audio/qaudiodeviceinfo_symbian_p.h
===================================================================
--- trunk/src/multimedia/audio/qaudiodeviceinfo_symbian_p.h	(revision 769)
+++ trunk/src/multimedia/audio/qaudiodeviceinfo_symbian_p.h	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
Index: trunk/src/multimedia/audio/qaudiodeviceinfo_win32_p.cpp
===================================================================
--- trunk/src/multimedia/audio/qaudiodeviceinfo_win32_p.cpp	(revision 769)
+++ trunk/src/multimedia/audio/qaudiodeviceinfo_win32_p.cpp	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
@@ -98,5 +98,5 @@
     if(mode == QAudio::AudioOutput) {
         nearest.setFrequency(44100);
-        nearest.setChannels(2);
+        nearest.setChannelCount(2);
         nearest.setByteOrder(QAudioFormat::LittleEndian);
         nearest.setSampleType(QAudioFormat::SignedInt);
@@ -105,5 +105,5 @@
     } else {
         nearest.setFrequency(11025);
-        nearest.setChannels(1);
+        nearest.setChannelCount(1);
         nearest.setByteOrder(QAudioFormat::LittleEndian);
         nearest.setSampleType(QAudioFormat::SignedInt);
@@ -197,6 +197,7 @@
             }
         }
-    }
-    if (!match) failed = true;
+        if (!match)
+            failed = true;
+    }
 
     // check frequency
@@ -209,4 +210,6 @@
             }
         }
+        if (!match)
+            failed = true;
     }
 
@@ -220,4 +223,6 @@
             }
         }
+        if (!match)
+            failed = true;
     }
 
@@ -231,4 +236,6 @@
             }
         }
+        if (!match)
+            failed = true;
     }
 
@@ -242,4 +249,6 @@
             }
         }
+        if (!match)
+            failed = true;
     }
 
@@ -269,5 +278,5 @@
 	    if(waveOutGetDevCaps(i, &woc, sizeof(WAVEOUTCAPS))
 	        == MMSYSERR_NOERROR) {
-		tmp = QString::fromUtf16((const unsigned short*)woc.szPname);
+		tmp = QString((const QChar *)woc.szPname);
 		if(tmp.compare(device) == 0) {
 		    match = true;
@@ -289,5 +298,5 @@
 	    if(waveInGetDevCaps(i, &woc, sizeof(WAVEINCAPS))
 	        == MMSYSERR_NOERROR) {
-		tmp = QString::fromUtf16((const unsigned short*)woc.szPname);
+		tmp = QString((const QChar *)woc.szPname);
 		if(tmp.compare(device) == 0) {
 		    match = true;
@@ -375,4 +384,9 @@
 	channelz.append(1);
 	channelz.append(2);
+        if (mode == QAudio::AudioOutput) {
+            channelz.append(4);
+            channelz.append(6);
+            channelz.append(8);
+        }
 
 	byteOrderz.append(QAudioFormat::LittleEndian);
@@ -400,5 +414,5 @@
 	    if(waveOutGetDevCaps(i, &woc, sizeof(WAVEOUTCAPS))
 	        == MMSYSERR_NOERROR) {
-	        devices.append(QString::fromUtf16((const unsigned short*)woc.szPname).toLocal8Bit().constData());
+	        devices.append(QString((const QChar *)woc.szPname).toLocal8Bit().constData());
 	    }
 	}
@@ -410,5 +424,5 @@
 	    if(waveInGetDevCaps(i, &woc, sizeof(WAVEINCAPS))
 	        == MMSYSERR_NOERROR) {
-	        devices.append(QString::fromUtf16((const unsigned short*)woc.szPname).toLocal8Bit().constData());
+	        devices.append(QString((const QChar *)woc.szPname).toLocal8Bit().constData());
 	    }
 	}
Index: trunk/src/multimedia/audio/qaudiodeviceinfo_win32_p.h
===================================================================
--- trunk/src/multimedia/audio/qaudiodeviceinfo_win32_p.h	(revision 769)
+++ trunk/src/multimedia/audio/qaudiodeviceinfo_win32_p.h	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
Index: trunk/src/multimedia/audio/qaudioengine.cpp
===================================================================
--- trunk/src/multimedia/audio/qaudioengine.cpp	(revision 769)
+++ trunk/src/multimedia/audio/qaudioengine.cpp	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
@@ -134,5 +134,5 @@
     creates an internal QIODevice. Returns a pointer to the QIODevice being used to handle
     the data transfer. This QIODevice can be used to write() audio data directly. Passing a
-    QIODevice allows the data to be transfered without any extra code.
+    QIODevice allows the data to be transferred without any extra code.
 */
 
@@ -248,5 +248,5 @@
     then the class creates an internal QIODevice. Returns a pointer to the
     QIODevice being used to handle the data transfer. This QIODevice can be used to
-    read() audio data directly. Passing a QIODevice allows the data to be transfered
+    read() audio data directly. Passing a QIODevice allows the data to be transferred
     without any extra code.
 */
Index: trunk/src/multimedia/audio/qaudioengine.h
===================================================================
--- trunk/src/multimedia/audio/qaudioengine.h	(revision 769)
+++ trunk/src/multimedia/audio/qaudioengine.h	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
Index: trunk/src/multimedia/audio/qaudioengineplugin.cpp
===================================================================
--- trunk/src/multimedia/audio/qaudioengineplugin.cpp	(revision 769)
+++ trunk/src/multimedia/audio/qaudioengineplugin.cpp	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
Index: trunk/src/multimedia/audio/qaudioengineplugin.h
===================================================================
--- trunk/src/multimedia/audio/qaudioengineplugin.h	(revision 769)
+++ trunk/src/multimedia/audio/qaudioengineplugin.h	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
Index: trunk/src/multimedia/audio/qaudioformat.cpp
===================================================================
--- trunk/src/multimedia/audio/qaudioformat.cpp	(revision 769)
+++ trunk/src/multimedia/audio/qaudioformat.cpp	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
@@ -112,5 +112,5 @@
             \o Description
         \row
-            \o Frequency
+            \o Sample Rate
             \o Samples per second of audio data in Hertz.
         \row
@@ -144,6 +144,6 @@
     Values are initialized as follows:
     \list
-    \o frequency()  = -1
-    \o channels()   = -1
+    \o sampleRate()  = -1
+    \o channelCount() = -1
     \o sampleSize() = -1
     \o byteOrder()  = QAudioFormat::Endian(QSysInfo::ByteOrder)
@@ -225,5 +225,18 @@
 
 /*!
-   Sets the frequency to \a frequency.
+   Sets the sample rate to \a samplerate Hertz.
+
+   \since 4.7
+*/
+
+void QAudioFormat::setSampleRate(int samplerate)
+{
+    d->frequency = samplerate;
+}
+
+/*!
+   \obsolete
+
+   Use setSampleRate() instead.
 */
 
@@ -234,5 +247,18 @@
 
 /*!
-    Returns the current frequency value.
+    Returns the current sample rate in Hertz.
+
+    \since 4.7
+*/
+
+int QAudioFormat::sampleRate() const
+{
+    return d->frequency;
+}
+
+/*!
+   \obsolete
+
+   Use sampleRate() instead.
 */
 
@@ -243,5 +269,18 @@
 
 /*!
-   Sets the channels to \a channels.
+   Sets the channel count to \a channels.
+
+   \since 4.7
+*/
+
+void QAudioFormat::setChannelCount(int channels)
+{
+    d->channels = channels;
+}
+
+/*!
+   \obsolete
+
+   Use setChannelCount() instead.
 */
 
@@ -252,5 +291,18 @@
 
 /*!
-    Returns the current channel value.
+    Returns the current channel count value.
+
+    \since 4.7
+*/
+
+int QAudioFormat::channelCount() const
+{
+    return d->channels;
+}
+
+/*!
+    \obsolete
+
+    Use channelCount() instead.
 */
 
Index: trunk/src/multimedia/audio/qaudioformat.h
===================================================================
--- trunk/src/multimedia/audio/qaudioformat.h	(revision 769)
+++ trunk/src/multimedia/audio/qaudioformat.h	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
@@ -76,7 +76,11 @@
     void setFrequency(int frequency);
     int frequency() const;
+    void setSampleRate(int sampleRate);
+    int sampleRate() const;
 
     void setChannels(int channels);
     int channels() const;
+    void setChannelCount(int channelCount);
+    int channelCount() const;
 
     void setSampleSize(int sampleSize);
Index: trunk/src/multimedia/audio/qaudioinput.cpp
===================================================================
--- trunk/src/multimedia/audio/qaudioinput.cpp	(revision 769)
+++ trunk/src/multimedia/audio/qaudioinput.cpp	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
@@ -202,5 +202,5 @@
 /*!
      Uses the \a device as the QIODevice to transfer data.
-     Passing a QIODevice allows the data to be transfered without any extra code.
+     Passing a QIODevice allows the data to be transferred without any extra code.
      All that is required is to open the QIODevice.
 
@@ -212,9 +212,5 @@
      state() is set to QAudio::StoppedState and stateChanged() signal is emitted.
 
-    In either case, the stateChanged() signal may be emitted either synchronously
-    during execution of the start() function or asynchronously after start() has
-    returned to the caller.
-
-     \sa {Symbian Platform Security Requirements}
+     \l{QAudioInput#Symbian Platform Security Requirements}
 
      \sa QIODevice
@@ -238,9 +234,5 @@
     state() is set to QAudio::StoppedState and stateChanged() signal is emitted.
 
-    In either case, the stateChanged() signal may be emitted either synchronously
-    during execution of the start() function or asynchronously after start() has
-    returned to the caller.
-
-    \sa {Symbian Platform Security Requirements}
+    \l{QAudioInput#Symbian Platform Security Requirements}
 
     \sa QIODevice
@@ -287,6 +279,4 @@
     Sets error() to QAudio::NoError, state() to QAudio::SuspendedState and
     emit stateChanged() signal.
-
-    Note: signal will always be emitted during execution of the resume() function.
 */
 
@@ -311,5 +301,5 @@
 
 /*!
-    Sets the audio buffer size to \a value bytes.
+    Sets the audio buffer size to \a value milliseconds.
 
     Note: This function can be called anytime before start(), calls to this
@@ -326,5 +316,5 @@
 
 /*!
-    Returns the audio buffer size in bytes.
+    Returns the audio buffer size in milliseconds.
 
     If called before start(), returns platform default value.
Index: trunk/src/multimedia/audio/qaudioinput.h
===================================================================
--- trunk/src/multimedia/audio/qaudioinput.h	(revision 769)
+++ trunk/src/multimedia/audio/qaudioinput.h	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
Index: trunk/src/multimedia/audio/qaudioinput_alsa_p.cpp
===================================================================
--- trunk/src/multimedia/audio/qaudioinput_alsa_p.cpp	(revision 769)
+++ trunk/src/multimedia/audio/qaudioinput_alsa_p.cpp	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
@@ -121,5 +121,5 @@
             reset = true;
         else {
-            bytesAvailable = bytesReady();
+            bytesAvailable = checkBytesReady();
             if (bytesAvailable <= 0)
                 reset = true;
@@ -153,5 +153,5 @@
 int QAudioInputPrivate::setFormat()
 {
-    snd_pcm_format_t format = SND_PCM_FORMAT_S16;
+    snd_pcm_format_t format = SND_PCM_FORMAT_UNKNOWN;
 
     if(settings.sampleSize() == 8) {
@@ -205,5 +205,7 @@
     }
 
-    return snd_pcm_hw_params_set_format( handle, hwparams, format);
+    return format != SND_PCM_FORMAT_UNKNOWN
+            ? snd_pcm_hw_params_set_format( handle, hwparams, format)
+            : -1;
 }
 
@@ -260,7 +262,23 @@
 
     int dir;
-    int err=-1;
+    int err = 0;
     int count=0;
     unsigned int freakuency=settings.frequency();
+
+    if (!settings.isValid()) {
+        qWarning("QAudioOutput: open error, invalid format.");
+    } else if (settings.frequency() <= 0) {
+        qWarning("QAudioOutput: open error, invalid sample rate (%d).",
+                 settings.frequency());
+    } else {
+        err = -1;
+    }
+
+    if (err == 0) {
+        errorState = QAudio::OpenError;
+        deviceState = QAudio::StoppedState;
+        return false;
+    }
+
 
     QString dev = QString(QLatin1String(m_device.constData()));
@@ -409,5 +427,5 @@
 
     // Step 5: Setup timer
-    bytesAvailable = bytesReady();
+    bytesAvailable = checkBytesReady();
 
     if(pullMode)
@@ -438,34 +456,43 @@
 }
 
+int QAudioInputPrivate::checkBytesReady()
+{
+    if(resuming)
+        bytesAvailable = period_size;
+    else if(deviceState != QAudio::ActiveState
+            && deviceState != QAudio::IdleState)
+        bytesAvailable = 0;
+    else {
+        int frames = snd_pcm_avail_update(handle);
+        if (frames < 0) {
+            bytesAvailable = frames;
+        } else {
+            if((int)frames > (int)buffer_frames)
+                frames = buffer_frames;
+            bytesAvailable = snd_pcm_frames_to_bytes(handle, frames);
+        }
+    }
+    return bytesAvailable;
+}
+
 int QAudioInputPrivate::bytesReady() const
 {
-    if(resuming)
-        return period_size;
-
-    if(deviceState != QAudio::ActiveState && deviceState != QAudio::IdleState)
-        return 0;
-    int frames = snd_pcm_avail_update(handle);
-    if (frames < 0) return frames;
-    if((int)frames > (int)buffer_frames)
-        frames = buffer_frames;
-
-    return snd_pcm_frames_to_bytes(handle, frames);
+    return qMax(bytesAvailable, 0);
 }
 
 qint64 QAudioInputPrivate::read(char* data, qint64 len)
 {
-    Q_UNUSED(len)
-
     // Read in some audio data and write it to QIODevice, pull mode
     if ( !handle )
         return 0;
 
-    bytesAvailable = bytesReady();
-
-    if (bytesAvailable < 0) {
+    // bytesAvaiable is saved as a side effect of checkBytesReady().
+    int bytesToRead = checkBytesReady();
+
+    if (bytesToRead < 0) {
         // bytesAvailable as negative is error code, try to recover from it.
-        xrun_recovery(bytesAvailable);
-        bytesAvailable = bytesReady();
-        if (bytesAvailable < 0) {
+        xrun_recovery(bytesToRead);
+        bytesToRead = checkBytesReady();
+        if (bytesToRead < 0) {
             // recovery failed must stop and set error.
             close();
@@ -477,7 +504,9 @@
     }
 
+    bytesToRead = qMin<qint64>(len, bytesToRead);
+    bytesToRead -= bytesToRead % period_size;
     int count=0, err = 0;
     while(count < 5) {
-        int chunks = bytesAvailable/period_size;
+        int chunks = bytesToRead/period_size;
         int frames = chunks*period_frames;
         if(frames > (int)buffer_frames)
@@ -527,4 +556,5 @@
                 }
             } else {
+                bytesAvailable -= err;
                 totalTimeValue += err;
                 resuming = false;
@@ -539,4 +569,5 @@
         } else {
             memcpy(data,audioBuffer,err);
+            bytesAvailable -= err;
             totalTimeValue += err;
             resuming = false;
@@ -634,5 +665,5 @@
     if(pullMode) {
         // reads some audio data and writes it to QIODevice
-        read(0,0);
+        read(0, buffer_size);
     } else {
         // emits readyRead() so user will call read() on QIODevice to get some audio data
@@ -640,8 +671,22 @@
         a->trigger();
     }
-    bytesAvailable = bytesReady();
+    bytesAvailable = checkBytesReady();
 
     if(deviceState != QAudio::ActiveState)
         return true;
+
+    if (bytesAvailable < 0) {
+        // bytesAvailable as negative is error code, try to recover from it.
+        xrun_recovery(bytesAvailable);
+        bytesAvailable = checkBytesReady();
+        if (bytesAvailable < 0) {
+            // recovery failed must stop and set error.
+            close();
+            errorState = QAudio::IOError;
+            deviceState = QAudio::StoppedState;
+            emit stateChanged(deviceState);
+            return 0;
+        }
+    }
 
     if(intervalTime && (timeStamp.elapsed() + elapsedTimeOffset) > intervalTime) {
Index: trunk/src/multimedia/audio/qaudioinput_alsa_p.h
===================================================================
--- trunk/src/multimedia/audio/qaudioinput_alsa_p.h	(revision 769)
+++ trunk/src/multimedia/audio/qaudioinput_alsa_p.h	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
@@ -62,4 +62,5 @@
 #include <QtCore/qstring.h>
 #include <QtCore/qstringlist.h>
+#include <QtCore/qelapsedtimer.h>
 #include <QtCore/qdatetime.h>
 
@@ -110,4 +111,5 @@
 
 private:
+    int checkBytesReady();
     int xrun_recovery(int err);
     int setFormat();
@@ -117,6 +119,6 @@
 
     QTimer* timer;
-    QTime timeStamp;
-    QTime clockStamp;
+    QElapsedTimer timeStamp;
+    QElapsedTimer clockStamp;
     qint64 elapsedTimeOffset;
     int intervalTime;
Index: trunk/src/multimedia/audio/qaudioinput_mac_p.cpp
===================================================================
--- trunk/src/multimedia/audio/qaudioinput_mac_p.cpp	(revision 769)
+++ trunk/src/multimedia/audio/qaudioinput_mac_p.cpp	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
@@ -211,4 +211,9 @@
     }
 
+    bool empty() const
+    {
+        return position == totalPackets;
+    }
+
 private:
     UInt32 totalPackets;
@@ -260,5 +265,5 @@
                              UInt32 inNumberFrames)
     {
-        const bool  wasEmpty = m_buffer->used() == 0;
+        const bool  pullMode = m_device == 0;
 
         OSStatus    err;
@@ -276,34 +281,30 @@
             QAudioPacketFeeder  feeder(m_inputBufferList);
 
-            bool    wecan = true;
             int     copied = 0;
-
             const int available = m_buffer->free();
 
-            while (err == noErr && wecan) {
+            while (err == noErr && !feeder.empty()) {
                 QAudioRingBuffer::Region region = m_buffer->acquireWriteRegion(available);
 
-                if (region.second > 0) {
-                    AudioBufferList     output;
-                    output.mNumberBuffers = 1;
-                    output.mBuffers[0].mNumberChannels = 1;
-                    output.mBuffers[0].mDataByteSize = region.second;
-                    output.mBuffers[0].mData = region.first;
-
-                    UInt32  packetSize = region.second / m_outputFormat.mBytesPerPacket;
-                    err = AudioConverterFillComplexBuffer(m_audioConverter,
-                                                          converterCallback,
-                                                          &feeder,
-                                                          &packetSize,
-                                                          &output,
-                                                          0);
-
-                    region.second = output.mBuffers[0].mDataByteSize;
-                    copied += region.second;
-
-                    m_buffer->releaseWriteRegion(region);
-                }
-                else
-                    wecan = false;
+                if (region.second == 0)
+                    break;
+
+                AudioBufferList     output;
+                output.mNumberBuffers = 1;
+                output.mBuffers[0].mNumberChannels = 1;
+                output.mBuffers[0].mDataByteSize = region.second;
+                output.mBuffers[0].mData = region.first;
+
+                UInt32  packetSize = region.second / m_outputFormat.mBytesPerPacket;
+                err = AudioConverterFillComplexBuffer(m_audioConverter,
+                                                      converterCallback,
+                                                      &feeder,
+                                                      &packetSize,
+                                                      &output,
+                                                      0);
+                region.second = output.mBuffers[0].mDataByteSize;
+                copied += region.second;
+
+                m_buffer->releaseWriteRegion(region);
             }
 
@@ -331,5 +332,5 @@
         }
 
-        if (wasEmpty && framesRendered > 0)
+        if (pullMode && framesRendered > 0)
             emit readyRead();
 
@@ -717,5 +718,5 @@
     QIODevice*  op = device;
 
-    if (!audioFormat.isValid() || !open()) {
+    if (!audioDeviceInfo->isFormatSupported(audioFormat) || !open()) {
         stateCode = QAudio::StoppedState;
         errorCode = QAudio::OpenError;
Index: trunk/src/multimedia/audio/qaudioinput_mac_p.h
===================================================================
--- trunk/src/multimedia/audio/qaudioinput_mac_p.h	(revision 769)
+++ trunk/src/multimedia/audio/qaudioinput_mac_p.h	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
Index: trunk/src/multimedia/audio/qaudioinput_symbian_p.cpp
===================================================================
--- trunk/src/multimedia/audio/qaudioinput_symbian_p.cpp	(revision 769)
+++ trunk/src/multimedia/audio/qaudioinput_symbian_p.cpp	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
@@ -175,14 +175,19 @@
         m_notifyTimer->stop();
         m_pullTimer->stop();
-        m_devSound->pause();
         const qint64 samplesRecorded = getSamplesRecorded();
         m_totalSamplesRecorded += samplesRecorded;
 
-        if (m_devSoundBuffer) {
-            m_devSoundBufferQ.append(m_devSoundBuffer);
+        const bool paused = m_devSound->pause();
+        if (paused) {
+            if (m_devSoundBuffer)
+                m_devSoundBufferQ.append(m_devSoundBuffer);
             m_devSoundBuffer = 0;
+            setState(SymbianAudio::SuspendedPausedState);
+        } else {
+            m_devSoundBuffer = 0;
+            m_devSoundBufferQ.clear();
+            m_devSoundBufferPos = 0;
+            setState(SymbianAudio::SuspendedStoppedState);
         }
-
-        setState(SymbianAudio::SuspendedState);
     }
 }
@@ -190,6 +195,8 @@
 void QAudioInputPrivate::resume()
 {
-    if (SymbianAudio::SuspendedState == m_internalState) {
-        if (!m_pullMode && !bytesReady())
+    if (QAudio::SuspendedState == m_externalState) {
+        if (SymbianAudio::SuspendedPausedState == m_internalState)
+            m_devSound->resume();
+        else
             m_devSound->start();
         startDataTransfer();
@@ -247,5 +254,5 @@
 {
     int samplesPlayed = 0;
-    if (m_devSound && SymbianAudio::SuspendedState != m_internalState)
+    if (m_devSound && QAudio::SuspendedState != m_externalState)
         samplesPlayed = getSamplesRecorded();
 
@@ -336,5 +343,5 @@
             pushData();
     } else {
-        if (SymbianAudio::SuspendedState == m_internalState)
+        if (QAudio::SuspendedState == m_externalState)
             setState(SymbianAudio::ActiveState);
         else
@@ -374,5 +381,6 @@
         TDesC8 &inputBuffer = buffer->Data();
 
-        const qint64 inputBytes = bytesReady();
+        Q_ASSERT(inputBuffer.Length() >= m_devSoundBufferPos);
+        const qint64 inputBytes = inputBuffer.Length() - m_devSoundBufferPos;
         const qint64 outputBytes = len - bytesRead;
         const qint64 copyBytes = outputBytes < inputBytes ?
@@ -385,5 +393,5 @@
         bytesRead += copyBytes;
 
-        if (!bytesReady())
+        if (inputBytes == copyBytes)
             bufferEmptied();
     }
@@ -404,5 +412,6 @@
         TDesC8 &inputBuffer = buffer->Data();
 
-        const qint64 inputBytes = bytesReady();
+        Q_ASSERT(inputBuffer.Length() >= m_devSoundBufferPos);
+        const qint64 inputBytes = inputBuffer.Length() - m_devSoundBufferPos;
         const qint64 bytesPushed = m_sink->write(
             (char*)inputBuffer.Ptr() + m_devSoundBufferPos, inputBytes);
@@ -410,5 +419,5 @@
         m_devSoundBufferPos += bytesPushed;
 
-        if (!bytesReady())
+        if (inputBytes == bytesPushed)
             bufferEmptied();
 
@@ -442,5 +451,5 @@
     m_totalBytesReady += buffer->Data().Length();
 
-    if (SymbianAudio::SuspendedState == m_internalState) {
+    if (SymbianAudio::SuspendedPausedState == m_internalState) {
         m_devSoundBufferQ.append(buffer);
     } else {
Index: trunk/src/multimedia/audio/qaudioinput_symbian_p.h
===================================================================
--- trunk/src/multimedia/audio/qaudioinput_symbian_p.h	(revision 769)
+++ trunk/src/multimedia/audio/qaudioinput_symbian_p.h	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
Index: trunk/src/multimedia/audio/qaudioinput_win32_p.cpp
===================================================================
--- trunk/src/multimedia/audio/qaudioinput_win32_p.cpp	(revision 769)
+++ trunk/src/multimedia/audio/qaudioinput_win32_p.cpp	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
@@ -80,5 +80,5 @@
 }
 
-void CALLBACK QAudioInputPrivate::waveInProc( HWAVEIN hWaveIn, UINT uMsg,
+void QT_WIN_CALLBACK QAudioInputPrivate::waveInProc( HWAVEIN hWaveIn, UINT uMsg,
         DWORD dwInstance, DWORD dwParam1, DWORD dwParam2 )
 {
@@ -149,5 +149,5 @@
     for(int i = 0; i < count; i++) {
         waveInUnprepareHeader(hWaveIn,blocks, sizeof(WAVEHDR));
-        blocks+=sizeof(WAVEHDR);
+        blocks++;
     }
     HeapFree(GetProcessHeap(), 0, blockArray);
@@ -215,11 +215,42 @@
 #endif
     header = 0;
-    if(buffer_size == 0) {
-        // Default buffer size, 200ms, default period size is 40ms
-        buffer_size = settings.frequency()*settings.channels()*(settings.sampleSize()/8)*0.2;
-	period_size = buffer_size/5;
+    period_size = 0;
+
+    if (!settings.isValid()) {
+        qWarning("QAudioInput: open error, invalid format.");
+    } else if (settings.channels() <= 0) {
+        qWarning("QAudioInput: open error, invalid number of channels (%d).",
+                 settings.channels());
+    } else if (settings.sampleSize() <= 0) {
+        qWarning("QAudioInput: open error, invalid sample size (%d).",
+                 settings.sampleSize());
+    } else if (settings.frequency() < 8000 || settings.frequency() > 48000) {
+        qWarning("QAudioInput: open error, frequency out of range (%d).", settings.frequency());
+    } else if (buffer_size == 0) {
+
+        buffer_size
+                = (settings.frequency()
+                * settings.channels()
+                * settings.sampleSize()
+#ifndef Q_OS_WINCE  // Default buffer size, 200ms, default period size is 40ms
+                + 39) / 40;
+        period_size = buffer_size / 5;
     } else {
-        period_size = buffer_size/5;
-    }
+        period_size = buffer_size / 5;
+#else               // For wince reduce size to 40ms for buffer size and 20ms period
+                + 199) / 200;
+        period_size = buffer_size / 2;
+    } else {
+        period_size = buffer_size / 2;
+#endif
+    }
+
+    if (period_size == 0) {
+        errorState = QAudio::OpenError;
+        deviceState = QAudio::StoppedState;
+        emit stateChanged(deviceState);
+        return false;
+    }
+
     timeStamp.restart();
     elapsedTimeOffset = 0;
@@ -242,5 +273,5 @@
 	    == MMSYSERR_NOERROR) {
 	    QString tmp;
-	    tmp = QString::fromUtf16((const unsigned short*)wic.szPname);
+	    tmp = QString((const QChar *)wic.szPname);
 	    if(tmp.compare(QLatin1String(m_device)) == 0) {
 	        devId = ii;
@@ -370,7 +401,10 @@
                 }
             } else {
+                l = qMin<qint64>(len, waveBlocks[header].dwBytesRecorded);
                 // push mode
-                memcpy(p,waveBlocks[header].lpData,waveBlocks[header].dwBytesRecorded);
-                l = waveBlocks[header].dwBytesRecorded;
+                memcpy(p, waveBlocks[header].lpData, l);
+
+                len -= l;
+
 #ifdef DEBUG_AUDIO
                 qDebug()<<"IN: "<<waveBlocks[header].dwBytesRecorded<<", OUT: "<<l;
@@ -427,5 +461,5 @@
         mutex.lock();
         if(!pullMode) {
-	    if(l+period_size > len && waveFreeBlockCount == buffer_size/period_size)
+            if(len < period_size || waveFreeBlockCount == buffer_size/period_size)
 	        done = true;
 	} else {
@@ -538,5 +572,5 @@
     if(pullMode) {
         // reads some audio data and writes it to QIODevice
-        read(0,0);
+        read(0, buffer_size);
     } else {
         // emits readyRead() so user will call read() on QIODevice to get some audio data
Index: trunk/src/multimedia/audio/qaudioinput_win32_p.h
===================================================================
--- trunk/src/multimedia/audio/qaudioinput_win32_p.h	(revision 769)
+++ trunk/src/multimedia/audio/qaudioinput_win32_p.h	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
@@ -125,6 +125,5 @@
 
     QMutex mutex;
-
-    static void CALLBACK waveInProc( HWAVEIN hWaveIn, UINT uMsg,
+    static void QT_WIN_CALLBACK waveInProc( HWAVEIN hWaveIn, UINT uMsg,
             DWORD dwInstance, DWORD dwParam1, DWORD dwParam2 );
 
Index: trunk/src/multimedia/audio/qaudiooutput.cpp
===================================================================
--- trunk/src/multimedia/audio/qaudiooutput.cpp	(revision 769)
+++ trunk/src/multimedia/audio/qaudiooutput.cpp	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
@@ -200,5 +200,5 @@
 /*!
     Uses the \a device as the QIODevice to transfer data.
-    Passing a QIODevice allows the data to be transfered without any extra code.
+    Passing a QIODevice allows the data to be transferred without any extra code.
     All that is required is to open the QIODevice.
 
Index: trunk/src/multimedia/audio/qaudiooutput.h
===================================================================
--- trunk/src/multimedia/audio/qaudiooutput.h	(revision 769)
+++ trunk/src/multimedia/audio/qaudiooutput.h	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
Index: trunk/src/multimedia/audio/qaudiooutput_alsa_p.cpp
===================================================================
--- trunk/src/multimedia/audio/qaudiooutput_alsa_p.cpp	(revision 769)
+++ trunk/src/multimedia/audio/qaudiooutput_alsa_p.cpp	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
@@ -156,5 +156,5 @@
 int QAudioOutputPrivate::setFormat()
 {
-    snd_pcm_format_t pcmformat = SND_PCM_FORMAT_S16;
+    snd_pcm_format_t pcmformat = SND_PCM_FORMAT_UNKNOWN;
 
     if(settings.sampleSize() == 8) {
@@ -209,5 +209,7 @@
     }
 
-    return snd_pcm_hw_params_set_format( handle, hwparams, pcmformat);
+    return pcmformat != SND_PCM_FORMAT_UNKNOWN
+            ? snd_pcm_hw_params_set_format( handle, hwparams, pcmformat)
+            : -1;
 }
 
@@ -276,7 +278,22 @@
 
     int dir;
-    int err=-1;
+    int err = 0;
     int count=0;
     unsigned int freakuency=settings.frequency();
+
+    if (!settings.isValid()) {
+        qWarning("QAudioOutput: open error, invalid format.");
+    } else if (settings.frequency() <= 0) {
+        qWarning("QAudioOutput: open error, invalid sample rate (%d).",
+                 settings.frequency());
+    } else {
+        err = -1;
+    }
+
+    if (err == 0) {
+        errorState = QAudio::OpenError;
+        deviceState = QAudio::StoppedState;
+        return false;
+    }
 
     QString dev = QString(QLatin1String(m_device.constData()));
Index: trunk/src/multimedia/audio/qaudiooutput_alsa_p.h
===================================================================
--- trunk/src/multimedia/audio/qaudiooutput_alsa_p.h	(revision 769)
+++ trunk/src/multimedia/audio/qaudiooutput_alsa_p.h	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
@@ -61,4 +61,5 @@
 #include <QtCore/qstring.h>
 #include <QtCore/qstringlist.h>
+#include <QtCore/qelapsedtimer.h>
 #include <QtCore/qdatetime.h>
 
@@ -134,6 +135,6 @@
     QByteArray m_device;
     int bytesAvailable;
-    QTime timeStamp;
-    QTime clockStamp;
+    QElapsedTimer timeStamp;
+    QElapsedTimer clockStamp;
     qint64 elapsedTimeOffset;
     char* audioBuffer;
Index: trunk/src/multimedia/audio/qaudiooutput_mac_p.cpp
===================================================================
--- trunk/src/multimedia/audio/qaudiooutput_mac_p.cpp	(revision 769)
+++ trunk/src/multimedia/audio/qaudiooutput_mac_p.cpp	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
@@ -61,9 +61,9 @@
 #include <QtCore/qdebug.h>
 
-#include <QtMultimedia/qaudiodeviceinfo.h>
 #include <QtMultimedia/qaudiooutput.h>
 
 #include "qaudio_mac_p.h"
 #include "qaudiooutput_mac_p.h"
+#include "qaudiodeviceinfo_mac_p.h"
 
 
@@ -279,4 +279,5 @@
         errorCode = QAudio::OpenError;
     else {
+        audioDeviceInfo = new QAudioDeviceInfoInternal(device, QAudio::AudioOutput);
         isOpen = false;
         audioDeviceId = AudioDeviceID(did);
@@ -300,4 +301,5 @@
 QAudioOutputPrivate::~QAudioOutputPrivate()
 {
+    delete audioDeviceInfo;
     close();
 }
@@ -359,15 +361,5 @@
     streamFormat = toAudioStreamBasicDescription(audioFormat);
 
-    UInt32 size = sizeof(deviceFormat);
-    if (AudioUnitGetProperty(audioUnit,
-                                kAudioUnitProperty_StreamFormat,
-                                kAudioUnitScope_Input,
-                                0,
-                                &deviceFormat,
-                                &size) != noErr) {
-        qWarning() << "QAudioOutput: Unable to retrieve device format";
-        return false;
-    }
-
+    UInt32 size = sizeof(streamFormat);
     if (AudioUnitSetProperty(audioUnit,
                                 kAudioUnitProperty_StreamFormat,
@@ -393,6 +385,5 @@
     }
 
-    periodSizeBytes = (numberOfFrames * streamFormat.mSampleRate / deviceFormat.mSampleRate) * 
-                        streamFormat.mBytesPerFrame;
+    periodSizeBytes = numberOfFrames * streamFormat.mBytesPerFrame;
     if (internalBufferSize < periodSizeBytes * 2)
         internalBufferSize = periodSizeBytes * 2;
@@ -436,5 +427,5 @@
     QIODevice*  op = device;
 
-    if (!audioFormat.isValid() || !open()) {
+    if (!audioDeviceInfo->isFormatSupported(audioFormat) || !open()) {
         stateCode = QAudio::StoppedState;
         errorCode = QAudio::OpenError;
Index: trunk/src/multimedia/audio/qaudiooutput_mac_p.h
===================================================================
--- trunk/src/multimedia/audio/qaudiooutput_mac_p.h	(revision 769)
+++ trunk/src/multimedia/audio/qaudiooutput_mac_p.h	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
@@ -74,4 +74,5 @@
 
 class QIODevice;
+class QAbstractAudioDeviceInfo;
 
 namespace QtMultimediaInternal
@@ -102,4 +103,5 @@
     QMutex          mutex;
     QTimer*         intervalTimer;
+    QAbstractAudioDeviceInfo *audioDeviceInfo;
 
     QAudio::Error    errorCode;
Index: trunk/src/multimedia/audio/qaudiooutput_symbian_p.cpp
===================================================================
--- trunk/src/multimedia/audio/qaudiooutput_symbian_p.cpp	(revision 769)
+++ trunk/src/multimedia/audio/qaudiooutput_symbian_p.cpp	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
@@ -181,28 +181,21 @@
         m_notifyTimer->stop();
         m_underflowTimer->stop();
-
         const qint64 samplesWritten = SymbianAudio::Utils::bytesToSamples(
                                           m_format, m_bytesWritten);
-
         const qint64 samplesPlayed = getSamplesPlayed();
-
+        m_totalSamplesPlayed += samplesPlayed;
         m_bytesWritten = 0;
-
-        // CMMFDevSound::Pause() is not guaranteed to work correctly in all
-        // implementations, for play-mode DevSound sessions.  We therefore
-        // have to implement suspend() by calling CMMFDevSound::Stop().
-        // Because this causes buffered data to be dropped, we replace the
-        // lost data with silence following a call to resume(), in order to
-        // ensure that processedUSecs() returns the correct value.
-        m_devSound->stop();
-        m_totalSamplesPlayed += samplesPlayed;
-
-        // Calculate the amount of data dropped
-        const qint64 paddingSamples = samplesWritten - samplesPlayed;
-        Q_ASSERT(paddingSamples >= 0);
-        m_bytesPadding = SymbianAudio::Utils::samplesToBytes(m_format,
-                                                             paddingSamples);
-
-        setState(SymbianAudio::SuspendedState);
+        const bool paused = m_devSound->pause();
+        if (paused) {
+            setState(SymbianAudio::SuspendedPausedState);
+        } else {
+            m_devSoundBuffer = 0;
+            // Calculate the amount of data dropped
+            const qint64 paddingSamples = samplesWritten - samplesPlayed;
+            Q_ASSERT(paddingSamples >= 0);
+            m_bytesPadding = SymbianAudio::Utils::samplesToBytes(m_format,
+                                                                 paddingSamples);
+            setState(SymbianAudio::SuspendedStoppedState);
+        }
     }
 }
@@ -210,8 +203,9 @@
 void QAudioOutputPrivate::resume()
 {
-    if (SymbianAudio::SuspendedState == m_internalState) {
-        if (!m_pullMode && m_devSoundBuffer && m_devSoundBuffer->Data().Length())
-            bufferFilled();
-        startPlayback();
+    if (QAudio::SuspendedState == m_externalState) {
+        if (SymbianAudio::SuspendedPausedState == m_internalState)
+            m_devSound->resume();
+        else
+            startPlayback();
     }
 }
@@ -271,5 +265,5 @@
 {
     int samplesPlayed = 0;
-    if (m_devSound && SymbianAudio::SuspendedState != m_internalState)
+    if (m_devSound && QAudio::SuspendedState != m_externalState)
         samplesPlayed = getSamplesPlayed();
 
@@ -371,4 +365,7 @@
         else
             setState(SymbianAudio::IdleState);
+        break;
+    case KErrOverflow:
+        // Silently consume this error when in playback mode
         break;
     default:
Index: trunk/src/multimedia/audio/qaudiooutput_symbian_p.h
===================================================================
--- trunk/src/multimedia/audio/qaudiooutput_symbian_p.h	(revision 769)
+++ trunk/src/multimedia/audio/qaudiooutput_symbian_p.h	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
Index: trunk/src/multimedia/audio/qaudiooutput_win32_p.cpp
===================================================================
--- trunk/src/multimedia/audio/qaudiooutput_win32_p.cpp	(revision 769)
+++ trunk/src/multimedia/audio/qaudiooutput_win32_p.cpp	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
@@ -53,4 +53,51 @@
 #include "qaudiooutput_win32_p.h"
 
+#ifndef SPEAKER_FRONT_LEFT
+    #define SPEAKER_FRONT_LEFT            0x00000001
+    #define SPEAKER_FRONT_RIGHT           0x00000002
+    #define SPEAKER_FRONT_CENTER          0x00000004
+    #define SPEAKER_LOW_FREQUENCY         0x00000008
+    #define SPEAKER_BACK_LEFT             0x00000010
+    #define SPEAKER_BACK_RIGHT            0x00000020
+    #define SPEAKER_FRONT_LEFT_OF_CENTER  0x00000040
+    #define SPEAKER_FRONT_RIGHT_OF_CENTER 0x00000080
+    #define SPEAKER_BACK_CENTER           0x00000100
+    #define SPEAKER_SIDE_LEFT             0x00000200
+    #define SPEAKER_SIDE_RIGHT            0x00000400
+    #define SPEAKER_TOP_CENTER            0x00000800
+    #define SPEAKER_TOP_FRONT_LEFT        0x00001000
+    #define SPEAKER_TOP_FRONT_CENTER      0x00002000
+    #define SPEAKER_TOP_FRONT_RIGHT       0x00004000
+    #define SPEAKER_TOP_BACK_LEFT         0x00008000
+    #define SPEAKER_TOP_BACK_CENTER       0x00010000
+    #define SPEAKER_TOP_BACK_RIGHT        0x00020000
+    #define SPEAKER_RESERVED              0x7FFC0000
+    #define SPEAKER_ALL                   0x80000000
+#endif
+
+#ifndef _WAVEFORMATEXTENSIBLE_
+
+    #define _WAVEFORMATEXTENSIBLE_
+    typedef struct
+    {
+        WAVEFORMATEX Format;          // Base WAVEFORMATEX data
+        union
+        {
+            WORD wValidBitsPerSample; // Valid bits in each sample container
+            WORD wSamplesPerBlock;    // Samples per block of audio data; valid
+                                      // if wBitsPerSample=0 (but rarely used).
+            WORD wReserved;           // Zero if neither case above applies.
+        } Samples;
+        DWORD dwChannelMask;          // Positions of the audio channels
+        GUID SubFormat;               // Format identifier GUID
+    } WAVEFORMATEXTENSIBLE, *PWAVEFORMATEXTENSIBLE, *LPPWAVEFORMATEXTENSIBLE;
+    typedef const WAVEFORMATEXTENSIBLE* LPCWAVEFORMATEXTENSIBLE;
+
+#endif
+
+#if !defined(WAVE_FORMAT_EXTENSIBLE)
+#define WAVE_FORMAT_EXTENSIBLE 0xFFFE
+#endif
+
 //#define DEBUG_AUDIO 1
 
@@ -147,5 +194,5 @@
     for(int i = 0; i < count; i++) {
         waveOutUnprepareHeader(hWaveOut,blocks, sizeof(WAVEHDR));
-        blocks+=sizeof(WAVEHDR);
+        blocks++;
     }
     HeapFree(GetProcessHeap(), 0, blockArray);
@@ -205,18 +252,36 @@
     qDebug()<<now.second()<<"s "<<now.msec()<<"ms :open()";
 #endif
-    if (!(settings.frequency() >= 8000 && settings.frequency() <= 48000)) {
+
+    period_size = 0;
+
+    if (!settings.isValid()) {
+        qWarning("QAudioOutput: open error, invalid format.");
+    } else if (settings.channels() <= 0) {
+        qWarning("QAudioOutput: open error, invalid number of channels (%d).",
+                 settings.channels());
+    } else if (settings.sampleSize() <= 0) {
+        qWarning("QAudioOutput: open error, invalid sample size (%d).",
+                 settings.sampleSize());
+    } else if (settings.frequency() < 8000 || settings.frequency() > 48000) {
+        qWarning("QAudioOutput: open error, frequency out of range (%d).", settings.frequency());
+    } else if (buffer_size == 0) {
+        // Default buffer size, 200ms, default period size is 40ms
+        buffer_size
+                = (settings.frequency()
+                * settings.channels()
+                * settings.sampleSize()
+                + 39) / 40;
+        period_size = buffer_size / 5;
+    } else {
+        period_size = buffer_size / 5;
+    }
+
+    if (period_size == 0) {
         errorState = QAudio::OpenError;
         deviceState = QAudio::StoppedState;
         emit stateChanged(deviceState);
-        qWarning("QAudioOutput: open error, frequency out of range.");
         return false;
     }
-    if(buffer_size == 0) {
-        // Default buffer size, 200ms, default period size is 40ms
-        buffer_size = settings.frequency()*settings.channels()*(settings.sampleSize()/8)*0.2;
-	period_size = buffer_size/5;
-    } else {
-        period_size = buffer_size/5;
-    }
+
     waveBlocks = allocateBlocks(period_size, buffer_size/period_size);
 
@@ -251,5 +316,5 @@
 	    == MMSYSERR_NOERROR) {
 	    QString tmp;
-	    tmp = QString::fromUtf16((const unsigned short*)woc.szPname);
+	    tmp = QString((const QChar *)woc.szPname);
             if(tmp.compare(QLatin1String(m_device)) == 0) {
 	        devId = ii;
@@ -259,13 +324,47 @@
     }
 
-    if(waveOutOpen(&hWaveOut, devId, &wfx,
-                (DWORD_PTR)&waveOutProc,
-                (DWORD_PTR) this,
-                CALLBACK_FUNCTION) != MMSYSERR_NOERROR) {
-        errorState = QAudio::OpenError;
-        deviceState = QAudio::StoppedState;
-        emit stateChanged(deviceState);
-        qWarning("QAudioOutput: open error");
-        return false;
+    if ( settings.channels() <= 2) {
+        if(waveOutOpen(&hWaveOut, devId, &wfx,
+                    (DWORD_PTR)&waveOutProc,
+                    (DWORD_PTR) this,
+                    CALLBACK_FUNCTION) != MMSYSERR_NOERROR) {
+            errorState = QAudio::OpenError;
+            deviceState = QAudio::StoppedState;
+            emit stateChanged(deviceState);
+            qWarning("QAudioOutput: open error");
+            return false;
+        }
+    } else {
+        WAVEFORMATEXTENSIBLE wfex;
+        wfex.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
+        wfex.Format.nChannels = settings.channels();
+        wfex.Format.wBitsPerSample = settings.sampleSize();
+        wfex.Format.nSamplesPerSec = settings.frequency();
+        wfex.Format.nBlockAlign = wfex.Format.nChannels*wfex.Format.wBitsPerSample/8;
+        wfex.Format.nAvgBytesPerSec=wfex.Format.nSamplesPerSec*wfex.Format.nBlockAlign;
+        wfex.Samples.wValidBitsPerSample=wfex.Format.wBitsPerSample;
+        static const GUID _KSDATAFORMAT_SUBTYPE_PCM = {
+             0x00000001, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
+        wfex.SubFormat=_KSDATAFORMAT_SUBTYPE_PCM;
+        wfex.Format.cbSize=22;
+
+        wfex.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT;
+        if (settings.channels() >= 4)
+            wfex.dwChannelMask |= SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT;
+        if (settings.channels() >= 6)
+            wfex.dwChannelMask |= SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY;
+        if (settings.channels() == 8)
+            wfex.dwChannelMask |= SPEAKER_SIDE_LEFT | SPEAKER_SIDE_RIGHT;
+
+        if(waveOutOpen(&hWaveOut, devId, &wfex.Format,
+                    (DWORD_PTR)&waveOutProc,
+                    (DWORD_PTR) this,
+                    CALLBACK_FUNCTION) != MMSYSERR_NOERROR) {
+            errorState = QAudio::OpenError;
+            deviceState = QAudio::StoppedState;
+            emit stateChanged(deviceState);
+            qWarning("QAudioOutput: open error");
+            return false;
+        }
     }
 
@@ -488,5 +587,5 @@
             }
             if ( out < l) {
-                // Didnt write all data
+                // Didn't write all data
                 audioSource->seek(audioSource->pos()-(l-out));
             }
Index: trunk/src/multimedia/audio/qaudiooutput_win32_p.h
===================================================================
--- trunk/src/multimedia/audio/qaudiooutput_win32_p.h	(revision 769)
+++ trunk/src/multimedia/audio/qaudiooutput_win32_p.h	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
@@ -118,5 +118,5 @@
     bool pullMode;
     int intervalTime;
-    static void CALLBACK waveOutProc( HWAVEOUT hWaveOut, UINT uMsg,
+    static void QT_WIN_CALLBACK waveOutProc( HWAVEOUT hWaveOut, UINT uMsg,
             DWORD dwInstance, DWORD dwParam1, DWORD dwParam2 );
 
Index: trunk/src/multimedia/multimedia.pro
===================================================================
--- trunk/src/multimedia/multimedia.pro	(revision 769)
+++ trunk/src/multimedia/multimedia.pro	(revision 846)
@@ -12,3 +12,5 @@
 include(video/video.pri)
 
-symbian: TARGET.UID3 = 0x2001E627
+symbian: {
+    TARGET.UID3 = 0x2001E627
+}
Index: trunk/src/multimedia/video/qabstractvideobuffer.cpp
===================================================================
--- trunk/src/multimedia/video/qabstractvideobuffer.cpp	(revision 769)
+++ trunk/src/multimedia/video/qabstractvideobuffer.cpp	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
@@ -72,4 +72,7 @@
     \value NoHandle The buffer has no handle, its data can only be accessed by mapping the buffer.
     \value GLTextureHandle The handle of the buffer is an OpenGL texture ID.
+    \value XvShmImageHandle The handle contains pointer to shared memory XVideo image.
+    \value CoreImageHandle The handle contains pointer to Mac OS X CIImage.
+    \value QPixmapHandle The handle of the buffer is a QPixmap.
     \value UserHandle Start value for user defined handle types.
 
@@ -85,5 +88,5 @@
     \value ReadOnly The mapped memory is populated with data from the video buffer when mapped, but
     the content of the mapped memory may be discarded when unmapped.
-    \value WriteOnly The mapped memory in unitialized when mapped, and the content will be used to
+    \value WriteOnly The mapped memory is uninitialized when mapped, and the content will be used to
     populate the video buffer when unmapped.
     \value ReadWrite The mapped memory is populated with data from the video buffer, and the
Index: trunk/src/multimedia/video/qabstractvideobuffer.h
===================================================================
--- trunk/src/multimedia/video/qabstractvideobuffer.h	(revision 769)
+++ trunk/src/multimedia/video/qabstractvideobuffer.h	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
@@ -62,4 +62,7 @@
         NoHandle,
         GLTextureHandle,
+        XvShmImageHandle,
+        CoreImageHandle,
+        QPixmapHandle,
         UserHandle = 1000
     };
Index: trunk/src/multimedia/video/qabstractvideobuffer_p.h
===================================================================
--- trunk/src/multimedia/video/qabstractvideobuffer_p.h	(revision 769)
+++ trunk/src/multimedia/video/qabstractvideobuffer_p.h	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
@@ -66,4 +66,7 @@
     {}
 
+    virtual ~QAbstractVideoBufferPrivate()
+    {}
+
     QAbstractVideoBuffer::HandleType handleType;
 };
Index: trunk/src/multimedia/video/qabstractvideosurface.cpp
===================================================================
--- trunk/src/multimedia/video/qabstractvideosurface.cpp	(revision 769)
+++ trunk/src/multimedia/video/qabstractvideosurface.cpp	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
Index: trunk/src/multimedia/video/qabstractvideosurface.h
===================================================================
--- trunk/src/multimedia/video/qabstractvideosurface.h	(revision 769)
+++ trunk/src/multimedia/video/qabstractvideosurface.h	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
Index: trunk/src/multimedia/video/qabstractvideosurface_p.h
===================================================================
--- trunk/src/multimedia/video/qabstractvideosurface_p.h	(revision 769)
+++ trunk/src/multimedia/video/qabstractvideosurface_p.h	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
Index: trunk/src/multimedia/video/qimagevideobuffer.cpp
===================================================================
--- trunk/src/multimedia/video/qimagevideobuffer.cpp	(revision 769)
+++ trunk/src/multimedia/video/qimagevideobuffer.cpp	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
Index: trunk/src/multimedia/video/qimagevideobuffer_p.h
===================================================================
--- trunk/src/multimedia/video/qimagevideobuffer_p.h	(revision 769)
+++ trunk/src/multimedia/video/qimagevideobuffer_p.h	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
Index: trunk/src/multimedia/video/qmemoryvideobuffer.cpp
===================================================================
--- trunk/src/multimedia/video/qmemoryvideobuffer.cpp	(revision 769)
+++ trunk/src/multimedia/video/qmemoryvideobuffer.cpp	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
Index: trunk/src/multimedia/video/qmemoryvideobuffer_p.h
===================================================================
--- trunk/src/multimedia/video/qmemoryvideobuffer_p.h	(revision 769)
+++ trunk/src/multimedia/video/qmemoryvideobuffer_p.h	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
Index: trunk/src/multimedia/video/qvideoframe.cpp
===================================================================
--- trunk/src/multimedia/video/qvideoframe.cpp	(revision 769)
+++ trunk/src/multimedia/video/qvideoframe.cpp	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
@@ -666,4 +666,5 @@
         return Format_RGB565;
     case QImage::Format_ARGB8565_Premultiplied:
+        return Format_ARGB8565_Premultiplied;
     case QImage::Format_RGB666:
     case QImage::Format_ARGB6666_Premultiplied:
Index: trunk/src/multimedia/video/qvideoframe.h
===================================================================
--- trunk/src/multimedia/video/qvideoframe.h	(revision 769)
+++ trunk/src/multimedia/video/qvideoframe.h	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
Index: trunk/src/multimedia/video/qvideosurfaceformat.cpp
===================================================================
--- trunk/src/multimedia/video/qvideosurfaceformat.cpp	(revision 769)
+++ trunk/src/multimedia/video/qvideosurfaceformat.cpp	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
@@ -253,5 +253,5 @@
 bool QVideoSurfaceFormat::isValid() const
 {
-    return d->pixelFormat == QVideoFrame::Format_Invalid && d->frameSize.isValid();
+    return d->pixelFormat != QVideoFrame::Format_Invalid && d->frameSize.isValid();
 }
 
Index: trunk/src/multimedia/video/qvideosurfaceformat.h
===================================================================
--- trunk/src/multimedia/video/qvideosurfaceformat.h	(revision 769)
+++ trunk/src/multimedia/video/qvideosurfaceformat.h	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
