| OLD | NEW |
| 1 /* | 1 /* |
| 2 * utils for libavcodec | 2 * utils for libavcodec |
| 3 * Copyright (c) 2001 Fabrice Bellard | 3 * Copyright (c) 2001 Fabrice Bellard |
| 4 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at> | 4 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at> |
| 5 * | 5 * |
| 6 * This file is part of FFmpeg. | 6 * This file is part of FFmpeg. |
| 7 * | 7 * |
| 8 * FFmpeg is free software; you can redistribute it and/or | 8 * FFmpeg is free software; you can redistribute it and/or |
| 9 * modify it under the terms of the GNU Lesser General Public | 9 * modify it under the terms of the GNU Lesser General Public |
| 10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 * @file libavcodec/utils.c | 24 * @file libavcodec/utils.c |
| 25 * utils. | 25 * utils. |
| 26 */ | 26 */ |
| 27 | 27 |
| 28 /* needed for mkstemp() */ | 28 /* needed for mkstemp() */ |
| 29 #define _XOPEN_SOURCE 600 | 29 #define _XOPEN_SOURCE 600 |
| 30 | 30 |
| 31 #include "libavutil/avstring.h" | 31 #include "libavutil/avstring.h" |
| 32 #include "libavutil/integer.h" | 32 #include "libavutil/integer.h" |
| 33 #include "libavutil/crc.h" | 33 #include "libavutil/crc.h" |
| 34 #include "libavutil/pixdesc.h" |
| 34 #include "avcodec.h" | 35 #include "avcodec.h" |
| 35 #include "dsputil.h" | 36 #include "dsputil.h" |
| 36 #include "opt.h" | 37 #include "opt.h" |
| 37 #include "imgconvert.h" | 38 #include "imgconvert.h" |
| 38 #include "thread.h" | 39 #include "thread.h" |
| 39 #include "audioconvert.h" | 40 #include "audioconvert.h" |
| 41 #include "libxvid_internal.h" |
| 40 #include "internal.h" | 42 #include "internal.h" |
| 41 #include <stdlib.h> | 43 #include <stdlib.h> |
| 42 #include <stdarg.h> | 44 #include <stdarg.h> |
| 43 #include <limits.h> | 45 #include <limits.h> |
| 44 #include <float.h> | 46 #include <float.h> |
| 45 #if !HAVE_MKSTEMP | 47 #if !HAVE_MKSTEMP |
| 46 #include <fcntl.h> | 48 #include <fcntl.h> |
| 47 #endif | 49 #endif |
| 48 | 50 |
| 49 static int volatile entangled_thread_counter=0; | 51 static int volatile entangled_thread_counter=0; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 int last_pic_num; | 113 int last_pic_num; |
| 112 uint8_t *base[4]; | 114 uint8_t *base[4]; |
| 113 uint8_t *data[4]; | 115 uint8_t *data[4]; |
| 114 int linesize[4]; | 116 int linesize[4]; |
| 115 int width, height; | 117 int width, height; |
| 116 enum PixelFormat pix_fmt; | 118 enum PixelFormat pix_fmt; |
| 117 }InternalBuffer; | 119 }InternalBuffer; |
| 118 | 120 |
| 119 #define INTERNAL_BUFFER_SIZE 32 | 121 #define INTERNAL_BUFFER_SIZE 32 |
| 120 | 122 |
| 121 void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height){ | 123 void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height, int l
inesize_align[4]){ |
| 122 int w_align= 1; | 124 int w_align= 1; |
| 123 int h_align= 1; | 125 int h_align= 1; |
| 124 | 126 |
| 125 switch(s->pix_fmt){ | 127 switch(s->pix_fmt){ |
| 126 case PIX_FMT_YUV420P: | 128 case PIX_FMT_YUV420P: |
| 127 case PIX_FMT_YUYV422: | 129 case PIX_FMT_YUYV422: |
| 128 case PIX_FMT_UYVY422: | 130 case PIX_FMT_UYVY422: |
| 129 case PIX_FMT_YUV422P: | 131 case PIX_FMT_YUV422P: |
| 130 case PIX_FMT_YUV440P: | 132 case PIX_FMT_YUV440P: |
| 131 case PIX_FMT_YUV444P: | 133 case PIX_FMT_YUV444P: |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 default: | 176 default: |
| 175 w_align= 1; | 177 w_align= 1; |
| 176 h_align= 1; | 178 h_align= 1; |
| 177 break; | 179 break; |
| 178 } | 180 } |
| 179 | 181 |
| 180 *width = FFALIGN(*width , w_align); | 182 *width = FFALIGN(*width , w_align); |
| 181 *height= FFALIGN(*height, h_align); | 183 *height= FFALIGN(*height, h_align); |
| 182 if(s->codec_id == CODEC_ID_H264) | 184 if(s->codec_id == CODEC_ID_H264) |
| 183 *height+=2; // some of the optimized chroma MC reads one line too much | 185 *height+=2; // some of the optimized chroma MC reads one line too much |
| 186 |
| 187 linesize_align[0] = |
| 188 linesize_align[1] = |
| 189 linesize_align[2] = |
| 190 linesize_align[3] = STRIDE_ALIGN; |
| 191 //STRIDE_ALIGN is 8 for SSE* but this does not work for SVQ1 chroma planes |
| 192 //we could change STRIDE_ALIGN to 16 for x86/sse but it would increase the |
| 193 //picture size unneccessarily in some cases. The solution here is not |
| 194 //pretty and better ideas are welcome! |
| 195 #if HAVE_MMX |
| 196 if(s->codec_id == CODEC_ID_SVQ1 || s->codec_id == CODEC_ID_VP5 || |
| 197 s->codec_id == CODEC_ID_VP6 || s->codec_id == CODEC_ID_VP6F || |
| 198 s->codec_id == CODEC_ID_VP6A) { |
| 199 linesize_align[0] = |
| 200 linesize_align[1] = |
| 201 linesize_align[2] = 16; |
| 202 } |
| 203 #endif |
| 204 } |
| 205 |
| 206 void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height){ |
| 207 int chroma_shift = av_pix_fmt_descriptors[s->pix_fmt].log2_chroma_w; |
| 208 int linesize_align[4]; |
| 209 int align; |
| 210 avcodec_align_dimensions2(s, width, height, linesize_align); |
| 211 align = FFMAX(linesize_align[0], linesize_align[3]); |
| 212 linesize_align[1] <<= chroma_shift; |
| 213 linesize_align[2] <<= chroma_shift; |
| 214 align = FFMAX3(align, linesize_align[1], linesize_align[2]); |
| 215 *width=FFALIGN(*width, align); |
| 184 } | 216 } |
| 185 | 217 |
| 186 int avcodec_check_dimensions(void *av_log_ctx, unsigned int w, unsigned int h){ | 218 int avcodec_check_dimensions(void *av_log_ctx, unsigned int w, unsigned int h){ |
| 187 if((int)w>0 && (int)h>0 && (w+128)*(uint64_t)(h+128) < INT_MAX/8) | 219 if((int)w>0 && (int)h>0 && (w+128)*(uint64_t)(h+128) < INT_MAX/8) |
| 188 return 0; | 220 return 0; |
| 189 | 221 |
| 190 av_log(av_log_ctx, AV_LOG_ERROR, "picture size invalid (%ux%u)\n", w, h); | 222 av_log(av_log_ctx, AV_LOG_ERROR, "picture size invalid (%ux%u)\n", w, h); |
| 191 return -1; | 223 return -1; |
| 192 } | 224 } |
| 193 | 225 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 }else{ | 275 }else{ |
| 244 int h_chroma_shift, v_chroma_shift; | 276 int h_chroma_shift, v_chroma_shift; |
| 245 int size[4] = {0}; | 277 int size[4] = {0}; |
| 246 int tmpsize; | 278 int tmpsize; |
| 247 int unaligned; | 279 int unaligned; |
| 248 AVPicture picture; | 280 AVPicture picture; |
| 249 int stride_align[4]; | 281 int stride_align[4]; |
| 250 | 282 |
| 251 avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shi
ft); | 283 avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shi
ft); |
| 252 | 284 |
| 253 avcodec_align_dimensions(s, &w, &h); | 285 avcodec_align_dimensions2(s, &w, &h, stride_align); |
| 254 | 286 |
| 255 if(!(s->flags&CODEC_FLAG_EMU_EDGE)){ | 287 if(!(s->flags&CODEC_FLAG_EMU_EDGE)){ |
| 256 w+= EDGE_WIDTH*2; | 288 w+= EDGE_WIDTH*2; |
| 257 h+= EDGE_WIDTH*2; | 289 h+= EDGE_WIDTH*2; |
| 258 } | 290 } |
| 259 | 291 |
| 260 do { | 292 do { |
| 261 // NOTE: do not align linesizes individually, this breaks e.g. assum
ptions | 293 // NOTE: do not align linesizes individually, this breaks e.g. assum
ptions |
| 262 // that linesize[0] == 2*linesize[1] in the MPEG-encoder for 4:2:2 | 294 // that linesize[0] == 2*linesize[1] in the MPEG-encoder for 4:2:2 |
| 263 ff_fill_linesize(&picture, s->pix_fmt, w); | 295 ff_fill_linesize(&picture, s->pix_fmt, w); |
| 264 // increase alignment of w for next try (rhs gives the lowest bit se
t in w) | 296 // increase alignment of w for next try (rhs gives the lowest bit se
t in w) |
| 265 w += w & ~(w-1); | 297 w += w & ~(w-1); |
| 266 | 298 |
| 267 unaligned = 0; | 299 unaligned = 0; |
| 268 for (i=0; i<4; i++){ | 300 for (i=0; i<4; i++){ |
| 269 //STRIDE_ALIGN is 8 for SSE* but this does not work for SVQ1 chroma planes | |
| 270 //we could change STRIDE_ALIGN to 16 for x86/sse but it would increase the | |
| 271 //picture size unneccessarily in some cases. The solution here is not | |
| 272 //pretty and better ideas are welcome! | |
| 273 #if HAVE_MMX | |
| 274 if(s->codec_id == CODEC_ID_SVQ1) | |
| 275 stride_align[i]= 16; | |
| 276 else | |
| 277 #endif | |
| 278 stride_align[i] = STRIDE_ALIGN; | |
| 279 unaligned |= picture.linesize[i] % stride_align[i]; | 301 unaligned |= picture.linesize[i] % stride_align[i]; |
| 280 } | 302 } |
| 281 } while (unaligned); | 303 } while (unaligned); |
| 282 | 304 |
| 283 tmpsize = ff_fill_pointer(&picture, NULL, s->pix_fmt, h); | 305 tmpsize = ff_fill_pointer(&picture, NULL, s->pix_fmt, h); |
| 284 if (tmpsize < 0) | 306 if (tmpsize < 0) |
| 285 return -1; | 307 return -1; |
| 286 | 308 |
| 287 for (i=0; i<3 && picture.data[i+1]; i++) | 309 for (i=0; i<3 && picture.data[i+1]; i++) |
| 288 size[i] = picture.data[i+1] - picture.data[i]; | 310 size[i] = picture.data[i+1] - picture.data[i]; |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 697 entangled_thread_counter--; | 719 entangled_thread_counter--; |
| 698 return -1; | 720 return -1; |
| 699 } | 721 } |
| 700 | 722 |
| 701 if (HAVE_THREADS && avctx->thread_opaque) | 723 if (HAVE_THREADS && avctx->thread_opaque) |
| 702 avcodec_thread_free(avctx); | 724 avcodec_thread_free(avctx); |
| 703 if (avctx->codec && avctx->codec->close && !(avctx->active_thread_type&FF_TH
READ_FRAME)) | 725 if (avctx->codec && avctx->codec->close && !(avctx->active_thread_type&FF_TH
READ_FRAME)) |
| 704 avctx->codec->close(avctx); | 726 avctx->codec->close(avctx); |
| 705 avcodec_default_free_buffers(avctx); | 727 avcodec_default_free_buffers(avctx); |
| 706 av_freep(&avctx->priv_data); | 728 av_freep(&avctx->priv_data); |
| 729 if(avctx->codec->encode) |
| 730 av_freep(&avctx->extradata); |
| 707 avctx->codec = NULL; | 731 avctx->codec = NULL; |
| 708 avctx->active_thread_type = 0; | 732 avctx->active_thread_type = 0; |
| 709 entangled_thread_counter--; | 733 entangled_thread_counter--; |
| 710 | 734 |
| 711 /* Release any user-supplied mutex. */ | 735 /* Release any user-supplied mutex. */ |
| 712 if (ff_lockmgr_cb) { | 736 if (ff_lockmgr_cb) { |
| 713 (*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE); | 737 (*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE); |
| 714 } | 738 } |
| 715 return 0; | 739 return 0; |
| 716 } | 740 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 760 return NULL; | 784 return NULL; |
| 761 p = first_avcodec; | 785 p = first_avcodec; |
| 762 while (p) { | 786 while (p) { |
| 763 if (p->decode != NULL && strcmp(name,p->name) == 0) | 787 if (p->decode != NULL && strcmp(name,p->name) == 0) |
| 764 return p; | 788 return p; |
| 765 p = p->next; | 789 p = p->next; |
| 766 } | 790 } |
| 767 return NULL; | 791 return NULL; |
| 768 } | 792 } |
| 769 | 793 |
| 770 int av_get_bit_rate(AVCodecContext *ctx) | 794 static int get_bit_rate(AVCodecContext *ctx) |
| 771 { | 795 { |
| 772 int bit_rate; | 796 int bit_rate; |
| 773 int bits_per_sample; | 797 int bits_per_sample; |
| 774 | 798 |
| 775 switch(ctx->codec_type) { | 799 switch(ctx->codec_type) { |
| 776 case CODEC_TYPE_VIDEO: | 800 case CODEC_TYPE_VIDEO: |
| 777 bit_rate = ctx->bit_rate; | 801 bit_rate = ctx->bit_rate; |
| 778 break; | 802 break; |
| 779 case CODEC_TYPE_AUDIO: | 803 case CODEC_TYPE_AUDIO: |
| 780 bits_per_sample = av_get_bits_per_sample(ctx->codec_id); | 804 bits_per_sample = av_get_bits_per_sample(ctx->codec_id); |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 898 return; | 922 return; |
| 899 } | 923 } |
| 900 if (encode) { | 924 if (encode) { |
| 901 if (enc->flags & CODEC_FLAG_PASS1) | 925 if (enc->flags & CODEC_FLAG_PASS1) |
| 902 snprintf(buf + strlen(buf), buf_size - strlen(buf), | 926 snprintf(buf + strlen(buf), buf_size - strlen(buf), |
| 903 ", pass 1"); | 927 ", pass 1"); |
| 904 if (enc->flags & CODEC_FLAG_PASS2) | 928 if (enc->flags & CODEC_FLAG_PASS2) |
| 905 snprintf(buf + strlen(buf), buf_size - strlen(buf), | 929 snprintf(buf + strlen(buf), buf_size - strlen(buf), |
| 906 ", pass 2"); | 930 ", pass 2"); |
| 907 } | 931 } |
| 908 bitrate = av_get_bit_rate(enc); | 932 bitrate = get_bit_rate(enc); |
| 909 if (bitrate != 0) { | 933 if (bitrate != 0) { |
| 910 snprintf(buf + strlen(buf), buf_size - strlen(buf), | 934 snprintf(buf + strlen(buf), buf_size - strlen(buf), |
| 911 ", %d kb/s", bitrate / 1000); | 935 ", %d kb/s", bitrate / 1000); |
| 912 } | 936 } |
| 913 } | 937 } |
| 914 | 938 |
| 915 unsigned avcodec_version( void ) | 939 unsigned avcodec_version( void ) |
| 916 { | 940 { |
| 917 return LIBAVCODEC_VERSION_INT; | 941 return LIBAVCODEC_VERSION_INT; |
| 918 } | 942 } |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1318 | 1342 |
| 1319 void ff_thread_await_progress(AVFrame *f, int progress, int field) | 1343 void ff_thread_await_progress(AVFrame *f, int progress, int field) |
| 1320 { | 1344 { |
| 1321 } | 1345 } |
| 1322 | 1346 |
| 1323 void ff_thread_finish_frame(AVFrame *f) | 1347 void ff_thread_finish_frame(AVFrame *f) |
| 1324 { | 1348 { |
| 1325 } | 1349 } |
| 1326 | 1350 |
| 1327 #endif | 1351 #endif |
| OLD | NEW |