Libav 0.7.1
|
00001 /* 00002 * utils for libavcodec 00003 * Copyright (c) 2001 Fabrice Bellard 00004 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at> 00005 * 00006 * This file is part of Libav. 00007 * 00008 * Libav is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU Lesser General Public 00010 * License as published by the Free Software Foundation; either 00011 * version 2.1 of the License, or (at your option) any later version. 00012 * 00013 * Libav is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 * Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public 00019 * License along with Libav; if not, write to the Free Software 00020 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00021 */ 00022 00028 #include "libavutil/avstring.h" 00029 #include "libavutil/integer.h" 00030 #include "libavutil/crc.h" 00031 #include "libavutil/pixdesc.h" 00032 #include "libavutil/audioconvert.h" 00033 #include "libavutil/imgutils.h" 00034 #include "libavutil/samplefmt.h" 00035 #include "avcodec.h" 00036 #include "dsputil.h" 00037 #include "libavutil/opt.h" 00038 #include "imgconvert.h" 00039 #include "thread.h" 00040 #include "audioconvert.h" 00041 #include "internal.h" 00042 #include <stdlib.h> 00043 #include <stdarg.h> 00044 #include <limits.h> 00045 #include <float.h> 00046 00047 static int volatile entangled_thread_counter=0; 00048 static int (*ff_lockmgr_cb)(void **mutex, enum AVLockOp op); 00049 static void *codec_mutex; 00050 00051 void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size) 00052 { 00053 if(min_size < *size) 00054 return ptr; 00055 00056 min_size= FFMAX(17*min_size/16 + 32, min_size); 00057 00058 ptr= av_realloc(ptr, min_size); 00059 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 00060 min_size= 0; 00061 00062 *size= min_size; 00063 00064 return ptr; 00065 } 00066 00067 void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size) 00068 { 00069 void **p = ptr; 00070 if (min_size < *size) 00071 return; 00072 min_size= FFMAX(17*min_size/16 + 32, min_size); 00073 av_free(*p); 00074 *p = av_malloc(min_size); 00075 if (!*p) min_size = 0; 00076 *size= min_size; 00077 } 00078 00079 /* encoder management */ 00080 static AVCodec *first_avcodec = NULL; 00081 00082 AVCodec *av_codec_next(AVCodec *c){ 00083 if(c) return c->next; 00084 else return first_avcodec; 00085 } 00086 00087 void avcodec_register(AVCodec *codec) 00088 { 00089 AVCodec **p; 00090 avcodec_init(); 00091 p = &first_avcodec; 00092 while (*p != NULL) p = &(*p)->next; 00093 *p = codec; 00094 codec->next = NULL; 00095 } 00096 00097 unsigned avcodec_get_edge_width(void) 00098 { 00099 return EDGE_WIDTH; 00100 } 00101 00102 void avcodec_set_dimensions(AVCodecContext *s, int width, int height){ 00103 s->coded_width = width; 00104 s->coded_height= height; 00105 s->width = -((-width )>>s->lowres); 00106 s->height= -((-height)>>s->lowres); 00107 } 00108 00109 typedef struct InternalBuffer{ 00110 int last_pic_num; 00111 uint8_t *base[4]; 00112 uint8_t *data[4]; 00113 int linesize[4]; 00114 int width, height; 00115 enum PixelFormat pix_fmt; 00116 }InternalBuffer; 00117 00118 #define INTERNAL_BUFFER_SIZE (32+1) 00119 00120 void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height, int linesize_align[4]){ 00121 int w_align= 1; 00122 int h_align= 1; 00123 00124 switch(s->pix_fmt){ 00125 case PIX_FMT_YUV420P: 00126 case PIX_FMT_YUYV422: 00127 case PIX_FMT_UYVY422: 00128 case PIX_FMT_YUV422P: 00129 case PIX_FMT_YUV440P: 00130 case PIX_FMT_YUV444P: 00131 case PIX_FMT_GRAY8: 00132 case PIX_FMT_GRAY16BE: 00133 case PIX_FMT_GRAY16LE: 00134 case PIX_FMT_YUVJ420P: 00135 case PIX_FMT_YUVJ422P: 00136 case PIX_FMT_YUVJ440P: 00137 case PIX_FMT_YUVJ444P: 00138 case PIX_FMT_YUVA420P: 00139 case PIX_FMT_YUV420P9LE: 00140 case PIX_FMT_YUV420P9BE: 00141 case PIX_FMT_YUV420P10LE: 00142 case PIX_FMT_YUV420P10BE: 00143 case PIX_FMT_YUV422P10LE: 00144 case PIX_FMT_YUV422P10BE: 00145 case PIX_FMT_YUV444P9LE: 00146 case PIX_FMT_YUV444P9BE: 00147 case PIX_FMT_YUV444P10LE: 00148 case PIX_FMT_YUV444P10BE: 00149 w_align= 16; //FIXME check for non mpeg style codecs and use less alignment 00150 h_align= 16; 00151 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) 00152 h_align= 32; // interlaced is rounded up to 2 MBs 00153 break; 00154 case PIX_FMT_YUV411P: 00155 case PIX_FMT_UYYVYY411: 00156 w_align=32; 00157 h_align=8; 00158 break; 00159 case PIX_FMT_YUV410P: 00160 if(s->codec_id == CODEC_ID_SVQ1){ 00161 w_align=64; 00162 h_align=64; 00163 } 00164 case PIX_FMT_RGB555: 00165 if(s->codec_id == CODEC_ID_RPZA){ 00166 w_align=4; 00167 h_align=4; 00168 } 00169 case PIX_FMT_PAL8: 00170 case PIX_FMT_BGR8: 00171 case PIX_FMT_RGB8: 00172 if(s->codec_id == CODEC_ID_SMC){ 00173 w_align=4; 00174 h_align=4; 00175 } 00176 break; 00177 case PIX_FMT_BGR24: 00178 if((s->codec_id == CODEC_ID_MSZH) || (s->codec_id == CODEC_ID_ZLIB)){ 00179 w_align=4; 00180 h_align=4; 00181 } 00182 break; 00183 default: 00184 w_align= 1; 00185 h_align= 1; 00186 break; 00187 } 00188 00189 *width = FFALIGN(*width , w_align); 00190 *height= FFALIGN(*height, h_align); 00191 if(s->codec_id == CODEC_ID_H264 || s->lowres) 00192 *height+=2; // some of the optimized chroma MC reads one line too much 00193 // which is also done in mpeg decoders with lowres > 0 00194 00195 linesize_align[0] = 00196 linesize_align[1] = 00197 linesize_align[2] = 00198 linesize_align[3] = STRIDE_ALIGN; 00199 //STRIDE_ALIGN is 8 for SSE* but this does not work for SVQ1 chroma planes 00200 //we could change STRIDE_ALIGN to 16 for x86/sse but it would increase the 00201 //picture size unneccessarily in some cases. The solution here is not 00202 //pretty and better ideas are welcome! 00203 #if HAVE_MMX 00204 if(s->codec_id == CODEC_ID_SVQ1 || s->codec_id == CODEC_ID_VP5 || 00205 s->codec_id == CODEC_ID_VP6 || s->codec_id == CODEC_ID_VP6F || 00206 s->codec_id == CODEC_ID_VP6A) { 00207 linesize_align[0] = 00208 linesize_align[1] = 00209 linesize_align[2] = 16; 00210 } 00211 #endif 00212 } 00213 00214 void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height){ 00215 int chroma_shift = av_pix_fmt_descriptors[s->pix_fmt].log2_chroma_w; 00216 int linesize_align[4]; 00217 int align; 00218 avcodec_align_dimensions2(s, width, height, linesize_align); 00219 align = FFMAX(linesize_align[0], linesize_align[3]); 00220 linesize_align[1] <<= chroma_shift; 00221 linesize_align[2] <<= chroma_shift; 00222 align = FFMAX3(align, linesize_align[1], linesize_align[2]); 00223 *width=FFALIGN(*width, align); 00224 } 00225 00226 int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic){ 00227 int i; 00228 int w= s->width; 00229 int h= s->height; 00230 InternalBuffer *buf; 00231 int *picture_number; 00232 00233 if(pic->data[0]!=NULL) { 00234 av_log(s, AV_LOG_ERROR, "pic->data[0]!=NULL in avcodec_default_get_buffer\n"); 00235 return -1; 00236 } 00237 if(s->internal_buffer_count >= INTERNAL_BUFFER_SIZE) { 00238 av_log(s, AV_LOG_ERROR, "internal_buffer_count overflow (missing release_buffer?)\n"); 00239 return -1; 00240 } 00241 00242 if(av_image_check_size(w, h, 0, s)) 00243 return -1; 00244 00245 if(s->internal_buffer==NULL){ 00246 s->internal_buffer= av_mallocz((INTERNAL_BUFFER_SIZE+1)*sizeof(InternalBuffer)); 00247 } 00248 #if 0 00249 s->internal_buffer= av_fast_realloc( 00250 s->internal_buffer, 00251 &s->internal_buffer_size, 00252 sizeof(InternalBuffer)*FFMAX(99, s->internal_buffer_count+1)/*FIXME*/ 00253 ); 00254 #endif 00255 00256 buf= &((InternalBuffer*)s->internal_buffer)[s->internal_buffer_count]; 00257 picture_number= &(((InternalBuffer*)s->internal_buffer)[INTERNAL_BUFFER_SIZE]).last_pic_num; //FIXME ugly hack 00258 (*picture_number)++; 00259 00260 if(buf->base[0] && (buf->width != w || buf->height != h || buf->pix_fmt != s->pix_fmt)){ 00261 if(s->active_thread_type&FF_THREAD_FRAME) { 00262 av_log_missing_feature(s, "Width/height changing with frame threads is", 0); 00263 return -1; 00264 } 00265 00266 for(i=0; i<4; i++){ 00267 av_freep(&buf->base[i]); 00268 buf->data[i]= NULL; 00269 } 00270 } 00271 00272 if(buf->base[0]){ 00273 pic->age= *picture_number - buf->last_pic_num; 00274 buf->last_pic_num= *picture_number; 00275 }else{ 00276 int h_chroma_shift, v_chroma_shift; 00277 int size[4] = {0}; 00278 int tmpsize; 00279 int unaligned; 00280 AVPicture picture; 00281 int stride_align[4]; 00282 const int pixel_size = av_pix_fmt_descriptors[s->pix_fmt].comp[0].step_minus1+1; 00283 00284 avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift); 00285 00286 avcodec_align_dimensions2(s, &w, &h, stride_align); 00287 00288 if(!(s->flags&CODEC_FLAG_EMU_EDGE)){ 00289 w+= EDGE_WIDTH*2; 00290 h+= EDGE_WIDTH*2; 00291 } 00292 00293 do { 00294 // NOTE: do not align linesizes individually, this breaks e.g. assumptions 00295 // that linesize[0] == 2*linesize[1] in the MPEG-encoder for 4:2:2 00296 av_image_fill_linesizes(picture.linesize, s->pix_fmt, w); 00297 // increase alignment of w for next try (rhs gives the lowest bit set in w) 00298 w += w & ~(w-1); 00299 00300 unaligned = 0; 00301 for (i=0; i<4; i++){ 00302 unaligned |= picture.linesize[i] % stride_align[i]; 00303 } 00304 } while (unaligned); 00305 00306 tmpsize = av_image_fill_pointers(picture.data, s->pix_fmt, h, NULL, picture.linesize); 00307 if (tmpsize < 0) 00308 return -1; 00309 00310 for (i=0; i<3 && picture.data[i+1]; i++) 00311 size[i] = picture.data[i+1] - picture.data[i]; 00312 size[i] = tmpsize - (picture.data[i] - picture.data[0]); 00313 00314 buf->last_pic_num= -256*256*256*64; 00315 memset(buf->base, 0, sizeof(buf->base)); 00316 memset(buf->data, 0, sizeof(buf->data)); 00317 00318 for(i=0; i<4 && size[i]; i++){ 00319 const int h_shift= i==0 ? 0 : h_chroma_shift; 00320 const int v_shift= i==0 ? 0 : v_chroma_shift; 00321 00322 buf->linesize[i]= picture.linesize[i]; 00323 00324 buf->base[i]= av_malloc(size[i]+16); //FIXME 16 00325 if(buf->base[i]==NULL) return -1; 00326 memset(buf->base[i], 128, size[i]); 00327 00328 // no edge if EDGE EMU or not planar YUV 00329 if((s->flags&CODEC_FLAG_EMU_EDGE) || !size[2]) 00330 buf->data[i] = buf->base[i]; 00331 else 00332 buf->data[i] = buf->base[i] + FFALIGN((buf->linesize[i]*EDGE_WIDTH>>v_shift) + (pixel_size*EDGE_WIDTH>>h_shift), stride_align[i]); 00333 } 00334 if(size[1] && !size[2]) 00335 ff_set_systematic_pal2((uint32_t*)buf->data[1], s->pix_fmt); 00336 buf->width = s->width; 00337 buf->height = s->height; 00338 buf->pix_fmt= s->pix_fmt; 00339 pic->age= 256*256*256*64; 00340 } 00341 pic->type= FF_BUFFER_TYPE_INTERNAL; 00342 00343 for(i=0; i<4; i++){ 00344 pic->base[i]= buf->base[i]; 00345 pic->data[i]= buf->data[i]; 00346 pic->linesize[i]= buf->linesize[i]; 00347 } 00348 s->internal_buffer_count++; 00349 00350 if(s->pkt) pic->pkt_pts= s->pkt->pts; 00351 else pic->pkt_pts= AV_NOPTS_VALUE; 00352 pic->reordered_opaque= s->reordered_opaque; 00353 00354 if(s->debug&FF_DEBUG_BUFFERS) 00355 av_log(s, AV_LOG_DEBUG, "default_get_buffer called on pic %p, %d buffers used\n", pic, s->internal_buffer_count); 00356 00357 return 0; 00358 } 00359 00360 void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic){ 00361 int i; 00362 InternalBuffer *buf, *last; 00363 00364 assert(pic->type==FF_BUFFER_TYPE_INTERNAL); 00365 assert(s->internal_buffer_count); 00366 00367 if(s->internal_buffer){ 00368 buf = NULL; /* avoids warning */ 00369 for(i=0; i<s->internal_buffer_count; i++){ //just 3-5 checks so is not worth to optimize 00370 buf= &((InternalBuffer*)s->internal_buffer)[i]; 00371 if(buf->data[0] == pic->data[0]) 00372 break; 00373 } 00374 assert(i < s->internal_buffer_count); 00375 s->internal_buffer_count--; 00376 last = &((InternalBuffer*)s->internal_buffer)[s->internal_buffer_count]; 00377 00378 FFSWAP(InternalBuffer, *buf, *last); 00379 } 00380 00381 for(i=0; i<4; i++){ 00382 pic->data[i]=NULL; 00383 // pic->base[i]=NULL; 00384 } 00385 //printf("R%X\n", pic->opaque); 00386 00387 if(s->debug&FF_DEBUG_BUFFERS) 00388 av_log(s, AV_LOG_DEBUG, "default_release_buffer called on pic %p, %d buffers used\n", pic, s->internal_buffer_count); 00389 } 00390 00391 int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic){ 00392 AVFrame temp_pic; 00393 int i; 00394 00395 /* If no picture return a new buffer */ 00396 if(pic->data[0] == NULL) { 00397 /* We will copy from buffer, so must be readable */ 00398 pic->buffer_hints |= FF_BUFFER_HINTS_READABLE; 00399 return s->get_buffer(s, pic); 00400 } 00401 00402 /* If internal buffer type return the same buffer */ 00403 if(pic->type == FF_BUFFER_TYPE_INTERNAL) { 00404 if(s->pkt) pic->pkt_pts= s->pkt->pts; 00405 else pic->pkt_pts= AV_NOPTS_VALUE; 00406 pic->reordered_opaque= s->reordered_opaque; 00407 return 0; 00408 } 00409 00410 /* 00411 * Not internal type and reget_buffer not overridden, emulate cr buffer 00412 */ 00413 temp_pic = *pic; 00414 for(i = 0; i < 4; i++) 00415 pic->data[i] = pic->base[i] = NULL; 00416 pic->opaque = NULL; 00417 /* Allocate new frame */ 00418 if (s->get_buffer(s, pic)) 00419 return -1; 00420 /* Copy image data from old buffer to new buffer */ 00421 av_picture_copy((AVPicture*)pic, (AVPicture*)&temp_pic, s->pix_fmt, s->width, 00422 s->height); 00423 s->release_buffer(s, &temp_pic); // Release old frame 00424 return 0; 00425 } 00426 00427 int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size){ 00428 int i; 00429 00430 for(i=0; i<count; i++){ 00431 int r= func(c, (char*)arg + i*size); 00432 if(ret) ret[i]= r; 00433 } 00434 return 0; 00435 } 00436 00437 int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int jobnr, int threadnr),void *arg, int *ret, int count){ 00438 int i; 00439 00440 for(i=0; i<count; i++){ 00441 int r= func(c, arg, i, 0); 00442 if(ret) ret[i]= r; 00443 } 00444 return 0; 00445 } 00446 00447 enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum PixelFormat *fmt){ 00448 while (*fmt != PIX_FMT_NONE && ff_is_hwaccel_pix_fmt(*fmt)) 00449 ++fmt; 00450 return fmt[0]; 00451 } 00452 00453 void avcodec_get_frame_defaults(AVFrame *pic){ 00454 memset(pic, 0, sizeof(AVFrame)); 00455 00456 pic->pts= AV_NOPTS_VALUE; 00457 pic->key_frame= 1; 00458 } 00459 00460 AVFrame *avcodec_alloc_frame(void){ 00461 AVFrame *pic= av_malloc(sizeof(AVFrame)); 00462 00463 if(pic==NULL) return NULL; 00464 00465 avcodec_get_frame_defaults(pic); 00466 00467 return pic; 00468 } 00469 00470 int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec) 00471 { 00472 int ret = 0; 00473 00474 /* If there is a user-supplied mutex locking routine, call it. */ 00475 if (ff_lockmgr_cb) { 00476 if ((*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_OBTAIN)) 00477 return -1; 00478 } 00479 00480 entangled_thread_counter++; 00481 if(entangled_thread_counter != 1){ 00482 av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n"); 00483 ret = -1; 00484 goto end; 00485 } 00486 00487 if(avctx->codec || !codec) { 00488 ret = AVERROR(EINVAL); 00489 goto end; 00490 } 00491 00492 if (codec->priv_data_size > 0) { 00493 if(!avctx->priv_data){ 00494 avctx->priv_data = av_mallocz(codec->priv_data_size); 00495 if (!avctx->priv_data) { 00496 ret = AVERROR(ENOMEM); 00497 goto end; 00498 } 00499 if(codec->priv_class){ //this can be droped once all user apps use avcodec_get_context_defaults3() 00500 *(AVClass**)avctx->priv_data= codec->priv_class; 00501 av_opt_set_defaults(avctx->priv_data); 00502 } 00503 } 00504 } else { 00505 avctx->priv_data = NULL; 00506 } 00507 00508 if(avctx->coded_width && avctx->coded_height) 00509 avcodec_set_dimensions(avctx, avctx->coded_width, avctx->coded_height); 00510 else if(avctx->width && avctx->height) 00511 avcodec_set_dimensions(avctx, avctx->width, avctx->height); 00512 00513 if ((avctx->coded_width || avctx->coded_height || avctx->width || avctx->height) 00514 && ( av_image_check_size(avctx->coded_width, avctx->coded_height, 0, avctx) < 0 00515 || av_image_check_size(avctx->width, avctx->height, 0, avctx) < 0)) { 00516 av_log(avctx, AV_LOG_WARNING, "ignoring invalid width/height values\n"); 00517 avcodec_set_dimensions(avctx, 0, 0); 00518 } 00519 00520 /* if the decoder init function was already called previously, 00521 free the already allocated subtitle_header before overwriting it */ 00522 if (codec->decode) 00523 av_freep(&avctx->subtitle_header); 00524 00525 #define SANE_NB_CHANNELS 128U 00526 if (avctx->channels > SANE_NB_CHANNELS) { 00527 ret = AVERROR(EINVAL); 00528 goto free_and_end; 00529 } 00530 00531 avctx->codec = codec; 00532 if ((avctx->codec_type == AVMEDIA_TYPE_UNKNOWN || avctx->codec_type == codec->type) && 00533 avctx->codec_id == CODEC_ID_NONE) { 00534 avctx->codec_type = codec->type; 00535 avctx->codec_id = codec->id; 00536 } 00537 if (avctx->codec_id != codec->id || (avctx->codec_type != codec->type 00538 && avctx->codec_type != AVMEDIA_TYPE_ATTACHMENT)) { 00539 av_log(avctx, AV_LOG_ERROR, "codec type or id mismatches\n"); 00540 ret = AVERROR(EINVAL); 00541 goto free_and_end; 00542 } 00543 avctx->frame_number = 0; 00544 00545 if (HAVE_THREADS && !avctx->thread_opaque) { 00546 ret = ff_thread_init(avctx); 00547 if (ret < 0) { 00548 goto free_and_end; 00549 } 00550 } 00551 00552 if (avctx->codec->max_lowres < avctx->lowres) { 00553 av_log(avctx, AV_LOG_ERROR, "The maximum value for lowres supported by the decoder is %d\n", 00554 avctx->codec->max_lowres); 00555 ret = AVERROR(EINVAL); 00556 goto free_and_end; 00557 } 00558 if (avctx->codec->encode) { 00559 int i; 00560 if (avctx->codec->sample_fmts) { 00561 for (i = 0; avctx->codec->sample_fmts[i] != AV_SAMPLE_FMT_NONE; i++) 00562 if (avctx->sample_fmt == avctx->codec->sample_fmts[i]) 00563 break; 00564 if (avctx->codec->sample_fmts[i] == AV_SAMPLE_FMT_NONE) { 00565 av_log(avctx, AV_LOG_ERROR, "Specified sample_fmt is not supported.\n"); 00566 ret = AVERROR(EINVAL); 00567 goto free_and_end; 00568 } 00569 } 00570 if (avctx->codec->supported_samplerates) { 00571 for (i = 0; avctx->codec->supported_samplerates[i] != 0; i++) 00572 if (avctx->sample_rate == avctx->codec->supported_samplerates[i]) 00573 break; 00574 if (avctx->codec->supported_samplerates[i] == 0) { 00575 av_log(avctx, AV_LOG_ERROR, "Specified sample_rate is not supported\n"); 00576 ret = AVERROR(EINVAL); 00577 goto free_and_end; 00578 } 00579 } 00580 if (avctx->codec->channel_layouts) { 00581 if (!avctx->channel_layout) { 00582 av_log(avctx, AV_LOG_WARNING, "channel_layout not specified\n"); 00583 } else { 00584 for (i = 0; avctx->codec->channel_layouts[i] != 0; i++) 00585 if (avctx->channel_layout == avctx->codec->channel_layouts[i]) 00586 break; 00587 if (avctx->codec->channel_layouts[i] == 0) { 00588 av_log(avctx, AV_LOG_ERROR, "Specified channel_layout is not supported\n"); 00589 ret = AVERROR(EINVAL); 00590 goto free_and_end; 00591 } 00592 } 00593 } 00594 if (avctx->channel_layout && avctx->channels) { 00595 if (av_get_channel_layout_nb_channels(avctx->channel_layout) != avctx->channels) { 00596 av_log(avctx, AV_LOG_ERROR, "channel layout does not match number of channels\n"); 00597 ret = AVERROR(EINVAL); 00598 goto free_and_end; 00599 } 00600 } else if (avctx->channel_layout) { 00601 avctx->channels = av_get_channel_layout_nb_channels(avctx->channel_layout); 00602 } 00603 } 00604 00605 if(avctx->codec->init && !(avctx->active_thread_type&FF_THREAD_FRAME)){ 00606 ret = avctx->codec->init(avctx); 00607 if (ret < 0) { 00608 goto free_and_end; 00609 } 00610 } 00611 end: 00612 entangled_thread_counter--; 00613 00614 /* Release any user-supplied mutex. */ 00615 if (ff_lockmgr_cb) { 00616 (*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE); 00617 } 00618 return ret; 00619 free_and_end: 00620 av_freep(&avctx->priv_data); 00621 avctx->codec= NULL; 00622 goto end; 00623 } 00624 00625 int attribute_align_arg avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size, 00626 const short *samples) 00627 { 00628 if(buf_size < FF_MIN_BUFFER_SIZE && 0){ 00629 av_log(avctx, AV_LOG_ERROR, "buffer smaller than minimum size\n"); 00630 return -1; 00631 } 00632 if((avctx->codec->capabilities & CODEC_CAP_DELAY) || samples){ 00633 int ret = avctx->codec->encode(avctx, buf, buf_size, samples); 00634 avctx->frame_number++; 00635 return ret; 00636 }else 00637 return 0; 00638 } 00639 00640 int attribute_align_arg avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size, 00641 const AVFrame *pict) 00642 { 00643 if(buf_size < FF_MIN_BUFFER_SIZE){ 00644 av_log(avctx, AV_LOG_ERROR, "buffer smaller than minimum size\n"); 00645 return -1; 00646 } 00647 if(av_image_check_size(avctx->width, avctx->height, 0, avctx)) 00648 return -1; 00649 if((avctx->codec->capabilities & CODEC_CAP_DELAY) || pict){ 00650 int ret = avctx->codec->encode(avctx, buf, buf_size, pict); 00651 avctx->frame_number++; 00652 emms_c(); //needed to avoid an emms_c() call before every return; 00653 00654 return ret; 00655 }else 00656 return 0; 00657 } 00658 00659 int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size, 00660 const AVSubtitle *sub) 00661 { 00662 int ret; 00663 if(sub->start_display_time) { 00664 av_log(avctx, AV_LOG_ERROR, "start_display_time must be 0.\n"); 00665 return -1; 00666 } 00667 if(sub->num_rects == 0 || !sub->rects) 00668 return -1; 00669 ret = avctx->codec->encode(avctx, buf, buf_size, sub); 00670 avctx->frame_number++; 00671 return ret; 00672 } 00673 00674 int attribute_align_arg avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture, 00675 int *got_picture_ptr, 00676 AVPacket *avpkt) 00677 { 00678 int ret; 00679 00680 *got_picture_ptr= 0; 00681 if((avctx->coded_width||avctx->coded_height) && av_image_check_size(avctx->coded_width, avctx->coded_height, 0, avctx)) 00682 return -1; 00683 00684 avctx->pkt = avpkt; 00685 00686 if((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size || (avctx->active_thread_type&FF_THREAD_FRAME)){ 00687 if (HAVE_PTHREADS && avctx->active_thread_type&FF_THREAD_FRAME) 00688 ret = ff_thread_decode_frame(avctx, picture, got_picture_ptr, 00689 avpkt); 00690 else { 00691 ret = avctx->codec->decode(avctx, picture, got_picture_ptr, 00692 avpkt); 00693 picture->pkt_dts= avpkt->dts; 00694 } 00695 00696 emms_c(); //needed to avoid an emms_c() call before every return; 00697 00698 if (*got_picture_ptr) 00699 avctx->frame_number++; 00700 }else 00701 ret= 0; 00702 00703 return ret; 00704 } 00705 00706 int attribute_align_arg avcodec_decode_audio3(AVCodecContext *avctx, int16_t *samples, 00707 int *frame_size_ptr, 00708 AVPacket *avpkt) 00709 { 00710 int ret; 00711 00712 avctx->pkt = avpkt; 00713 00714 if((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size){ 00715 //FIXME remove the check below _after_ ensuring that all audio check that the available space is enough 00716 if(*frame_size_ptr < AVCODEC_MAX_AUDIO_FRAME_SIZE){ 00717 av_log(avctx, AV_LOG_ERROR, "buffer smaller than AVCODEC_MAX_AUDIO_FRAME_SIZE\n"); 00718 return -1; 00719 } 00720 if(*frame_size_ptr < FF_MIN_BUFFER_SIZE || 00721 *frame_size_ptr < avctx->channels * avctx->frame_size * sizeof(int16_t)){ 00722 av_log(avctx, AV_LOG_ERROR, "buffer %d too small\n", *frame_size_ptr); 00723 return -1; 00724 } 00725 00726 ret = avctx->codec->decode(avctx, samples, frame_size_ptr, avpkt); 00727 avctx->frame_number++; 00728 }else{ 00729 ret= 0; 00730 *frame_size_ptr=0; 00731 } 00732 return ret; 00733 } 00734 00735 int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, 00736 int *got_sub_ptr, 00737 AVPacket *avpkt) 00738 { 00739 int ret; 00740 00741 avctx->pkt = avpkt; 00742 *got_sub_ptr = 0; 00743 ret = avctx->codec->decode(avctx, sub, got_sub_ptr, avpkt); 00744 if (*got_sub_ptr) 00745 avctx->frame_number++; 00746 return ret; 00747 } 00748 00749 void avsubtitle_free(AVSubtitle *sub) 00750 { 00751 int i; 00752 00753 for (i = 0; i < sub->num_rects; i++) 00754 { 00755 av_freep(&sub->rects[i]->pict.data[0]); 00756 av_freep(&sub->rects[i]->pict.data[1]); 00757 av_freep(&sub->rects[i]->pict.data[2]); 00758 av_freep(&sub->rects[i]->pict.data[3]); 00759 av_freep(&sub->rects[i]->text); 00760 av_freep(&sub->rects[i]->ass); 00761 av_freep(&sub->rects[i]); 00762 } 00763 00764 av_freep(&sub->rects); 00765 00766 memset(sub, 0, sizeof(AVSubtitle)); 00767 } 00768 00769 av_cold int avcodec_close(AVCodecContext *avctx) 00770 { 00771 /* If there is a user-supplied mutex locking routine, call it. */ 00772 if (ff_lockmgr_cb) { 00773 if ((*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_OBTAIN)) 00774 return -1; 00775 } 00776 00777 entangled_thread_counter++; 00778 if(entangled_thread_counter != 1){ 00779 av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n"); 00780 entangled_thread_counter--; 00781 return -1; 00782 } 00783 00784 if (HAVE_THREADS && avctx->thread_opaque) 00785 ff_thread_free(avctx); 00786 if (avctx->codec && avctx->codec->close) 00787 avctx->codec->close(avctx); 00788 avcodec_default_free_buffers(avctx); 00789 avctx->coded_frame = NULL; 00790 if (avctx->codec && avctx->codec->priv_class) 00791 av_opt_free(avctx->priv_data); 00792 av_opt_free(avctx); 00793 av_freep(&avctx->priv_data); 00794 if(avctx->codec && avctx->codec->encode) 00795 av_freep(&avctx->extradata); 00796 avctx->codec = NULL; 00797 avctx->active_thread_type = 0; 00798 entangled_thread_counter--; 00799 00800 /* Release any user-supplied mutex. */ 00801 if (ff_lockmgr_cb) { 00802 (*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE); 00803 } 00804 return 0; 00805 } 00806 00807 AVCodec *avcodec_find_encoder(enum CodecID id) 00808 { 00809 AVCodec *p, *experimental=NULL; 00810 p = first_avcodec; 00811 while (p) { 00812 if (p->encode != NULL && p->id == id) { 00813 if (p->capabilities & CODEC_CAP_EXPERIMENTAL && !experimental) { 00814 experimental = p; 00815 } else 00816 return p; 00817 } 00818 p = p->next; 00819 } 00820 return experimental; 00821 } 00822 00823 AVCodec *avcodec_find_encoder_by_name(const char *name) 00824 { 00825 AVCodec *p; 00826 if (!name) 00827 return NULL; 00828 p = first_avcodec; 00829 while (p) { 00830 if (p->encode != NULL && strcmp(name,p->name) == 0) 00831 return p; 00832 p = p->next; 00833 } 00834 return NULL; 00835 } 00836 00837 AVCodec *avcodec_find_decoder(enum CodecID id) 00838 { 00839 AVCodec *p; 00840 p = first_avcodec; 00841 while (p) { 00842 if (p->decode != NULL && p->id == id) 00843 return p; 00844 p = p->next; 00845 } 00846 return NULL; 00847 } 00848 00849 AVCodec *avcodec_find_decoder_by_name(const char *name) 00850 { 00851 AVCodec *p; 00852 if (!name) 00853 return NULL; 00854 p = first_avcodec; 00855 while (p) { 00856 if (p->decode != NULL && strcmp(name,p->name) == 0) 00857 return p; 00858 p = p->next; 00859 } 00860 return NULL; 00861 } 00862 00863 static int get_bit_rate(AVCodecContext *ctx) 00864 { 00865 int bit_rate; 00866 int bits_per_sample; 00867 00868 switch(ctx->codec_type) { 00869 case AVMEDIA_TYPE_VIDEO: 00870 case AVMEDIA_TYPE_DATA: 00871 case AVMEDIA_TYPE_SUBTITLE: 00872 case AVMEDIA_TYPE_ATTACHMENT: 00873 bit_rate = ctx->bit_rate; 00874 break; 00875 case AVMEDIA_TYPE_AUDIO: 00876 bits_per_sample = av_get_bits_per_sample(ctx->codec_id); 00877 bit_rate = bits_per_sample ? ctx->sample_rate * ctx->channels * bits_per_sample : ctx->bit_rate; 00878 break; 00879 default: 00880 bit_rate = 0; 00881 break; 00882 } 00883 return bit_rate; 00884 } 00885 00886 size_t av_get_codec_tag_string(char *buf, size_t buf_size, unsigned int codec_tag) 00887 { 00888 int i, len, ret = 0; 00889 00890 for (i = 0; i < 4; i++) { 00891 len = snprintf(buf, buf_size, 00892 isprint(codec_tag&0xFF) ? "%c" : "[%d]", codec_tag&0xFF); 00893 buf += len; 00894 buf_size = buf_size > len ? buf_size - len : 0; 00895 ret += len; 00896 codec_tag>>=8; 00897 } 00898 return ret; 00899 } 00900 00901 void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode) 00902 { 00903 const char *codec_name; 00904 const char *profile = NULL; 00905 AVCodec *p; 00906 char buf1[32]; 00907 int bitrate; 00908 AVRational display_aspect_ratio; 00909 00910 if (encode) 00911 p = avcodec_find_encoder(enc->codec_id); 00912 else 00913 p = avcodec_find_decoder(enc->codec_id); 00914 00915 if (p) { 00916 codec_name = p->name; 00917 profile = av_get_profile_name(p, enc->profile); 00918 } else if (enc->codec_id == CODEC_ID_MPEG2TS) { 00919 /* fake mpeg2 transport stream codec (currently not 00920 registered) */ 00921 codec_name = "mpeg2ts"; 00922 } else if (enc->codec_name[0] != '\0') { 00923 codec_name = enc->codec_name; 00924 } else { 00925 /* output avi tags */ 00926 char tag_buf[32]; 00927 av_get_codec_tag_string(tag_buf, sizeof(tag_buf), enc->codec_tag); 00928 snprintf(buf1, sizeof(buf1), "%s / 0x%04X", tag_buf, enc->codec_tag); 00929 codec_name = buf1; 00930 } 00931 00932 switch(enc->codec_type) { 00933 case AVMEDIA_TYPE_VIDEO: 00934 snprintf(buf, buf_size, 00935 "Video: %s%s", 00936 codec_name, enc->mb_decision ? " (hq)" : ""); 00937 if (profile) 00938 snprintf(buf + strlen(buf), buf_size - strlen(buf), 00939 " (%s)", profile); 00940 if (enc->pix_fmt != PIX_FMT_NONE) { 00941 snprintf(buf + strlen(buf), buf_size - strlen(buf), 00942 ", %s", 00943 av_get_pix_fmt_name(enc->pix_fmt)); 00944 } 00945 if (enc->width) { 00946 snprintf(buf + strlen(buf), buf_size - strlen(buf), 00947 ", %dx%d", 00948 enc->width, enc->height); 00949 if (enc->sample_aspect_ratio.num) { 00950 av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den, 00951 enc->width*enc->sample_aspect_ratio.num, 00952 enc->height*enc->sample_aspect_ratio.den, 00953 1024*1024); 00954 snprintf(buf + strlen(buf), buf_size - strlen(buf), 00955 " [PAR %d:%d DAR %d:%d]", 00956 enc->sample_aspect_ratio.num, enc->sample_aspect_ratio.den, 00957 display_aspect_ratio.num, display_aspect_ratio.den); 00958 } 00959 if(av_log_get_level() >= AV_LOG_DEBUG){ 00960 int g= av_gcd(enc->time_base.num, enc->time_base.den); 00961 snprintf(buf + strlen(buf), buf_size - strlen(buf), 00962 ", %d/%d", 00963 enc->time_base.num/g, enc->time_base.den/g); 00964 } 00965 } 00966 if (encode) { 00967 snprintf(buf + strlen(buf), buf_size - strlen(buf), 00968 ", q=%d-%d", enc->qmin, enc->qmax); 00969 } 00970 break; 00971 case AVMEDIA_TYPE_AUDIO: 00972 snprintf(buf, buf_size, 00973 "Audio: %s", 00974 codec_name); 00975 if (profile) 00976 snprintf(buf + strlen(buf), buf_size - strlen(buf), 00977 " (%s)", profile); 00978 if (enc->sample_rate) { 00979 snprintf(buf + strlen(buf), buf_size - strlen(buf), 00980 ", %d Hz", enc->sample_rate); 00981 } 00982 av_strlcat(buf, ", ", buf_size); 00983 av_get_channel_layout_string(buf + strlen(buf), buf_size - strlen(buf), enc->channels, enc->channel_layout); 00984 if (enc->sample_fmt != AV_SAMPLE_FMT_NONE) { 00985 snprintf(buf + strlen(buf), buf_size - strlen(buf), 00986 ", %s", av_get_sample_fmt_name(enc->sample_fmt)); 00987 } 00988 break; 00989 case AVMEDIA_TYPE_DATA: 00990 snprintf(buf, buf_size, "Data: %s", codec_name); 00991 break; 00992 case AVMEDIA_TYPE_SUBTITLE: 00993 snprintf(buf, buf_size, "Subtitle: %s", codec_name); 00994 break; 00995 case AVMEDIA_TYPE_ATTACHMENT: 00996 snprintf(buf, buf_size, "Attachment: %s", codec_name); 00997 break; 00998 default: 00999 snprintf(buf, buf_size, "Invalid Codec type %d", enc->codec_type); 01000 return; 01001 } 01002 if (encode) { 01003 if (enc->flags & CODEC_FLAG_PASS1) 01004 snprintf(buf + strlen(buf), buf_size - strlen(buf), 01005 ", pass 1"); 01006 if (enc->flags & CODEC_FLAG_PASS2) 01007 snprintf(buf + strlen(buf), buf_size - strlen(buf), 01008 ", pass 2"); 01009 } 01010 bitrate = get_bit_rate(enc); 01011 if (bitrate != 0) { 01012 snprintf(buf + strlen(buf), buf_size - strlen(buf), 01013 ", %d kb/s", bitrate / 1000); 01014 } 01015 } 01016 01017 const char *av_get_profile_name(const AVCodec *codec, int profile) 01018 { 01019 const AVProfile *p; 01020 if (profile == FF_PROFILE_UNKNOWN || !codec->profiles) 01021 return NULL; 01022 01023 for (p = codec->profiles; p->profile != FF_PROFILE_UNKNOWN; p++) 01024 if (p->profile == profile) 01025 return p->name; 01026 01027 return NULL; 01028 } 01029 01030 unsigned avcodec_version( void ) 01031 { 01032 return LIBAVCODEC_VERSION_INT; 01033 } 01034 01035 const char *avcodec_configuration(void) 01036 { 01037 return LIBAV_CONFIGURATION; 01038 } 01039 01040 const char *avcodec_license(void) 01041 { 01042 #define LICENSE_PREFIX "libavcodec license: " 01043 return LICENSE_PREFIX LIBAV_LICENSE + sizeof(LICENSE_PREFIX) - 1; 01044 } 01045 01046 void avcodec_init(void) 01047 { 01048 static int initialized = 0; 01049 01050 if (initialized != 0) 01051 return; 01052 initialized = 1; 01053 01054 dsputil_static_init(); 01055 } 01056 01057 void avcodec_flush_buffers(AVCodecContext *avctx) 01058 { 01059 if(HAVE_PTHREADS && avctx->active_thread_type&FF_THREAD_FRAME) 01060 ff_thread_flush(avctx); 01061 else if(avctx->codec->flush) 01062 avctx->codec->flush(avctx); 01063 } 01064 01065 void avcodec_default_free_buffers(AVCodecContext *s){ 01066 int i, j; 01067 01068 if(s->internal_buffer==NULL) return; 01069 01070 if (s->internal_buffer_count) 01071 av_log(s, AV_LOG_WARNING, "Found %i unreleased buffers!\n", s->internal_buffer_count); 01072 for(i=0; i<INTERNAL_BUFFER_SIZE; i++){ 01073 InternalBuffer *buf= &((InternalBuffer*)s->internal_buffer)[i]; 01074 for(j=0; j<4; j++){ 01075 av_freep(&buf->base[j]); 01076 buf->data[j]= NULL; 01077 } 01078 } 01079 av_freep(&s->internal_buffer); 01080 01081 s->internal_buffer_count=0; 01082 } 01083 01084 #if FF_API_OLD_FF_PICT_TYPES 01085 char av_get_pict_type_char(int pict_type){ 01086 return av_get_picture_type_char(pict_type); 01087 } 01088 #endif 01089 01090 int av_get_bits_per_sample(enum CodecID codec_id){ 01091 switch(codec_id){ 01092 case CODEC_ID_ADPCM_SBPRO_2: 01093 return 2; 01094 case CODEC_ID_ADPCM_SBPRO_3: 01095 return 3; 01096 case CODEC_ID_ADPCM_SBPRO_4: 01097 case CODEC_ID_ADPCM_CT: 01098 case CODEC_ID_ADPCM_IMA_WAV: 01099 case CODEC_ID_ADPCM_MS: 01100 case CODEC_ID_ADPCM_YAMAHA: 01101 return 4; 01102 case CODEC_ID_ADPCM_G722: 01103 case CODEC_ID_PCM_ALAW: 01104 case CODEC_ID_PCM_MULAW: 01105 case CODEC_ID_PCM_S8: 01106 case CODEC_ID_PCM_U8: 01107 case CODEC_ID_PCM_ZORK: 01108 return 8; 01109 case CODEC_ID_PCM_S16BE: 01110 case CODEC_ID_PCM_S16LE: 01111 case CODEC_ID_PCM_S16LE_PLANAR: 01112 case CODEC_ID_PCM_U16BE: 01113 case CODEC_ID_PCM_U16LE: 01114 return 16; 01115 case CODEC_ID_PCM_S24DAUD: 01116 case CODEC_ID_PCM_S24BE: 01117 case CODEC_ID_PCM_S24LE: 01118 case CODEC_ID_PCM_U24BE: 01119 case CODEC_ID_PCM_U24LE: 01120 return 24; 01121 case CODEC_ID_PCM_S32BE: 01122 case CODEC_ID_PCM_S32LE: 01123 case CODEC_ID_PCM_U32BE: 01124 case CODEC_ID_PCM_U32LE: 01125 case CODEC_ID_PCM_F32BE: 01126 case CODEC_ID_PCM_F32LE: 01127 return 32; 01128 case CODEC_ID_PCM_F64BE: 01129 case CODEC_ID_PCM_F64LE: 01130 return 64; 01131 default: 01132 return 0; 01133 } 01134 } 01135 01136 #if FF_API_OLD_SAMPLE_FMT 01137 int av_get_bits_per_sample_format(enum AVSampleFormat sample_fmt) { 01138 return av_get_bits_per_sample_fmt(sample_fmt); 01139 } 01140 #endif 01141 01142 #if !HAVE_THREADS 01143 int ff_thread_init(AVCodecContext *s){ 01144 return -1; 01145 } 01146 #endif 01147 01148 unsigned int av_xiphlacing(unsigned char *s, unsigned int v) 01149 { 01150 unsigned int n = 0; 01151 01152 while(v >= 0xff) { 01153 *s++ = 0xff; 01154 v -= 0xff; 01155 n++; 01156 } 01157 *s = v; 01158 n++; 01159 return n; 01160 } 01161 01162 int ff_match_2uint16(const uint16_t (*tab)[2], int size, int a, int b){ 01163 int i; 01164 for(i=0; i<size && !(tab[i][0]==a && tab[i][1]==b); i++); 01165 return i; 01166 } 01167 01168 void av_log_missing_feature(void *avc, const char *feature, int want_sample) 01169 { 01170 av_log(avc, AV_LOG_WARNING, "%s not implemented. Update your Libav " 01171 "version to the newest one from Git. If the problem still " 01172 "occurs, it means that your file has a feature which has not " 01173 "been implemented.\n", feature); 01174 if(want_sample) 01175 av_log_ask_for_sample(avc, NULL); 01176 } 01177 01178 void av_log_ask_for_sample(void *avc, const char *msg, ...) 01179 { 01180 va_list argument_list; 01181 01182 va_start(argument_list, msg); 01183 01184 if (msg) 01185 av_vlog(avc, AV_LOG_WARNING, msg, argument_list); 01186 av_log(avc, AV_LOG_WARNING, "If you want to help, upload a sample " 01187 "of this file to ftp://upload.libav.org/incoming/ " 01188 "and contact the libav-devel mailing list.\n"); 01189 01190 va_end(argument_list); 01191 } 01192 01193 static AVHWAccel *first_hwaccel = NULL; 01194 01195 void av_register_hwaccel(AVHWAccel *hwaccel) 01196 { 01197 AVHWAccel **p = &first_hwaccel; 01198 while (*p) 01199 p = &(*p)->next; 01200 *p = hwaccel; 01201 hwaccel->next = NULL; 01202 } 01203 01204 AVHWAccel *av_hwaccel_next(AVHWAccel *hwaccel) 01205 { 01206 return hwaccel ? hwaccel->next : first_hwaccel; 01207 } 01208 01209 AVHWAccel *ff_find_hwaccel(enum CodecID codec_id, enum PixelFormat pix_fmt) 01210 { 01211 AVHWAccel *hwaccel=NULL; 01212 01213 while((hwaccel= av_hwaccel_next(hwaccel))){ 01214 if ( hwaccel->id == codec_id 01215 && hwaccel->pix_fmt == pix_fmt) 01216 return hwaccel; 01217 } 01218 return NULL; 01219 } 01220 01221 int av_lockmgr_register(int (*cb)(void **mutex, enum AVLockOp op)) 01222 { 01223 if (ff_lockmgr_cb) { 01224 if (ff_lockmgr_cb(&codec_mutex, AV_LOCK_DESTROY)) 01225 return -1; 01226 } 01227 01228 ff_lockmgr_cb = cb; 01229 01230 if (ff_lockmgr_cb) { 01231 if (ff_lockmgr_cb(&codec_mutex, AV_LOCK_CREATE)) 01232 return -1; 01233 } 01234 return 0; 01235 } 01236 01237 unsigned int ff_toupper4(unsigned int x) 01238 { 01239 return toupper( x &0xFF) 01240 + (toupper((x>>8 )&0xFF)<<8 ) 01241 + (toupper((x>>16)&0xFF)<<16) 01242 + (toupper((x>>24)&0xFF)<<24); 01243 } 01244 01245 #if !HAVE_PTHREADS 01246 01247 int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f) 01248 { 01249 f->owner = avctx; 01250 return avctx->get_buffer(avctx, f); 01251 } 01252 01253 void ff_thread_release_buffer(AVCodecContext *avctx, AVFrame *f) 01254 { 01255 f->owner->release_buffer(f->owner, f); 01256 } 01257 01258 void ff_thread_finish_setup(AVCodecContext *avctx) 01259 { 01260 } 01261 01262 void ff_thread_report_progress(AVFrame *f, int progress, int field) 01263 { 01264 } 01265 01266 void ff_thread_await_progress(AVFrame *f, int progress, int field) 01267 { 01268 } 01269 01270 #endif 01271 01272 #if FF_API_THREAD_INIT 01273 int avcodec_thread_init(AVCodecContext *s, int thread_count) 01274 { 01275 s->thread_count = thread_count; 01276 return ff_thread_init(s); 01277 } 01278 #endif