Merge "PAL: add additional CKVs for devicePP"
diff --git a/configs/parrot/resourcemanager_ravelin_idp.xml b/configs/parrot/resourcemanager_ravelin_idp.xml
index 82be902..2d46588 100644
--- a/configs/parrot/resourcemanager_ravelin_idp.xml
+++ b/configs/parrot/resourcemanager_ravelin_idp.xml
@@ -916,9 +916,6 @@
                 <custom-config key="32K">
                     <samplerate>32000</samplerate>
                 </custom-config>
-                <custom-config key="44.1K">
-                    <samplerate>44100</samplerate>
-                </custom-config>
                 <custom-config key="48K">
                     <samplerate>48000</samplerate>
                 </custom-config>
@@ -929,9 +926,18 @@
                 <custom-config key="8K">
                     <samplerate>8000</samplerate>
                 </custom-config>
+                <custom-config key="11K">
+                    <samplerate>11025</samplerate>
+                </custom-config>
                 <custom-config key="16K">
                     <samplerate>16000</samplerate>
                 </custom-config>
+                <custom-config key="22K">
+                    <samplerate>22050</samplerate>
+                </custom-config>
+                <custom-config key="24K">
+                    <samplerate>24000</samplerate>
+                </custom-config>
                 <custom-config key="32K">
                     <samplerate>32000</samplerate>
                 </custom-config>
@@ -941,6 +947,27 @@
                 <custom-config key="48K">
                     <samplerate>48000</samplerate>
                 </custom-config>
+                <custom-config key="64K">
+                    <samplerate>64000</samplerate>
+                </custom-config>
+                <custom-config key="88.2K">
+                    <samplerate>88200</samplerate>
+                </custom-config>
+                <custom-config key="96K">
+                    <samplerate>96000</samplerate>
+                </custom-config>
+                <custom-config key="176.4K">
+                    <samplerate>176400</samplerate>
+                </custom-config>
+                <custom-config key="192K">
+                    <samplerate>192000</samplerate>
+                </custom-config>
+                <custom-config key="352.8K">
+                    <samplerate>352800</samplerate>
+                </custom-config>
+                <custom-config key="384K">
+                    <samplerate>384000</samplerate>
+                </custom-config>
             </usecase>
             <usecase>
                 <name>PAL_STREAM_PCM_OFFLOAD</name>
@@ -948,9 +975,18 @@
                 <custom-config key="8K">
                     <samplerate>8000</samplerate>
                 </custom-config>
+                <custom-config key="11K">
+                    <samplerate>11025</samplerate>
+                </custom-config>
                 <custom-config key="16K">
                     <samplerate>16000</samplerate>
                 </custom-config>
+                <custom-config key="22K">
+                    <samplerate>22050</samplerate>
+                </custom-config>
+                <custom-config key="24K">
+                    <samplerate>24000</samplerate>
+                </custom-config>
                 <custom-config key="32K">
                     <samplerate>32000</samplerate>
                 </custom-config>
@@ -960,6 +996,27 @@
                 <custom-config key="48K">
                     <samplerate>48000</samplerate>
                 </custom-config>
+                <custom-config key="64K">
+                    <samplerate>64000</samplerate>
+                </custom-config>
+                <custom-config key="88.2K">
+                    <samplerate>88200</samplerate>
+                </custom-config>
+                <custom-config key="96K">
+                    <samplerate>96000</samplerate>
+                </custom-config>
+                <custom-config key="176.4K">
+                    <samplerate>176400</samplerate>
+                </custom-config>
+                <custom-config key="192K">
+                    <samplerate>192000</samplerate>
+                </custom-config>
+                <custom-config key="352.8K">
+                    <samplerate>352800</samplerate>
+                </custom-config>
+                <custom-config key="384K">
+                    <samplerate>384000</samplerate>
+                </custom-config>
             </usecase>
             <usecase>
                 <name>PAL_STREAM_COMPRESSED</name>
@@ -967,9 +1024,18 @@
                 <custom-config key="8K">
                     <samplerate>8000</samplerate>
                 </custom-config>
+                <custom-config key="11K">
+                    <samplerate>11025</samplerate>
+                </custom-config>
                 <custom-config key="16K">
                     <samplerate>16000</samplerate>
                 </custom-config>
+                <custom-config key="22K">
+                    <samplerate>22050</samplerate>
+                </custom-config>
+                <custom-config key="24K">
+                    <samplerate>24000</samplerate>
+                </custom-config>
                 <custom-config key="32K">
                     <samplerate>32000</samplerate>
                 </custom-config>
@@ -979,6 +1045,27 @@
                 <custom-config key="48K">
                     <samplerate>48000</samplerate>
                 </custom-config>
