OSDN Git Service

fix crash when ffmpeg video port notify setting change event.
authorMichael Chen <omxcodec@gmail.com>
Fri, 1 Nov 2013 11:51:11 +0000 (19:51 +0800)
committerMichael Chen <omxcodec@gmail.com>
Fri, 1 Nov 2013 11:51:11 +0000 (19:51 +0800)
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
libstagefright/codecs/ffmpegdec/vdec/SoftFFmpegVideo.h

index ff6d988..4de59a6 100644 (file)
@@ -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;
index cfb3d53..930948b 100644 (file)
@@ -112,7 +112,7 @@ private:
     };
 
     bool mFFmpegAlreadyInited;
-       bool mCodecAlreadyOpened;
+    bool mCodecAlreadyOpened;
        bool mPendingFrameAsSettingChanged;
     AVCodecContext *mCtx;
     struct SwsContext *mImgConvertCtx;