[Libva] [PATCH 1/2] jpeg: generate default Huffman tables.

Gwenole Beauchesne gb.devel at gmail.com
Mon Jun 18 07:49:44 PDT 2012


If no Huffman table is provided from the application layer, then make
sure the driver does generate and upload meaningful values to the HW.

Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne at intel.com>
---
 src/gen7_mfd.c           |  119 ++++++++++++++++++++++++++-------------------
 src/gen7_mfd.h           |    4 ++
 src/i965_decoder.h       |    1 +
 src/i965_decoder_utils.c |   94 ++++++++++++++++++++++++++++++++++++
 src/i965_decoder_utils.h |    3 +
 5 files changed, 171 insertions(+), 50 deletions(-)

diff --git a/src/gen7_mfd.c b/src/gen7_mfd.c
index 4f8927a..654d2b9 100644
--- a/src/gen7_mfd.c
+++ b/src/gen7_mfd.c
@@ -1918,6 +1918,16 @@ gen7_mfd_vc1_decode_picture(VADriverContextP ctx,
     intel_batchbuffer_flush(batch);
 }
 
+static inline void
+gen7_mfd_jpeg_context_init(
+    VADriverContextP         ctx,
+    struct gen7_mfd_context *gen7_mfd_context
+)
+{
+    /* Initialize default Huffman table */
+    jpeg_gen_default_huffman_table(&gen7_mfd_context->huffman_table.jpeg);
+}
+
 static void
 gen7_mfd_jpeg_decode_init(VADriverContextP ctx,
                           struct decode_state *decode_state,
@@ -2083,31 +2093,62 @@ static const int va_to_gen7_jpeg_hufftable[2] = {
 
 static void
 gen7_mfd_jpeg_huff_table_state(VADriverContextP ctx,
-                               struct decode_state *decode_state,
-                               struct gen7_mfd_context *gen7_mfd_context,
-                               int num_tables)
+                               unsigned int HuffTableID,
+                               unsigned char dc_bits[12],
+                               unsigned char dc_huffval[12],
+                               unsigned char ac_bits[16],
+                               unsigned char ac_huffval[162],
+                               struct gen7_mfd_context *gen7_mfd_context)
 {
-    VAHuffmanTableBufferJPEG *huffman_table;
-    struct intel_batchbuffer *batch = gen7_mfd_context->base.batch;
-    int index;
+    struct intel_batchbuffer * const batch = gen7_mfd_context->base.batch;
+
+    BEGIN_BCS_BATCH(batch, 53);
+    OUT_BCS_BATCH(batch, MFX_JPEG_HUFF_TABLE_STATE | (53 - 2));
+    OUT_BCS_BATCH(batch, HuffTableID);
+    intel_batchbuffer_data(batch, dc_bits, 12);
+    intel_batchbuffer_data(batch, dc_huffval, 12);
+    intel_batchbuffer_data(batch, ac_bits, 16);
+    intel_batchbuffer_data(batch, ac_huffval, 164);
+    ADVANCE_BCS_BATCH(batch);
+}
 
-    if (!decode_state->huffman_table || !decode_state->huffman_table->buffer)
-        return;
+static void
+gen7_mfd_jpeg_update_huff_table_state(VADriverContextP ctx,
+                                      struct decode_state *decode_state,
+                                      struct gen7_mfd_context *gen7_mfd_context)
+{
+    VAHuffmanTableBufferJPEG * const gen_huffman_table = &gen7_mfd_context->huffman_table.jpeg;
+    unsigned int i, id;
 
-    huffman_table = (VAHuffmanTableBufferJPEG *)decode_state->huffman_table->buffer;
+    /* Update internal Huffman tables */
+    if (decode_state->huffman_table && decode_state->huffman_table->buffer) {
+        VAHuffmanTableBufferJPEG * const huffman_table =
+            (VAHuffmanTableBufferJPEG *)decode_state->huffman_table->buffer;
 
-    for (index = 0; index < num_tables; index++) {
-        int id = va_to_gen7_jpeg_hufftable[index];
-        if (!huffman_table->load_huffman_table[index])
+        for (i = 0; i < ARRAY_ELEMS(huffman_table->huffman_table); i++) {
+            if (!huffman_table->load_huffman_table[i])
+                continue;
+            id = va_to_gen7_jpeg_hufftable[i];
+            memcpy(&gen_huffman_table->huffman_table[id],
+                   &huffman_table->huffman_table[i],
+                   sizeof(gen_huffman_table->huffman_table[id]));
+            gen_huffman_table->load_huffman_table[id] = 1;
+        }
+    }
+
+    /* Upload Huffman table, if necessary */
+    for (i = 0; i < ARRAY_ELEMS(gen_huffman_table->huffman_table); i++) {
+        if (!gen_huffman_table->load_huffman_table[i])
             continue;
-        BEGIN_BCS_BATCH(batch, 53);
-        OUT_BCS_BATCH(batch, MFX_JPEG_HUFF_TABLE_STATE | (53 - 2));
-        OUT_BCS_BATCH(batch, id);
-        intel_batchbuffer_data(batch, huffman_table->huffman_table[index].num_dc_codes, 12);
-        intel_batchbuffer_data(batch, huffman_table->huffman_table[index].dc_values, 12);
-        intel_batchbuffer_data(batch, huffman_table->huffman_table[index].num_ac_codes, 16);
-        intel_batchbuffer_data(batch, huffman_table->huffman_table[index].ac_values, 164);
-        ADVANCE_BCS_BATCH(batch);
+        gen7_mfd_jpeg_huff_table_state(
+            ctx, i,
+            gen_huffman_table->huffman_table[i].num_dc_codes,
+            gen_huffman_table->huffman_table[i].dc_values,
+            gen_huffman_table->huffman_table[i].num_ac_codes,
+            gen_huffman_table->huffman_table[i].ac_values,
+            gen7_mfd_context
+        );
+        gen_huffman_table->load_huffman_table[i] = 0;
     }
 }
 
@@ -2626,7 +2667,7 @@ gen7_mfd_jpeg_decode_picture(VADriverContextP ctx,
     VAPictureParameterBufferJPEG *pic_param;
     VASliceParameterBufferJPEG *slice_param, *next_slice_param, *next_slice_group_param;
     dri_bo *slice_data_bo;
-    int i, j, max_selector = 0;
+    int i, j;
 
     assert(decode_state->pic_param && decode_state->pic_param->buffer);
     pic_param = (VAPictureParameterBufferJPEG *)decode_state->pic_param->buffer;
@@ -2645,39 +2686,12 @@ gen7_mfd_jpeg_decode_picture(VADriverContextP ctx,
 
     for (j = 0; j < decode_state->num_slice_params; j++) {
         assert(decode_state->slice_params && decode_state->slice_params[j]->buffer);
-        slice_param = (VASliceParameterBufferJPEG *)decode_state->slice_params[j]->buffer;
+        assert(decode_state->slice_datas[j]->bo);
         slice_data_bo = decode_state->slice_datas[j]->bo;
         gen7_mfd_ind_obj_base_addr_state(ctx, slice_data_bo, MFX_FORMAT_JPEG, gen7_mfd_context);
-
-        if (j == decode_state->num_slice_params - 1)
-            next_slice_group_param = NULL;
-        else
-            next_slice_group_param = (VASliceParameterBufferJPEG *)decode_state->slice_params[j + 1]->buffer;
-
-        for (i = 0; i < decode_state->slice_params[j]->num_elements; i++) {
-            int component;
-
-            assert(slice_param->slice_data_flag == VA_SLICE_DATA_FLAG_ALL);
-
-            if (i < decode_state->slice_params[j]->num_elements - 1)
-                next_slice_param = slice_param + 1;
-            else
-                next_slice_param = next_slice_group_param;
-
-            for (component = 0; component < slice_param->num_components; component++) {
-                if (max_selector < slice_param->components[component].dc_table_selector)
-                    max_selector = slice_param->components[component].dc_table_selector;
-
-                if (max_selector < slice_param->components[component].ac_table_selector)
-                    max_selector = slice_param->components[component].ac_table_selector;
-            }
-
-            slice_param++;
-        }
     }
 
-    assert(max_selector < 2);
-    gen7_mfd_jpeg_huff_table_state(ctx, decode_state, gen7_mfd_context, max_selector + 1);
+    gen7_mfd_jpeg_update_huff_table_state(ctx, decode_state, gen7_mfd_context);
 
     for (j = 0; j < decode_state->num_slice_params; j++) {
         assert(decode_state->slice_params && decode_state->slice_params[j]->buffer);
@@ -2819,6 +2833,11 @@ gen7_dec_hw_context_init(VADriverContextP ctx, struct object_config *obj_config)
     case VAProfileH264High:
         gen7_mfd_avc_context_init(ctx, gen7_mfd_context);
         break;
+
+    case VAProfileJPEGBaseline:
+        gen7_mfd_jpeg_context_init(ctx, gen7_mfd_context);
+        break;
+
     default:
         break;
     }
diff --git a/src/gen7_mfd.h b/src/gen7_mfd.h
index 08d9e3a..e2e25b6 100644
--- a/src/gen7_mfd.h
+++ b/src/gen7_mfd.h
@@ -84,6 +84,10 @@ struct gen7_mfd_context
         VAIQMatrixBufferH264  h264;     /* flat scaling lists (default) */
     } iq_matrix;
 
+    union {
+        VAHuffmanTableBufferJPEG jpeg;  /* in MFX format */
+    } huffman_table;
+
     GenFrameStore       reference_surface[MAX_GEN_REFERENCE_FRAMES];
     GenBuffer           post_deblocking_output;
     GenBuffer           pre_deblocking_output;
diff --git a/src/i965_decoder.h b/src/i965_decoder.h
index 0e69e14..8d88e3b 100644
--- a/src/i965_decoder.h
+++ b/src/i965_decoder.h
@@ -27,6 +27,7 @@
 
 #include <stdint.h>
 #include <va/va.h>
+#include <va/va_dec_jpeg.h>
 #include <intel_bufmgr.h>
 
 #define MAX_GEN_REFERENCE_FRAMES 16
diff --git a/src/i965_decoder_utils.c b/src/i965_decoder_utils.c
index 06df5dd..042ec95 100644
--- a/src/i965_decoder_utils.c
+++ b/src/i965_decoder_utils.c
@@ -30,6 +30,100 @@
 #include "i965_drv_video.h"
 #include "i965_defines.h"
 
+/* Generate default Huffman table for decoding */
+void
+jpeg_gen_default_huffman_table(VAHuffmanTableBufferJPEG *huffman_table)
+{
+    static const VAHuffmanTableBufferJPEG default_huffman_table = {
+        .huffman_table = {
+
+            // Luma component
+            {
+                .num_dc_codes = {
+                    0x00, 0x01, 0x05, 0x01, 0x01, 0x01, 0x01, 0x01,
+                    0x01,
+                },
+                .dc_values = {
+                    0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+                    0x08, 0x09, 0x0a, 0x0b
+                },
+
+                .num_ac_codes = {
+                    0x00, 0x02, 0x01, 0x03, 0x03, 0x02, 0x04, 0x03,
+                    0x05, 0x05, 0x04, 0x04, 0x00, 0x00, 0x01, 0x7d
+                },
+                .ac_values = {
+                    0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12,
+                    0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07,
+                    0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08,
+                    0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0,
+                    0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16,
+                    0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28,
+                    0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
+                    0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
+                    0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
+                    0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
+                    0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
+                    0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
+                    0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98,
+                    0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
+                    0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
+                    0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5,
+                    0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4,
+                    0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2,
+                    0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea,
+                    0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
+                    0xf9, 0xfa
+                },
+            },
+
+            // Chroma component
+            {
+                .num_dc_codes = {
+                    0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+                    0x01, 0x01, 0x01,
+                },
+                .dc_values = {
+                    0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+                    0x08, 0x09, 0x0a, 0x0b
+                },
+
+                .num_ac_codes = {
+                    0x00, 0x02, 0x01, 0x02, 0x04, 0x04, 0x03, 0x04,
+                    0x07, 0x05, 0x04, 0x04, 0x00, 0x01, 0x02, 0x77
+                },
+                .ac_values = {
+                    0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21,
+                    0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
+                    0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,
+                    0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0,
+                    0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34,
+                    0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26,
+                    0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38,
+                    0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
+                    0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
+                    0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
+                    0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
+                    0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
+                    0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96,
+                    0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5,
+                    0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4,
+                    0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3,
+                    0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2,
+                    0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda,
+                    0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
+                    0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
+                    0xf9, 0xfa
+                },
+            },
+        }
+    };
+
+    memcpy(huffman_table, &default_huffman_table, sizeof(*huffman_table));
+    huffman_table->load_huffman_table[0] = 1;
+    huffman_table->load_huffman_table[1] = 1;
+}
+
 /* Set reference surface if backing store exists */
 static inline int
 set_ref_frame(
diff --git a/src/i965_decoder_utils.h b/src/i965_decoder_utils.h
index 0d86523..aa1eba1 100644
--- a/src/i965_decoder_utils.h
+++ b/src/i965_decoder_utils.h
@@ -29,6 +29,9 @@
 
 struct decode_state;
 
+void
+jpeg_gen_default_huffman_table(VAHuffmanTableBufferJPEG *huffman_table);
+
 int
 mpeg2_wa_slice_vertical_position(
     struct decode_state           *decode_state,
-- 
1.7.5.4



More information about the Libva mailing list