Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / libjingle / source / talk / app / webrtc / java / src / org / webrtc / MediaCodecVideoEncoder.java
index 45b8d6a..cf11573 100644 (file)
@@ -78,7 +78,7 @@ class MediaCodecVideoEncoder {
 
   // Helper struct for findVp8HwEncoder() below.
   private static class EncoderProperties {
-    EncoderProperties(String codecName, int colorFormat) {
+    public EncoderProperties(String codecName, int colorFormat) {
       this.codecName = codecName;
       this.colorFormat = colorFormat;
     }
@@ -106,26 +106,33 @@ class MediaCodecVideoEncoder {
         continue;  // No VP8 support in this codec; try the next one.
       }
       Log.d(TAG, "Found candidate encoder " + name);
+
+      // Check if this is supported HW encoder.
+      boolean supportedCodec = false;
+      for (String hwCodecPrefix : supportedHwCodecPrefixes) {
+        if (name.startsWith(hwCodecPrefix)) {
+          supportedCodec = true;
+          break;
+        }
+      }
+      if (!supportedCodec) {
+        continue;
+      }
+
       CodecCapabilities capabilities =
           info.getCapabilitiesForType(VP8_MIME_TYPE);
       for (int colorFormat : capabilities.colorFormats) {
         Log.d(TAG, "   Color: 0x" + Integer.toHexString(colorFormat));
       }
 
-      // Check if this is supported HW encoder
-      for (String hwCodecPrefix : supportedHwCodecPrefixes) {
-        if (!name.startsWith(hwCodecPrefix)) {
-          continue;
-        }
-        // Check if codec supports either yuv420 or nv12
-        for (int supportedColorFormat : supportedColorList) {
-          for (int codecColorFormat : capabilities.colorFormats) {
-            if (codecColorFormat == supportedColorFormat) {
-              // Found supported HW VP8 encoder
-              Log.d(TAG, "Found target encoder " + name +
-                  ". Color: 0x" + Integer.toHexString(codecColorFormat));
-              return new EncoderProperties(name, codecColorFormat);
-            }
+      // Check if codec supports either yuv420 or nv12.
+      for (int supportedColorFormat : supportedColorList) {
+        for (int codecColorFormat : capabilities.colorFormats) {
+          if (codecColorFormat == supportedColorFormat) {
+            // Found supported HW VP8 encoder.
+            Log.d(TAG, "Found target encoder " + name +
+                ". Color: 0x" + Integer.toHexString(codecColorFormat));
+            return new EncoderProperties(name, codecColorFormat);
           }
         }
       }
@@ -137,15 +144,6 @@ class MediaCodecVideoEncoder {
     return findVp8HwEncoder() != null;
   }
 
-  private static int bitRate(int kbps) {
-    // webrtc "kilo" means 1000, not 1024.  Apparently.
-    // (and the price for overshooting is frame-dropping as webrtc enforces its
-    // bandwidth estimation, which is unpleasant).
-    // Since the HW encoder in the N5 overshoots, we clamp to a bit less than
-    // the requested rate.  Sad but true.  Bug 3194.
-    return kbps * 950;
-  }
-
   private void checkOnMediaCodecThread() {
     if (mediaCodecThread.getId() != Thread.currentThread().getId()) {
       throw new RuntimeException(
@@ -170,7 +168,7 @@ class MediaCodecVideoEncoder {
     try {
       MediaFormat format =
           MediaFormat.createVideoFormat(VP8_MIME_TYPE, width, height);
-      format.setInteger(MediaFormat.KEY_BIT_RATE, bitRate(kbps));
+      format.setInteger(MediaFormat.KEY_BIT_RATE, 1000 * kbps);
       format.setInteger("bitrate-mode", VIDEO_ControlRateConstant);
       format.setInteger(MediaFormat.KEY_COLOR_FORMAT, properties.colorFormat);
       // Default WebRTC settings
@@ -241,7 +239,7 @@ class MediaCodecVideoEncoder {
     Log.v(TAG, "setRates: " + kbps + " kbps. Fps: " + frameRateIgnored);
     try {
       Bundle params = new Bundle();
-      params.putInt(MediaCodec.PARAMETER_KEY_VIDEO_BITRATE, bitRate(kbps));
+      params.putInt(MediaCodec.PARAMETER_KEY_VIDEO_BITRATE, 1000 * kbps);
       mediaCodec.setParameters(params);
       return true;
     } catch (IllegalStateException e) {