Bug 1043515 - Add support for a preferred codec to be chosen/offered first always. r=ehugg, a=lmandel
authorRandell Jesup <rjesup@jesup.org>
Sun, 27 Jul 2014 20:00:35 -0400
changeset 216240 1f0ef1b4edd786d206e285c39f7928ccd65da92f
parent 216239 f7a26b0d0de524c8e80a5b6f90d58369bfaa1230
child 216241 11f605516d11b09eb7561dc10509c39a79e26882
push id3857
push userraliiev@mozilla.com
push dateTue, 02 Sep 2014 16:39:23 +0000
treeherdermozilla-beta@5638b907b505 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehugg, lmandel
bugs1043515
milestone33.0a2
Bug 1043515 - Add support for a preferred codec to be chosen/offered first always. r=ehugg, a=lmandel
media/webrtc/signaling/src/media/VcmSIPCCBinding.cpp
media/webrtc/signaling/src/sipcc/core/common/prot_configmgr.c
media/webrtc/signaling/src/sipcc/include/vcm.h
--- a/media/webrtc/signaling/src/media/VcmSIPCCBinding.cpp
+++ b/media/webrtc/signaling/src/media/VcmSIPCCBinding.cpp
@@ -3438,8 +3438,20 @@ short vcmGetVideoMaxMbps(uint16_t codec,
 #ifdef MOZ_WEBRTC_OMX
     // Level 1.2; but let's allow CIF@30 or QVGA@30+ by default
     *max_mbps = 11880;
     ret = 0;
 #endif
   }
   return ret;
 }
+
+short vcmGetVideoPreferredCodec(int32_t *preferred_codec) {
+  short ret;
+
+  mozilla::SyncRunnable::DispatchToThread(VcmSIPCCBinding::getMainThread(),
+      WrapRunnableNMRet(&vcmGetVideoPref_m,
+                        (uint16_t)0,
+                        "media.navigator.video.preferred_codec",
+                        preferred_codec,
+                        &ret));
+  return ret;
+}
--- a/media/webrtc/signaling/src/sipcc/core/common/prot_configmgr.c
+++ b/media/webrtc/signaling/src/sipcc/core/common/prot_configmgr.c
@@ -456,25 +456,33 @@ sip_config_get_display_name (line_t line
  *
  * @param[in] none.
  *
  * @return rtp_ptype of the codec.
  */
 rtp_ptype
 sip_config_preferred_codec (void)
 {
+#if 1
+  uint32_t codec;
+
+  if(vcmGetVideoPreferredCodec((int32_t *) &codec) == 0) {
+    return (rtp_ptype) codec;
+  }
+#else
     key_table_entry_t cfg_preferred_codec;
 
     config_get_value(CFGID_PREFERRED_CODEC, &cfg_preferred_codec,
                      sizeof(cfg_preferred_codec));
     if ((cfg_preferred_codec.name != NULL) &&
         (cfg_preferred_codec.name[0] != '\0')) {
         /* The configuration has preferred codec configured */
         return (cfg_preferred_codec.value);
     }
+#endif
     /* No preferred codec configured */
     return (RTP_NONE);
 }
 
 /**
  * sip_config_local_supported_codecs_get()
  * Get the locally supported codec list. The returned list
  * of codecs will be in the ordered of preference. If there is
@@ -651,16 +659,17 @@ sip_config_video_add_codecs (rtp_ptype a
  *
  * Get the locally supported codec list.
  */
 uint16_t
 sip_config_video_supported_codecs_get (rtp_ptype aSupportedCodecs[],
                           uint16_t supportedCodecsLen, boolean isOffer)
 {
     uint16_t count = 0;
+    rtp_ptype pref_codec;
     int codec_mask;
     int hw_codec_mask = vcmGetVideoCodecList(VCM_DSP_FULLDUPLEX_HW);
     int gmp_codec_mask = vcmGetVideoCodecList(VCM_DSP_FULLDUPLEX_GMP);
 
     if ( isOffer ) {
         codec_mask = vcmGetVideoCodecList(VCM_DSP_FULLDUPLEX);
     } else {
         /* we are trying to match the answer then we
@@ -675,16 +684,32 @@ sip_config_video_supported_codecs_get (r
     codec_mask &= ~hw_codec_mask;
     count += sip_config_video_add_codecs(&aSupportedCodecs[count],
                                          supportedCodecsLen, codec_mask);
     // Now add any GMP codecs that aren't already in
     gmp_codec_mask &= ~(hw_codec_mask | codec_mask);
     count += sip_config_video_add_codecs(&aSupportedCodecs[count],
                                          supportedCodecsLen, gmp_codec_mask);
 
+    // Now promote the preferred codec if any
+    pref_codec = sip_config_preferred_codec();
+    if (pref_codec != RTP_NONE) {
+      int i,j;
+      for (i = 1; i < count; i++) {
+        if (aSupportedCodecs[i] == pref_codec) {
+          // bump it to the front; bump all the rest down
+          for (j = i; j > 0; j--) {
+            aSupportedCodecs[j] = aSupportedCodecs[j-1];
+          }
+          aSupportedCodecs[0] = pref_codec;
+          return count;
+        }
+      }
+      // preferred not found, oh well
+    }
     return count;
 }
 
 /**
  * The function fills in the given codec array based on the
  * platform bit mask of codecs.  Note, that the enumerated list
  * produced is also in the preferred order.
  *
--- a/media/webrtc/signaling/src/sipcc/include/vcm.h
+++ b/media/webrtc/signaling/src/sipcc/include/vcm.h
@@ -1086,16 +1086,18 @@ int vcmDisableRtcpComponent(const char *
 short vcmGetVideoMaxFs(uint16_t codec, int32_t *max_fs);
 
 short vcmGetVideoMaxFr(uint16_t codec, int32_t *max_fr);
 
 short vcmGetVideoMaxBr(uint16_t codec, int32_t *max_br);
 
 short vcmGetVideoMaxMbps(uint16_t codec, int32_t *max_mbps);
 
+short vcmGetVideoPreferredCodec(int32_t *preferred_codec);
+
 //Using C++ for gips. This is the end of extern "C" above.
 #ifdef __cplusplus
 }
 #endif