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/sdk_media_codec_bridge.h" | 5 #include "media/base/android/sdk_media_codec_bridge.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
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" | |
15 #include "base/logging.h" | 14 #include "base/logging.h" |
16 #include "base/numerics/safe_conversions.h" | 15 #include "base/numerics/safe_conversions.h" |
17 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
18 #include "jni/MediaCodecBridge_jni.h" | 17 #include "jni/MediaCodecBridge_jni.h" |
19 #include "media/base/bit_reader.h" | 18 #include "media/base/bit_reader.h" |
20 #include "media/base/decrypt_config.h" | 19 #include "media/base/decrypt_config.h" |
21 | 20 |
22 using base::android::AttachCurrentThread; | 21 using base::android::AttachCurrentThread; |
23 using base::android::ConvertJavaStringToUTF8; | 22 using base::android::ConvertJavaStringToUTF8; |
24 using base::android::ConvertUTF8ToJavaString; | 23 using base::android::ConvertUTF8ToJavaString; |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 bool SdkMediaCodecBridge::CopyFromOutputBuffer(int index, | 298 bool SdkMediaCodecBridge::CopyFromOutputBuffer(int index, |
300 size_t offset, | 299 size_t offset, |
301 void* dst, | 300 void* dst, |
302 int dst_size) { | 301 int dst_size) { |
303 void* src_data = nullptr; | 302 void* src_data = nullptr; |
304 size_t src_capacity = GetOutputBufferAddress(index, offset, &src_data); | 303 size_t src_capacity = GetOutputBufferAddress(index, offset, &src_data); |
305 if (src_capacity < offset || | 304 if (src_capacity < offset || |
306 src_capacity - offset < static_cast<size_t>(dst_size)) { | 305 src_capacity - offset < static_cast<size_t>(dst_size)) { |
307 return false; | 306 return false; |
308 } | 307 } |
309 memcpy(dst, static_cast<uint8*>(src_data) + offset, dst_size); | 308 memcpy(dst, static_cast<uint8_t*>(src_data) + offset, dst_size); |
310 return true; | 309 return true; |
311 } | 310 } |
312 | 311 |
313 int SdkMediaCodecBridge::GetOutputBufferAddress(int index, | 312 int SdkMediaCodecBridge::GetOutputBufferAddress(int index, |
314 size_t offset, | 313 size_t offset, |
315 void** addr) { | 314 void** addr) { |
316 JNIEnv* env = AttachCurrentThread(); | 315 JNIEnv* env = AttachCurrentThread(); |
317 ScopedJavaLocalRef<jobject> j_buffer( | 316 ScopedJavaLocalRef<jobject> j_buffer( |
318 Java_MediaCodecBridge_getOutputBuffer(env, j_media_codec_.obj(), index)); | 317 Java_MediaCodecBridge_getOutputBuffer(env, j_media_codec_.obj(), index)); |
319 *addr = | 318 *addr = |
320 reinterpret_cast<uint8*>(env->GetDirectBufferAddress(j_buffer.obj())) + | 319 reinterpret_cast<uint8_t*>(env->GetDirectBufferAddress(j_buffer.obj())) + |
321 offset; | 320 offset; |
322 return env->GetDirectBufferCapacity(j_buffer.obj()) - offset; | 321 return env->GetDirectBufferCapacity(j_buffer.obj()) - offset; |
323 } | 322 } |
324 | 323 |
325 // static | 324 // static |
326 bool SdkMediaCodecBridge::RegisterSdkMediaCodecBridge(JNIEnv* env) { | 325 bool SdkMediaCodecBridge::RegisterSdkMediaCodecBridge(JNIEnv* env) { |
327 return RegisterNativesImpl(env); | 326 return RegisterNativesImpl(env); |
328 } | 327 } |
329 | 328 |
330 // static | 329 // static |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
634 if (adaptive_playback_supported_for_testing_ == 0) | 633 if (adaptive_playback_supported_for_testing_ == 0) |
635 return false; | 634 return false; |
636 else if (adaptive_playback_supported_for_testing_ > 0) | 635 else if (adaptive_playback_supported_for_testing_ > 0) |
637 return true; | 636 return true; |
638 JNIEnv* env = AttachCurrentThread(); | 637 JNIEnv* env = AttachCurrentThread(); |
639 return Java_MediaCodecBridge_isAdaptivePlaybackSupported(env, media_codec(), | 638 return Java_MediaCodecBridge_isAdaptivePlaybackSupported(env, media_codec(), |
640 width, height); | 639 width, height); |
641 } | 640 } |
642 | 641 |
643 } // namespace media | 642 } // namespace media |
OLD | NEW |