| 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 return "video/x-vnd.on2.vp8"; | 74 return "video/x-vnd.on2.vp8"; |
| 75 case kCodecVP9: | 75 case kCodecVP9: |
| 76 return "video/x-vnd.on2.vp9"; | 76 return "video/x-vnd.on2.vp9"; |
| 77 default: | 77 default: |
| 78 return std::string(); | 78 return std::string(); |
| 79 } | 79 } |
| 80 } | 80 } |
| 81 | 81 |
| 82 SdkMediaCodecBridge::SdkMediaCodecBridge(const std::string& mime, | 82 SdkMediaCodecBridge::SdkMediaCodecBridge(const std::string& mime, |
| 83 bool is_secure, | 83 bool is_secure, |
| 84 MediaCodecDirection direction) { | 84 MediaCodecDirection direction, |
| 85 bool require_software) { |
| 85 JNIEnv* env = AttachCurrentThread(); | 86 JNIEnv* env = AttachCurrentThread(); |
| 86 CHECK(env); | 87 CHECK(env); |
| 87 DCHECK(!mime.empty()); | 88 DCHECK(!mime.empty()); |
| 88 ScopedJavaLocalRef<jstring> j_mime = ConvertUTF8ToJavaString(env, mime); | 89 ScopedJavaLocalRef<jstring> j_mime = ConvertUTF8ToJavaString(env, mime); |
| 89 j_media_codec_.Reset( | 90 j_media_codec_.Reset(Java_MediaCodecBridge_create( |
| 90 Java_MediaCodecBridge_create(env, j_mime.obj(), is_secure, direction)); | 91 env, j_mime.obj(), is_secure, direction, require_software)); |
| 91 } | 92 } |
| 92 | 93 |
| 93 SdkMediaCodecBridge::~SdkMediaCodecBridge() { | 94 SdkMediaCodecBridge::~SdkMediaCodecBridge() { |
| 94 JNIEnv* env = AttachCurrentThread(); | 95 JNIEnv* env = AttachCurrentThread(); |
| 95 CHECK(env); | 96 CHECK(env); |
| 96 if (j_media_codec_.obj()) | 97 if (j_media_codec_.obj()) |
| 97 Java_MediaCodecBridge_release(env, j_media_codec_.obj()); | 98 Java_MediaCodecBridge_release(env, j_media_codec_.obj()); |
| 98 } | 99 } |
| 99 | 100 |
| 100 bool SdkMediaCodecBridge::Start() { | 101 bool SdkMediaCodecBridge::Start() { |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 | 357 |
| 357 // static | 358 // static |
| 358 bool AudioCodecBridge::IsKnownUnaccelerated(const AudioCodec& codec) { | 359 bool AudioCodecBridge::IsKnownUnaccelerated(const AudioCodec& codec) { |
| 359 return MediaCodecUtil::IsKnownUnaccelerated( | 360 return MediaCodecUtil::IsKnownUnaccelerated( |
| 360 AudioCodecToAndroidMimeType(codec), MEDIA_CODEC_DECODER); | 361 AudioCodecToAndroidMimeType(codec), MEDIA_CODEC_DECODER); |
| 361 } | 362 } |
| 362 | 363 |
| 363 AudioCodecBridge::AudioCodecBridge(const std::string& mime) | 364 AudioCodecBridge::AudioCodecBridge(const std::string& mime) |
| 364 // Audio codec doesn't care about security level and there is no need for | 365 // Audio codec doesn't care about security level and there is no need for |
| 365 // audio encoding yet. | 366 // audio encoding yet. |
| 366 : SdkMediaCodecBridge(mime, false, MEDIA_CODEC_DECODER) {} | 367 : SdkMediaCodecBridge(mime, false, MEDIA_CODEC_DECODER, false) {} |
| 367 | 368 |
| 368 bool AudioCodecBridge::ConfigureAndStart(const AudioDecoderConfig& config, | 369 bool AudioCodecBridge::ConfigureAndStart(const AudioDecoderConfig& config, |
| 369 bool play_audio, | 370 bool play_audio, |
| 370 jobject media_crypto) { | 371 jobject media_crypto) { |
| 371 const int channel_count = | 372 const int channel_count = |
| 372 ChannelLayoutToChannelCount(config.channel_layout()); | 373 ChannelLayoutToChannelCount(config.channel_layout()); |
| 373 const int64_t codec_delay_ns = base::Time::kNanosecondsPerSecond * | 374 const int64_t codec_delay_ns = base::Time::kNanosecondsPerSecond * |
| 374 config.codec_delay() / | 375 config.codec_delay() / |
| 375 config.samples_per_second(); | 376 config.samples_per_second(); |
| 376 const int64_t seek_preroll_ns = | 377 const int64_t seek_preroll_ns = |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 } | 603 } |
| 603 | 604 |
| 604 // static | 605 // static |
| 605 bool VideoCodecBridge::IsKnownUnaccelerated(const VideoCodec& codec, | 606 bool VideoCodecBridge::IsKnownUnaccelerated(const VideoCodec& codec, |
| 606 MediaCodecDirection direction) { | 607 MediaCodecDirection direction) { |
| 607 return MediaCodecUtil::IsKnownUnaccelerated( | 608 return MediaCodecUtil::IsKnownUnaccelerated( |
| 608 VideoCodecToAndroidMimeType(codec), direction); | 609 VideoCodecToAndroidMimeType(codec), direction); |
| 609 } | 610 } |
| 610 | 611 |
| 611 // static | 612 // static |
| 612 VideoCodecBridge* VideoCodecBridge::CreateDecoder( | 613 VideoCodecBridge* VideoCodecBridge::CreateDecoder(const VideoCodec& codec, |
| 613 const VideoCodec& codec, | 614 bool is_secure, |
| 614 bool is_secure, | 615 const gfx::Size& size, |
| 615 const gfx::Size& size, | 616 jobject surface, |
| 616 jobject surface, | 617 jobject media_crypto, |
| 617 jobject media_crypto, | 618 bool allow_adaptive_playback, |
| 618 bool allow_adaptive_playback) { | 619 bool require_software) { |
| 619 if (!MediaCodecUtil::IsMediaCodecAvailable()) | 620 if (!MediaCodecUtil::IsMediaCodecAvailable()) |
| 620 return nullptr; | 621 return nullptr; |
| 621 | 622 |
| 622 const std::string mime = VideoCodecToAndroidMimeType(codec); | 623 const std::string mime = VideoCodecToAndroidMimeType(codec); |
| 623 if (mime.empty()) | 624 if (mime.empty()) |
| 624 return nullptr; | 625 return nullptr; |
| 625 | 626 |
| 626 std::unique_ptr<VideoCodecBridge> bridge( | 627 std::unique_ptr<VideoCodecBridge> bridge(new VideoCodecBridge( |
| 627 new VideoCodecBridge(mime, is_secure, MEDIA_CODEC_DECODER)); | 628 mime, is_secure, MEDIA_CODEC_DECODER, require_software)); |
| 628 if (!bridge->media_codec()) | 629 if (!bridge->media_codec()) |
| 629 return nullptr; | 630 return nullptr; |
| 630 | 631 |
| 631 JNIEnv* env = AttachCurrentThread(); | 632 JNIEnv* env = AttachCurrentThread(); |
| 632 ScopedJavaLocalRef<jstring> j_mime = ConvertUTF8ToJavaString(env, mime); | 633 ScopedJavaLocalRef<jstring> j_mime = ConvertUTF8ToJavaString(env, mime); |
| 633 ScopedJavaLocalRef<jobject> j_format( | 634 ScopedJavaLocalRef<jobject> j_format( |
| 634 Java_MediaCodecBridge_createVideoDecoderFormat( | 635 Java_MediaCodecBridge_createVideoDecoderFormat( |
| 635 env, j_mime.obj(), size.width(), size.height())); | 636 env, j_mime.obj(), size.width(), size.height())); |
| 636 DCHECK(!j_format.is_null()); | 637 DCHECK(!j_format.is_null()); |
| 637 if (!Java_MediaCodecBridge_configureVideo( | 638 if (!Java_MediaCodecBridge_configureVideo( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 651 int i_frame_interval, | 652 int i_frame_interval, |
| 652 int color_format) { | 653 int color_format) { |
| 653 if (!MediaCodecUtil::IsMediaCodecAvailable()) | 654 if (!MediaCodecUtil::IsMediaCodecAvailable()) |
| 654 return nullptr; | 655 return nullptr; |
| 655 | 656 |
| 656 const std::string mime = VideoCodecToAndroidMimeType(codec); | 657 const std::string mime = VideoCodecToAndroidMimeType(codec); |
| 657 if (mime.empty()) | 658 if (mime.empty()) |
| 658 return nullptr; | 659 return nullptr; |
| 659 | 660 |
| 660 std::unique_ptr<VideoCodecBridge> bridge( | 661 std::unique_ptr<VideoCodecBridge> bridge( |
| 661 new VideoCodecBridge(mime, false, MEDIA_CODEC_ENCODER)); | 662 new VideoCodecBridge(mime, false, MEDIA_CODEC_ENCODER, false)); |
| 662 if (!bridge->media_codec()) | 663 if (!bridge->media_codec()) |
| 663 return nullptr; | 664 return nullptr; |
| 664 | 665 |
| 665 JNIEnv* env = AttachCurrentThread(); | 666 JNIEnv* env = AttachCurrentThread(); |
| 666 ScopedJavaLocalRef<jstring> j_mime = ConvertUTF8ToJavaString(env, mime); | 667 ScopedJavaLocalRef<jstring> j_mime = ConvertUTF8ToJavaString(env, mime); |
| 667 ScopedJavaLocalRef<jobject> j_format( | 668 ScopedJavaLocalRef<jobject> j_format( |
| 668 Java_MediaCodecBridge_createVideoEncoderFormat( | 669 Java_MediaCodecBridge_createVideoEncoderFormat( |
| 669 env, j_mime.obj(), size.width(), size.height(), bit_rate, frame_rate, | 670 env, j_mime.obj(), size.width(), size.height(), bit_rate, frame_rate, |
| 670 i_frame_interval, color_format)); | 671 i_frame_interval, color_format)); |
| 671 DCHECK(!j_format.is_null()); | 672 DCHECK(!j_format.is_null()); |
| 672 if (!Java_MediaCodecBridge_configureVideo(env, bridge->media_codec(), | 673 if (!Java_MediaCodecBridge_configureVideo(env, bridge->media_codec(), |
| 673 j_format.obj(), nullptr, nullptr, | 674 j_format.obj(), nullptr, nullptr, |
| 674 kConfigureFlagEncode, true)) { | 675 kConfigureFlagEncode, true)) { |
| 675 return nullptr; | 676 return nullptr; |
| 676 } | 677 } |
| 677 | 678 |
| 678 return bridge->Start() ? bridge.release() : nullptr; | 679 return bridge->Start() ? bridge.release() : nullptr; |
| 679 } | 680 } |
| 680 | 681 |
| 681 VideoCodecBridge::VideoCodecBridge(const std::string& mime, | 682 VideoCodecBridge::VideoCodecBridge(const std::string& mime, |
| 682 bool is_secure, | 683 bool is_secure, |
| 683 MediaCodecDirection direction) | 684 MediaCodecDirection direction, |
| 684 : SdkMediaCodecBridge(mime, is_secure, direction), | 685 bool require_software) |
| 686 : SdkMediaCodecBridge(mime, is_secure, direction, require_software), |
| 685 adaptive_playback_supported_for_testing_(-1) {} | 687 adaptive_playback_supported_for_testing_(-1) {} |
| 686 | 688 |
| 687 void VideoCodecBridge::SetVideoBitrate(int bps) { | 689 void VideoCodecBridge::SetVideoBitrate(int bps) { |
| 688 JNIEnv* env = AttachCurrentThread(); | 690 JNIEnv* env = AttachCurrentThread(); |
| 689 Java_MediaCodecBridge_setVideoBitrate(env, media_codec(), bps); | 691 Java_MediaCodecBridge_setVideoBitrate(env, media_codec(), bps); |
| 690 } | 692 } |
| 691 | 693 |
| 692 void VideoCodecBridge::RequestKeyFrameSoon() { | 694 void VideoCodecBridge::RequestKeyFrameSoon() { |
| 693 JNIEnv* env = AttachCurrentThread(); | 695 JNIEnv* env = AttachCurrentThread(); |
| 694 Java_MediaCodecBridge_requestKeyFrameSoon(env, media_codec()); | 696 Java_MediaCodecBridge_requestKeyFrameSoon(env, media_codec()); |
| 695 } | 697 } |
| 696 | 698 |
| 697 bool VideoCodecBridge::IsAdaptivePlaybackSupported(int width, int height) { | 699 bool VideoCodecBridge::IsAdaptivePlaybackSupported(int width, int height) { |
| 698 if (adaptive_playback_supported_for_testing_ == 0) | 700 if (adaptive_playback_supported_for_testing_ == 0) |
| 699 return false; | 701 return false; |
| 700 else if (adaptive_playback_supported_for_testing_ > 0) | 702 else if (adaptive_playback_supported_for_testing_ > 0) |
| 701 return true; | 703 return true; |
| 702 JNIEnv* env = AttachCurrentThread(); | 704 JNIEnv* env = AttachCurrentThread(); |
| 703 return Java_MediaCodecBridge_isAdaptivePlaybackSupported(env, media_codec(), | 705 return Java_MediaCodecBridge_isAdaptivePlaybackSupported(env, media_codec(), |
| 704 width, height); | 706 width, height); |
| 705 } | 707 } |
| 706 | 708 |
| 707 } // namespace media | 709 } // namespace media |
| OLD | NEW |