diff mbox series

[FFmpeg-devel] avcodec/jpeg2000:fast-fail if HTJ2K codeblocks are present

Message ID 20220419081701.8021-1-etemesicaleb@gmail.com
State New
Headers show
Series [FFmpeg-devel] avcodec/jpeg2000:fast-fail if HTJ2K codeblocks are present | expand

Checks

Context Check Description
yinshiyou/commit_msg_loongarch64 warning The first line of the commit message must start with a context terminated by a colon and a space, for example "lavu/opt: " or "doc: ".
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/commit_msg_x86 warning The first line of the commit message must start with a context terminated by a colon and a space, for example "lavu/opt: " or "doc: ".
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/commit_msg_armv7_RPi4 warning The first line of the commit message must start with a context terminated by a colon and a space, for example "lavu/opt: " or "doc: ".
andriy/make_armv7_RPi4 success Make finished
andriy/make_fate_armv7_RPi4 success Make fate finished

Commit Message

caleb April 19, 2022, 8:17 a.m. UTC
---
This patch adds support for detecting Part 15 codeblocks to JPEG2000 specified in (Rec. ITU-T T.814 | ISO/IEC 15444-15).

The decoder on detecting Part 15 codeblocks now fails gracefully with a AVERROR_PATCHWELCOME return code

 libavcodec/jpeg2000.h    | 2 ++
 libavcodec/jpeg2000dec.c | 9 +++++++++
 2 files changed, 11 insertions(+)

Comments

Pierre-Anthony Lemieux April 19, 2022, 8:52 p.m. UTC | #1
FYI. This is the qualification task for the GSOC project at [1].

[1] https://trac.ffmpeg.org/wiki/SponsoringPrograms/GSoC/2022#AddsupportforPart15totheJPEG2000decoder

