Directory: | ../../../ffmpeg/ |
---|---|
File: | src/libavcodec/mpeg_er.c |
Date: | 2022-07-04 19:11:22 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 70 | 77 | 90.9% |
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 "error_resilience.h" | ||
20 | #include "mpegvideo.h" | ||
21 | #include "mpeg_er.h" | ||
22 | |||
23 | 32388 | static void set_erpic(ERPicture *dst, Picture *src) | |
24 | { | ||
25 | int i; | ||
26 | |||
27 | 32388 | memset(dst, 0, sizeof(*dst)); | |
28 |
2/2✓ Branch 0 taken 289 times.
✓ Branch 1 taken 32099 times.
|
32388 | if (!src) { |
29 | 289 | dst->f = NULL; | |
30 | 289 | dst->tf = NULL; | |
31 | 289 | return; | |
32 | } | ||
33 | |||
34 | 32099 | dst->f = src->f; | |
35 | 32099 | dst->tf = &src->tf; | |
36 | |||
37 |
2/2✓ Branch 0 taken 64198 times.
✓ Branch 1 taken 32099 times.
|
96297 | for (i = 0; i < 2; i++) { |
38 | 64198 | dst->motion_val[i] = src->motion_val[i]; | |
39 | 64198 | dst->ref_index[i] = src->ref_index[i]; | |
40 | } | ||
41 | |||
42 | 32099 | dst->mb_type = src->mb_type; | |
43 | 32099 | dst->field_picture = src->field_picture; | |
44 | } | ||
45 | |||
46 | 10796 | void ff_mpeg_er_frame_start(MpegEncContext *s) | |
47 | { | ||
48 | 10796 | ERContext *er = &s->er; | |
49 | |||
50 | 10796 | set_erpic(&er->cur_pic, s->current_picture_ptr); | |
51 | 10796 | set_erpic(&er->next_pic, s->next_picture_ptr); | |
52 | 10796 | set_erpic(&er->last_pic, s->last_picture_ptr); | |
53 | |||
54 | 10796 | er->pp_time = s->pp_time; | |
55 | 10796 | er->pb_time = s->pb_time; | |
56 | 10796 | er->quarter_sample = s->quarter_sample; | |
57 | 10796 | er->partitioned_frame = s->partitioned_frame; | |
58 | |||
59 | 10796 | ff_er_frame_start(er); | |
60 | 10796 | } | |
61 | |||
62 | 59062 | 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 | 59062 | MpegEncContext *s = opaque; | |
67 | |||
68 | 59062 | s->mv_dir = mv_dir; | |
69 | 59062 | s->mv_type = mv_type; | |
70 | 59062 | s->mb_intra = mb_intra; | |
71 | 59062 | s->mb_skipped = mb_skipped; | |
72 | 59062 | s->mb_x = mb_x; | |
73 | 59062 | s->mb_y = mb_y; | |
74 | 59062 | s->mcsel = 0; | |
75 | 59062 | memcpy(s->mv, mv, sizeof(*mv)); | |
76 | |||
77 | 59062 | ff_init_block_index(s); | |
78 | 59062 | ff_update_block_index(s); | |
79 | |||
80 | 59062 | s->bdsp.clear_blocks(s->block[0]); | |
81 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 59062 times.
|
59062 | if (!s->chroma_y_shift) |
82 | ✗ | s->bdsp.clear_blocks(s->block[6]); | |
83 | |||
84 | 59062 | s->dest[0] = s->current_picture.f->data[0] + | |
85 | 59062 | s->mb_y * 16 * s->linesize + | |
86 | 59062 | s->mb_x * 16; | |
87 | 59062 | s->dest[1] = s->current_picture.f->data[1] + | |
88 | 59062 | s->mb_y * (16 >> s->chroma_y_shift) * s->uvlinesize + | |
89 | 59062 | s->mb_x * (16 >> s->chroma_x_shift); | |
90 | 59062 | s->dest[2] = s->current_picture.f->data[2] + | |
91 | 59062 | s->mb_y * (16 >> s->chroma_y_shift) * s->uvlinesize + | |
92 | 59062 | s->mb_x * (16 >> s->chroma_x_shift); | |
93 | |||
94 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 59062 times.
|
59062 | if (ref) |
95 | ✗ | av_log(s->avctx, AV_LOG_DEBUG, | |
96 | "Interlaced error concealment is not fully implemented\n"); | ||
97 | 59062 | ff_mpv_reconstruct_mb(s, s->block); | |
98 | 59062 | } | |
99 | |||
100 | 616 | int ff_mpeg_er_init(MpegEncContext *s) | |
101 | { | ||
102 | 616 | ERContext *er = &s->er; | |
103 | 616 | int mb_array_size = s->mb_height * s->mb_stride; | |
104 | int i; | ||
105 | |||
106 | 616 | er->avctx = s->avctx; | |
107 | |||
108 | 616 | er->mb_index2xy = s->mb_index2xy; | |
109 | 616 | er->mb_num = s->mb_num; | |
110 | 616 | er->mb_width = s->mb_width; | |
111 | 616 | er->mb_height = s->mb_height; | |
112 | 616 | er->mb_stride = s->mb_stride; | |
113 | 616 | er->b8_stride = s->b8_stride; | |
114 | |||
115 | 616 | er->er_temp_buffer = av_malloc(s->mb_height * s->mb_stride * (4*sizeof(int) + 1)); | |
116 | 616 | er->error_status_table = av_mallocz(mb_array_size); | |
117 |
2/4✓ Branch 0 taken 616 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 616 times.
|
616 | if (!er->er_temp_buffer || !er->error_status_table) |
118 | ✗ | goto fail; | |
119 | |||
120 | 616 | er->mbskip_table = s->mbskip_table; | |
121 | 616 | er->mbintra_table = s->mbintra_table; | |
122 | |||
123 |
2/2✓ Branch 0 taken 1848 times.
✓ Branch 1 taken 616 times.
|
2464 | for (i = 0; i < FF_ARRAY_ELEMS(s->dc_val); i++) |
124 | 1848 | er->dc_val[i] = s->dc_val[i]; | |
125 | |||
126 | 616 | er->decode_mb = mpeg_er_decode_mb; | |
127 | 616 | er->opaque = s; | |
128 | |||
129 | 616 | return 0; | |
130 | ✗ | fail: | |
131 | ✗ | av_freep(&er->er_temp_buffer); | |
132 | ✗ | av_freep(&er->error_status_table); | |
133 | ✗ | return AVERROR(ENOMEM); | |
134 | } | ||
135 |