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.

1268 lines
37KB

  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 Libav.
  7. *
  8. * Libav 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. * Libav 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 Libav; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. /**
  23. * @file
  24. * utils.
  25. */
  26. #include "libavutil/avstring.h"
  27. #include "libavutil/integer.h"
  28. #include "libavutil/crc.h"
  29. #include "libavutil/pixdesc.h"
  30. #include "libavutil/audioconvert.h"
  31. #include "libavutil/imgutils.h"
  32. #include "libavutil/samplefmt.h"
  33. #include "avcodec.h"
  34. #include "dsputil.h"
  35. #include "libavutil/opt.h"
  36. #include "imgconvert.h"
  37. #include "thread.h"
  38. #include "audioconvert.h"
  39. #include "internal.h"
  40. #include <stdlib.h>
  41. #include <stdarg.h>
  42. #include <limits.h>
  43. #include <float.h>
  44. static int volatile entangled_thread_counter=0;
  45. static int (*ff_lockmgr_cb)(void **mutex, enum AVLockOp op);
  46. static void *codec_mutex;
  47. void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
  48. {
  49. if(min_size < *size)
  50. return ptr;
  51. min_size= FFMAX(17*min_size/16 + 32, min_size);
  52. ptr= av_realloc(ptr, min_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. min_size= 0;
  55. *size= min_size;
  56. return ptr;
  57. }
  58. void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
  59. {
  60. void **p = ptr;
  61. if (min_size < *size)
  62. return;
  63. min_size= FFMAX(17*min_size/16 + 32, min_size);
  64. av_free(*p);
  65. *p = av_malloc(min_size);
  66. if (!*p) min_size = 0;
  67. *size= min_size;
  68. }
  69. /* encoder management */
  70. static AVCodec *first_avcodec = NULL;
  71. AVCodec *av_codec_next(AVCodec *c){
  72. if(c) return c->next;
  73. else return first_avcodec;
  74. }
  75. void avcodec_register(AVCodec *codec)
  76. {
  77. AVCodec **p;
  78. avcodec_init();
  79. p = &first_avcodec;
  80. while (*p != NULL) p = &(*p)->next;
  81. *p = codec;
  82. codec->next = NULL;
  83. }
  84. unsigned avcodec_get_edge_width(void)
  85. {
  86. return EDGE_WIDTH;
  87. }
  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_dimensions2(AVCodecContext *s, int *width, int *height, int linesize_align[4]){
  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. case PIX_FMT_YUV420P9LE:
  122. case PIX_FMT_YUV420P9BE:
  123. case PIX_FMT_YUV420P10LE:
  124. case PIX_FMT_YUV420P10BE:
  125. w_align= 16; //FIXME check for non mpeg style codecs and use less alignment
  126. h_align= 16;
  127. 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)
  128. h_align= 32; // interlaced is rounded up to 2 MBs
  129. break;
  130. case PIX_FMT_YUV411P:
  131. case PIX_FMT_UYYVYY411:
  132. w_align=32;
  133. h_align=8;
  134. break;
  135. case PIX_FMT_YUV410P:
  136. if(s->codec_id == CODEC_ID_SVQ1){
  137. w_align=64;
  138. h_align=64;
  139. }
  140. case PIX_FMT_RGB555:
  141. if(s->codec_id == CODEC_ID_RPZA){
  142. w_align=4;
  143. h_align=4;
  144. }
  145. case PIX_FMT_PAL8:
  146. case PIX_FMT_BGR8:
  147. case PIX_FMT_RGB8:
  148. if(s->codec_id == CODEC_ID_SMC){
  149. w_align=4;
  150. h_align=4;
  151. }
  152. break;
  153. case PIX_FMT_BGR24:
  154. if((s->codec_id == CODEC_ID_MSZH) || (s->codec_id == CODEC_ID_ZLIB)){
  155. w_align=4;
  156. h_align=4;
  157. }
  158. break;
  159. default:
  160. w_align= 1;
  161. h_align= 1;
  162. break;
  163. }
  164. *width = FFALIGN(*width , w_align);
  165. *height= FFALIGN(*height, h_align);
  166. if(s->codec_id == CODEC_ID_H264 || s->lowres)
  167. *height+=2; // some of the optimized chroma MC reads one line too much
  168. // which is also done in mpeg decoders with lowres > 0
  169. linesize_align[0] =
  170. linesize_align[1] =
  171. linesize_align[2] =
  172. linesize_align[3] = STRIDE_ALIGN;
  173. //STRIDE_ALIGN is 8 for SSE* but this does not work for SVQ1 chroma planes
  174. //we could change STRIDE_ALIGN to 16 for x86/sse but it would increase the
  175. //picture size unneccessarily in some cases. The solution here is not
  176. //pretty and better ideas are welcome!
  177. #if HAVE_MMX
  178. if(s->codec_id == CODEC_ID_SVQ1 || s->codec_id == CODEC_ID_VP5 ||
  179. s->codec_id == CODEC_ID_VP6 || s->codec_id == CODEC_ID_VP6F ||
  180. s->codec_id == CODEC_ID_VP6A) {
  181. linesize_align[0] =
  182. linesize_align[1] =
  183. linesize_align[2] = 16;
  184. }
  185. #endif
  186. }
  187. void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height){
  188. int chroma_shift = av_pix_fmt_descriptors[s->pix_fmt].log2_chroma_w;
  189. int linesize_align[4];
  190. int align;
  191. avcodec_align_dimensions2(s, width, height, linesize_align);
  192. align = FFMAX(linesize_align[0], linesize_align[3]);
  193. linesize_align[1] <<= chroma_shift;
  194. linesize_align[2] <<= chroma_shift;
  195. align = FFMAX3(align, linesize_align[1], linesize_align[2]);
  196. *width=FFALIGN(*width, align);
  197. }
  198. int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic){
  199. int i;
  200. int w= s->width;
  201. int h= s->height;
  202. InternalBuffer *buf;
  203. int *picture_number;
  204. if(pic->data[0]!=NULL) {
  205. av_log(s, AV_LOG_ERROR, "pic->data[0]!=NULL in avcodec_default_get_buffer\n");
  206. return -1;
  207. }
  208. if(s->internal_buffer_count >= INTERNAL_BUFFER_SIZE) {
  209. av_log(s, AV_LOG_ERROR, "internal_buffer_count overflow (missing release_buffer?)\n");
  210. return -1;
  211. }
  212. if(av_image_check_size(w, h, 0, s))
  213. return -1;
  214. if(s->internal_buffer==NULL){
  215. s->internal_buffer= av_mallocz((INTERNAL_BUFFER_SIZE+1)*sizeof(InternalBuffer));
  216. }
  217. #if 0
  218. s->internal_buffer= av_fast_realloc(
  219. s->internal_buffer,
  220. &s->internal_buffer_size,
  221. sizeof(InternalBuffer)*FFMAX(99, s->internal_buffer_count+1)/*FIXME*/
  222. );
  223. #endif
  224. buf= &((InternalBuffer*)s->internal_buffer)[s->internal_buffer_count];
  225. picture_number= &(((InternalBuffer*)s->internal_buffer)[INTERNAL_BUFFER_SIZE]).last_pic_num; //FIXME ugly hack
  226. (*picture_number)++;
  227. if(buf->base[0] && (buf->width != w || buf->height != h || buf->pix_fmt != s->pix_fmt)){
  228. if(s->active_thread_type&FF_THREAD_FRAME) {
  229. av_log_missing_feature(s, "Width/height changing with frame threads is", 0);
  230. return -1;
  231. }
  232. for(i=0; i<4; i++){
  233. av_freep(&buf->base[i]);
  234. buf->data[i]= NULL;
  235. }
  236. }
  237. if(buf->base[0]){
  238. pic->age= *picture_number - buf->last_pic_num;
  239. buf->last_pic_num= *picture_number;
  240. }else{
  241. int h_chroma_shift, v_chroma_shift;
  242. int size[4] = {0};
  243. int tmpsize;
  244. int unaligned;
  245. AVPicture picture;
  246. int stride_align[4];
  247. const int pixel_size = av_pix_fmt_descriptors[s->pix_fmt].comp[0].step_minus1+1;
  248. avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift);
  249. avcodec_align_dimensions2(s, &w, &h, stride_align);
  250. if(!(s->flags&CODEC_FLAG_EMU_EDGE)){
  251. w+= EDGE_WIDTH*2;
  252. h+= EDGE_WIDTH*2;
  253. }
  254. do {
  255. // NOTE: do not align linesizes individually, this breaks e.g. assumptions
  256. // that linesize[0] == 2*linesize[1] in the MPEG-encoder for 4:2:2
  257. av_image_fill_linesizes(picture.linesize, s->pix_fmt, w);
  258. // increase alignment of w for next try (rhs gives the lowest bit set in w)
  259. w += w & ~(w-1);
  260. unaligned = 0;
  261. for (i=0; i<4; i++){
  262. unaligned |= picture.linesize[i] % stride_align[i];
  263. }
  264. } while (unaligned);
  265. tmpsize = av_image_fill_pointers(picture.data, s->pix_fmt, h, NULL, picture.linesize);
  266. if (tmpsize < 0)
  267. return -1;
  268. for (i=0; i<3 && picture.data[i+1]; i++)
  269. size[i] = picture.data[i+1] - picture.data[i];
  270. size[i] = tmpsize - (picture.data[i] - picture.data[0]);
  271. buf->last_pic_num= -256*256*256*64;
  272. memset(buf->base, 0, sizeof(buf->base));
  273. memset(buf->data, 0, sizeof(buf->data));
  274. for(i=0; i<4 && size[i]; i++){
  275. const int h_shift= i==0 ? 0 : h_chroma_shift;
  276. const int v_shift= i==0 ? 0 : v_chroma_shift;
  277. buf->linesize[i]= picture.linesize[i];
  278. buf->base[i]= av_malloc(size[i]+16); //FIXME 16
  279. if(buf->base[i]==NULL) return -1;
  280. memset(buf->base[i], 128, size[i]);
  281. // no edge if EDGE EMU or not planar YUV
  282. if((s->flags&CODEC_FLAG_EMU_EDGE) || !size[2])
  283. buf->data[i] = buf->base[i];
  284. else
  285. buf->data[i] = buf->base[i] + FFALIGN((buf->linesize[i]*EDGE_WIDTH>>v_shift) + (pixel_size*EDGE_WIDTH>>h_shift), stride_align[i]);
  286. }
  287. if(size[1] && !size[2])
  288. ff_set_systematic_pal2((uint32_t*)buf->data[1], s->pix_fmt);
  289. buf->width = s->width;
  290. buf->height = s->height;
  291. buf->pix_fmt= s->pix_fmt;
  292. pic->age= 256*256*256*64;
  293. }
  294. pic->type= FF_BUFFER_TYPE_INTERNAL;
  295. for(i=0; i<4; i++){
  296. pic->base[i]= buf->base[i];
  297. pic->data[i]= buf->data[i];
  298. pic->linesize[i]= buf->linesize[i];
  299. }
  300. s->internal_buffer_count++;
  301. if(s->pkt) pic->pkt_pts= s->pkt->pts;
  302. else pic->pkt_pts= AV_NOPTS_VALUE;
  303. pic->reordered_opaque= s->reordered_opaque;
  304. if(s->debug&FF_DEBUG_BUFFERS)
  305. av_log(s, AV_LOG_DEBUG, "default_get_buffer called on pic %p, %d buffers used\n", pic, s->internal_buffer_count);
  306. return 0;
  307. }
  308. void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic){
  309. int i;
  310. InternalBuffer *buf, *last;
  311. assert(pic->type==FF_BUFFER_TYPE_INTERNAL);
  312. assert(s->internal_buffer_count);
  313. buf = NULL; /* avoids warning */
  314. for(i=0; i<s->internal_buffer_count; i++){ //just 3-5 checks so is not worth to optimize
  315. buf= &((InternalBuffer*)s->internal_buffer)[i];
  316. if(buf->data[0] == pic->data[0])
  317. break;
  318. }
  319. assert(i < s->internal_buffer_count);
  320. s->internal_buffer_count--;
  321. last = &((InternalBuffer*)s->internal_buffer)[s->internal_buffer_count];
  322. FFSWAP(InternalBuffer, *buf, *last);
  323. for(i=0; i<4; i++){
  324. pic->data[i]=NULL;
  325. // pic->base[i]=NULL;
  326. }
  327. //printf("R%X\n", pic->opaque);
  328. if(s->debug&FF_DEBUG_BUFFERS)
  329. av_log(s, AV_LOG_DEBUG, "default_release_buffer called on pic %p, %d buffers used\n", pic, s->internal_buffer_count);
  330. }
  331. int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic){
  332. AVFrame temp_pic;
  333. int i;
  334. /* If no picture return a new buffer */
  335. if(pic->data[0] == NULL) {
  336. /* We will copy from buffer, so must be readable */
  337. pic->buffer_hints |= FF_BUFFER_HINTS_READABLE;
  338. return s->get_buffer(s, pic);
  339. }
  340. /* If internal buffer type return the same buffer */
  341. if(pic->type == FF_BUFFER_TYPE_INTERNAL) {
  342. if(s->pkt) pic->pkt_pts= s->pkt->pts;
  343. else pic->pkt_pts= AV_NOPTS_VALUE;
  344. pic->reordered_opaque= s->reordered_opaque;
  345. return 0;
  346. }
  347. /*
  348. * Not internal type and reget_buffer not overridden, emulate cr buffer
  349. */
  350. temp_pic = *pic;
  351. for(i = 0; i < 4; i++)
  352. pic->data[i] = pic->base[i] = NULL;
  353. pic->opaque = NULL;
  354. /* Allocate new frame */
  355. if (s->get_buffer(s, pic))
  356. return -1;
  357. /* Copy image data from old buffer to new buffer */
  358. av_picture_copy((AVPicture*)pic, (AVPicture*)&temp_pic, s->pix_fmt, s->width,
  359. s->height);
  360. s->release_buffer(s, &temp_pic); // Release old frame
  361. return 0;
  362. }
  363. int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size){
  364. int i;
  365. for(i=0; i<count; i++){
  366. int r= func(c, (char*)arg + i*size);
  367. if(ret) ret[i]= r;
  368. }
  369. return 0;
  370. }
  371. int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int jobnr, int threadnr),void *arg, int *ret, int count){
  372. int i;
  373. for(i=0; i<count; i++){
  374. int r= func(c, arg, i, 0);
  375. if(ret) ret[i]= r;
  376. }
  377. return 0;
  378. }
  379. enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum PixelFormat *fmt){
  380. while (*fmt != PIX_FMT_NONE && ff_is_hwaccel_pix_fmt(*fmt))
  381. ++fmt;
  382. return fmt[0];
  383. }
  384. void avcodec_get_frame_defaults(AVFrame *pic){
  385. memset(pic, 0, sizeof(AVFrame));
  386. pic->pts= AV_NOPTS_VALUE;
  387. pic->key_frame= 1;
  388. }
  389. AVFrame *avcodec_alloc_frame(void){
  390. AVFrame *pic= av_malloc(sizeof(AVFrame));
  391. if(pic==NULL) return NULL;
  392. avcodec_get_frame_defaults(pic);
  393. return pic;
  394. }
  395. int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec)
  396. {
  397. int ret = 0;
  398. /* If there is a user-supplied mutex locking routine, call it. */
  399. if (ff_lockmgr_cb) {
  400. if ((*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_OBTAIN))
  401. return -1;
  402. }
  403. entangled_thread_counter++;
  404. if(entangled_thread_counter != 1){
  405. av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n");
  406. ret = -1;
  407. goto end;
  408. }
  409. if(avctx->codec || !codec) {
  410. ret = AVERROR(EINVAL);
  411. goto end;
  412. }
  413. if (codec->priv_data_size > 0) {
  414. if(!avctx->priv_data){
  415. avctx->priv_data = av_mallocz(codec->priv_data_size);
  416. if (!avctx->priv_data) {
  417. ret = AVERROR(ENOMEM);
  418. goto end;
  419. }
  420. if(codec->priv_class){ //this can be droped once all user apps use avcodec_get_context_defaults3()
  421. *(AVClass**)avctx->priv_data= codec->priv_class;
  422. av_opt_set_defaults(avctx->priv_data);
  423. }
  424. }
  425. } else {
  426. avctx->priv_data = NULL;
  427. }
  428. if(avctx->coded_width && avctx->coded_height)
  429. avcodec_set_dimensions(avctx, avctx->coded_width, avctx->coded_height);
  430. else if(avctx->width && avctx->height)
  431. avcodec_set_dimensions(avctx, avctx->width, avctx->height);
  432. if ((avctx->coded_width || avctx->coded_height || avctx->width || avctx->height)
  433. && ( av_image_check_size(avctx->coded_width, avctx->coded_height, 0, avctx) < 0
  434. || av_image_check_size(avctx->width, avctx->height, 0, avctx) < 0)) {
  435. av_log(avctx, AV_LOG_WARNING, "ignoring invalid width/height values\n");
  436. avcodec_set_dimensions(avctx, 0, 0);
  437. }
  438. /* if the decoder init function was already called previously,
  439. free the already allocated subtitle_header before overwriting it */
  440. if (codec->decode)
  441. av_freep(&avctx->subtitle_header);
  442. #define SANE_NB_CHANNELS 128U
  443. if (avctx->channels > SANE_NB_CHANNELS) {
  444. ret = AVERROR(EINVAL);
  445. goto free_and_end;
  446. }
  447. avctx->codec = codec;
  448. if ((avctx->codec_type == AVMEDIA_TYPE_UNKNOWN || avctx->codec_type == codec->type) &&
  449. avctx->codec_id == CODEC_ID_NONE) {
  450. avctx->codec_type = codec->type;
  451. avctx->codec_id = codec->id;
  452. }
  453. if (avctx->codec_id != codec->id || (avctx->codec_type != codec->type
  454. && avctx->codec_type != AVMEDIA_TYPE_ATTACHMENT)) {
  455. av_log(avctx, AV_LOG_ERROR, "codec type or id mismatches\n");
  456. ret = AVERROR(EINVAL);
  457. goto free_and_end;
  458. }
  459. avctx->frame_number = 0;
  460. if (HAVE_THREADS && !avctx->thread_opaque) {
  461. ret = ff_thread_init(avctx);
  462. if (ret < 0) {
  463. goto free_and_end;
  464. }
  465. }
  466. if (avctx->codec->max_lowres < avctx->lowres) {
  467. av_log(avctx, AV_LOG_ERROR, "The maximum value for lowres supported by the decoder is %d\n",
  468. avctx->codec->max_lowres);
  469. ret = AVERROR(EINVAL);
  470. goto free_and_end;
  471. }
  472. if (avctx->codec->encode) {
  473. int i;
  474. if (avctx->codec->sample_fmts) {
  475. for (i = 0; avctx->codec->sample_fmts[i] != AV_SAMPLE_FMT_NONE; i++)
  476. if (avctx->sample_fmt == avctx->codec->sample_fmts[i])
  477. break;
  478. if (avctx->codec->sample_fmts[i] == AV_SAMPLE_FMT_NONE) {
  479. av_log(avctx, AV_LOG_ERROR, "Specified sample_fmt is not supported.\n");
  480. ret = AVERROR(EINVAL);
  481. goto free_and_end;
  482. }
  483. }
  484. if (avctx->codec->supported_samplerates) {
  485. for (i = 0; avctx->codec->supported_samplerates[i] != 0; i++)
  486. if (avctx->sample_rate == avctx->codec->supported_samplerates[i])
  487. break;
  488. if (avctx->codec->supported_samplerates[i] == 0) {
  489. av_log(avctx, AV_LOG_ERROR, "Specified sample_rate is not supported\n");
  490. ret = AVERROR(EINVAL);
  491. goto free_and_end;
  492. }
  493. }
  494. if (avctx->codec->channel_layouts) {
  495. if (!avctx->channel_layout) {
  496. av_log(avctx, AV_LOG_WARNING, "channel_layout not specified\n");
  497. } else {
  498. for (i = 0; avctx->codec->channel_layouts[i] != 0; i++)
  499. if (avctx->channel_layout == avctx->codec->channel_layouts[i])
  500. break;
  501. if (avctx->codec->channel_layouts[i] == 0) {
  502. av_log(avctx, AV_LOG_ERROR, "Specified channel_layout is not supported\n");
  503. ret = AVERROR(EINVAL);
  504. goto free_and_end;
  505. }
  506. }
  507. }
  508. if (avctx->channel_layout && avctx->channels) {
  509. if (av_get_channel_layout_nb_channels(avctx->channel_layout) != avctx->channels) {
  510. av_log(avctx, AV_LOG_ERROR, "channel layout does not match number of channels\n");
  511. ret = AVERROR(EINVAL);
  512. goto free_and_end;
  513. }
  514. } else if (avctx->channel_layout) {
  515. avctx->channels = av_get_channel_layout_nb_channels(avctx->channel_layout);
  516. }
  517. }
  518. if(avctx->codec->init && !(avctx->active_thread_type&FF_THREAD_FRAME)){
  519. ret = avctx->codec->init(avctx);
  520. if (ret < 0) {
  521. goto free_and_end;
  522. }
  523. }
  524. end:
  525. entangled_thread_counter--;
  526. /* Release any user-supplied mutex. */
  527. if (ff_lockmgr_cb) {
  528. (*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE);
  529. }
  530. return ret;
  531. free_and_end:
  532. av_freep(&avctx->priv_data);
  533. avctx->codec= NULL;
  534. goto end;
  535. }
  536. int attribute_align_arg avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size,
  537. const short *samples)
  538. {
  539. if(buf_size < FF_MIN_BUFFER_SIZE && 0){
  540. av_log(avctx, AV_LOG_ERROR, "buffer smaller than minimum size\n");
  541. return -1;
  542. }
  543. if((avctx->codec->capabilities & CODEC_CAP_DELAY) || samples){
  544. int ret = avctx->codec->encode(avctx, buf, buf_size, samples);
  545. avctx->frame_number++;
  546. return ret;
  547. }else
  548. return 0;
  549. }
  550. int attribute_align_arg avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size,
  551. const AVFrame *pict)
  552. {
  553. if(buf_size < FF_MIN_BUFFER_SIZE){
  554. av_log(avctx, AV_LOG_ERROR, "buffer smaller than minimum size\n");
  555. return -1;
  556. }
  557. if(av_image_check_size(avctx->width, avctx->height, 0, avctx))
  558. return -1;
  559. if((avctx->codec->capabilities & CODEC_CAP_DELAY) || pict){
  560. int ret = avctx->codec->encode(avctx, buf, buf_size, pict);
  561. avctx->frame_number++;
  562. emms_c(); //needed to avoid an emms_c() call before every return;
  563. return ret;
  564. }else
  565. return 0;
  566. }
  567. int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size,
  568. const AVSubtitle *sub)
  569. {
  570. int ret;
  571. if(sub->start_display_time) {
  572. av_log(avctx, AV_LOG_ERROR, "start_display_time must be 0.\n");
  573. return -1;
  574. }
  575. if(sub->num_rects == 0 || !sub->rects)
  576. return -1;
  577. ret = avctx->codec->encode(avctx, buf, buf_size, sub);
  578. avctx->frame_number++;
  579. return ret;
  580. }
  581. int attribute_align_arg avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture,
  582. int *got_picture_ptr,
  583. AVPacket *avpkt)
  584. {
  585. int ret;
  586. *got_picture_ptr= 0;
  587. if((avctx->coded_width||avctx->coded_height) && av_image_check_size(avctx->coded_width, avctx->coded_height, 0, avctx))
  588. return -1;
  589. avctx->pkt = avpkt;
  590. if((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size || (avctx->active_thread_type&FF_THREAD_FRAME)){
  591. if (HAVE_PTHREADS && avctx->active_thread_type&FF_THREAD_FRAME)
  592. ret = ff_thread_decode_frame(avctx, picture, got_picture_ptr,
  593. avpkt);
  594. else {
  595. ret = avctx->codec->decode(avctx, picture, got_picture_ptr,
  596. avpkt);
  597. picture->pkt_dts= avpkt->dts;
  598. }
  599. emms_c(); //needed to avoid an emms_c() call before every return;
  600. if (*got_picture_ptr)
  601. avctx->frame_number++;
  602. }else
  603. ret= 0;
  604. return ret;
  605. }
  606. int attribute_align_arg avcodec_decode_audio3(AVCodecContext *avctx, int16_t *samples,
  607. int *frame_size_ptr,
  608. AVPacket *avpkt)
  609. {
  610. int ret;
  611. avctx->pkt = avpkt;
  612. if((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size){
  613. //FIXME remove the check below _after_ ensuring that all audio check that the available space is enough
  614. if(*frame_size_ptr < AVCODEC_MAX_AUDIO_FRAME_SIZE){
  615. av_log(avctx, AV_LOG_ERROR, "buffer smaller than AVCODEC_MAX_AUDIO_FRAME_SIZE\n");
  616. return -1;
  617. }
  618. if(*frame_size_ptr < FF_MIN_BUFFER_SIZE ||
  619. *frame_size_ptr < avctx->channels * avctx->frame_size * sizeof(int16_t)){
  620. av_log(avctx, AV_LOG_ERROR, "buffer %d too small\n", *frame_size_ptr);
  621. return -1;
  622. }
  623. ret = avctx->codec->decode(avctx, samples, frame_size_ptr, avpkt);
  624. avctx->frame_number++;
  625. }else{
  626. ret= 0;
  627. *frame_size_ptr=0;
  628. }
  629. return ret;
  630. }
  631. int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub,
  632. int *got_sub_ptr,
  633. AVPacket *avpkt)
  634. {
  635. int ret;
  636. avctx->pkt = avpkt;
  637. *got_sub_ptr = 0;
  638. ret = avctx->codec->decode(avctx, sub, got_sub_ptr, avpkt);
  639. if (*got_sub_ptr)
  640. avctx->frame_number++;
  641. return ret;
  642. }
  643. void avsubtitle_free(AVSubtitle *sub)
  644. {
  645. int i;
  646. for (i = 0; i < sub->num_rects; i++)
  647. {
  648. av_freep(&sub->rects[i]->pict.data[0]);
  649. av_freep(&sub->rects[i]->pict.data[1]);
  650. av_freep(&sub->rects[i]->pict.data[2]);
  651. av_freep(&sub->rects[i]->pict.data[3]);
  652. av_freep(&sub->rects[i]->text);
  653. av_freep(&sub->rects[i]->ass);
  654. av_freep(&sub->rects[i]);
  655. }
  656. av_freep(&sub->rects);
  657. memset(sub, 0, sizeof(AVSubtitle));
  658. }
  659. av_cold int avcodec_close(AVCodecContext *avctx)
  660. {
  661. /* If there is a user-supplied mutex locking routine, call it. */
  662. if (ff_lockmgr_cb) {
  663. if ((*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_OBTAIN))
  664. return -1;
  665. }
  666. entangled_thread_counter++;
  667. if(entangled_thread_counter != 1){
  668. av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n");
  669. entangled_thread_counter--;
  670. return -1;
  671. }
  672. if (HAVE_THREADS && avctx->thread_opaque)
  673. ff_thread_free(avctx);
  674. if (avctx->codec && avctx->codec->close)
  675. avctx->codec->close(avctx);
  676. avcodec_default_free_buffers(avctx);
  677. avctx->coded_frame = NULL;
  678. av_freep(&avctx->priv_data);
  679. if(avctx->codec && avctx->codec->encode)
  680. av_freep(&avctx->extradata);
  681. avctx->codec = NULL;
  682. avctx->active_thread_type = 0;
  683. entangled_thread_counter--;
  684. /* Release any user-supplied mutex. */
  685. if (ff_lockmgr_cb) {
  686. (*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE);
  687. }
  688. return 0;
  689. }
  690. AVCodec *avcodec_find_encoder(enum CodecID id)
  691. {
  692. AVCodec *p, *experimental=NULL;
  693. p = first_avcodec;
  694. while (p) {
  695. if (p->encode != NULL && p->id == id) {
  696. if (p->capabilities & CODEC_CAP_EXPERIMENTAL && !experimental) {
  697. experimental = p;
  698. } else
  699. return p;
  700. }
  701. p = p->next;
  702. }
  703. return experimental;
  704. }
  705. AVCodec *avcodec_find_encoder_by_name(const char *name)
  706. {
  707. AVCodec *p;
  708. if (!name)
  709. return NULL;
  710. p = first_avcodec;
  711. while (p) {
  712. if (p->encode != NULL && strcmp(name,p->name) == 0)
  713. return p;
  714. p = p->next;
  715. }
  716. return NULL;
  717. }
  718. AVCodec *avcodec_find_decoder(enum CodecID id)
  719. {
  720. AVCodec *p;
  721. p = first_avcodec;
  722. while (p) {
  723. if (p->decode != NULL && p->id == id)
  724. return p;
  725. p = p->next;
  726. }
  727. return NULL;
  728. }
  729. AVCodec *avcodec_find_decoder_by_name(const char *name)
  730. {
  731. AVCodec *p;
  732. if (!name)
  733. return NULL;
  734. p = first_avcodec;
  735. while (p) {
  736. if (p->decode != NULL && strcmp(name,p->name) == 0)
  737. return p;
  738. p = p->next;
  739. }
  740. return NULL;
  741. }
  742. static int get_bit_rate(AVCodecContext *ctx)
  743. {
  744. int bit_rate;
  745. int bits_per_sample;
  746. switch(ctx->codec_type) {
  747. case AVMEDIA_TYPE_VIDEO:
  748. case AVMEDIA_TYPE_DATA:
  749. case AVMEDIA_TYPE_SUBTITLE:
  750. case AVMEDIA_TYPE_ATTACHMENT:
  751. bit_rate = ctx->bit_rate;
  752. break;
  753. case AVMEDIA_TYPE_AUDIO:
  754. bits_per_sample = av_get_bits_per_sample(ctx->codec_id);
  755. bit_rate = bits_per_sample ? ctx->sample_rate * ctx->channels * bits_per_sample : ctx->bit_rate;
  756. break;
  757. default:
  758. bit_rate = 0;
  759. break;
  760. }
  761. return bit_rate;
  762. }
  763. size_t av_get_codec_tag_string(char *buf, size_t buf_size, unsigned int codec_tag)
  764. {
  765. int i, len, ret = 0;
  766. for (i = 0; i < 4; i++) {
  767. len = snprintf(buf, buf_size,
  768. isprint(codec_tag&0xFF) ? "%c" : "[%d]", codec_tag&0xFF);
  769. buf += len;
  770. buf_size = buf_size > len ? buf_size - len : 0;
  771. ret += len;
  772. codec_tag>>=8;
  773. }
  774. return ret;
  775. }
  776. void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
  777. {
  778. const char *codec_name;
  779. const char *profile = NULL;
  780. AVCodec *p;
  781. char buf1[32];
  782. int bitrate;
  783. AVRational display_aspect_ratio;
  784. if (encode)
  785. p = avcodec_find_encoder(enc->codec_id);
  786. else
  787. p = avcodec_find_decoder(enc->codec_id);
  788. if (p) {
  789. codec_name = p->name;
  790. profile = av_get_profile_name(p, enc->profile);
  791. } else if (enc->codec_id == CODEC_ID_MPEG2TS) {
  792. /* fake mpeg2 transport stream codec (currently not
  793. registered) */
  794. codec_name = "mpeg2ts";
  795. } else if (enc->codec_name[0] != '\0') {
  796. codec_name = enc->codec_name;
  797. } else {
  798. /* output avi tags */
  799. char tag_buf[32];
  800. av_get_codec_tag_string(tag_buf, sizeof(tag_buf), enc->codec_tag);
  801. snprintf(buf1, sizeof(buf1), "%s / 0x%04X", tag_buf, enc->codec_tag);
  802. codec_name = buf1;
  803. }
  804. switch(enc->codec_type) {
  805. case AVMEDIA_TYPE_VIDEO:
  806. snprintf(buf, buf_size,
  807. "Video: %s%s",
  808. codec_name, enc->mb_decision ? " (hq)" : "");
  809. if (profile)
  810. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  811. " (%s)", profile);
  812. if (enc->pix_fmt != PIX_FMT_NONE) {
  813. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  814. ", %s",
  815. avcodec_get_pix_fmt_name(enc->pix_fmt));
  816. }
  817. if (enc->width) {
  818. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  819. ", %dx%d",
  820. enc->width, enc->height);
  821. if (enc->sample_aspect_ratio.num) {
  822. av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,
  823. enc->width*enc->sample_aspect_ratio.num,
  824. enc->height*enc->sample_aspect_ratio.den,
  825. 1024*1024);
  826. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  827. " [PAR %d:%d DAR %d:%d]",
  828. enc->sample_aspect_ratio.num, enc->sample_aspect_ratio.den,
  829. display_aspect_ratio.num, display_aspect_ratio.den);
  830. }
  831. if(av_log_get_level() >= AV_LOG_DEBUG){
  832. int g= av_gcd(enc->time_base.num, enc->time_base.den);
  833. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  834. ", %d/%d",
  835. enc->time_base.num/g, enc->time_base.den/g);
  836. }
  837. }
  838. if (encode) {
  839. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  840. ", q=%d-%d", enc->qmin, enc->qmax);
  841. }
  842. break;
  843. case AVMEDIA_TYPE_AUDIO:
  844. snprintf(buf, buf_size,
  845. "Audio: %s",
  846. codec_name);
  847. if (profile)
  848. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  849. " (%s)", profile);
  850. if (enc->sample_rate) {
  851. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  852. ", %d Hz", enc->sample_rate);
  853. }
  854. av_strlcat(buf, ", ", buf_size);
  855. av_get_channel_layout_string(buf + strlen(buf), buf_size - strlen(buf), enc->channels, enc->channel_layout);
  856. if (enc->sample_fmt != AV_SAMPLE_FMT_NONE) {
  857. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  858. ", %s", av_get_sample_fmt_name(enc->sample_fmt));
  859. }
  860. break;
  861. case AVMEDIA_TYPE_DATA:
  862. snprintf(buf, buf_size, "Data: %s", codec_name);
  863. break;
  864. case AVMEDIA_TYPE_SUBTITLE:
  865. snprintf(buf, buf_size, "Subtitle: %s", codec_name);
  866. break;
  867. case AVMEDIA_TYPE_ATTACHMENT:
  868. snprintf(buf, buf_size, "Attachment: %s", codec_name);
  869. break;
  870. default:
  871. snprintf(buf, buf_size, "Invalid Codec type %d", enc->codec_type);
  872. return;
  873. }
  874. if (encode) {
  875. if (enc->flags & CODEC_FLAG_PASS1)
  876. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  877. ", pass 1");
  878. if (enc->flags & CODEC_FLAG_PASS2)
  879. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  880. ", pass 2");
  881. }
  882. bitrate = get_bit_rate(enc);
  883. if (bitrate != 0) {
  884. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  885. ", %d kb/s", bitrate / 1000);
  886. }
  887. }
  888. const char *av_get_profile_name(const AVCodec *codec, int profile)
  889. {
  890. const AVProfile *p;
  891. if (profile == FF_PROFILE_UNKNOWN || !codec->profiles)
  892. return NULL;
  893. for (p = codec->profiles; p->profile != FF_PROFILE_UNKNOWN; p++)
  894. if (p->profile == profile)
  895. return p->name;
  896. return NULL;
  897. }
  898. unsigned avcodec_version( void )
  899. {
  900. return LIBAVCODEC_VERSION_INT;
  901. }
  902. const char *avcodec_configuration(void)
  903. {
  904. return LIBAV_CONFIGURATION;
  905. }
  906. const char *avcodec_license(void)
  907. {
  908. #define LICENSE_PREFIX "libavcodec license: "
  909. return LICENSE_PREFIX LIBAV_LICENSE + sizeof(LICENSE_PREFIX) - 1;
  910. }
  911. void avcodec_init(void)
  912. {
  913. static int initialized = 0;
  914. if (initialized != 0)
  915. return;
  916. initialized = 1;
  917. dsputil_static_init();
  918. }
  919. void avcodec_flush_buffers(AVCodecContext *avctx)
  920. {
  921. if(HAVE_PTHREADS && avctx->active_thread_type&FF_THREAD_FRAME)
  922. ff_thread_flush(avctx);
  923. if(avctx->codec->flush)
  924. avctx->codec->flush(avctx);
  925. }
  926. void avcodec_default_free_buffers(AVCodecContext *s){
  927. int i, j;
  928. if(s->internal_buffer==NULL) return;
  929. if (s->internal_buffer_count)
  930. av_log(s, AV_LOG_WARNING, "Found %i unreleased buffers!\n", s->internal_buffer_count);
  931. for(i=0; i<INTERNAL_BUFFER_SIZE; i++){
  932. InternalBuffer *buf= &((InternalBuffer*)s->internal_buffer)[i];
  933. for(j=0; j<4; j++){
  934. av_freep(&buf->base[j]);
  935. buf->data[j]= NULL;
  936. }
  937. }
  938. av_freep(&s->internal_buffer);
  939. s->internal_buffer_count=0;
  940. }
  941. #if FF_API_OLD_FF_PICT_TYPES
  942. char av_get_pict_type_char(int pict_type){
  943. return av_get_picture_type_char(pict_type);
  944. }
  945. #endif
  946. int av_get_bits_per_sample(enum CodecID codec_id){
  947. switch(codec_id){
  948. case CODEC_ID_ADPCM_SBPRO_2:
  949. return 2;
  950. case CODEC_ID_ADPCM_SBPRO_3:
  951. return 3;
  952. case CODEC_ID_ADPCM_SBPRO_4:
  953. case CODEC_ID_ADPCM_CT:
  954. case CODEC_ID_ADPCM_IMA_WAV:
  955. case CODEC_ID_ADPCM_MS:
  956. case CODEC_ID_ADPCM_YAMAHA:
  957. return 4;
  958. case CODEC_ID_ADPCM_G722:
  959. case CODEC_ID_PCM_ALAW:
  960. case CODEC_ID_PCM_MULAW:
  961. case CODEC_ID_PCM_S8:
  962. case CODEC_ID_PCM_U8:
  963. case CODEC_ID_PCM_ZORK:
  964. return 8;
  965. case CODEC_ID_PCM_S16BE:
  966. case CODEC_ID_PCM_S16LE:
  967. case CODEC_ID_PCM_S16LE_PLANAR:
  968. case CODEC_ID_PCM_U16BE:
  969. case CODEC_ID_PCM_U16LE:
  970. return 16;
  971. case CODEC_ID_PCM_S24DAUD:
  972. case CODEC_ID_PCM_S24BE:
  973. case CODEC_ID_PCM_S24LE:
  974. case CODEC_ID_PCM_U24BE:
  975. case CODEC_ID_PCM_U24LE:
  976. return 24;
  977. case CODEC_ID_PCM_S32BE:
  978. case CODEC_ID_PCM_S32LE:
  979. case CODEC_ID_PCM_U32BE:
  980. case CODEC_ID_PCM_U32LE:
  981. case CODEC_ID_PCM_F32BE:
  982. case CODEC_ID_PCM_F32LE:
  983. return 32;
  984. case CODEC_ID_PCM_F64BE:
  985. case CODEC_ID_PCM_F64LE:
  986. return 64;
  987. default:
  988. return 0;
  989. }
  990. }
  991. #if FF_API_OLD_SAMPLE_FMT
  992. int av_get_bits_per_sample_format(enum AVSampleFormat sample_fmt) {
  993. return av_get_bits_per_sample_fmt(sample_fmt);
  994. }
  995. #endif
  996. #if !HAVE_THREADS
  997. int ff_thread_init(AVCodecContext *s){
  998. return -1;
  999. }
  1000. #endif
  1001. unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
  1002. {
  1003. unsigned int n = 0;
  1004. while(v >= 0xff) {
  1005. *s++ = 0xff;
  1006. v -= 0xff;
  1007. n++;
  1008. }
  1009. *s = v;
  1010. n++;
  1011. return n;
  1012. }
  1013. int ff_match_2uint16(const uint16_t (*tab)[2], int size, int a, int b){
  1014. int i;
  1015. for(i=0; i<size && !(tab[i][0]==a && tab[i][1]==b); i++);
  1016. return i;
  1017. }
  1018. void av_log_missing_feature(void *avc, const char *feature, int want_sample)
  1019. {
  1020. av_log(avc, AV_LOG_WARNING, "%s not implemented. Update your Libav "
  1021. "version to the newest one from Git. If the problem still "
  1022. "occurs, it means that your file has a feature which has not "
  1023. "been implemented.\n", feature);
  1024. if(want_sample)
  1025. av_log_ask_for_sample(avc, NULL);
  1026. }
  1027. void av_log_ask_for_sample(void *avc, const char *msg, ...)
  1028. {
  1029. va_list argument_list;
  1030. va_start(argument_list, msg);
  1031. if (msg)
  1032. av_vlog(avc, AV_LOG_WARNING, msg, argument_list);
  1033. av_log(avc, AV_LOG_WARNING, "If you want to help, upload a sample "
  1034. "of this file to ftp://upload.libav.org/incoming/ "
  1035. "and contact the libav-devel mailing list.\n");
  1036. va_end(argument_list);
  1037. }
  1038. static AVHWAccel *first_hwaccel = NULL;
  1039. void av_register_hwaccel(AVHWAccel *hwaccel)
  1040. {
  1041. AVHWAccel **p = &first_hwaccel;
  1042. while (*p)
  1043. p = &(*p)->next;
  1044. *p = hwaccel;
  1045. hwaccel->next = NULL;
  1046. }
  1047. AVHWAccel *av_hwaccel_next(AVHWAccel *hwaccel)
  1048. {
  1049. return hwaccel ? hwaccel->next : first_hwaccel;
  1050. }
  1051. AVHWAccel *ff_find_hwaccel(enum CodecID codec_id, enum PixelFormat pix_fmt)
  1052. {
  1053. AVHWAccel *hwaccel=NULL;
  1054. while((hwaccel= av_hwaccel_next(hwaccel))){
  1055. if ( hwaccel->id == codec_id
  1056. && hwaccel->pix_fmt == pix_fmt)
  1057. return hwaccel;
  1058. }
  1059. return NULL;
  1060. }
  1061. int av_lockmgr_register(int (*cb)(void **mutex, enum AVLockOp op))
  1062. {
  1063. if (ff_lockmgr_cb) {
  1064. if (ff_lockmgr_cb(&codec_mutex, AV_LOCK_DESTROY))
  1065. return -1;
  1066. }
  1067. ff_lockmgr_cb = cb;
  1068. if (ff_lockmgr_cb) {
  1069. if (ff_lockmgr_cb(&codec_mutex, AV_LOCK_CREATE))
  1070. return -1;
  1071. }
  1072. return 0;
  1073. }
  1074. unsigned int ff_toupper4(unsigned int x)
  1075. {
  1076. return toupper( x &0xFF)
  1077. + (toupper((x>>8 )&0xFF)<<8 )
  1078. + (toupper((x>>16)&0xFF)<<16)
  1079. + (toupper((x>>24)&0xFF)<<24);
  1080. }
  1081. #if !HAVE_PTHREADS
  1082. int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f)
  1083. {
  1084. f->owner = avctx;
  1085. return avctx->get_buffer(avctx, f);
  1086. }
  1087. void ff_thread_release_buffer(AVCodecContext *avctx, AVFrame *f)
  1088. {
  1089. f->owner->release_buffer(f->owner, f);
  1090. }
  1091. void ff_thread_finish_setup(AVCodecContext *avctx)
  1092. {
  1093. }
  1094. void ff_thread_report_progress(AVFrame *f, int progress, int field)
  1095. {
  1096. }
  1097. void ff_thread_await_progress(AVFrame *f, int progress, int field)
  1098. {
  1099. }
  1100. #endif
  1101. #if FF_API_THREAD_INIT
  1102. int avcodec_thread_init(AVCodecContext *s, int thread_count)
  1103. {
  1104. s->thread_count = thread_count;
  1105. return ff_thread_init(s);
  1106. }
  1107. #endif