diff options
author | Anton Khirnov <anton@khirnov.net> | 2012-02-20 08:01:48 +0100 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2012-02-21 22:47:01 +0100 |
commit | 5d42ac7ffb5471666136402a553454caf3a3c989 (patch) | |
tree | c05dd44e30736d4a05f1581a92e8a78a163f0ff2 /libavcodec/mpegvideo_enc.c | |
parent | b38b6d56ca5a0796d9b48fdaef14c5950c3abac5 (diff) | |
download | ffmpeg-5d42ac7ffb5471666136402a553454caf3a3c989.tar.gz |
mpegvideo_enc: only allocate output packet when we know there will be output
Fixes a memleak.
Diffstat (limited to 'libavcodec/mpegvideo_enc.c')
-rw-r--r-- | libavcodec/mpegvideo_enc.c | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 68adef7992..6f4df59517 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -1384,20 +1384,6 @@ int ff_MPV_encode_picture(AVCodecContext *avctx, AVPacket *pkt, int i, stuffing_count, ret; int context_count = s->slice_context_count; - if (!pkt->data && - (ret = ff_alloc_packet(pkt, s->mb_width*s->mb_height*MAX_MB_BYTES)) < 0) - return ret; - - for (i = 0; i < context_count; i++) { - int start_y = s->thread_context[i]->start_mb_y; - int end_y = s->thread_context[i]-> end_mb_y; - int h = s->mb_height; - uint8_t *start = pkt->data + (size_t)(((int64_t) pkt->size) * start_y / h); - uint8_t *end = pkt->data + (size_t)(((int64_t) pkt->size) * end_y / h); - - init_put_bits(&s->thread_context[i]->pb, start, end - start); - } - s->picture_in_gop_number++; if (load_input_picture(s, pic_arg) < 0) @@ -1409,6 +1395,20 @@ int ff_MPV_encode_picture(AVCodecContext *avctx, AVPacket *pkt, /* output? */ if (s->new_picture.f.data[0]) { + if (!pkt->data && + (ret = ff_alloc_packet(pkt, s->mb_width*s->mb_height*MAX_MB_BYTES)) < 0) + return ret; + + for (i = 0; i < context_count; i++) { + int start_y = s->thread_context[i]->start_mb_y; + int end_y = s->thread_context[i]-> end_mb_y; + int h = s->mb_height; + uint8_t *start = pkt->data + (size_t)(((int64_t) pkt->size) * start_y / h); + uint8_t *end = pkt->data + (size_t)(((int64_t) pkt->size) * end_y / h); + + init_put_bits(&s->thread_context[i]->pb, start, end - start); + } + s->pict_type = s->new_picture.f.pict_type; //emms_c(); //printf("qs:%f %f %d\n", s->new_picture.quality, |