Reputation: 21
I'm working on an MCU that decodes user h264 video stream using libav v5.1. I use WebRTC and RTP protocol to establish connection and transfer packets over the Internet. When network is congested I see some amount of packets being lost, which produce the following error on the libav side:
[h264 @ 0x7f8bd97f80c0] Frame num change from 77 to 7
[h264 @ 0x7f8bd97f80c0] decode_slice_header error
[h264 @ 0x7f8bd97f80c0] Frame num change from 77 to 8
[h264 @ 0x7f8bd97f80c0] decode_slice_header error
and etc...
When network stabilise there's no packet loss but errors keep going and it seems like codec can't recover from previous packets being lost. It also results in a frozen video on the client. So I guess I need to send some Nacks or PLI but I can't intercept this error in order to do that. It seems from here (line 733) and here (line 1888) that libav only logs the error and doesn't output this as a return value anywhere. I checked AVFrame->decode_error_flags
(always zero) and return value from avcodec_receive_frame
, which is always AVERROR(EAGAIN)
with this type of error. Am I missing something?
Here's the related code:
//codec initialization
ctx->decoder = avcodec_find_decoder(AV_CODEC_ID_H264);
ctx->av_ctx = avcodec_alloc_context3(ctx->decoder);
if (ctx->decoder->capabilities & AV_CODEC_CAP_TRUNCATED)
ctx->av_ctx->flags |= AV_CODEC_FLAG_TRUNCATED;
ctx->av_ctx->flags2 |= AV_CODEC_FLAG2_CHUNKS;
avcodec_open2(ctx->av_ctx, ctx->decoder, NULL);
//actual decoding
ret = avcodec_send_packet(ctx->av_ctx, ctx->pkt);
if (ret < 0) {
printf("err send pkt to decoding: %d\n", ret);
return NULL;
}
while (ret >= 0) {
ret = avcodec_receive_frame(ctx->av_ctx, ctx->dec_frame);
if (ctx->dec_frame->decode_error_flags) {
//never executed
printf("decode error flags %d\n", ctx->dec_frame->decode_error_flags);
fflush(stdout);
}
if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {
//need more pkts
return ctx->scaled_frame;
} else if (ret < 0) {
//never executed
printf("err recv pkt from decoding: %d\n", ret);
return NULL;
}
}
Upvotes: 0
Views: 645