Advertisement
Guest User

sherpa-ffmpeg-patch

a guest
Apr 29th, 2013
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.06 KB | None | 0 0
  1. diff --git a/libavcodec/j2kdec.c b/libavcodec/j2kdec.c
  2. index 683062d..3e78b0b 100644
  3. --- a/libavcodec/j2kdec.c
  4. +++ b/libavcodec/j2kdec.c
  5. @@ -30,6 +30,7 @@
  6.  #include "avcodec.h"
  7.  #include "bytestream.h"
  8.  #include "internal.h"
  9. +#include "thread.h"
  10.  #include "j2k.h"
  11.  #include "libavutil/common.h"
  12.  
  13. @@ -205,6 +206,7 @@ static int tag_tree_decode(J2kDecoderContext *s, J2kTgtNode *node, int threshold
  14.  static int get_siz(J2kDecoderContext *s)
  15.  {
  16.      int i, ret;
  17. +    ThreadFrame frame = { .f = s->picture };
  18.  
  19.      if (bytestream2_get_bytes_left(&s->g) < 36)
  20.          return AVERROR(EINVAL);
  21. @@ -282,7 +284,7 @@ static int get_siz(J2kDecoderContext *s)
  22.      }
  23.  
  24.  
  25. -    if ((ret = ff_get_buffer(s->avctx, s->picture, 0)) < 0)
  26. +    if ((ret = ff_thread_get_buffer(s->avctx, &frame, 0)) < 0)
  27.          return ret;
  28.  
  29.      s->picture->pict_type = AV_PICTURE_TYPE_I;
  30. @@ -1088,6 +1090,6 @@ AVCodec ff_j2k_decoder = {
  31.      .priv_data_size = sizeof(J2kDecoderContext),
  32.      .init           = j2kdec_init,
  33.      .decode         = decode_frame,
  34. -    .capabilities   = CODEC_CAP_EXPERIMENTAL,
  35. +    .capabilities   = CODEC_CAP_EXPERIMENTAL | CODEC_CAP_FRAME_THREADS,
  36.      .long_name      = NULL_IF_CONFIG_SMALL("JPEG 2000"),
  37.  };
  38. diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c
  39. index 20e5c9c..7b902fa 100644
  40. --- a/libavcodec/jpeg2000dec.c
  41. +++ b/libavcodec/jpeg2000dec.c
  42. @@ -86,9 +86,6 @@ typedef struct Jpeg2000DecoderContext {
  43.      int16_t         curtileno;
  44.      Jpeg2000Tile    *tile;
  45.  
  46. -    /*options parameters*/
  47. -    int16_t         lowres;
  48. -    int16_t         reduction_factor;
  49.  } Jpeg2000DecoderContext;
  50.  
  51.  /* get_bits functions for JPEG2000 packet bitstream
  52. @@ -205,9 +202,9 @@ static int get_siz(Jpeg2000DecoderContext *s)
  53.  
  54.      /* compute image size with reduction factor */
  55.      s->avctx->width  = ff_jpeg2000_ceildivpow2(s->width  - s->image_offset_x,
  56. -                                               s->reduction_factor);
  57. +                                               s->avctx->lowres);
  58.      s->avctx->height = ff_jpeg2000_ceildivpow2(s->height - s->image_offset_y,
  59. -                                               s->reduction_factor);
  60. +                                               s->avctx->lowres);
  61.  
  62.      switch (s->avctx->profile) {
  63.      case FF_PROFILE_JPEG2000_DCINEMA_2K:
  64. @@ -254,10 +251,10 @@ static int get_cox(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c)
  65.      c->nreslevels = bytestream_get_byte(&s->buf) + 1; // num of resolution levels - 1
  66.  
  67.      /* compute number of resolution levels to decode */
  68. -    if (c->nreslevels < s->reduction_factor)
  69. +    if (c->nreslevels < s->avctx->lowres)
  70.          c->nreslevels2decode = 1;
  71.      else
  72. -        c->nreslevels2decode = c->nreslevels - s->reduction_factor;
  73. +        c->nreslevels2decode = c->nreslevels - s->avctx->lowres;
  74.  
  75.      c->log2_cblk_width  = bytestream_get_byte(&s->buf) + 2; // cblk width
  76.      c->log2_cblk_height = bytestream_get_byte(&s->buf) + 2; // cblk height
  77. @@ -635,7 +632,14 @@ static int jpeg2000_decode_packet(Jpeg2000DecoderContext *s,
  78.              Jpeg2000Cblk *cblk = prec->cblk + cblkno;
  79.              if (s->buf_end - s->buf < cblk->lengthinc)
  80.                  return AVERROR(EINVAL);
  81. -            bytestream_get_buffer(&s->buf, cblk->data, cblk->lengthinc);
  82. +            /* A code-block data can be empty. In that case initialize data
  83. +             * with 0xffff. */
  84. +            if (cblk->lengthinc > 0)
  85. +                bytestream_get_buffer(&s->buf, cblk->data, cblk->lengthinc);
  86. +            else {
  87. +                cblk->data[0] = 0xff;
  88. +                cblk->data[1] = 0xff;
  89. +            }
  90.              cblk->length   += cblk->lengthinc;
  91.              cblk->lengthinc = 0;
  92.          }
  93. @@ -853,12 +857,15 @@ static int decode_cblk(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *codsty,
  94.  {
  95.      int passno = cblk->npasses, pass_t = 2, bpno = cblk->nonzerobits - 1, y;
  96.  
  97. -    for (y = 0; y < height + 2; y++)
  98. -        memset(t1->flags[y], 0, (width + 2) * sizeof(width));
  99. -
  100.      for (y = 0; y < height; y++)
  101.          memset(t1->data[y], 0, width * sizeof(width));
  102.  
  103. +    /* If code-block contains no compressed data: nothing to do. */
  104. +    if (cblk->length == 0)
  105. +        return 0;
  106. +    for (y = 0; y < height + 2; y++)
  107. +        memset(t1->flags[y], 0, (width + 2) * sizeof(width));
  108. +
  109.      ff_mqc_initdec(&t1->mqc, cblk->data);
  110.      cblk->data[cblk->length]     = 0xff;
  111.      cblk->data[cblk->length + 1] = 0xff;
  112. @@ -1252,8 +1259,6 @@ static int jpeg2000_decode_frame(AVCodecContext *avctx, void *data,
  113.      s->buf_end   = s->buf_start + avpkt->size;
  114.      s->curtileno = 0; // TODO: only one tile in DCI JP2K. to implement for more tiles
  115.  
  116. -    // reduction factor, i.e number of resolution levels to skip
  117. -    s->reduction_factor = s->lowres;
  118.  
  119.      ff_jpeg2000_init_tier1_luts();
  120.  
  121. @@ -1301,12 +1306,6 @@ static int jpeg2000_decode_frame(AVCodecContext *avctx, void *data,
  122.  #define OFFSET(x) offsetof(Jpeg2000DecoderContext, x)
  123.  #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
  124.  
  125. -static const AVOption options[] = {
  126. -    { "lowres",  "Lower the decoding resolution by a power of two",
  127. -        OFFSET(lowres), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, JPEG2000_MAX_RESLEVELS - 1, VD },
  128. -    { NULL },
  129. -};
  130. -
  131.  static const AVProfile profiles[] = {
  132.      { FF_PROFILE_JPEG2000_CSTREAM_RESTRICTION_0,  "JPEG 2000 codestream restriction 0"   },
  133.      { FF_PROFILE_JPEG2000_CSTREAM_RESTRICTION_1,  "JPEG 2000 codestream restriction 1"   },
  134. @@ -1319,7 +1318,6 @@ static const AVProfile profiles[] = {
  135.  static const AVClass class = {
  136.      .class_name = "jpeg2000",
  137.      .item_name  = av_default_item_name,
  138. -    .option     = options,
  139.      .version    = LIBAVUTIL_VERSION_INT,
  140.  };
  141.  
  142. @@ -1330,6 +1328,7 @@ AVCodec ff_jpeg2000_decoder = {
  143.      .id             = AV_CODEC_ID_JPEG2000,
  144.      .capabilities   = CODEC_CAP_FRAME_THREADS,
  145.      .priv_data_size = sizeof(Jpeg2000DecoderContext),
  146. +    .max_lowres     = 31,
  147.      .decode         = jpeg2000_decode_frame,
  148.      .priv_class     = &class,
  149.      .pix_fmts       = (enum PixelFormat[]) { AV_PIX_FMT_XYZ12,
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement