Commit eeb9e61a authored by Aneesh Dogra's avatar Aneesh Dogra Committed by Justin Ruggles

v210enc: Use Bytestream2 functions

Signed-off-by: 's avatarJustin Ruggles <justin.ruggles@gmail.com>
parent af701d42
...@@ -55,18 +55,20 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, ...@@ -55,18 +55,20 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf,
const AVFrame *pic = data; const AVFrame *pic = data;
int aligned_width = ((avctx->width + 47) / 48) * 48; int aligned_width = ((avctx->width + 47) / 48) * 48;
int stride = aligned_width * 8 / 3; int stride = aligned_width * 8 / 3;
int line_padding = stride - ((avctx->width * 8 + 11) / 12) * 4;
int h, w; int h, w;
const uint16_t *y = (const uint16_t*)pic->data[0]; const uint16_t *y = (const uint16_t*)pic->data[0];
const uint16_t *u = (const uint16_t*)pic->data[1]; const uint16_t *u = (const uint16_t*)pic->data[1];
const uint16_t *v = (const uint16_t*)pic->data[2]; const uint16_t *v = (const uint16_t*)pic->data[2];
uint8_t *p = buf; PutByteContext p;
uint8_t *pdst = buf;
if (buf_size < avctx->height * stride) { if (buf_size < avctx->height * stride) {
av_log(avctx, AV_LOG_ERROR, "output buffer too small\n"); av_log(avctx, AV_LOG_ERROR, "output buffer too small\n");
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
} }
bytestream2_init_writer(&p, buf, buf_size);
#define CLIP(v) av_clip(v, 4, 1019) #define CLIP(v) av_clip(v, 4, 1019)
#define WRITE_PIXELS(a, b, c) \ #define WRITE_PIXELS(a, b, c) \
...@@ -74,7 +76,7 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, ...@@ -74,7 +76,7 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf,
val = CLIP(*a++); \ val = CLIP(*a++); \
val |= (CLIP(*b++) << 10) | \ val |= (CLIP(*b++) << 10) | \
(CLIP(*c++) << 20); \ (CLIP(*c++) << 20); \
bytestream_put_le32(&p, val); \ bytestream2_put_le32u(&p, val); \
} while (0) } while (0)
for (h = 0; h < avctx->height; h++) { for (h = 0; h < avctx->height; h++) {
...@@ -90,25 +92,24 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, ...@@ -90,25 +92,24 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf,
val = CLIP(*y++); val = CLIP(*y++);
if (w == avctx->width - 2) if (w == avctx->width - 2)
bytestream_put_le32(&p, val); bytestream2_put_le32u(&p, val);
} }
if (w < avctx->width - 3) { if (w < avctx->width - 3) {
val |= (CLIP(*u++) << 10) | (CLIP(*y++) << 20); val |= (CLIP(*u++) << 10) | (CLIP(*y++) << 20);
bytestream_put_le32(&p, val); bytestream2_put_le32u(&p, val);
val = CLIP(*v++) | (CLIP(*y++) << 10); val = CLIP(*v++) | (CLIP(*y++) << 10);
bytestream_put_le32(&p, val); bytestream2_put_le32u(&p, val);
} }
pdst += stride; bytestream2_set_buffer(&p, 0, line_padding);
memset(p, 0, pdst - p);
p = pdst;
y += pic->linesize[0] / 2 - avctx->width; y += pic->linesize[0] / 2 - avctx->width;
u += pic->linesize[1] / 2 - avctx->width / 2; u += pic->linesize[1] / 2 - avctx->width / 2;
v += pic->linesize[2] / 2 - avctx->width / 2; v += pic->linesize[2] / 2 - avctx->width / 2;
} }
return p - buf; return bytestream2_tell_p(&p);
} }
static av_cold int encode_close(AVCodecContext *avctx) static av_cold int encode_close(AVCodecContext *avctx)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment