Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: talk/app/webrtc/java/jni/androidmediadecoder_jni.cc

Issue 1615153002: Change PeerConnectionFactory.setVideoHwAccelerationOptions to create shared Egl context for harware… (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Added eglbase_jni to avoid code duplication. Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * libjingle 2 * libjingle
3 * Copyright 2015 Google Inc. 3 * Copyright 2015 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 FindClass(jni, "org/webrtc/SurfaceTextureHelper"), 340 FindClass(jni, "org/webrtc/SurfaceTextureHelper"),
341 "create", 341 "create",
342 "(Lorg/webrtc/EglBase$Context;)" 342 "(Lorg/webrtc/EglBase$Context;)"
343 "Lorg/webrtc/SurfaceTextureHelper;"), 343 "Lorg/webrtc/SurfaceTextureHelper;"),
344 render_egl_context_); 344 render_egl_context_);
345 RTC_CHECK(java_surface_texture_helper_ != nullptr); 345 RTC_CHECK(java_surface_texture_helper_ != nullptr);
346 surface_texture_helper_ = new rtc::RefCountedObject<SurfaceTextureHelper>( 346 surface_texture_helper_ = new rtc::RefCountedObject<SurfaceTextureHelper>(
347 jni, java_surface_texture_helper_); 347 jni, java_surface_texture_helper_);
348 } 348 }
349 349
350 jobject j_video_codec_enum = JavaEnumFromIndex( 350 jobject j_video_codec_enum = JavaEnumFromIndexAndClassName(
351 jni, "MediaCodecVideoDecoder$VideoCodecType", codecType_); 351 jni, "MediaCodecVideoDecoder$VideoCodecType", codecType_);
352 bool success = jni->CallBooleanMethod( 352 bool success = jni->CallBooleanMethod(
353 *j_media_codec_video_decoder_, 353 *j_media_codec_video_decoder_,
354 j_init_decode_method_, 354 j_init_decode_method_,
355 j_video_codec_enum, 355 j_video_codec_enum,
356 codec_.width, 356 codec_.width,
357 codec_.height, 357 codec_.height,
358 java_surface_texture_helper_); 358 java_surface_texture_helper_);
359 if (CheckException(jni) || !success) { 359 if (CheckException(jni) || !success) {
360 ALOGE << "Codec initialization error - fallback to SW codec."; 360 ALOGE << "Codec initialization error - fallback to SW codec.";
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 CheckOnCodecThread(); 812 CheckOnCodecThread();
813 813
814 if (!DeliverPendingOutputs(jni, 0)) { 814 if (!DeliverPendingOutputs(jni, 0)) {
815 ALOGE << "OnMessage: DeliverPendingOutputs error"; 815 ALOGE << "OnMessage: DeliverPendingOutputs error";
816 ProcessHWErrorOnCodecThread(); 816 ProcessHWErrorOnCodecThread();
817 return; 817 return;
818 } 818 }
819 codec_thread_->PostDelayed(kMediaCodecPollMs, this); 819 codec_thread_->PostDelayed(kMediaCodecPollMs, this);
820 } 820 }
821 821
822 MediaCodecVideoDecoderFactory::MediaCodecVideoDecoderFactory() : 822 MediaCodecVideoDecoderFactory::MediaCodecVideoDecoderFactory() {
823 render_egl_context_(NULL) {
824 ALOGD << "MediaCodecVideoDecoderFactory ctor"; 823 ALOGD << "MediaCodecVideoDecoderFactory ctor";
825 JNIEnv* jni = AttachCurrentThreadIfNeeded(); 824 JNIEnv* jni = AttachCurrentThreadIfNeeded();
826 ScopedLocalRefFrame local_ref_frame(jni); 825 ScopedLocalRefFrame local_ref_frame(jni);
827 jclass j_decoder_class = FindClass(jni, "org/webrtc/MediaCodecVideoDecoder"); 826 jclass j_decoder_class = FindClass(jni, "org/webrtc/MediaCodecVideoDecoder");
828 supported_codec_types_.clear(); 827 supported_codec_types_.clear();
829 828
830 bool is_vp8_hw_supported = jni->CallStaticBooleanMethod( 829 bool is_vp8_hw_supported = jni->CallStaticBooleanMethod(
831 j_decoder_class, 830 j_decoder_class,
832 GetStaticMethodID(jni, j_decoder_class, "isVp8HwSupported", "()Z")); 831 GetStaticMethodID(jni, j_decoder_class, "isVp8HwSupported", "()Z"));
833 if (CheckException(jni)) { 832 if (CheckException(jni)) {
(...skipping 22 matching lines...) Expand all
856 is_h264_hw_supported = false; 855 is_h264_hw_supported = false;
857 } 856 }
858 if (is_h264_hw_supported) { 857 if (is_h264_hw_supported) {
859 ALOGD << "H264 HW Decoder supported."; 858 ALOGD << "H264 HW Decoder supported.";
860 supported_codec_types_.push_back(kVideoCodecH264); 859 supported_codec_types_.push_back(kVideoCodecH264);
861 } 860 }
862 } 861 }
863 862
864 MediaCodecVideoDecoderFactory::~MediaCodecVideoDecoderFactory() { 863 MediaCodecVideoDecoderFactory::~MediaCodecVideoDecoderFactory() {
865 ALOGD << "MediaCodecVideoDecoderFactory dtor"; 864 ALOGD << "MediaCodecVideoDecoderFactory dtor";
866 if (render_egl_context_) {
867 JNIEnv* jni = AttachCurrentThreadIfNeeded();
868 jni->DeleteGlobalRef(render_egl_context_);
869 render_egl_context_ = NULL;
870 }
871 } 865 }
872 866
873 void MediaCodecVideoDecoderFactory::SetEGLContext( 867 void MediaCodecVideoDecoderFactory::SetEGLContext(
874 JNIEnv* jni, jobject render_egl_context) { 868 JNIEnv* jni, jobject render_egl_context) {
875 ALOGD << "MediaCodecVideoDecoderFactory::SetEGLContext"; 869 ALOGD << "MediaCodecVideoDecoderFactory::SetEGLContext";
876 if (render_egl_context_) { 870 if (!egl_.CreateEglBase(jni, render_egl_context)) {
877 jni->DeleteGlobalRef(render_egl_context_); 871 ALOGW << "Invalid EGL context - HW surface decoding is disabled.";
878 render_egl_context_ = NULL;
879 }
880 if (!IsNull(jni, render_egl_context)) {
881 render_egl_context_ = jni->NewGlobalRef(render_egl_context);
882 if (CheckException(jni)) {
883 ALOGE << "error calling NewGlobalRef for EGL Context.";
884 render_egl_context_ = NULL;
885 } else {
886 jclass j_egl_context_class =
887 FindClass(jni, "org/webrtc/EglBase$Context");
888 if (!jni->IsInstanceOf(render_egl_context_, j_egl_context_class)) {
889 ALOGE << "Wrong EGL Context.";
890 jni->DeleteGlobalRef(render_egl_context_);
891 render_egl_context_ = NULL;
892 }
893 }
894 }
895 if (render_egl_context_ == NULL) {
896 ALOGW << "NULL VideoDecoder EGL context - HW surface decoding is disabled.";
897 } 872 }
898 } 873 }
899 874
900 webrtc::VideoDecoder* MediaCodecVideoDecoderFactory::CreateVideoDecoder( 875 webrtc::VideoDecoder* MediaCodecVideoDecoderFactory::CreateVideoDecoder(
901 VideoCodecType type) { 876 VideoCodecType type) {
902 if (supported_codec_types_.empty()) { 877 if (supported_codec_types_.empty()) {
903 ALOGW << "No HW video decoder for type " << (int)type; 878 ALOGW << "No HW video decoder for type " << (int)type;
904 return NULL; 879 return nullptr;
905 } 880 }
906 for (VideoCodecType codec_type : supported_codec_types_) { 881 for (VideoCodecType codec_type : supported_codec_types_) {
907 if (codec_type == type) { 882 if (codec_type == type) {
908 ALOGD << "Create HW video decoder for type " << (int)type; 883 ALOGD << "Create HW video decoder for type " << (int)type;
909 return new MediaCodecVideoDecoder( 884 return new MediaCodecVideoDecoder(AttachCurrentThreadIfNeeded(), type,
910 AttachCurrentThreadIfNeeded(), type, render_egl_context_); 885 egl_.egl_base_context());
911 } 886 }
912 } 887 }
913 ALOGW << "Can not find HW video decoder for type " << (int)type; 888 ALOGW << "Can not find HW video decoder for type " << (int)type;
914 return NULL; 889 return nullptr;
915 } 890 }
916 891
917 void MediaCodecVideoDecoderFactory::DestroyVideoDecoder( 892 void MediaCodecVideoDecoderFactory::DestroyVideoDecoder(
918 webrtc::VideoDecoder* decoder) { 893 webrtc::VideoDecoder* decoder) {
919 ALOGD << "Destroy video decoder."; 894 ALOGD << "Destroy video decoder.";
920 delete decoder; 895 delete decoder;
921 } 896 }
922 897
923 const char* MediaCodecVideoDecoder::ImplementationName() const { 898 const char* MediaCodecVideoDecoder::ImplementationName() const {
924 return "MediaCodec"; 899 return "MediaCodec";
925 } 900 }
926 901
927 } // namespace webrtc_jni 902 } // namespace webrtc_jni
928 903
OLDNEW
« no previous file with comments | « talk/app/webrtc/java/jni/androidmediadecoder_jni.h ('k') | talk/app/webrtc/java/jni/androidmediaencoder_jni.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698