ffmpeg / libavcodec / utils.c @ 043d2ff2
History | View | Annotate | Download (38.4 KB)
1 | de6d9b64 | Fabrice Bellard | /*
|
---|---|---|---|
2 | * utils for libavcodec
|
||
3 | 406792e7 | Diego Biurrun | * Copyright (c) 2001 Fabrice Bellard
|
4 | 8f2ab833 | Michael Niedermayer | * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
|
5 | de6d9b64 | Fabrice Bellard | *
|
6 | b78e7197 | Diego Biurrun | * This file is part of FFmpeg.
|
7 | *
|
||
8 | * FFmpeg is free software; you can redistribute it and/or
|
||
9 | ff4ec49e | Fabrice Bellard | * modify it under the terms of the GNU Lesser General Public
|
10 | * License as published by the Free Software Foundation; either
|
||
11 | b78e7197 | Diego Biurrun | * version 2.1 of the License, or (at your option) any later version.
|
12 | de6d9b64 | Fabrice Bellard | *
|
13 | b78e7197 | Diego Biurrun | * FFmpeg is distributed in the hope that it will be useful,
|
14 | de6d9b64 | Fabrice Bellard | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 | ff4ec49e | Fabrice Bellard | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
16 | * Lesser General Public License for more details.
|
||
17 | de6d9b64 | Fabrice Bellard | *
|
18 | ff4ec49e | Fabrice Bellard | * You should have received a copy of the GNU Lesser General Public
|
19 | b78e7197 | Diego Biurrun | * License along with FFmpeg; if not, write to the Free Software
|
20 | 5509bffa | Diego Biurrun | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
21 | de6d9b64 | Fabrice Bellard | */
|
22 | 115329f1 | Diego Biurrun | |
23 | 983e3246 | Michael Niedermayer | /**
|
24 | ba87f080 | Diego Biurrun | * @file
|
25 | 983e3246 | Michael Niedermayer | * utils.
|
26 | */
|
||
27 | 115329f1 | Diego Biurrun | |
28 | 7fb94406 | Diego Biurrun | #include "libavutil/avstring.h" |
29 | 245976da | Diego Biurrun | #include "libavutil/integer.h" |
30 | #include "libavutil/crc.h" |
||
31 | eb285cfe | Reimar Döffinger | #include "libavutil/pixdesc.h" |
32 | 63e8d976 | Stefano Sabatini | #include "libavcore/audioconvert.h" |
33 | 05236ed7 | Stefano Sabatini | #include "libavcore/imgutils.h" |
34 | ed5d30d9 | Stefano Sabatini | #include "libavcore/internal.h" |
35 | ba7d6e79 | Stefano Sabatini | #include "libavcore/samplefmt.h" |
36 | de6d9b64 | Fabrice Bellard | #include "avcodec.h" |
37 | 3123dd79 | Fabrice Bellard | #include "dsputil.h" |
38 | 6ed04040 | Michael Niedermayer | #include "libavutil/opt.h" |
39 | db7ae7d1 | Vitor Sessak | #include "imgconvert.h" |
40 | b38f008e | Alexander Strange | #include "thread.h" |
41 | 9e82a113 | Peter Ross | #include "audioconvert.h" |
42 | 0ba39dd1 | Kenan Gillet | #include "internal.h" |
43 | 7246177d | Aurelien Jacobs | #include <stdlib.h> |
44 | 9b879566 | Michel Bardiaux | #include <stdarg.h> |
45 | 4c263142 | Michael Niedermayer | #include <limits.h> |
46 | 860a40c8 | Michael Niedermayer | #include <float.h> |
47 | de6d9b64 | Fabrice Bellard | |
48 | ddebfb15 | Michael Niedermayer | static int volatile entangled_thread_counter=0; |
49 | 291f326a | Diego Elio Pettenò | static int (*ff_lockmgr_cb)(void **mutex, enum AVLockOp op); |
50 | f988ce6c | Andreas Öman | static void *codec_mutex; |
51 | ddebfb15 | Michael Niedermayer | |
52 | 372c3f82 | Michael Niedermayer | void *av_fast_realloc(void *ptr, unsigned int *size, FF_INTERNALC_MEM_TYPE min_size) |
53 | 8e1e6f31 | Fabrice Bellard | { |
54 | 115329f1 | Diego Biurrun | if(min_size < *size)
|
55 | 8e1e6f31 | Fabrice Bellard | return ptr;
|
56 | 115329f1 | Diego Biurrun | |
57 | 372c3f82 | Michael Niedermayer | min_size= FFMAX(17*min_size/16 + 32, min_size); |
58 | 8e1e6f31 | Fabrice Bellard | |
59 | 372c3f82 | Michael Niedermayer | ptr= av_realloc(ptr, min_size); |
60 | 978805b2 | Michael Niedermayer | if(!ptr) //we could set this to the unmodified min_size but this is safer if the user lost the ptr and uses NULL now |
61 | 372c3f82 | Michael Niedermayer | min_size= 0;
|
62 | |||
63 | *size= min_size; |
||
64 | 978805b2 | Michael Niedermayer | |
65 | return ptr;
|
||
66 | 8e1e6f31 | Fabrice Bellard | } |
67 | |||
68 | 372c3f82 | Michael Niedermayer | void av_fast_malloc(void *ptr, unsigned int *size, FF_INTERNALC_MEM_TYPE min_size) |
69 | 238ef6da | Reimar Döffinger | { |
70 | void **p = ptr;
|
||
71 | if (min_size < *size)
|
||
72 | return;
|
||
73 | 372c3f82 | Michael Niedermayer | min_size= FFMAX(17*min_size/16 + 32, min_size); |
74 | 238ef6da | Reimar Döffinger | av_free(*p); |
75 | 372c3f82 | Michael Niedermayer | *p = av_malloc(min_size); |
76 | if (!*p) min_size = 0; |
||
77 | *size= min_size; |
||
78 | 238ef6da | Reimar Döffinger | } |
79 | |||
80 | de6d9b64 | Fabrice Bellard | /* encoder management */
|
81 | e6df765e | Diego Pettenò | static AVCodec *first_avcodec = NULL; |
82 | de6d9b64 | Fabrice Bellard | |
83 | 55b9e69a | Michael Niedermayer | AVCodec *av_codec_next(AVCodec *c){ |
84 | if(c) return c->next; |
||
85 | else return first_avcodec; |
||
86 | } |
||
87 | |||
88 | 85662f49 | Stefano Sabatini | void avcodec_register(AVCodec *codec)
|
89 | de6d9b64 | Fabrice Bellard | { |
90 | AVCodec **p; |
||
91 | 7a961a46 | Stefano Sabatini | avcodec_init(); |
92 | de6d9b64 | Fabrice Bellard | p = &first_avcodec; |
93 | while (*p != NULL) p = &(*p)->next; |
||
94 | 335a761a | Stefano Sabatini | *p = codec; |
95 | codec->next = NULL;
|
||
96 | de6d9b64 | Fabrice Bellard | } |
97 | |||
98 | 9d385cfe | Stefano Sabatini | #if LIBAVCODEC_VERSION_MAJOR < 53 |
99 | 85662f49 | Stefano Sabatini | void register_avcodec(AVCodec *codec)
|
100 | { |
||
101 | avcodec_register(codec); |
||
102 | } |
||
103 | 9d385cfe | Stefano Sabatini | #endif
|
104 | 85662f49 | Stefano Sabatini | |
105 | 0fb49b59 | Bobby Bingham | unsigned avcodec_get_edge_width(void) |
106 | { |
||
107 | return EDGE_WIDTH;
|
||
108 | } |
||
109 | |||
110 | 21adafec | Michael Niedermayer | void avcodec_set_dimensions(AVCodecContext *s, int width, int height){ |
111 | s->coded_width = width; |
||
112 | s->coded_height= height; |
||
113 | s->width = -((-width )>>s->lowres); |
||
114 | s->height= -((-height)>>s->lowres); |
||
115 | } |
||
116 | |||
117 | d90cf87b | Michael Niedermayer | typedef struct InternalBuffer{ |
118 | 1e491e29 | Michael Niedermayer | int last_pic_num;
|
119 | d90cf87b | Michael Niedermayer | uint8_t *base[4];
|
120 | 1e491e29 | Michael Niedermayer | uint8_t *data[4];
|
121 | 237e4938 | Michael Niedermayer | int linesize[4]; |
122 | 0701006e | Michael Niedermayer | int width, height;
|
123 | enum PixelFormat pix_fmt;
|
||
124 | d90cf87b | Michael Niedermayer | }InternalBuffer; |
125 | |||
126 | #define INTERNAL_BUFFER_SIZE 32 |
||
127 | 1e491e29 | Michael Niedermayer | |
128 | eb285cfe | Reimar Döffinger | void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height, int linesize_align[4]){ |
129 | 115329f1 | Diego Biurrun | int w_align= 1; |
130 | int h_align= 1; |
||
131 | |||
132 | f0bbfc4a | Michael Niedermayer | switch(s->pix_fmt){
|
133 | case PIX_FMT_YUV420P:
|
||
134 | 71e445fc | Diego Biurrun | case PIX_FMT_YUYV422:
|
135 | ebb177dd | Todd Kirby | case PIX_FMT_UYVY422:
|
136 | f0bbfc4a | Michael Niedermayer | case PIX_FMT_YUV422P:
|
137 | 98c82d69 | Michael Niedermayer | case PIX_FMT_YUV440P:
|
138 | f0bbfc4a | Michael Niedermayer | case PIX_FMT_YUV444P:
|
139 | case PIX_FMT_GRAY8:
|
||
140 | 34380af0 | Kostya Shishkov | case PIX_FMT_GRAY16BE:
|
141 | case PIX_FMT_GRAY16LE:
|
||
142 | f0bbfc4a | Michael Niedermayer | case PIX_FMT_YUVJ420P:
|
143 | case PIX_FMT_YUVJ422P:
|
||
144 | 98c82d69 | Michael Niedermayer | case PIX_FMT_YUVJ440P:
|
145 | f0bbfc4a | Michael Niedermayer | case PIX_FMT_YUVJ444P:
|
146 | b70335a2 | Aurelien Jacobs | case PIX_FMT_YUVA420P:
|
147 | f0bbfc4a | Michael Niedermayer | w_align= 16; //FIXME check for non mpeg style codecs and use less alignment |
148 | h_align= 16;
|
||
149 | 00d1e96b | Reimar Döffinger | if(s->codec_id == CODEC_ID_MPEG2VIDEO || s->codec_id == CODEC_ID_MJPEG || s->codec_id == CODEC_ID_AMV || s->codec_id == CODEC_ID_THP || s->codec_id == CODEC_ID_H264)
|
150 | c81185a1 | Michael Niedermayer | h_align= 32; // interlaced is rounded up to 2 MBs |
151 | f0bbfc4a | Michael Niedermayer | break;
|
152 | case PIX_FMT_YUV411P:
|
||
153 | 71e445fc | Diego Biurrun | case PIX_FMT_UYYVYY411:
|
154 | f0bbfc4a | Michael Niedermayer | w_align=32;
|
155 | h_align=8;
|
||
156 | break;
|
||
157 | case PIX_FMT_YUV410P:
|
||
158 | if(s->codec_id == CODEC_ID_SVQ1){
|
||
159 | w_align=64;
|
||
160 | h_align=64;
|
||
161 | } |
||
162 | d99fbbf4 | Roberto Togni | case PIX_FMT_RGB555:
|
163 | if(s->codec_id == CODEC_ID_RPZA){
|
||
164 | w_align=4;
|
||
165 | h_align=4;
|
||
166 | } |
||
167 | case PIX_FMT_PAL8:
|
||
168 | 6337178b | Michael Niedermayer | case PIX_FMT_BGR8:
|
169 | case PIX_FMT_RGB8:
|
||
170 | d99fbbf4 | Roberto Togni | if(s->codec_id == CODEC_ID_SMC){
|
171 | w_align=4;
|
||
172 | h_align=4;
|
||
173 | } |
||
174 | f0bbfc4a | Michael Niedermayer | break;
|
175 | c31b8121 | Roberto Togni | case PIX_FMT_BGR24:
|
176 | if((s->codec_id == CODEC_ID_MSZH) || (s->codec_id == CODEC_ID_ZLIB)){
|
||
177 | w_align=4;
|
||
178 | h_align=4;
|
||
179 | } |
||
180 | break;
|
||
181 | f0bbfc4a | Michael Niedermayer | default:
|
182 | w_align= 1;
|
||
183 | h_align= 1;
|
||
184 | break;
|
||
185 | } |
||
186 | |||
187 | ef516f73 | David Conrad | *width = FFALIGN(*width , w_align); |
188 | *height= FFALIGN(*height, h_align); |
||
189 | ba68d9d3 | Anatoly Nenashev | if(s->codec_id == CODEC_ID_H264 || s->lowres)
|
190 | ae4ffe9f | Michael Niedermayer | *height+=2; // some of the optimized chroma MC reads one line too much |
191 | ba68d9d3 | Anatoly Nenashev | // which is also done in mpeg decoders with lowres > 0
|
192 | eb285cfe | Reimar Döffinger | |
193 | linesize_align[0] =
|
||
194 | linesize_align[1] =
|
||
195 | linesize_align[2] =
|
||
196 | linesize_align[3] = STRIDE_ALIGN;
|
||
197 | //STRIDE_ALIGN is 8 for SSE* but this does not work for SVQ1 chroma planes
|
||
198 | //we could change STRIDE_ALIGN to 16 for x86/sse but it would increase the
|
||
199 | //picture size unneccessarily in some cases. The solution here is not
|
||
200 | //pretty and better ideas are welcome!
|
||
201 | #if HAVE_MMX
|
||
202 | if(s->codec_id == CODEC_ID_SVQ1 || s->codec_id == CODEC_ID_VP5 ||
|
||
203 | s->codec_id == CODEC_ID_VP6 || s->codec_id == CODEC_ID_VP6F || |
||
204 | s->codec_id == CODEC_ID_VP6A) { |
||
205 | linesize_align[0] =
|
||
206 | linesize_align[1] =
|
||
207 | linesize_align[2] = 16; |
||
208 | } |
||
209 | #endif
|
||
210 | } |
||
211 | |||
212 | void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height){ |
||
213 | int chroma_shift = av_pix_fmt_descriptors[s->pix_fmt].log2_chroma_w;
|
||
214 | int linesize_align[4]; |
||
215 | int align;
|
||
216 | avcodec_align_dimensions2(s, width, height, linesize_align); |
||
217 | align = FFMAX(linesize_align[0], linesize_align[3]); |
||
218 | linesize_align[1] <<= chroma_shift;
|
||
219 | linesize_align[2] <<= chroma_shift;
|
||
220 | align = FFMAX3(align, linesize_align[1], linesize_align[2]); |
||
221 | *width=FFALIGN(*width, align); |
||
222 | f0bbfc4a | Michael Niedermayer | } |
223 | |||
224 | bf176f58 | Stefano Sabatini | #if LIBAVCODEC_VERSION_MAJOR < 53 |
225 | 0ecca7a4 | Michael Niedermayer | int avcodec_check_dimensions(void *av_log_ctx, unsigned int w, unsigned int h){ |
226 | e16f217c | Stefano Sabatini | return av_image_check_size(w, h, 0, av_log_ctx); |
227 | 0ecca7a4 | Michael Niedermayer | } |
228 | bf176f58 | Stefano Sabatini | #endif
|
229 | 0ecca7a4 | Michael Niedermayer | |
230 | 492cd3a9 | Michael Niedermayer | int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic){
|
231 | 1e491e29 | Michael Niedermayer | int i;
|
232 | f0bbfc4a | Michael Niedermayer | int w= s->width;
|
233 | int h= s->height;
|
||
234 | d90cf87b | Michael Niedermayer | InternalBuffer *buf; |
235 | 237e4938 | Michael Niedermayer | int *picture_number;
|
236 | 0ecca7a4 | Michael Niedermayer | |
237 | 65d999d6 | Michel Bardiaux | if(pic->data[0]!=NULL) { |
238 | av_log(s, AV_LOG_ERROR, "pic->data[0]!=NULL in avcodec_default_get_buffer\n");
|
||
239 | return -1; |
||
240 | } |
||
241 | if(s->internal_buffer_count >= INTERNAL_BUFFER_SIZE) {
|
||
242 | av_log(s, AV_LOG_ERROR, "internal_buffer_count overflow (missing release_buffer?)\n");
|
||
243 | return -1; |
||
244 | } |
||
245 | 1e491e29 | Michael Niedermayer | |
246 | e16f217c | Stefano Sabatini | if(av_image_check_size(w, h, 0, s)) |
247 | 0ecca7a4 | Michael Niedermayer | return -1; |
248 | |||
249 | d90cf87b | Michael Niedermayer | if(s->internal_buffer==NULL){ |
250 | 6ebc89ac | Michael Niedermayer | s->internal_buffer= av_mallocz((INTERNAL_BUFFER_SIZE+1)*sizeof(InternalBuffer)); |
251 | d90cf87b | Michael Niedermayer | } |
252 | #if 0
|
||
253 | s->internal_buffer= av_fast_realloc(
|
||
254 | 115329f1 | Diego Biurrun | s->internal_buffer,
|
255 | &s->internal_buffer_size,
|
||
256 | d90cf87b | Michael Niedermayer | sizeof(InternalBuffer)*FFMAX(99, s->internal_buffer_count+1)/*FIXME*/
|
257 | );
|
||
258 | #endif
|
||
259 | 115329f1 | Diego Biurrun | |
260 | d90cf87b | Michael Niedermayer | buf= &((InternalBuffer*)s->internal_buffer)[s->internal_buffer_count]; |
261 | 6ebc89ac | Michael Niedermayer | picture_number= &(((InternalBuffer*)s->internal_buffer)[INTERNAL_BUFFER_SIZE]).last_pic_num; //FIXME ugly hack
|
262 | 237e4938 | Michael Niedermayer | (*picture_number)++; |
263 | 115329f1 | Diego Biurrun | |
264 | 0701006e | Michael Niedermayer | if(buf->base[0] && (buf->width != w || buf->height != h || buf->pix_fmt != s->pix_fmt)){ |
265 | b38f008e | Alexander Strange | if(s->active_thread_type&FF_THREAD_FRAME) {
|
266 | av_log_missing_feature(s, "Width/height changing with frame threads is", 0); |
||
267 | return -1; |
||
268 | } |
||
269 | |||
270 | 0701006e | Michael Niedermayer | for(i=0; i<4; i++){ |
271 | av_freep(&buf->base[i]); |
||
272 | buf->data[i]= NULL;
|
||
273 | } |
||
274 | } |
||
275 | |||
276 | d90cf87b | Michael Niedermayer | if(buf->base[0]){ |
277 | 237e4938 | Michael Niedermayer | pic->age= *picture_number - buf->last_pic_num; |
278 | buf->last_pic_num= *picture_number; |
||
279 | 1e491e29 | Michael Niedermayer | }else{
|
280 | f0bbfc4a | Michael Niedermayer | int h_chroma_shift, v_chroma_shift;
|
281 | db7ae7d1 | Vitor Sessak | int size[4] = {0}; |
282 | int tmpsize;
|
||
283 | c9d6e847 | Reimar Döffinger | int unaligned;
|
284 | c7622f9a | Michael Niedermayer | AVPicture picture; |
285 | 503bc402 | Michael Niedermayer | int stride_align[4]; |
286 | c7622f9a | Michael Niedermayer | |
287 | 1e491e29 | Michael Niedermayer | avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift); |
288 | f0bbfc4a | Michael Niedermayer | |
289 | eb285cfe | Reimar Döffinger | avcodec_align_dimensions2(s, &w, &h, stride_align); |
290 | 115329f1 | Diego Biurrun | |
291 | 1e491e29 | Michael Niedermayer | if(!(s->flags&CODEC_FLAG_EMU_EDGE)){
|
292 | w+= EDGE_WIDTH*2;
|
||
293 | h+= EDGE_WIDTH*2;
|
||
294 | } |
||
295 | 5b67307a | Loren Merritt | |
296 | c9d6e847 | Reimar Döffinger | do {
|
297 | // NOTE: do not align linesizes individually, this breaks e.g. assumptions
|
||
298 | // that linesize[0] == 2*linesize[1] in the MPEG-encoder for 4:2:2
|
||
299 | 9d2e0ad8 | Stefano Sabatini | av_image_fill_linesizes(picture.linesize, s->pix_fmt, w); |
300 | c9d6e847 | Reimar Döffinger | // increase alignment of w for next try (rhs gives the lowest bit set in w)
|
301 | w += w & ~(w-1);
|
||
302 | db7ae7d1 | Vitor Sessak | |
303 | c9d6e847 | Reimar Döffinger | unaligned = 0;
|
304 | 45bae968 | Reimar Döffinger | for (i=0; i<4; i++){ |
305 | c9d6e847 | Reimar Döffinger | unaligned |= picture.linesize[i] % stride_align[i]; |
306 | 45bae968 | Reimar Döffinger | } |
307 | c9d6e847 | Reimar Döffinger | } while (unaligned);
|
308 | db7ae7d1 | Vitor Sessak | |
309 | 9d2e0ad8 | Stefano Sabatini | tmpsize = av_image_fill_pointers(picture.data, s->pix_fmt, h, NULL, picture.linesize);
|
310 | f8c96d01 | Reimar Döffinger | if (tmpsize < 0) |
311 | return -1; |
||
312 | db7ae7d1 | Vitor Sessak | |
313 | for (i=0; i<3 && picture.data[i+1]; i++) |
||
314 | size[i] = picture.data[i+1] - picture.data[i];
|
||
315 | cf73e32a | Vitor Sessak | size[i] = tmpsize - (picture.data[i] - picture.data[0]);
|
316 | c7622f9a | Michael Niedermayer | |
317 | d90cf87b | Michael Niedermayer | buf->last_pic_num= -256*256*256*64; |
318 | c7622f9a | Michael Niedermayer | memset(buf->base, 0, sizeof(buf->base)); |
319 | memset(buf->data, 0, sizeof(buf->data)); |
||
320 | 1e491e29 | Michael Niedermayer | |
321 | b70335a2 | Aurelien Jacobs | for(i=0; i<4 && size[i]; i++){ |
322 | 2c19981a | Michael Niedermayer | const int h_shift= i==0 ? 0 : h_chroma_shift; |
323 | const int v_shift= i==0 ? 0 : v_chroma_shift; |
||
324 | 1e491e29 | Michael Niedermayer | |
325 | c7622f9a | Michael Niedermayer | buf->linesize[i]= picture.linesize[i]; |
326 | 1e491e29 | Michael Niedermayer | |
327 | c7622f9a | Michael Niedermayer | buf->base[i]= av_malloc(size[i]+16); //FIXME 16 |
328 | d90cf87b | Michael Niedermayer | if(buf->base[i]==NULL) return -1; |
329 | c7622f9a | Michael Niedermayer | memset(buf->base[i], 128, size[i]);
|
330 | |||
331 | 3491a9b2 | Jai Menon | // no edge if EDGE EMU or not planar YUV
|
332 | 6337178b | Michael Niedermayer | if((s->flags&CODEC_FLAG_EMU_EDGE) || !size[2]) |
333 | d90cf87b | Michael Niedermayer | buf->data[i] = buf->base[i]; |
334 | 1e491e29 | Michael Niedermayer | else
|
335 | ef516f73 | David Conrad | buf->data[i] = buf->base[i] + FFALIGN((buf->linesize[i]*EDGE_WIDTH>>v_shift) + (EDGE_WIDTH>>h_shift), stride_align[i]); |
336 | 1e491e29 | Michael Niedermayer | } |
337 | 6337178b | Michael Niedermayer | if(size[1] && !size[2]) |
338 | ed5d30d9 | Stefano Sabatini | ff_set_systematic_pal2((uint32_t*)buf->data[1], s->pix_fmt);
|
339 | 0701006e | Michael Niedermayer | buf->width = s->width; |
340 | buf->height = s->height; |
||
341 | buf->pix_fmt= s->pix_fmt; |
||
342 | 1e491e29 | Michael Niedermayer | pic->age= 256*256*256*64; |
343 | } |
||
344 | 237e4938 | Michael Niedermayer | pic->type= FF_BUFFER_TYPE_INTERNAL; |
345 | 1e491e29 | Michael Niedermayer | |
346 | d90cf87b | Michael Niedermayer | for(i=0; i<4; i++){ |
347 | pic->base[i]= buf->base[i]; |
||
348 | pic->data[i]= buf->data[i]; |
||
349 | 237e4938 | Michael Niedermayer | pic->linesize[i]= buf->linesize[i]; |
350 | d90cf87b | Michael Niedermayer | } |
351 | s->internal_buffer_count++; |
||
352 | |||
353 | 393cbb96 | Michael Niedermayer | if(s->pkt) pic->pkt_pts= s->pkt->pts;
|
354 | else pic->pkt_pts= AV_NOPTS_VALUE;
|
||
355 | 79de84f2 | Michael Niedermayer | pic->reordered_opaque= s->reordered_opaque; |
356 | |||
357 | 385c820b | Alexander Strange | if(s->debug&FF_DEBUG_BUFFERS)
|
358 | av_log(s, AV_LOG_DEBUG, "default_get_buffer called on pic %p, %d buffers used\n", pic, s->internal_buffer_count);
|
||
359 | |||
360 | 1e491e29 | Michael Niedermayer | return 0; |
361 | } |
||
362 | |||
363 | 492cd3a9 | Michael Niedermayer | void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic){
|
364 | 1e491e29 | Michael Niedermayer | int i;
|
365 | 6829ac8d | Aurelien Jacobs | InternalBuffer *buf, *last; |
366 | d90cf87b | Michael Niedermayer | |
367 | 4e00e76b | Michael Niedermayer | assert(pic->type==FF_BUFFER_TYPE_INTERNAL); |
368 | 59c673d5 | Michael Niedermayer | assert(s->internal_buffer_count); |
369 | d90cf87b | Michael Niedermayer | |
370 | b1609412 | Fabrice Bellard | buf = NULL; /* avoids warning */ |
371 | d90cf87b | Michael Niedermayer | for(i=0; i<s->internal_buffer_count; i++){ //just 3-5 checks so is not worth to optimize |
372 | buf= &((InternalBuffer*)s->internal_buffer)[i]; |
||
373 | if(buf->data[0] == pic->data[0]) |
||
374 | break;
|
||
375 | } |
||
376 | assert(i < s->internal_buffer_count); |
||
377 | s->internal_buffer_count--; |
||
378 | last = &((InternalBuffer*)s->internal_buffer)[s->internal_buffer_count]; |
||
379 | |||
380 | 6829ac8d | Aurelien Jacobs | FFSWAP(InternalBuffer, *buf, *last); |
381 | d90cf87b | Michael Niedermayer | |
382 | b70335a2 | Aurelien Jacobs | for(i=0; i<4; i++){ |
383 | 1e491e29 | Michael Niedermayer | pic->data[i]=NULL;
|
384 | d90cf87b | Michael Niedermayer | // pic->base[i]=NULL;
|
385 | } |
||
386 | 1e491e29 | Michael Niedermayer | //printf("R%X\n", pic->opaque);
|
387 | 385c820b | Alexander Strange | |
388 | if(s->debug&FF_DEBUG_BUFFERS)
|
||
389 | av_log(s, AV_LOG_DEBUG, "default_release_buffer called on pic %p, %d buffers used\n", pic, s->internal_buffer_count);
|
||
390 | 1e491e29 | Michael Niedermayer | } |
391 | |||
392 | e1c2a5a0 | Roberto Togni | int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic){
|
393 | AVFrame temp_pic; |
||
394 | int i;
|
||
395 | |||
396 | /* If no picture return a new buffer */
|
||
397 | if(pic->data[0] == NULL) { |
||
398 | /* We will copy from buffer, so must be readable */
|
||
399 | pic->buffer_hints |= FF_BUFFER_HINTS_READABLE; |
||
400 | return s->get_buffer(s, pic);
|
||
401 | } |
||
402 | |||
403 | /* If internal buffer type return the same buffer */
|
||
404 | b8af4fe9 | Michael Niedermayer | if(pic->type == FF_BUFFER_TYPE_INTERNAL) {
|
405 | cf96cce7 | Nicolas George | if(s->pkt) pic->pkt_pts= s->pkt->pts;
|
406 | else pic->pkt_pts= AV_NOPTS_VALUE;
|
||
407 | b8af4fe9 | Michael Niedermayer | pic->reordered_opaque= s->reordered_opaque; |
408 | e1c2a5a0 | Roberto Togni | return 0; |
409 | b8af4fe9 | Michael Niedermayer | } |
410 | e1c2a5a0 | Roberto Togni | |
411 | /*
|
||
412 | * Not internal type and reget_buffer not overridden, emulate cr buffer
|
||
413 | */
|
||
414 | temp_pic = *pic; |
||
415 | for(i = 0; i < 4; i++) |
||
416 | pic->data[i] = pic->base[i] = NULL;
|
||
417 | pic->opaque = NULL;
|
||
418 | /* Allocate new frame */
|
||
419 | if (s->get_buffer(s, pic))
|
||
420 | return -1; |
||
421 | /* Copy image data from old buffer to new buffer */
|
||
422 | 636d6a4a | Panagiotis Issaris | av_picture_copy((AVPicture*)pic, (AVPicture*)&temp_pic, s->pix_fmt, s->width, |
423 | e1c2a5a0 | Roberto Togni | s->height); |
424 | s->release_buffer(s, &temp_pic); // Release old frame
|
||
425 | return 0; |
||
426 | } |
||
427 | |||
428 | 3a84713a | Roman Shaposhnik | int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size){ |
429 | 9c3d33d6 | Michael Niedermayer | int i;
|
430 | |||
431 | for(i=0; i<count; i++){ |
||
432 | 3a84713a | Roman Shaposhnik | int r= func(c, (char*)arg + i*size); |
433 | 9c3d33d6 | Michael Niedermayer | if(ret) ret[i]= r;
|
434 | } |
||
435 | return 0; |
||
436 | } |
||
437 | |||
438 | 8d23a86f | Reimar Döffinger | int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int jobnr, int threadnr),void *arg, int *ret, int count){ |
439 | int i;
|
||
440 | |||
441 | for(i=0; i<count; i++){ |
||
442 | int r= func(c, arg, i, 0); |
||
443 | if(ret) ret[i]= r;
|
||
444 | } |
||
445 | return 0; |
||
446 | } |
||
447 | |||
448 | c269cf68 | Michael Niedermayer | enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum PixelFormat *fmt){ |
449 | while (*fmt != PIX_FMT_NONE && ff_is_hwaccel_pix_fmt(*fmt))
|
||
450 | ++fmt; |
||
451 | a33c7159 | Michael Niedermayer | return fmt[0]; |
452 | } |
||
453 | |||
454 | 9740beff | Michael Niedermayer | void avcodec_get_frame_defaults(AVFrame *pic){
|
455 | memset(pic, 0, sizeof(AVFrame)); |
||
456 | |||
457 | 76ad67ca | Nicolas George | pic->pts = pic->best_effort_timestamp = AV_NOPTS_VALUE; |
458 | c342499d | Michael Niedermayer | pic->key_frame= 1;
|
459 | 9740beff | Michael Niedermayer | } |
460 | |||
461 | 492cd3a9 | Michael Niedermayer | AVFrame *avcodec_alloc_frame(void){
|
462 | 9740beff | Michael Niedermayer | AVFrame *pic= av_malloc(sizeof(AVFrame));
|
463 | 115329f1 | Diego Biurrun | |
464 | 9740beff | Michael Niedermayer | if(pic==NULL) return NULL; |
465 | 115329f1 | Diego Biurrun | |
466 | 9740beff | Michael Niedermayer | avcodec_get_frame_defaults(pic); |
467 | 115329f1 | Diego Biurrun | |
468 | 1e491e29 | Michael Niedermayer | return pic;
|
469 | } |
||
470 | |||
471 | 5e4c7ca2 | Ramiro Polla | int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec)
|
472 | de6d9b64 | Fabrice Bellard | { |
473 | ddebfb15 | Michael Niedermayer | int ret= -1; |
474 | 115329f1 | Diego Biurrun | |
475 | f988ce6c | Andreas Öman | /* If there is a user-supplied mutex locking routine, call it. */
|
476 | if (ff_lockmgr_cb) {
|
||
477 | if ((*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_OBTAIN))
|
||
478 | return -1; |
||
479 | } |
||
480 | |||
481 | ddebfb15 | Michael Niedermayer | entangled_thread_counter++; |
482 | if(entangled_thread_counter != 1){ |
||
483 | av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n");
|
||
484 | goto end;
|
||
485 | } |
||
486 | de6d9b64 | Fabrice Bellard | |
487 | 9c87b8f7 | Reimar Döffinger | if(avctx->codec || !codec)
|
488 | ddebfb15 | Michael Niedermayer | goto end;
|
489 | 09770af8 | Michael Niedermayer | |
490 | 0edf8a7a | Philip Gladstone | if (codec->priv_data_size > 0) { |
491 | dc51a72b | Michael Niedermayer | if(!avctx->priv_data){
|
492 | 0edf8a7a | Philip Gladstone | avctx->priv_data = av_mallocz(codec->priv_data_size); |
493 | 90f06cea | Panagiotis Issaris | if (!avctx->priv_data) {
|
494 | ret = AVERROR(ENOMEM); |
||
495 | ddebfb15 | Michael Niedermayer | goto end;
|
496 | 90f06cea | Panagiotis Issaris | } |
497 | dc51a72b | Michael Niedermayer | if(codec->priv_class){ //this can be droped once all user apps use avcodec_get_context_defaults3() |
498 | *(AVClass**)avctx->priv_data= codec->priv_class; |
||
499 | av_opt_set_defaults(avctx->priv_data); |
||
500 | } |
||
501 | } |
||
502 | 0edf8a7a | Philip Gladstone | } else {
|
503 | avctx->priv_data = NULL;
|
||
504 | } |
||
505 | 21adafec | Michael Niedermayer | |
506 | if(avctx->coded_width && avctx->coded_height)
|
||
507 | avcodec_set_dimensions(avctx, avctx->coded_width, avctx->coded_height); |
||
508 | else if(avctx->width && avctx->height) |
||
509 | avcodec_set_dimensions(avctx, avctx->width, avctx->height); |
||
510 | |||
511 | 82eac2f3 | Reimar Döffinger | if ((avctx->coded_width || avctx->coded_height || avctx->width || avctx->height)
|
512 | && ( av_image_check_size(avctx->coded_width, avctx->coded_height, 0, avctx) < 0 |
||
513 | || av_image_check_size(avctx->width, avctx->height, 0, avctx) < 0)) { |
||
514 | av_log(avctx, AV_LOG_WARNING, "ignoring invalid width/height values\n");
|
||
515 | avcodec_set_dimensions(avctx, 0, 0); |
||
516 | } |
||
517 | |||
518 | f19c58b4 | Aurelien Jacobs | /* if the decoder init function was already called previously,
|
519 | free the already allocated subtitle_header before overwriting it */
|
||
520 | if (codec->decode)
|
||
521 | av_freep(&avctx->subtitle_header); |
||
522 | |||
523 | fa77dd63 | Peter Ross | #define SANE_NB_CHANNELS 128U |
524 | 82eac2f3 | Reimar Döffinger | if (avctx->channels > SANE_NB_CHANNELS) {
|
525 | 7868349a | Panagiotis Issaris | ret = AVERROR(EINVAL); |
526 | 2a9b5c9b | Michael Niedermayer | goto free_and_end;
|
527 | 0ecca7a4 | Michael Niedermayer | } |
528 | |||
529 | b5c85991 | Michael Niedermayer | avctx->codec = codec; |
530 | 72415b2a | Stefano Sabatini | if ((avctx->codec_type == AVMEDIA_TYPE_UNKNOWN || avctx->codec_type == codec->type) &&
|
531 | 681c180d | Reimar Döffinger | avctx->codec_id == CODEC_ID_NONE) { |
532 | avctx->codec_type = codec->type; |
||
533 | avctx->codec_id = codec->id; |
||
534 | } |
||
535 | e83c716e | Aurelien Jacobs | if (avctx->codec_id != codec->id || (avctx->codec_type != codec->type
|
536 | && avctx->codec_type != AVMEDIA_TYPE_ATTACHMENT)) { |
||
537 | 4c0dda2b | Michael Niedermayer | av_log(avctx, AV_LOG_ERROR, "codec type or id mismatches\n");
|
538 | 2a9b5c9b | Michael Niedermayer | goto free_and_end;
|
539 | 4c0dda2b | Michael Niedermayer | } |
540 | b5c85991 | Michael Niedermayer | avctx->frame_number = 0;
|
541 | b38f008e | Alexander Strange | |
542 | if (HAVE_THREADS && !avctx->thread_opaque) {
|
||
543 | 043d2ff2 | Alexander Strange | ret = ff_thread_init(avctx, avctx->thread_count); |
544 | b38f008e | Alexander Strange | if (ret < 0) { |
545 | goto free_and_end;
|
||
546 | } |
||
547 | } |
||
548 | |||
549 | 527c91e3 | Carl Eugen Hoyos | if (avctx->codec->max_lowres < avctx->lowres) {
|
550 | av_log(avctx, AV_LOG_ERROR, "The maximum value for lowres supported by the decoder is %d\n",
|
||
551 | avctx->codec->max_lowres); |
||
552 | goto free_and_end;
|
||
553 | } |
||
554 | 0fd0ef79 | Carl Eugen Hoyos | |
555 | 76ad67ca | Nicolas George | avctx->pts_correction_num_faulty_pts = |
556 | avctx->pts_correction_num_faulty_dts = 0;
|
||
557 | avctx->pts_correction_last_pts = |
||
558 | avctx->pts_correction_last_dts = INT64_MIN; |
||
559 | |||
560 | b38f008e | Alexander Strange | if(avctx->codec->init && !(avctx->active_thread_type&FF_THREAD_FRAME)){
|
561 | 2de4f9eb | Michael Niedermayer | ret = avctx->codec->init(avctx); |
562 | if (ret < 0) { |
||
563 | 2a9b5c9b | Michael Niedermayer | goto free_and_end;
|
564 | 2de4f9eb | Michael Niedermayer | } |
565 | 6e546aaa | Michael Niedermayer | } |
566 | ddebfb15 | Michael Niedermayer | ret=0;
|
567 | end:
|
||
568 | entangled_thread_counter--; |
||
569 | f988ce6c | Andreas Öman | |
570 | /* Release any user-supplied mutex. */
|
||
571 | if (ff_lockmgr_cb) {
|
||
572 | (*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE); |
||
573 | } |
||
574 | ddebfb15 | Michael Niedermayer | return ret;
|
575 | 2a9b5c9b | Michael Niedermayer | free_and_end:
|
576 | av_freep(&avctx->priv_data); |
||
577 | avctx->codec= NULL;
|
||
578 | goto end;
|
||
579 | de6d9b64 | Fabrice Bellard | } |
580 | |||
581 | 5e4c7ca2 | Ramiro Polla | int attribute_align_arg avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size, |
582 | de6d9b64 | Fabrice Bellard | const short *samples) |
583 | { |
||
584 | 0ecca7a4 | Michael Niedermayer | if(buf_size < FF_MIN_BUFFER_SIZE && 0){ |
585 | 5286d11f | Michel Bardiaux | av_log(avctx, AV_LOG_ERROR, "buffer smaller than minimum size\n");
|
586 | 0ecca7a4 | Michael Niedermayer | return -1; |
587 | } |
||
588 | 6f824977 | Michael Niedermayer | if((avctx->codec->capabilities & CODEC_CAP_DELAY) || samples){
|
589 | 8eb027c8 | Baptiste Coudurier | int ret = avctx->codec->encode(avctx, buf, buf_size, samples);
|
590 | 6f824977 | Michael Niedermayer | avctx->frame_number++; |
591 | return ret;
|
||
592 | }else
|
||
593 | return 0; |
||
594 | de6d9b64 | Fabrice Bellard | } |
595 | |||
596 | 5e4c7ca2 | Ramiro Polla | int attribute_align_arg avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size, |
597 | 492cd3a9 | Michael Niedermayer | const AVFrame *pict)
|
598 | de6d9b64 | Fabrice Bellard | { |
599 | 0ecca7a4 | Michael Niedermayer | if(buf_size < FF_MIN_BUFFER_SIZE){
|
600 | 5286d11f | Michel Bardiaux | av_log(avctx, AV_LOG_ERROR, "buffer smaller than minimum size\n");
|
601 | 0ecca7a4 | Michael Niedermayer | return -1; |
602 | } |
||
603 | e16f217c | Stefano Sabatini | if(av_image_check_size(avctx->width, avctx->height, 0, avctx)) |
604 | 0ecca7a4 | Michael Niedermayer | return -1; |
605 | 6f824977 | Michael Niedermayer | if((avctx->codec->capabilities & CODEC_CAP_DELAY) || pict){
|
606 | 8eb027c8 | Baptiste Coudurier | int ret = avctx->codec->encode(avctx, buf, buf_size, pict);
|
607 | 6f824977 | Michael Niedermayer | avctx->frame_number++; |
608 | bb628dae | Diego Biurrun | emms_c(); //needed to avoid an emms_c() call before every return;
|
609 | 115329f1 | Diego Biurrun | |
610 | 6f824977 | Michael Niedermayer | return ret;
|
611 | }else
|
||
612 | return 0; |
||
613 | de6d9b64 | Fabrice Bellard | } |
614 | |||
615 | 115329f1 | Diego Biurrun | int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size, |
616 | 240c1657 | Fabrice Bellard | const AVSubtitle *sub)
|
617 | { |
||
618 | int ret;
|
||
619 | 9413db9e | Björn Axelsson | if(sub->start_display_time) {
|
620 | av_log(avctx, AV_LOG_ERROR, "start_display_time must be 0.\n");
|
||
621 | return -1; |
||
622 | } |
||
623 | 505aa6c9 | Björn Axelsson | if(sub->num_rects == 0 || !sub->rects) |
624 | return -1; |
||
625 | 8eb027c8 | Baptiste Coudurier | ret = avctx->codec->encode(avctx, buf, buf_size, sub); |
626 | 240c1657 | Fabrice Bellard | avctx->frame_number++; |
627 | return ret;
|
||
628 | } |
||
629 | |||
630 | 76ad67ca | Nicolas George | /**
|
631 | * Attempt to guess proper monotonic timestamps for decoded video frames
|
||
632 | * which might have incorrect times. Input timestamps may wrap around, in
|
||
633 | * which case the output will as well.
|
||
634 | *
|
||
635 | * @param pts the pts field of the decoded AVPacket, as passed through
|
||
636 | * AVFrame.pkt_pts
|
||
637 | * @param dts the dts field of the decoded AVPacket
|
||
638 | * @return one of the input values, may be AV_NOPTS_VALUE
|
||
639 | */
|
||
640 | static int64_t guess_correct_pts(AVCodecContext *ctx,
|
||
641 | int64_t reordered_pts, int64_t dts) |
||
642 | { |
||
643 | int64_t pts = AV_NOPTS_VALUE; |
||
644 | |||
645 | if (dts != AV_NOPTS_VALUE) {
|
||
646 | ctx->pts_correction_num_faulty_dts += dts <= ctx->pts_correction_last_dts; |
||
647 | ctx->pts_correction_last_dts = dts; |
||
648 | } |
||
649 | if (reordered_pts != AV_NOPTS_VALUE) {
|
||
650 | ctx->pts_correction_num_faulty_pts += reordered_pts <= ctx->pts_correction_last_pts; |
||
651 | ctx->pts_correction_last_pts = reordered_pts; |
||
652 | } |
||
653 | if ((ctx->pts_correction_num_faulty_pts<=ctx->pts_correction_num_faulty_dts || dts == AV_NOPTS_VALUE)
|
||
654 | && reordered_pts != AV_NOPTS_VALUE) |
||
655 | pts = reordered_pts; |
||
656 | else
|
||
657 | pts = dts; |
||
658 | |||
659 | return pts;
|
||
660 | } |
||
661 | |||
662 | |||
663 | 164bc38c | Aurelien Jacobs | #if FF_API_VIDEO_OLD
|
664 | 5e4c7ca2 | Ramiro Polla | int attribute_align_arg avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture,
|
665 | de6d9b64 | Fabrice Bellard | int *got_picture_ptr,
|
666 | 2efa7fd1 | Michael Niedermayer | const uint8_t *buf, int buf_size) |
667 | de6d9b64 | Fabrice Bellard | { |
668 | 7a00bbad | Thilo Borgmann | AVPacket avpkt; |
669 | av_init_packet(&avpkt); |
||
670 | avpkt.data = buf; |
||
671 | avpkt.size = buf_size; |
||
672 | 10f9ff9b | Reimar Döffinger | // HACK for CorePNG to decode as normal PNG by default
|
673 | avpkt.flags = AV_PKT_FLAG_KEY; |
||
674 | 7a00bbad | Thilo Borgmann | |
675 | return avcodec_decode_video2(avctx, picture, got_picture_ptr, &avpkt);
|
||
676 | } |
||
677 | #endif
|
||
678 | |||
679 | int attribute_align_arg avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture,
|
||
680 | int *got_picture_ptr,
|
||
681 | AVPacket *avpkt) |
||
682 | { |
||
683 | de6d9b64 | Fabrice Bellard | int ret;
|
684 | 115329f1 | Diego Biurrun | |
685 | 53db1cae | Michael Niedermayer | *got_picture_ptr= 0;
|
686 | e16f217c | Stefano Sabatini | if((avctx->coded_width||avctx->coded_height) && av_image_check_size(avctx->coded_width, avctx->coded_height, 0, avctx)) |
687 | 0ecca7a4 | Michael Niedermayer | return -1; |
688 | 393cbb96 | Michael Niedermayer | |
689 | avctx->pkt = avpkt; |
||
690 | |||
691 | b38f008e | Alexander Strange | if((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size || (avctx->active_thread_type&FF_THREAD_FRAME)){
|
692 | if (HAVE_PTHREADS && avctx->active_thread_type&FF_THREAD_FRAME)
|
||
693 | ret = ff_thread_decode_frame(avctx, picture, got_picture_ptr, |
||
694 | avpkt); |
||
695 | else {
|
||
696 | ret = avctx->codec->decode(avctx, picture, got_picture_ptr, |
||
697 | avpkt); |
||
698 | picture->pkt_dts= avpkt->dts; |
||
699 | } |
||
700 | 6bb925f4 | Michael Niedermayer | |
701 | bb628dae | Diego Biurrun | emms_c(); //needed to avoid an emms_c() call before every return;
|
702 | 115329f1 | Diego Biurrun | |
703 | 76ad67ca | Nicolas George | picture->best_effort_timestamp = guess_correct_pts(avctx, |
704 | picture->pkt_pts, |
||
705 | picture->pkt_dts); |
||
706 | 1919feaf | Michael Niedermayer | |
707 | 115329f1 | Diego Biurrun | if (*got_picture_ptr)
|
708 | 934982c4 | Michael Niedermayer | avctx->frame_number++; |
709 | }else
|
||
710 | ret= 0;
|
||
711 | |||
712 | de6d9b64 | Fabrice Bellard | return ret;
|
713 | } |
||
714 | |||
715 | a377cfa6 | Aurelien Jacobs | #if FF_API_AUDIO_OLD
|
716 | 5e4c7ca2 | Ramiro Polla | int attribute_align_arg avcodec_decode_audio2(AVCodecContext *avctx, int16_t *samples,
|
717 | de6d9b64 | Fabrice Bellard | int *frame_size_ptr,
|
718 | 2efa7fd1 | Michael Niedermayer | const uint8_t *buf, int buf_size) |
719 | de6d9b64 | Fabrice Bellard | { |
720 | 7a00bbad | Thilo Borgmann | AVPacket avpkt; |
721 | av_init_packet(&avpkt); |
||
722 | avpkt.data = buf; |
||
723 | avpkt.size = buf_size; |
||
724 | |||
725 | return avcodec_decode_audio3(avctx, samples, frame_size_ptr, &avpkt);
|
||
726 | } |
||
727 | #endif
|
||
728 | |||
729 | int attribute_align_arg avcodec_decode_audio3(AVCodecContext *avctx, int16_t *samples,
|
||
730 | int *frame_size_ptr,
|
||
731 | AVPacket *avpkt) |
||
732 | { |
||
733 | de6d9b64 | Fabrice Bellard | int ret;
|
734 | |||
735 | 393cbb96 | Michael Niedermayer | avctx->pkt = avpkt; |
736 | |||
737 | 7a00bbad | Thilo Borgmann | if((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size){
|
738 | 9c856d62 | Michael Niedermayer | //FIXME remove the check below _after_ ensuring that all audio check that the available space is enough
|
739 | if(*frame_size_ptr < AVCODEC_MAX_AUDIO_FRAME_SIZE){
|
||
740 | av_log(avctx, AV_LOG_ERROR, "buffer smaller than AVCODEC_MAX_AUDIO_FRAME_SIZE\n");
|
||
741 | return -1; |
||
742 | } |
||
743 | if(*frame_size_ptr < FF_MIN_BUFFER_SIZE ||
|
||
744 | 81fc2f37 | Kostya Shishkov | *frame_size_ptr < avctx->channels * avctx->frame_size * sizeof(int16_t)){
|
745 | 9c856d62 | Michael Niedermayer | av_log(avctx, AV_LOG_ERROR, "buffer %d too small\n", *frame_size_ptr);
|
746 | return -1; |
||
747 | } |
||
748 | |||
749 | 7a00bbad | Thilo Borgmann | ret = avctx->codec->decode(avctx, samples, frame_size_ptr, avpkt); |
750 | fec9ccb7 | Michael Niedermayer | avctx->frame_number++; |
751 | ac66834c | Michael Niedermayer | }else{
|
752 | fec9ccb7 | Michael Niedermayer | ret= 0;
|
753 | ac66834c | Michael Niedermayer | *frame_size_ptr=0;
|
754 | } |
||
755 | de6d9b64 | Fabrice Bellard | return ret;
|
756 | } |
||
757 | |||
758 | 448ce925 | Aurelien Jacobs | #if FF_API_SUBTITLE_OLD
|
759 | 240c1657 | Fabrice Bellard | int avcodec_decode_subtitle(AVCodecContext *avctx, AVSubtitle *sub,
|
760 | int *got_sub_ptr,
|
||
761 | const uint8_t *buf, int buf_size) |
||
762 | { |
||
763 | 7a00bbad | Thilo Borgmann | AVPacket avpkt; |
764 | av_init_packet(&avpkt); |
||
765 | avpkt.data = buf; |
||
766 | avpkt.size = buf_size; |
||
767 | |||
768 | return avcodec_decode_subtitle2(avctx, sub, got_sub_ptr, &avpkt);
|
||
769 | } |
||
770 | #endif
|
||
771 | |||
772 | int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub,
|
||
773 | int *got_sub_ptr,
|
||
774 | AVPacket *avpkt) |
||
775 | { |
||
776 | 240c1657 | Fabrice Bellard | int ret;
|
777 | |||
778 | 393cbb96 | Michael Niedermayer | avctx->pkt = avpkt; |
779 | 240c1657 | Fabrice Bellard | *got_sub_ptr = 0;
|
780 | 7a00bbad | Thilo Borgmann | ret = avctx->codec->decode(avctx, sub, got_sub_ptr, avpkt); |
781 | 240c1657 | Fabrice Bellard | if (*got_sub_ptr)
|
782 | avctx->frame_number++; |
||
783 | return ret;
|
||
784 | } |
||
785 | |||
786 | e1d7c883 | Reimar Döffinger | void avsubtitle_free(AVSubtitle *sub)
|
787 | { |
||
788 | int i;
|
||
789 | |||
790 | for (i = 0; i < sub->num_rects; i++) |
||
791 | { |
||
792 | 8b834ac5 | Reimar Döffinger | av_freep(&sub->rects[i]->pict.data[0]);
|
793 | av_freep(&sub->rects[i]->pict.data[1]);
|
||
794 | av_freep(&sub->rects[i]->pict.data[2]);
|
||
795 | av_freep(&sub->rects[i]->pict.data[3]);
|
||
796 | av_freep(&sub->rects[i]->text); |
||
797 | av_freep(&sub->rects[i]->ass); |
||
798 | av_freep(&sub->rects[i]); |
||
799 | e1d7c883 | Reimar Döffinger | } |
800 | |||
801 | 8b834ac5 | Reimar Döffinger | av_freep(&sub->rects); |
802 | e1d7c883 | Reimar Döffinger | |
803 | memset(sub, 0, sizeof(AVSubtitle)); |
||
804 | } |
||
805 | |||
806 | 0752cd39 | Zuxy Meng | av_cold int avcodec_close(AVCodecContext *avctx)
|
807 | de6d9b64 | Fabrice Bellard | { |
808 | f988ce6c | Andreas Öman | /* If there is a user-supplied mutex locking routine, call it. */
|
809 | if (ff_lockmgr_cb) {
|
||
810 | if ((*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_OBTAIN))
|
||
811 | return -1; |
||
812 | } |
||
813 | |||
814 | ddebfb15 | Michael Niedermayer | entangled_thread_counter++; |
815 | if(entangled_thread_counter != 1){ |
||
816 | av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n");
|
||
817 | entangled_thread_counter--; |
||
818 | return -1; |
||
819 | } |
||
820 | |||
821 | 49fb20cb | Aurelien Jacobs | if (HAVE_THREADS && avctx->thread_opaque)
|
822 | 043d2ff2 | Alexander Strange | ff_thread_free(avctx); |
823 | dccda293 | Michael Niedermayer | if (avctx->codec && avctx->codec->close)
|
824 | de6d9b64 | Fabrice Bellard | avctx->codec->close(avctx); |
825 | eea8c08f | Michael Niedermayer | avcodec_default_free_buffers(avctx); |
826 | b3ab3199 | Reimar Döffinger | avctx->coded_frame = NULL;
|
827 | 3123dd79 | Fabrice Bellard | av_freep(&avctx->priv_data); |
828 | 77a670e7 | Craig Thomasson | if(avctx->codec && avctx->codec->encode)
|
829 | c4f267ab | Vitor Sessak | av_freep(&avctx->extradata); |
830 | de6d9b64 | Fabrice Bellard | avctx->codec = NULL;
|
831 | b38f008e | Alexander Strange | avctx->active_thread_type = 0;
|
832 | ddebfb15 | Michael Niedermayer | entangled_thread_counter--; |
833 | f988ce6c | Andreas Öman | |
834 | /* Release any user-supplied mutex. */
|
||
835 | if (ff_lockmgr_cb) {
|
||
836 | (*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE); |
||
837 | } |
||
838 | de6d9b64 | Fabrice Bellard | return 0; |
839 | } |
||
840 | |||
841 | AVCodec *avcodec_find_encoder(enum CodecID id)
|
||
842 | { |
||
843 | 93ebfeea | Janne Grunau | AVCodec *p, *experimental=NULL;
|
844 | de6d9b64 | Fabrice Bellard | p = first_avcodec; |
845 | while (p) {
|
||
846 | 93ebfeea | Janne Grunau | if (p->encode != NULL && p->id == id) { |
847 | if (p->capabilities & CODEC_CAP_EXPERIMENTAL && !experimental) {
|
||
848 | experimental = p; |
||
849 | } else
|
||
850 | return p;
|
||
851 | } |
||
852 | de6d9b64 | Fabrice Bellard | p = p->next; |
853 | } |
||
854 | 93ebfeea | Janne Grunau | return experimental;
|
855 | de6d9b64 | Fabrice Bellard | } |
856 | |||
857 | 98f3b098 | Arpi | AVCodec *avcodec_find_encoder_by_name(const char *name) |
858 | { |
||
859 | AVCodec *p; |
||
860 | fc228c90 | Aurelien Jacobs | if (!name)
|
861 | return NULL; |
||
862 | 98f3b098 | Arpi | p = first_avcodec; |
863 | while (p) {
|
||
864 | if (p->encode != NULL && strcmp(name,p->name) == 0) |
||
865 | return p;
|
||
866 | p = p->next; |
||
867 | } |
||
868 | return NULL; |
||
869 | } |
||
870 | |||
871 | de6d9b64 | Fabrice Bellard | AVCodec *avcodec_find_decoder(enum CodecID id)
|
872 | { |
||
873 | AVCodec *p; |
||
874 | p = first_avcodec; |
||
875 | while (p) {
|
||
876 | if (p->decode != NULL && p->id == id) |
||
877 | return p;
|
||
878 | p = p->next; |
||
879 | } |
||
880 | return NULL; |
||
881 | } |
||
882 | |||
883 | AVCodec *avcodec_find_decoder_by_name(const char *name) |
||
884 | { |
||
885 | AVCodec *p; |
||
886 | fc228c90 | Aurelien Jacobs | if (!name)
|
887 | return NULL; |
||
888 | de6d9b64 | Fabrice Bellard | p = first_avcodec; |
889 | while (p) {
|
||
890 | if (p->decode != NULL && strcmp(name,p->name) == 0) |
||
891 | return p;
|
||
892 | p = p->next; |
||
893 | } |
||
894 | return NULL; |
||
895 | } |
||
896 | |||
897 | 406aa93f | Carl Eugen Hoyos | static int get_bit_rate(AVCodecContext *ctx) |
898 | ce34ff6b | Robert Krüger | { |
899 | int bit_rate;
|
||
900 | int bits_per_sample;
|
||
901 | |||
902 | switch(ctx->codec_type) {
|
||
903 | 72415b2a | Stefano Sabatini | case AVMEDIA_TYPE_VIDEO:
|
904 | 4563cf24 | Stefano Sabatini | case AVMEDIA_TYPE_DATA:
|
905 | case AVMEDIA_TYPE_SUBTITLE:
|
||
906 | case AVMEDIA_TYPE_ATTACHMENT:
|
||
907 | ce34ff6b | Robert Krüger | bit_rate = ctx->bit_rate; |
908 | break;
|
||
909 | 72415b2a | Stefano Sabatini | case AVMEDIA_TYPE_AUDIO:
|
910 | ce34ff6b | Robert Krüger | bits_per_sample = av_get_bits_per_sample(ctx->codec_id); |
911 | bit_rate = bits_per_sample ? ctx->sample_rate * ctx->channels * bits_per_sample : ctx->bit_rate; |
||
912 | break;
|
||
913 | default:
|
||
914 | bit_rate = 0;
|
||
915 | break;
|
||
916 | } |
||
917 | return bit_rate;
|
||
918 | } |
||
919 | |||
920 | 7e566bbe | Stefano Sabatini | size_t av_get_codec_tag_string(char *buf, size_t buf_size, unsigned int codec_tag) |
921 | { |
||
922 | int i, len, ret = 0; |
||
923 | |||
924 | for (i = 0; i < 4; i++) { |
||
925 | len = snprintf(buf, buf_size, |
||
926 | isprint(codec_tag&0xFF) ? "%c" : "[%d]", codec_tag&0xFF); |
||
927 | buf += len; |
||
928 | buf_size = buf_size > len ? buf_size - len : 0;
|
||
929 | ret += len; |
||
930 | codec_tag>>=8;
|
||
931 | } |
||
932 | return ret;
|
||
933 | } |
||
934 | |||
935 | de6d9b64 | Fabrice Bellard | void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode) |
936 | { |
||
937 | const char *codec_name; |
||
938 | 2a81f4bd | Anssi Hannula | const char *profile = NULL; |
939 | de6d9b64 | Fabrice Bellard | AVCodec *p; |
940 | char buf1[32]; |
||
941 | a96b68b7 | Fabrice Bellard | int bitrate;
|
942 | 59771f71 | Michel Bardiaux | AVRational display_aspect_ratio; |
943 | de6d9b64 | Fabrice Bellard | |
944 | if (encode)
|
||
945 | p = avcodec_find_encoder(enc->codec_id); |
||
946 | else
|
||
947 | p = avcodec_find_decoder(enc->codec_id); |
||
948 | |||
949 | if (p) {
|
||
950 | codec_name = p->name; |
||
951 | 2a81f4bd | Anssi Hannula | profile = av_get_profile_name(p, enc->profile); |
952 | 985180a1 | Fabrice Bellard | } else if (enc->codec_id == CODEC_ID_MPEG2TS) { |
953 | /* fake mpeg2 transport stream codec (currently not
|
||
954 | registered) */
|
||
955 | codec_name = "mpeg2ts";
|
||
956 | de6d9b64 | Fabrice Bellard | } else if (enc->codec_name[0] != '\0') { |
957 | codec_name = enc->codec_name; |
||
958 | } else {
|
||
959 | /* output avi tags */
|
||
960 | ab0b5378 | Stefano Sabatini | char tag_buf[32]; |
961 | av_get_codec_tag_string(tag_buf, sizeof(tag_buf), enc->codec_tag);
|
||
962 | snprintf(buf1, sizeof(buf1), "%s / 0x%04X", tag_buf, enc->codec_tag); |
||
963 | de6d9b64 | Fabrice Bellard | codec_name = buf1; |
964 | } |
||
965 | |||
966 | switch(enc->codec_type) {
|
||
967 | 72415b2a | Stefano Sabatini | case AVMEDIA_TYPE_VIDEO:
|
968 | de6d9b64 | Fabrice Bellard | snprintf(buf, buf_size, |
969 | "Video: %s%s",
|
||
970 | 7d1c3fc1 | Michael Niedermayer | codec_name, enc->mb_decision ? " (hq)" : ""); |
971 | 2a81f4bd | Anssi Hannula | if (profile)
|
972 | snprintf(buf + strlen(buf), buf_size - strlen(buf), |
||
973 | " (%s)", profile);
|
||
974 | 82c0c4ba | Michael Niedermayer | if (enc->pix_fmt != PIX_FMT_NONE) {
|
975 | cf087595 | Fabrice Bellard | snprintf(buf + strlen(buf), buf_size - strlen(buf), |
976 | ", %s",
|
||
977 | 9bbffbb1 | Fabrice Bellard | avcodec_get_pix_fmt_name(enc->pix_fmt)); |
978 | cf087595 | Fabrice Bellard | } |
979 | de6d9b64 | Fabrice Bellard | if (enc->width) {
|
980 | snprintf(buf + strlen(buf), buf_size - strlen(buf), |
||
981 | 21189011 | Michael Niedermayer | ", %dx%d",
|
982 | enc->width, enc->height); |
||
983 | 7ee4dd02 | Baptiste Coudurier | if (enc->sample_aspect_ratio.num) {
|
984 | cbaf50f8 | Baptiste Coudurier | av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den, |
985 | enc->width*enc->sample_aspect_ratio.num, |
||
986 | enc->height*enc->sample_aspect_ratio.den, |
||
987 | 1024*1024); |
||
988 | snprintf(buf + strlen(buf), buf_size - strlen(buf), |
||
989 | " [PAR %d:%d DAR %d:%d]",
|
||
990 | enc->sample_aspect_ratio.num, enc->sample_aspect_ratio.den, |
||
991 | display_aspect_ratio.num, display_aspect_ratio.den); |
||
992 | 7ee4dd02 | Baptiste Coudurier | } |
993 | a309073b | Måns Rullgård | if(av_log_get_level() >= AV_LOG_DEBUG){
|
994 | 9ce6c138 | Aurelien Jacobs | int g= av_gcd(enc->time_base.num, enc->time_base.den);
|
995 | 21189011 | Michael Niedermayer | snprintf(buf + strlen(buf), buf_size - strlen(buf), |
996 | ", %d/%d",
|
||
997 | enc->time_base.num/g, enc->time_base.den/g); |
||
998 | } |
||
999 | de6d9b64 | Fabrice Bellard | } |
1000 | 4bfad535 | Fabrice Bellard | if (encode) {
|
1001 | snprintf(buf + strlen(buf), buf_size - strlen(buf), |
||
1002 | ", q=%d-%d", enc->qmin, enc->qmax);
|
||
1003 | } |
||
1004 | de6d9b64 | Fabrice Bellard | break;
|
1005 | 72415b2a | Stefano Sabatini | case AVMEDIA_TYPE_AUDIO:
|
1006 | de6d9b64 | Fabrice Bellard | snprintf(buf, buf_size, |
1007 | "Audio: %s",
|
||
1008 | codec_name); |
||
1009 | 2a81f4bd | Anssi Hannula | if (profile)
|
1010 | snprintf(buf + strlen(buf), buf_size - strlen(buf), |
||
1011 | " (%s)", profile);
|
||
1012 | de6d9b64 | Fabrice Bellard | if (enc->sample_rate) {
|
1013 | snprintf(buf + strlen(buf), buf_size - strlen(buf), |
||
1014 | 0d72e7d0 | Peter Ross | ", %d Hz", enc->sample_rate);
|
1015 | de6d9b64 | Fabrice Bellard | } |
1016 | 0d72e7d0 | Peter Ross | av_strlcat(buf, ", ", buf_size);
|
1017 | 63e8d976 | Stefano Sabatini | av_get_channel_layout_string(buf + strlen(buf), buf_size - strlen(buf), enc->channels, enc->channel_layout); |
1018 | 5d6e4c16 | Stefano Sabatini | if (enc->sample_fmt != AV_SAMPLE_FMT_NONE) {
|
1019 | 9e82a113 | Peter Ross | snprintf(buf + strlen(buf), buf_size - strlen(buf), |
1020 | ba7d6e79 | Stefano Sabatini | ", %s", av_get_sample_fmt_name(enc->sample_fmt));
|
1021 | 9e82a113 | Peter Ross | } |
1022 | de6d9b64 | Fabrice Bellard | break;
|
1023 | 72415b2a | Stefano Sabatini | case AVMEDIA_TYPE_DATA:
|
1024 | 985180a1 | Fabrice Bellard | snprintf(buf, buf_size, "Data: %s", codec_name);
|
1025 | 240c1657 | Fabrice Bellard | break;
|
1026 | 72415b2a | Stefano Sabatini | case AVMEDIA_TYPE_SUBTITLE:
|
1027 | 240c1657 | Fabrice Bellard | snprintf(buf, buf_size, "Subtitle: %s", codec_name);
|
1028 | 985180a1 | Fabrice Bellard | break;
|
1029 | 72415b2a | Stefano Sabatini | case AVMEDIA_TYPE_ATTACHMENT:
|
1030 | f8d7c9d3 | Evgeniy Stepanov | snprintf(buf, buf_size, "Attachment: %s", codec_name);
|
1031 | break;
|
||
1032 | de6d9b64 | Fabrice Bellard | default:
|
1033 | 9fe5a7b8 | Michael Niedermayer | snprintf(buf, buf_size, "Invalid Codec type %d", enc->codec_type);
|
1034 | return;
|
||
1035 | de6d9b64 | Fabrice Bellard | } |
1036 | 4bfad535 | Fabrice Bellard | if (encode) {
|
1037 | if (enc->flags & CODEC_FLAG_PASS1)
|
||
1038 | snprintf(buf + strlen(buf), buf_size - strlen(buf), |
||
1039 | ", pass 1");
|
||
1040 | if (enc->flags & CODEC_FLAG_PASS2)
|
||
1041 | snprintf(buf + strlen(buf), buf_size - strlen(buf), |
||
1042 | ", pass 2");
|
||
1043 | } |
||
1044 | 406aa93f | Carl Eugen Hoyos | bitrate = get_bit_rate(enc); |
1045 | a96b68b7 | Fabrice Bellard | if (bitrate != 0) { |
1046 | 115329f1 | Diego Biurrun | snprintf(buf + strlen(buf), buf_size - strlen(buf), |
1047 | a96b68b7 | Fabrice Bellard | ", %d kb/s", bitrate / 1000); |
1048 | de6d9b64 | Fabrice Bellard | } |
1049 | } |
||
1050 | |||
1051 | 060ec0a8 | Anssi Hannula | const char *av_get_profile_name(const AVCodec *codec, int profile) |
1052 | { |
||
1053 | const AVProfile *p;
|
||
1054 | if (profile == FF_PROFILE_UNKNOWN || !codec->profiles)
|
||
1055 | return NULL; |
||
1056 | |||
1057 | for (p = codec->profiles; p->profile != FF_PROFILE_UNKNOWN; p++)
|
||
1058 | if (p->profile == profile)
|
||
1059 | return p->name;
|
||
1060 | |||
1061 | return NULL; |
||
1062 | } |
||
1063 | |||
1064 | 156e5023 | Nick Kurshev | unsigned avcodec_version( void ) |
1065 | { |
||
1066 | return LIBAVCODEC_VERSION_INT;
|
||
1067 | } |
||
1068 | cf087595 | Fabrice Bellard | |
1069 | 41600690 | Stefano Sabatini | const char *avcodec_configuration(void) |
1070 | c1736936 | Diego Biurrun | { |
1071 | return FFMPEG_CONFIGURATION;
|
||
1072 | } |
||
1073 | |||
1074 | 41600690 | Stefano Sabatini | const char *avcodec_license(void) |
1075 | c1736936 | Diego Biurrun | { |
1076 | #define LICENSE_PREFIX "libavcodec license: " |
||
1077 | return LICENSE_PREFIX FFMPEG_LICENSE + sizeof(LICENSE_PREFIX) - 1; |
||
1078 | } |
||
1079 | |||
1080 | de6d9b64 | Fabrice Bellard | void avcodec_init(void) |
1081 | { |
||
1082 | 5e534865 | Diego Biurrun | static int initialized = 0; |
1083 | 0344cd0a | Alex Beregszaszi | |
1084 | 5e534865 | Diego Biurrun | if (initialized != 0) |
1085 | bb270c08 | Diego Biurrun | return;
|
1086 | 5e534865 | Diego Biurrun | initialized = 1;
|
1087 | 0344cd0a | Alex Beregszaszi | |
1088 | 486497e0 | Måns Rullgård | dsputil_static_init(); |
1089 | de6d9b64 | Fabrice Bellard | } |
1090 | |||
1091 | 1c2a8c7f | Michael Niedermayer | void avcodec_flush_buffers(AVCodecContext *avctx)
|
1092 | { |
||
1093 | b38f008e | Alexander Strange | if(HAVE_PTHREADS && avctx->active_thread_type&FF_THREAD_FRAME)
|
1094 | ff_thread_flush(avctx); |
||
1095 | 7a06ff14 | Michael Niedermayer | if(avctx->codec->flush)
|
1096 | avctx->codec->flush(avctx); |
||
1097 | 1c2a8c7f | Michael Niedermayer | } |
1098 | |||
1099 | b100eab8 | Michael Niedermayer | void avcodec_default_free_buffers(AVCodecContext *s){
|
1100 | d90cf87b | Michael Niedermayer | int i, j;
|
1101 | |||
1102 | if(s->internal_buffer==NULL) return; |
||
1103 | 115329f1 | Diego Biurrun | |
1104 | ea09f691 | Reimar Döffinger | if (s->internal_buffer_count)
|
1105 | av_log(s, AV_LOG_WARNING, "Found %i unreleased buffers!\n", s->internal_buffer_count);
|
||
1106 | d90cf87b | Michael Niedermayer | for(i=0; i<INTERNAL_BUFFER_SIZE; i++){ |
1107 | InternalBuffer *buf= &((InternalBuffer*)s->internal_buffer)[i]; |
||
1108 | for(j=0; j<4; j++){ |
||
1109 | av_freep(&buf->base[j]); |
||
1110 | buf->data[j]= NULL;
|
||
1111 | } |
||
1112 | } |
||
1113 | av_freep(&s->internal_buffer); |
||
1114 | 115329f1 | Diego Biurrun | |
1115 | d90cf87b | Michael Niedermayer | s->internal_buffer_count=0;
|
1116 | } |
||
1117 | |||
1118 | d8085ea7 | Michael Niedermayer | char av_get_pict_type_char(int pict_type){ |
1119 | switch(pict_type){
|
||
1120 | fbd4293d | Aurelien Jacobs | case FF_I_TYPE: return 'I'; |
1121 | case FF_P_TYPE: return 'P'; |
||
1122 | case FF_B_TYPE: return 'B'; |
||
1123 | case FF_S_TYPE: return 'S'; |
||
1124 | case FF_SI_TYPE:return 'i'; |
||
1125 | case FF_SP_TYPE:return 'p'; |
||
1126 | 48d533e6 | Aurelien Jacobs | case FF_BI_TYPE:return 'b'; |
1127 | c06ccb13 | Aurelien Jacobs | default: return '?'; |
1128 | d8085ea7 | Michael Niedermayer | } |
1129 | } |
||
1130 | |||
1131 | ac3e1834 | Baptiste Coudurier | int av_get_bits_per_sample(enum CodecID codec_id){ |
1132 | switch(codec_id){
|
||
1133 | 5da71469 | Aurelien Jacobs | case CODEC_ID_ADPCM_SBPRO_2:
|
1134 | f1b163e0 | Aurelien Jacobs | return 2; |
1135 | 5da71469 | Aurelien Jacobs | case CODEC_ID_ADPCM_SBPRO_3:
|
1136 | f1b163e0 | Aurelien Jacobs | return 3; |
1137 | 5da71469 | Aurelien Jacobs | case CODEC_ID_ADPCM_SBPRO_4:
|
1138 | f1b163e0 | Aurelien Jacobs | case CODEC_ID_ADPCM_CT:
|
1139 | 07f2a575 | Carl Eugen Hoyos | case CODEC_ID_ADPCM_IMA_WAV:
|
1140 | 9df9b810 | Daniel Verkamp | case CODEC_ID_ADPCM_MS:
|
1141 | case CODEC_ID_ADPCM_YAMAHA:
|
||
1142 | f1b163e0 | Aurelien Jacobs | return 4; |
1143 | ac3e1834 | Baptiste Coudurier | case CODEC_ID_PCM_ALAW:
|
1144 | case CODEC_ID_PCM_MULAW:
|
||
1145 | case CODEC_ID_PCM_S8:
|
||
1146 | case CODEC_ID_PCM_U8:
|
||
1147 | 9d49b8ff | Peter Ross | case CODEC_ID_PCM_ZORK:
|
1148 | ac3e1834 | Baptiste Coudurier | return 8; |
1149 | case CODEC_ID_PCM_S16BE:
|
||
1150 | case CODEC_ID_PCM_S16LE:
|
||
1151 | 725d86bf | Aurelien Jacobs | case CODEC_ID_PCM_S16LE_PLANAR:
|
1152 | ac3e1834 | Baptiste Coudurier | case CODEC_ID_PCM_U16BE:
|
1153 | case CODEC_ID_PCM_U16LE:
|
||
1154 | return 16; |
||
1155 | case CODEC_ID_PCM_S24DAUD:
|
||
1156 | case CODEC_ID_PCM_S24BE:
|
||
1157 | case CODEC_ID_PCM_S24LE:
|
||
1158 | case CODEC_ID_PCM_U24BE:
|
||
1159 | case CODEC_ID_PCM_U24LE:
|
||
1160 | return 24; |
||
1161 | case CODEC_ID_PCM_S32BE:
|
||
1162 | case CODEC_ID_PCM_S32LE:
|
||
1163 | case CODEC_ID_PCM_U32BE:
|
||
1164 | case CODEC_ID_PCM_U32LE:
|
||
1165 | aa29709e | Peter Ross | case CODEC_ID_PCM_F32BE:
|
1166 | 143a5d6f | Peter Ross | case CODEC_ID_PCM_F32LE:
|
1167 | ac3e1834 | Baptiste Coudurier | return 32; |
1168 | 143a5d6f | Peter Ross | case CODEC_ID_PCM_F64BE:
|
1169 | case CODEC_ID_PCM_F64LE:
|
||
1170 | return 64; |
||
1171 | ac3e1834 | Baptiste Coudurier | default:
|
1172 | return 0; |
||
1173 | } |
||
1174 | } |
||
1175 | |||
1176 | 6f84cd12 | Stefano Sabatini | #if FF_API_OLD_SAMPLE_FMT
|
1177 | 5d6e4c16 | Stefano Sabatini | int av_get_bits_per_sample_format(enum AVSampleFormat sample_fmt) { |
1178 | 6f84cd12 | Stefano Sabatini | return av_get_bits_per_sample_fmt(sample_fmt);
|
1179 | 42c71907 | David Conrad | } |
1180 | 6f84cd12 | Stefano Sabatini | #endif
|
1181 | 42c71907 | David Conrad | |
1182 | b250f9c6 | Aurelien Jacobs | #if !HAVE_THREADS
|
1183 | 043d2ff2 | Alexander Strange | int ff_thread_init(AVCodecContext *s, int thread_count){ |
1184 | 2e418f5e | Stefano Sabatini | s->thread_count = thread_count; |
1185 | ca8ad847 | Michael Niedermayer | return -1; |
1186 | } |
||
1187 | #endif
|
||
1188 | ad2b531d | Måns Rullgård | |
1189 | unsigned int av_xiphlacing(unsigned char *s, unsigned int v) |
||
1190 | { |
||
1191 | unsigned int n = 0; |
||
1192 | |||
1193 | while(v >= 0xff) { |
||
1194 | *s++ = 0xff;
|
||
1195 | v -= 0xff;
|
||
1196 | n++; |
||
1197 | } |
||
1198 | *s = v; |
||
1199 | n++; |
||
1200 | return n;
|
||
1201 | } |
||
1202 | 1005f542 | Corey Hickey | |
1203 | 126b638e | Stefano Sabatini | #if LIBAVCODEC_VERSION_MAJOR < 53 |
1204 | #include "libavcore/parseutils.h" |
||
1205 | 26ef3220 | Stefano Sabatini | |
1206 | int av_parse_video_frame_size(int *width_ptr, int *height_ptr, const char *str) |
||
1207 | { |
||
1208 | 126b638e | Stefano Sabatini | return av_parse_video_size(width_ptr, height_ptr, str);
|
1209 | 26ef3220 | Stefano Sabatini | } |
1210 | |||
1211 | int av_parse_video_frame_rate(AVRational *frame_rate, const char *arg) |
||
1212 | { |
||
1213 | 126b638e | Stefano Sabatini | return av_parse_video_rate(frame_rate, arg);
|
1214 | 26ef3220 | Stefano Sabatini | } |
1215 | 126b638e | Stefano Sabatini | #endif
|
1216 | ea779d91 | Justin Ruggles | |
1217 | c46eeae2 | Michael Niedermayer | int ff_match_2uint16(const uint16_t (*tab)[2], int size, int a, int b){ |
1218 | int i;
|
||
1219 | for(i=0; i<size && !(tab[i][0]==a && tab[i][1]==b); i++); |
||
1220 | return i;
|
||
1221 | } |
||
1222 | |||
1223 | ce863d7f | Ronald S. Bultje | void av_log_missing_feature(void *avc, const char *feature, int want_sample) |
1224 | ea779d91 | Justin Ruggles | { |
1225 | av_log(avc, AV_LOG_WARNING, "%s not implemented. Update your FFmpeg "
|
||
1226 | db323491 | Janne Grunau | "version to the newest one from Git. If the problem still "
|
1227 | ea779d91 | Justin Ruggles | "occurs, it means that your file has a feature which has not "
|
1228 | "been implemented.", feature);
|
||
1229 | if(want_sample)
|
||
1230 | ce863d7f | Ronald S. Bultje | av_log_ask_for_sample(avc, NULL);
|
1231 | 0ba39dd1 | Kenan Gillet | else
|
1232 | av_log(avc, AV_LOG_WARNING, "\n");
|
||
1233 | } |
||
1234 | |||
1235 | ce863d7f | Ronald S. Bultje | void av_log_ask_for_sample(void *avc, const char *msg) |
1236 | 0ba39dd1 | Kenan Gillet | { |
1237 | if (msg)
|
||
1238 | av_log(avc, AV_LOG_WARNING, "%s ", msg);
|
||
1239 | av_log(avc, AV_LOG_WARNING, "If you want to help, upload a sample "
|
||
1240 | "of this file to ftp://upload.ffmpeg.org/MPlayer/incoming/ "
|
||
1241 | "and contact the ffmpeg-devel mailing list.\n");
|
||
1242 | ea779d91 | Justin Ruggles | } |
1243 | c895618b | Michael Niedermayer | |
1244 | static AVHWAccel *first_hwaccel = NULL; |
||
1245 | |||
1246 | void av_register_hwaccel(AVHWAccel *hwaccel)
|
||
1247 | { |
||
1248 | AVHWAccel **p = &first_hwaccel; |
||
1249 | while (*p)
|
||
1250 | p = &(*p)->next; |
||
1251 | *p = hwaccel; |
||
1252 | hwaccel->next = NULL;
|
||
1253 | } |
||
1254 | 414d9d7f | Michael Niedermayer | |
1255 | AVHWAccel *av_hwaccel_next(AVHWAccel *hwaccel) |
||
1256 | { |
||
1257 | return hwaccel ? hwaccel->next : first_hwaccel;
|
||
1258 | } |
||
1259 | 6059f13c | Michael Niedermayer | |
1260 | AVHWAccel *ff_find_hwaccel(enum CodecID codec_id, enum PixelFormat pix_fmt) |
||
1261 | { |
||
1262 | AVHWAccel *hwaccel=NULL;
|
||
1263 | |||
1264 | while((hwaccel= av_hwaccel_next(hwaccel))){
|
||
1265 | if ( hwaccel->id == codec_id
|
||
1266 | && hwaccel->pix_fmt == pix_fmt) |
||
1267 | return hwaccel;
|
||
1268 | } |
||
1269 | return NULL; |
||
1270 | } |
||
1271 | f988ce6c | Andreas Öman | |
1272 | int av_lockmgr_register(int (*cb)(void **mutex, enum AVLockOp op)) |
||
1273 | { |
||
1274 | if (ff_lockmgr_cb) {
|
||
1275 | if (ff_lockmgr_cb(&codec_mutex, AV_LOCK_DESTROY))
|
||
1276 | return -1; |
||
1277 | } |
||
1278 | |||
1279 | ff_lockmgr_cb = cb; |
||
1280 | |||
1281 | if (ff_lockmgr_cb) {
|
||
1282 | if (ff_lockmgr_cb(&codec_mutex, AV_LOCK_CREATE))
|
||
1283 | return -1; |
||
1284 | } |
||
1285 | return 0; |
||
1286 | } |
||
1287 | 603a5f04 | Francesco Lavra | |
1288 | unsigned int ff_toupper4(unsigned int x) |
||
1289 | { |
||
1290 | return toupper( x &0xFF) |
||
1291 | + (toupper((x>>8 )&0xFF)<<8 ) |
||
1292 | + (toupper((x>>16)&0xFF)<<16) |
||
1293 | + (toupper((x>>24)&0xFF)<<24); |
||
1294 | } |
||
1295 | b38f008e | Alexander Strange | |
1296 | #if !HAVE_PTHREADS
|
||
1297 | |||
1298 | int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f)
|
||
1299 | { |
||
1300 | f->owner = avctx; |
||
1301 | return avctx->get_buffer(avctx, f);
|
||
1302 | } |
||
1303 | |||
1304 | void ff_thread_release_buffer(AVCodecContext *avctx, AVFrame *f)
|
||
1305 | { |
||
1306 | f->owner->release_buffer(f->owner, f); |
||
1307 | } |
||
1308 | |||
1309 | void ff_thread_finish_setup(AVCodecContext *avctx)
|
||
1310 | { |
||
1311 | } |
||
1312 | |||
1313 | void ff_thread_report_progress(AVFrame *f, int progress, int field) |
||
1314 | { |
||
1315 | } |
||
1316 | |||
1317 | void ff_thread_await_progress(AVFrame *f, int progress, int field) |
||
1318 | { |
||
1319 | } |
||
1320 | |||
1321 | #endif
|
||
1322 | 043d2ff2 | Alexander Strange | |
1323 | #if LIBAVCODEC_VERSION_MAJOR < 53 |
||
1324 | |||
1325 | int avcodec_thread_init(AVCodecContext *s, int thread_count) |
||
1326 | { |
||
1327 | return ff_thread_init(s, thread_count);
|
||
1328 | } |
||
1329 | |||
1330 | void avcodec_thread_free(AVCodecContext *s)
|
||
1331 | { |
||
1332 | return ff_thread_free(s);
|
||
1333 | } |
||
1334 | |||
1335 | #endif |