code cleanup, more use of av_strerr to give better error logs.

This commit is contained in:
Isaac Connor 2016-09-16 10:14:58 -04:00
parent 05f061b84b
commit fbc0729c83
2 changed files with 23 additions and 17 deletions

View File

@ -328,5 +328,10 @@ void zm_dump_stream_format(AVFormatContext *ic, int i, int index, int is_output)
#else #else
#define zm_av_unref_packet( packet ) av_free_packet( packet ) #define zm_av_unref_packet( packet ) av_free_packet( packet )
#endif #endif
#if LIBAVCODEC_VERSION_CHECK(52, 23, 0, 23, 0)
#define zm_avcodec_decode_video( context, rawFrame, frameComplete, packet ) avcodec_decode_video2( context, rawFrame, frameComplete, packet )
#else
#define zm_avcodec_decode_video(context, rawFrame, frameComplete, packet ) avcodec_decode_video( context, rawFrame, frameComplete, packet->data, packet->size)
#endif
#endif // ZM_FFMPEG_H #endif // ZM_FFMPEG_H

View File

@ -532,6 +532,7 @@ int FfmpegCamera::CaptureAndRecord( Image &image, bool recording, char* event_fi
return -1; return -1;
} }
int ret; int ret;
static char errbuf[AV_ERROR_MAX_STRING_SIZE];
// If the reopen thread has a value, but mCanCapture != 0, then we have just reopened the connection to the ffmpeg device, and we can clean up the thread. // If the reopen thread has a value, but mCanCapture != 0, then we have just reopened the connection to the ffmpeg device, and we can clean up the thread.
if (mReopenThread != 0) { if (mReopenThread != 0) {
@ -557,22 +558,21 @@ int FfmpegCamera::CaptureAndRecord( Image &image, bool recording, char* event_fi
AVPacket *packet = (AVPacket *)av_malloc(sizeof(AVPacket)); AVPacket *packet = (AVPacket *)av_malloc(sizeof(AVPacket));
av_init_packet( packet); av_init_packet( packet);
Debug(5, "Before av_read_frame"); Debug(5, "Before av_read_frame");
int avResult = av_read_frame( mFormatContext, packet ); ret = av_read_frame( mFormatContext, packet );
Debug(5, "After av_read_frame (%d)", avResult ); Debug(5, "After av_read_frame (%d)", ret );
if ( avResult < 0 ) { if ( ret < 0 ) {
char errbuf[AV_ERROR_MAX_STRING_SIZE]; av_strerror( ret, errbuf, AV_ERROR_MAX_STRING_SIZE );
av_strerror(avResult, errbuf, AV_ERROR_MAX_STRING_SIZE);
if ( if (
// Check if EOF. // Check if EOF.
(avResult == AVERROR_EOF || (mFormatContext->pb && mFormatContext->pb->eof_reached)) || (ret == AVERROR_EOF || (mFormatContext->pb && mFormatContext->pb->eof_reached)) ||
// Check for Connection failure. // Check for Connection failure.
(avResult == -110) (ret == -110)
) { ) {
Info( "av_read_frame returned \"%s\". Reopening stream.", errbuf); Info( "av_read_frame returned \"%s\". Reopening stream.", errbuf);
ReopenFfmpeg(); ReopenFfmpeg();
} }
Error( "Unable to read packet from stream %d: error %d \"%s\".", packet->stream_index, avResult, errbuf ); Error( "Unable to read packet from stream %d: error %d \"%s\".", packet->stream_index, ret, errbuf );
return( -1 ); return( -1 );
} }
Debug( 5, "Got packet from stream %d", packet->stream_index ); Debug( 5, "Got packet from stream %d", packet->stream_index );
@ -664,12 +664,13 @@ Debug(5, "After av_read_frame (%d)", avResult );
} // end if } // end if
if ( packet->stream_index == mVideoStreamId ) { if ( packet->stream_index == mVideoStreamId ) {
#if LIBAVCODEC_VERSION_CHECK(52, 23, 0, 23, 0) ret = zm_avcodec_decode_video( mVideoCodecContext, mRawFrame, &frameComplete, packet );
if (avcodec_decode_video2(mVideoCodecContext, mRawFrame, &frameComplete, packet) < 0) if ( ret < 0 ) {
#else av_strerror( ret, errbuf, AV_ERROR_MAX_STRING_SIZE );
if (avcodec_decode_video(mVideoCodecContext, mRawFrame, &frameComplete, packet->data, packet->size) < 0) Error( "Unable to decode frame at frame %d: %s, continuing", frameCount, errbuf );
#endif zm_av_unref_packet( packet );
Fatal( "Unable to decode frame at frame %d", frameCount ); continue;
}
Debug( 4, "Decoded video packet at frame %d", frameCount ); Debug( 4, "Decoded video packet at frame %d", frameCount );