Skip to content

Commit

Permalink
Reopen codec on errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
ua0lnj committed Aug 21, 2023
1 parent c4b2df5 commit 926992a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
11 changes: 6 additions & 5 deletions codec.c
Expand Up @@ -826,7 +826,7 @@ void DisplayPts(AVCodecContext * video_ctx, AVFrame * frame)
** @param decoder video decoder data
** @param avpkt video packet
*/
void CodecVideoDecode(VideoDecoder * decoder, const AVPacket * avpkt)
int CodecVideoDecode(VideoDecoder * decoder, const AVPacket * avpkt)
{
AVCodecContext *video_ctx;
AVFrame *frame;
Expand Down Expand Up @@ -869,12 +869,12 @@ void CodecVideoDecode(VideoDecoder * decoder, const AVPacket * avpkt)
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57,37,100)
used = avcodec_send_packet(video_ctx, pkt);
if (used < 0 && used != AVERROR(EAGAIN)&& used != AVERROR_EOF)
return;
return -1;

while(!used) { //multiple frames
used = avcodec_receive_frame(video_ctx, frame);
if (used < 0 && used != AVERROR(EAGAIN) && used != AVERROR_EOF)
return;
return -1;
if (used>=0)
got_frame = 1;
else got_frame = 0;
Expand Down Expand Up @@ -922,7 +922,7 @@ void CodecVideoDecode(VideoDecoder * decoder, const AVPacket * avpkt)
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(56,28,1)
av_frame_unref(decoder->Filt_Frame);
#endif
return;
return -1;
}
decoder->Filt_Frame->pts /=2;
#if LIBAVUTIL_VERSION_INT < AV_VERSION_INT(58,7,100)
Expand Down Expand Up @@ -963,7 +963,7 @@ void CodecVideoDecode(VideoDecoder * decoder, const AVPacket * avpkt)
// ffmpeg 0.8.7 dislikes our seq_end_h264 and enters endless loop here
if (used == 0 && pkt->size == 5 && pkt->data[4] == 0x0A) {
Warning("codec: ffmpeg 0.8.x workaround used\n");
return;
return -1;
}
if (used >= 0 && used < pkt->size) {
// some tv channels, produce this
Expand All @@ -987,6 +987,7 @@ void CodecVideoDecode(VideoDecoder * decoder, const AVPacket * avpkt)
}//data_size
#endif
}//codec_type
return 0;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion codec.h
Expand Up @@ -136,7 +136,7 @@ extern int CodecVideoOpen(VideoDecoder *, int);
extern void CodecVideoClose(VideoDecoder *);

/// Decode a video packet.
extern void CodecVideoDecode(VideoDecoder *, const AVPacket *);
extern int CodecVideoDecode(VideoDecoder *, const AVPacket *);

/// Flush video buffers.
extern void CodecVideoFlushBuffers(VideoDecoder *);
Expand Down
7 changes: 6 additions & 1 deletion softhddev.c
Expand Up @@ -1259,7 +1259,12 @@ int VideoDecodeInput(VideoStream * stream)
// lock decoder against close
pthread_mutex_lock(&stream->DecoderLockMutex);
if (stream->Decoder) {
CodecVideoDecode(stream->Decoder, avpkt);
if (CodecVideoDecode(stream->Decoder, avpkt) < 0) {
pthread_mutex_unlock(&stream->DecoderLockMutex);
stream->LastCodecID = AV_CODEC_ID_NONE;
CodecVideoClose(stream->Decoder);
goto skip;
}
}
pthread_mutex_unlock(&stream->DecoderLockMutex);
//fprintf(stderr, "]\n");
Expand Down
1 change: 1 addition & 0 deletions video.c
Expand Up @@ -15791,6 +15791,7 @@ void nvdec_uninit(AVCodecContext *s)

ist->hwaccel_uninit = NULL;
av_buffer_unref(&s->hw_frames_ctx);
s->hw_frames_ctx = NULL;
}

static int nvdec_alloc(AVCodecContext *s, NVdecDecoder * decoder)
Expand Down

0 comments on commit 926992a

Please sign in to comment.