On Tue, Apr 19, 2022 at 1:17 AM caleb <etemesicaleb@gmail.com> wrote:
>
> ---
> This patch adds support for detecting Part 15 codeblocks to JPEG2000 specified in (Rec. ITU-T T.814 | ISO/IEC 15444-15).
>
> The decoder on detecting Part 15 codeblocks now fails gracefully with a AVERROR_PATCHWELCOME return code
>
>  libavcodec/jpeg2000.h    | 2 ++
>  libavcodec/jpeg2000dec.c | 9 +++++++++
>  2 files changed, 11 insertions(+)
>
> diff --git a/libavcodec/jpeg2000.h b/libavcodec/jpeg2000.h
> index d06313425e..e5ecb4cbf9 100644
> --- a/libavcodec/jpeg2000.h
> +++ b/libavcodec/jpeg2000.h
> @@ -110,6 +110,8 @@ enum Jpeg2000Quantsty { // quantization style
>  #define JPEG2000_CSTY_PREC      0x01 // Precincts defined in coding style
>  #define JPEG2000_CSTY_SOP       0x02 // SOP marker present
>  #define JPEG2000_CSTY_EPH       0x04 // EPH marker present
> +#define JPEG2000_CTSY_HTJ2K_F   0x40 // Only HT code-blocks (Rec. ITU-T T.814 | ISO/IEC 15444-15) are present
> +#define JPEG2000_CTSY_HTJ2K_M   0xC0 // HT code blocks (Rec. ITU-T T.814 | ISO/IEC 15444-15) can be present
>
>  // Progression orders
>  #define JPEG2000_PGOD_LRCP      0x00  // Layer-resolution level-component-position progression
> diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c
> index 92966b11f5..ef4a653afe 100644
> --- a/libavcodec/jpeg2000dec.c
> +++ b/libavcodec/jpeg2000dec.c
> @@ -521,6 +521,15 @@ static int get_cox(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c)
>
>      c->cblk_style = bytestream2_get_byteu(&s->g);
>      if (c->cblk_style != 0) { // cblk style
> +        if (c->cblk_style & JPEG2000_CTSY_HTJ2K_M || c->cblk_style & JPEG2000_CTSY_HTJ2K_F) {
> +            /*
> +             * HT code-blocks (Rec. ITU-T T.814 | ISO/IEC 15444-15) bit-stream
> +             * Not yet supported in ffmpeg, cannot continue.
> +             */
> +            av_log(s->avctx, AV_LOG_FATAL, "Support for High throughput JPEG 2000 is not yet available\n");
> +            return AVERROR_PATCHWELCOME;
> +        }
> +
>          av_log(s->avctx, AV_LOG_WARNING, "extra cblk styles %X\n", c->cblk_style);
>          if (c->cblk_style & JPEG2000_CBLK_BYPASS)
>              av_log(s->avctx, AV_LOG_WARNING, "Selective arithmetic coding bypass\n");
> --
> 2.34.0
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Pierre-Anthony Lemieux May 4, 2022, 4:23 a.m. UTC | #2
Hi Caleb,

There is a space missing in the commit message before "fast-fail".

Few minor comments below.

Looks good otherwise -- it works as expected on an MXF file that
contains JPEG 2000 Part 15 code-blocks.

Looking forward to the full implementation!

Best,

-- Pierre

On Tue, Apr 19, 2022 at 1:17 AM caleb <etemesicaleb@gmail.com> wrote:
>
> ---
> This patch adds support for detecting Part 15 codeblocks to JPEG2000 specified in (Rec. ITU-T T.814 | ISO/IEC 15444-15).
>
> The decoder on detecting Part 15 codeblocks now fails gracefully with a AVERROR_PATCHWELCOME return code
>
>  libavcodec/jpeg2000.h    | 2 ++
>  libavcodec/jpeg2000dec.c | 9 +++++++++
>  2 files changed, 11 insertions(+)
>
> diff --git a/libavcodec/jpeg2000.h b/libavcodec/jpeg2000.h
> index d06313425e..e5ecb4cbf9 100644
> --- a/libavcodec/jpeg2000.h
> +++ b/libavcodec/jpeg2000.h
> @@ -110,6 +110,8 @@ enum Jpeg2000Quantsty { // quantization style
>  #define JPEG2000_CSTY_PREC      0x01 // Precincts defined in coding style
>  #define JPEG2000_CSTY_SOP       0x02 // SOP marker present
>  #define JPEG2000_CSTY_EPH       0x04 // EPH marker present
> +#define JPEG2000_CTSY_HTJ2K_F   0x40 // Only HT code-blocks (Rec. ITU-T T.814 | ISO/IEC 15444-15) are present
> +#define JPEG2000_CTSY_HTJ2K_M   0xC0 // HT code blocks (Rec. ITU-T T.814 | ISO/IEC 15444-15) can be present
>
>  // Progression orders
>  #define JPEG2000_PGOD_LRCP      0x00  // Layer-resolution level-component-position progression
> diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c
> index 92966b11f5..ef4a653afe 100644
> --- a/libavcodec/jpeg2000dec.c
> +++ b/libavcodec/jpeg2000dec.c
> @@ -521,6 +521,15 @@ static int get_cox(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c)
>
>      c->cblk_style = bytestream2_get_byteu(&s->g);
>      if (c->cblk_style != 0) { // cblk style
> +        if (c->cblk_style & JPEG2000_CTSY_HTJ2K_M || c->cblk_style & JPEG2000_CTSY_HTJ2K_F) {
> +            /*
> +             * HT code-blocks (Rec. ITU-T T.814 | ISO/IEC 15444-15) bit-stream
> +             * Not yet supported in ffmpeg, cannot continue.

The comment above can be removed since the av_log and return code are
sufficiently descriptive.

> +             */
> +            av_log(s->avctx, AV_LOG_FATAL, "Support for High throughput JPEG 2000 is not yet available\n");

That should probably be AV_LOG_ERROR.

> +            return AVERROR_PATCHWELCOME;
> +        }
> +
>          av_log(s->avctx, AV_LOG_WARNING, "extra cblk styles %X\n", c->cblk_style);
>          if (c->cblk_style & JPEG2000_CBLK_BYPASS)
>              av_log(s->avctx, AV_LOG_WARNING, "Selective arithmetic coding bypass\n");
> --
> 2.34.0
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
diff mbox series

Patch

diff --git a/libavcodec/jpeg2000.h b/libavcodec/jpeg2000.h
index d06313425e..e5ecb4cbf9 100644
--- a/libavcodec/jpeg2000.h
+++ b/libavcodec/jpeg2000.h
@@ -110,6 +110,8 @@  enum Jpeg2000Quantsty { // quantization style
 #define JPEG2000_CSTY_PREC      0x01 // Precincts defined in coding style
 #define JPEG2000_CSTY_SOP       0x02 // SOP marker present
 #define JPEG2000_CSTY_EPH       0x04 // EPH marker present
+#define JPEG2000_CTSY_HTJ2K_F   0x40 // Only HT code-blocks (Rec. ITU-T T.814 | ISO/IEC 15444-15) are present
+#define JPEG2000_CTSY_HTJ2K_M   0xC0 // HT code blocks (Rec. ITU-T T.814 | ISO/IEC 15444-15) can be present
 
 // Progression orders
 #define JPEG2000_PGOD_LRCP      0x00  // Layer-resolution level-component-position progression
diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c
index 92966b11f5..ef4a653afe 100644
--- a/libavcodec/jpeg2000dec.c
+++ b/libavcodec/jpeg2000dec.c
@@ -521,6 +521,15 @@  static int get_cox(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c)
 
     c->cblk_style = bytestream2_get_byteu(&s->g);
     if (c->cblk_style != 0) { // cblk style
+        if (c->cblk_style & JPEG2000_CTSY_HTJ2K_M || c->cblk_style & JPEG2000_CTSY_HTJ2K_F) {
+            /*
+             * HT code-blocks (Rec. ITU-T T.814 | ISO/IEC 15444-15) bit-stream
+             * Not yet supported in ffmpeg, cannot continue.
+             */
+            av_log(s->avctx, AV_LOG_FATAL, "Support for High throughput JPEG 2000 is not yet available\n");
+            return AVERROR_PATCHWELCOME;
+        }
+
         av_log(s->avctx, AV_LOG_WARNING, "extra cblk styles %X\n", c->cblk_style);
         if (c->cblk_style & JPEG2000_CBLK_BYPASS)
             av_log(s->avctx, AV_LOG_WARNING, "Selective arithmetic coding bypass\n");