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