Upstream version 10.38.220.0
[platform/framework/web/crosswalk.git] / src / media / base / android / media_codec_bridge.cc
index 0178844..3cbc9cc 100644 (file)
@@ -104,7 +104,15 @@ ToJavaIntArray(JNIEnv* env, scoped_ptr<jint[]> native_array, int size) {
 // static
 bool MediaCodecBridge::IsAvailable() {
   // MediaCodec is only available on JB and greater.
-  return base::android::BuildInfo::GetInstance()->sdk_int() >= 16;
+  if (base::android::BuildInfo::GetInstance()->sdk_int() < 16)
+    return false;
+  // Blacklist some devices on Jellybean as for MediaCodec support is buggy.
+  // http://crbug.com/365494.
+  if (base::android::BuildInfo::GetInstance()->sdk_int() == 16) {
+    std::string model(base::android::BuildInfo::GetInstance()->model());
+    return model != "GT-I9100" && model != "GT-I9300" && model != "GT-N7000";
+  }
+  return true;
 }
 
 // static
@@ -176,7 +184,8 @@ bool MediaCodecBridge::IsKnownUnaccelerated(const std::string& mime_type,
       // It would be nice if MediaCodecInfo externalized some notion of
       // HW-acceleration but it doesn't. Android Media guidance is that the
       // prefix below is always used for SW decoders, so that's what we use.
-      return StartsWithASCII(codecs_info[i].name, "OMX.google.", true);
+      if (!StartsWithASCII(codecs_info[i].name, "OMX.google.", true))
+        return false;
     }
   }
   return true;
@@ -593,7 +602,7 @@ bool AudioCodecBridge::ConfigureMediaFormat(jobject j_format,
   return true;
 }
 
-void AudioCodecBridge::PlayOutputBuffer(int index, size_t size) {
+int64 AudioCodecBridge::PlayOutputBuffer(int index, size_t size) {
   DCHECK_LE(0, index);
   int numBytes = base::checked_cast<int>(size);
   JNIEnv* env = AttachCurrentThread();
@@ -603,7 +612,8 @@ void AudioCodecBridge::PlayOutputBuffer(int index, size_t size) {
 
   ScopedJavaLocalRef<jbyteArray> byte_array =
       base::android::ToJavaByteArray(env, buffer, numBytes);
-  Java_MediaCodecBridge_playOutputBuffer(env, media_codec(), byte_array.obj());
+  return Java_MediaCodecBridge_playOutputBuffer(
+      env, media_codec(), byte_array.obj());
 }
 
 void AudioCodecBridge::SetVolume(double volume) {
@@ -715,7 +725,8 @@ VideoCodecBridge* VideoCodecBridge::CreateEncoder(const VideoCodec& codec,
 VideoCodecBridge::VideoCodecBridge(const std::string& mime,
                                    bool is_secure,
                                    MediaCodecDirection direction)
-    : MediaCodecBridge(mime, is_secure, direction) {}
+    : MediaCodecBridge(mime, is_secure, direction),
+      adaptive_playback_supported_for_testing_(-1) {}
 
 void VideoCodecBridge::SetVideoBitrate(int bps) {
   JNIEnv* env = AttachCurrentThread();
@@ -727,6 +738,16 @@ void VideoCodecBridge::RequestKeyFrameSoon() {
   Java_MediaCodecBridge_requestKeyFrameSoon(env, media_codec());
 }
 
+bool VideoCodecBridge::IsAdaptivePlaybackSupported(int width, int height) {
+  if (adaptive_playback_supported_for_testing_ == 0)
+    return false;
+  else if (adaptive_playback_supported_for_testing_ > 0)
+    return true;
+  JNIEnv* env = AttachCurrentThread();
+  return Java_MediaCodecBridge_isAdaptivePlaybackSupported(
+      env, media_codec(), width, height);
+}
+
 bool MediaCodecBridge::RegisterMediaCodecBridge(JNIEnv* env) {
   return RegisterNativesImpl(env);
 }