OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_bridge.h" | 5 #include "media/base/android/media_codec_bridge.h" |
6 | 6 |
7 #include <jni.h> | 7 #include <jni.h> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/android/build_info.h" | 10 #include "base/android/build_info.h" |
11 #include "base/android/jni_android.h" | 11 #include "base/android/jni_android.h" |
12 #include "base/android/jni_array.h" | 12 #include "base/android/jni_array.h" |
13 #include "base/android/jni_string.h" | 13 #include "base/android/jni_string.h" |
14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
15 #include "base/lazy_instance.h" | 15 #include "base/lazy_instance.h" |
16 #include "base/logging.h" | 16 #include "base/logging.h" |
17 #include "base/numerics/safe_conversions.h" | 17 #include "base/numerics/safe_conversions.h" |
18 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
19 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" |
20 #include "jni/MediaCodecBridge_jni.h" | 20 #include "jni/MediaCodecBridge_jni.h" |
21 #include "media/base/bit_reader.h" | 21 #include "media/base/bit_reader.h" |
22 #include "media/base/decrypt_config.h" | 22 #include "media/base/decrypt_config.h" |
23 | 23 |
24 using base::android::AttachCurrentThread; | 24 using base::android::AttachCurrentThread; |
25 using base::android::ConvertJavaStringToUTF8; | 25 using base::android::ConvertJavaStringToUTF8; |
26 using base::android::ConvertUTF8ToJavaString; | 26 using base::android::ConvertUTF8ToJavaString; |
| 27 using base::android::JavaIntArrayToIntVector; |
27 using base::android::ScopedJavaLocalRef; | 28 using base::android::ScopedJavaLocalRef; |
28 | 29 |
29 namespace media { | 30 namespace media { |
30 | 31 |
31 enum { | 32 enum { |
32 kBufferFlagSyncFrame = 1, // BUFFER_FLAG_SYNC_FRAME | 33 kBufferFlagSyncFrame = 1, // BUFFER_FLAG_SYNC_FRAME |
33 kBufferFlagEndOfStream = 4, // BUFFER_FLAG_END_OF_STREAM | 34 kBufferFlagEndOfStream = 4, // BUFFER_FLAG_END_OF_STREAM |
34 kConfigureFlagEncode = 1, // CONFIGURE_FLAG_ENCODE | 35 kConfigureFlagEncode = 1, // CONFIGURE_FLAG_ENCODE |
35 }; | 36 }; |
36 | 37 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 return std::string(); | 165 return std::string(); |
165 | 166 |
166 JNIEnv* env = AttachCurrentThread(); | 167 JNIEnv* env = AttachCurrentThread(); |
167 ScopedJavaLocalRef<jstring> j_mime = ConvertUTF8ToJavaString(env, mime_type); | 168 ScopedJavaLocalRef<jstring> j_mime = ConvertUTF8ToJavaString(env, mime_type); |
168 ScopedJavaLocalRef<jstring> j_codec_name = | 169 ScopedJavaLocalRef<jstring> j_codec_name = |
169 Java_MediaCodecBridge_getDefaultCodecName(env, j_mime.obj(), direction); | 170 Java_MediaCodecBridge_getDefaultCodecName(env, j_mime.obj(), direction); |
170 return ConvertJavaStringToUTF8(env, j_codec_name.obj()); | 171 return ConvertJavaStringToUTF8(env, j_codec_name.obj()); |
171 } | 172 } |
172 | 173 |
173 // static | 174 // static |
| 175 std::set<int> MediaCodecBridge::GetEncoderColorFormats( |
| 176 const std::string& mime_type) { |
| 177 std::set<int> color_formats; |
| 178 if (!IsAvailable()) |
| 179 return color_formats; |
| 180 |
| 181 JNIEnv* env = AttachCurrentThread(); |
| 182 ScopedJavaLocalRef<jstring> j_mime = ConvertUTF8ToJavaString(env, mime_type); |
| 183 ScopedJavaLocalRef<jintArray> j_color_format_array = |
| 184 Java_MediaCodecBridge_getEncoderColorFormatsForMime(env, j_mime.obj()); |
| 185 |
| 186 if (j_color_format_array.obj()) { |
| 187 std::vector<int> formats; |
| 188 JavaIntArrayToIntVector(env, j_color_format_array.obj(), &formats); |
| 189 color_formats = std::set<int>(formats.begin(), formats.end()); |
| 190 } |
| 191 |
| 192 return color_formats; |
| 193 } |
| 194 |
| 195 // static |
174 bool MediaCodecBridge::CanDecode(const std::string& codec, bool is_secure) { | 196 bool MediaCodecBridge::CanDecode(const std::string& codec, bool is_secure) { |
175 if (!IsAvailable()) | 197 if (!IsAvailable()) |
176 return false; | 198 return false; |
177 | 199 |
178 JNIEnv* env = AttachCurrentThread(); | 200 JNIEnv* env = AttachCurrentThread(); |
179 std::string mime = CodecTypeToAndroidMimeType(codec); | 201 std::string mime = CodecTypeToAndroidMimeType(codec); |
180 if (mime.empty()) | 202 if (mime.empty()) |
181 return false; | 203 return false; |
182 ScopedJavaLocalRef<jstring> j_mime = ConvertUTF8ToJavaString(env, mime); | 204 ScopedJavaLocalRef<jstring> j_mime = ConvertUTF8ToJavaString(env, mime); |
183 ScopedJavaLocalRef<jobject> j_media_codec_bridge = | 205 ScopedJavaLocalRef<jobject> j_media_codec_bridge = |
(...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
779 JNIEnv* env = AttachCurrentThread(); | 801 JNIEnv* env = AttachCurrentThread(); |
780 return Java_MediaCodecBridge_isAdaptivePlaybackSupported( | 802 return Java_MediaCodecBridge_isAdaptivePlaybackSupported( |
781 env, media_codec(), width, height); | 803 env, media_codec(), width, height); |
782 } | 804 } |
783 | 805 |
784 bool MediaCodecBridge::RegisterMediaCodecBridge(JNIEnv* env) { | 806 bool MediaCodecBridge::RegisterMediaCodecBridge(JNIEnv* env) { |
785 return RegisterNativesImpl(env); | 807 return RegisterNativesImpl(env); |
786 } | 808 } |
787 | 809 |
788 } // namespace media | 810 } // namespace media |
OLD | NEW |