+                <custom-config key="64K">
+                    <samplerate>64000</samplerate>
+                </custom-config>
+                <custom-config key="88.2K">
+                    <samplerate>88200</samplerate>
+                </custom-config>
+                <custom-config key="96K">
+                    <samplerate>96000</samplerate>
+                </custom-config>
+                <custom-config key="176.4K">
+                    <samplerate>176400</samplerate>
+                </custom-config>
+                <custom-config key="192K">
+                    <samplerate>192000</samplerate>
+                </custom-config>
+                <custom-config key="352.8K">
+                    <samplerate>352800</samplerate>
+                </custom-config>
+                <custom-config key="384K">
+                    <samplerate>384000</samplerate>
+                </custom-config>
             </usecase>
         </out-device>
         <out-device>
@@ -1004,9 +1091,6 @@
                 <custom-config key="32K">
                     <samplerate>32000</samplerate>
                 </custom-config>
-                <custom-config key="44.1K">
-                    <samplerate>44100</samplerate>
-                </custom-config>
                 <custom-config key="48K">
                     <samplerate>48000</samplerate>
                 </custom-config>
@@ -1017,9 +1101,18 @@
                 <custom-config key="8K">
                     <samplerate>8000</samplerate>
                 </custom-config>
+                <custom-config key="11K">
+                    <samplerate>11025</samplerate>
+                </custom-config>
                 <custom-config key="16K">
                     <samplerate>16000</samplerate>
                 </custom-config>
+                <custom-config key="22K">
+                    <samplerate>22050</samplerate>
+                </custom-config>
+                <custom-config key="24K">
+                    <samplerate>24000</samplerate>
+                </custom-config>
                 <custom-config key="32K">
                     <samplerate>32000</samplerate>
                 </custom-config>
@@ -1029,6 +1122,27 @@
                 <custom-config key="48K">
                     <samplerate>48000</samplerate>
                 </custom-config>
+                <custom-config key="64K">
+                    <samplerate>64000</samplerate>
+                </custom-config>
+                <custom-config key="88.2K">
+                    <samplerate>88200</samplerate>
+                </custom-config>
+                <custom-config key="96K">
+                    <samplerate>96000</samplerate>
+                </custom-config>
+                <custom-config key="176.4K">
+                    <samplerate>176400</samplerate>
+                </custom-config>
+                <custom-config key="192K">
+                    <samplerate>192000</samplerate>
+                </custom-config>
+                <custom-config key="352.8K">
+                    <samplerate>352800</samplerate>
+                </custom-config>
+                <custom-config key="384K">
+                    <samplerate>384000</samplerate>
+                </custom-config>
             </usecase>
             <usecase>
                 <name>PAL_STREAM_PCM_OFFLOAD</name>
@@ -1036,9 +1150,18 @@
                 <custom-config key="8K">
                     <samplerate>8000</samplerate>
                 </custom-config>
+                <custom-config key="11K">
+                    <samplerate>11025</samplerate>
+                </custom-config>
                 <custom-config key="16K">
                     <samplerate>16000</samplerate>
                 </custom-config>
+                <custom-config key="22K">
+                    <samplerate>22050</samplerate>
+                </custom-config>
+                <custom-config key="24K">
+                    <samplerate>24000</samplerate>
+                </custom-config>
                 <custom-config key="32K">
                     <samplerate>32000</samplerate>
                 </custom-config>
@@ -1048,6 +1171,27 @@
                 <custom-config key="48K">
                     <samplerate>48000</samplerate>
                 </custom-config>
+                <custom-config key="64K">
+                    <samplerate>64000</samplerate>
+                </custom-config>
+                <custom-config key="88.2K">
+                    <samplerate>88200</samplerate>
+                </custom-config>
+                <custom-config key="96K">
+                    <samplerate>96000</samplerate>
+                </custom-config>
+                <custom-config key="176.4K">
+                    <samplerate>176400</samplerate>
+                </custom-config>
+                <custom-config key="192K">
+                    <samplerate>192000</samplerate>
+                </custom-config>
+                <custom-config key="352.8K">
+                    <samplerate>352800</samplerate>
+                </custom-config>
+                <custom-config key="384K">
+                    <samplerate>384000</samplerate>
+                </custom-config>
             </usecase>
             <usecase>
                 <name>PAL_STREAM_COMPRESSED</name>
@@ -1055,9 +1199,18 @@
                 <custom-config key="8K">
                     <samplerate>8000</samplerate>
                 </custom-config>
+                <custom-config key="11K">
+                    <samplerate>11025</samplerate>
+                </custom-config>
                 <custom-config key="16K">
                     <samplerate>16000</samplerate>
                 </custom-config>
