You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1277 lines
36KB

  1. /*
  2. * utils for libavcodec
  3. * Copyright (c) 2001 Fabrice Bellard
  4. * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. /**
  23. * @file libavcodec/utils.c
  24. * utils.
  25. */
  26. /* needed for mkstemp() */
  27. #define _XOPEN_SOURCE 600
  28. #include "libavutil/avstring.h"
  29. #include "libavutil/integer.h"
  30. #include "libavutil/crc.h"
  31. #include "avcodec.h"
  32. #include "dsputil.h"
  33. #include "opt.h"
  34. #include "imgconvert.h"
  35. #include "audioconvert.h"
  36. #include "internal.h"
  37. #include <stdlib.h>
  38. #include <stdarg.h>
  39. #include <limits.h>
  40. #include <float.h>
  41. #if !HAVE_MKSTEMP
  42. #include <fcntl.h>
  43. #endif
  44. static int volatile entangled_thread_counter=0;
  45. int (*ff_lockmgr_cb)(void **mutex, enum AVLockOp op);
  46. static void *codec_mutex;
  47. void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size)
  48. {
  49. if(min_size < *size)
  50. return ptr;
  51. *size= FFMAX(17*min_size/16 + 32, min_size);
  52. ptr= av_realloc(ptr, *size);
  53. 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
  54. *size= 0;
  55. return ptr;
  56. }
  57. void av_fast_malloc(void *ptr, unsigned int *size, unsigned int min_size)
  58. {
  59. void **p = ptr;
  60. if (min_size < *size)
  61. return;
  62. *size= FFMAX(17*min_size/16 + 32, min_size);
  63. av_free(*p);
  64. *p = av_malloc(*size);
  65. if (!*p) *size = 0;
  66. }
  67. /* encoder management */
  68. static AVCodec *first_avcodec = NULL;
  69. AVCodec *av_codec_next(AVCodec *c){
  70. if(c) return c->next;
  71. else return first_avcodec;
  72. }
  73. void avcodec_register(AVCodec *codec)
  74. {
  75. AVCodec **p;
  76. avcodec_init();
  77. p = &first_avcodec;
  78. while (*p != NULL) p = &(*p)->next;
  79. *p = codec;
  80. codec->next = NULL;
  81. }
  82. #if LIBAVCODEC_VERSION_MAJOR < 53
  83. void register_avcodec(AVCodec *codec)
  84. {
  85. avcodec_register(codec);
  86. }
  87. #endif
  88. void avcodec_set_dimensions(AVCodecContext *s, int width, int height){
  89. s->coded_width = width;
  90. s->coded_height= height;
  91. s->width = -((-width )>>s->lowres);
  92. s->height= -((-height)>>s->lowres);
  93. }
  94. typedef struct InternalBuffer{
  95. int last_pic_num;
  96. uint8_t *base[4];
  97. uint8_t *data[4];
  98. int linesize[4];
  99. int width, height;
  100. enum PixelFormat pix_fmt;
  101. }InternalBuffer;
  102. #define INTERNAL_BUFFER_SIZE 32
  103. void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height){
  104. int w_align= 1;
  105. int h_align= 1;
  106. switch(s->pix_fmt){
  107. case PIX_FMT_YUV420P:
  108. case PIX_FMT_YUYV422:
  109. case PIX_FMT_UYVY422:
  110. case PIX_FMT_YUV422P:
  111. case PIX_FMT_YUV440P:
  112. case PIX_FMT_YUV444P:
  113. case PIX_FMT_GRAY8:
  114. case PIX_FMT_GRAY16BE:
  115. case PIX_FMT_GRAY16LE:
  116. case PIX_FMT_YUVJ420P:
  117. case PIX_FMT_YUVJ422P:
  118. case PIX_FMT_YUVJ440P:
  119. case PIX_FMT_YUVJ444P:
  120. case PIX_FMT_YUVA420P:
  121. w_align= 16; //FIXME check for non mpeg style codecs and use less alignment
  122. h_align= 16;
  123. 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)
  124. h_align= 32; // interlaced is rounded up to 2 MBs
  125. break;
  126. case PIX_FMT_YUV411P:
  127. case PIX_FMT_UYYVYY411:
  128. w_align=32;
  129. h_align=8;
  130. break;
  131. case PIX_FMT_YUV410P:
  132. if(s->codec_id == CODEC_ID_SVQ1){
  133. w_align=64;
  134. h_align=64;
  135. }
  136. case PIX_FMT_RGB555:
  137. if(s->codec_id == CODEC_ID_RPZA){
  138. w_align=4;
  139. h_align=4;
  140. }
  141. case PIX_FMT_PAL8:
  142. case PIX_FMT_BGR8:
  143. case PIX_FMT_RGB8:
  144. if(s->codec_id == CODEC_ID_SMC){
  145. w_align=4;
  146. h_align=4;
  147. }
  148. break;
  149. case PIX_FMT_BGR24:
  150. if((s->codec_id == CODEC_ID_MSZH) || (s->codec_id == CODEC_ID_ZLIB)){
  151. w_align=4;
  152. h_align=4;
  153. }
  154. break;
  155. default:
  156. w_align= 1;
  157. h_align= 1;
  158. break;
  159. }
  160. *width = FFALIGN(*width , w_align);
  161. *height= FFALIGN(*height, h_align);
  162. if(s->codec_id == CODEC_ID_H264)
  163. *height+=2; // some of the optimized chroma MC reads one line too much
  164. }
  165. int avcodec_check_dimensions(void *av_log_ctx, unsigned int w, unsigned int h){
  166. if((int)w>0 && (int)h>0 && (w+128)*(uint64_t)(h+128) < INT_MAX/8)
  167. return 0;
  168. av_log(av_log_ctx, AV_LOG_ERROR, "picture size invalid (%ux%u)\n", w, h);
  169. return -1;
  170. }
  171. int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic){
  172. int i;
  173. int w= s->width;
  174. int h= s->height;
  175. InternalBuffer *buf;
  176. int *picture_number;
  177. if(pic->data[0]!=NULL) {
  178. av_log(s, AV_LOG_ERROR, "pic->data[0]!=NULL in avcodec_default_get_buffer\n");
  179. return -1;
  180. }
  181. if(s->internal_buffer_count >= INTERNAL_BUFFER_SIZE) {
  182. av_log(s, AV_LOG_ERROR, "internal_buffer_count overflow (missing release_buffer?)\n");
  183. return -1;
  184. }
  185. if(avcodec_check_dimensions(s,w,h))
  186. return -1;
  187. if(s->internal_buffer==NULL){
  188. s->internal_buffer= av_mallocz((INTERNAL_BUFFER_SIZE+1)*sizeof(InternalBuffer));
  189. }
  190. #if 0
  191. s->internal_buffer= av_fast_realloc(
  192. s->internal_buffer,
  193. &s->internal_buffer_size,
  194. sizeof(InternalBuffer)*FFMAX(99, s->internal_buffer_count+1)/*FIXME*/
  195. );
  196. #endif
  197. buf= &((InternalBuffer*)s->internal_buffer)[s->internal_buffer_count];
  198. picture_number= &(((InternalBuffer*)s->internal_buffer)[INTERNAL_BUFFER_SIZE]).last_pic_num; //FIXME ugly hack
  199. (*picture_number)++;
  200. if(buf->base[0] && (buf->width != w || buf->height != h || buf->pix_fmt != s->pix_fmt)){
  201. for(i=0; i<4; i++){
  202. av_freep(&buf->base[i]);
  203. buf->data[i]= NULL;
  204. }
  205. }
  206. if(buf->base[0]){
  207. pic->age= *picture_number - buf->last_pic_num;
  208. buf->last_pic_num= *picture_number;
  209. }else{
  210. int h_chroma_shift, v_chroma_shift;
  211. int size[4] = {0};
  212. int tmpsize;
  213. int unaligned;
  214. AVPicture picture;
  215. int stride_align[4];
  216. avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift);
  217. avcodec_align_dimensions(s, &w, &h);
  218. if(!(s->flags&CODEC_FLAG_EMU_EDGE)){
  219. w+= EDGE_WIDTH*2;
  220. h+= EDGE_WIDTH*2;
  221. }
  222. do {
  223. // NOTE: do not align linesizes individually, this breaks e.g. assumptions
  224. // that linesize[0] == 2*linesize[1] in the MPEG-encoder for 4:2:2
  225. ff_fill_linesize(&picture, s->pix_fmt, w);
  226. // increase alignment of w for next try (rhs gives the lowest bit set in w)
  227. w += w & ~(w-1);
  228. unaligned = 0;
  229. for (i=0; i<4; i++){
  230. //STRIDE_ALIGN is 8 for SSE* but this does not work for SVQ1 chroma planes
  231. //we could change STRIDE_ALIGN to 16 for x86/sse but it would increase the
  232. //picture size unneccessarily in some cases. The solution here is not
  233. //pretty and better ideas are welcome!
  234. #if HAVE_MMX
  235. if(s->codec_id == CODEC_ID_SVQ1 || s->codec_id == CODEC_ID_VP5 ||
  236. s->codec_id == CODEC_ID_VP6 || s->codec_id == CODEC_ID_VP6F ||
  237. s->codec_id == CODEC_ID_VP6A)
  238. stride_align[i]= 16;
  239. else
  240. #endif
  241. stride_align[i] = STRIDE_ALIGN;
  242. unaligned |= picture.linesize[i] % stride_align[i];
  243. }
  244. } while (unaligned);
  245. tmpsize = ff_fill_pointer(&picture, NULL, s->pix_fmt, h);
  246. if (tmpsize < 0)
  247. return -1;
  248. for (i=0; i<3 && picture.data[i+1]; i++)
  249. size[i] = picture.data[i+1] - picture.data[i];
  250. size[i] = tmpsize - (picture.data[i] - picture.data[0]);
  251. buf->last_pic_num= -256*256*256*64;
  252. memset(buf->base, 0, sizeof(buf->base));
  253. memset(buf->data, 0, sizeof(buf->data));
  254. for(i=0; i<4 && size[i]; i++){
  255. const int h_shift= i==0 ? 0 : h_chroma_shift;
  256. const int v_shift= i==0 ? 0 : v_chroma_shift;
  257. buf->linesize[i]= picture.linesize[i];
  258. buf->base[i]= av_malloc(size[i]+16); //FIXME 16
  259. if(buf->base[i]==NULL) return -1;
  260. memset(buf->base[i], 128, size[i]);
  261. // no edge if EDEG EMU or not planar YUV
  262. if((s->flags&CODEC_FLAG_EMU_EDGE) || !size[2])
  263. buf->data[i] = buf->base[i];
  264. else
  265. buf->data[i] = buf->base[i] + FFALIGN((buf->linesize[i]*EDGE_WIDTH>>v_shift) + (EDGE_WIDTH>>h_shift), stride_align[i]);
  266. }
  267. if(size[1] && !size[2])
  268. ff_set_systematic_pal((uint32_t*)buf->data[1], s->pix_fmt);
  269. buf->width = s->width;
  270. buf->height = s->height;
  271. buf->pix_fmt= s->pix_fmt;
  272. pic->age= 256*256*256*64;
  273. }
  274. pic->type= FF_BUFFER_TYPE_INTERNAL;
  275. for(i=0; i<4; i++){
  276. pic->base[i]= buf->base[i];
  277. pic->data[i]= buf->data[i];
  278. pic->linesize[i]= buf->linesize[i];
  279. }
  280. s->internal_buffer_count++;
  281. pic->reordered_opaque= s->reordered_opaque;
  282. if(s->debug&FF_DEBUG_BUFFERS)
  283. av_log(s, AV_LOG_DEBUG, "default_get_buffer called on pic %p, %d buffers used\n", pic, s->internal_buffer_count);
  284. return 0;
  285. }
  286. void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic){
  287. int i;
  288. InternalBuffer *buf, *last;
  289. assert(pic->type==FF_BUFFER_TYPE_INTERNAL);
  290. assert(s->internal_buffer_count);
  291. buf = NULL; /* avoids warning */
  292. for(i=0; i<s->internal_buffer_count; i++){ //just 3-5 checks so is not worth to optimize
  293. buf= &((InternalBuffer*)s->internal_buffer)[i];
  294. if(buf->data[0] == pic->data[0])
  295. break;
  296. }
  297. assert(i < s->internal_buffer_count);
  298. s->internal_buffer_count--;
  299. last = &((InternalBuffer*)s->internal_buffer)[s->internal_buffer_count];
  300. FFSWAP(InternalBuffer, *buf, *last);
  301. for(i=0; i<4; i++){
  302. pic->data[i]=NULL;
  303. // pic->base[i]=NULL;
  304. }
  305. //printf("R%X\n", pic->opaque);
  306. if(s->debug&FF_DEBUG_BUFFERS)
  307. av_log(s, AV_LOG_DEBUG, "default_release_buffer called on pic %p, %d buffers used\n", pic, s->internal_buffer_count);
  308. }
  309. int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic){
  310. AVFrame temp_pic;
  311. int i;
  312. /* If no picture return a new buffer */
  313. if(pic->data[0] == NULL) {
  314. /* We will copy from buffer, so must be readable */
  315. pic->buffer_hints |= FF_BUFFER_HINTS_READABLE;
  316. return s->get_buffer(s, pic);
  317. }
  318. /* If internal buffer type return the same buffer */
  319. if(pic->type == FF_BUFFER_TYPE_INTERNAL) {
  320. pic->reordered_opaque= s->reordered_opaque;
  321. return 0;
  322. }
  323. /*
  324. * Not internal type and reget_buffer not overridden, emulate cr buffer
  325. */
  326. temp_pic = *pic;
  327. for(i = 0; i < 4; i++)
  328. pic->data[i] = pic->base[i] = NULL;
  329. pic->opaque = NULL;
  330. /* Allocate new frame */
  331. if (s->get_buffer(s, pic))
  332. return -1;
  333. /* Copy image data from old buffer to new buffer */
  334. av_picture_copy((AVPicture*)pic, (AVPicture*)&temp_pic, s->pix_fmt, s->width,
  335. s->height);
  336. s->release_buffer(s, &temp_pic); // Release old frame
  337. return 0;
  338. }
  339. int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size){
  340. int i;
  341. for(i=0; i<count; i++){
  342. int r= func(c, (char*)arg + i*size);
  343. if(ret) ret[i]= r;
  344. }
  345. return 0;
  346. }
  347. int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int jobnr, int threadnr),void *arg, int *ret, int count){
  348. int i;
  349. for(i=0; i<count; i++){
  350. int r= func(c, arg, i, 0);
  351. if(ret) ret[i]= r;
  352. }
  353. return 0;
  354. }
  355. enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum PixelFormat *fmt){
  356. while (*fmt != PIX_FMT_NONE && ff_is_hwaccel_pix_fmt(*fmt))
  357. ++fmt;
  358. return fmt[0];
  359. }
  360. void avcodec_get_frame_defaults(AVFrame *pic){
  361. memset(pic, 0, sizeof(AVFrame));
  362. pic->pts= AV_NOPTS_VALUE;
  363. pic->key_frame= 1;
  364. }
  365. AVFrame *avcodec_alloc_frame(void){
  366. AVFrame *pic= av_malloc(sizeof(AVFrame));
  367. if(pic==NULL) return NULL;
  368. avcodec_get_frame_defaults(pic);
  369. return pic;
  370. }
  371. int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec)
  372. {
  373. int ret= -1;
  374. /* If there is a user-supplied mutex locking routine, call it. */
  375. if (ff_lockmgr_cb) {
  376. if ((*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_OBTAIN))
  377. return -1;
  378. }
  379. entangled_thread_counter++;
  380. if(entangled_thread_counter != 1){
  381. av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n");
  382. goto end;
  383. }
  384. if(avctx->codec || !codec)
  385. goto end;
  386. if (codec->priv_data_size > 0) {
  387. avctx->priv_data = av_mallocz(codec->priv_data_size);
  388. if (!avctx->priv_data) {
  389. ret = AVERROR(ENOMEM);
  390. goto end;
  391. }
  392. } else {
  393. avctx->priv_data = NULL;
  394. }
  395. if(avctx->coded_width && avctx->coded_height)
  396. avcodec_set_dimensions(avctx, avctx->coded_width, avctx->coded_height);
  397. else if(avctx->width && avctx->height)
  398. avcodec_set_dimensions(avctx, avctx->width, avctx->height);
  399. #define SANE_NB_CHANNELS 128U
  400. if (((avctx->coded_width || avctx->coded_height)
  401. && avcodec_check_dimensions(avctx, avctx->coded_width, avctx->coded_height))
  402. || avctx->channels > SANE_NB_CHANNELS) {
  403. ret = AVERROR(EINVAL);
  404. goto free_and_end;
  405. }
  406. avctx->codec = codec;
  407. if ((avctx->codec_type == CODEC_TYPE_UNKNOWN || avctx->codec_type == codec->type) &&
  408. avctx->codec_id == CODEC_ID_NONE) {
  409. avctx->codec_type = codec->type;
  410. avctx->codec_id = codec->id;
  411. }
  412. if(avctx->codec_id != codec->id || avctx->codec_type != codec->type){
  413. av_log(avctx, AV_LOG_ERROR, "codec type or id mismatches\n");
  414. goto free_and_end;
  415. }
  416. avctx->frame_number = 0;
  417. if(avctx->codec->init){
  418. ret = avctx->codec->init(avctx);
  419. if (ret < 0) {
  420. goto free_and_end;
  421. }
  422. }
  423. ret=0;
  424. end:
  425. entangled_thread_counter--;
  426. /* Release any user-supplied mutex. */
  427. if (ff_lockmgr_cb) {
  428. (*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE);
  429. }
  430. return ret;
  431. free_and_end:
  432. av_freep(&avctx->priv_data);
  433. avctx->codec= NULL;
  434. goto end;
  435. }
  436. int attribute_align_arg avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size,
  437. const short *samples)
  438. {
  439. if(buf_size < FF_MIN_BUFFER_SIZE && 0){
  440. av_log(avctx, AV_LOG_ERROR, "buffer smaller than minimum size\n");
  441. return -1;
  442. }
  443. if((avctx->codec->capabilities & CODEC_CAP_DELAY) || samples){
  444. int ret = avctx->codec->encode(avctx, buf, buf_size, samples);
  445. avctx->frame_number++;
  446. return ret;
  447. }else
  448. return 0;
  449. }
  450. int attribute_align_arg avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size,
  451. const AVFrame *pict)
  452. {
  453. if(buf_size < FF_MIN_BUFFER_SIZE){
  454. av_log(avctx, AV_LOG_ERROR, "buffer smaller than minimum size\n");
  455. return -1;
  456. }
  457. if(avcodec_check_dimensions(avctx,avctx->width,avctx->height))
  458. return -1;
  459. if((avctx->codec->capabilities & CODEC_CAP_DELAY) || pict){
  460. int ret = avctx->codec->encode(avctx, buf, buf_size, pict);
  461. avctx->frame_number++;
  462. emms_c(); //needed to avoid an emms_c() call before every return;
  463. return ret;
  464. }else
  465. return 0;
  466. }
  467. int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size,
  468. const AVSubtitle *sub)
  469. {
  470. int ret;
  471. if(sub->start_display_time) {
  472. av_log(avctx, AV_LOG_ERROR, "start_display_time must be 0.\n");
  473. return -1;
  474. }
  475. if(sub->num_rects == 0 || !sub->rects)
  476. return -1;
  477. ret = avctx->codec->encode(avctx, buf, buf_size, sub);
  478. avctx->frame_number++;
  479. return ret;
  480. }
  481. #if LIBAVCODEC_VERSION_MAJOR < 53
  482. int attribute_align_arg avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture,
  483. int *got_picture_ptr,
  484. const uint8_t *buf, int buf_size)
  485. {
  486. AVPacket avpkt;
  487. av_init_packet(&avpkt);
  488. avpkt.data = buf;
  489. avpkt.size = buf_size;
  490. // HACK for CorePNG to decode as normal PNG by default
  491. avpkt.flags = AV_PKT_FLAG_KEY;
  492. return avcodec_decode_video2(avctx, picture, got_picture_ptr, &avpkt);
  493. }
  494. #endif
  495. int attribute_align_arg avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture,
  496. int *got_picture_ptr,
  497. AVPacket *avpkt)
  498. {
  499. int ret;
  500. *got_picture_ptr= 0;
  501. if((avctx->coded_width||avctx->coded_height) && avcodec_check_dimensions(avctx,avctx->coded_width,avctx->coded_height))
  502. return -1;
  503. if((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size){
  504. ret = avctx->codec->decode(avctx, picture, got_picture_ptr,
  505. avpkt);
  506. emms_c(); //needed to avoid an emms_c() call before every return;
  507. if (*got_picture_ptr)
  508. avctx->frame_number++;
  509. }else
  510. ret= 0;
  511. return ret;
  512. }
  513. #if LIBAVCODEC_VERSION_MAJOR < 53
  514. int attribute_align_arg avcodec_decode_audio2(AVCodecContext *avctx, int16_t *samples,
  515. int *frame_size_ptr,
  516. const uint8_t *buf, int buf_size)
  517. {
  518. AVPacket avpkt;
  519. av_init_packet(&avpkt);
  520. avpkt.data = buf;
  521. avpkt.size = buf_size;
  522. return avcodec_decode_audio3(avctx, samples, frame_size_ptr, &avpkt);
  523. }
  524. #endif
  525. int attribute_align_arg avcodec_decode_audio3(AVCodecContext *avctx, int16_t *samples,
  526. int *frame_size_ptr,
  527. AVPacket *avpkt)
  528. {
  529. int ret;
  530. if((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size){
  531. //FIXME remove the check below _after_ ensuring that all audio check that the available space is enough
  532. if(*frame_size_ptr < AVCODEC_MAX_AUDIO_FRAME_SIZE){
  533. av_log(avctx, AV_LOG_ERROR, "buffer smaller than AVCODEC_MAX_AUDIO_FRAME_SIZE\n");
  534. return -1;
  535. }
  536. if(*frame_size_ptr < FF_MIN_BUFFER_SIZE ||
  537. *frame_size_ptr < avctx->channels * avctx->frame_size * sizeof(int16_t)){
  538. av_log(avctx, AV_LOG_ERROR, "buffer %d too small\n", *frame_size_ptr);
  539. return -1;
  540. }
  541. ret = avctx->codec->decode(avctx, samples, frame_size_ptr, avpkt);
  542. avctx->frame_number++;
  543. }else{
  544. ret= 0;
  545. *frame_size_ptr=0;
  546. }
  547. return ret;
  548. }
  549. #if LIBAVCODEC_VERSION_MAJOR < 53
  550. int avcodec_decode_subtitle(AVCodecContext *avctx, AVSubtitle *sub,
  551. int *got_sub_ptr,
  552. const uint8_t *buf, int buf_size)
  553. {
  554. AVPacket avpkt;
  555. av_init_packet(&avpkt);
  556. avpkt.data = buf;
  557. avpkt.size = buf_size;
  558. return avcodec_decode_subtitle2(avctx, sub, got_sub_ptr, &avpkt);
  559. }
  560. #endif
  561. int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub,
  562. int *got_sub_ptr,
  563. AVPacket *avpkt)
  564. {
  565. int ret;
  566. *got_sub_ptr = 0;
  567. ret = avctx->codec->decode(avctx, sub, got_sub_ptr, avpkt);
  568. if (*got_sub_ptr)
  569. avctx->frame_number++;
  570. return ret;
  571. }
  572. av_cold int avcodec_close(AVCodecContext *avctx)
  573. {
  574. /* If there is a user-supplied mutex locking routine, call it. */
  575. if (ff_lockmgr_cb) {
  576. if ((*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_OBTAIN))
  577. return -1;
  578. }
  579. entangled_thread_counter++;
  580. if(entangled_thread_counter != 1){
  581. av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n");
  582. entangled_thread_counter--;
  583. return -1;
  584. }
  585. if (HAVE_THREADS && avctx->thread_opaque)
  586. avcodec_thread_free(avctx);
  587. if (avctx->codec && avctx->codec->close)
  588. avctx->codec->close(avctx);
  589. avcodec_default_free_buffers(avctx);
  590. av_freep(&avctx->priv_data);
  591. if(avctx->codec->encode)
  592. av_freep(&avctx->extradata);
  593. avctx->codec = NULL;
  594. entangled_thread_counter--;
  595. /* Release any user-supplied mutex. */
  596. if (ff_lockmgr_cb) {
  597. (*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE);
  598. }
  599. return 0;
  600. }
  601. AVCodec *avcodec_find_encoder(enum CodecID id)
  602. {
  603. AVCodec *p;
  604. p = first_avcodec;
  605. while (p) {
  606. if (p->encode != NULL && p->id == id)
  607. return p;
  608. p = p->next;
  609. }
  610. return NULL;
  611. }
  612. AVCodec *avcodec_find_encoder_by_name(const char *name)
  613. {
  614. AVCodec *p;
  615. if (!name)
  616. return NULL;
  617. p = first_avcodec;
  618. while (p) {
  619. if (p->encode != NULL && strcmp(name,p->name) == 0)
  620. return p;
  621. p = p->next;
  622. }
  623. return NULL;
  624. }
  625. AVCodec *avcodec_find_decoder(enum CodecID id)
  626. {
  627. AVCodec *p;
  628. p = first_avcodec;
  629. while (p) {
  630. if (p->decode != NULL && p->id == id)
  631. return p;
  632. p = p->next;
  633. }
  634. return NULL;
  635. }
  636. AVCodec *avcodec_find_decoder_by_name(const char *name)
  637. {
  638. AVCodec *p;
  639. if (!name)
  640. return NULL;
  641. p = first_avcodec;
  642. while (p) {
  643. if (p->decode != NULL && strcmp(name,p->name) == 0)
  644. return p;
  645. p = p->next;
  646. }
  647. return NULL;
  648. }
  649. int av_get_bit_rate(AVCodecContext *ctx)
  650. {
  651. int bit_rate;
  652. int bits_per_sample;
  653. switch(ctx->codec_type) {
  654. case CODEC_TYPE_VIDEO:
  655. bit_rate = ctx->bit_rate;
  656. break;
  657. case CODEC_TYPE_AUDIO:
  658. bits_per_sample = av_get_bits_per_sample(ctx->codec_id);
  659. bit_rate = bits_per_sample ? ctx->sample_rate * ctx->channels * bits_per_sample : ctx->bit_rate;
  660. break;
  661. case CODEC_TYPE_DATA:
  662. bit_rate = ctx->bit_rate;
  663. break;
  664. case CODEC_TYPE_SUBTITLE:
  665. bit_rate = ctx->bit_rate;
  666. break;
  667. case CODEC_TYPE_ATTACHMENT:
  668. bit_rate = ctx->bit_rate;
  669. break;
  670. default:
  671. bit_rate = 0;
  672. break;
  673. }
  674. return bit_rate;
  675. }
  676. void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
  677. {
  678. const char *codec_name;
  679. AVCodec *p;
  680. char buf1[32];
  681. int bitrate;
  682. AVRational display_aspect_ratio;
  683. if (encode)
  684. p = avcodec_find_encoder(enc->codec_id);
  685. else
  686. p = avcodec_find_decoder(enc->codec_id);
  687. if (p) {
  688. codec_name = p->name;
  689. } else if (enc->codec_id == CODEC_ID_MPEG2TS) {
  690. /* fake mpeg2 transport stream codec (currently not
  691. registered) */
  692. codec_name = "mpeg2ts";
  693. } else if (enc->codec_name[0] != '\0') {
  694. codec_name = enc->codec_name;
  695. } else {
  696. /* output avi tags */
  697. if( isprint(enc->codec_tag&0xFF) && isprint((enc->codec_tag>>8)&0xFF)
  698. && isprint((enc->codec_tag>>16)&0xFF) && isprint((enc->codec_tag>>24)&0xFF)){
  699. snprintf(buf1, sizeof(buf1), "%c%c%c%c / 0x%04X",
  700. enc->codec_tag & 0xff,
  701. (enc->codec_tag >> 8) & 0xff,
  702. (enc->codec_tag >> 16) & 0xff,
  703. (enc->codec_tag >> 24) & 0xff,
  704. enc->codec_tag);
  705. } else {
  706. snprintf(buf1, sizeof(buf1), "0x%04x", enc->codec_tag);
  707. }
  708. codec_name = buf1;
  709. }
  710. switch(enc->codec_type) {
  711. case CODEC_TYPE_VIDEO:
  712. snprintf(buf, buf_size,
  713. "Video: %s%s",
  714. codec_name, enc->mb_decision ? " (hq)" : "");
  715. if (enc->pix_fmt != PIX_FMT_NONE) {
  716. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  717. ", %s",
  718. avcodec_get_pix_fmt_name(enc->pix_fmt));
  719. }
  720. if (enc->width) {
  721. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  722. ", %dx%d",
  723. enc->width, enc->height);
  724. if (enc->sample_aspect_ratio.num) {
  725. av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,
  726. enc->width*enc->sample_aspect_ratio.num,
  727. enc->height*enc->sample_aspect_ratio.den,
  728. 1024*1024);
  729. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  730. " [PAR %d:%d DAR %d:%d]",
  731. enc->sample_aspect_ratio.num, enc->sample_aspect_ratio.den,
  732. display_aspect_ratio.num, display_aspect_ratio.den);
  733. }
  734. if(av_log_get_level() >= AV_LOG_DEBUG){
  735. int g= av_gcd(enc->time_base.num, enc->time_base.den);
  736. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  737. ", %d/%d",
  738. enc->time_base.num/g, enc->time_base.den/g);
  739. }
  740. }
  741. if (encode) {
  742. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  743. ", q=%d-%d", enc->qmin, enc->qmax);
  744. }
  745. break;
  746. case CODEC_TYPE_AUDIO:
  747. snprintf(buf, buf_size,
  748. "Audio: %s",
  749. codec_name);
  750. if (enc->sample_rate) {
  751. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  752. ", %d Hz", enc->sample_rate);
  753. }
  754. av_strlcat(buf, ", ", buf_size);
  755. avcodec_get_channel_layout_string(buf + strlen(buf), buf_size - strlen(buf), enc->channels, enc->channel_layout);
  756. if (enc->sample_fmt != SAMPLE_FMT_NONE) {
  757. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  758. ", %s", avcodec_get_sample_fmt_name(enc->sample_fmt));
  759. }
  760. break;
  761. case CODEC_TYPE_DATA:
  762. snprintf(buf, buf_size, "Data: %s", codec_name);
  763. break;
  764. case CODEC_TYPE_SUBTITLE:
  765. snprintf(buf, buf_size, "Subtitle: %s", codec_name);
  766. break;
  767. case CODEC_TYPE_ATTACHMENT:
  768. snprintf(buf, buf_size, "Attachment: %s", codec_name);
  769. break;
  770. default:
  771. snprintf(buf, buf_size, "Invalid Codec type %d", enc->codec_type);
  772. return;
  773. }
  774. if (encode) {
  775. if (enc->flags & CODEC_FLAG_PASS1)
  776. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  777. ", pass 1");
  778. if (enc->flags & CODEC_FLAG_PASS2)
  779. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  780. ", pass 2");
  781. }
  782. bitrate = av_get_bit_rate(enc);
  783. if (bitrate != 0) {
  784. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  785. ", %d kb/s", bitrate / 1000);
  786. }
  787. }
  788. unsigned avcodec_version( void )
  789. {
  790. return LIBAVCODEC_VERSION_INT;
  791. }
  792. const char *avcodec_configuration(void)
  793. {
  794. return FFMPEG_CONFIGURATION;
  795. }
  796. const char *avcodec_license(void)
  797. {
  798. #define LICENSE_PREFIX "libavcodec license: "
  799. return LICENSE_PREFIX FFMPEG_LICENSE + sizeof(LICENSE_PREFIX) - 1;
  800. }
  801. void avcodec_init(void)
  802. {
  803. static int initialized = 0;
  804. if (initialized != 0)
  805. return;
  806. initialized = 1;
  807. dsputil_static_init();
  808. }
  809. void avcodec_flush_buffers(AVCodecContext *avctx)
  810. {
  811. if(avctx->codec->flush)
  812. avctx->codec->flush(avctx);
  813. }
  814. void avcodec_default_free_buffers(AVCodecContext *s){
  815. int i, j;
  816. if(s->internal_buffer==NULL) return;
  817. if (s->internal_buffer_count)
  818. av_log(s, AV_LOG_WARNING, "Found %i unreleased buffers!\n", s->internal_buffer_count);
  819. for(i=0; i<INTERNAL_BUFFER_SIZE; i++){
  820. InternalBuffer *buf= &((InternalBuffer*)s->internal_buffer)[i];
  821. for(j=0; j<4; j++){
  822. av_freep(&buf->base[j]);
  823. buf->data[j]= NULL;
  824. }
  825. }
  826. av_freep(&s->internal_buffer);
  827. s->internal_buffer_count=0;
  828. }
  829. char av_get_pict_type_char(int pict_type){
  830. switch(pict_type){
  831. case FF_I_TYPE: return 'I';
  832. case FF_P_TYPE: return 'P';
  833. case FF_B_TYPE: return 'B';
  834. case FF_S_TYPE: return 'S';
  835. case FF_SI_TYPE:return 'i';
  836. case FF_SP_TYPE:return 'p';
  837. case FF_BI_TYPE:return 'b';
  838. default: return '?';
  839. }
  840. }
  841. int av_get_bits_per_sample(enum CodecID codec_id){
  842. switch(codec_id){
  843. case CODEC_ID_ADPCM_SBPRO_2:
  844. return 2;
  845. case CODEC_ID_ADPCM_SBPRO_3:
  846. return 3;
  847. case CODEC_ID_ADPCM_SBPRO_4:
  848. case CODEC_ID_ADPCM_CT:
  849. case CODEC_ID_ADPCM_IMA_WAV:
  850. case CODEC_ID_ADPCM_MS:
  851. case CODEC_ID_ADPCM_YAMAHA:
  852. return 4;
  853. case CODEC_ID_PCM_ALAW:
  854. case CODEC_ID_PCM_MULAW:
  855. case CODEC_ID_PCM_S8:
  856. case CODEC_ID_PCM_U8:
  857. case CODEC_ID_PCM_ZORK:
  858. return 8;
  859. case CODEC_ID_PCM_S16BE:
  860. case CODEC_ID_PCM_S16LE:
  861. case CODEC_ID_PCM_S16LE_PLANAR:
  862. case CODEC_ID_PCM_U16BE:
  863. case CODEC_ID_PCM_U16LE:
  864. return 16;
  865. case CODEC_ID_PCM_S24DAUD:
  866. case CODEC_ID_PCM_S24BE:
  867. case CODEC_ID_PCM_S24LE:
  868. case CODEC_ID_PCM_U24BE:
  869. case CODEC_ID_PCM_U24LE:
  870. return 24;
  871. case CODEC_ID_PCM_S32BE:
  872. case CODEC_ID_PCM_S32LE:
  873. case CODEC_ID_PCM_U32BE:
  874. case CODEC_ID_PCM_U32LE:
  875. case CODEC_ID_PCM_F32BE:
  876. case CODEC_ID_PCM_F32LE:
  877. return 32;
  878. case CODEC_ID_PCM_F64BE:
  879. case CODEC_ID_PCM_F64LE:
  880. return 64;
  881. default:
  882. return 0;
  883. }
  884. }
  885. int av_get_bits_per_sample_format(enum SampleFormat sample_fmt) {
  886. switch (sample_fmt) {
  887. case SAMPLE_FMT_U8:
  888. return 8;
  889. case SAMPLE_FMT_S16:
  890. return 16;
  891. case SAMPLE_FMT_S32:
  892. case SAMPLE_FMT_FLT:
  893. return 32;
  894. case SAMPLE_FMT_DBL:
  895. return 64;
  896. default:
  897. return 0;
  898. }
  899. }
  900. #if !HAVE_THREADS
  901. int avcodec_thread_init(AVCodecContext *s, int thread_count){
  902. s->thread_count = thread_count;
  903. return -1;
  904. }
  905. #endif
  906. unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
  907. {
  908. unsigned int n = 0;
  909. while(v >= 0xff) {
  910. *s++ = 0xff;
  911. v -= 0xff;
  912. n++;
  913. }
  914. *s = v;
  915. n++;
  916. return n;
  917. }
  918. /* Wrapper to work around the lack of mkstemp() on mingw/cygin.
  919. * Also, tries to create file in /tmp first, if possible.
  920. * *prefix can be a character constant; *filename will be allocated internally.
  921. * Returns file descriptor of opened file (or -1 on error)
  922. * and opened file name in **filename. */
  923. int av_tempfile(char *prefix, char **filename) {
  924. int fd=-1;
  925. #if !HAVE_MKSTEMP
  926. *filename = tempnam(".", prefix);
  927. #else
  928. size_t len = strlen(prefix) + 12; /* room for "/tmp/" and "XXXXXX\0" */
  929. *filename = av_malloc(len);
  930. #endif
  931. /* -----common section-----*/
  932. if (*filename == NULL) {
  933. av_log(NULL, AV_LOG_ERROR, "ff_tempfile: Cannot allocate file name\n");
  934. return -1;
  935. }
  936. #if !HAVE_MKSTEMP
  937. fd = open(*filename, O_RDWR | O_BINARY | O_CREAT, 0444);
  938. #else
  939. snprintf(*filename, len, "/tmp/%sXXXXXX", prefix);
  940. fd = mkstemp(*filename);
  941. if (fd < 0) {
  942. snprintf(*filename, len, "./%sXXXXXX", prefix);
  943. fd = mkstemp(*filename);
  944. }
  945. #endif
  946. /* -----common section-----*/
  947. if (fd < 0) {
  948. av_log(NULL, AV_LOG_ERROR, "ff_tempfile: Cannot open temporary file %s\n", *filename);
  949. return -1;
  950. }
  951. return fd; /* success */
  952. }
  953. typedef struct {
  954. const char *abbr;
  955. int width, height;
  956. } VideoFrameSizeAbbr;
  957. typedef struct {
  958. const char *abbr;
  959. int rate_num, rate_den;
  960. } VideoFrameRateAbbr;
  961. static const VideoFrameSizeAbbr video_frame_size_abbrs[] = {
  962. { "ntsc", 720, 480 },
  963. { "pal", 720, 576 },
  964. { "qntsc", 352, 240 }, /* VCD compliant NTSC */
  965. { "qpal", 352, 288 }, /* VCD compliant PAL */
  966. { "sntsc", 640, 480 }, /* square pixel NTSC */
  967. { "spal", 768, 576 }, /* square pixel PAL */
  968. { "film", 352, 240 },
  969. { "ntsc-film", 352, 240 },
  970. { "sqcif", 128, 96 },
  971. { "qcif", 176, 144 },
  972. { "cif", 352, 288 },
  973. { "4cif", 704, 576 },
  974. { "16cif", 1408,1152 },
  975. { "qqvga", 160, 120 },
  976. { "qvga", 320, 240 },
  977. { "vga", 640, 480 },
  978. { "svga", 800, 600 },
  979. { "xga", 1024, 768 },
  980. { "uxga", 1600,1200 },
  981. { "qxga", 2048,1536 },
  982. { "sxga", 1280,1024 },
  983. { "qsxga", 2560,2048 },
  984. { "hsxga", 5120,4096 },
  985. { "wvga", 852, 480 },
  986. { "wxga", 1366, 768 },
  987. { "wsxga", 1600,1024 },
  988. { "wuxga", 1920,1200 },
  989. { "woxga", 2560,1600 },
  990. { "wqsxga", 3200,2048 },
  991. { "wquxga", 3840,2400 },
  992. { "whsxga", 6400,4096 },
  993. { "whuxga", 7680,4800 },
  994. { "cga", 320, 200 },
  995. { "ega", 640, 350 },
  996. { "hd480", 852, 480 },
  997. { "hd720", 1280, 720 },
  998. { "hd1080", 1920,1080 },
  999. };
  1000. static const VideoFrameRateAbbr video_frame_rate_abbrs[]= {
  1001. { "ntsc", 30000, 1001 },
  1002. { "pal", 25, 1 },
  1003. { "qntsc", 30000, 1001 }, /* VCD compliant NTSC */
  1004. { "qpal", 25, 1 }, /* VCD compliant PAL */
  1005. { "sntsc", 30000, 1001 }, /* square pixel NTSC */
  1006. { "spal", 25, 1 }, /* square pixel PAL */
  1007. { "film", 24, 1 },
  1008. { "ntsc-film", 24000, 1001 },
  1009. };
  1010. int av_parse_video_frame_size(int *width_ptr, int *height_ptr, const char *str)
  1011. {
  1012. int i;
  1013. int n = FF_ARRAY_ELEMS(video_frame_size_abbrs);
  1014. char *p;
  1015. int frame_width = 0, frame_height = 0;
  1016. for(i=0;i<n;i++) {
  1017. if (!strcmp(video_frame_size_abbrs[i].abbr, str)) {
  1018. frame_width = video_frame_size_abbrs[i].width;
  1019. frame_height = video_frame_size_abbrs[i].height;
  1020. break;
  1021. }
  1022. }
  1023. if (i == n) {
  1024. p = str;
  1025. frame_width = strtol(p, &p, 10);
  1026. if (*p)
  1027. p++;
  1028. frame_height = strtol(p, &p, 10);
  1029. }
  1030. if (frame_width <= 0 || frame_height <= 0)
  1031. return -1;
  1032. *width_ptr = frame_width;
  1033. *height_ptr = frame_height;
  1034. return 0;
  1035. }
  1036. int av_parse_video_frame_rate(AVRational *frame_rate, const char *arg)
  1037. {
  1038. int i;
  1039. int n = FF_ARRAY_ELEMS(video_frame_rate_abbrs);
  1040. char* cp;
  1041. /* First, we check our abbreviation table */
  1042. for (i = 0; i < n; ++i)
  1043. if (!strcmp(video_frame_rate_abbrs[i].abbr, arg)) {
  1044. frame_rate->num = video_frame_rate_abbrs[i].rate_num;
  1045. frame_rate->den = video_frame_rate_abbrs[i].rate_den;
  1046. return 0;
  1047. }
  1048. /* Then, we try to parse it as fraction */
  1049. cp = strchr(arg, '/');
  1050. if (!cp)
  1051. cp = strchr(arg, ':');
  1052. if (cp) {
  1053. char* cpp;
  1054. frame_rate->num = strtol(arg, &cpp, 10);
  1055. if (cpp != arg || cpp == cp)
  1056. frame_rate->den = strtol(cp+1, &cpp, 10);
  1057. else
  1058. frame_rate->num = 0;
  1059. }
  1060. else {
  1061. /* Finally we give up and parse it as double */
  1062. AVRational time_base = av_d2q(strtod(arg, 0), 1001000);
  1063. frame_rate->den = time_base.den;
  1064. frame_rate->num = time_base.num;
  1065. }
  1066. if (!frame_rate->num || !frame_rate->den)
  1067. return -1;
  1068. else
  1069. return 0;
  1070. }
  1071. int ff_match_2uint16(const uint16_t (*tab)[2], int size, int a, int b){
  1072. int i;
  1073. for(i=0; i<size && !(tab[i][0]==a && tab[i][1]==b); i++);
  1074. return i;
  1075. }
  1076. void av_log_missing_feature(void *avc, const char *feature, int want_sample)
  1077. {
  1078. av_log(avc, AV_LOG_WARNING, "%s not implemented. Update your FFmpeg "
  1079. "version to the newest one from SVN. If the problem still "
  1080. "occurs, it means that your file has a feature which has not "
  1081. "been implemented.", feature);
  1082. if(want_sample)
  1083. av_log_ask_for_sample(avc, NULL);
  1084. else
  1085. av_log(avc, AV_LOG_WARNING, "\n");
  1086. }
  1087. void av_log_ask_for_sample(void *avc, const char *msg)
  1088. {
  1089. if (msg)
  1090. av_log(avc, AV_LOG_WARNING, "%s ", msg);
  1091. av_log(avc, AV_LOG_WARNING, "If you want to help, upload a sample "
  1092. "of this file to ftp://upload.ffmpeg.org/MPlayer/incoming/ "
  1093. "and contact the ffmpeg-devel mailing list.\n");
  1094. }
  1095. static AVHWAccel *first_hwaccel = NULL;
  1096. void av_register_hwaccel(AVHWAccel *hwaccel)
  1097. {
  1098. AVHWAccel **p = &first_hwaccel;
  1099. while (*p)
  1100. p = &(*p)->next;
  1101. *p = hwaccel;
  1102. hwaccel->next = NULL;
  1103. }
  1104. AVHWAccel *av_hwaccel_next(AVHWAccel *hwaccel)
  1105. {
  1106. return hwaccel ? hwaccel->next : first_hwaccel;
  1107. }
  1108. AVHWAccel *ff_find_hwaccel(enum CodecID codec_id, enum PixelFormat pix_fmt)
  1109. {
  1110. AVHWAccel *hwaccel=NULL;
  1111. while((hwaccel= av_hwaccel_next(hwaccel))){
  1112. if ( hwaccel->id == codec_id
  1113. && hwaccel->pix_fmt == pix_fmt)
  1114. return hwaccel;
  1115. }
  1116. return NULL;
  1117. }
  1118. int av_lockmgr_register(int (*cb)(void **mutex, enum AVLockOp op))
  1119. {
  1120. if (ff_lockmgr_cb) {
  1121. if (ff_lockmgr_cb(&codec_mutex, AV_LOCK_DESTROY))
  1122. return -1;
  1123. }
  1124. ff_lockmgr_cb = cb;
  1125. if (ff_lockmgr_cb) {
  1126. if (ff_lockmgr_cb(&codec_mutex, AV_LOCK_CREATE))
  1127. return -1;
  1128. }
  1129. return 0;
  1130. }