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; | |
xhwang
2016/02/12 10:15:04
nit: If you don't care about this overloaded versi
Tima Vaisburd
2016/02/13 01:31:24
I wanted to see that conversion to nanoseconds is
xhwang
2016/02/13 07:43:12
Acknowledged.
| |
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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
470 uint8_t csd[kCsdLength]; | 496 uint8_t csd[kCsdLength]; |
471 csd[0] = profile << 3 | frequency_index >> 1; | 497 csd[0] = profile << 3 | frequency_index >> 1; |
472 csd[1] = (frequency_index & 0x01) << 7 | channel_config << 3; | 498 csd[1] = (frequency_index & 0x01) << 7 | channel_config << 3; |
473 ScopedJavaLocalRef<jbyteArray> byte_array = | 499 ScopedJavaLocalRef<jbyteArray> byte_array = |
474 base::android::ToJavaByteArray(env, csd, kCsdLength); | 500 base::android::ToJavaByteArray(env, csd, kCsdLength); |
475 Java_MediaCodecBridge_setCodecSpecificData(env, j_format, 0, | 501 Java_MediaCodecBridge_setCodecSpecificData(env, j_format, 0, |
476 byte_array.obj()); | 502 byte_array.obj()); |
477 | 503 |
478 // TODO(qinmin): pass an extra variable to this function to determine | 504 // TODO(qinmin): pass an extra variable to this function to determine |
479 // whether we need to call this. | 505 // whether we need to call this. |
480 Java_MediaCodecBridge_setFrameHasADTSHeader(env, j_format); | 506 if (0) { |
507 Java_MediaCodecBridge_setFrameHasADTSHeader(env, j_format); | |
508 } | |
xhwang
2016/02/12 10:15:04
Is this for local test only?
Tima Vaisburd
2016/02/13 01:31:24
Oops! Reverted.
| |
481 break; | 509 break; |
482 } | 510 } |
483 case kCodecOpus: { | 511 case kCodecOpus: { |
484 if (!extra_data || extra_data_size == 0 || codec_delay_ns < 0 || | 512 if (!extra_data || extra_data_size == 0 || codec_delay_ns < 0 || |
485 seek_preroll_ns < 0) { | 513 seek_preroll_ns < 0) { |
486 LOG(ERROR) << "Invalid Opus Header"; | 514 LOG(ERROR) << "Invalid Opus Header"; |
487 return false; | 515 return false; |
488 } | 516 } |
489 | 517 |
490 // csd0 - Opus Header | 518 // csd0 - Opus Header |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
632 if (adaptive_playback_supported_for_testing_ == 0) | 660 if (adaptive_playback_supported_for_testing_ == 0) |
633 return false; | 661 return false; |
634 else if (adaptive_playback_supported_for_testing_ > 0) | 662 else if (adaptive_playback_supported_for_testing_ > 0) |
635 return true; | 663 return true; |
636 JNIEnv* env = AttachCurrentThread(); | 664 JNIEnv* env = AttachCurrentThread(); |
637 return Java_MediaCodecBridge_isAdaptivePlaybackSupported(env, media_codec(), | 665 return Java_MediaCodecBridge_isAdaptivePlaybackSupported(env, media_codec(), |
638 width, height); | 666 width, height); |
639 } | 667 } |
640 | 668 |
641 } // namespace media | 669 } // namespace media |
OLD | NEW |