+                <custom-config key="22K">
+                    <samplerate>22050</samplerate>
+                </custom-config>
+                <custom-config key="24K">
+                    <samplerate>24000</samplerate>
+                </custom-config>
                 <custom-config key="32K">
                     <samplerate>32000</samplerate>
                 </custom-config>
@@ -1067,6 +1220,27 @@
                 <custom-config key="48K">
                     <samplerate>48000</samplerate>
                 </custom-config>
+                <custom-config key="64K">
+                    <samplerate>64000</samplerate>
+                </custom-config>
+                <custom-config key="88.2K">
+                    <samplerate>88200</samplerate>
+                </custom-config>
+                <custom-config key="96K">
+                    <samplerate>96000</samplerate>
+                </custom-config>
+                <custom-config key="176.4K">
+                    <samplerate>176400</samplerate>
+                </custom-config>
+                <custom-config key="192K">
+                    <samplerate>192000</samplerate>
+                </custom-config>
+                <custom-config key="352.8K">
+                    <samplerate>352800</samplerate>
+                </custom-config>
+                <custom-config key="384K">
+                    <samplerate>384000</samplerate>
+                </custom-config>
             </usecase>
         </out-device>
         <out-device>
diff --git a/session/src/PayloadBuilder.cpp b/session/src/PayloadBuilder.cpp
index 3aca622..63b347e 100644
--- a/session/src/PayloadBuilder.cpp
+++ b/session/src/PayloadBuilder.cpp
@@ -182,6 +182,8 @@
 std::vector<allKVs> PayloadBuilder::all_devices;
 std::vector<allKVs> PayloadBuilder::all_devicepps;
 
+uint32_t getSamplerateKv(uint32_t samplerate);
+
 template <typename T>
 void PayloadBuilder::populateChannelMap(T pcmChannel, uint8_t numChannel)
 {
@@ -2929,6 +2931,61 @@
     return status;
 }
 
+uint32_t getSamplerateKv(uint32_t samplerate)
+{
+    uint32_t value = 0;
+
+    switch (samplerate)
+    {
+        case 8000:
+            value = SAMPLINGRATE_8K;
+        break;
+        case 11025:
+            value = SAMPLINGRATE_11K;
+        break;
+        case 16000:
+            value = SAMPLINGRATE_16K;
+        break;
+        case 22050:
+            value = SAMPLINGRATE_22K;
+        break;
+        case 32000:
+            value = SAMPLINGRATE_32K;
+        break;
+        case 44100:
+            value = SAMPLINGRATE_44K;
+        break;
+        case 48000:
+            value = SAMPLINGRATE_48K;
+        break;
+        case 64000:
+            value = SAMPLINGRATE_64K;
+        break;
+        case 88200:
+            value = SAMPLINGRATE_88K;
+        break;
+        case 96000:
+            value = SAMPLINGRATE_96K;
+        break;
+        case 176400:
+            value = SAMPLINGRATE_176K;
+        break;
+        case 192000:
+            value = SAMPLINGRATE_192K;
+        break;
+        case 352800:
+            value = SAMPLINGRATE_352K;
+        break;
+        case 384000:
+            value = SAMPLINGRATE_384K;
+        break;
+        default:
+            break;
+    }
+    return value;
+}
+
+
 int PayloadBuilder::populateDevicePPCkv(Stream *s, std::vector <std::pair<int,int>> &keyVector)
 {
     int status = 0;
@@ -2936,6 +2993,7 @@
     std::vector<std::shared_ptr<Device>> associatedDevices;
     struct pal_device dAttr;
     std::shared_ptr<ResourceManager> rm = ResourceManager::getInstance();
+    uint32_t sampleRateKv = 0;
 
     PAL_DBG(LOG_TAG,"Enter");
     sattr = new struct pal_stream_attributes;
@@ -3011,18 +3069,15 @@
                     (dAttr.id == PAL_DEVICE_OUT_HANDSET) ||
                     (dAttr.id == PAL_DEVICE_OUT_WIRED_HEADSET) ||
                     (dAttr.id == PAL_DEVICE_OUT_WIRED_HEADPHONE) ||
+                    (dAttr.id == PAL_DEVICE_OUT_USB_HEADSET) ||
+                    (dAttr.id == PAL_DEVICE_OUT_USB_DEVICE) ||
                     (dAttr.id == PAL_DEVICE_IN_SPEAKER_MIC) ||
                     (dAttr.id == PAL_DEVICE_IN_HANDSET_MIC) ||
-                    (dAttr.id == PAL_DEVICE_IN_WIRED_HEADSET)) {
-                    if (dAttr.config.sample_rate == 8000) {
-                        keyVector.push_back(std::make_pair(SAMPLINGRATE, SAMPLINGRATE_8K));
-                    } else if (dAttr.config.sample_rate == 16000) {
-                        keyVector.push_back(std::make_pair(SAMPLINGRATE, SAMPLINGRATE_16K));
-                    } else if (dAttr.config.sample_rate == 32000) {
-                        keyVector.push_back(std::make_pair(SAMPLINGRATE, SAMPLINGRATE_32K));
-                    } else if (dAttr.config.sample_rate == 48000) {
-                        keyVector.push_back(std::make_pair(SAMPLINGRATE, SAMPLINGRATE_48K));
-                    }
+                    (dAttr.id == PAL_DEVICE_IN_WIRED_HEADSET) ||
+                    (dAttr.id == PAL_DEVICE_IN_USB_HEADSET)) {
+                    if ((sampleRateKv = getSamplerateKv(dAttr.config.sample_rate)) != 0)
+                        keyVector.push_back(std::make_pair(SAMPLINGRATE, sampleRateKv));
+                    PAL_DBG(LOG_TAG,"stream type %d Sample Rate[%d]\n", sattr->type, dAttr.config.sample_rate);
                 }
 
                 /* TBD: Push Channels for these types once Channels are added */
