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.

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