From 3f77c41171267462b5269ef6dadc6fe591201d71 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 11 Feb 2012 19:44:05 +0100 Subject: bmpenc: switch to encode2(). --- libavcodec/bmpenc.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'libavcodec') diff --git a/libavcodec/bmpenc.c b/libavcodec/bmpenc.c index ca2951ab37..3747784183 100644 --- a/libavcodec/bmpenc.c +++ b/libavcodec/bmpenc.c @@ -24,6 +24,7 @@ #include "avcodec.h" #include "bytestream.h" #include "bmp.h" +#include "internal.h" static const uint32_t monoblack_pal[] = { 0x000000, 0xFFFFFF }; static const uint32_t rgb565_masks[] = { 0xF800, 0x07E0, 0x001F }; @@ -63,16 +64,16 @@ static av_cold int bmp_encode_init(AVCodecContext *avctx){ return 0; } -static int bmp_encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){ +static int bmp_encode_frame(AVCodecContext *avctx, AVPacket *pkt, + const AVFrame *pict, int *got_packet) +{ BMPContext *s = avctx->priv_data; - AVFrame *pict = data; AVFrame * const p= (AVFrame*)&s->picture; - int n_bytes_image, n_bytes_per_row, n_bytes, i, n, hsize; + int n_bytes_image, n_bytes_per_row, n_bytes, i, n, hsize, ret; const uint32_t *pal = NULL; int pad_bytes_per_row, pal_entries = 0, compression = BMP_RGB; int bit_count = avctx->bits_per_coded_sample; - uint8_t *ptr; - unsigned char* buf0 = buf; + uint8_t *ptr, *buf; *p = *pict; p->pict_type= AV_PICTURE_TYPE_I; p->key_frame= 1; @@ -111,10 +112,11 @@ static int bmp_encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_s #define SIZE_BITMAPINFOHEADER 40 hsize = SIZE_BITMAPFILEHEADER + SIZE_BITMAPINFOHEADER + (pal_entries << 2); n_bytes = n_bytes_image + hsize; - if(n_bytes>buf_size) { - av_log(avctx, AV_LOG_ERROR, "buf size too small (need %d, got %d)\n", n_bytes, buf_size); - return -1; + if ((ret = ff_alloc_packet(pkt, n_bytes)) < 0) { + av_log(avctx, AV_LOG_ERROR, "Error getting output packet.\n"); + return ret; } + buf = pkt->data; bytestream_put_byte(&buf, 'B'); // BITMAPFILEHEADER.bfType bytestream_put_byte(&buf, 'M'); // do. bytestream_put_le32(&buf, n_bytes); // BITMAPFILEHEADER.bfSize @@ -136,7 +138,7 @@ static int bmp_encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_s bytestream_put_le32(&buf, pal[i] & 0xFFFFFF); // BMP files are bottom-to-top so we start from the end... ptr = p->data[0] + (avctx->height - 1) * p->linesize[0]; - buf = buf0 + hsize; + buf = pkt->data + hsize; for(i = 0; i < avctx->height; i++) { if (bit_count == 16) { const uint16_t *src = (const uint16_t *) ptr; @@ -151,7 +153,10 @@ static int bmp_encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_s buf += pad_bytes_per_row; ptr -= p->linesize[0]; // ... and go back } - return n_bytes; + + pkt->flags |= AV_PKT_FLAG_KEY; + *got_packet = 1; + return 0; } AVCodec ff_bmp_encoder = { @@ -160,7 +165,7 @@ AVCodec ff_bmp_encoder = { .id = CODEC_ID_BMP, .priv_data_size = sizeof(BMPContext), .init = bmp_encode_init, - .encode = bmp_encode_frame, + .encode2 = bmp_encode_frame, .pix_fmts = (const enum PixelFormat[]){ PIX_FMT_BGR24, PIX_FMT_RGB555, PIX_FMT_RGB444, PIX_FMT_RGB565, -- cgit v1.2.3 From 89829242a633789fa614ec7ca9ffb912b5f02765 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 11 Feb 2012 20:03:42 +0100 Subject: dnxhdenc: switch to encode2. --- libavcodec/dnxhdenc.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'libavcodec') diff --git a/libavcodec/dnxhdenc.c b/libavcodec/dnxhdenc.c index 2b7089b946..322151324c 100644 --- a/libavcodec/dnxhdenc.c +++ b/libavcodec/dnxhdenc.c @@ -29,6 +29,7 @@ #include "libavutil/opt.h" #include "avcodec.h" #include "dsputil.h" +#include "internal.h" #include "mpegvideo.h" #include "mpegvideo_common.h" #include "dnxhdenc.h" @@ -903,18 +904,21 @@ static void dnxhd_load_picture(DNXHDEncContext *ctx, const AVFrame *frame) ctx->cur_field = frame->interlaced_frame && !frame->top_field_first; } -static int dnxhd_encode_picture(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data) +static int dnxhd_encode_picture(AVCodecContext *avctx, AVPacket *pkt, + const AVFrame *frame, int *got_packet) { DNXHDEncContext *ctx = avctx->priv_data; int first_field = 1; int offset, i, ret; + uint8_t *buf; - if (buf_size < ctx->cid_table->frame_size) { + if ((ret = ff_alloc_packet(pkt, ctx->cid_table->frame_size)) < 0) { av_log(avctx, AV_LOG_ERROR, "output buffer is too small to compress picture\n"); - return -1; + return ret; } + buf = pkt->data; - dnxhd_load_picture(ctx, data); + dnxhd_load_picture(ctx, frame); encode_coding_unit: for (i = 0; i < 3; i++) { @@ -955,13 +959,14 @@ static int dnxhd_encode_picture(AVCodecContext *avctx, unsigned char *buf, int b first_field = 0; ctx->cur_field ^= 1; buf += ctx->cid_table->coding_unit_size; - buf_size -= ctx->cid_table->coding_unit_size; goto encode_coding_unit; } ctx->frame.quality = ctx->qscale*FF_QP2LAMBDA; - return ctx->cid_table->frame_size; + pkt->flags |= AV_PKT_FLAG_KEY; + *got_packet = 1; + return 0; } static int dnxhd_encode_end(AVCodecContext *avctx) @@ -999,7 +1004,7 @@ AVCodec ff_dnxhd_encoder = { .id = CODEC_ID_DNXHD, .priv_data_size = sizeof(DNXHDEncContext), .init = dnxhd_encode_init, - .encode = dnxhd_encode_picture, + .encode2 = dnxhd_encode_picture, .close = dnxhd_encode_end, .capabilities = CODEC_CAP_SLICE_THREADS, .pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUV422P, PIX_FMT_YUV422P10, PIX_FMT_NONE}, -- cgit v1.2.3 From 177bb4bf50d762fcc1ace3e357a2a2bba54744ee Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 11 Feb 2012 20:37:41 +0100 Subject: cljr: set the properties of the coded_frame, not input frame. --- libavcodec/cljr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libavcodec') diff --git a/libavcodec/cljr.c b/libavcodec/cljr.c index cf307bb06a..a3bb66c500 100644 --- a/libavcodec/cljr.c +++ b/libavcodec/cljr.c @@ -135,8 +135,8 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, AVFrame *p = data; int x, y; - p->pict_type = AV_PICTURE_TYPE_I; - p->key_frame = 1; + avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I; + avctx->coded_frame->key_frame = 1; init_put_bits(&pb, buf, buf_size / 8); -- cgit v1.2.3 From 3dffa1b46c6a03c2f58d88da2b83f1a467575a72 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 11 Feb 2012 20:39:12 +0100 Subject: cljr: implement encode2. --- libavcodec/cljr.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'libavcodec') diff --git a/libavcodec/cljr.c b/libavcodec/cljr.c index a3bb66c500..40d8a4c449 100644 --- a/libavcodec/cljr.c +++ b/libavcodec/cljr.c @@ -26,6 +26,7 @@ #include "avcodec.h" #include "get_bits.h" +#include "internal.h" #include "put_bits.h" typedef struct CLJRContext { @@ -128,17 +129,21 @@ AVCodec ff_cljr_decoder = { #endif #if CONFIG_CLJR_ENCODER -static int encode_frame(AVCodecContext *avctx, unsigned char *buf, - int buf_size, void *data) +static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, + const AVFrame *p, int *got_packet) { PutBitContext pb; - AVFrame *p = data; - int x, y; + int x, y, ret; + + if ((ret = ff_alloc_packet(pkt, 32*avctx->height*avctx->width/4)) < 0) { + av_log(avctx, AV_LOG_ERROR, "Error getting output packet.\n"); + return ret; + } avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I; avctx->coded_frame->key_frame = 1; - init_put_bits(&pb, buf, buf_size / 8); + init_put_bits(&pb, pkt->data, pkt->size); for (y = 0; y < avctx->height; y++) { uint8_t *luma = &p->data[0][y * p->linesize[0]]; @@ -157,7 +162,10 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, flush_put_bits(&pb); - return put_bits_count(&pb) / 8; + pkt->size = put_bits_count(&pb) / 8; + pkt->flags |= AV_PKT_FLAG_KEY; + *got_packet = 1; + return 0; } AVCodec ff_cljr_encoder = { @@ -166,7 +174,7 @@ AVCodec ff_cljr_encoder = { .id = CODEC_ID_CLJR, .priv_data_size = sizeof(CLJRContext), .init = common_init, - .encode = encode_frame, + .encode2 = encode_frame, .pix_fmts = (const enum PixelFormat[]) { PIX_FMT_YUV411P, PIX_FMT_NONE }, .long_name = NULL_IF_CONFIG_SMALL("Cirrus Logic AccuPak"), -- cgit v1.2.3