diff --git a/sdk/android/src/jni/videodecoderwrapper.cc b/sdk/android/src/jni/videodecoderwrapper.cc index 4dfbf93db9..762025a9ae 100644 --- a/sdk/android/src/jni/videodecoderwrapper.cc +++ b/sdk/android/src/jni/videodecoderwrapper.cc @@ -76,6 +76,8 @@ VideoDecoderWrapper::VideoDecoderWrapper(JNIEnv* jni, jobject decoder) initialized_ = false; // QP parsing starts enabled and we disable it if the decoder provides frames. qp_parsing_enabled_ = true; + + implementation_name_ = GetImplementationName(jni); } int32_t VideoDecoderWrapper::InitDecode(const VideoCodec* codec_settings, @@ -163,11 +165,7 @@ bool VideoDecoderWrapper::PrefersLateDecoding() const { } const char* VideoDecoderWrapper::ImplementationName() const { - JNIEnv* jni = AttachCurrentThreadIfNeeded(); - ScopedLocalRefFrame local_ref_frame(jni); - jstring jname = reinterpret_cast( - jni->CallObjectMethod(*decoder_, get_implementation_name_method_)); - return JavaToStdString(jni, jname).c_str(); + return implementation_name_.c_str(); } void VideoDecoderWrapper::OnDecodedFrame(JNIEnv* jni, @@ -298,6 +296,12 @@ rtc::Optional VideoDecoderWrapper::ParseQP( return qp; } +std::string VideoDecoderWrapper::GetImplementationName(JNIEnv* jni) const { + jstring jname = reinterpret_cast( + jni->CallObjectMethod(*decoder_, get_implementation_name_method_)); + return JavaToStdString(jni, jname); +} + JNI_FUNCTION_DECLARATION(void, VideoDecoderWrapperCallback_nativeOnDecodedFrame, JNIEnv* jni, diff --git a/sdk/android/src/jni/videodecoderwrapper.h b/sdk/android/src/jni/videodecoderwrapper.h index 2da6892525..978be871e7 100644 --- a/sdk/android/src/jni/videodecoderwrapper.h +++ b/sdk/android/src/jni/videodecoderwrapper.h @@ -72,6 +72,8 @@ class VideoDecoderWrapper : public VideoDecoder { rtc::Optional ParseQP(const EncodedImage& input_image); + std::string GetImplementationName(JNIEnv* jni) const; + VideoCodec codec_settings_; int32_t number_of_cores_; @@ -80,6 +82,7 @@ class VideoDecoderWrapper : public VideoDecoder { std::deque frame_extra_infos_; bool qp_parsing_enabled_; H264BitstreamParser h264_bitstream_parser_; + std::string implementation_name_; DecodedImageCallback* callback_;