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}
This commit is contained in:
Sami Kalliomäki
2017-10-13 15:20:32 +02:00
committed by Commit Bot
parent ae012cf8b8
commit cee3e53631
2 changed files with 12 additions and 5 deletions

View File

@ -76,6 +76,8 @@ VideoDecoderWrapper::VideoDecoderWrapper(JNIEnv* jni, jobject decoder)
initialized_ = false; initialized_ = false;
// QP parsing starts enabled and we disable it if the decoder provides frames. // QP parsing starts enabled and we disable it if the decoder provides frames.
qp_parsing_enabled_ = true; qp_parsing_enabled_ = true;
implementation_name_ = GetImplementationName(jni);
} }
int32_t VideoDecoderWrapper::InitDecode(const VideoCodec* codec_settings, int32_t VideoDecoderWrapper::InitDecode(const VideoCodec* codec_settings,
@ -163,11 +165,7 @@ bool VideoDecoderWrapper::PrefersLateDecoding() const {
} }
const char* VideoDecoderWrapper::ImplementationName() const { const char* VideoDecoderWrapper::ImplementationName() const {
JNIEnv* jni = AttachCurrentThreadIfNeeded(); return implementation_name_.c_str();
ScopedLocalRefFrame local_ref_frame(jni);
jstring jname = reinterpret_cast<jstring>(
jni->CallObjectMethod(*decoder_, get_implementation_name_method_));
return JavaToStdString(jni, jname).c_str();
} }
void VideoDecoderWrapper::OnDecodedFrame(JNIEnv* jni, void VideoDecoderWrapper::OnDecodedFrame(JNIEnv* jni,
@ -298,6 +296,12 @@ rtc::Optional<uint8_t> VideoDecoderWrapper::ParseQP(
return qp; 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, JNI_FUNCTION_DECLARATION(void,
VideoDecoderWrapperCallback_nativeOnDecodedFrame, VideoDecoderWrapperCallback_nativeOnDecodedFrame,
JNIEnv* jni, JNIEnv* jni,

View File

@ -72,6 +72,8 @@ class VideoDecoderWrapper : public VideoDecoder {
rtc::Optional<uint8_t> ParseQP(const EncodedImage& input_image); rtc::Optional<uint8_t> ParseQP(const EncodedImage& input_image);
std::string GetImplementationName(JNIEnv* jni) const;
VideoCodec codec_settings_; VideoCodec codec_settings_;
int32_t number_of_cores_; int32_t number_of_cores_;
@ -80,6 +82,7 @@ class VideoDecoderWrapper : public VideoDecoder {
std::deque<FrameExtraInfo> frame_extra_infos_; std::deque<FrameExtraInfo> frame_extra_infos_;
bool qp_parsing_enabled_; bool qp_parsing_enabled_;
H264BitstreamParser h264_bitstream_parser_; H264BitstreamParser h264_bitstream_parser_;
std::string implementation_name_;
DecodedImageCallback* callback_; DecodedImageCallback* callback_;