@@ -3033,36 +3088,26 @@
                 if ((dAttr.id != PAL_DEVICE_OUT_SPEAKER) &&
                     (dAttr.id != PAL_DEVICE_OUT_HANDSET) &&
                     (dAttr.id != PAL_DEVICE_OUT_WIRED_HEADSET) &&
-                    (dAttr.id != PAL_DEVICE_OUT_WIRED_HEADPHONE))
+                    (dAttr.id != PAL_DEVICE_OUT_WIRED_HEADPHONE) &&
+                    (dAttr.id != PAL_DEVICE_OUT_USB_HEADSET) &&
+                    (dAttr.id != PAL_DEVICE_OUT_USB_DEVICE))
                     break;
 
                 PAL_DBG(LOG_TAG,"VoiP_RX Sample Rate[%d]\n", dAttr.config.sample_rate);
-                if (dAttr.config.sample_rate == 8000) {
-                    keyVector.push_back(std::make_pair(SAMPLINGRATE, SAMPLINGRATE_8K));
-                } else if (dAttr.config.sample_rate == 16000) {
-                    keyVector.push_back(std::make_pair(SAMPLINGRATE, SAMPLINGRATE_16K));
-                } else if (dAttr.config.sample_rate == 32000) {
-                    keyVector.push_back(std::make_pair(SAMPLINGRATE, SAMPLINGRATE_32K));
-                } else if (dAttr.config.sample_rate == 48000) {
-                    keyVector.push_back(std::make_pair(SAMPLINGRATE, SAMPLINGRATE_48K));
-                }
+                if ((sampleRateKv = getSamplerateKv(dAttr.config.sample_rate)) != 0)
+                    keyVector.push_back(std::make_pair(SAMPLINGRATE, sampleRateKv));
                 break;
            case PAL_STREAM_VOIP_TX:
+           case PAL_STREAM_VOICE_RECOGNITION:
                 if ((dAttr.id != PAL_DEVICE_IN_SPEAKER_MIC) &&
                     (dAttr.id != PAL_DEVICE_IN_HANDSET_MIC) &&
-                    (dAttr.id != PAL_DEVICE_IN_WIRED_HEADSET))
+                    (dAttr.id != PAL_DEVICE_IN_WIRED_HEADSET) &&
+                    (dAttr.id != PAL_DEVICE_IN_USB_HEADSET))
                     break;
 
-                PAL_DBG(LOG_TAG,"VoiP_TX Sample Rate[%d]\n", dAttr.config.sample_rate);
-                if (dAttr.config.sample_rate == 8000) {
-                    keyVector.push_back(std::make_pair(SAMPLINGRATE, SAMPLINGRATE_8K));
-                } else if (dAttr.config.sample_rate == 16000) {
-                    keyVector.push_back(std::make_pair(SAMPLINGRATE, SAMPLINGRATE_16K));
-                } else if (dAttr.config.sample_rate == 32000) {
-                    keyVector.push_back(std::make_pair(SAMPLINGRATE, SAMPLINGRATE_32K));
-                } else if (dAttr.config.sample_rate == 48000) {
-                    keyVector.push_back(std::make_pair(SAMPLINGRATE, SAMPLINGRATE_48K));
-                }
+                PAL_DBG(LOG_TAG,"stream type %d Sample Rate[%d]\n", sattr->type, dAttr.config.sample_rate);
+                if ((sampleRateKv = getSamplerateKv(dAttr.config.sample_rate)) != 0)
+                    keyVector.push_back(std::make_pair(SAMPLINGRATE, sampleRateKv));
                 break;
             default:
                 PAL_VERBOSE(LOG_TAG,"stream type %d doesn't support DevicePP CKV ", sattr->type);