Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

int Impala::Core::Stream::RgbDataSrcLavc_old::DecodeNextFrame ( bool &  isValidFrame,
bool &  isKeyFrame 
) [inline, private]

Definition at line 1352 of file RgbDataSrcLavc_old.h.

References ILOG_DEBUG, ILOG_WARN, and Impala::Max().

Referenced by FindNextDecodedFrame().

01353     {
01354         //avcodec_get_frame_defaults(mFrame);
01355 
01356         const int MAX_READ_FAILURES = Impala::Max(15, 5 * mGopSize);
01357         int nrOfReadFailures = 0;
01358 
01359         int atEndOfFile = 
01360 #ifdef FFMPEG_52
01361         url_feof(mFormatCtx->pb);
01362 #else
01363         url_feof(&mFormatCtx->pb);
01364 #endif
01365         //if (atEndOfFile != 0)
01366         //    return -1;
01367 
01368         bool readFrameFailed = false;
01369 
01370         isValidFrame = false;
01371         isKeyFrame = false;
01372         int rc = 0;
01373         while (true)
01374         {
01375             int readFrameResult = av_read_frame(mFormatCtx, mPacket);
01376             readFrameFailed = (readFrameResult < 0);
01377             if (readFrameFailed)
01378             {
01379                 // upon a negative value, there may still be 
01380                 // valid frames left to decode
01381                 ILOG_DEBUG("av_read_frame failed and returned: " << readFrameResult);
01382             }
01383 
01384             //ILOG_DEBUG("  video stream's curdts=" << mVideoStream->cur_dts << " mPacket->dts=" << mPacket->dts);
01385             //ILOG_DEBUG("  [DecodeNextFrame] mPacket->size=" << mPacket->size << "; mPacket->flags=" << mPacket->flags << "; bp.pos=" << mFormatCtx->pb.pos);
01386 
01387             if (mPacket->stream_index == mVideoStreamIndex) 
01388             {
01389                 int frameDecoded = -1;
01390 
01391                 //int len = avcodec_decode_video(mCodecCtx, mFrame, &frameDecoded,
01392                 //                           mPacket->data, mPacket->size);
01393 
01394                 // provide buffer padding cf. definition of avcodec_decode_video;
01395                 // unsure if required here, but rather safe than sorry...
01396                 const int bufSize = mPacket->size;
01397                 uint8_t *buf = new uint8_t[bufSize + FF_INPUT_BUFFER_PADDING_SIZE];
01398                 for (int i = 0; i < bufSize; i++)
01399                     buf[i] = (mPacket->data)[i];
01400                 for (int i = 0; i < FF_INPUT_BUFFER_PADDING_SIZE; i++)
01401                     buf[bufSize + i] = 0;
01402                 int len = avcodec_decode_video(mCodecCtx, mFrame, &frameDecoded,
01403                                            buf, bufSize);
01404                 delete [] buf;
01405 
01406                 ILOG_DEBUG("mPacket->pts =  " << mPacket->pts << " ; mPacket->dts =  " << mPacket->dts);
01407                 if (len < 0)
01408                     ILOG_DEBUG("  avcodec_decode_video returned: " << len); // implies: frameDecoded==false
01409 
01410                 if (frameDecoded)
01411                 {
01412                     isValidFrame = true;
01413                     isKeyFrame = (mFrame->pict_type==FF_I_TYPE && mFrame->key_frame==1);
01414                     break;
01415                 }
01416                 else
01417                 {
01418 #ifdef FFMPEG_52
01419                     ILOG_DEBUG(
01420                         "  [DecodeNextFrame] Frame not valid; mPacket->size=" << 
01421                         mPacket->size << "; mPacket->flags=" << 
01422                         mPacket->flags << "; bp->pos=" << mFormatCtx->pb->pos);
01423 #else
01424                     ILOG_DEBUG(
01425                         "  [DecodeNextFrame] Frame not valid; mPacket->size=" << 
01426                         mPacket->size << "; mPacket->flags=" << 
01427                         mPacket->flags << "; bp.pos=" << mFormatCtx->pb.pos);
01428 #endif
01429 
01430                     // don't continue if reading reached eof
01431                     if (atEndOfFile)
01432                     {
01433                         rc = -3;
01434                         break;
01435                     }
01436 
01437                     // mPacket->flags unequal zero seems to indicate incomplete
01438                     // frames other than P or B frames missing I or P frame data
01439                     if (mPacket->flags == 0)
01440                         break;
01441                 }
01442             }
01443 
01444             av_free_packet(mPacket);
01445  
01446             // while the read buffer already reached the eof, there may
01447             // still be some valid frames left to decode!
01448             nrOfReadFailures++;
01449             if ((atEndOfFile || readFrameFailed) && (nrOfReadFailures > MAX_READ_FAILURES))
01450             {
01451                 ILOG_WARN("Max. nr of frame read failures reached (" <<
01452                     MAX_READ_FAILURES << "); probably at end of file");
01453                 rc = -1;
01454                 break;
01455             }
01456         }
01457 
01458         av_free_packet(mPacket);
01459         return rc;
01460     }

Here is the call graph for this function:


Generated on Fri Mar 19 11:17:56 2010 for ImpalaSrc by  doxygen 1.5.1