diff mbox series

[FFmpeg-devel,2/8] libavcodec/jpeg2000_parser: Simplify, fix reset_context()

Message ID a68bc77d48bafd63f9e682387c8871c655d2e546.camel@acc.umu.se
State New
Headers show
Series [FFmpeg-devel,1/8] libavcodec/jpeg2000_parser: Speed up long skips | expand

Checks

Context Check Description
andriy/configure_x86 warning Failed to apply patch

Commit Message

Tomas Härdin May 31, 2022, 9:59 a.m. UTC

Comments

Michael Niedermayer June 1, 2022, 4:50 p.m. UTC | #1
On Tue, May 31, 2022 at 11:59:15AM +0200, Tomas Härdin wrote:
> 

>  jpeg2000_parser.c |   23 ++++++++++-------------
>  1 file changed, 10 insertions(+), 13 deletions(-)
> 54fa89b694ebf1b0fb5adf18a5f53a2aabcbc9c9  0002-libavcodec-jpeg2000_parser-Simplify-fix-reset_contex.patch
> From 4bf4593c0d4cbc36d8fcaabe9e36b39134403c34 Mon Sep 17 00:00:00 2001
> From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= <git@haerdin.se>
> Date: Fri, 20 May 2022 11:44:06 +0200
> Subject: [PATCH 2/8] libavcodec/jpeg2000_parser: Simplify, fix reset_context()
> 
> ---
>  libavcodec/jpeg2000_parser.c | 23 ++++++++++-------------
>  1 file changed, 10 insertions(+), 13 deletions(-)

should be ok

thx

[...]
diff mbox series

Patch

From 4bf4593c0d4cbc36d8fcaabe9e36b39134403c34 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= <git@haerdin.se>
Date: Fri, 20 May 2022 11:44:06 +0200
Subject: [PATCH 2/8] libavcodec/jpeg2000_parser: Simplify, fix reset_context()

---
 libavcodec/jpeg2000_parser.c | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)

diff --git a/libavcodec/jpeg2000_parser.c b/libavcodec/jpeg2000_parser.c
index 9fac958dfa..a7f72710e4 100644
--- a/libavcodec/jpeg2000_parser.c
+++ b/libavcodec/jpeg2000_parser.c
@@ -51,7 +51,7 @@  static inline void reset_context(JPEG2000ParserContext *m)
     ParseContext *pc = &m->pc;
 
     pc->frame_start_found= 0;
-    pc->state = 0;
+    pc->state64 = 0;
     m->bytes_read = 0;
     m->ft = 0;
     m->skipped_codestream = 0;
@@ -82,16 +82,14 @@  static int find_frame_end(JPEG2000ParserContext *m, const uint8_t *buf, int buf_
 {
     ParseContext *pc= &m->pc;
     int i;
-    uint32_t state, next_state;
-    uint64_t state64;
-    state= pc->state;
-    state64 = pc->state64;
+    uint32_t next_state;
+    uint64_t state64 = pc->state64;
+
     if (buf_size == 0) {
         return 0;
     }
 
     for (i = 0; i < buf_size; i++) {
-        state = state << 8 | buf[i];
         state64 = state64 << 8 | buf[i];
         m->bytes_read++;
         if (m->skip_bytes) {
@@ -132,9 +130,9 @@  static int find_frame_end(JPEG2000ParserContext *m, const uint8_t *buf, int buf_
             }
             m->fheader_read--;
         }
-        if (state == 0x0000000C && m->bytes_read >= 3) { // Indicates start of JP2 file. Check signature next.
+        if ((state64 & 0xFFFFFFFF) == 0x0000000C && m->bytes_read >= 3) { // Indicates start of JP2 file. Check signature next.
             m->fheader_read = 8;
-        } else if ((state & 0xFFFF) == 0xFF4F) {
+        } else if ((state64 & 0xFFFF) == 0xFF4F) {
             m->in_codestream = 1;
             if (!pc->frame_start_found) {
                 pc->frame_start_found = 1;
@@ -143,7 +141,7 @@  static int find_frame_end(JPEG2000ParserContext *m, const uint8_t *buf, int buf_
                 reset_context(m);
                 return i - 1;
             }
-        } else if ((state & 0xFFFF) == 0xFFD9) {
+        } else if ((state64 & 0xFFFF) == 0xFFD9) {
             if (pc->frame_start_found && m->ft == jp2_file) {
                 m->skipped_codestream = 1;
             } else if (pc->frame_start_found && m->ft == j2k_cstream) {
@@ -151,11 +149,11 @@  static int find_frame_end(JPEG2000ParserContext *m, const uint8_t *buf, int buf_
                 return i + 1; // End of frame detected, return frame size.
             }
             m->in_codestream = 0;
-        } else if (m->in_codestream && (state & 0xFFFF) == 0xFF90) { // Are we in tile part header?
+        } else if (m->in_codestream && (state64 & 0xFFFF) == 0xFF90) { // Are we in tile part header?
             m->read_tp = 8;
-        } else if (pc->frame_start_found && info_marker((state & 0xFFFF0000)>>16) && m->in_codestream && (state & 0xFFFF)) {
+        } else if (pc->frame_start_found && info_marker((state64 & 0xFFFF0000)>>16) && m->in_codestream && (state64 & 0xFFFF)) {
             // Calculate number of bytes to skip to get to end of the next marker.
-            m->skip_bytes = (state & 0xFFFF)-1;
+            m->skip_bytes = (state64 & 0xFFFF)-1;
 
             // If the next marker is an info marker, skip to the end of of the marker length.
             if (i + m->skip_bytes + 1 < buf_size) {
@@ -168,7 +166,6 @@  static int find_frame_end(JPEG2000ParserContext *m, const uint8_t *buf, int buf_
         }
     }
 
-    pc->state = state;
     pc->state64 = state64;
     return END_NOT_FOUND;
 }
-- 
2.30.2