FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/mpeg_er.c
Date: 2025-06-01 09:29:47
Exec Total Coverage
Lines: 66 72 91.7%
Functions: 4 4 100.0%
Branches: 11 14 78.6%

Line Branch Exec Source
1 /*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include "libavutil/avassert.h"
20 #include "libavutil/mem.h"
21 #include "error_resilience.h"
22 #include "mpegvideo.h"
23 #include "mpegvideodec.h"
24 #include "mpeg_er.h"
25
26 33681 static void set_erpic(ERPicture *dst, const MPVPicture *src)
27 {
28 int i;
29
30 33681 memset(dst, 0, sizeof(*dst));
31
2/2
✓ Branch 0 taken 313 times.
✓ Branch 1 taken 33368 times.
33681 if (!src)
32 313 return;
33
34 33368 dst->f = src->f;
35 33368 dst->progress = &src->progress;
36
37
2/2
✓ Branch 0 taken 66736 times.
✓ Branch 1 taken 33368 times.
100104 for (i = 0; i < 2; i++) {
38 66736 dst->motion_val[i] = src->motion_val[i];
39 66736 dst->ref_index[i] = src->ref_index[i];
40 }
41
42 33368 dst->mb_type = src->mb_type;
43 33368 dst->field_picture = src->field_picture;
44 }
45
46 11227 void ff_mpeg_er_frame_start(MpegEncContext *s)
47 {
48 11227 ERContext *er = &s->er;
49
50 11227 set_erpic(&er->cur_pic, s->cur_pic.ptr);
51 11227 set_erpic(&er->next_pic, s->next_pic.ptr);
52 11227 set_erpic(&er->last_pic, s->last_pic.ptr);
53
54 11227 er->pp_time = s->pp_time;
55 11227 er->pb_time = s->pb_time;
56 11227 er->quarter_sample = s->quarter_sample;
57 11227 er->partitioned_frame = s->partitioned_frame;
58
59 11227 ff_er_frame_start(er);
60 11227 }
61
62 59282 static void mpeg_er_decode_mb(void *opaque, int ref, int mv_dir, int mv_type,
63 int (*mv)[2][4][2], int mb_x, int mb_y,
64 int mb_intra, int mb_skipped)
65 {
66 59282 MpegEncContext *s = opaque;
67
68 av_assert1(!mb_intra);
69
70 59282 s->mv_dir = mv_dir;
71 59282 s->mv_type = mv_type;
72 59282 s->mb_intra = mb_intra;
73 59282 s->mb_skipped = mb_skipped;
74 59282 s->mb_x = mb_x;
75 59282 s->mb_y = mb_y;
76 59282 s->mcsel = 0;
77 59282 memcpy(s->mv, mv, sizeof(*mv));
78
79 // The following disables the IDCT.
80
2/2
✓ Branch 0 taken 711384 times.
✓ Branch 1 taken 59282 times.
770666 for (size_t i = 0; i < FF_ARRAY_ELEMS(s->block_last_index); i++)
81 711384 s->block_last_index[i] = -1;
82
83 59282 s->dest[0] = s->cur_pic.data[0] +
84 59282 s->mb_y * 16 * s->linesize +
85 59282 s->mb_x * 16;
86 59282 s->dest[1] = s->cur_pic.data[1] +
87 59282 s->mb_y * (16 >> s->chroma_y_shift) * s->uvlinesize +
88 59282 s->mb_x * (16 >> s->chroma_x_shift);
89 59282 s->dest[2] = s->cur_pic.data[2] +
90 59282 s->mb_y * (16 >> s->chroma_y_shift) * s->uvlinesize +
91 59282 s->mb_x * (16 >> s->chroma_x_shift);
92
93
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 59282 times.
59282 if (ref)
94 av_log(s->avctx, AV_LOG_DEBUG,
95 "Interlaced error concealment is not fully implemented\n");
96 59282 ff_mpv_reconstruct_mb(s, s->block);
97 59282 }
98
99 647 int ff_mpeg_er_init(MpegEncContext *s)
100 {
101 647 ERContext *er = &s->er;
102 647 int mb_array_size = s->mb_height * s->mb_stride;
103 int i;
104
105 647 er->avctx = s->avctx;
106
107 647 er->mb_index2xy = s->mb_index2xy;
108 647 er->mb_num = s->mb_num;
109 647 er->mb_width = s->mb_width;
110 647 er->mb_height = s->mb_height;
111 647 er->mb_stride = s->mb_stride;
112 647 er->b8_stride = s->b8_stride;
113
114 647 er->er_temp_buffer = av_malloc(s->mb_height * s->mb_stride * (4*sizeof(int) + 1));
115 647 er->error_status_table = av_mallocz(mb_array_size);
116
2/4
✓ Branch 0 taken 647 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 647 times.
647 if (!er->er_temp_buffer || !er->error_status_table)
117 goto fail;
118
119 647 er->mbskip_table = s->mbskip_table;
120 647 er->mbintra_table = s->mbintra_table;
121
122
2/2
✓ Branch 0 taken 1941 times.
✓ Branch 1 taken 647 times.
2588 for (i = 0; i < FF_ARRAY_ELEMS(s->dc_val); i++)
123 1941 er->dc_val[i] = s->dc_val[i];
124
125 647 er->decode_mb = mpeg_er_decode_mb;
126 647 er->opaque = s;
127
128 647 return 0;
129 fail:
130 av_freep(&er->er_temp_buffer);
131 av_freep(&er->error_status_table);
132 return AVERROR(ENOMEM);
133 }
134