diff options
author | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2021-04-25 01:43:26 +0200 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2021-05-05 13:55:42 +0200 |
commit | ae7a7dc458113e62add7c559c555efccab4f8eee (patch) | |
tree | 8a2e42687c6b157a57c4cef1599d75e72fe21c57 | |
parent | 1393c7edae338fd6fd3d53bde824646e1841ab2c (diff) | |
download | ffmpeg-ae7a7dc458113e62add7c559c555efccab4f8eee.tar.gz |
avcodec/dpxenc: Avoid copying packet data, allow user-supplied buffers
When the packet size is known in advance like here, one can avoid
an intermediate buffer for the packet data; this also makes it easy
to allow user-supplied buffers. Only one thing needed to be changed:
One can no longer use a pointer to uint16_t for the destination buffer
because its alignment is unknown.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
-rw-r--r-- | libavcodec/dpxenc.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/libavcodec/dpxenc.c b/libavcodec/dpxenc.c index a546c98ad9..fa8b7d5ddc 100644 --- a/libavcodec/dpxenc.c +++ b/libavcodec/dpxenc.c @@ -23,6 +23,7 @@ #include "libavutil/intreadwrite.h" #include "libavutil/imgutils.h" #include "avcodec.h" +#include "encode.h" #include "internal.h" typedef struct DPXContext { @@ -142,7 +143,7 @@ static void encode_gbrp10(AVCodecContext *avctx, const AVFrame *pic, uint8_t *ds } } -static void encode_gbrp12(AVCodecContext *avctx, const AVFrame *pic, uint16_t *dst) +static void encode_gbrp12(AVCodecContext *avctx, const AVFrame *pic, uint8_t *dst) { DPXContext *s = avctx->priv_data; const uint16_t *src[3] = {(uint16_t*)pic->data[0], @@ -163,11 +164,11 @@ static void encode_gbrp12(AVCodecContext *avctx, const AVFrame *pic, uint16_t *d value[2] = AV_RL16(src[1] + x) << 4; value[0] = AV_RL16(src[2] + x) << 4; } - for (i = 0; i < 3; i++) - write16(dst++, value[i]); + for (i = 0; i < 3; i++, dst += 2) + write16(dst, value[i]); } - for (i = 0; i < pad; i++) - *dst++ = 0; + for (i = 0; i < pad; i++, dst += 2) + AV_WN16(dst, 0); for (i = 0; i < 3; i++) src[i] += pic->linesize[i]/2; } @@ -196,7 +197,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, need_align = size - len; size *= avctx->height; } - if ((ret = ff_alloc_packet2(avctx, pkt, size + HEADER_SIZE, 0)) < 0) + if ((ret = ff_get_encode_buffer(avctx, pkt, size + HEADER_SIZE, 0)) < 0) return ret; buf = pkt->data; @@ -259,7 +260,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, encode_rgb48_10bit(avctx, frame, buf + HEADER_SIZE); break; case 12: - encode_gbrp12(avctx, frame, (uint16_t*)(buf + HEADER_SIZE)); + encode_gbrp12(avctx, frame, buf + HEADER_SIZE); break; default: av_log(avctx, AV_LOG_ERROR, "Unsupported bit depth: %d\n", s->bits_per_component); @@ -281,6 +282,7 @@ const AVCodec ff_dpx_encoder = { .long_name = NULL_IF_CONFIG_SMALL("DPX (Digital Picture Exchange) image"), .type = AVMEDIA_TYPE_VIDEO, .id = AV_CODEC_ID_DPX, + .capabilities = AV_CODEC_CAP_DR1, .priv_data_size = sizeof(DPXContext), .init = encode_init, .encode2 = encode_frame, |