1 /*
2 * Mpeg video formats-related picture management functions
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include <stdint.h>
22
27
34
36 {
39
43
44 for (
int i = 0;
i < 2;
i++) {
47 }
48 }
49
51 {
53
55 return 0;
57 if (!new)
61 return 0;
62 }
63
65 {
66 #define MAKE_WRITABLE(table) \
67 do {\
68 int ret = make_table_writable(&pic->table); \
69 if (ret < 0) \
70 return ret; \
71 } while (0)
72
76
78 for (
int i = 0;
i < 2;
i++) {
81 }
82 }
83
84 return 0;
85 }
86
89 {
90 # define EMU_EDGE_HEIGHT (4 * 70)
92
94 return 0;
95
96 if (linesize < 24) {
99 }
100
103
104 // edge emu needs blocksize + filter length - 1
105 // (= 17x17 for halfpel / 21x21 for H.264)
106 // VC-1 computes luma and chroma simultaneously and needs 19X19 + 9x9
107 // at uvlinesize. It supports only YUV420 so 24x24 is enough
108 // linesize * interlaced * MBsize
109 // we also use this buffer for encoding in encode_mb_internal() needig an additional 32 lines
114 }
115
116 me->temp =
me->scratchpad;
120
121 return 0;
122 }
123
124 /**
125 * Check the pic's linesize and allocate linesize dependent scratch buffers
126 */
129 int linesize, int uvlinesize)
130 {
132
133 if ((linesize && linesize != pic->
f->
linesize[0]) ||
134 (uvlinesize && uvlinesize != pic->
f->
linesize[1])) {
136 "get_buffer() failed (stride changed: linesize=%d/%d uvlinesize=%d/%d)\n",
140 return -1;
141 }
142
146 "get_buffer() failed (uv stride mismatch)\n");
148 return -1;
149 }
150
155 "get_buffer() failed to allocate context scratch buffers.\n");
158 }
159
160 return 0;
161 }
162
164 int mb_stride, int mb_width, int mb_height, int b8_stride)
165 {
166 const int big_mb_num = mb_stride * (mb_height + 1) + 1;
167 const int mb_array_size = mb_stride * mb_height;
168 const int b8_array_size = b8_stride * mb_height * 2;
170
171
175 sizeof(uint32_t));
178
179 if (out_format ==
FMT_H263 || encoding ||
181 int mv_size = 2 * (b8_array_size + 4) * sizeof(int16_t);
182 int ref_index_size = 4 * mb_array_size;
183
184 for (
i = 0; mv_size &&
i < 2;
i++) {
189 }
190 }
191
195
196 return 0;
197 }
198
199 /**
200 * Allocate a Picture.
201 * The pixels are allocated/set by calling get_buffer() if shared = 0
202 */
205 int mb_stride, int mb_width, int mb_height, int b8_stride,
206 ptrdiff_t *linesize, ptrdiff_t *uvlinesize)
207 {
209
214
216 *linesize, *uvlinesize) < 0)
217 return -1;
218
221
224 mb_stride, mb_width, mb_height, b8_stride);
225 else
229
233
235 for (
i = 0;
i < 2;
i++) {
238 }
239 }
240
241 return 0;
247 }
248
249 /**
250 * Deallocate a picture; frees the picture tables in case they
251 * need to be reallocated anyway.
252 */
254 {
257
259
262
270 }
271
273 {
275
279 for (
i = 0;
i < 2;
i++) {
282 }
283
287 }
288
292 for (
i = 0;
i < 2;
i++) {
295 }
296
300
301 return 0;
302 }
303
305 {
307
310
316
320
322 src->hwaccel_picture_private);
323
331
332 return 0;
336 }
337
339 {
341 return 1;
343 return 1;
344 return 0;
345 }
346
348 {
350
351 if (shared) {
353 if (!picture[
i].
f->buf[0])
355 }
356 } else {
360 }
361 }
362
364 "Internal error, picture buffer overflow\n");
365 /* We could return -1, but the codec would crash trying to draw into a
366 * non-existing frame anyway. This is safer than waiting for a random crash.
367 * Also the return of this is never useful, an encoder must only allocate
368 * as much as allowed in the specification. This has no relationship to how
369 * much libavcodec could allocate (and MAX_PICTURE_COUNT is always large
370 * enough for such valid streams).
371 * Plus, a decoder has to check stream validity and remove frames if too
372 * many reference frames are around. Waiting for "OOM" is not correct at
373 * all. Similarly, missing reference frames have to be replaced by
374 * interpolated/MC frames, anything else is a bug in the codec ...
375 */
376 abort();
377 return -1;
378 }
379
381 {
383
385 if (picture[
ret].needs_realloc) {
387 }
388 }
390 }
391
393 {
397 }