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.

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