Remove bad waiting code from video decoder release function.

Instead keep surface texture object alive while video codec
is re-initialized with a different resolution.

BUG=
R=tkchin@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/28649004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@7401 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
glaznev@webrtc.org 2014-10-09 00:00:11 +00:00
parent 97abeee282
commit 95bacfed08
2 changed files with 13 additions and 14 deletions

View File

@ -2048,6 +2048,7 @@ class MediaCodecVideoDecoder : public webrtc::VideoDecoder,
// Global references; must be deleted in Release(). // Global references; must be deleted in Release().
std::vector<jobject> input_buffers_; std::vector<jobject> input_buffers_;
jobject surface_texture_; jobject surface_texture_;
jobject previous_surface_texture_;
// Render EGL context. // Render EGL context.
static jobject render_egl_context_; static jobject render_egl_context_;
@ -2082,6 +2083,8 @@ MediaCodecVideoDecoder::MediaCodecVideoDecoder(JNIEnv* jni)
: key_frame_required_(true), : key_frame_required_(true),
inited_(false), inited_(false),
error_count_(0), error_count_(0),
surface_texture_(NULL),
previous_surface_texture_(NULL),
codec_thread_(new Thread()), codec_thread_(new Thread()),
j_media_codec_video_decoder_class_( j_media_codec_video_decoder_class_(
jni, jni,
@ -2156,6 +2159,12 @@ MediaCodecVideoDecoder::MediaCodecVideoDecoder(JNIEnv* jni)
MediaCodecVideoDecoder::~MediaCodecVideoDecoder() { MediaCodecVideoDecoder::~MediaCodecVideoDecoder() {
// Call Release() to ensure no more callbacks to us after we are deleted. // Call Release() to ensure no more callbacks to us after we are deleted.
Release(); Release();
// Delete global references.
JNIEnv* jni = AttachCurrentThreadIfNeeded();
if (previous_surface_texture_ != NULL)
jni->DeleteGlobalRef(previous_surface_texture_);
if (surface_texture_ != NULL)
jni->DeleteGlobalRef(surface_texture_);
} }
int32_t MediaCodecVideoDecoder::InitDecode(const VideoCodec* inst, int32_t MediaCodecVideoDecoder::InitDecode(const VideoCodec* inst,
@ -2233,6 +2242,10 @@ int32_t MediaCodecVideoDecoder::InitDecodeOnCodecThread() {
if (use_surface_) { if (use_surface_) {
jobject surface_texture = GetObjectField( jobject surface_texture = GetObjectField(
jni, *j_media_codec_video_decoder_, j_surface_texture_field_); jni, *j_media_codec_video_decoder_, j_surface_texture_field_);
if (previous_surface_texture_ != NULL) {
jni->DeleteGlobalRef(previous_surface_texture_);
}
previous_surface_texture_ = surface_texture_;
surface_texture_ = jni->NewGlobalRef(surface_texture); surface_texture_ = jni->NewGlobalRef(surface_texture);
} }
codec_thread_->PostDelayed(kMediaCodecPollMs, this); codec_thread_->PostDelayed(kMediaCodecPollMs, this);
@ -2257,18 +2270,6 @@ int32_t MediaCodecVideoDecoder::ReleaseOnCodecThread() {
jni->DeleteGlobalRef(input_buffers_[i]); jni->DeleteGlobalRef(input_buffers_[i]);
} }
input_buffers_.clear(); input_buffers_.clear();
if (use_surface_) {
// Before deleting texture object make sure it is no longer referenced
// by any TextureVideoFrame.
int32_t waitTimeoutUs = 3000000; // 3 second wait
while (waitTimeoutUs > 0 && native_handle_.ref_count() > 0) {
ALOGD("Current Texture RefCnt: %d", native_handle_.ref_count());
usleep(30000);
waitTimeoutUs -= 30000;
}
ALOGD("TextureRefCnt: %d", native_handle_.ref_count());
jni->DeleteGlobalRef(surface_texture_);
}
jni->CallVoidMethod(*j_media_codec_video_decoder_, j_release_method_); jni->CallVoidMethod(*j_media_codec_video_decoder_, j_release_method_);
CHECK_EXCEPTION(jni); CHECK_EXCEPTION(jni);
rtc::MessageQueueManager::Clear(this); rtc::MessageQueueManager::Clear(this);

View File

@ -365,8 +365,6 @@ class MediaCodecVideoDecoder {
mediaCodecThread = null; mediaCodecThread = null;
if (useSurface) { if (useSurface) {
surface.release(); surface.release();
surface = null;
surfaceTexture = null;
if (textureID >= 0) { if (textureID >= 0) {
int[] textures = new int[1]; int[] textures = new int[1];
textures[0] = textureID; textures[0] = textureID;