Skip to content

Commit

Permalink
h264: propagate error return values for AV_LOG_ERROR-triggering events
Browse files Browse the repository at this point in the history
Signed-off-by: Ronald S. Bultje <rsbultje@gmail.com>
  • Loading branch information
Dustin Brody authored and rbultje committed Aug 9, 2011
1 parent 94d4738 commit 12fe759
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
32 changes: 19 additions & 13 deletions libavcodec/h264.c
Expand Up @@ -1194,15 +1194,15 @@ static int decode_update_thread_context(AVCodecContext *dst, const AVCodecContex
if(!s->current_picture_ptr) return 0;

if(!s->dropable) {
ff_h264_execute_ref_pic_marking(h, h->mmco, h->mmco_index);
err = ff_h264_execute_ref_pic_marking(h, h->mmco, h->mmco_index);
h->prev_poc_msb = h->poc_msb;
h->prev_poc_lsb = h->poc_lsb;
}
h->prev_frame_num_offset= h->frame_num_offset;
h->prev_frame_num = h->frame_num;
h->outputed_poc = h->next_outputed_poc;

return 0;
return err;
}

int ff_h264_frame_start(H264Context *h){
Expand Down Expand Up @@ -2318,9 +2318,10 @@ static void init_scan_tables(H264Context *h){
}
}

static void field_end(H264Context *h, int in_setup){
static int field_end(H264Context *h, int in_setup){
MpegEncContext * const s = &h->s;
AVCodecContext * const avctx= s->avctx;
int err = 0;
s->mb_y= 0;

if (!in_setup && !s->dropable)
Expand All @@ -2332,7 +2333,7 @@ static void field_end(H264Context *h, int in_setup){

if(in_setup || !(avctx->active_thread_type&FF_THREAD_FRAME)){
if(!s->dropable) {
ff_h264_execute_ref_pic_marking(h, h->mmco, h->mmco_index);
err = ff_h264_execute_ref_pic_marking(h, h->mmco, h->mmco_index);
h->prev_poc_msb= h->poc_msb;
h->prev_poc_lsb= h->poc_lsb;
}
Expand Down Expand Up @@ -2367,6 +2368,8 @@ static void field_end(H264Context *h, int in_setup){
MPV_frame_end(s);

h->current_slice=0;

return err;
}

/**
Expand Down Expand Up @@ -2668,7 +2671,9 @@ static int decode_slice_header(H264Context *h, H264Context *h0){
ff_thread_report_progress((AVFrame*)s->current_picture_ptr, INT_MAX, 0);
ff_thread_report_progress((AVFrame*)s->current_picture_ptr, INT_MAX, 1);
ff_generate_sliding_window_mmcos(h);
ff_h264_execute_ref_pic_marking(h, h->mmco, h->mmco_index);
if (ff_h264_execute_ref_pic_marking(h, h->mmco, h->mmco_index) < 0 &&
s->avctx->error_recognition >= FF_ER_EXPLODE)
return AVERROR_INVALIDDATA;
/* Error concealment: if a ref is missing, copy the previous ref in its place.
* FIXME: avoiding a memcpy would be nice, but ref handling makes many assumptions
* about there being no actual duplicates.
Expand Down Expand Up @@ -2842,8 +2847,9 @@ static int decode_slice_header(H264Context *h, H264Context *h0){
}
}

if(h->nal_ref_idc)
ff_h264_decode_ref_pic_marking(h0, &s->gb);
if(h->nal_ref_idc && ff_h264_decode_ref_pic_marking(h0, &s->gb) < 0 &&
s->avctx->error_recognition >= FF_ER_EXPLODE)
return AVERROR_INVALIDDATA;

if(FRAME_MBAFF){
ff_h264_fill_mbaff_ref_list(h);
Expand Down Expand Up @@ -3467,18 +3473,16 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg){
* @param h h264 master context
* @param context_count number of contexts to execute
*/
static void execute_decode_slices(H264Context *h, int context_count){
static int execute_decode_slices(H264Context *h, int context_count){
MpegEncContext * const s = &h->s;
AVCodecContext * const avctx= s->avctx;
H264Context *hx;
int i;

if (s->avctx->hwaccel)
return;
if(s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU)
return;
if (s->avctx->hwaccel || s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU)
return 0;
if(context_count == 1) {
decode_slice(avctx, &h);
return decode_slice(avctx, &h);
} else {
for(i = 1; i < context_count; i++) {
hx = h->thread_context[i];
Expand All @@ -3498,6 +3502,8 @@ static void execute_decode_slices(H264Context *h, int context_count){
for(i = 1; i < context_count; i++)
h->s.error_count += h->thread_context[i]->s.error_count;
}

return 0;
}


Expand Down
8 changes: 6 additions & 2 deletions libavcodec/h264_refs.c
Expand Up @@ -498,7 +498,7 @@ void ff_generate_sliding_window_mmcos(H264Context *h) {
int ff_h264_execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count){
MpegEncContext * const s = &h->s;
int i, av_uninit(j);
int current_ref_assigned=0;
int current_ref_assigned=0, err=0;
Picture *av_uninit(pic);

if((s->avctx->debug&FF_DEBUG_MMCO) && mmco_count==0)
Expand All @@ -517,6 +517,7 @@ int ff_h264_execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count){
if(mmco[i].opcode != MMCO_SHORT2LONG || !h->long_ref[mmco[i].long_arg]
|| h->long_ref[mmco[i].long_arg]->frame_num != frame_num)
av_log(h->s.avctx, AV_LOG_ERROR, "mmco: unref short failure\n");
err = AVERROR_INVALIDDATA;
continue;
}
}
Expand Down Expand Up @@ -608,10 +609,12 @@ int ff_h264_execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count){
"assignment for second field "
"in complementary field pair "
"(first field is long term)\n");
err = AVERROR_INVALIDDATA;
} else {
pic= remove_short(h, s->current_picture_ptr->frame_num, 0);
if(pic){
av_log(h->s.avctx, AV_LOG_ERROR, "illegal short term buffer state detected\n");
err = AVERROR_INVALIDDATA;
}

if(h->short_ref_count)
Expand All @@ -634,6 +637,7 @@ int ff_h264_execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count){
"number of reference frames (%d+%d) exceeds max (%d; probably "
"corrupt input), discarding one\n",
h->long_ref_count, h->short_ref_count, h->sps.ref_frame_count);
err = AVERROR_INVALIDDATA;

if (h->long_ref_count && !h->short_ref_count) {
for (i = 0; i < 16; ++i)
Expand All @@ -650,7 +654,7 @@ int ff_h264_execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count){

print_short_term(h);
print_long_term(h);
return 0;
return err;
}

int ff_h264_decode_ref_pic_marking(H264Context *h, GetBitContext *gb){
Expand Down

0 comments on commit 12fe759

Please sign in to comment.