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.

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