OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
836 CheckOnCodecThread(); | 836 CheckOnCodecThread(); |
837 | 837 |
838 if (!DeliverPendingOutputs(jni, 0)) { | 838 if (!DeliverPendingOutputs(jni, 0)) { |
839 ALOGE << "OnMessage: DeliverPendingOutputs error"; | 839 ALOGE << "OnMessage: DeliverPendingOutputs error"; |
840 ProcessHWErrorOnCodecThread(); | 840 ProcessHWErrorOnCodecThread(); |
841 return; | 841 return; |
842 } | 842 } |
843 codec_thread_->PostDelayed(kMediaCodecPollMs, this); | 843 codec_thread_->PostDelayed(kMediaCodecPollMs, this); |
844 } | 844 } |
845 | 845 |
846 MediaCodecVideoDecoderFactory::MediaCodecVideoDecoderFactory() { | 846 MediaCodecVideoDecoderFactory::MediaCodecVideoDecoderFactory() |
| 847 : egl_context_(nullptr) { |
847 ALOGD << "MediaCodecVideoDecoderFactory ctor"; | 848 ALOGD << "MediaCodecVideoDecoderFactory ctor"; |
848 JNIEnv* jni = AttachCurrentThreadIfNeeded(); | 849 JNIEnv* jni = AttachCurrentThreadIfNeeded(); |
849 ScopedLocalRefFrame local_ref_frame(jni); | 850 ScopedLocalRefFrame local_ref_frame(jni); |
850 jclass j_decoder_class = FindClass(jni, "org/webrtc/MediaCodecVideoDecoder"); | 851 jclass j_decoder_class = FindClass(jni, "org/webrtc/MediaCodecVideoDecoder"); |
851 supported_codec_types_.clear(); | 852 supported_codec_types_.clear(); |
852 | 853 |
853 bool is_vp8_hw_supported = jni->CallStaticBooleanMethod( | 854 bool is_vp8_hw_supported = jni->CallStaticBooleanMethod( |
854 j_decoder_class, | 855 j_decoder_class, |
855 GetStaticMethodID(jni, j_decoder_class, "isVp8HwSupported", "()Z")); | 856 GetStaticMethodID(jni, j_decoder_class, "isVp8HwSupported", "()Z")); |
856 if (CheckException(jni)) { | 857 if (CheckException(jni)) { |
(...skipping 22 matching lines...) Expand all Loading... |
879 is_h264_hw_supported = false; | 880 is_h264_hw_supported = false; |
880 } | 881 } |
881 if (is_h264_hw_supported) { | 882 if (is_h264_hw_supported) { |
882 ALOGD << "H264 HW Decoder supported."; | 883 ALOGD << "H264 HW Decoder supported."; |
883 supported_codec_types_.push_back(kVideoCodecH264); | 884 supported_codec_types_.push_back(kVideoCodecH264); |
884 } | 885 } |
885 } | 886 } |
886 | 887 |
887 MediaCodecVideoDecoderFactory::~MediaCodecVideoDecoderFactory() { | 888 MediaCodecVideoDecoderFactory::~MediaCodecVideoDecoderFactory() { |
888 ALOGD << "MediaCodecVideoDecoderFactory dtor"; | 889 ALOGD << "MediaCodecVideoDecoderFactory dtor"; |
| 890 if (egl_context_) { |
| 891 JNIEnv* jni = AttachCurrentThreadIfNeeded(); |
| 892 jni->DeleteGlobalRef(egl_context_); |
| 893 } |
889 } | 894 } |
890 | 895 |
891 void MediaCodecVideoDecoderFactory::SetEGLContext( | 896 void MediaCodecVideoDecoderFactory::SetEGLContext( |
892 JNIEnv* jni, jobject render_egl_context) { | 897 JNIEnv* jni, jobject egl_context) { |
893 ALOGD << "MediaCodecVideoDecoderFactory::SetEGLContext"; | 898 ALOGD << "MediaCodecVideoDecoderFactory::SetEGLContext"; |
894 if (!egl_.CreateEglBase(jni, render_egl_context)) { | 899 RTC_DCHECK(!egl_context_); |
895 ALOGW << "Invalid EGL context - HW surface decoding is disabled."; | 900 egl_context_ = jni->NewGlobalRef(egl_context); |
| 901 if (CheckException(jni)) { |
| 902 ALOGE << "error calling NewGlobalRef for EGL Context."; |
896 } | 903 } |
897 } | 904 } |
898 | 905 |
899 webrtc::VideoDecoder* MediaCodecVideoDecoderFactory::CreateVideoDecoder( | 906 webrtc::VideoDecoder* MediaCodecVideoDecoderFactory::CreateVideoDecoder( |
900 VideoCodecType type) { | 907 VideoCodecType type) { |
901 if (supported_codec_types_.empty()) { | 908 if (supported_codec_types_.empty()) { |
902 ALOGW << "No HW video decoder for type " << (int)type; | 909 ALOGW << "No HW video decoder for type " << (int)type; |
903 return nullptr; | 910 return nullptr; |
904 } | 911 } |
905 for (VideoCodecType codec_type : supported_codec_types_) { | 912 for (VideoCodecType codec_type : supported_codec_types_) { |
906 if (codec_type == type) { | 913 if (codec_type == type) { |
907 ALOGD << "Create HW video decoder for type " << (int)type; | 914 ALOGD << "Create HW video decoder for type " << (int)type; |
908 return new MediaCodecVideoDecoder(AttachCurrentThreadIfNeeded(), type, | 915 return new MediaCodecVideoDecoder(AttachCurrentThreadIfNeeded(), type, |
909 egl_.egl_base_context()); | 916 egl_context_); |
910 } | 917 } |
911 } | 918 } |
912 ALOGW << "Can not find HW video decoder for type " << (int)type; | 919 ALOGW << "Can not find HW video decoder for type " << (int)type; |
913 return nullptr; | 920 return nullptr; |
914 } | 921 } |
915 | 922 |
916 void MediaCodecVideoDecoderFactory::DestroyVideoDecoder( | 923 void MediaCodecVideoDecoderFactory::DestroyVideoDecoder( |
917 webrtc::VideoDecoder* decoder) { | 924 webrtc::VideoDecoder* decoder) { |
918 ALOGD << "Destroy video decoder."; | 925 ALOGD << "Destroy video decoder."; |
919 delete decoder; | 926 delete decoder; |
920 } | 927 } |
921 | 928 |
922 const char* MediaCodecVideoDecoder::ImplementationName() const { | 929 const char* MediaCodecVideoDecoder::ImplementationName() const { |
923 return "MediaCodec"; | 930 return "MediaCodec"; |
924 } | 931 } |
925 | 932 |
926 } // namespace webrtc_jni | 933 } // namespace webrtc_jni |
927 | 934 |
OLD | NEW |