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 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 34 if (codec == "mp4a") | 34 if (codec == "mp4a") |
| 35 return "audio/mp4a-latm"; | 35 return "audio/mp4a-latm"; |
| 36 if (codec == "vp8" || codec == "vp8.0") | 36 if (codec == "vp8" || codec == "vp8.0") |
| 37 return "video/x-vnd.on2.vp8"; | 37 return "video/x-vnd.on2.vp8"; |
| 38 if (codec == "vp9" || codec == "vp9.0") | 38 if (codec == "vp9" || codec == "vp9.0") |
| 39 return "video/x-vnd.on2.vp9"; | 39 return "video/x-vnd.on2.vp9"; |
| 40 if (codec == "vorbis") | 40 if (codec == "vorbis") |
| 41 return "audio/vorbis"; | 41 return "audio/vorbis"; |
| 42 if (codec == "opus") | 42 if (codec == "opus") |
| 43 return "audio/opus"; | 43 return "audio/opus"; |
| 44 return std::string(); | 44 return std::string(); |
|
ddorwin
2016/04/18 20:30:44
Should there be a NOTREACHED() here or at least a
qinmin
2016/04/18 21:32:53
Done.
| |
| 45 } | 45 } |
| 46 | 46 |
| 47 static std::string GetDefaultCodecName(const std::string& mime_type, | 47 static std::string GetDefaultCodecName(const std::string& mime_type, |
| 48 MediaCodecDirection direction) { | 48 MediaCodecDirection direction) { |
| 49 DCHECK(MediaCodecUtil::IsMediaCodecAvailable()); | 49 DCHECK(MediaCodecUtil::IsMediaCodecAvailable()); |
| 50 JNIEnv* env = AttachCurrentThread(); | 50 JNIEnv* env = AttachCurrentThread(); |
| 51 ScopedJavaLocalRef<jstring> j_mime = ConvertUTF8ToJavaString(env, mime_type); | 51 ScopedJavaLocalRef<jstring> j_mime = ConvertUTF8ToJavaString(env, mime_type); |
| 52 ScopedJavaLocalRef<jstring> j_codec_name = | 52 ScopedJavaLocalRef<jstring> j_codec_name = |
| 53 Java_MediaCodecUtil_getDefaultCodecName(env, j_mime.obj(), direction); | 53 Java_MediaCodecUtil_getDefaultCodecName(env, j_mime.obj(), direction); |
| 54 return ConvertJavaStringToUTF8(env, j_codec_name.obj()); | 54 return ConvertJavaStringToUTF8(env, j_codec_name.obj()); |
| 55 } | 55 } |
| 56 | 56 |
| 57 static bool IsDecoderSupportedByDevice(const std::string& mime_type) { | 57 static bool IsDecoderSupportedByDevice(const std::string& mime_type) { |
|
ddorwin
2016/04/18 20:30:44
Would it be safer to have this function (or even t
qinmin
2016/04/18 21:32:54
Done.
| |
| 58 DCHECK(MediaCodecUtil::IsMediaCodecAvailable()); | 58 DCHECK(MediaCodecUtil::IsMediaCodecAvailable()); |
| 59 JNIEnv* env = AttachCurrentThread(); | 59 JNIEnv* env = AttachCurrentThread(); |
| 60 ScopedJavaLocalRef<jstring> j_mime = ConvertUTF8ToJavaString(env, mime_type); | 60 ScopedJavaLocalRef<jstring> j_mime = ConvertUTF8ToJavaString(env, mime_type); |
| 61 return Java_MediaCodecUtil_isDecoderSupportedForDevice(env, j_mime.obj()); | 61 return Java_MediaCodecUtil_isDecoderSupportedForDevice(env, j_mime.obj()); |
| 62 } | 62 } |
| 63 | 63 |
| 64 // static | 64 // static |
| 65 bool MediaCodecUtil::IsMediaCodecAvailable() { | 65 bool MediaCodecUtil::IsMediaCodecAvailable() { |
| 66 // MediaCodec is only available on JB and greater. | 66 // MediaCodec is only available on JB and greater. |
| 67 if (base::android::BuildInfo::GetInstance()->sdk_int() < 16) | 67 if (base::android::BuildInfo::GetInstance()->sdk_int() < 16) |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 | 109 |
| 110 JNIEnv* env = AttachCurrentThread(); | 110 JNIEnv* env = AttachCurrentThread(); |
| 111 std::string mime = CodecTypeToAndroidMimeType(codec); | 111 std::string mime = CodecTypeToAndroidMimeType(codec); |
| 112 if (mime.empty()) | 112 if (mime.empty()) |
| 113 return false; | 113 return false; |
| 114 ScopedJavaLocalRef<jstring> j_mime = ConvertUTF8ToJavaString(env, mime); | 114 ScopedJavaLocalRef<jstring> j_mime = ConvertUTF8ToJavaString(env, mime); |
| 115 return Java_MediaCodecUtil_canDecode(env, j_mime.obj(), is_secure); | 115 return Java_MediaCodecUtil_canDecode(env, j_mime.obj(), is_secure); |
| 116 } | 116 } |
| 117 | 117 |
| 118 // static | 118 // static |
| 119 bool MediaCodecUtil::IsKnownUnaccelerated(const std::string& mime_type, | 119 bool MediaCodecUtil::IsKnownUnaccelerated(const std::string& mime_type, |
|
ddorwin
2016/04/18 20:30:44
|android_mime_type|?
qinmin
2016/04/18 21:32:54
Done.
| |
| 120 MediaCodecDirection direction) { | 120 MediaCodecDirection direction) { |
| 121 if (!IsMediaCodecAvailable()) | 121 if (!IsMediaCodecAvailable()) |
| 122 return true; | 122 return true; |
| 123 | 123 |
| 124 std::string codec_name = GetDefaultCodecName(mime_type, direction); | 124 std::string codec_name = GetDefaultCodecName(mime_type, direction); |
| 125 DVLOG(1) << __FUNCTION__ << "Default codec for " << mime_type << " : " | 125 DVLOG(1) << __FUNCTION__ << "Default codec for " << mime_type << " : " |
| 126 << codec_name << ", direction: " << direction; | 126 << codec_name << ", direction: " << direction; |
| 127 if (!codec_name.size()) | 127 if (!codec_name.size()) |
| 128 return true; | 128 return true; |
| 129 | 129 |
| 130 // MediaTek hardware vp8 is known slower than the software implementation. | 130 // MediaTek hardware vp8 is known slower than the software implementation. |
| 131 // MediaTek hardware vp9 is known crashy, see http://crbug.com/446974 and | 131 // MediaTek hardware vp9 is known crashy, see http://crbug.com/446974 and |
| 132 // http://crbug.com/597836. | 132 // http://crbug.com/597836. |
| 133 if (base::StartsWith(codec_name, "OMX.MTK.", base::CompareCase::SENSITIVE)) { | 133 if (base::StartsWith(codec_name, "OMX.MTK.", base::CompareCase::SENSITIVE)) { |
| 134 if (mime_type == "video/x-vnd.on2.vp8") | 134 if (mime_type == "video/x-vnd.on2.vp8") |
|
ddorwin
2016/04/18 20:30:44
Should we make these constants. This one appears t
qinmin
2016/04/18 21:32:54
Done.
| |
| 135 return true; | 135 return true; |
| 136 | 136 |
| 137 if (mime_type == "video/x-vnd.on2.vp9") | 137 if (mime_type == "video/x-vnd.on2.vp9") |
| 138 return base::android::BuildInfo::GetInstance()->sdk_int() < 21; | 138 return base::android::BuildInfo::GetInstance()->sdk_int() < 21; |
| 139 | 139 |
| 140 return false; | 140 return false; |
| 141 } | 141 } |
| 142 | 142 |
| 143 // It would be nice if MediaCodecInfo externalized some notion of | 143 // It would be nice if MediaCodecInfo externalized some notion of |
| 144 // HW-acceleration but it doesn't. Android Media guidance is that the | 144 // HW-acceleration but it doesn't. Android Media guidance is that the |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 171 return (spec.find("m3u8") != std::string::npos); | 171 return (spec.find("m3u8") != std::string::npos); |
| 172 } | 172 } |
| 173 | 173 |
| 174 // static | 174 // static |
| 175 bool MediaCodecUtil::RegisterMediaCodecUtil(JNIEnv* env) { | 175 bool MediaCodecUtil::RegisterMediaCodecUtil(JNIEnv* env) { |
| 176 return RegisterNativesImpl(env); | 176 return RegisterNativesImpl(env); |
| 177 } | 177 } |
| 178 | 178 |
| 179 // static | 179 // static |
| 180 bool MediaCodecUtil::IsVp8DecoderAvailable() { | 180 bool MediaCodecUtil::IsVp8DecoderAvailable() { |
| 181 return IsMediaCodecAvailable() && IsDecoderSupportedByDevice("vp8"); | 181 return IsMediaCodecAvailable() && |
|
Tima Vaisburd
2016/04/19 01:19:18
I would have just replaced "vp8" and "vp9" down th
| |
| 182 IsDecoderSupportedByDevice(CodecTypeToAndroidMimeType("vp8")); | |
| 182 } | 183 } |
| 183 | 184 |
| 184 // static | 185 // static |
| 185 bool MediaCodecUtil::IsVp8EncoderAvailable() { | 186 bool MediaCodecUtil::IsVp8EncoderAvailable() { |
| 186 // Currently the vp8 encoder and decoder blacklists cover the same devices, | 187 // Currently the vp8 encoder and decoder blacklists cover the same devices, |
| 187 // but we have a second method for clarity in future issues. | 188 // but we have a second method for clarity in future issues. |
| 188 return IsVp8DecoderAvailable(); | 189 return IsVp8DecoderAvailable(); |
| 189 } | 190 } |
| 190 | 191 |
| 191 // static | 192 // static |
| 192 bool MediaCodecUtil::IsVp9DecoderAvailable() { | 193 bool MediaCodecUtil::IsVp9DecoderAvailable() { |
| 193 return IsMediaCodecAvailable() && IsDecoderSupportedByDevice("vp9"); | 194 return IsMediaCodecAvailable() && |
| 195 IsDecoderSupportedByDevice(CodecTypeToAndroidMimeType("vp9")); | |
| 194 } | 196 } |
| 195 | 197 |
| 196 // static | 198 // static |
| 197 bool MediaCodecUtil::IsSurfaceViewOutputSupported() { | 199 bool MediaCodecUtil::IsSurfaceViewOutputSupported() { |
| 198 // Disable SurfaceView output for the Samsung Galaxy S3; it does not work | 200 // Disable SurfaceView output for the Samsung Galaxy S3; it does not work |
| 199 // well enough for even 360p24 H264 playback. http://crbug.com/602870. | 201 // well enough for even 360p24 H264 playback. http://crbug.com/602870. |
| 200 // | 202 // |
| 201 // Notably this is codec agnostic at present, so any devices added to | 203 // Notably this is codec agnostic at present, so any devices added to |
| 202 // the blacklist will avoid trying to play any codecs on SurfaceView. If | 204 // the blacklist will avoid trying to play any codecs on SurfaceView. If |
| 203 // needed in the future this can be expanded to be codec specific. | 205 // needed in the future this can be expanded to be codec specific. |
| 204 return !base::StartsWith(base::android::BuildInfo::GetInstance()->model(), | 206 return !base::StartsWith(base::android::BuildInfo::GetInstance()->model(), |
| 205 "GT-I9300", base::CompareCase::INSENSITIVE_ASCII); | 207 "GT-I9300", base::CompareCase::INSENSITIVE_ASCII); |
| 206 } | 208 } |
| 207 | 209 |
| 208 } // namespace media | 210 } // namespace media |
| OLD | NEW |