From cde5c27afefd49701d44ea71b346d1bd33c54c81 Mon Sep 17 00:00:00 2001 From: Michael Chen Date: Fri, 1 Nov 2013 19:51:11 +0800 Subject: [PATCH] fix crash when ffmpeg video port notify setting change event. We don't notify event until "outQueue.size() == kNumOutputBuffers" crash log: I/SoftFFmpegVideo( 4196): ffmpeg video port setting change event(352x144)->(352x288). F/OMXCodec( 4196): frameworks/av/media/libstagefright/OMXCodec.cpp:3285 CHECK(info->mStatus == OWNED_BY_US || info->mStatus == OWNED_BY_NATIVE_WINDOW) failed. F/libc ( 4196): Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1), thread 4241 (OMXCallbackDisp) --- libstagefright/codecs/ffmpegdec/vdec/SoftFFmpegVideo.cpp | 9 +++++---- libstagefright/codecs/ffmpegdec/vdec/SoftFFmpegVideo.h | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/libstagefright/codecs/ffmpegdec/vdec/SoftFFmpegVideo.cpp b/libstagefright/codecs/ffmpegdec/vdec/SoftFFmpegVideo.cpp index ff6d988..4de59a6 100644 --- a/libstagefright/codecs/ffmpegdec/vdec/SoftFFmpegVideo.cpp +++ b/libstagefright/codecs/ffmpegdec/vdec/SoftFFmpegVideo.cpp @@ -918,7 +918,7 @@ int32_t SoftFFmpegVideo::drainOneOutputBuffer() { int sws_flags = SWS_BICUBIC; mImgConvertCtx = sws_getCachedContext(mImgConvertCtx, - mWidth, mHeight, mCtx->pix_fmt, mWidth, mHeight, + mWidth, mHeight, (AVPixelFormat)mFrame->format, mWidth, mHeight, PIX_FMT_YUV420P, sws_flags, NULL, NULL, NULL); if (mImgConvertCtx == NULL) { ALOGE("Cannot initialize the conversion context"); @@ -948,7 +948,7 @@ int32_t SoftFFmpegVideo::drainOneOutputBuffer() { if (pts == AV_NOPTS_VALUE) { pts = 0; } - outHeader->nTimeStamp = pts; + outHeader->nTimeStamp = pts; //FIXME pts is right??? #if DEBUG_FRM ALOGV("mFrame pts: %lld", pts); @@ -1041,7 +1041,7 @@ void SoftFFmpegVideo::onQueueFilled(OMX_U32 portIndex) { } while (((mEOSStatus != INPUT_DATA_AVAILABLE) || !inQueue.empty()) - && !outQueue.empty()) { + && outQueue.size() == kNumOutputBuffers) { if (mEOSStatus == INPUT_EOS_SEEN) { drainAllOutputBuffers(); return; @@ -1148,7 +1148,8 @@ void SoftFFmpegVideo::updatePortDefinitions() { def->format.video.nStride = def->format.video.nFrameWidth; def->format.video.nSliceHeight = def->format.video.nFrameHeight; def->nBufferSize = - def->format.video.nFrameWidth * def->format.video.nFrameHeight; + (def->format.video.nFrameWidth + * def->format.video.nFrameHeight * 3) / 2; def = &editPortInfo(1)->mDef; def->format.video.nFrameWidth = mWidth; diff --git a/libstagefright/codecs/ffmpegdec/vdec/SoftFFmpegVideo.h b/libstagefright/codecs/ffmpegdec/vdec/SoftFFmpegVideo.h index cfb3d53..930948b 100644 --- a/libstagefright/codecs/ffmpegdec/vdec/SoftFFmpegVideo.h +++ b/libstagefright/codecs/ffmpegdec/vdec/SoftFFmpegVideo.h @@ -112,7 +112,7 @@ private: }; bool mFFmpegAlreadyInited; - bool mCodecAlreadyOpened; + bool mCodecAlreadyOpened; bool mPendingFrameAsSettingChanged; AVCodecContext *mCtx; struct SwsContext *mImgConvertCtx; -- 2.11.0