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.

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