Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/libavcodec/utvideoenc.c b/libavcodec/utvideoenc.c
- index 68a1a5b..988f821 100644
- --- a/libavcodec/utvideoenc.c
- +++ b/libavcodec/utvideoenc.c
- @@ -27,6 +27,7 @@
- #include "libavutil/intreadwrite.h"
- #include "avcodec.h"
- #include "internal.h"
- +#include "bytestream.h"
- #include "put_bits.h"
- #include "dsputil.h"
- #include "mathops.h"
- @@ -152,7 +153,7 @@ static av_cold int utvideo_encode_init(AVCodecContext *avctx)
- * Set how many slices are going to be used.
- * Set one slice for now.
- */
- - c->slices = 1;
- + c->slices = 4;
- /* Set compression mode */
- c->compression = COMP_HUFF;
- @@ -462,10 +463,9 @@ static int write_huff_codes(uint8_t *src, uint8_t *dst, int dst_size,
- static int encode_plane(AVCodecContext *avctx, uint8_t *src,
- uint8_t *dst, int step, int stride,
- - int width, int height, uint8_t **pkt_dst)
- + int width, int height, PutByteContext *pb)
- {
- UtvideoContext *c = avctx->priv_data;
- - uint8_t *where_to_write = *pkt_dst + 256 + (c->slices * 4);
- uint8_t lengths[256];
- uint32_t counts[256] = { 0 };
- @@ -522,17 +522,15 @@ static int encode_plane(AVCodecContext *avctx, uint8_t *src,
- */
- for (i = 0; i < 256; i++) {
- if (i == symbol)
- - (*pkt_dst)[i] = 0;
- + bytestream2_put_byte(pb, 0);
- else
- - (*pkt_dst)[i] = 0xFF;
- + bytestream2_put_byte(pb, 0xFF);
- }
- - *pkt_dst += 256;
- /* Write zeroes for lengths */
- for (i = 0; i < c->slices; i++) {
- - AV_WL32(*pkt_dst + (4 * i), 0);
- + bytestream2_put_le32(pb, 0);
- }
- - *pkt_dst += 4 * c->slices;
- /* And that's all for that plane folks */
- return 0;
- @@ -550,11 +548,10 @@ static int encode_plane(AVCodecContext *avctx, uint8_t *src,
- * - slice end offsets (gotten from the slice lengths)
- */
- for (i = 0; i < 256; i++) {
- - (*pkt_dst)[i] = lengths[i];
- + bytestream2_put_byte(pb, lengths[i]);
- he[i].len = lengths[i];
- he[i].sym = i;
- }
- - *pkt_dst += 256;
- /* Calculate the huffman codes themselves */
- calculate_codes(he);
- @@ -574,24 +571,29 @@ static int encode_plane(AVCodecContext *avctx, uint8_t *src,
- slice_len = offset - slice_len;
- - /* Write the offset to the stream */
- - AV_WL32(*pkt_dst + (4 * i), offset);
- -
- - /* Byteswap the written data */
- + /* Byteswap the written huffman codes */
- c->dsp.bswap_buf((uint32_t *) c->slice_bits,
- (uint32_t *) c->slice_bits,
- slice_len >> 2);
- + /* Write the offset to the stream */
- + bytestream2_put_le32(pb, offset);
- +
- + /* Seek to the data part of the packet */
- + bytestream2_seek_p(pb, (4 * ((i + 1) - c->slices)) +
- + (offset - slice_len), SEEK_CUR);
- +
- /* Write the slices' data into the output packet */
- - memcpy(where_to_write, c->slice_bits, slice_len);
- + bytestream2_put_buffer(pb, c->slice_bits, slice_len);
- - where_to_write += slice_len;
- + /* Seek back to the slice offsets */
- + bytestream2_seek_p(pb, (-4 * ((i + 1) - c->slices)) - offset,
- + SEEK_CUR);
- slice_len = offset;
- }
- - /* Move destination pointer to the start of next plane */
- - *pkt_dst += offset + (4 * c->slices);
- + bytestream2_seek_p(pb, offset, SEEK_CUR);
- return 0;
- }
- @@ -600,6 +602,7 @@ static int utvideo_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
- const AVFrame *pic, int *got_packet)
- {
- UtvideoContext *c = avctx->priv_data;
- + PutByteContext pb;
- uint32_t frame_info;
- @@ -620,6 +623,9 @@ static int utvideo_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
- dst = pkt->data;
- + bytestream2_init_writer(&pb, dst, ((256 + (4 * c->slices) +
- + (width * height)) * c->planes));
- +
- slice_buffer = av_malloc(width * height + FF_INPUT_BUFFER_PADDING_SIZE);
- if (!slice_buffer) {
- @@ -651,7 +657,7 @@ static int utvideo_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
- for (i = 0; i < c->planes; i++) {
- ret = encode_plane(avctx, pic->data[0] + rgb_order[i],
- slice_buffer, c->planes, pic->linesize[0],
- - width, height, &dst);
- + width, height, &pb);
- if (ret) {
- av_log(avctx, AV_LOG_ERROR, "Error encoding plane %d.\n", i);
- @@ -662,7 +668,7 @@ static int utvideo_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
- case PIX_FMT_YUV422P:
- for (i = 0; i < c->planes; i++) {
- ret = encode_plane(avctx, pic->data[i], slice_buffer, 1,
- - pic->linesize[i], width >>!! i, height, &dst);
- + pic->linesize[i], width >>!! i, height, &pb);
- if (ret) {
- av_log(avctx, AV_LOG_ERROR, "Error encoding plane %d.\n", i);
- @@ -674,7 +680,7 @@ static int utvideo_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
- for (i = 0; i < c->planes; i++) {
- ret = encode_plane(avctx, pic->data[i], slice_buffer, 1,
- pic->linesize[i], width >>!! i, height >>!! i,
- - &dst);
- + &pb);
- if (ret) {
- av_log(avctx, AV_LOG_ERROR, "Error encoding plane %d.\n", i);
- @@ -694,8 +700,7 @@ static int utvideo_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
- * Contains the prediction method.
- */
- frame_info = c->frame_pred << 8;
- - AV_WL32(dst, frame_info);
- - dst += 4;
- + bytestream2_put_le32(&pb, frame_info);
- /*
- * At least currently Ut Video is IDR only.
- @@ -705,7 +710,7 @@ static int utvideo_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
- avctx->coded_frame->key_frame = 1;
- avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
- - pkt->size = dst - pkt->data;
- + pkt->size = bytestream2_tell_p(&pb);
- pkt->flags |= AV_PKT_FLAG_KEY;
- /* Packet should be done */
Add Comment
Please, Sign In to add comment