Guest User

Untitled

a guest
Sep 18th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 6.48 KB | None | 0 0
  1. diff --git a/libavcodec/utvideoenc.c b/libavcodec/utvideoenc.c
  2. index 68a1a5b..988f821 100644
  3. --- a/libavcodec/utvideoenc.c
  4. +++ b/libavcodec/utvideoenc.c
  5. @@ -27,6 +27,7 @@
  6.  #include "libavutil/intreadwrite.h"
  7.  #include "avcodec.h"
  8.  #include "internal.h"
  9. +#include "bytestream.h"
  10.  #include "put_bits.h"
  11.  #include "dsputil.h"
  12.  #include "mathops.h"
  13. @@ -152,7 +153,7 @@ static av_cold int utvideo_encode_init(AVCodecContext *avctx)
  14.       * Set how many slices are going to be used.
  15.       * Set one slice for now.
  16.       */
  17. -    c->slices = 1;
  18. +    c->slices = 4;
  19.  
  20.      /* Set compression mode */
  21.      c->compression = COMP_HUFF;
  22. @@ -462,10 +463,9 @@ static int write_huff_codes(uint8_t *src, uint8_t *dst, int dst_size,
  23.  
  24.  static int encode_plane(AVCodecContext *avctx, uint8_t *src,
  25.                          uint8_t *dst, int step, int stride,
  26. -                        int width, int height, uint8_t **pkt_dst)
  27. +                        int width, int height, PutByteContext *pb)
  28.  {
  29.      UtvideoContext *c        = avctx->priv_data;
  30. -    uint8_t  *where_to_write = *pkt_dst + 256 + (c->slices * 4);
  31.      uint8_t  lengths[256];
  32.      uint32_t counts[256]     = { 0 };
  33.  
  34. @@ -522,17 +522,15 @@ static int encode_plane(AVCodecContext *avctx, uint8_t *src,
  35.                   */
  36.                  for (i = 0; i < 256; i++) {
  37.                      if (i == symbol)
  38. -                        (*pkt_dst)[i] = 0;
  39. +                        bytestream2_put_byte(pb, 0);
  40.                      else
  41. -                        (*pkt_dst)[i] = 0xFF;
  42. +                        bytestream2_put_byte(pb, 0xFF);
  43.                  }
  44. -                *pkt_dst += 256;
  45.  
  46.                  /* Write zeroes for lengths */
  47.                  for (i = 0; i < c->slices; i++) {
  48. -                    AV_WL32(*pkt_dst + (4 * i), 0);
  49. +                    bytestream2_put_le32(pb, 0);
  50.                  }
  51. -                *pkt_dst += 4 * c->slices;
  52.  
  53.                  /* And that's all for that plane folks */
  54.                  return 0;
  55. @@ -550,11 +548,10 @@ static int encode_plane(AVCodecContext *avctx, uint8_t *src,
  56.       * - slice end offsets (gotten from the slice lengths)
  57.       */
  58.      for (i = 0; i < 256; i++) {
  59. -        (*pkt_dst)[i] = lengths[i];
  60. +        bytestream2_put_byte(pb, lengths[i]);
  61.          he[i].len     = lengths[i];
  62.          he[i].sym     = i;
  63.      }
  64. -    *pkt_dst += 256;
  65.  
  66.      /* Calculate the huffman codes themselves */
  67.      calculate_codes(he);
  68. @@ -574,24 +571,29 @@ static int encode_plane(AVCodecContext *avctx, uint8_t *src,
  69.  
  70.          slice_len = offset - slice_len;
  71.  
  72. -        /* Write the offset to the stream */
  73. -        AV_WL32(*pkt_dst + (4 * i), offset);
  74. -
  75. -        /* Byteswap the written data */
  76. +        /* Byteswap the written huffman codes */
  77.          c->dsp.bswap_buf((uint32_t *) c->slice_bits,
  78.                           (uint32_t *) c->slice_bits,
  79.                           slice_len >> 2);
  80.  
  81. +        /* Write the offset to the stream */
  82. +        bytestream2_put_le32(pb, offset);
  83. +
  84. +        /* Seek to the data part of the packet */
  85. +        bytestream2_seek_p(pb, (4 * ((i + 1) - c->slices)) +
  86. +                           (offset - slice_len), SEEK_CUR);
  87. +
  88.          /* Write the slices' data into the output packet */
  89. -        memcpy(where_to_write, c->slice_bits, slice_len);
  90. +        bytestream2_put_buffer(pb, c->slice_bits, slice_len);
  91.  
  92. -        where_to_write += slice_len;
  93. +        /* Seek back to the slice offsets */
  94. +        bytestream2_seek_p(pb, (-4 * ((i + 1) - c->slices)) - offset,
  95. +                           SEEK_CUR);
  96.  
  97.          slice_len = offset;
  98.      }
  99.  
  100. -    /* Move destination pointer to the start of next plane */
  101. -    *pkt_dst += offset + (4 * c->slices);
  102. +    bytestream2_seek_p(pb, offset, SEEK_CUR);
  103.  
  104.      return 0;
  105.  }
  106. @@ -600,6 +602,7 @@ static int utvideo_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
  107.                                  const AVFrame *pic, int *got_packet)
  108.  {
  109.      UtvideoContext *c = avctx->priv_data;
  110. +    PutByteContext pb;
  111.  
  112.      uint32_t frame_info;
  113.  
  114. @@ -620,6 +623,9 @@ static int utvideo_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
  115.  
  116.      dst = pkt->data;
  117.  
  118. +    bytestream2_init_writer(&pb, dst, ((256 + (4 * c->slices) +
  119. +                            (width * height)) * c->planes));
  120. +
  121.      slice_buffer = av_malloc(width * height + FF_INPUT_BUFFER_PADDING_SIZE);
  122.  
  123.      if (!slice_buffer) {
  124. @@ -651,7 +657,7 @@ static int utvideo_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
  125.          for (i = 0; i < c->planes; i++) {
  126.              ret = encode_plane(avctx, pic->data[0] + rgb_order[i],
  127.                                 slice_buffer, c->planes, pic->linesize[0],
  128. -                               width, height, &dst);
  129. +                               width, height, &pb);
  130.  
  131.              if (ret) {
  132.                  av_log(avctx, AV_LOG_ERROR, "Error encoding plane %d.\n", i);
  133. @@ -662,7 +668,7 @@ static int utvideo_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
  134.      case PIX_FMT_YUV422P:
  135.          for (i = 0; i < c->planes; i++) {
  136.              ret = encode_plane(avctx, pic->data[i], slice_buffer, 1,
  137. -                               pic->linesize[i], width >>!! i, height, &dst);
  138. +                               pic->linesize[i], width >>!! i, height, &pb);
  139.  
  140.              if (ret) {
  141.                  av_log(avctx, AV_LOG_ERROR, "Error encoding plane %d.\n", i);
  142. @@ -674,7 +680,7 @@ static int utvideo_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
  143.          for (i = 0; i < c->planes; i++) {
  144.              ret = encode_plane(avctx, pic->data[i], slice_buffer, 1,
  145.                                 pic->linesize[i], width >>!! i, height >>!! i,
  146. -                               &dst);
  147. +                               &pb);
  148.  
  149.              if (ret) {
  150.                  av_log(avctx, AV_LOG_ERROR, "Error encoding plane %d.\n", i);
  151. @@ -694,8 +700,7 @@ static int utvideo_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
  152.       * Contains the prediction method.
  153.       */
  154.      frame_info = c->frame_pred << 8;
  155. -    AV_WL32(dst, frame_info);
  156. -    dst += 4;
  157. +    bytestream2_put_le32(&pb, frame_info);
  158.  
  159.      /*
  160.       * At least currently Ut Video is IDR only.
  161. @@ -705,7 +710,7 @@ static int utvideo_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
  162.      avctx->coded_frame->key_frame = 1;
  163.      avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
  164.  
  165. -    pkt->size   = dst - pkt->data;
  166. +    pkt->size   = bytestream2_tell_p(&pb);
  167.      pkt->flags |= AV_PKT_FLAG_KEY;
  168.  
  169.      /* Packet should be done */
Add Comment
Please, Sign In to add comment