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 #include <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 env, j_media_codec_.obj(), input_buffer_index)); | 307 env, j_media_codec_.obj(), input_buffer_index)); |
308 if (j_buffer.is_null()) | 308 if (j_buffer.is_null()) |
309 return MEDIA_CODEC_ERROR; | 309 return MEDIA_CODEC_ERROR; |
310 | 310 |
311 *data = static_cast<uint8_t*>(env->GetDirectBufferAddress(j_buffer.obj())); | 311 *data = static_cast<uint8_t*>(env->GetDirectBufferAddress(j_buffer.obj())); |
312 *capacity = | 312 *capacity = |
313 base::checked_cast<size_t>(env->GetDirectBufferCapacity(j_buffer.obj())); | 313 base::checked_cast<size_t>(env->GetDirectBufferCapacity(j_buffer.obj())); |
314 return MEDIA_CODEC_OK; | 314 return MEDIA_CODEC_OK; |
315 } | 315 } |
316 | 316 |
317 MediaCodecStatus SdkMediaCodecBridge::CopyFromOutputBuffer(int index, | 317 MediaCodecStatus SdkMediaCodecBridge::GetOutputBufferAddress( |
318 size_t offset, | 318 int index, |
319 void* dst, | 319 size_t offset, |
320 size_t num) { | 320 const uint8_t** addr, |
321 void* src_data = nullptr; | 321 size_t* capacity) { |
322 size_t src_capacity = 0; | |
323 MediaCodecStatus status = | |
324 GetOutputBufferAddress(index, offset, &src_data, &src_capacity); | |
325 if (status == MEDIA_CODEC_OK) { | |
326 CHECK_GE(src_capacity, num); | |
327 memcpy(dst, src_data, num); | |
328 } | |
329 return status; | |
330 } | |
331 | |
332 MediaCodecStatus SdkMediaCodecBridge::GetOutputBufferAddress(int index, | |
333 size_t offset, | |
334 void** addr, | |
335 size_t* capacity) { | |
336 JNIEnv* env = AttachCurrentThread(); | 322 JNIEnv* env = AttachCurrentThread(); |
337 ScopedJavaLocalRef<jobject> j_buffer( | 323 ScopedJavaLocalRef<jobject> j_buffer( |
338 Java_MediaCodecBridge_getOutputBuffer(env, j_media_codec_.obj(), index)); | 324 Java_MediaCodecBridge_getOutputBuffer(env, j_media_codec_.obj(), index)); |
339 if (j_buffer.is_null()) | 325 if (j_buffer.is_null()) |
340 return MEDIA_CODEC_ERROR; | 326 return MEDIA_CODEC_ERROR; |
341 const size_t total_capacity = env->GetDirectBufferCapacity(j_buffer.obj()); | 327 const size_t total_capacity = env->GetDirectBufferCapacity(j_buffer.obj()); |
342 CHECK_GE(total_capacity, offset); | 328 CHECK_GE(total_capacity, offset); |
343 *addr = | 329 *addr = reinterpret_cast<const uint8_t*>( |
344 reinterpret_cast<uint8_t*>(env->GetDirectBufferAddress(j_buffer.obj())) + | 330 env->GetDirectBufferAddress(j_buffer.obj())) + |
345 offset; | 331 offset; |
346 *capacity = total_capacity - offset; | 332 *capacity = total_capacity - offset; |
347 return MEDIA_CODEC_OK; | 333 return MEDIA_CODEC_OK; |
348 } | 334 } |
349 | 335 |
350 // static | 336 // static |
351 bool SdkMediaCodecBridge::RegisterSdkMediaCodecBridge(JNIEnv* env) { | 337 bool SdkMediaCodecBridge::RegisterSdkMediaCodecBridge(JNIEnv* env) { |
352 return RegisterNativesImpl(env); | 338 return RegisterNativesImpl(env); |
353 } | 339 } |
354 | 340 |
355 // static | 341 // static |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
572 } | 558 } |
573 | 559 |
574 MediaCodecStatus AudioCodecBridge::PlayOutputBuffer(int index, | 560 MediaCodecStatus AudioCodecBridge::PlayOutputBuffer(int index, |
575 size_t size, | 561 size_t size, |
576 size_t offset, | 562 size_t offset, |
577 bool postpone, | 563 bool postpone, |
578 int64_t* playback_pos) { | 564 int64_t* playback_pos) { |
579 DCHECK_LE(0, index); | 565 DCHECK_LE(0, index); |
580 int numBytes = base::checked_cast<int>(size); | 566 int numBytes = base::checked_cast<int>(size); |
581 | 567 |
582 void* buffer = nullptr; | 568 const uint8_t* buffer = nullptr; |
583 size_t capacity = 0; | 569 size_t capacity = 0; |
584 MediaCodecStatus status = | 570 MediaCodecStatus status = |
585 GetOutputBufferAddress(index, offset, &buffer, &capacity); | 571 GetOutputBufferAddress(index, offset, &buffer, &capacity); |
586 if (status == MEDIA_CODEC_ERROR) | 572 if (status == MEDIA_CODEC_ERROR) |
587 return status; | 573 return status; |
588 | 574 |
589 numBytes = std::min(base::checked_cast<int>(capacity), numBytes); | 575 numBytes = std::min(base::checked_cast<int>(capacity), numBytes); |
590 CHECK_GE(numBytes, 0); | 576 CHECK_GE(numBytes, 0); |
591 | 577 |
592 JNIEnv* env = AttachCurrentThread(); | 578 JNIEnv* env = AttachCurrentThread(); |
593 ScopedJavaLocalRef<jbyteArray> byte_array = base::android::ToJavaByteArray( | 579 ScopedJavaLocalRef<jbyteArray> byte_array = |
594 env, static_cast<uint8_t*>(buffer), numBytes); | 580 base::android::ToJavaByteArray(env, buffer, numBytes); |
595 *playback_pos = Java_MediaCodecBridge_playOutputBuffer( | 581 *playback_pos = Java_MediaCodecBridge_playOutputBuffer( |
596 env, media_codec(), byte_array.obj(), postpone); | 582 env, media_codec(), byte_array.obj(), postpone); |
597 return status; | 583 return status; |
598 } | 584 } |
599 | 585 |
600 void AudioCodecBridge::SetVolume(double volume) { | 586 void AudioCodecBridge::SetVolume(double volume) { |
601 JNIEnv* env = AttachCurrentThread(); | 587 JNIEnv* env = AttachCurrentThread(); |
602 Java_MediaCodecBridge_setVolume(env, media_codec(), volume); | 588 Java_MediaCodecBridge_setVolume(env, media_codec(), volume); |
603 } | 589 } |
604 | 590 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
699 if (adaptive_playback_supported_for_testing_ == 0) | 685 if (adaptive_playback_supported_for_testing_ == 0) |
700 return false; | 686 return false; |
701 else if (adaptive_playback_supported_for_testing_ > 0) | 687 else if (adaptive_playback_supported_for_testing_ > 0) |
702 return true; | 688 return true; |
703 JNIEnv* env = AttachCurrentThread(); | 689 JNIEnv* env = AttachCurrentThread(); |
704 return Java_MediaCodecBridge_isAdaptivePlaybackSupported(env, media_codec(), | 690 return Java_MediaCodecBridge_isAdaptivePlaybackSupported(env, media_codec(), |
705 width, height); | 691 width, height); |
706 } | 692 } |
707 | 693 |
708 } // namespace media | 694 } // namespace media |
OLD | NEW |