History

avcodec/h264_refs: Use smaller scope, don't use av_uninit

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.

Andreas Rheinhardt committed 2 years ago

Commit 348461e1 parent ac14d681 file · +53 −68Browse files

Showing the changes to libavcodec (1 of 1 file). Show all

Unified · Split

libavcodec/h264_refs.c+53−68
@@ -38,8 +38,7 @@ · 37 unmodified lines
3838
3939 static void pic_as_field(H264Ref *pic, const int parity)
4040 {
41− int i;
42− for (i = 0; i < FF_ARRAY_ELEMS(pic->data); ++i) {
41+ for (int i = 0; i < FF_ARRAY_ELEMS(pic->data); ++i) {
4342 if (parity == PICT_BOTTOM_FIELD)
4443 pic->data[i] += pic->linesize[i];
4544 pic->reference = parity;
@@ -104,13 +103,12 @@ static int build_def_list(H264Ref *def, int def_len, · 58 unmodified lines
104103 static int add_sorted(H264Picture **sorted, H264Picture * const *src,
105104 int len, int limit, int dir)
106105 {
107− int i, best_poc;
108106 int out_i = 0;
109107
110108 for (;;) {
111− best_poc = dir ? INT_MIN : INT_MAX;
109+ int best_poc = dir ? INT_MIN : INT_MAX;
112110
113− for (i = 0; i < len; i++) {
111+ for (int i = 0; i < len; i++) {
114112 const int poc = src[i]->poc;
115113 if (((poc > limit) ^ dir) && ((poc < best_poc) ^ dir)) {
116114 best_poc = poc;
@@ -134,12 +132,11 @@ static int mismatches_ref(const H264Context *h, const H264Picture *pic) · 17 unmodified lines
134132
135133 static void h264_initialise_ref_list(H264Context *h, H264SliceContext *sl)
136134 {
137− int i, len;
138− int j;
135+ int len;
139136
140137 if (sl->slice_type_nos == AV_PICTURE_TYPE_B) {
141138 H264Picture *sorted[32];
142− int cur_poc, list;
139+ int cur_poc;
143140 int lens[2];
144141
145142 if (FIELD_PICTURE(h))
@@ -147,7 +144,7 @@ static void h264_initialise_ref_list(H264Context *h, H264SliceContext *sl) · 1 unmodified line
147144 else
148145 cur_poc = h->cur_pic_ptr->poc;
149146
150− for (list = 0; list < 2; list++) {
147+ for (int list = 0; list < 2; list++) {
151148 len = add_sorted(sorted, h->short_ref, h->short_ref_count, cur_poc, 1 ^ list);
152149 len += add_sorted(sorted + len, h->short_ref, h->short_ref_count, cur_poc, 0 ^ list);
153150 av_assert0(len <= 32);
@@ -165,6 +162,7 @@ static void h264_initialise_ref_list(H264Context *h, H264SliceContext *sl) · 11 unmodified lines
165162 }
166163
167164 if (lens[0] == lens[1] && lens[1] > 1) {
165+ int i;
168166 for (i = 0; i < lens[0] &&
169167 sl->ref_list[0][i].parent->f->buf[0]->buffer ==
170168 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
184182 memset(&sl->ref_list[0][len], 0, sizeof(H264Ref) * (sl->ref_count[0] - len));
185183 }
186184 #ifdef TRACE
187− for (i = 0; i < sl->ref_count[0]; i++) {
185+ for (int i = 0; i < sl->ref_count[0]; i++) {
188186 ff_tlog(h->avctx, "List0: %s fn:%d 0x%p\n",
189187 (sl->ref_list[0][i].parent ? (sl->ref_list[0][i].parent->long_ref ? "LT" : "ST") : "??"),
190188 sl->ref_list[0][i].pic_id,
191189 sl->ref_list[0][i].data[0]);
192190 }
193191 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++) {
195193 ff_tlog(h->avctx, "List1: %s fn:%d 0x%p\n",
196194 (sl->ref_list[1][i].parent ? (sl->ref_list[1][i].parent->long_ref ? "LT" : "ST") : "??"),
197195 sl->ref_list[1][i].pic_id,
@@ -200,8 +198,8 @@ static void h264_initialise_ref_list(H264Context *h, H264SliceContext *sl) · 2 unmodified lines
200198 }
201199 #endif
202200
203− for (j = 0; j<1+(sl->slice_type_nos == AV_PICTURE_TYPE_B); j++) {
204− for (i = 0; i < sl->ref_count[j]; i++) {
201+ for (int j = 0; j < 1 + (sl->slice_type_nos == AV_PICTURE_TYPE_B); j++) {
202+ for (int i = 0; i < sl->ref_count[j]; i++) {
205203 if (sl->ref_list[j][i].parent) {
206204 if (mismatches_ref(h, sl->ref_list[j][i].parent)) {
207205 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
210208 }
211209 }
212210 }
213− for (i = 0; i < sl->list_count; i++)
211+ for (int i = 0; i < sl->list_count; i++)
214212 h->default_ref[i] = sl->ref_list[i][0];
215213 }
216214
@@ -219,10 +217,9 @@ static void h264_initialise_ref_list(H264Context *h, H264SliceContext *sl) · 2 unmodified lines
219217 */
220218 static void print_short_term(const H264Context *h)
221219 {
222− uint32_t i;
223220 if (h->avctx->debug & FF_DEBUG_MMCO) {
224221 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++) {
226223 H264Picture *pic = h->short_ref[i];
227224 av_log(h->avctx, AV_LOG_DEBUG, "%"PRIu32" fn:%d poc:%d %p\n",
228225 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
235232 */
236233 static void print_long_term(const H264Context *h)
237234 {
238− uint32_t i;
239235 if (h->avctx->debug & FF_DEBUG_MMCO) {
240236 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++) {
242238 H264Picture *pic = h->long_ref[i];
243239 if (pic) {
244240 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
273269
274270 static void h264_fill_mbaff_ref_list(H264SliceContext *sl)
275271 {
276− int list, i, j;
277− for (list = 0; list < sl->list_count; list++) {
278− for (i = 0; i < sl->ref_count[list]; i++) {
272+ for (int list = 0; list < sl->list_count; list++) {
273+ for (int i = 0; i < sl->ref_count[list]; i++) {
279274 const H264Ref *frame = &sl->ref_list[list][i];
280275 H264Ref *field = &sl->ref_list[list][16 + 2 * i];
281276
282277 field[0] = *frame;
283278
284− for (j = 0; j < 3; j++)
279+ for (int j = 0; j < 3; j++)
285280 field[0].linesize[j] <<= 1;
286281 field[0].reference = PICT_TOP_FIELD;
287282 field[0].poc = field[0].parent->field_poc[0];
288283
289284 field[1] = field[0];
290285
291− for (j = 0; j < 3; j++)
286+ for (int j = 0; j < 3; j++)
292287 field[1].data[j] += frame->parent->f->linesize[j];
293288 field[1].reference = PICT_BOTTOM_FIELD;
294289 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
298293
299294 int ff_h264_build_ref_list(H264Context *h, H264SliceContext *sl)
300295 {
301− int list, index, pic_structure;
302−
303296 print_short_term(h);
304297 print_long_term(h);
305298
306299 h264_initialise_ref_list(h, sl);
307300
308− for (list = 0; list < sl->list_count; list++) {
301+ for (int list = 0; list < sl->list_count; list++) {
309302 int pred = sl->curr_pic_num;
310303
311− for (index = 0; index < sl->nb_ref_modifications[list]; index++) {
304+ for (int index = 0; index < sl->nb_ref_modifications[list]; index++) {
312305 unsigned int modification_of_pic_nums_idc = sl->ref_modifications[list][index].op;
313306 unsigned int val = sl->ref_modifications[list][index].val;
314307 unsigned int pic_id;
315− int i;
308+ int i, pic_structure;
316309 H264Picture *ref = NULL;
317310
318311 switch (modification_of_pic_nums_idc) {
@@ -396,13 +389,13 @@ int ff_h264_build_ref_list(H264Context *h, H264SliceContext *sl) · 77 unmodified lines
396389 }
397390 }
398391 }
399− for (list = 0; list < sl->list_count; list++) {
400− for (index = 0; index < sl->ref_count[list]; index++) {
392+ for (int list = 0; list < sl->list_count; list++) {
393+ for (int index = 0; index < sl->ref_count[list]; index++) {
401394 if ( !sl->ref_list[list][index].parent
402395 || (!FIELD_PICTURE(h) && (sl->ref_list[list][index].reference&3) != 3)) {
403− int i;
404396 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++)
406399 h->last_pocs[i] = INT_MIN;
407400 if (h->default_ref[list].parent
408401 && !(!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
433426
434427 int ff_h264_decode_ref_pic_list_reordering(H264SliceContext *sl, void *logctx)
435428 {
436− int list, index;
437−
438429 sl->nb_ref_modifications[0] = 0;
439430 sl->nb_ref_modifications[1] = 0;
440431
441− for (list = 0; list < sl->list_count; list++) {
432+ for (int list = 0; list < sl->list_count; list++) {
442433 if (!get_bits1(&sl->gb)) // ref_pic_list_modification_flag_l[01]
443434 continue;
444435
445− for (index = 0; ; index++) {
436+ for (int index = 0; ; index++) {
446437 unsigned int op = get_ue_golomb_31(&sl->gb);
447438
448439 if (op == 3)
@@ -479,11 +470,10 @@ int ff_h264_decode_ref_pic_list_reordering(H264SliceContext *sl, void *logctx) · 30 unmodified lines
479470 */
480471 static inline int unreference_pic(H264Context *h, H264Picture *pic, int refmask)
481472 {
482− int i;
483473 if (pic->reference &= refmask) {
484474 return 0;
485475 } else {
486− for(i = 0; h->delayed_pic[i]; i++)
476+ for (int i = 0; h->delayed_pic[i]; i++)
487477 if(pic == h->delayed_pic[i]){
488478 pic->reference = DELAYED_PIC_REF;
489479 break;
@@ -502,9 +492,7 @@ static inline int unreference_pic(H264Context *h, H264Picture *pic, int refmask) · 12 unmodified lines
502492 */
503493 static H264Picture *find_short(H264Context *h, int frame_num, int *idx)
504494 {
505− int i;
506−
507− for (i = 0; i < h->short_ref_count; i++) {
495+ for (int i = 0; i < h->short_ref_count; i++) {
508496 H264Picture *pic = h->short_ref[i];
509497 if (h->avctx->debug & FF_DEBUG_MMCO)
510498 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
575563
576564 void ff_h264_remove_all_refs(H264Context *h)
577565 {
578− int i;
579−
580− for (i = 0; i < 16; i++) {
566+ for (int i = 0; i < 16; i++)
581567 remove_long(h, i, 0);
582− }
583568 assert(h->long_ref_count == 0);
584569
585570 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
587572 ff_h264_ref_picture(&h->last_pic_for_ec, h->short_ref[0]);
588573 }
589574
590− for (i = 0; i < h->short_ref_count; i++) {
575+ for (int i = 0; i < h->short_ref_count; i++) {
591576 unreference_pic(h, h->short_ref[i], 0);
592577 h->short_ref[i] = NULL;
593578 }
@@ -622,10 +607,8 @@ int ff_h264_execute_ref_pic_marking(H264Context *h) · 28 unmodified lines
622607 {
623608 MMCO *mmco = h->mmco;
624609 int mmco_count;
625− int i, av_uninit(j);
626610 int pps_ref_count[2] = {0};
627611 int current_ref_assigned = 0, err = 0;
628− H264Picture *av_uninit(pic);
629612
630613 if (!h->ps.sps) {
631614 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
640623 if ((h->avctx->debug & FF_DEBUG_MMCO) && mmco_count == 0)
641624 av_log(h->avctx, AV_LOG_DEBUG, "no mmco here\n");
642625
643− for (i = 0; i < mmco_count; i++) {
644− int av_uninit(structure), av_uninit(frame_num);
626+ for (int i = 0; i < mmco_count; i++) {
645627 if (h->avctx->debug & FF_DEBUG_MMCO)
646628 av_log(h->avctx, AV_LOG_DEBUG, "mmco:%d %d %d\n", h->mmco[i].opcode,
647629 h->mmco[i].short_pic_num, h->mmco[i].long_arg);
648630
649631 switch (mmco[i].opcode) {
650632 case MMCO_SHORT2UNUSED:
651− case MMCO_SHORT2LONG:
652− frame_num = pic_num_extract(h, mmco[i].short_pic_num, &structure);
653− pic = find_short(h, frame_num, &j);
633+ case MMCO_SHORT2LONG: {
634+ int structure, 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+
654638 if (!pic) {
655639 if (mmco[i].opcode != MMCO_SHORT2LONG ||
656640 !h->long_ref[mmco[i].long_arg] ||
@@ -677,14 +661,16 @@ int ff_h264_execute_ref_pic_marking(H264Context *h) · 20 unmodified lines
677661 }
678662 }
679663 break;
680− case MMCO_LONG2UNUSED:
681− j = pic_num_extract(h, mmco[i].long_arg, &structure);
682− pic = h->long_ref[j];
664+ }
665+ case MMCO_LONG2UNUSED: {
666+ int structure, j = pic_num_extract(h, mmco[i].long_arg, &structure);
667+ H264Picture *pic = h->long_ref[j];
683668 if (pic) {
684669 remove_long(h, j, structure ^ PICT_FRAME);
685670 } else if (h->avctx->debug & FF_DEBUG_MMCO)
686671 av_log(h->avctx, AV_LOG_DEBUG, "mmco: unref long failure\n");
687672 break;
673+ }
688674 case MMCO_LONG:
689675 // Comment below left from previous code as it is an interesting note.
690676 /* 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
700686
701687 /* make sure the current picture is not already assigned as a long ref */
702688 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++) {
704690 if (h->long_ref[j] == h->cur_pic_ptr) {
705691 if (j != mmco[i].long_arg)
706692 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
724710 case MMCO_SET_MAX_LONG:
725711 assert(mmco[i].long_arg <= 16);
726712 // 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++)
728714 remove_long(h, j, 0);
729− }
730715 break;
731716 case MMCO_RESET:
732717 while (h->short_ref_count) {
733718 remove_short(h, h->short_ref[0]->frame_num, 0);
734719 }
735− for (j = 0; j < 16; j++) {
720+ for (int j = 0; j < 16; j++)
736721 remove_long(h, j, 0);
737− }
738722 h->poc.frame_num = h->cur_pic_ptr->frame_num = 0;
739723 h->mmco_reset = 1;
740724 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++)
742726 h->last_pocs[j] = INT_MIN;
743727 break;
744728 default: av_assert0(0);
@@ -762,7 +746,7 @@ int ff_h264_execute_ref_pic_marking(H264Context *h) · 17 unmodified lines
762746 "(first field is long term)\n");
763747 err = AVERROR_INVALIDDATA;
764748 } 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);
766750 if (pic) {
767751 av_log(h->avctx, AV_LOG_ERROR, "illegal short term buffer state detected\n");
768752 err = AVERROR_INVALIDDATA;
@@ -791,6 +775,7 @@ int ff_h264_execute_ref_pic_marking(H264Context *h) · 22 unmodified lines
791775 err = AVERROR_INVALIDDATA;
792776
793777 if (h->long_ref_count && !h->short_ref_count) {
778+ int i;
794779 for (i = 0; i < 16; ++i)
795780 if (h->long_ref[i])
796781 break;
@@ -798,13 +783,13 @@ int ff_h264_execute_ref_pic_marking(H264Context *h) · 1 unmodified line
798783 assert(i < 16);
799784 remove_long(h, i, 0);
800785 } else {
801− pic = h->short_ref[h->short_ref_count - 1];
786+ H264Picture *pic = h->short_ref[h->short_ref_count - 1];
802787 remove_short(h, pic->frame_num, 0);
803788 }
804789 }
805790
806− for (i = 0; i<h->short_ref_count; i++) {
807− pic = h->short_ref[i];
791+ for (int i = 0; i < h->short_ref_count; i++) {
792+ H264Picture *pic = h->short_ref[i];
808793 if (pic->invalid_gap) {
809794 int d = av_mod_uintp2(h->cur_pic_ptr->frame_num - pic->frame_num, h->ps.sps->log2_max_frame_num);
810795 if (d > h->ps.sps->ref_frame_count)
@@ -815,7 +800,7 @@ int ff_h264_execute_ref_pic_marking(H264Context *h) · 4 unmodified lines
815800 print_short_term(h);
816801 print_long_term(h);
817802
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++) {
819804 if (h->ps.pps_list[i]) {
820805 const PPS *pps = h->ps.pps_list[i];
821806 pps_ref_count[0] = FFMAX(pps_ref_count[0], pps->ref_count[0]);
@@ -843,7 +828,6 @@ out: · 21 unmodified lines
843828 int ff_h264_decode_ref_pic_marking(H264SliceContext *sl, GetBitContext *gb,
844829 const H2645NAL *nal, void *logctx)
845830 {
846− int i;
847831 MMCO *mmco = sl->mmco;
848832 int nb_mmco = 0;
849833
@@ -858,6 +842,7 @@ int ff_h264_decode_ref_pic_marking(H264SliceContext *sl, GetBitContext *gb, · 8 unmodified lines
858842 } else {
859843 sl->explicit_ref_marking = get_bits1(gb);
860844 if (sl->explicit_ref_marking) {
845+ int i;
861846 for (i = 0; i < FF_ARRAY_ELEMS(sl->mmco); i++) {
862847 MMCOOpcode opcode = get_ue_golomb_31(gb);
863848

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t