1 |
|
|
/* |
2 |
|
|
* H.26L/H.264/AVC/JVT/14496-10/... decoder |
3 |
|
|
* Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at> |
4 |
|
|
* |
5 |
|
|
* This file is part of FFmpeg. |
6 |
|
|
* |
7 |
|
|
* FFmpeg is free software; you can redistribute it and/or |
8 |
|
|
* modify it under the terms of the GNU Lesser General Public |
9 |
|
|
* License as published by the Free Software Foundation; either |
10 |
|
|
* version 2.1 of the License, or (at your option) any later version. |
11 |
|
|
* |
12 |
|
|
* FFmpeg is distributed in the hope that it will be useful, |
13 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 |
|
|
* Lesser General Public License for more details. |
16 |
|
|
* |
17 |
|
|
* You should have received a copy of the GNU Lesser General Public |
18 |
|
|
* License along with FFmpeg; if not, write to the Free Software |
19 |
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
20 |
|
|
*/ |
21 |
|
|
|
22 |
|
|
/** |
23 |
|
|
* @file |
24 |
|
|
* H.264 / AVC / MPEG-4 part10 codec. |
25 |
|
|
* @author Michael Niedermayer <michaelni@gmx.at> |
26 |
|
|
*/ |
27 |
|
|
|
28 |
|
|
#include "libavutil/avassert.h" |
29 |
|
|
#include "libavutil/imgutils.h" |
30 |
|
|
#include "internal.h" |
31 |
|
|
#include "cabac.h" |
32 |
|
|
#include "cabac_functions.h" |
33 |
|
|
#include "error_resilience.h" |
34 |
|
|
#include "avcodec.h" |
35 |
|
|
#include "h264dec.h" |
36 |
|
|
#include "h264data.h" |
37 |
|
|
#include "h264chroma.h" |
38 |
|
|
#include "h264_mvpred.h" |
39 |
|
|
#include "mathops.h" |
40 |
|
|
#include "mpegutils.h" |
41 |
|
|
#include "rectangle.h" |
42 |
|
|
#include "thread.h" |
43 |
|
|
|
44 |
|
122104 |
void ff_h264_unref_picture(H264Context *h, H264Picture *pic) |
45 |
|
|
{ |
46 |
|
122104 |
int off = offsetof(H264Picture, tf) + sizeof(pic->tf); |
47 |
|
|
int i; |
48 |
|
|
|
49 |
✓✗✓✓
|
122104 |
if (!pic->f || !pic->f->buf[0]) |
50 |
|
74139 |
return; |
51 |
|
|
|
52 |
|
47965 |
ff_thread_release_buffer(h->avctx, &pic->tf); |
53 |
|
47965 |
av_buffer_unref(&pic->hwaccel_priv_buf); |
54 |
|
|
|
55 |
|
47965 |
av_buffer_unref(&pic->qscale_table_buf); |
56 |
|
47965 |
av_buffer_unref(&pic->mb_type_buf); |
57 |
|
47965 |
av_buffer_unref(&pic->pps_buf); |
58 |
✓✓ |
143895 |
for (i = 0; i < 2; i++) { |
59 |
|
95930 |
av_buffer_unref(&pic->motion_val_buf[i]); |
60 |
|
95930 |
av_buffer_unref(&pic->ref_index_buf[i]); |
61 |
|
|
} |
62 |
|
|
|
63 |
|
47965 |
memset((uint8_t*)pic + off, 0, sizeof(*pic) - off); |
64 |
|
|
} |
65 |
|
|
|
66 |
|
24614 |
int ff_h264_ref_picture(H264Context *h, H264Picture *dst, H264Picture *src) |
67 |
|
|
{ |
68 |
|
|
int ret, i; |
69 |
|
|
|
70 |
✗✓ |
24614 |
av_assert0(!dst->f->buf[0]); |
71 |
✗✓ |
24614 |
av_assert0(src->f->buf[0]); |
72 |
✗✓ |
24614 |
av_assert0(src->tf.f == src->f); |
73 |
|
|
|
74 |
|
24614 |
dst->tf.f = dst->f; |
75 |
|
24614 |
ret = ff_thread_ref_frame(&dst->tf, &src->tf); |
76 |
✗✓ |
24614 |
if (ret < 0) |
77 |
|
|
goto fail; |
78 |
|
|
|
79 |
|
24614 |
dst->qscale_table_buf = av_buffer_ref(src->qscale_table_buf); |
80 |
|
24614 |
dst->mb_type_buf = av_buffer_ref(src->mb_type_buf); |
81 |
|
24614 |
dst->pps_buf = av_buffer_ref(src->pps_buf); |
82 |
✓✗✓✗ ✗✓ |
24614 |
if (!dst->qscale_table_buf || !dst->mb_type_buf || !dst->pps_buf) { |
83 |
|
|
ret = AVERROR(ENOMEM); |
84 |
|
|
goto fail; |
85 |
|
|
} |
86 |
|
24614 |
dst->qscale_table = src->qscale_table; |
87 |
|
24614 |
dst->mb_type = src->mb_type; |
88 |
|
24614 |
dst->pps = src->pps; |
89 |
|
|
|
90 |
✓✓ |
73842 |
for (i = 0; i < 2; i++) { |
91 |
|
49228 |
dst->motion_val_buf[i] = av_buffer_ref(src->motion_val_buf[i]); |
92 |
|
49228 |
dst->ref_index_buf[i] = av_buffer_ref(src->ref_index_buf[i]); |
93 |
✓✗✗✓
|
49228 |
if (!dst->motion_val_buf[i] || !dst->ref_index_buf[i]) { |
94 |
|
|
ret = AVERROR(ENOMEM); |
95 |
|
|
goto fail; |
96 |
|
|
} |
97 |
|
49228 |
dst->motion_val[i] = src->motion_val[i]; |
98 |
|
49228 |
dst->ref_index[i] = src->ref_index[i]; |
99 |
|
|
} |
100 |
|
|
|
101 |
✗✓ |
24614 |
if (src->hwaccel_picture_private) { |
102 |
|
|
dst->hwaccel_priv_buf = av_buffer_ref(src->hwaccel_priv_buf); |
103 |
|
|
if (!dst->hwaccel_priv_buf) { |
104 |
|
|
ret = AVERROR(ENOMEM); |
105 |
|
|
goto fail; |
106 |
|
|
} |
107 |
|
|
dst->hwaccel_picture_private = dst->hwaccel_priv_buf->data; |
108 |
|
|
} |
109 |
|
|
|
110 |
✓✓ |
73842 |
for (i = 0; i < 2; i++) |
111 |
|
49228 |
dst->field_poc[i] = src->field_poc[i]; |
112 |
|
|
|
113 |
|
24614 |
memcpy(dst->ref_poc, src->ref_poc, sizeof(src->ref_poc)); |
114 |
|
24614 |
memcpy(dst->ref_count, src->ref_count, sizeof(src->ref_count)); |
115 |
|
|
|
116 |
|
24614 |
dst->poc = src->poc; |
117 |
|
24614 |
dst->frame_num = src->frame_num; |
118 |
|
24614 |
dst->mmco_reset = src->mmco_reset; |
119 |
|
24614 |
dst->long_ref = src->long_ref; |
120 |
|
24614 |
dst->mbaff = src->mbaff; |
121 |
|
24614 |
dst->field_picture = src->field_picture; |
122 |
|
24614 |
dst->reference = src->reference; |
123 |
|
24614 |
dst->recovered = src->recovered; |
124 |
|
24614 |
dst->invalid_gap = src->invalid_gap; |
125 |
|
24614 |
dst->sei_recovery_frame_cnt = src->sei_recovery_frame_cnt; |
126 |
|
24614 |
dst->mb_width = src->mb_width; |
127 |
|
24614 |
dst->mb_height = src->mb_height; |
128 |
|
24614 |
dst->mb_stride = src->mb_stride; |
129 |
|
|
|
130 |
|
24614 |
return 0; |
131 |
|
|
fail: |
132 |
|
|
ff_h264_unref_picture(h, dst); |
133 |
|
|
return ret; |
134 |
|
|
} |
135 |
|
|
|
136 |
|
124472 |
void ff_h264_set_erpic(ERPicture *dst, H264Picture *src) |
137 |
|
|
{ |
138 |
|
|
#if CONFIG_ERROR_RESILIENCE |
139 |
|
|
int i; |
140 |
|
|
|
141 |
|
124472 |
memset(dst, 0, sizeof(*dst)); |
142 |
|
|
|
143 |
✓✓ |
124472 |
if (!src) |
144 |
|
80064 |
return; |
145 |
|
|
|
146 |
|
44408 |
dst->f = src->f; |
147 |
|
44408 |
dst->tf = &src->tf; |
148 |
|
|
|
149 |
✓✓ |
133224 |
for (i = 0; i < 2; i++) { |
150 |
|
88816 |
dst->motion_val[i] = src->motion_val[i]; |
151 |
|
88816 |
dst->ref_index[i] = src->ref_index[i]; |
152 |
|
|
} |
153 |
|
|
|
154 |
|
44408 |
dst->mb_type = src->mb_type; |
155 |
|
44408 |
dst->field_picture = src->field_picture; |
156 |
|
|
#endif /* CONFIG_ERROR_RESILIENCE */ |
157 |
|
|
} |
158 |
|
|
|
159 |
|
25912 |
int ff_h264_field_end(H264Context *h, H264SliceContext *sl, int in_setup) |
160 |
|
|
{ |
161 |
|
25912 |
AVCodecContext *const avctx = h->avctx; |
162 |
|
25912 |
int err = 0; |
163 |
|
25912 |
h->mb_y = 0; |
164 |
|
|
|
165 |
✓✓✓✓
|
25912 |
if (in_setup || !(avctx->active_thread_type & FF_THREAD_FRAME)) { |
166 |
✓✓ |
25880 |
if (!h->droppable) { |
167 |
|
16806 |
err = ff_h264_execute_ref_pic_marking(h); |
168 |
|
16806 |
h->poc.prev_poc_msb = h->poc.poc_msb; |
169 |
|
16806 |
h->poc.prev_poc_lsb = h->poc.poc_lsb; |
170 |
|
|
} |
171 |
|
25880 |
h->poc.prev_frame_num_offset = h->poc.frame_num_offset; |
172 |
|
25880 |
h->poc.prev_frame_num = h->poc.frame_num; |
173 |
|
|
} |
174 |
|
|
|
175 |
✗✓ |
25912 |
if (avctx->hwaccel) { |
176 |
|
|
err = avctx->hwaccel->end_frame(avctx); |
177 |
|
|
if (err < 0) |
178 |
|
|
av_log(avctx, AV_LOG_ERROR, |
179 |
|
|
"hardware accelerator failed to decode picture\n"); |
180 |
|
|
} |
181 |
|
|
|
182 |
✓✓✓✓
|
25912 |
if (!in_setup && !h->droppable) |
183 |
|
16756 |
ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, |
184 |
|
16756 |
h->picture_structure == PICT_BOTTOM_FIELD); |
185 |
|
25912 |
emms_c(); |
186 |
|
|
|
187 |
|
25912 |
h->current_slice = 0; |
188 |
|
|
|
189 |
|
25912 |
return err; |
190 |
|
|
} |