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.

1275 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. avctx->codec = NULL;
  592. entangled_thread_counter--;
  593. /* Release any user-supplied mutex. */
  594. if (ff_lockmgr_cb) {
  595. (*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE);
  596. }
  597. return 0;
  598. }
  599. AVCodec *avcodec_find_encoder(enum CodecID id)
  600. {
  601. AVCodec *p;
  602. p = first_avcodec;
  603. while (p) {
  604. if (p->encode != NULL && p->id == id)
  605. return p;
  606. p = p->next;
  607. }
  608. return NULL;
  609. }
  610. AVCodec *avcodec_find_encoder_by_name(const char *name)
  611. {
  612. AVCodec *p;
  613. if (!name)
  614. return NULL;
  615. p = first_avcodec;
  616. while (p) {
  617. if (p->encode != NULL && strcmp(name,p->name) == 0)
  618. return p;
  619. p = p->next;
  620. }
  621. return NULL;
  622. }
  623. AVCodec *avcodec_find_decoder(enum CodecID id)
  624. {
  625. AVCodec *p;
  626. p = first_avcodec;
  627. while (p) {
  628. if (p->decode != NULL && p->id == id)
  629. return p;
  630. p = p->next;
  631. }
  632. return NULL;
  633. }
  634. AVCodec *avcodec_find_decoder_by_name(const char *name)
  635. {
  636. AVCodec *p;
  637. if (!name)
  638. return NULL;
  639. p = first_avcodec;
  640. while (p) {
  641. if (p->decode != NULL && strcmp(name,p->name) == 0)
  642. return p;
  643. p = p->next;
  644. }
  645. return NULL;
  646. }
  647. int av_get_bit_rate(AVCodecContext *ctx)
  648. {
  649. int bit_rate;
  650. int bits_per_sample;
  651. switch(ctx->codec_type) {
  652. case CODEC_TYPE_VIDEO:
  653. bit_rate = ctx->bit_rate;
  654. break;
  655. case CODEC_TYPE_AUDIO:
  656. bits_per_sample = av_get_bits_per_sample(ctx->codec_id);
  657. bit_rate = bits_per_sample ? ctx->sample_rate * ctx->channels * bits_per_sample : ctx->bit_rate;
  658. break;
  659. case CODEC_TYPE_DATA:
  660. bit_rate = ctx->bit_rate;
  661. break;
  662. case CODEC_TYPE_SUBTITLE:
  663. bit_rate = ctx->bit_rate;
  664. break;
  665. case CODEC_TYPE_ATTACHMENT:
  666. bit_rate = ctx->bit_rate;
  667. break;
  668. default:
  669. bit_rate = 0;
  670. break;
  671. }
  672. return bit_rate;
  673. }
  674. void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
  675. {
  676. const char *codec_name;
  677. AVCodec *p;
  678. char buf1[32];
  679. int bitrate;
  680. AVRational display_aspect_ratio;
  681. if (encode)
  682. p = avcodec_find_encoder(enc->codec_id);
  683. else
  684. p = avcodec_find_decoder(enc->codec_id);
  685. if (p) {
  686. codec_name = p->name;
  687. } else if (enc->codec_id == CODEC_ID_MPEG2TS) {
  688. /* fake mpeg2 transport stream codec (currently not
  689. registered) */
  690. codec_name = "mpeg2ts";
  691. } else if (enc->codec_name[0] != '\0') {
  692. codec_name = enc->codec_name;
  693. } else {
  694. /* output avi tags */
  695. if( isprint(enc->codec_tag&0xFF) && isprint((enc->codec_tag>>8)&0xFF)
  696. && isprint((enc->codec_tag>>16)&0xFF) && isprint((enc->codec_tag>>24)&0xFF)){
  697. snprintf(buf1, sizeof(buf1), "%c%c%c%c / 0x%04X",
  698. enc->codec_tag & 0xff,
  699. (enc->codec_tag >> 8) & 0xff,
  700. (enc->codec_tag >> 16) & 0xff,
  701. (enc->codec_tag >> 24) & 0xff,
  702. enc->codec_tag);
  703. } else {
  704. snprintf(buf1, sizeof(buf1), "0x%04x", enc->codec_tag);
  705. }
  706. codec_name = buf1;
  707. }
  708. switch(enc->codec_type) {
  709. case CODEC_TYPE_VIDEO:
  710. snprintf(buf, buf_size,
  711. "Video: %s%s",
  712. codec_name, enc->mb_decision ? " (hq)" : "");
  713. if (enc->pix_fmt != PIX_FMT_NONE) {
  714. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  715. ", %s",
  716. avcodec_get_pix_fmt_name(enc->pix_fmt));
  717. }
  718. if (enc->width) {
  719. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  720. ", %dx%d",
  721. enc->width, enc->height);
  722. if (enc->sample_aspect_ratio.num) {
  723. av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,
  724. enc->width*enc->sample_aspect_ratio.num,
  725. enc->height*enc->sample_aspect_ratio.den,
  726. 1024*1024);
  727. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  728. " [PAR %d:%d DAR %d:%d]",
  729. enc->sample_aspect_ratio.num, enc->sample_aspect_ratio.den,
  730. display_aspect_ratio.num, display_aspect_ratio.den);
  731. }
  732. if(av_log_get_level() >= AV_LOG_DEBUG){
  733. int g= av_gcd(enc->time_base.num, enc->time_base.den);
  734. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  735. ", %d/%d",
  736. enc->time_base.num/g, enc->time_base.den/g);
  737. }
  738. }
  739. if (encode) {
  740. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  741. ", q=%d-%d", enc->qmin, enc->qmax);
  742. }
  743. break;
  744. case CODEC_TYPE_AUDIO:
  745. snprintf(buf, buf_size,
  746. "Audio: %s",
  747. codec_name);
  748. if (enc->sample_rate) {
  749. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  750. ", %d Hz", enc->sample_rate);
  751. }
  752. av_strlcat(buf, ", ", buf_size);
  753. avcodec_get_channel_layout_string(buf + strlen(buf), buf_size - strlen(buf), enc->channels, enc->channel_layout);
  754. if (enc->sample_fmt != SAMPLE_FMT_NONE) {
  755. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  756. ", %s", avcodec_get_sample_fmt_name(enc->sample_fmt));
  757. }
  758. break;
  759. case CODEC_TYPE_DATA:
  760. snprintf(buf, buf_size, "Data: %s", codec_name);
  761. break;
  762. case CODEC_TYPE_SUBTITLE:
  763. snprintf(buf, buf_size, "Subtitle: %s", codec_name);
  764. break;
  765. case CODEC_TYPE_ATTACHMENT:
  766. snprintf(buf, buf_size, "Attachment: %s", codec_name);
  767. break;
  768. default:
  769. snprintf(buf, buf_size, "Invalid Codec type %d", enc->codec_type);
  770. return;
  771. }
  772. if (encode) {
  773. if (enc->flags & CODEC_FLAG_PASS1)
  774. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  775. ", pass 1");
  776. if (enc->flags & CODEC_FLAG_PASS2)
  777. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  778. ", pass 2");
  779. }
  780. bitrate = av_get_bit_rate(enc);
  781. if (bitrate != 0) {
  782. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  783. ", %d kb/s", bitrate / 1000);
  784. }
  785. }
  786. unsigned avcodec_version( void )
  787. {
  788. return LIBAVCODEC_VERSION_INT;
  789. }
  790. const char *avcodec_configuration(void)
  791. {
  792. return FFMPEG_CONFIGURATION;
  793. }
  794. const char *avcodec_license(void)
  795. {
  796. #define LICENSE_PREFIX "libavcodec license: "
  797. return LICENSE_PREFIX FFMPEG_LICENSE + sizeof(LICENSE_PREFIX) - 1;
  798. }
  799. void avcodec_init(void)
  800. {
  801. static int initialized = 0;
  802. if (initialized != 0)
  803. return;
  804. initialized = 1;
  805. dsputil_static_init();
  806. }
  807. void avcodec_flush_buffers(AVCodecContext *avctx)
  808. {
  809. if(avctx->codec->flush)
  810. avctx->codec->flush(avctx);
  811. }
  812. void avcodec_default_free_buffers(AVCodecContext *s){
  813. int i, j;
  814. if(s->internal_buffer==NULL) return;
  815. if (s->internal_buffer_count)
  816. av_log(s, AV_LOG_WARNING, "Found %i unreleased buffers!\n", s->internal_buffer_count);
  817. for(i=0; i<INTERNAL_BUFFER_SIZE; i++){
  818. InternalBuffer *buf= &((InternalBuffer*)s->internal_buffer)[i];
  819. for(j=0; j<4; j++){
  820. av_freep(&buf->base[j]);
  821. buf->data[j]= NULL;
  822. }
  823. }
  824. av_freep(&s->internal_buffer);
  825. s->internal_buffer_count=0;
  826. }
  827. char av_get_pict_type_char(int pict_type){
  828. switch(pict_type){
  829. case FF_I_TYPE: return 'I';
  830. case FF_P_TYPE: return 'P';
  831. case FF_B_TYPE: return 'B';
  832. case FF_S_TYPE: return 'S';
  833. case FF_SI_TYPE:return 'i';
  834. case FF_SP_TYPE:return 'p';
  835. case FF_BI_TYPE:return 'b';
  836. default: return '?';
  837. }
  838. }
  839. int av_get_bits_per_sample(enum CodecID codec_id){
  840. switch(codec_id){
  841. case CODEC_ID_ADPCM_SBPRO_2:
  842. return 2;
  843. case CODEC_ID_ADPCM_SBPRO_3:
  844. return 3;
  845. case CODEC_ID_ADPCM_SBPRO_4:
  846. case CODEC_ID_ADPCM_CT:
  847. case CODEC_ID_ADPCM_IMA_WAV:
  848. case CODEC_ID_ADPCM_MS:
  849. case CODEC_ID_ADPCM_YAMAHA:
  850. return 4;
  851. case CODEC_ID_PCM_ALAW:
  852. case CODEC_ID_PCM_MULAW:
  853. case CODEC_ID_PCM_S8:
  854. case CODEC_ID_PCM_U8:
  855. case CODEC_ID_PCM_ZORK:
  856. return 8;
  857. case CODEC_ID_PCM_S16BE:
  858. case CODEC_ID_PCM_S16LE:
  859. case CODEC_ID_PCM_S16LE_PLANAR:
  860. case CODEC_ID_PCM_U16BE:
  861. case CODEC_ID_PCM_U16LE:
  862. return 16;
  863. case CODEC_ID_PCM_S24DAUD:
  864. case CODEC_ID_PCM_S24BE:
  865. case CODEC_ID_PCM_S24LE:
  866. case CODEC_ID_PCM_U24BE:
  867. case CODEC_ID_PCM_U24LE:
  868. return 24;
  869. case CODEC_ID_PCM_S32BE:
  870. case CODEC_ID_PCM_S32LE:
  871. case CODEC_ID_PCM_U32BE:
  872. case CODEC_ID_PCM_U32LE:
  873. case CODEC_ID_PCM_F32BE:
  874. case CODEC_ID_PCM_F32LE:
  875. return 32;
  876. case CODEC_ID_PCM_F64BE:
  877. case CODEC_ID_PCM_F64LE:
  878. return 64;
  879. default:
  880. return 0;
  881. }
  882. }
  883. int av_get_bits_per_sample_format(enum SampleFormat sample_fmt) {
  884. switch (sample_fmt) {
  885. case SAMPLE_FMT_U8:
  886. return 8;
  887. case SAMPLE_FMT_S16:
  888. return 16;
  889. case SAMPLE_FMT_S32:
  890. case SAMPLE_FMT_FLT:
  891. return 32;
  892. case SAMPLE_FMT_DBL:
  893. return 64;
  894. default:
  895. return 0;
  896. }
  897. }
  898. #if !HAVE_THREADS
  899. int avcodec_thread_init(AVCodecContext *s, int thread_count){
  900. s->thread_count = thread_count;
  901. return -1;
  902. }
  903. #endif
  904. unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
  905. {
  906. unsigned int n = 0;
  907. while(v >= 0xff) {
  908. *s++ = 0xff;
  909. v -= 0xff;
  910. n++;
  911. }
  912. *s = v;
  913. n++;
  914. return n;
  915. }
  916. /* Wrapper to work around the lack of mkstemp() on mingw/cygin.
  917. * Also, tries to create file in /tmp first, if possible.
  918. * *prefix can be a character constant; *filename will be allocated internally.
  919. * Returns file descriptor of opened file (or -1 on error)
  920. * and opened file name in **filename. */
  921. int av_tempfile(char *prefix, char **filename) {
  922. int fd=-1;
  923. #if !HAVE_MKSTEMP
  924. *filename = tempnam(".", prefix);
  925. #else
  926. size_t len = strlen(prefix) + 12; /* room for "/tmp/" and "XXXXXX\0" */
  927. *filename = av_malloc(len);
  928. #endif
  929. /* -----common section-----*/
  930. if (*filename == NULL) {
  931. av_log(NULL, AV_LOG_ERROR, "ff_tempfile: Cannot allocate file name\n");
  932. return -1;
  933. }
  934. #if !HAVE_MKSTEMP
  935. fd = open(*filename, O_RDWR | O_BINARY | O_CREAT, 0444);
  936. #else
  937. snprintf(*filename, len, "/tmp/%sXXXXXX", prefix);
  938. fd = mkstemp(*filename);
  939. if (fd < 0) {
  940. snprintf(*filename, len, "./%sXXXXXX", prefix);
  941. fd = mkstemp(*filename);
  942. }
  943. #endif
  944. /* -----common section-----*/
  945. if (fd < 0) {
  946. av_log(NULL, AV_LOG_ERROR, "ff_tempfile: Cannot open temporary file %s\n", *filename);
  947. return -1;
  948. }
  949. return fd; /* success */
  950. }
  951. typedef struct {
  952. const char *abbr;
  953. int width, height;
  954. } VideoFrameSizeAbbr;
  955. typedef struct {
  956. const char *abbr;
  957. int rate_num, rate_den;
  958. } VideoFrameRateAbbr;
  959. static const VideoFrameSizeAbbr video_frame_size_abbrs[] = {
  960. { "ntsc", 720, 480 },
  961. { "pal", 720, 576 },
  962. { "qntsc", 352, 240 }, /* VCD compliant NTSC */
  963. { "qpal", 352, 288 }, /* VCD compliant PAL */
  964. { "sntsc", 640, 480 }, /* square pixel NTSC */
  965. { "spal", 768, 576 }, /* square pixel PAL */
  966. { "film", 352, 240 },
  967. { "ntsc-film", 352, 240 },
  968. { "sqcif", 128, 96 },
  969. { "qcif", 176, 144 },
  970. { "cif", 352, 288 },
  971. { "4cif", 704, 576 },
  972. { "16cif", 1408,1152 },
  973. { "qqvga", 160, 120 },
  974. { "qvga", 320, 240 },
  975. { "vga", 640, 480 },
  976. { "svga", 800, 600 },
  977. { "xga", 1024, 768 },
  978. { "uxga", 1600,1200 },
  979. { "qxga", 2048,1536 },
  980. { "sxga", 1280,1024 },
  981. { "qsxga", 2560,2048 },
  982. { "hsxga", 5120,4096 },
  983. { "wvga", 852, 480 },
  984. { "wxga", 1366, 768 },
  985. { "wsxga", 1600,1024 },
  986. { "wuxga", 1920,1200 },
  987. { "woxga", 2560,1600 },
  988. { "wqsxga", 3200,2048 },
  989. { "wquxga", 3840,2400 },
  990. { "whsxga", 6400,4096 },
  991. { "whuxga", 7680,4800 },
  992. { "cga", 320, 200 },
  993. { "ega", 640, 350 },
  994. { "hd480", 852, 480 },
  995. { "hd720", 1280, 720 },
  996. { "hd1080", 1920,1080 },
  997. };
  998. static const VideoFrameRateAbbr video_frame_rate_abbrs[]= {
  999. { "ntsc", 30000, 1001 },
  1000. { "pal", 25, 1 },
  1001. { "qntsc", 30000, 1001 }, /* VCD compliant NTSC */
  1002. { "qpal", 25, 1 }, /* VCD compliant PAL */
  1003. { "sntsc", 30000, 1001 }, /* square pixel NTSC */
  1004. { "spal", 25, 1 }, /* square pixel PAL */
  1005. { "film", 24, 1 },
  1006. { "ntsc-film", 24000, 1001 },
  1007. };
  1008. int av_parse_video_frame_size(int *width_ptr, int *height_ptr, const char *str)
  1009. {
  1010. int i;
  1011. int n = FF_ARRAY_ELEMS(video_frame_size_abbrs);
  1012. char *p;
  1013. int frame_width = 0, frame_height = 0;
  1014. for(i=0;i<n;i++) {
  1015. if (!strcmp(video_frame_size_abbrs[i].abbr, str)) {
  1016. frame_width = video_frame_size_abbrs[i].width;
  1017. frame_height = video_frame_size_abbrs[i].height;
  1018. break;
  1019. }
  1020. }
  1021. if (i == n) {
  1022. p = str;
  1023. frame_width = strtol(p, &p, 10);
  1024. if (*p)
  1025. p++;
  1026. frame_height = strtol(p, &p, 10);
  1027. }
  1028. if (frame_width <= 0 || frame_height <= 0)
  1029. return -1;
  1030. *width_ptr = frame_width;
  1031. *height_ptr = frame_height;
  1032. return 0;
  1033. }
  1034. int av_parse_video_frame_rate(AVRational *frame_rate, const char *arg)
  1035. {
  1036. int i;
  1037. int n = FF_ARRAY_ELEMS(video_frame_rate_abbrs);
  1038. char* cp;
  1039. /* First, we check our abbreviation table */
  1040. for (i = 0; i < n; ++i)
  1041. if (!strcmp(video_frame_rate_abbrs[i].abbr, arg)) {
  1042. frame_rate->num = video_frame_rate_abbrs[i].rate_num;
  1043. frame_rate->den = video_frame_rate_abbrs[i].rate_den;
  1044. return 0;
  1045. }
  1046. /* Then, we try to parse it as fraction */
  1047. cp = strchr(arg, '/');
  1048. if (!cp)
  1049. cp = strchr(arg, ':');
  1050. if (cp) {
  1051. char* cpp;
  1052. frame_rate->num = strtol(arg, &cpp, 10);
  1053. if (cpp != arg || cpp == cp)
  1054. frame_rate->den = strtol(cp+1, &cpp, 10);
  1055. else
  1056. frame_rate->num = 0;
  1057. }
  1058. else {
  1059. /* Finally we give up and parse it as double */
  1060. AVRational time_base = av_d2q(strtod(arg, 0), 1001000);
  1061. frame_rate->den = time_base.den;
  1062. frame_rate->num = time_base.num;
  1063. }
  1064. if (!frame_rate->num || !frame_rate->den)
  1065. return -1;
  1066. else
  1067. return 0;
  1068. }
  1069. int ff_match_2uint16(const uint16_t (*tab)[2], int size, int a, int b){
  1070. int i;
  1071. for(i=0; i<size && !(tab[i][0]==a && tab[i][1]==b); i++);
  1072. return i;
  1073. }
  1074. void av_log_missing_feature(void *avc, const char *feature, int want_sample)
  1075. {
  1076. av_log(avc, AV_LOG_WARNING, "%s not implemented. Update your FFmpeg "
  1077. "version to the newest one from SVN. If the problem still "
  1078. "occurs, it means that your file has a feature which has not "
  1079. "been implemented.", feature);
  1080. if(want_sample)
  1081. av_log_ask_for_sample(avc, NULL);
  1082. else
  1083. av_log(avc, AV_LOG_WARNING, "\n");
  1084. }
  1085. void av_log_ask_for_sample(void *avc, const char *msg)
  1086. {
  1087. if (msg)
  1088. av_log(avc, AV_LOG_WARNING, "%s ", msg);
  1089. av_log(avc, AV_LOG_WARNING, "If you want to help, upload a sample "
  1090. "of this file to ftp://upload.ffmpeg.org/MPlayer/incoming/ "
  1091. "and contact the ffmpeg-devel mailing list.\n");
  1092. }
  1093. static AVHWAccel *first_hwaccel = NULL;
  1094. void av_register_hwaccel(AVHWAccel *hwaccel)
  1095. {
  1096. AVHWAccel **p = &first_hwaccel;
  1097. while (*p)
  1098. p = &(*p)->next;
  1099. *p = hwaccel;
  1100. hwaccel->next = NULL;
  1101. }
  1102. AVHWAccel *av_hwaccel_next(AVHWAccel *hwaccel)
  1103. {
  1104. return hwaccel ? hwaccel->next : first_hwaccel;
  1105. }
  1106. AVHWAccel *ff_find_hwaccel(enum CodecID codec_id, enum PixelFormat pix_fmt)
  1107. {
  1108. AVHWAccel *hwaccel=NULL;
  1109. while((hwaccel= av_hwaccel_next(hwaccel))){
  1110. if ( hwaccel->id == codec_id
  1111. && hwaccel->pix_fmt == pix_fmt)
  1112. return hwaccel;
  1113. }
  1114. return NULL;
  1115. }
  1116. int av_lockmgr_register(int (*cb)(void **mutex, enum AVLockOp op))
  1117. {
  1118. if (ff_lockmgr_cb) {
  1119. if (ff_lockmgr_cb(&codec_mutex, AV_LOCK_DESTROY))
  1120. return -1;
  1121. }
  1122. ff_lockmgr_cb = cb;
  1123. if (ff_lockmgr_cb) {
  1124. if (ff_lockmgr_cb(&codec_mutex, AV_LOCK_CREATE))
  1125. return -1;
  1126. }
  1127. return 0;
  1128. }