FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/mpeg_er.c
Date: 2024-04-18 10:05:09
Exec Total Coverage
Lines: 71 78 91.0%
Functions: 4 4 100.0%
Branches: 10 14 71.4%

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/mem.h"
20 #include "error_resilience.h"
21 #include "mpegvideo.h"
22 #include "mpegvideodec.h"
23 #include "mpeg_er.h"
24
25 33651 static void set_erpic(ERPicture *dst, Picture *src)
26 {
27 int i;
28
29 33651 memset(dst, 0, sizeof(*dst));
30
2/2
✓ Branch 0 taken 313 times.
✓ Branch 1 taken 33338 times.
33651 if (!src) {
31 313 dst->f = NULL;
32 313 dst->tf = NULL;
33 313 return;
34 }
35
36 33338 dst->f = src->f;
37 33338 dst->tf = &src->tf;
38
39
2/2
✓ Branch 0 taken 66676 times.
✓ Branch 1 taken 33338 times.
100014 for (i = 0; i < 2; i++) {
40 66676 dst->motion_val[i] = src->motion_val[i];
41 66676 dst->ref_index[i] = src->ref_index[i];
42 }
43
44 33338 dst->mb_type = src->mb_type;
45 33338 dst->field_picture = src->field_picture;
46 }
47
48 11217 void ff_mpeg_er_frame_start(MpegEncContext *s)
49 {
50 11217 ERContext *er = &s->er;
51
52 11217 set_erpic(&er->cur_pic, s->current_picture_ptr);
53 11217 set_erpic(&er->next_pic, s->next_picture_ptr);
54 11217 set_erpic(&er->last_pic, s->last_picture_ptr);
55
56 11217 er->pp_time = s->pp_time;
57 11217 er->pb_time = s->pb_time;
58 11217 er->quarter_sample = s->quarter_sample;
59 11217 er->partitioned_frame = s->partitioned_frame;
60
61 11217 ff_er_frame_start(er);
62 11217 }
63
64 59282 static void mpeg_er_decode_mb(void *opaque, int ref, int mv_dir, int mv_type,
65 int (*mv)[2][4][2], int mb_x, int mb_y,
66 int mb_intra, int mb_skipped)
67 {
68 59282 MpegEncContext *s = opaque;
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 59282 ff_init_block_index(s);
80 59282 ff_update_block_index(s, s->avctx->bits_per_raw_sample,
81 59282 s->avctx->lowres, s->chroma_x_shift);
82
83 59282 s->bdsp.clear_blocks(s->block[0]);
84
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 59282 times.
59282 if (!s->chroma_y_shift)
85 s->bdsp.clear_blocks(s->block[6]);
86
87 59282 s->dest[0] = s->current_picture.f->data[0] +
88 59282 s->mb_y * 16 * s->linesize +
89 59282 s->mb_x * 16;
90 59282 s->dest[1] = s->current_picture.f->data[1] +
91 59282 s->mb_y * (16 >> s->chroma_y_shift) * s->uvlinesize +
92 59282 s->mb_x * (16 >> s->chroma_x_shift);
93 59282 s->dest[2] = s->current_picture.f->data[2] +
94 59282 s->mb_y * (16 >> s->chroma_y_shift) * s->uvlinesize +
95 59282 s->mb_x * (16 >> s->chroma_x_shift);
96
97
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 59282 times.
59282 if (ref)
98 av_log(s->avctx, AV_LOG_DEBUG,
99 "Interlaced error concealment is not fully implemented\n");
100 59282 ff_mpv_reconstruct_mb(s, s->block);
101 59282 }
102
103 640 int ff_mpeg_er_init(MpegEncContext *s)
104 {
105 640 ERContext *er = &s->er;
106 640 int mb_array_size = s->mb_height * s->mb_stride;
107 int i;
108
109 640 er->avctx = s->avctx;
110
111 640 er->mb_index2xy = s->mb_index2xy;
112 640 er->mb_num = s->mb_num;
113 640 er->mb_width = s->mb_width;
114 640 er->mb_height = s->mb_height;
115 640 er->mb_stride = s->mb_stride;
116 640 er->b8_stride = s->b8_stride;
117
118 640 er->er_temp_buffer = av_malloc(s->mb_height * s->mb_stride * (4*sizeof(int) + 1));
119 640 er->error_status_table = av_mallocz(mb_array_size);
120
2/4
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 640 times.
640 if (!er->er_temp_buffer || !er->error_status_table)
121 goto fail;
122
123 640 er->mbskip_table = s->mbskip_table;
124 640 er->mbintra_table = s->mbintra_table;
125
126
2/2
✓ Branch 0 taken 1920 times.
✓ Branch 1 taken 640 times.
2560 for (i = 0; i < FF_ARRAY_ELEMS(s->dc_val); i++)
127 1920 er->dc_val[i] = s->dc_val[i];
128
129 640 er->decode_mb = mpeg_er_decode_mb;
130 640 er->opaque = s;
131
132 640 return 0;
133 fail:
134 av_freep(&er->er_temp_buffer);
135 av_freep(&er->error_status_table);
136 return AVERROR(ENOMEM);
137 }
138