Android: Cache implementation name in VideoDecoderWrapper.
This fixes a crash caused by access to already freed memory returned
by VideoDecoderWrapper::ImplementationName method.
Bug: webrtc:7760
Change-Id: Ia4b020d1dd861e6a45637abde35f12951b7c43ea
Reviewed-on: https://webrtc-review.googlesource.com/9420
Reviewed-by: Magnus Jedvert <magjed@webrtc.org>
Commit-Queue: Sami Kalliomäki <sakal@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#20290}
diff --git a/sdk/android/src/jni/videodecoderwrapper.cc b/sdk/android/src/jni/videodecoderwrapper.cc
index 4dfbf93..762025a 100644
--- a/sdk/android/src/jni/videodecoderwrapper.cc
+++ b/sdk/android/src/jni/videodecoderwrapper.cc
@@ -76,6 +76,8 @@
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 @@
}
const char* VideoDecoderWrapper::ImplementationName() const {
- JNIEnv* jni = AttachCurrentThreadIfNeeded();
- ScopedLocalRefFrame local_ref_frame(jni);
- jstring jname = reinterpret_cast<jstring>(
- 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 @@
return qp;
}
+std::string VideoDecoderWrapper::GetImplementationName(JNIEnv* jni) const {
+ jstring jname = reinterpret_cast<jstring>(
+ 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 2da6892..978be87 100644
--- a/sdk/android/src/jni/videodecoderwrapper.h
+++ b/sdk/android/src/jni/videodecoderwrapper.h
@@ -72,6 +72,8 @@
rtc::Optional<uint8_t> ParseQP(const EncodedImage& input_image);
+ std::string GetImplementationName(JNIEnv* jni) const;
+
VideoCodec codec_settings_;
int32_t number_of_cores_;
@@ -80,6 +82,7 @@
std::deque<FrameExtraInfo> frame_extra_infos_;
bool qp_parsing_enabled_;
H264BitstreamParser h264_bitstream_parser_;
+ std::string implementation_name_;
DecodedImageCallback* callback_;