Bug 999902 - Enable WebRTC OMX codec only when Android version >= 18. r=jesup
authorJohn <jolin@mozilla.com>
Wed, 23 Apr 2014 02:59:00 +0200
changeset 180276 3dd6d30c3050fbf931c6a2f98333b66f2fd55faf
parent 180275 40318d23916cdfeea419b1aa063f8718d9f6ff9c
child 180320 fb7439e1e112b9320dfe7317b133f0a98a072e1c
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersjesup
bugs999902
milestone31.0a1
Bug 999902 - Enable WebRTC OMX codec only when Android version >= 18. r=jesup
build/gyp.mozbuild
content/media/omx/OMXCodecWrapper.cpp
content/media/omx/OMXCodecWrapper.h
media/webrtc/signaling/signaling.gyp
media/webrtc/signaling/src/media/VcmSIPCCBinding.cpp
--- a/build/gyp.mozbuild
+++ b/build/gyp.mozbuild
@@ -30,17 +30,17 @@ gyp_vars = {
     # saves 4MB when webrtc_trace is off
     'enable_lazy_trace_alloc': 1,
 
      # turn off mandatory use of NEON and instead use NEON detection
     'arm_neon': 0,
     'arm_neon_optional': 1,
 
     'moz_widget_toolkit_gonk': 0,
-    'moz_omx_encoder': 0,
+    'moz_webrtc_omx': 0,
 
     # (for vp8) chromium sets to 0 also
     'use_temporal_layers': 0,
     # Creates AEC internal sample dump files in current directory
     # 'aec_debug_dump': 1,
 
     # codec enable/disables:
     'include_g711': 1,
@@ -57,18 +57,18 @@ if os == 'WINNT':
     gyp_vars.update(
         MSVS_VERSION=CONFIG['_MSVS_VERSION'],
         MSVS_OS_BITS=64 if CONFIG['HAVE_64BIT_OS'] else 32,
     )
 elif os == 'Android':
     if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
         gyp_vars['build_with_gonk'] = 1
         gyp_vars['moz_widget_toolkit_gonk'] = 1
-        if CONFIG['MOZ_OMX_ENCODER']:
-          gyp_vars['moz_omx_encoder'] = 1
+        if int(CONFIG['ANDROID_VERSION']) >= 18:
+          gyp_vars['moz_webrtc_omx'] = 1
     else:
         gyp_vars.update(
             gtest_target_type='executable',
             android_toolchain=CONFIG['ANDROID_TOOLCHAIN'],
         )
 
 flavors = {
     'WINNT': 'win',
--- a/content/media/omx/OMXCodecWrapper.cpp
+++ b/content/media/omx/OMXCodecWrapper.cpp
@@ -413,25 +413,28 @@ OMXVideoEncoder::AppendFrame(nsTArray<ui
 nsresult
 OMXVideoEncoder::GetCodecConfig(nsTArray<uint8_t>* aOutputBuf)
 {
   MOZ_ASSERT(mHasConfigBlob, "Haven't received codec config yet.");
 
   return AppendDecoderConfig(aOutputBuf, nullptr) == OK ? NS_OK : NS_ERROR_FAILURE;
 }
 
+// MediaCodec::setParameters() is available only after API level 18.
+#if ANDROID_VERSION >= 18
 nsresult
 OMXVideoEncoder::SetBitrate(int32_t aKbps)
 {
   sp<AMessage> msg = new AMessage();
   msg->setInt32("videoBitrate", aKbps * 1000 /* kbps -> bps */);
   status_t result = mCodec->setParameters(msg);
   MOZ_ASSERT(result == OK);
   return result == OK ? NS_OK : NS_ERROR_FAILURE;
 }
+#endif
 
 nsresult
 OMXAudioEncoder::Configure(int aChannels, int aInputSampleRate,
                            int aEncodedSampleRate)
 {
   MOZ_ASSERT(!mStarted);
 
   NS_ENSURE_TRUE(aChannels > 0 && aInputSampleRate > 0 && aEncodedSampleRate >= 0,
--- a/content/media/omx/OMXCodecWrapper.h
+++ b/content/media/omx/OMXCodecWrapper.h
@@ -262,18 +262,20 @@ public:
    * Encode a aWidth pixels wide and aHeight pixels tall video frame of
    * semi-planar YUV420 format stored in the buffer of aImage. aTimestamp gives
    * the frame timestamp/presentation time (in microseconds). To notify end of
    * stream, set aInputFlags to BUFFER_EOS.
    */
   nsresult Encode(const mozilla::layers::Image* aImage, int aWidth, int aHeight,
                   int64_t aTimestamp, int aInputFlags = 0);
 
+#if ANDROID_VERSION >= 18
   /** Set encoding bitrate (in kbps). */
   nsresult SetBitrate(int32_t aKbps);
+#endif
 
   /**
    * Get current AVC codec config blob. The output format depends on the
    * aBlobFormat argument given when Configure() was called.
    */
   nsresult GetCodecConfig(nsTArray<uint8_t>* aOutputBuf);
 
 protected:
--- a/media/webrtc/signaling/signaling.gyp
+++ b/media/webrtc/signaling/signaling.gyp
@@ -187,34 +187,34 @@
         '$(NSS_CFLAGS)',
         '$(MOZ_PIXMAN_CFLAGS)',
       ],
 
       #
       # Conditionals
       #
       'conditions': [
-        ['moz_omx_encoder==1', {
+        ['moz_webrtc_omx==1', {
           'sources': [
             './src/media-conduit/WebrtcOMXH264VideoCodec.cpp',
             './src/media-conduit/OMXVideoCodec.cpp',
           ],
           'include_dirs': [
             '../../../content/media/omx',
             '../../../gfx/layers/client',
           ],
           'cflags_mozilla': [
             '-I$(ANDROID_SOURCE)/frameworks/av/include/media/stagefright',
             '-I$(ANDROID_SOURCE)/frameworks/av/include',
             '-I$(ANDROID_SOURCE)/frameworks/native/include/media/openmax',
             '-I$(ANDROID_SOURCE)/frameworks/native/include',
             '-I$(ANDROID_SOURCE)/frameworks/native/opengl/include',
           ],
           'defines' : [
-            'MOZ_OMX_ENCODER'
+            'MOZ_WEBRTC_OMX'
           ],
         }],
         ['build_for_test==0', {
           'defines' : [
             'MOZILLA_INTERNAL_API'
           ],
           'sources': [
             './src/peerconnection/WebrtcGlobalInformation.cpp',
--- a/media/webrtc/signaling/src/media/VcmSIPCCBinding.cpp
+++ b/media/webrtc/signaling/src/media/VcmSIPCCBinding.cpp
@@ -32,17 +32,17 @@
 #include "nsIPrefBranch.h"
 
 #include <stdlib.h>
 #include <stdio.h>
 #include <ssl.h>
 #include <sslproto.h>
 #include <algorithm>
 
-#ifdef MOZ_OMX_ENCODER
+#ifdef MOZ_WEBRTC_OMX
 #include "OMXVideoCodec.h"
 #endif
 
 extern "C" {
 #include "ccsdp.h"
 #include "vcm.h"
 #include "cc_call_feature.h"
 #include "cip_mmgr_mediadefinitions.h"
@@ -2115,17 +2115,17 @@ short vcmTxOpen(cc_mcapid_t mcap_id,
 /*
  * Add external H.264 video codec.
  */
 static int vcmEnsureExternalCodec(
     const mozilla::RefPtr<mozilla::VideoSessionConduit>& conduit,
     mozilla::VideoCodecConfig* config,
     bool send)
 {
-#ifdef MOZ_OMX_ENCODER
+#ifdef MOZ_WEBRTC_OMX
   // Here we use "I420" to register H.264 because WebRTC.org code has a
   // whitelist of supported video codec in |webrtc::ViECodecImpl::CodecValid()|
   // and will reject registration of those not in it.
   // TODO: bug 995884 to support H.264 in WebRTC.org code.
   if (config->mName != "I420") {
     // Do nothing for non-I420 config.
     return send ? kMediaConduitInvalidSendCodec : kMediaConduitInvalidReceiveCodec;
   }