| 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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 avcodec_align_dimensions2(s, width, height, linesize_align); | 209 avcodec_align_dimensions2(s, width, height, linesize_align); |
| 210 align = FFMAX(linesize_align[0], linesize_align[3]); | 210 align = FFMAX(linesize_align[0], linesize_align[3]); |
| 211 linesize_align[1] <<= chroma_shift; | 211 linesize_align[1] <<= chroma_shift; |
| 212 linesize_align[2] <<= chroma_shift; | 212 linesize_align[2] <<= chroma_shift; |
| 213 align = FFMAX3(align, linesize_align[1], linesize_align[2]); | 213 align = FFMAX3(align, linesize_align[1], linesize_align[2]); |
| 214 *width=FFALIGN(*width, align); | 214 *width=FFALIGN(*width, align); |
| 215 } | 215 } |
| 216 | 216 |
| 217 #if LIBAVCODEC_VERSION_MAJOR < 53 | 217 #if LIBAVCODEC_VERSION_MAJOR < 53 |
| 218 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){ |
| 219 return av_check_image_size(w, h, 0, av_log_ctx); | 219 return av_image_check_size(w, h, 0, av_log_ctx); |
| 220 } | 220 } |
| 221 #endif | 221 #endif |
| 222 | 222 |
| 223 int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic){ | 223 int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic){ |
| 224 int i; | 224 int i; |
| 225 int w= s->width; | 225 int w= s->width; |
| 226 int h= s->height; | 226 int h= s->height; |
| 227 InternalBuffer *buf; | 227 InternalBuffer *buf; |
| 228 int *picture_number; | 228 int *picture_number; |
| 229 | 229 |
| 230 if(pic->data[0]!=NULL) { | 230 if(pic->data[0]!=NULL) { |
| 231 av_log(s, AV_LOG_ERROR, "pic->data[0]!=NULL in avcodec_default_get_buffe
r\n"); | 231 av_log(s, AV_LOG_ERROR, "pic->data[0]!=NULL in avcodec_default_get_buffe
r\n"); |
| 232 return -1; | 232 return -1; |
| 233 } | 233 } |
| 234 if(s->internal_buffer_count >= INTERNAL_BUFFER_SIZE) { | 234 if(s->internal_buffer_count >= INTERNAL_BUFFER_SIZE) { |
| 235 av_log(s, AV_LOG_ERROR, "internal_buffer_count overflow (missing release
_buffer?)\n"); | 235 av_log(s, AV_LOG_ERROR, "internal_buffer_count overflow (missing release
_buffer?)\n"); |
| 236 return -1; | 236 return -1; |
| 237 } | 237 } |
| 238 | 238 |
| 239 if(av_check_image_size(w, h, 0, s)) | 239 if(av_image_check_size(w, h, 0, s)) |
| 240 return -1; | 240 return -1; |
| 241 | 241 |
| 242 if(s->internal_buffer==NULL){ | 242 if(s->internal_buffer==NULL){ |
| 243 s->internal_buffer= av_mallocz((INTERNAL_BUFFER_SIZE+1)*sizeof(InternalB
uffer)); | 243 s->internal_buffer= av_mallocz((INTERNAL_BUFFER_SIZE+1)*sizeof(InternalB
uffer)); |
| 244 } | 244 } |
| 245 #if 0 | 245 #if 0 |
| 246 s->internal_buffer= av_fast_realloc( | 246 s->internal_buffer= av_fast_realloc( |
| 247 s->internal_buffer, | 247 s->internal_buffer, |
| 248 &s->internal_buffer_size, | 248 &s->internal_buffer_size, |
| 249 sizeof(InternalBuffer)*FFMAX(99, s->internal_buffer_count+1)/*FIXME*/ | 249 sizeof(InternalBuffer)*FFMAX(99, s->internal_buffer_count+1)/*FIXME*/ |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 avcodec_align_dimensions2(s, &w, &h, stride_align); | 282 avcodec_align_dimensions2(s, &w, &h, stride_align); |
| 283 | 283 |
| 284 if(!(s->flags&CODEC_FLAG_EMU_EDGE)){ | 284 if(!(s->flags&CODEC_FLAG_EMU_EDGE)){ |
| 285 w+= EDGE_WIDTH*2; | 285 w+= EDGE_WIDTH*2; |
| 286 h+= EDGE_WIDTH*2; | 286 h+= EDGE_WIDTH*2; |
| 287 } | 287 } |
| 288 | 288 |
| 289 do { | 289 do { |
| 290 // NOTE: do not align linesizes individually, this breaks e.g. assum
ptions | 290 // NOTE: do not align linesizes individually, this breaks e.g. assum
ptions |
| 291 // that linesize[0] == 2*linesize[1] in the MPEG-encoder for 4:2:2 | 291 // that linesize[0] == 2*linesize[1] in the MPEG-encoder for 4:2:2 |
| 292 av_fill_image_linesizes(picture.linesize, s->pix_fmt, w); | 292 av_image_fill_linesizes(picture.linesize, s->pix_fmt, w); |
| 293 // increase alignment of w for next try (rhs gives the lowest bit se
t in w) | 293 // increase alignment of w for next try (rhs gives the lowest bit se
t in w) |
| 294 w += w & ~(w-1); | 294 w += w & ~(w-1); |
| 295 | 295 |
| 296 unaligned = 0; | 296 unaligned = 0; |
| 297 for (i=0; i<4; i++){ | 297 for (i=0; i<4; i++){ |
| 298 unaligned |= picture.linesize[i] % stride_align[i]; | 298 unaligned |= picture.linesize[i] % stride_align[i]; |
| 299 } | 299 } |
| 300 } while (unaligned); | 300 } while (unaligned); |
| 301 | 301 |
| 302 tmpsize = av_fill_image_pointers(picture.data, s->pix_fmt, h, NULL, pict
ure.linesize); | 302 tmpsize = av_image_fill_pointers(picture.data, s->pix_fmt, h, NULL, pict
ure.linesize); |
| 303 if (tmpsize < 0) | 303 if (tmpsize < 0) |
| 304 return -1; | 304 return -1; |
| 305 | 305 |
| 306 for (i=0; i<3 && picture.data[i+1]; i++) | 306 for (i=0; i<3 && picture.data[i+1]; i++) |
| 307 size[i] = picture.data[i+1] - picture.data[i]; | 307 size[i] = picture.data[i+1] - picture.data[i]; |
| 308 size[i] = tmpsize - (picture.data[i] - picture.data[0]); | 308 size[i] = tmpsize - (picture.data[i] - picture.data[0]); |
| 309 | 309 |
| 310 buf->last_pic_num= -256*256*256*64; | 310 buf->last_pic_num= -256*256*256*64; |
| 311 memset(buf->base, 0, sizeof(buf->base)); | 311 memset(buf->base, 0, sizeof(buf->base)); |
| 312 memset(buf->data, 0, sizeof(buf->data)); | 312 memset(buf->data, 0, sizeof(buf->data)); |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 avctx->priv_data = NULL; | 488 avctx->priv_data = NULL; |
| 489 } | 489 } |
| 490 | 490 |
| 491 if(avctx->coded_width && avctx->coded_height) | 491 if(avctx->coded_width && avctx->coded_height) |
| 492 avcodec_set_dimensions(avctx, avctx->coded_width, avctx->coded_height); | 492 avcodec_set_dimensions(avctx, avctx->coded_width, avctx->coded_height); |
| 493 else if(avctx->width && avctx->height) | 493 else if(avctx->width && avctx->height) |
| 494 avcodec_set_dimensions(avctx, avctx->width, avctx->height); | 494 avcodec_set_dimensions(avctx, avctx->width, avctx->height); |
| 495 | 495 |
| 496 #define SANE_NB_CHANNELS 128U | 496 #define SANE_NB_CHANNELS 128U |
| 497 if (((avctx->coded_width || avctx->coded_height) | 497 if (((avctx->coded_width || avctx->coded_height) |
| 498 && av_check_image_size(avctx->coded_width, avctx->coded_height, 0, avctx
)) | 498 && av_image_check_size(avctx->coded_width, avctx->coded_height, 0, avctx
)) |
| 499 || avctx->channels > SANE_NB_CHANNELS) { | 499 || avctx->channels > SANE_NB_CHANNELS) { |
| 500 ret = AVERROR(EINVAL); | 500 ret = AVERROR(EINVAL); |
| 501 goto free_and_end; | 501 goto free_and_end; |
| 502 } | 502 } |
| 503 | 503 |
| 504 avctx->codec = codec; | 504 avctx->codec = codec; |
| 505 if ((avctx->codec_type == AVMEDIA_TYPE_UNKNOWN || avctx->codec_type == codec
->type) && | 505 if ((avctx->codec_type == AVMEDIA_TYPE_UNKNOWN || avctx->codec_type == codec
->type) && |
| 506 avctx->codec_id == CODEC_ID_NONE) { | 506 avctx->codec_id == CODEC_ID_NONE) { |
| 507 avctx->codec_type = codec->type; | 507 avctx->codec_type = codec->type; |
| 508 avctx->codec_id = codec->id; | 508 avctx->codec_id = codec->id; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 return 0; | 565 return 0; |
| 566 } | 566 } |
| 567 | 567 |
| 568 int attribute_align_arg avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf
, int buf_size, | 568 int attribute_align_arg avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf
, int buf_size, |
| 569 const AVFrame *pict) | 569 const AVFrame *pict) |
| 570 { | 570 { |
| 571 if(buf_size < FF_MIN_BUFFER_SIZE){ | 571 if(buf_size < FF_MIN_BUFFER_SIZE){ |
| 572 av_log(avctx, AV_LOG_ERROR, "buffer smaller than minimum size\n"); | 572 av_log(avctx, AV_LOG_ERROR, "buffer smaller than minimum size\n"); |
| 573 return -1; | 573 return -1; |
| 574 } | 574 } |
| 575 if(av_check_image_size(avctx->width, avctx->height, 0, avctx)) | 575 if(av_image_check_size(avctx->width, avctx->height, 0, avctx)) |
| 576 return -1; | 576 return -1; |
| 577 if((avctx->codec->capabilities & CODEC_CAP_DELAY) || pict){ | 577 if((avctx->codec->capabilities & CODEC_CAP_DELAY) || pict){ |
| 578 int ret = avctx->codec->encode(avctx, buf, buf_size, pict); | 578 int ret = avctx->codec->encode(avctx, buf, buf_size, pict); |
| 579 avctx->frame_number++; | 579 avctx->frame_number++; |
| 580 emms_c(); //needed to avoid an emms_c() call before every return; | 580 emms_c(); //needed to avoid an emms_c() call before every return; |
| 581 | 581 |
| 582 return ret; | 582 return ret; |
| 583 }else | 583 }else |
| 584 return 0; | 584 return 0; |
| 585 } | 585 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 616 #endif | 616 #endif |
| 617 | 617 |
| 618 int attribute_align_arg avcodec_decode_video2(AVCodecContext *avctx, AVFrame *pi
cture, | 618 int attribute_align_arg avcodec_decode_video2(AVCodecContext *avctx, AVFrame *pi
cture, |
| 619 int *got_picture_ptr, | 619 int *got_picture_ptr, |
| 620 AVPacket *avpkt) | 620 AVPacket *avpkt) |
| 621 { | 621 { |
| 622 int ret; | 622 int ret; |
| 623 int threaded = avctx->active_thread_type&FF_THREAD_FRAME; | 623 int threaded = avctx->active_thread_type&FF_THREAD_FRAME; |
| 624 | 624 |
| 625 *got_picture_ptr= 0; | 625 *got_picture_ptr= 0; |
| 626 if((avctx->coded_width||avctx->coded_height) && av_check_image_size(avctx->c
oded_width, avctx->coded_height, 0, avctx)) | 626 if((avctx->coded_width||avctx->coded_height) && av_image_check_size(avctx->c
oded_width, avctx->coded_height, 0, avctx)) |
| 627 return -1; | 627 return -1; |
| 628 if((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size || threaded
){ | 628 if((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size || threaded
){ |
| 629 if (HAVE_PTHREADS && threaded) ret = ff_thread_decode_frame(avctx, pictu
re, | 629 if (HAVE_PTHREADS && threaded) ret = ff_thread_decode_frame(avctx, pictu
re, |
| 630 got_picture_ptr, avpkt); | 630 got_picture_ptr, avpkt); |
| 631 else ret = avctx->codec->decode(avctx, picture, got_picture_ptr, | 631 else ret = avctx->codec->decode(avctx, picture, got_picture_ptr, |
| 632 avpkt); | 632 avpkt); |
| 633 | 633 |
| 634 emms_c(); //needed to avoid an emms_c() call before every return; | 634 emms_c(); //needed to avoid an emms_c() call before every return; |
| 635 | 635 |
| 636 if (*got_picture_ptr) | 636 if (*got_picture_ptr) |
| (...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1231 | 1231 |
| 1232 void ff_thread_await_progress(AVFrame *f, int progress, int field) | 1232 void ff_thread_await_progress(AVFrame *f, int progress, int field) |
| 1233 { | 1233 { |
| 1234 } | 1234 } |
| 1235 | 1235 |
| 1236 void ff_thread_finish_frame(AVFrame *f) | 1236 void ff_thread_finish_frame(AVFrame *f) |
| 1237 { | 1237 { |
| 1238 } | 1238 } |
| 1239 | 1239 |
| 1240 #endif | 1240 #endif |
| OLD | NEW |