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 <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 bool AudioCodecBridge::IsKnownUnaccelerated(const AudioCodec& codec) { | 338 bool AudioCodecBridge::IsKnownUnaccelerated(const AudioCodec& codec) { |
339 return MediaCodecUtil::IsKnownUnaccelerated( | 339 return MediaCodecUtil::IsKnownUnaccelerated( |
340 AudioCodecToAndroidMimeType(codec), MEDIA_CODEC_DECODER); | 340 AudioCodecToAndroidMimeType(codec), MEDIA_CODEC_DECODER); |
341 } | 341 } |
342 | 342 |
343 AudioCodecBridge::AudioCodecBridge(const std::string& mime) | 343 AudioCodecBridge::AudioCodecBridge(const std::string& mime) |
344 // Audio codec doesn't care about security level and there is no need for | 344 // Audio codec doesn't care about security level and there is no need for |
345 // audio encoding yet. | 345 // audio encoding yet. |
346 : SdkMediaCodecBridge(mime, false, MEDIA_CODEC_DECODER) {} | 346 : SdkMediaCodecBridge(mime, false, MEDIA_CODEC_DECODER) {} |
347 | 347 |
| 348 bool AudioCodecBridge::ConfigureAndStart(const AudioDecoderConfig& config, |
| 349 bool play_audio, |
| 350 jobject media_crypto) { |
| 351 const int channel_count = |
| 352 ChannelLayoutToChannelCount(config.channel_layout()); |
| 353 const int64_t codec_delay_ns = base::Time::kNanosecondsPerSecond * |
| 354 config.codec_delay() / |
| 355 config.samples_per_second(); |
| 356 const int64_t seek_preroll_ns = |
| 357 1000LL * config.seek_preroll().InMicroseconds(); |
| 358 |
| 359 return ConfigureAndStart(config.codec(), config.samples_per_second(), |
| 360 channel_count, config.extra_data().data(), |
| 361 config.extra_data().size(), codec_delay_ns, |
| 362 seek_preroll_ns, play_audio, media_crypto); |
| 363 } |
| 364 |
348 bool AudioCodecBridge::ConfigureAndStart(const AudioCodec& codec, | 365 bool AudioCodecBridge::ConfigureAndStart(const AudioCodec& codec, |
349 int sample_rate, | 366 int sample_rate, |
350 int channel_count, | 367 int channel_count, |
351 const uint8_t* extra_data, | 368 const uint8_t* extra_data, |
352 size_t extra_data_size, | 369 size_t extra_data_size, |
353 int64_t codec_delay_ns, | 370 int64_t codec_delay_ns, |
354 int64_t seek_preroll_ns, | 371 int64_t seek_preroll_ns, |
355 bool play_audio, | 372 bool play_audio, |
356 jobject media_crypto) { | 373 jobject media_crypto) { |
357 JNIEnv* env = AttachCurrentThread(); | 374 DVLOG(2) << __FUNCTION__ << ": " |
| 375 << " codec:" << GetCodecName(codec) |
| 376 << " samples_per_second:" << sample_rate |
| 377 << " channel_count:" << channel_count |
| 378 << " codec_delay_ns:" << codec_delay_ns |
| 379 << " seek_preroll_ns:" << seek_preroll_ns |
| 380 << " extra data size:" << extra_data_size |
| 381 << " play audio:" << play_audio << " media_crypto:" << media_crypto; |
358 | 382 |
359 if (!media_codec()) | 383 if (!media_codec()) |
360 return false; | 384 return false; |
361 | 385 |
362 std::string codec_string = AudioCodecToAndroidMimeType(codec); | 386 std::string codec_string = AudioCodecToAndroidMimeType(codec); |
363 if (codec_string.empty()) | 387 if (codec_string.empty()) |
364 return false; | 388 return false; |
365 | 389 |
| 390 JNIEnv* env = AttachCurrentThread(); |
| 391 |
366 ScopedJavaLocalRef<jstring> j_mime = | 392 ScopedJavaLocalRef<jstring> j_mime = |
367 ConvertUTF8ToJavaString(env, codec_string); | 393 ConvertUTF8ToJavaString(env, codec_string); |
368 ScopedJavaLocalRef<jobject> j_format(Java_MediaCodecBridge_createAudioFormat( | 394 ScopedJavaLocalRef<jobject> j_format(Java_MediaCodecBridge_createAudioFormat( |
369 env, j_mime.obj(), sample_rate, channel_count)); | 395 env, j_mime.obj(), sample_rate, channel_count)); |
370 DCHECK(!j_format.is_null()); | 396 DCHECK(!j_format.is_null()); |
371 | 397 |
372 if (!ConfigureMediaFormat(j_format.obj(), codec, extra_data, extra_data_size, | 398 if (!ConfigureMediaFormat(j_format.obj(), codec, extra_data, extra_data_size, |
373 codec_delay_ns, seek_preroll_ns)) { | 399 codec_delay_ns, seek_preroll_ns)) { |
374 return false; | 400 return false; |
375 } | 401 } |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 if (adaptive_playback_supported_for_testing_ == 0) | 658 if (adaptive_playback_supported_for_testing_ == 0) |
633 return false; | 659 return false; |
634 else if (adaptive_playback_supported_for_testing_ > 0) | 660 else if (adaptive_playback_supported_for_testing_ > 0) |
635 return true; | 661 return true; |
636 JNIEnv* env = AttachCurrentThread(); | 662 JNIEnv* env = AttachCurrentThread(); |
637 return Java_MediaCodecBridge_isAdaptivePlaybackSupported(env, media_codec(), | 663 return Java_MediaCodecBridge_isAdaptivePlaybackSupported(env, media_codec(), |
638 width, height); | 664 width, height); |
639 } | 665 } |
640 | 666 |
641 } // namespace media | 667 } // namespace media |
OLD | NEW |