In particular, declare iterators with loop scope. Also remove av_uninit while at it, because they are now unnecessary due to the changes of the preceding commit.
Showing the changes to libavcodec (1 of 1 file). Show all
Unified · Split
| @@ -38,8 +38,7 @@ · 37 unmodified lines | |||
| 38 | 38 | ||
| 39 | static void pic_as_field(H264Ref *pic, const int parity) | 39 | static void pic_as_field(H264Ref *pic, const int parity) |
| 40 | { | 40 | { |
| 41 | int i; | 41 | for (int i = 0; i < FF_ARRAY_ELEMS(pic->data); ++i) { |
| 42 | for (i = 0; i < FF_ARRAY_ELEMS(pic->data); ++i) { | ||
| 43 | if (parity == PICT_BOTTOM_FIELD) | 42 | if (parity == PICT_BOTTOM_FIELD) |
| 44 | pic->data[i] += pic->linesize[i]; | 43 | pic->data[i] += pic->linesize[i]; |
| 45 | pic->reference = parity; | 44 | pic->reference = parity; |
| @@ -104,13 +103,12 @@ static int build_def_list(H264Ref *def, int def_len, · 58 unmodified lines | |||
| 104 | static int add_sorted(H264Picture **sorted, H264Picture * const *src, | 103 | static int add_sorted(H264Picture **sorted, H264Picture * const *src, |
| 105 | int len, int limit, int dir) | 104 | int len, int limit, int dir) |
| 106 | { | 105 | { |
| 107 | int i, best_poc; | ||
| 108 | int out_i = 0; | 106 | int out_i = 0; |
| 109 | 107 | ||
| 110 | for (;;) { | 108 | for (;;) { |
| 111 | best_poc = dir ? INT_MIN : INT_MAX; | 109 | int best_poc = dir ? INT_MIN : INT_MAX; |
| 112 | 110 | ||
| 113 | for (i = 0; i < len; i++) { | 111 | for (int i = 0; i < len; i++) { |
| 114 | const int poc = src[i]->poc; | 112 | const int poc = src[i]->poc; |
| 115 | if (((poc > limit) ^ dir) && ((poc < best_poc) ^ dir)) { | 113 | if (((poc > limit) ^ dir) && ((poc < best_poc) ^ dir)) { |
| 116 | best_poc = poc; | 114 | best_poc = poc; |
| @@ -134,12 +132,11 @@ static int mismatches_ref(const H264Context *h, const H264Picture *pic) · 17 unmodified lines | |||
| 134 | 132 | ||
| 135 | static void h264_initialise_ref_list(H264Context *h, H264SliceContext *sl) | 133 | static void h264_initialise_ref_list(H264Context *h, H264SliceContext *sl) |
| 136 | { | 134 | { |
| 137 | int i, len; | 135 | int len; |
| 138 | int j; | ||
| 139 | 136 | ||
| 140 | if (sl->slice_type_nos == AV_PICTURE_TYPE_B) { | 137 | if (sl->slice_type_nos == AV_PICTURE_TYPE_B) { |
| 141 | H264Picture *sorted[32]; | 138 | H264Picture *sorted[32]; |
| 142 | int cur_poc, list; | 139 | int cur_poc; |
| 143 | int lens[2]; | 140 | int lens[2]; |
| 144 | 141 | ||
| 145 | if (FIELD_PICTURE(h)) | 142 | if (FIELD_PICTURE(h)) |
| @@ -147,7 +144,7 @@ static void h264_initialise_ref_list(H264Context *h, H264SliceContext *sl) · 1 unmodified line | |||
| 147 | else | 144 | else |
| 148 | cur_poc = h->cur_pic_ptr->poc; | 145 | cur_poc = h->cur_pic_ptr->poc; |
| 149 | 146 | ||
| 150 | for (list = 0; list < 2; list++) { | 147 | for (int list = 0; list < 2; list++) { |
| 151 | len = add_sorted(sorted, h->short_ref, h->short_ref_count, cur_poc, 1 ^ list); | 148 | len = add_sorted(sorted, h->short_ref, h->short_ref_count, cur_poc, 1 ^ list); |
| 152 | len += add_sorted(sorted + len, h->short_ref, h->short_ref_count, cur_poc, 0 ^ list); | 149 | len += add_sorted(sorted + len, h->short_ref, h->short_ref_count, cur_poc, 0 ^ list); |
| 153 | av_assert0(len <= 32); | 150 | av_assert0(len <= 32); |
| @@ -165,6 +162,7 @@ static void h264_initialise_ref_list(H264Context *h, H264SliceContext *sl) · 11 unmodified lines | |||
| 165 | } | 162 | } |
| 166 | 163 | ||
| 167 | if (lens[0] == lens[1] && lens[1] > 1) { | 164 | if (lens[0] == lens[1] && lens[1] > 1) { |
| 165 | int i; | ||
| 168 | for (i = 0; i < lens[0] && | 166 | for (i = 0; i < lens[0] && |
| 169 | sl->ref_list[0][i].parent->f->buf[0]->buffer == | 167 | sl->ref_list[0][i].parent->f->buf[0]->buffer == |
| 170 | sl->ref_list[1][i].parent->f->buf[0]->buffer; i++); | 168 | sl->ref_list[1][i].parent->f->buf[0]->buffer; i++); |
| @@ -184,14 +182,14 @@ static void h264_initialise_ref_list(H264Context *h, H264SliceContext *sl) · 13 unmodified lines | |||
| 184 | memset(&sl->ref_list[0][len], 0, sizeof(H264Ref) * (sl->ref_count[0] - len)); | 182 | memset(&sl->ref_list[0][len], 0, sizeof(H264Ref) * (sl->ref_count[0] - len)); |
| 185 | } | 183 | } |
| 186 | #ifdef TRACE | 184 | #ifdef TRACE |
| 187 | for (i = 0; i < sl->ref_count[0]; i++) { | 185 | for (int i = 0; i < sl->ref_count[0]; i++) { |
| 188 | ff_tlog(h->avctx, "List0: %s fn:%d 0x%p\n", | 186 | ff_tlog(h->avctx, "List0: %s fn:%d 0x%p\n", |
| 189 | (sl->ref_list[0][i].parent ? (sl->ref_list[0][i].parent->long_ref ? "LT" : "ST") : "??"), | 187 | (sl->ref_list[0][i].parent ? (sl->ref_list[0][i].parent->long_ref ? "LT" : "ST") : "??"), |
| 190 | sl->ref_list[0][i].pic_id, | 188 | sl->ref_list[0][i].pic_id, |
| 191 | sl->ref_list[0][i].data[0]); | 189 | sl->ref_list[0][i].data[0]); |
| 192 | } | 190 | } |
| 193 | if (sl->slice_type_nos == AV_PICTURE_TYPE_B) { | 191 | if (sl->slice_type_nos == AV_PICTURE_TYPE_B) { |
| 194 | for (i = 0; i < sl->ref_count[1]; i++) { | 192 | for (int i = 0; i < sl->ref_count[1]; i++) { |
| 195 | ff_tlog(h->avctx, "List1: %s fn:%d 0x%p\n", | 193 | ff_tlog(h->avctx, "List1: %s fn:%d 0x%p\n", |
| 196 | (sl->ref_list[1][i].parent ? (sl->ref_list[1][i].parent->long_ref ? "LT" : "ST") : "??"), | 194 | (sl->ref_list[1][i].parent ? (sl->ref_list[1][i].parent->long_ref ? "LT" : "ST") : "??"), |
| 197 | sl->ref_list[1][i].pic_id, | 195 | sl->ref_list[1][i].pic_id, |
| @@ -200,8 +198,8 @@ static void h264_initialise_ref_list(H264Context *h, H264SliceContext *sl) · 2 unmodified lines | |||
| 200 | } | 198 | } |
| 201 | #endif | 199 | #endif |
| 202 | 200 | ||
| 203 | for (j = 0; j<1+(sl->slice_type_nos == AV_PICTURE_TYPE_B); j++) { | 201 | for (int j = 0; j < 1 + (sl->slice_type_nos == AV_PICTURE_TYPE_B); j++) { |
| 204 | for (i = 0; i < sl->ref_count[j]; i++) { | 202 | for (int i = 0; i < sl->ref_count[j]; i++) { |
| 205 | if (sl->ref_list[j][i].parent) { | 203 | if (sl->ref_list[j][i].parent) { |
| 206 | if (mismatches_ref(h, sl->ref_list[j][i].parent)) { | 204 | if (mismatches_ref(h, sl->ref_list[j][i].parent)) { |
| 207 | av_log(h->avctx, AV_LOG_ERROR, "Discarding mismatching reference\n"); | 205 | av_log(h->avctx, AV_LOG_ERROR, "Discarding mismatching reference\n"); |
| @@ -210,7 +208,7 @@ static void h264_initialise_ref_list(H264Context *h, H264SliceContext *sl) · 2 unmodified lines | |||
| 210 | } | 208 | } |
| 211 | } | 209 | } |
| 212 | } | 210 | } |
| 213 | for (i = 0; i < sl->list_count; i++) | 211 | for (int i = 0; i < sl->list_count; i++) |
| 214 | h->default_ref[i] = sl->ref_list[i][0]; | 212 | h->default_ref[i] = sl->ref_list[i][0]; |
| 215 | } | 213 | } |
| 216 | 214 | ||
| @@ -219,10 +217,9 @@ static void h264_initialise_ref_list(H264Context *h, H264SliceContext *sl) · 2 unmodified lines | |||
| 219 | */ | 217 | */ |
| 220 | static void print_short_term(const H264Context *h) | 218 | static void print_short_term(const H264Context *h) |
| 221 | { | 219 | { |
| 222 | uint32_t i; | ||
| 223 | if (h->avctx->debug & FF_DEBUG_MMCO) { | 220 | if (h->avctx->debug & FF_DEBUG_MMCO) { |
| 224 | av_log(h->avctx, AV_LOG_DEBUG, "short term list:\n"); | 221 | av_log(h->avctx, AV_LOG_DEBUG, "short term list:\n"); |
| 225 | for (i = 0; i < h->short_ref_count; i++) { | 222 | for (uint32_t i = 0; i < h->short_ref_count; i++) { |
| 226 | H264Picture *pic = h->short_ref[i]; | 223 | H264Picture *pic = h->short_ref[i]; |
| 227 | av_log(h->avctx, AV_LOG_DEBUG, "%"PRIu32" fn:%d poc:%d %p\n", | 224 | av_log(h->avctx, AV_LOG_DEBUG, "%"PRIu32" fn:%d poc:%d %p\n", |
| 228 | i, pic->frame_num, pic->poc, pic->f->data[0]); | 225 | i, pic->frame_num, pic->poc, pic->f->data[0]); |
| @@ -235,10 +232,9 @@ static void print_short_term(const H264Context *h) · 6 unmodified lines | |||
| 235 | */ | 232 | */ |
| 236 | static void print_long_term(const H264Context *h) | 233 | static void print_long_term(const H264Context *h) |
| 237 | { | 234 | { |
| 238 | uint32_t i; | ||
| 239 | if (h->avctx->debug & FF_DEBUG_MMCO) { | 235 | if (h->avctx->debug & FF_DEBUG_MMCO) { |
| 240 | av_log(h->avctx, AV_LOG_DEBUG, "long term list:\n"); | 236 | av_log(h->avctx, AV_LOG_DEBUG, "long term list:\n"); |
| 241 | for (i = 0; i < 16; i++) { | 237 | for (uint32_t i = 0; i < 16; i++) { |
| 242 | H264Picture *pic = h->long_ref[i]; | 238 | H264Picture *pic = h->long_ref[i]; |
| 243 | if (pic) { | 239 | if (pic) { |
| 244 | av_log(h->avctx, AV_LOG_DEBUG, "%"PRIu32" fn:%d poc:%d %p\n", | 240 | av_log(h->avctx, AV_LOG_DEBUG, "%"PRIu32" fn:%d poc:%d %p\n", |
| @@ -273,22 +269,21 @@ static int pic_num_extract(const H264Context *h, int pic_num, int *structure) · 28 unmodified lines | |||
| 273 | 269 | ||
| 274 | static void h264_fill_mbaff_ref_list(H264SliceContext *sl) | 270 | static void h264_fill_mbaff_ref_list(H264SliceContext *sl) |
| 275 | { | 271 | { |
| 276 | int list, i, j; | 272 | for (int list = 0; list < sl->list_count; list++) { |
| 277 | for (list = 0; list < sl->list_count; list++) { | 273 | for (int i = 0; i < sl->ref_count[list]; i++) { |
| 278 | for (i = 0; i < sl->ref_count[list]; i++) { | ||
| 279 | const H264Ref *frame = &sl->ref_list[list][i]; | 274 | const H264Ref *frame = &sl->ref_list[list][i]; |
| 280 | H264Ref *field = &sl->ref_list[list][16 + 2 * i]; | 275 | H264Ref *field = &sl->ref_list[list][16 + 2 * i]; |
| 281 | 276 | ||
| 282 | field[0] = *frame; | 277 | field[0] = *frame; |
| 283 | 278 | ||
| 284 | for (j = 0; j < 3; j++) | 279 | for (int j = 0; j < 3; j++) |
| 285 | field[0].linesize[j] <<= 1; | 280 | field[0].linesize[j] <<= 1; |
| 286 | field[0].reference = PICT_TOP_FIELD; | 281 | field[0].reference = PICT_TOP_FIELD; |
| 287 | field[0].poc = field[0].parent->field_poc[0]; | 282 | field[0].poc = field[0].parent->field_poc[0]; |
| 288 | 283 | ||
| 289 | field[1] = field[0]; | 284 | field[1] = field[0]; |
| 290 | 285 | ||
| 291 | for (j = 0; j < 3; j++) | 286 | for (int j = 0; j < 3; j++) |
| 292 | field[1].data[j] += frame->parent->f->linesize[j]; | 287 | field[1].data[j] += frame->parent->f->linesize[j]; |
| 293 | field[1].reference = PICT_BOTTOM_FIELD; | 288 | field[1].reference = PICT_BOTTOM_FIELD; |
| 294 | field[1].poc = field[1].parent->field_poc[1]; | 289 | field[1].poc = field[1].parent->field_poc[1]; |
| @@ -298,21 +293,19 @@ static void h264_fill_mbaff_ref_list(H264SliceContext *sl) · 3 unmodified lines | |||
| 298 | 293 | ||
| 299 | int ff_h264_build_ref_list(H264Context *h, H264SliceContext *sl) | 294 | int ff_h264_build_ref_list(H264Context *h, H264SliceContext *sl) |
| 300 | { | 295 | { |
| 301 | int list, index, pic_structure; | ||
| 302 | |||
| 303 | print_short_term(h); | 296 | print_short_term(h); |
| 304 | print_long_term(h); | 297 | print_long_term(h); |
| 305 | 298 | ||
| 306 | h264_initialise_ref_list(h, sl); | 299 | h264_initialise_ref_list(h, sl); |
| 307 | 300 | ||
| 308 | for (list = 0; list < sl->list_count; list++) { | 301 | for (int list = 0; list < sl->list_count; list++) { |
| 309 | int pred = sl->curr_pic_num; | 302 | int pred = sl->curr_pic_num; |
| 310 | 303 | ||
| 311 | for (index = 0; index < sl->nb_ref_modifications[list]; index++) { | 304 | for (int index = 0; index < sl->nb_ref_modifications[list]; index++) { |
| 312 | unsigned int modification_of_pic_nums_idc = sl->ref_modifications[list][index].op; | 305 | unsigned int modification_of_pic_nums_idc = sl->ref_modifications[list][index].op; |
| 313 | unsigned int val = sl->ref_modifications[list][index].val; | 306 | unsigned int val = sl->ref_modifications[list][index].val; |
| 314 | unsigned int pic_id; | 307 | unsigned int pic_id; |
| 315 | int i; | 308 | int i, pic_structure; |
| 316 | H264Picture *ref = NULL; | 309 | H264Picture *ref = NULL; |
| 317 | 310 | ||
| 318 | switch (modification_of_pic_nums_idc) { | 311 | switch (modification_of_pic_nums_idc) { |
| @@ -396,13 +389,13 @@ int ff_h264_build_ref_list(H264Context *h, H264SliceContext *sl) · 77 unmodified lines | |||
| 396 | } | 389 | } |
| 397 | } | 390 | } |
| 398 | } | 391 | } |
| 399 | for (list = 0; list < sl->list_count; list++) { | 392 | for (int list = 0; list < sl->list_count; list++) { |
| 400 | for (index = 0; index < sl->ref_count[list]; index++) { | 393 | for (int index = 0; index < sl->ref_count[list]; index++) { |
| 401 | if ( !sl->ref_list[list][index].parent | 394 | if ( !sl->ref_list[list][index].parent |
| 402 | || (!FIELD_PICTURE(h) && (sl->ref_list[list][index].reference&3) != 3)) { | 395 | || (!FIELD_PICTURE(h) && (sl->ref_list[list][index].reference&3) != 3)) { |
| 403 | int i; | ||
| 404 | av_log(h->avctx, AV_LOG_ERROR, "Missing reference picture, default is %d\n", h->default_ref[list].poc); | 396 | av_log(h->avctx, AV_LOG_ERROR, "Missing reference picture, default is %d\n", h->default_ref[list].poc); |
| 405 | for (i = 0; i < FF_ARRAY_ELEMS(h->last_pocs); i++) | 397 | |
| 398 | for (int i = 0; i < FF_ARRAY_ELEMS(h->last_pocs); i++) | ||
| 406 | h->last_pocs[i] = INT_MIN; | 399 | h->last_pocs[i] = INT_MIN; |
| 407 | if (h->default_ref[list].parent | 400 | if (h->default_ref[list].parent |
| 408 | && !(!FIELD_PICTURE(h) && (h->default_ref[list].reference&3) != 3)) | 401 | && !(!FIELD_PICTURE(h) && (h->default_ref[list].reference&3) != 3)) |
| @@ -433,16 +426,14 @@ int ff_h264_build_ref_list(H264Context *h, H264SliceContext *sl) · 24 unmodified lines | |||
| 433 | 426 | ||
| 434 | int ff_h264_decode_ref_pic_list_reordering(H264SliceContext *sl, void *logctx) | 427 | int ff_h264_decode_ref_pic_list_reordering(H264SliceContext *sl, void *logctx) |
| 435 | { | 428 | { |
| 436 | int list, index; | ||
| 437 | |||
| 438 | sl->nb_ref_modifications[0] = 0; | 429 | sl->nb_ref_modifications[0] = 0; |
| 439 | sl->nb_ref_modifications[1] = 0; | 430 | sl->nb_ref_modifications[1] = 0; |
| 440 | 431 | ||
| 441 | for (list = 0; list < sl->list_count; list++) { | 432 | for (int list = 0; list < sl->list_count; list++) { |
| 442 | if (!get_bits1(&sl->gb)) // ref_pic_list_modification_flag_l[01] | 433 | if (!get_bits1(&sl->gb)) // ref_pic_list_modification_flag_l[01] |
| 443 | continue; | 434 | continue; |
| 444 | 435 | ||
| 445 | for (index = 0; ; index++) { | 436 | for (int index = 0; ; index++) { |
| 446 | unsigned int op = get_ue_golomb_31(&sl->gb); | 437 | unsigned int op = get_ue_golomb_31(&sl->gb); |
| 447 | 438 | ||
| 448 | if (op == 3) | 439 | if (op == 3) |
| @@ -479,11 +470,10 @@ int ff_h264_decode_ref_pic_list_reordering(H264SliceContext *sl, void *logctx) · 30 unmodified lines | |||
| 479 | */ | 470 | */ |
| 480 | static inline int unreference_pic(H264Context *h, H264Picture *pic, int refmask) | 471 | static inline int unreference_pic(H264Context *h, H264Picture *pic, int refmask) |
| 481 | { | 472 | { |
| 482 | int i; | ||
| 483 | if (pic->reference &= refmask) { | 473 | if (pic->reference &= refmask) { |
| 484 | return 0; | 474 | return 0; |
| 485 | } else { | 475 | } else { |
| 486 | for(i = 0; h->delayed_pic[i]; i++) | 476 | for (int i = 0; h->delayed_pic[i]; i++) |
| 487 | if(pic == h->delayed_pic[i]){ | 477 | if(pic == h->delayed_pic[i]){ |
| 488 | pic->reference = DELAYED_PIC_REF; | 478 | pic->reference = DELAYED_PIC_REF; |
| 489 | break; | 479 | break; |
| @@ -502,9 +492,7 @@ static inline int unreference_pic(H264Context *h, H264Picture *pic, int refmask) · 12 unmodified lines | |||
| 502 | */ | 492 | */ |
| 503 | static H264Picture *find_short(H264Context *h, int frame_num, int *idx) | 493 | static H264Picture *find_short(H264Context *h, int frame_num, int *idx) |
| 504 | { | 494 | { |
| 505 | int i; | 495 | for (int i = 0; i < h->short_ref_count; i++) { |
| 506 | |||
| 507 | for (i = 0; i < h->short_ref_count; i++) { | ||
| 508 | H264Picture *pic = h->short_ref[i]; | 496 | H264Picture *pic = h->short_ref[i]; |
| 509 | if (h->avctx->debug & FF_DEBUG_MMCO) | 497 | if (h->avctx->debug & FF_DEBUG_MMCO) |
| 510 | av_log(h->avctx, AV_LOG_DEBUG, "%d %d %p\n", i, pic->frame_num, pic); | 498 | av_log(h->avctx, AV_LOG_DEBUG, "%d %d %p\n", i, pic->frame_num, pic); |
| @@ -575,11 +563,8 @@ static H264Picture *remove_long(H264Context *h, int i, int ref_mask) · 64 unmodified lines | |||
| 575 | 563 | ||
| 576 | void ff_h264_remove_all_refs(H264Context *h) | 564 | void ff_h264_remove_all_refs(H264Context *h) |
| 577 | { | 565 | { |
| 578 | int i; | 566 | for (int i = 0; i < 16; i++) |
| 579 | |||
| 580 | for (i = 0; i < 16; i++) { | ||
| 581 | remove_long(h, i, 0); | 567 | remove_long(h, i, 0); |
| 582 | } | ||
| 583 | assert(h->long_ref_count == 0); | 568 | assert(h->long_ref_count == 0); |
| 584 | 569 | ||
| 585 | if (h->short_ref_count && !h->last_pic_for_ec.f->data[0]) { | 570 | if (h->short_ref_count && !h->last_pic_for_ec.f->data[0]) { |
| @@ -587,7 +572,7 @@ void ff_h264_remove_all_refs(H264Context *h) · 1 unmodified line | |||
| 587 | ff_h264_ref_picture(&h->last_pic_for_ec, h->short_ref[0]); | 572 | ff_h264_ref_picture(&h->last_pic_for_ec, h->short_ref[0]); |
| 588 | } | 573 | } |
| 589 | 574 | ||
| 590 | for (i = 0; i < h->short_ref_count; i++) { | 575 | for (int i = 0; i < h->short_ref_count; i++) { |
| 591 | unreference_pic(h, h->short_ref[i], 0); | 576 | unreference_pic(h, h->short_ref[i], 0); |
| 592 | h->short_ref[i] = NULL; | 577 | h->short_ref[i] = NULL; |
| 593 | } | 578 | } |
| @@ -622,10 +607,8 @@ int ff_h264_execute_ref_pic_marking(H264Context *h) · 28 unmodified lines | |||
| 622 | { | 607 | { |
| 623 | MMCO *mmco = h->mmco; | 608 | MMCO *mmco = h->mmco; |
| 624 | int mmco_count; | 609 | int mmco_count; |
| 625 | int i, av_uninit(j); | ||
| 626 | int pps_ref_count[2] = {0}; | 610 | int pps_ref_count[2] = {0}; |
| 627 | int current_ref_assigned = 0, err = 0; | 611 | int current_ref_assigned = 0, err = 0; |
| 628 | H264Picture *av_uninit(pic); | ||
| 629 | 612 | ||
| 630 | if (!h->ps.sps) { | 613 | if (!h->ps.sps) { |
| 631 | av_log(h->avctx, AV_LOG_ERROR, "SPS is unset\n"); | 614 | av_log(h->avctx, AV_LOG_ERROR, "SPS is unset\n"); |
| @@ -640,17 +623,18 @@ int ff_h264_execute_ref_pic_marking(H264Context *h) · 8 unmodified lines | |||
| 640 | if ((h->avctx->debug & FF_DEBUG_MMCO) && mmco_count == 0) | 623 | if ((h->avctx->debug & FF_DEBUG_MMCO) && mmco_count == 0) |
| 641 | av_log(h->avctx, AV_LOG_DEBUG, "no mmco here\n"); | 624 | av_log(h->avctx, AV_LOG_DEBUG, "no mmco here\n"); |
| 642 | 625 | ||
| 643 | for (i = 0; i < mmco_count; i++) { | 626 | for (int i = 0; i < mmco_count; i++) { |
| 644 | int av_uninit(structure), av_uninit(frame_num); | ||
| 645 | if (h->avctx->debug & FF_DEBUG_MMCO) | 627 | if (h->avctx->debug & FF_DEBUG_MMCO) |
| 646 | av_log(h->avctx, AV_LOG_DEBUG, "mmco:%d %d %d\n", h->mmco[i].opcode, | 628 | av_log(h->avctx, AV_LOG_DEBUG, "mmco:%d %d %d\n", h->mmco[i].opcode, |
| 647 | h->mmco[i].short_pic_num, h->mmco[i].long_arg); | 629 | h->mmco[i].short_pic_num, h->mmco[i].long_arg); |
| 648 | 630 | ||
| 649 | switch (mmco[i].opcode) { | 631 | switch (mmco[i].opcode) { |
| 650 | case MMCO_SHORT2UNUSED: | 632 | case MMCO_SHORT2UNUSED: |
| 651 | case MMCO_SHORT2LONG: | 633 | case MMCO_SHORT2LONG: { |
| 652 | frame_num = pic_num_extract(h, mmco[i].short_pic_num, &structure); | 634 | int structure, j; |
| 653 | pic = find_short(h, frame_num, &j); | 635 | int frame_num = pic_num_extract(h, mmco[i].short_pic_num, &structure); |
| 636 | H264Picture *pic = find_short(h, frame_num, &j); | ||
| 637 | |||
| 654 | if (!pic) { | 638 | if (!pic) { |
| 655 | if (mmco[i].opcode != MMCO_SHORT2LONG || | 639 | if (mmco[i].opcode != MMCO_SHORT2LONG || |
| 656 | !h->long_ref[mmco[i].long_arg] || | 640 | !h->long_ref[mmco[i].long_arg] || |
| @@ -677,14 +661,16 @@ int ff_h264_execute_ref_pic_marking(H264Context *h) · 20 unmodified lines | |||
| 677 | } | 661 | } |
| 678 | } | 662 | } |
| 679 | break; | 663 | break; |
| 680 | case MMCO_LONG2UNUSED: | 664 | } |
| 681 | j = pic_num_extract(h, mmco[i].long_arg, &structure); | 665 | case MMCO_LONG2UNUSED: { |
| 682 | pic = h->long_ref[j]; | 666 | int structure, j = pic_num_extract(h, mmco[i].long_arg, &structure); |
| 667 | H264Picture *pic = h->long_ref[j]; | ||
| 683 | if (pic) { | 668 | if (pic) { |
| 684 | remove_long(h, j, structure ^ PICT_FRAME); | 669 | remove_long(h, j, structure ^ PICT_FRAME); |
| 685 | } else if (h->avctx->debug & FF_DEBUG_MMCO) | 670 | } else if (h->avctx->debug & FF_DEBUG_MMCO) |
| 686 | av_log(h->avctx, AV_LOG_DEBUG, "mmco: unref long failure\n"); | 671 | av_log(h->avctx, AV_LOG_DEBUG, "mmco: unref long failure\n"); |
| 687 | break; | 672 | break; |
| 673 | } | ||
| 688 | case MMCO_LONG: | 674 | case MMCO_LONG: |
| 689 | // Comment below left from previous code as it is an interesting note. | 675 | // Comment below left from previous code as it is an interesting note. |
| 690 | /* First field in pair is in short term list or | 676 | /* First field in pair is in short term list or |
| @@ -700,7 +686,7 @@ int ff_h264_execute_ref_pic_marking(H264Context *h) · 9 unmodified lines | |||
| 700 | 686 | ||
| 701 | /* make sure the current picture is not already assigned as a long ref */ | 687 | /* make sure the current picture is not already assigned as a long ref */ |
| 702 | if (h->cur_pic_ptr->long_ref) { | 688 | if (h->cur_pic_ptr->long_ref) { |
| 703 | for (j = 0; j < FF_ARRAY_ELEMS(h->long_ref); j++) { | 689 | for (int j = 0; j < FF_ARRAY_ELEMS(h->long_ref); j++) { |
| 704 | if (h->long_ref[j] == h->cur_pic_ptr) { | 690 | if (h->long_ref[j] == h->cur_pic_ptr) { |
| 705 | if (j != mmco[i].long_arg) | 691 | if (j != mmco[i].long_arg) |
| 706 | av_log(h->avctx, AV_LOG_ERROR, "mmco: cannot assign current picture to 2 long term references\n"); | 692 | av_log(h->avctx, AV_LOG_ERROR, "mmco: cannot assign current picture to 2 long term references\n"); |
| @@ -724,21 +710,19 @@ int ff_h264_execute_ref_pic_marking(H264Context *h) · 17 unmodified lines | |||
| 724 | case MMCO_SET_MAX_LONG: | 710 | case MMCO_SET_MAX_LONG: |
| 725 | assert(mmco[i].long_arg <= 16); | 711 | assert(mmco[i].long_arg <= 16); |
| 726 | // just remove the long term which index is greater than new max | 712 | // just remove the long term which index is greater than new max |
| 727 | for (j = mmco[i].long_arg; j < 16; j++) { | 713 | for (int j = mmco[i].long_arg; j < 16; j++) |
| 728 | remove_long(h, j, 0); | 714 | remove_long(h, j, 0); |
| 729 | } | ||
| 730 | break; | 715 | break; |
| 731 | case MMCO_RESET: | 716 | case MMCO_RESET: |
| 732 | while (h->short_ref_count) { | 717 | while (h->short_ref_count) { |
| 733 | remove_short(h, h->short_ref[0]->frame_num, 0); | 718 | remove_short(h, h->short_ref[0]->frame_num, 0); |
| 734 | } | 719 | } |
| 735 | for (j = 0; j < 16; j++) { | 720 | for (int j = 0; j < 16; j++) |
| 736 | remove_long(h, j, 0); | 721 | remove_long(h, j, 0); |
| 737 | } | ||
| 738 | h->poc.frame_num = h->cur_pic_ptr->frame_num = 0; | 722 | h->poc.frame_num = h->cur_pic_ptr->frame_num = 0; |
| 739 | h->mmco_reset = 1; | 723 | h->mmco_reset = 1; |
| 740 | h->cur_pic_ptr->mmco_reset = 1; | 724 | h->cur_pic_ptr->mmco_reset = 1; |
| 741 | for (j = 0; j < FF_ARRAY_ELEMS(h->last_pocs); j++) | 725 | for (int j = 0; j < FF_ARRAY_ELEMS(h->last_pocs); j++) |
| 742 | h->last_pocs[j] = INT_MIN; | 726 | h->last_pocs[j] = INT_MIN; |
| 743 | break; | 727 | break; |
| 744 | default: av_assert0(0); | 728 | default: av_assert0(0); |
| @@ -762,7 +746,7 @@ int ff_h264_execute_ref_pic_marking(H264Context *h) · 17 unmodified lines | |||
| 762 | "(first field is long term)\n"); | 746 | "(first field is long term)\n"); |
| 763 | err = AVERROR_INVALIDDATA; | 747 | err = AVERROR_INVALIDDATA; |
| 764 | } else { | 748 | } else { |
| 765 | pic = remove_short(h, h->cur_pic_ptr->frame_num, 0); | 749 | H264Picture *pic = remove_short(h, h->cur_pic_ptr->frame_num, 0); |
| 766 | if (pic) { | 750 | if (pic) { |
| 767 | av_log(h->avctx, AV_LOG_ERROR, "illegal short term buffer state detected\n"); | 751 | av_log(h->avctx, AV_LOG_ERROR, "illegal short term buffer state detected\n"); |
| 768 | err = AVERROR_INVALIDDATA; | 752 | err = AVERROR_INVALIDDATA; |
| @@ -791,6 +775,7 @@ int ff_h264_execute_ref_pic_marking(H264Context *h) · 22 unmodified lines | |||
| 791 | err = AVERROR_INVALIDDATA; | 775 | err = AVERROR_INVALIDDATA; |
| 792 | 776 | ||
| 793 | if (h->long_ref_count && !h->short_ref_count) { | 777 | if (h->long_ref_count && !h->short_ref_count) { |
| 778 | int i; | ||
| 794 | for (i = 0; i < 16; ++i) | 779 | for (i = 0; i < 16; ++i) |
| 795 | if (h->long_ref[i]) | 780 | if (h->long_ref[i]) |
| 796 | break; | 781 | break; |
| @@ -798,13 +783,13 @@ int ff_h264_execute_ref_pic_marking(H264Context *h) · 1 unmodified line | |||
| 798 | assert(i < 16); | 783 | assert(i < 16); |
| 799 | remove_long(h, i, 0); | 784 | remove_long(h, i, 0); |
| 800 | } else { | 785 | } else { |
| 801 | pic = h->short_ref[h->short_ref_count - 1]; | 786 | H264Picture *pic = h->short_ref[h->short_ref_count - 1]; |
| 802 | remove_short(h, pic->frame_num, 0); | 787 | remove_short(h, pic->frame_num, 0); |
| 803 | } | 788 | } |
| 804 | } | 789 | } |
| 805 | 790 | ||
| 806 | for (i = 0; i<h->short_ref_count; i++) { | 791 | for (int i = 0; i < h->short_ref_count; i++) { |
| 807 | pic = h->short_ref[i]; | 792 | H264Picture *pic = h->short_ref[i]; |
| 808 | if (pic->invalid_gap) { | 793 | if (pic->invalid_gap) { |
| 809 | int d = av_mod_uintp2(h->cur_pic_ptr->frame_num - pic->frame_num, h->ps.sps->log2_max_frame_num); | 794 | int d = av_mod_uintp2(h->cur_pic_ptr->frame_num - pic->frame_num, h->ps.sps->log2_max_frame_num); |
| 810 | if (d > h->ps.sps->ref_frame_count) | 795 | if (d > h->ps.sps->ref_frame_count) |
| @@ -815,7 +800,7 @@ int ff_h264_execute_ref_pic_marking(H264Context *h) · 4 unmodified lines | |||
| 815 | print_short_term(h); | 800 | print_short_term(h); |
| 816 | print_long_term(h); | 801 | print_long_term(h); |
| 817 | 802 | ||
| 818 | for (i = 0; i < FF_ARRAY_ELEMS(h->ps.pps_list); i++) { | 803 | for (int i = 0; i < FF_ARRAY_ELEMS(h->ps.pps_list); i++) { |
| 819 | if (h->ps.pps_list[i]) { | 804 | if (h->ps.pps_list[i]) { |
| 820 | const PPS *pps = h->ps.pps_list[i]; | 805 | const PPS *pps = h->ps.pps_list[i]; |
| 821 | pps_ref_count[0] = FFMAX(pps_ref_count[0], pps->ref_count[0]); | 806 | pps_ref_count[0] = FFMAX(pps_ref_count[0], pps->ref_count[0]); |
| @@ -843,7 +828,6 @@ out: · 21 unmodified lines | |||
| 843 | int ff_h264_decode_ref_pic_marking(H264SliceContext *sl, GetBitContext *gb, | 828 | int ff_h264_decode_ref_pic_marking(H264SliceContext *sl, GetBitContext *gb, |
| 844 | const H2645NAL *nal, void *logctx) | 829 | const H2645NAL *nal, void *logctx) |
| 845 | { | 830 | { |
| 846 | int i; | ||
| 847 | MMCO *mmco = sl->mmco; | 831 | MMCO *mmco = sl->mmco; |
| 848 | int nb_mmco = 0; | 832 | int nb_mmco = 0; |
| 849 | 833 | ||
| @@ -858,6 +842,7 @@ int ff_h264_decode_ref_pic_marking(H264SliceContext *sl, GetBitContext *gb, · 8 unmodified lines | |||
| 858 | } else { | 842 | } else { |
| 859 | sl->explicit_ref_marking = get_bits1(gb); | 843 | sl->explicit_ref_marking = get_bits1(gb); |
| 860 | if (sl->explicit_ref_marking) { | 844 | if (sl->explicit_ref_marking) { |
| 845 | int i; | ||
| 861 | for (i = 0; i < FF_ARRAY_ELEMS(sl->mmco); i++) { | 846 | for (i = 0; i < FF_ARRAY_ELEMS(sl->mmco); i++) { |
| 862 | MMCOOpcode opcode = get_ue_golomb_31(gb); | 847 | MMCOOpcode opcode = get_ue_golomb_31(gb); |
| 863 | 848 | ||