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.

1322 lines
38KB

  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 FFmpeg.
  7. *
  8. * FFmpeg 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. * FFmpeg 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 FFmpeg; 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 "libavcore/audioconvert.h"
  31. #include "libavcore/imgutils.h"
  32. #include "libavcore/internal.h"
  33. #include "libavcore/samplefmt.h"
  34. #include "avcodec.h"
  35. #include "dsputil.h"
  36. #include "libavutil/opt.h"
  37. #include "imgconvert.h"
  38. #include "thread.h"
  39. #include "audioconvert.h"
  40. #include "internal.h"
  41. #include <stdlib.h>
  42. #include <stdarg.h>
  43. #include <limits.h>
  44. #include <float.h>
  45. static int volatile entangled_thread_counter=0;
  46. static int (*ff_lockmgr_cb)(void **mutex, enum AVLockOp op);
  47. static void *codec_mutex;
  48. void *av_fast_realloc(void *ptr, unsigned int *size, FF_INTERNALC_MEM_TYPE min_size)
  49. {
  50. if(min_size < *size)
  51. return ptr;
  52. min_size= FFMAX(17*min_size/16 + 32, min_size);
  53. ptr= av_realloc(ptr, min_size);
  54. 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
  55. min_size= 0;
  56. *size= min_size;
  57. return ptr;
  58. }
  59. void av_fast_malloc(void *ptr, unsigned int *size, FF_INTERNALC_MEM_TYPE min_size)
  60. {
  61. void **p = ptr;
  62. if (min_size < *size)
  63. return;
  64. min_size= FFMAX(17*min_size/16 + 32, min_size);
  65. av_free(*p);
  66. *p = av_malloc(min_size);
  67. if (!*p) min_size = 0;
  68. *size= min_size;
  69. }
  70. /* encoder management */
  71. static AVCodec *first_avcodec = NULL;
  72. AVCodec *av_codec_next(AVCodec *c){
  73. if(c) return c->next;
  74. else return first_avcodec;
  75. }
  76. void avcodec_register(AVCodec *codec)
  77. {
  78. AVCodec **p;
  79. avcodec_init();
  80. p = &first_avcodec;
  81. while (*p != NULL) p = &(*p)->next;
  82. *p = codec;
  83. codec->next = NULL;
  84. }
  85. #if LIBAVCODEC_VERSION_MAJOR < 53
  86. void register_avcodec(AVCodec *codec)
  87. {
  88. avcodec_register(codec);
  89. }
  90. #endif
  91. unsigned avcodec_get_edge_width(void)
  92. {
  93. return EDGE_WIDTH;
  94. }
  95. void avcodec_set_dimensions(AVCodecContext *s, int width, int height){
  96. s->coded_width = width;
  97. s->coded_height= height;
  98. s->width = -((-width )>>s->lowres);
  99. s->height= -((-height)>>s->lowres);
  100. }
  101. typedef struct InternalBuffer{
  102. int last_pic_num;
  103. uint8_t *base[4];
  104. uint8_t *data[4];
  105. int linesize[4];
  106. int width, height;
  107. enum PixelFormat pix_fmt;
  108. }InternalBuffer;
  109. #define INTERNAL_BUFFER_SIZE 32
  110. void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height, int linesize_align[4]){
  111. int w_align= 1;
  112. int h_align= 1;
  113. switch(s->pix_fmt){
  114. case PIX_FMT_YUV420P:
  115. case PIX_FMT_YUYV422:
  116. case PIX_FMT_UYVY422:
  117. case PIX_FMT_YUV422P:
  118. case PIX_FMT_YUV440P:
  119. case PIX_FMT_YUV444P:
  120. case PIX_FMT_GRAY8:
  121. case PIX_FMT_GRAY16BE:
  122. case PIX_FMT_GRAY16LE:
  123. case PIX_FMT_YUVJ420P:
  124. case PIX_FMT_YUVJ422P:
  125. case PIX_FMT_YUVJ440P:
  126. case PIX_FMT_YUVJ444P:
  127. case PIX_FMT_YUVA420P:
  128. w_align= 16; //FIXME check for non mpeg style codecs and use less alignment
  129. h_align= 16;
  130. 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)
  131. h_align= 32; // interlaced is rounded up to 2 MBs
  132. break;
  133. case PIX_FMT_YUV411P:
  134. case PIX_FMT_UYYVYY411:
  135. w_align=32;
  136. h_align=8;
  137. break;
  138. case PIX_FMT_YUV410P:
  139. if(s->codec_id == CODEC_ID_SVQ1){
  140. w_align=64;
  141. h_align=64;
  142. }
  143. case PIX_FMT_RGB555:
  144. if(s->codec_id == CODEC_ID_RPZA){
  145. w_align=4;
  146. h_align=4;
  147. }
  148. case PIX_FMT_PAL8:
  149. case PIX_FMT_BGR8:
  150. case PIX_FMT_RGB8:
  151. if(s->codec_id == CODEC_ID_SMC){
  152. w_align=4;
  153. h_align=4;
  154. }
  155. break;
  156. case PIX_FMT_BGR24:
  157. if((s->codec_id == CODEC_ID_MSZH) || (s->codec_id == CODEC_ID_ZLIB)){
  158. w_align=4;
  159. h_align=4;
  160. }
  161. break;
  162. default:
  163. w_align= 1;
  164. h_align= 1;
  165. break;
  166. }
  167. *width = FFALIGN(*width , w_align);
  168. *height= FFALIGN(*height, h_align);
  169. if(s->codec_id == CODEC_ID_H264 || s->lowres)
  170. *height+=2; // some of the optimized chroma MC reads one line too much
  171. // which is also done in mpeg decoders with lowres > 0
  172. linesize_align[0] =
  173. linesize_align[1] =
  174. linesize_align[2] =
  175. linesize_align[3] = STRIDE_ALIGN;
  176. //STRIDE_ALIGN is 8 for SSE* but this does not work for SVQ1 chroma planes
  177. //we could change STRIDE_ALIGN to 16 for x86/sse but it would increase the
  178. //picture size unneccessarily in some cases. The solution here is not
  179. //pretty and better ideas are welcome!
  180. #if HAVE_MMX
  181. if(s->codec_id == CODEC_ID_SVQ1 || s->codec_id == CODEC_ID_VP5 ||
  182. s->codec_id == CODEC_ID_VP6 || s->codec_id == CODEC_ID_VP6F ||
  183. s->codec_id == CODEC_ID_VP6A) {
  184. linesize_align[0] =
  185. linesize_align[1] =
  186. linesize_align[2] = 16;
  187. }
  188. #endif
  189. }
  190. void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height){
  191. int chroma_shift = av_pix_fmt_descriptors[s->pix_fmt].log2_chroma_w;
  192. int linesize_align[4];
  193. int align;
  194. avcodec_align_dimensions2(s, width, height, linesize_align);
  195. align = FFMAX(linesize_align[0], linesize_align[3]);
  196. linesize_align[1] <<= chroma_shift;
  197. linesize_align[2] <<= chroma_shift;
  198. align = FFMAX3(align, linesize_align[1], linesize_align[2]);
  199. *width=FFALIGN(*width, align);
  200. }
  201. #if LIBAVCODEC_VERSION_MAJOR < 53
  202. int avcodec_check_dimensions(void *av_log_ctx, unsigned int w, unsigned int h){
  203. return av_image_check_size(w, h, 0, av_log_ctx);
  204. }
  205. #endif
  206. int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic){
  207. int i;
  208. int w= s->width;
  209. int h= s->height;
  210. InternalBuffer *buf;
  211. int *picture_number;
  212. if(pic->data[0]!=NULL) {
  213. av_log(s, AV_LOG_ERROR, "pic->data[0]!=NULL in avcodec_default_get_buffer\n");
  214. return -1;
  215. }
  216. if(s->internal_buffer_count >= INTERNAL_BUFFER_SIZE) {
  217. av_log(s, AV_LOG_ERROR, "internal_buffer_count overflow (missing release_buffer?)\n");
  218. return -1;
  219. }
  220. if(av_image_check_size(w, h, 0, s))
  221. return -1;
  222. if(s->internal_buffer==NULL){
  223. s->internal_buffer= av_mallocz((INTERNAL_BUFFER_SIZE+1)*sizeof(InternalBuffer));
  224. }
  225. #if 0
  226. s->internal_buffer= av_fast_realloc(
  227. s->internal_buffer,
  228. &s->internal_buffer_size,
  229. sizeof(InternalBuffer)*FFMAX(99, s->internal_buffer_count+1)/*FIXME*/
  230. );
  231. #endif
  232. buf= &((InternalBuffer*)s->internal_buffer)[s->internal_buffer_count];
  233. picture_number= &(((InternalBuffer*)s->internal_buffer)[INTERNAL_BUFFER_SIZE]).last_pic_num; //FIXME ugly hack
  234. (*picture_number)++;
  235. if(buf->base[0] && (buf->width != w || buf->height != h || buf->pix_fmt != s->pix_fmt)){
  236. if(s->active_thread_type&FF_THREAD_FRAME) {
  237. av_log_missing_feature(s, "Width/height changing with frame threads is", 0);
  238. return -1;
  239. }
  240. for(i=0; i<4; i++){
  241. av_freep(&buf->base[i]);
  242. buf->data[i]= NULL;
  243. }
  244. }
  245. if(buf->base[0]){
  246. pic->age= *picture_number - buf->last_pic_num;
  247. buf->last_pic_num= *picture_number;
  248. }else{
  249. int h_chroma_shift, v_chroma_shift;
  250. int size[4] = {0};
  251. int tmpsize;
  252. int unaligned;
  253. AVPicture picture;
  254. int stride_align[4];
  255. avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift);
  256. avcodec_align_dimensions2(s, &w, &h, stride_align);
  257. if(!(s->flags&CODEC_FLAG_EMU_EDGE)){
  258. w+= EDGE_WIDTH*2;
  259. h+= EDGE_WIDTH*2;
  260. }
  261. do {
  262. // NOTE: do not align linesizes individually, this breaks e.g. assumptions
  263. // that linesize[0] == 2*linesize[1] in the MPEG-encoder for 4:2:2
  264. av_image_fill_linesizes(picture.linesize, s->pix_fmt, w);
  265. // increase alignment of w for next try (rhs gives the lowest bit set in w)
  266. w += w & ~(w-1);
  267. unaligned = 0;
  268. for (i=0; i<4; i++){
  269. unaligned |= picture.linesize[i] % stride_align[i];
  270. }
  271. } while (unaligned);
  272. tmpsize = av_image_fill_pointers(picture.data, s->pix_fmt, h, NULL, picture.linesize);
  273. if (tmpsize < 0)
  274. return -1;
  275. for (i=0; i<3 && picture.data[i+1]; i++)
  276. size[i] = picture.data[i+1] - picture.data[i];
  277. size[i] = tmpsize - (picture.data[i] - picture.data[0]);
  278. buf->last_pic_num= -256*256*256*64;
  279. memset(buf->base, 0, sizeof(buf->base));
  280. memset(buf->data, 0, sizeof(buf->data));
  281. for(i=0; i<4 && size[i]; i++){
  282. const int h_shift= i==0 ? 0 : h_chroma_shift;
  283. const int v_shift= i==0 ? 0 : v_chroma_shift;
  284. buf->linesize[i]= picture.linesize[i];
  285. buf->base[i]= av_malloc(size[i]+16); //FIXME 16
  286. if(buf->base[i]==NULL) return -1;
  287. memset(buf->base[i], 128, size[i]);
  288. // no edge if EDGE EMU or not planar YUV
  289. if((s->flags&CODEC_FLAG_EMU_EDGE) || !size[2])
  290. buf->data[i] = buf->base[i];
  291. else
  292. buf->data[i] = buf->base[i] + FFALIGN((buf->linesize[i]*EDGE_WIDTH>>v_shift) + (EDGE_WIDTH>>h_shift), stride_align[i]);
  293. }
  294. if(size[1] && !size[2])
  295. ff_set_systematic_pal2((uint32_t*)buf->data[1], s->pix_fmt);
  296. buf->width = s->width;
  297. buf->height = s->height;
  298. buf->pix_fmt= s->pix_fmt;
  299. pic->age= 256*256*256*64;
  300. }
  301. pic->type= FF_BUFFER_TYPE_INTERNAL;
  302. for(i=0; i<4; i++){
  303. pic->base[i]= buf->base[i];
  304. pic->data[i]= buf->data[i];
  305. pic->linesize[i]= buf->linesize[i];
  306. }
  307. s->internal_buffer_count++;
  308. if(s->pkt) pic->pkt_pts= s->pkt->pts;
  309. else pic->pkt_pts= AV_NOPTS_VALUE;
  310. pic->reordered_opaque= s->reordered_opaque;
  311. if(s->debug&FF_DEBUG_BUFFERS)
  312. av_log(s, AV_LOG_DEBUG, "default_get_buffer called on pic %p, %d buffers used\n", pic, s->internal_buffer_count);
  313. return 0;
  314. }
  315. void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic){
  316. int i;
  317. InternalBuffer *buf, *last;
  318. assert(pic->type==FF_BUFFER_TYPE_INTERNAL);
  319. assert(s->internal_buffer_count);
  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. 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 = pic->best_effort_timestamp = 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= -1;
  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. goto end;
  414. }
  415. if(avctx->codec || !codec)
  416. goto end;
  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. goto free_and_end;
  461. }
  462. avctx->frame_number = 0;
  463. if (HAVE_THREADS && !avctx->thread_opaque) {
  464. ret = avcodec_thread_init(avctx, avctx->thread_count);
  465. if (ret < 0) {
  466. goto free_and_end;
  467. }
  468. }
  469. if (avctx->codec->max_lowres < avctx->lowres) {
  470. av_log(avctx, AV_LOG_ERROR, "The maximum value for lowres supported by the decoder is %d\n",
  471. avctx->codec->max_lowres);
  472. goto free_and_end;
  473. }
  474. avctx->pts_correction_num_faulty_pts =
  475. avctx->pts_correction_num_faulty_dts = 0;
  476. avctx->pts_correction_last_pts =
  477. avctx->pts_correction_last_dts = INT64_MIN;
  478. if(avctx->codec->init && !(avctx->active_thread_type&FF_THREAD_FRAME)){
  479. ret = avctx->codec->init(avctx);
  480. if (ret < 0) {
  481. goto free_and_end;
  482. }
  483. }
  484. ret=0;
  485. end:
  486. entangled_thread_counter--;
  487. /* Release any user-supplied mutex. */
  488. if (ff_lockmgr_cb) {
  489. (*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE);
  490. }
  491. return ret;
  492. free_and_end:
  493. av_freep(&avctx->priv_data);
  494. avctx->codec= NULL;
  495. goto end;
  496. }
  497. int attribute_align_arg avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size,
  498. const short *samples)
  499. {
  500. if(buf_size < FF_MIN_BUFFER_SIZE && 0){
  501. av_log(avctx, AV_LOG_ERROR, "buffer smaller than minimum size\n");
  502. return -1;
  503. }
  504. if((avctx->codec->capabilities & CODEC_CAP_DELAY) || samples){
  505. int ret = avctx->codec->encode(avctx, buf, buf_size, samples);
  506. avctx->frame_number++;
  507. return ret;
  508. }else
  509. return 0;
  510. }
  511. int attribute_align_arg avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size,
  512. const AVFrame *pict)
  513. {
  514. if(buf_size < FF_MIN_BUFFER_SIZE){
  515. av_log(avctx, AV_LOG_ERROR, "buffer smaller than minimum size\n");
  516. return -1;
  517. }
  518. if(av_image_check_size(avctx->width, avctx->height, 0, avctx))
  519. return -1;
  520. if((avctx->codec->capabilities & CODEC_CAP_DELAY) || pict){
  521. int ret = avctx->codec->encode(avctx, buf, buf_size, pict);
  522. avctx->frame_number++;
  523. emms_c(); //needed to avoid an emms_c() call before every return;
  524. return ret;
  525. }else
  526. return 0;
  527. }
  528. int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size,
  529. const AVSubtitle *sub)
  530. {
  531. int ret;
  532. if(sub->start_display_time) {
  533. av_log(avctx, AV_LOG_ERROR, "start_display_time must be 0.\n");
  534. return -1;
  535. }
  536. if(sub->num_rects == 0 || !sub->rects)
  537. return -1;
  538. ret = avctx->codec->encode(avctx, buf, buf_size, sub);
  539. avctx->frame_number++;
  540. return ret;
  541. }
  542. /**
  543. * Attempt to guess proper monotonic timestamps for decoded video frames
  544. * which might have incorrect times. Input timestamps may wrap around, in
  545. * which case the output will as well.
  546. *
  547. * @param pts the pts field of the decoded AVPacket, as passed through
  548. * AVFrame.pkt_pts
  549. * @param dts the dts field of the decoded AVPacket
  550. * @return one of the input values, may be AV_NOPTS_VALUE
  551. */
  552. static int64_t guess_correct_pts(AVCodecContext *ctx,
  553. int64_t reordered_pts, int64_t dts)
  554. {
  555. int64_t pts = AV_NOPTS_VALUE;
  556. if (dts != AV_NOPTS_VALUE) {
  557. ctx->pts_correction_num_faulty_dts += dts <= ctx->pts_correction_last_dts;
  558. ctx->pts_correction_last_dts = dts;
  559. }
  560. if (reordered_pts != AV_NOPTS_VALUE) {
  561. ctx->pts_correction_num_faulty_pts += reordered_pts <= ctx->pts_correction_last_pts;
  562. ctx->pts_correction_last_pts = reordered_pts;
  563. }
  564. if ((ctx->pts_correction_num_faulty_pts<=ctx->pts_correction_num_faulty_dts || dts == AV_NOPTS_VALUE)
  565. && reordered_pts != AV_NOPTS_VALUE)
  566. pts = reordered_pts;
  567. else
  568. pts = dts;
  569. return pts;
  570. }
  571. #if FF_API_VIDEO_OLD
  572. int attribute_align_arg avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture,
  573. int *got_picture_ptr,
  574. const uint8_t *buf, int buf_size)
  575. {
  576. AVPacket avpkt;
  577. av_init_packet(&avpkt);
  578. avpkt.data = buf;
  579. avpkt.size = buf_size;
  580. // HACK for CorePNG to decode as normal PNG by default
  581. avpkt.flags = AV_PKT_FLAG_KEY;
  582. return avcodec_decode_video2(avctx, picture, got_picture_ptr, &avpkt);
  583. }
  584. #endif
  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. picture->best_effort_timestamp = guess_correct_pts(avctx,
  605. picture->pkt_pts,
  606. picture->pkt_dts);
  607. if (*got_picture_ptr)
  608. avctx->frame_number++;
  609. }else
  610. ret= 0;
  611. return ret;
  612. }
  613. #if FF_API_AUDIO_OLD
  614. int attribute_align_arg avcodec_decode_audio2(AVCodecContext *avctx, int16_t *samples,
  615. int *frame_size_ptr,
  616. const uint8_t *buf, int buf_size)
  617. {
  618. AVPacket avpkt;
  619. av_init_packet(&avpkt);
  620. avpkt.data = buf;
  621. avpkt.size = buf_size;
  622. return avcodec_decode_audio3(avctx, samples, frame_size_ptr, &avpkt);
  623. }
  624. #endif
  625. int attribute_align_arg avcodec_decode_audio3(AVCodecContext *avctx, int16_t *samples,
  626. int *frame_size_ptr,
  627. AVPacket *avpkt)
  628. {
  629. int ret;
  630. avctx->pkt = avpkt;
  631. if((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size){
  632. //FIXME remove the check below _after_ ensuring that all audio check that the available space is enough
  633. if(*frame_size_ptr < AVCODEC_MAX_AUDIO_FRAME_SIZE){
  634. av_log(avctx, AV_LOG_ERROR, "buffer smaller than AVCODEC_MAX_AUDIO_FRAME_SIZE\n");
  635. return -1;
  636. }
  637. if(*frame_size_ptr < FF_MIN_BUFFER_SIZE ||
  638. *frame_size_ptr < avctx->channels * avctx->frame_size * sizeof(int16_t)){
  639. av_log(avctx, AV_LOG_ERROR, "buffer %d too small\n", *frame_size_ptr);
  640. return -1;
  641. }
  642. ret = avctx->codec->decode(avctx, samples, frame_size_ptr, avpkt);
  643. avctx->frame_number++;
  644. }else{
  645. ret= 0;
  646. *frame_size_ptr=0;
  647. }
  648. return ret;
  649. }
  650. #if FF_API_SUBTITLE_OLD
  651. int avcodec_decode_subtitle(AVCodecContext *avctx, AVSubtitle *sub,
  652. int *got_sub_ptr,
  653. const uint8_t *buf, int buf_size)
  654. {
  655. AVPacket avpkt;
  656. av_init_packet(&avpkt);
  657. avpkt.data = buf;
  658. avpkt.size = buf_size;
  659. return avcodec_decode_subtitle2(avctx, sub, got_sub_ptr, &avpkt);
  660. }
  661. #endif
  662. int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub,
  663. int *got_sub_ptr,
  664. AVPacket *avpkt)
  665. {
  666. int ret;
  667. avctx->pkt = avpkt;
  668. *got_sub_ptr = 0;
  669. ret = avctx->codec->decode(avctx, sub, got_sub_ptr, avpkt);
  670. if (*got_sub_ptr)
  671. avctx->frame_number++;
  672. return ret;
  673. }
  674. void avsubtitle_free(AVSubtitle *sub)
  675. {
  676. int i;
  677. for (i = 0; i < sub->num_rects; i++)
  678. {
  679. av_freep(&sub->rects[i]->pict.data[0]);
  680. av_freep(&sub->rects[i]->pict.data[1]);
  681. av_freep(&sub->rects[i]->pict.data[2]);
  682. av_freep(&sub->rects[i]->pict.data[3]);
  683. av_freep(&sub->rects[i]->text);
  684. av_freep(&sub->rects[i]->ass);
  685. av_freep(&sub->rects[i]);
  686. }
  687. av_freep(&sub->rects);
  688. memset(sub, 0, sizeof(AVSubtitle));
  689. }
  690. av_cold int avcodec_close(AVCodecContext *avctx)
  691. {
  692. /* If there is a user-supplied mutex locking routine, call it. */
  693. if (ff_lockmgr_cb) {
  694. if ((*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_OBTAIN))
  695. return -1;
  696. }
  697. entangled_thread_counter++;
  698. if(entangled_thread_counter != 1){
  699. av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n");
  700. entangled_thread_counter--;
  701. return -1;
  702. }
  703. if (HAVE_THREADS && avctx->thread_opaque)
  704. avcodec_thread_free(avctx);
  705. if (avctx->codec && avctx->codec->close)
  706. avctx->codec->close(avctx);
  707. avcodec_default_free_buffers(avctx);
  708. avctx->coded_frame = NULL;
  709. av_freep(&avctx->priv_data);
  710. if(avctx->codec && avctx->codec->encode)
  711. av_freep(&avctx->extradata);
  712. avctx->codec = NULL;
  713. avctx->active_thread_type = 0;
  714. entangled_thread_counter--;
  715. /* Release any user-supplied mutex. */
  716. if (ff_lockmgr_cb) {
  717. (*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE);
  718. }
  719. return 0;
  720. }
  721. AVCodec *avcodec_find_encoder(enum CodecID id)
  722. {
  723. AVCodec *p, *experimental=NULL;
  724. p = first_avcodec;
  725. while (p) {
  726. if (p->encode != NULL && p->id == id) {
  727. if (p->capabilities & CODEC_CAP_EXPERIMENTAL && !experimental) {
  728. experimental = p;
  729. } else
  730. return p;
  731. }
  732. p = p->next;
  733. }
  734. return experimental;
  735. }
  736. AVCodec *avcodec_find_encoder_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->encode != NULL && strcmp(name,p->name) == 0)
  744. return p;
  745. p = p->next;
  746. }
  747. return NULL;
  748. }
  749. AVCodec *avcodec_find_decoder(enum CodecID id)
  750. {
  751. AVCodec *p;
  752. p = first_avcodec;
  753. while (p) {
  754. if (p->decode != NULL && p->id == id)
  755. return p;
  756. p = p->next;
  757. }
  758. return NULL;
  759. }
  760. AVCodec *avcodec_find_decoder_by_name(const char *name)
  761. {
  762. AVCodec *p;
  763. if (!name)
  764. return NULL;
  765. p = first_avcodec;
  766. while (p) {
  767. if (p->decode != NULL && strcmp(name,p->name) == 0)
  768. return p;
  769. p = p->next;
  770. }
  771. return NULL;
  772. }
  773. static int get_bit_rate(AVCodecContext *ctx)
  774. {
  775. int bit_rate;
  776. int bits_per_sample;
  777. switch(ctx->codec_type) {
  778. case AVMEDIA_TYPE_VIDEO:
  779. case AVMEDIA_TYPE_DATA:
  780. case AVMEDIA_TYPE_SUBTITLE:
  781. case AVMEDIA_TYPE_ATTACHMENT:
  782. bit_rate = ctx->bit_rate;
  783. break;
  784. case AVMEDIA_TYPE_AUDIO:
  785. bits_per_sample = av_get_bits_per_sample(ctx->codec_id);
  786. bit_rate = bits_per_sample ? ctx->sample_rate * ctx->channels * bits_per_sample : ctx->bit_rate;
  787. break;
  788. default:
  789. bit_rate = 0;
  790. break;
  791. }
  792. return bit_rate;
  793. }
  794. size_t av_get_codec_tag_string(char *buf, size_t buf_size, unsigned int codec_tag)
  795. {
  796. int i, len, ret = 0;
  797. for (i = 0; i < 4; i++) {
  798. len = snprintf(buf, buf_size,
  799. isprint(codec_tag&0xFF) ? "%c" : "[%d]", codec_tag&0xFF);
  800. buf += len;
  801. buf_size = buf_size > len ? buf_size - len : 0;
  802. ret += len;
  803. codec_tag>>=8;
  804. }
  805. return ret;
  806. }
  807. void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
  808. {
  809. const char *codec_name;
  810. const char *profile = NULL;
  811. AVCodec *p;
  812. char buf1[32];
  813. int bitrate;
  814. AVRational display_aspect_ratio;
  815. if (encode)
  816. p = avcodec_find_encoder(enc->codec_id);
  817. else
  818. p = avcodec_find_decoder(enc->codec_id);
  819. if (p) {
  820. codec_name = p->name;
  821. profile = av_get_profile_name(p, enc->profile);
  822. } else if (enc->codec_id == CODEC_ID_MPEG2TS) {
  823. /* fake mpeg2 transport stream codec (currently not
  824. registered) */
  825. codec_name = "mpeg2ts";
  826. } else if (enc->codec_name[0] != '\0') {
  827. codec_name = enc->codec_name;
  828. } else {
  829. /* output avi tags */
  830. char tag_buf[32];
  831. av_get_codec_tag_string(tag_buf, sizeof(tag_buf), enc->codec_tag);
  832. snprintf(buf1, sizeof(buf1), "%s / 0x%04X", tag_buf, enc->codec_tag);
  833. codec_name = buf1;
  834. }
  835. switch(enc->codec_type) {
  836. case AVMEDIA_TYPE_VIDEO:
  837. snprintf(buf, buf_size,
  838. "Video: %s%s",
  839. codec_name, enc->mb_decision ? " (hq)" : "");
  840. if (profile)
  841. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  842. " (%s)", profile);
  843. if (enc->pix_fmt != PIX_FMT_NONE) {
  844. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  845. ", %s",
  846. avcodec_get_pix_fmt_name(enc->pix_fmt));
  847. }
  848. if (enc->width) {
  849. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  850. ", %dx%d",
  851. enc->width, enc->height);
  852. if (enc->sample_aspect_ratio.num) {
  853. av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,
  854. enc->width*enc->sample_aspect_ratio.num,
  855. enc->height*enc->sample_aspect_ratio.den,
  856. 1024*1024);
  857. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  858. " [PAR %d:%d DAR %d:%d]",
  859. enc->sample_aspect_ratio.num, enc->sample_aspect_ratio.den,
  860. display_aspect_ratio.num, display_aspect_ratio.den);
  861. }
  862. if(av_log_get_level() >= AV_LOG_DEBUG){
  863. int g= av_gcd(enc->time_base.num, enc->time_base.den);
  864. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  865. ", %d/%d",
  866. enc->time_base.num/g, enc->time_base.den/g);
  867. }
  868. }
  869. if (encode) {
  870. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  871. ", q=%d-%d", enc->qmin, enc->qmax);
  872. }
  873. break;
  874. case AVMEDIA_TYPE_AUDIO:
  875. snprintf(buf, buf_size,
  876. "Audio: %s",
  877. codec_name);
  878. if (profile)
  879. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  880. " (%s)", profile);
  881. if (enc->sample_rate) {
  882. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  883. ", %d Hz", enc->sample_rate);
  884. }
  885. av_strlcat(buf, ", ", buf_size);
  886. av_get_channel_layout_string(buf + strlen(buf), buf_size - strlen(buf), enc->channels, enc->channel_layout);
  887. if (enc->sample_fmt != AV_SAMPLE_FMT_NONE) {
  888. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  889. ", %s", av_get_sample_fmt_name(enc->sample_fmt));
  890. }
  891. break;
  892. case AVMEDIA_TYPE_DATA:
  893. snprintf(buf, buf_size, "Data: %s", codec_name);
  894. break;
  895. case AVMEDIA_TYPE_SUBTITLE:
  896. snprintf(buf, buf_size, "Subtitle: %s", codec_name);
  897. break;
  898. case AVMEDIA_TYPE_ATTACHMENT:
  899. snprintf(buf, buf_size, "Attachment: %s", codec_name);
  900. break;
  901. default:
  902. snprintf(buf, buf_size, "Invalid Codec type %d", enc->codec_type);
  903. return;
  904. }
  905. if (encode) {
  906. if (enc->flags & CODEC_FLAG_PASS1)
  907. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  908. ", pass 1");
  909. if (enc->flags & CODEC_FLAG_PASS2)
  910. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  911. ", pass 2");
  912. }
  913. bitrate = get_bit_rate(enc);
  914. if (bitrate != 0) {
  915. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  916. ", %d kb/s", bitrate / 1000);
  917. }
  918. }
  919. const char *av_get_profile_name(const AVCodec *codec, int profile)
  920. {
  921. const AVProfile *p;
  922. if (profile == FF_PROFILE_UNKNOWN || !codec->profiles)
  923. return NULL;
  924. for (p = codec->profiles; p->profile != FF_PROFILE_UNKNOWN; p++)
  925. if (p->profile == profile)
  926. return p->name;
  927. return NULL;
  928. }
  929. unsigned avcodec_version( void )
  930. {
  931. return LIBAVCODEC_VERSION_INT;
  932. }
  933. const char *avcodec_configuration(void)
  934. {
  935. return FFMPEG_CONFIGURATION;
  936. }
  937. const char *avcodec_license(void)
  938. {
  939. #define LICENSE_PREFIX "libavcodec license: "
  940. return LICENSE_PREFIX FFMPEG_LICENSE + sizeof(LICENSE_PREFIX) - 1;
  941. }
  942. void avcodec_init(void)
  943. {
  944. static int initialized = 0;
  945. if (initialized != 0)
  946. return;
  947. initialized = 1;
  948. dsputil_static_init();
  949. }
  950. void avcodec_flush_buffers(AVCodecContext *avctx)
  951. {
  952. if(HAVE_PTHREADS && avctx->active_thread_type&FF_THREAD_FRAME)
  953. ff_thread_flush(avctx);
  954. if(avctx->codec->flush)
  955. avctx->codec->flush(avctx);
  956. }
  957. void avcodec_default_free_buffers(AVCodecContext *s){
  958. int i, j;
  959. if(s->internal_buffer==NULL) return;
  960. if (s->internal_buffer_count)
  961. av_log(s, AV_LOG_WARNING, "Found %i unreleased buffers!\n", s->internal_buffer_count);
  962. for(i=0; i<INTERNAL_BUFFER_SIZE; i++){
  963. InternalBuffer *buf= &((InternalBuffer*)s->internal_buffer)[i];
  964. for(j=0; j<4; j++){
  965. av_freep(&buf->base[j]);
  966. buf->data[j]= NULL;
  967. }
  968. }
  969. av_freep(&s->internal_buffer);
  970. s->internal_buffer_count=0;
  971. }
  972. char av_get_pict_type_char(int pict_type){
  973. switch(pict_type){
  974. case FF_I_TYPE: return 'I';
  975. case FF_P_TYPE: return 'P';
  976. case FF_B_TYPE: return 'B';
  977. case FF_S_TYPE: return 'S';
  978. case FF_SI_TYPE:return 'i';
  979. case FF_SP_TYPE:return 'p';
  980. case FF_BI_TYPE:return 'b';
  981. default: return '?';
  982. }
  983. }
  984. int av_get_bits_per_sample(enum CodecID codec_id){
  985. switch(codec_id){
  986. case CODEC_ID_ADPCM_SBPRO_2:
  987. return 2;
  988. case CODEC_ID_ADPCM_SBPRO_3:
  989. return 3;
  990. case CODEC_ID_ADPCM_SBPRO_4:
  991. case CODEC_ID_ADPCM_CT:
  992. case CODEC_ID_ADPCM_IMA_WAV:
  993. case CODEC_ID_ADPCM_MS:
  994. case CODEC_ID_ADPCM_YAMAHA:
  995. return 4;
  996. case CODEC_ID_PCM_ALAW:
  997. case CODEC_ID_PCM_MULAW:
  998. case CODEC_ID_PCM_S8:
  999. case CODEC_ID_PCM_U8:
  1000. case CODEC_ID_PCM_ZORK:
  1001. return 8;
  1002. case CODEC_ID_PCM_S16BE:
  1003. case CODEC_ID_PCM_S16LE:
  1004. case CODEC_ID_PCM_S16LE_PLANAR:
  1005. case CODEC_ID_PCM_U16BE:
  1006. case CODEC_ID_PCM_U16LE:
  1007. return 16;
  1008. case CODEC_ID_PCM_S24DAUD:
  1009. case CODEC_ID_PCM_S24BE:
  1010. case CODEC_ID_PCM_S24LE:
  1011. case CODEC_ID_PCM_U24BE:
  1012. case CODEC_ID_PCM_U24LE:
  1013. return 24;
  1014. case CODEC_ID_PCM_S32BE:
  1015. case CODEC_ID_PCM_S32LE:
  1016. case CODEC_ID_PCM_U32BE:
  1017. case CODEC_ID_PCM_U32LE:
  1018. case CODEC_ID_PCM_F32BE:
  1019. case CODEC_ID_PCM_F32LE:
  1020. return 32;
  1021. case CODEC_ID_PCM_F64BE:
  1022. case CODEC_ID_PCM_F64LE:
  1023. return 64;
  1024. default:
  1025. return 0;
  1026. }
  1027. }
  1028. #if FF_API_OLD_SAMPLE_FMT
  1029. int av_get_bits_per_sample_format(enum AVSampleFormat sample_fmt) {
  1030. return av_get_bits_per_sample_fmt(sample_fmt);
  1031. }
  1032. #endif
  1033. #if !HAVE_THREADS
  1034. int avcodec_thread_init(AVCodecContext *s, int thread_count){
  1035. s->thread_count = thread_count;
  1036. return -1;
  1037. }
  1038. #endif
  1039. unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
  1040. {
  1041. unsigned int n = 0;
  1042. while(v >= 0xff) {
  1043. *s++ = 0xff;
  1044. v -= 0xff;
  1045. n++;
  1046. }
  1047. *s = v;
  1048. n++;
  1049. return n;
  1050. }
  1051. #if LIBAVCODEC_VERSION_MAJOR < 53
  1052. #include "libavcore/parseutils.h"
  1053. int av_parse_video_frame_size(int *width_ptr, int *height_ptr, const char *str)
  1054. {
  1055. return av_parse_video_size(width_ptr, height_ptr, str);
  1056. }
  1057. int av_parse_video_frame_rate(AVRational *frame_rate, const char *arg)
  1058. {
  1059. return av_parse_video_rate(frame_rate, arg);
  1060. }
  1061. #endif
  1062. int ff_match_2uint16(const uint16_t (*tab)[2], int size, int a, int b){
  1063. int i;
  1064. for(i=0; i<size && !(tab[i][0]==a && tab[i][1]==b); i++);
  1065. return i;
  1066. }
  1067. void av_log_missing_feature(void *avc, const char *feature, int want_sample)
  1068. {
  1069. av_log(avc, AV_LOG_WARNING, "%s not implemented. Update your FFmpeg "
  1070. "version to the newest one from Git. If the problem still "
  1071. "occurs, it means that your file has a feature which has not "
  1072. "been implemented.", feature);
  1073. if(want_sample)
  1074. av_log_ask_for_sample(avc, NULL);
  1075. else
  1076. av_log(avc, AV_LOG_WARNING, "\n");
  1077. }
  1078. void av_log_ask_for_sample(void *avc, const char *msg)
  1079. {
  1080. if (msg)
  1081. av_log(avc, AV_LOG_WARNING, "%s ", msg);
  1082. av_log(avc, AV_LOG_WARNING, "If you want to help, upload a sample "
  1083. "of this file to ftp://upload.ffmpeg.org/MPlayer/incoming/ "
  1084. "and contact the ffmpeg-devel mailing list.\n");
  1085. }
  1086. static AVHWAccel *first_hwaccel = NULL;
  1087. void av_register_hwaccel(AVHWAccel *hwaccel)
  1088. {
  1089. AVHWAccel **p = &first_hwaccel;
  1090. while (*p)
  1091. p = &(*p)->next;
  1092. *p = hwaccel;
  1093. hwaccel->next = NULL;
  1094. }
  1095. AVHWAccel *av_hwaccel_next(AVHWAccel *hwaccel)
  1096. {
  1097. return hwaccel ? hwaccel->next : first_hwaccel;
  1098. }
  1099. AVHWAccel *ff_find_hwaccel(enum CodecID codec_id, enum PixelFormat pix_fmt)
  1100. {
  1101. AVHWAccel *hwaccel=NULL;
  1102. while((hwaccel= av_hwaccel_next(hwaccel))){
  1103. if ( hwaccel->id == codec_id
  1104. && hwaccel->pix_fmt == pix_fmt)
  1105. return hwaccel;
  1106. }
  1107. return NULL;
  1108. }
  1109. int av_lockmgr_register(int (*cb)(void **mutex, enum AVLockOp op))
  1110. {
  1111. if (ff_lockmgr_cb) {
  1112. if (ff_lockmgr_cb(&codec_mutex, AV_LOCK_DESTROY))
  1113. return -1;
  1114. }
  1115. ff_lockmgr_cb = cb;
  1116. if (ff_lockmgr_cb) {
  1117. if (ff_lockmgr_cb(&codec_mutex, AV_LOCK_CREATE))
  1118. return -1;
  1119. }
  1120. return 0;
  1121. }
  1122. unsigned int ff_toupper4(unsigned int x)
  1123. {
  1124. return toupper( x &0xFF)
  1125. + (toupper((x>>8 )&0xFF)<<8 )
  1126. + (toupper((x>>16)&0xFF)<<16)
  1127. + (toupper((x>>24)&0xFF)<<24);
  1128. }
  1129. #if !HAVE_PTHREADS
  1130. int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f)
  1131. {
  1132. f->owner = avctx;
  1133. return avctx->get_buffer(avctx, f);
  1134. }
  1135. void ff_thread_release_buffer(AVCodecContext *avctx, AVFrame *f)
  1136. {
  1137. f->owner->release_buffer(f->owner, f);
  1138. }
  1139. void ff_thread_finish_setup(AVCodecContext *avctx)
  1140. {
  1141. }
  1142. void ff_thread_report_progress(AVFrame *f, int progress, int field)
  1143. {
  1144. }
  1145. void ff_thread_await_progress(AVFrame *f, int progress, int field)
  1146. {
  1147. }
  1148. #endif