Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "media/base/android/media_codec_util.h" | 5 #include "media/base/android/media_codec_util.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| 11 #include "base/android/build_info.h" | 11 #include "base/android/build_info.h" |
| 12 #include "base/android/jni_android.h" | 12 #include "base/android/jni_android.h" |
| 13 #include "base/android/jni_array.h" | 13 #include "base/android/jni_array.h" |
| 14 #include "base/android/jni_string.h" | 14 #include "base/android/jni_string.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 17 #include "jni/MediaCodecUtil_jni.h" | 17 #include "jni/MediaCodecUtil_jni.h" |
| 18 #include "media/base/android/media_codec_bridge.h" | |
| 18 #include "url/gurl.h" | 19 #include "url/gurl.h" |
| 19 | 20 |
| 20 using base::android::AttachCurrentThread; | 21 using base::android::AttachCurrentThread; |
| 21 using base::android::ConvertJavaStringToUTF8; | 22 using base::android::ConvertJavaStringToUTF8; |
| 22 using base::android::ConvertUTF8ToJavaString; | 23 using base::android::ConvertUTF8ToJavaString; |
| 23 using base::android::JavaIntArrayToIntVector; | 24 using base::android::JavaIntArrayToIntVector; |
| 24 using base::android::ScopedJavaLocalRef; | 25 using base::android::ScopedJavaLocalRef; |
| 25 | 26 |
| 26 namespace media { | 27 namespace media { |
| 27 | 28 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 58 } | 59 } |
| 59 | 60 |
| 60 static bool IsSupportedAndroidMimeType(const std::string& mime_type) { | 61 static bool IsSupportedAndroidMimeType(const std::string& mime_type) { |
| 61 std::vector<std::string> supported{ | 62 std::vector<std::string> supported{ |
| 62 kMp4aMimeType, kOpusMimeType, kVorbisMimeType, kAvcMimeType, | 63 kMp4aMimeType, kOpusMimeType, kVorbisMimeType, kAvcMimeType, |
| 63 kHevcMimeType, kVp8MimeType, kVp9MimeType}; | 64 kHevcMimeType, kVp8MimeType, kVp9MimeType}; |
| 64 return std::find(supported.begin(), supported.end(), mime_type) != | 65 return std::find(supported.begin(), supported.end(), mime_type) != |
| 65 supported.end(); | 66 supported.end(); |
| 66 } | 67 } |
| 67 | 68 |
| 68 static std::string GetDefaultCodecName(const std::string& mime_type, | |
| 69 MediaCodecDirection direction) { | |
| 70 DCHECK(MediaCodecUtil::IsMediaCodecAvailable()); | |
| 71 JNIEnv* env = AttachCurrentThread(); | |
| 72 ScopedJavaLocalRef<jstring> j_mime = ConvertUTF8ToJavaString(env, mime_type); | |
| 73 ScopedJavaLocalRef<jstring> j_codec_name = | |
| 74 Java_MediaCodecUtil_getDefaultCodecName(env, j_mime.obj(), direction); | |
| 75 return ConvertJavaStringToUTF8(env, j_codec_name.obj()); | |
| 76 } | |
| 77 | |
| 78 static bool IsDecoderSupportedByDevice(const std::string& android_mime_type) { | 69 static bool IsDecoderSupportedByDevice(const std::string& android_mime_type) { |
| 79 DCHECK(MediaCodecUtil::IsMediaCodecAvailable()); | 70 DCHECK(MediaCodecUtil::IsMediaCodecAvailable()); |
| 80 DCHECK(IsSupportedAndroidMimeType(android_mime_type)); | 71 DCHECK(IsSupportedAndroidMimeType(android_mime_type)); |
| 81 JNIEnv* env = AttachCurrentThread(); | 72 JNIEnv* env = AttachCurrentThread(); |
| 82 ScopedJavaLocalRef<jstring> j_mime = | 73 ScopedJavaLocalRef<jstring> j_mime = |
| 83 ConvertUTF8ToJavaString(env, android_mime_type); | 74 ConvertUTF8ToJavaString(env, android_mime_type); |
| 84 return Java_MediaCodecUtil_isDecoderSupportedForDevice(env, j_mime.obj()); | 75 return Java_MediaCodecUtil_isDecoderSupportedForDevice(env, j_mime.obj()); |
| 85 } | 76 } |
| 86 | 77 |
| 87 // static | 78 // static |
| 88 bool MediaCodecUtil::IsMediaCodecAvailable() { | 79 bool MediaCodecUtil::IsMediaCodecAvailable() { |
| 89 // MediaCodec is only available on JB and greater. | 80 // MediaCodec is only available on JB and greater. |
| 90 if (base::android::BuildInfo::GetInstance()->sdk_int() < 16) | 81 if (base::android::BuildInfo::GetInstance()->sdk_int() < 16) |
| 91 return false; | 82 return false; |
| 92 // Blacklist some devices on Jellybean as for MediaCodec support is buggy. | 83 // Blacklist some devices on Jellybean as for MediaCodec support is buggy. |
| 93 // http://crbug.com/365494. | 84 // http://crbug.com/365494. |
| 94 if (base::android::BuildInfo::GetInstance()->sdk_int() == 16) { | 85 if (base::android::BuildInfo::GetInstance()->sdk_int() == 16) { |
| 95 std::string model(base::android::BuildInfo::GetInstance()->model()); | 86 std::string model(base::android::BuildInfo::GetInstance()->model()); |
| 96 return model != "GT-I9100" && model != "GT-I9300" && model != "GT-N7000"; | 87 return model != "GT-I9100" && model != "GT-I9300" && model != "GT-N7000"; |
| 97 } | 88 } |
| 98 return true; | 89 return true; |
| 99 } | 90 } |
| 100 | 91 |
| 101 // static | 92 // static |
| 93 std::string MediaCodecUtil::GetDefaultCodecName(const std::string& mime_type, | |
|
DaleCurtis
2016/04/23 19:06:21
Is this even necessary if our blacklist really onl
| |
| 94 MediaCodecDirection direction) { | |
| 95 DCHECK(MediaCodecUtil::IsMediaCodecAvailable()); | |
| 96 JNIEnv* env = AttachCurrentThread(); | |
| 97 ScopedJavaLocalRef<jstring> j_mime = ConvertUTF8ToJavaString(env, mime_type); | |
| 98 ScopedJavaLocalRef<jstring> j_codec_name = | |
| 99 Java_MediaCodecUtil_getDefaultCodecName(env, j_mime.obj(), direction); | |
| 100 return ConvertJavaStringToUTF8(env, j_codec_name.obj()); | |
| 101 } | |
| 102 | |
| 103 // static | |
| 102 bool MediaCodecUtil::SupportsSetParameters() { | 104 bool MediaCodecUtil::SupportsSetParameters() { |
| 103 // MediaCodec.setParameters() is only available starting with K. | 105 // MediaCodec.setParameters() is only available starting with K. |
| 104 return base::android::BuildInfo::GetInstance()->sdk_int() >= 19; | 106 return base::android::BuildInfo::GetInstance()->sdk_int() >= 19; |
| 105 } | 107 } |
| 106 | 108 |
| 107 // static | 109 // static |
| 108 std::set<int> MediaCodecUtil::GetEncoderColorFormats( | 110 std::set<int> MediaCodecUtil::GetEncoderColorFormats( |
| 109 const std::string& mime_type) { | 111 const std::string& mime_type) { |
| 110 std::set<int> color_formats; | 112 std::set<int> color_formats; |
| 111 if (!IsMediaCodecAvailable()) | 113 if (!IsMediaCodecAvailable()) |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 222 // Disable SurfaceView output for the Samsung Galaxy S3; it does not work | 224 // Disable SurfaceView output for the Samsung Galaxy S3; it does not work |
| 223 // well enough for even 360p24 H264 playback. http://crbug.com/602870. | 225 // well enough for even 360p24 H264 playback. http://crbug.com/602870. |
| 224 // | 226 // |
| 225 // Notably this is codec agnostic at present, so any devices added to | 227 // Notably this is codec agnostic at present, so any devices added to |
| 226 // the blacklist will avoid trying to play any codecs on SurfaceView. If | 228 // the blacklist will avoid trying to play any codecs on SurfaceView. If |
| 227 // needed in the future this can be expanded to be codec specific. | 229 // needed in the future this can be expanded to be codec specific. |
| 228 return !base::StartsWith(base::android::BuildInfo::GetInstance()->model(), | 230 return !base::StartsWith(base::android::BuildInfo::GetInstance()->model(), |
| 229 "GT-I9300", base::CompareCase::INSENSITIVE_ASCII); | 231 "GT-I9300", base::CompareCase::INSENSITIVE_ASCII); |
| 230 } | 232 } |
| 231 | 233 |
| 234 // static | |
| 235 bool MediaCodecUtil::CodecNeedsFlushWorkaround(MediaCodecBridge* codec) { | |
| 236 int sdk_int = base::android::BuildInfo::GetInstance()->sdk_int(); | |
| 237 std::string codec_name = codec->GetName(); | |
| 238 return sdk_int < 18 || | |
| 239 (sdk_int == 18 && ("OMX.SEC.avc.dec" == codec_name || | |
| 240 "OMX.SEC.avc.dec.secure" == codec_name)) || | |
| 241 (sdk_int == 19 && | |
| 242 base::StartsWith(base::android::BuildInfo::GetInstance()->model(), | |
| 243 "SM-G800", base::CompareCase::INSENSITIVE_ASCII) && | |
|
qinmin
2016/04/25 22:44:58
This feels strange, so the same decoder works on o
watk
2016/04/25 22:53:53
Yeah, perhaps it happens on other devices too, but
qinmin
2016/04/25 23:07:39
Yes, we should blacklist for all other devices.
| |
| 244 ("OMX.Exynos.avc.dec" == codec_name || | |
| 245 "OMX.Exynos.avc.dec.secure" == codec_name)); | |
| 246 } | |
| 247 | |
| 232 } // namespace media | 248 } // namespace media |
| OLD | NEW |