radeon/uvd: use bitstream coded number for symbols of Huffman tables
authorLeo Liu <leo.liu@amd.com>
Tue, 18 Sep 2018 20:19:57 +0000 (16:19 -0400)
committerLeo Liu <leo.liu@amd.com>
Mon, 24 Sep 2018 13:12:49 +0000 (09:12 -0400)
Signed-off-by: Leo Liu <leo.liu@amd.com>
Fixes: 130d1f456(radeon/uvd: reconstruct MJPEG bitstream)
Cc: "18.2" <mesa-stable@lists.freedesktop.org>
Reviewed-by: Boyuan Zhang <boyuan.zhang@amd.com>
src/gallium/drivers/radeon/radeon_uvd.c

index 923216d77f1e5d082884a189e682659adf3bc2a8..a7ef4252ee0b9bc1753f18afe06fc174daa1a82c 100644 (file)
@@ -1003,25 +1003,35 @@ static void get_mjpeg_slice_header(struct ruvd_decoder *dec, struct pipe_mjpeg_p
        size++;
 
        for (i = 0; i < 2; ++i) {
+               int num = 0, j;
+
                if (pic->huffman_table.load_huffman_table[i] == 0)
                        continue;
 
                buf[size++] = 0x00 | i;
                memcpy((buf + size), &pic->huffman_table.table[i].num_dc_codes, 16);
                size += 16;
-               memcpy((buf + size), &pic->huffman_table.table[i].dc_values, 12);
-               size += 12;
+               for (j = 0; j < 16; ++j)
+                       num += pic->huffman_table.table[i].num_dc_codes[j];
+               assert(num <= 12);
+               memcpy((buf + size), &pic->huffman_table.table[i].dc_values, num);
+               size += num;
        }
 
        for (i = 0; i < 2; ++i) {
+               int num = 0, j;
+
                if (pic->huffman_table.load_huffman_table[i] == 0)
                        continue;
 
                buf[size++] = 0x10 | i;
                memcpy((buf + size), &pic->huffman_table.table[i].num_ac_codes, 16);
                size += 16;
-               memcpy((buf + size), &pic->huffman_table.table[i].ac_values, 162);
-               size += 162;
+               for (j = 0; j < 16; ++j)
+                       num += pic->huffman_table.table[i].num_ac_codes[j];
+               assert(num <= 162);
+               memcpy((buf + size), &pic->huffman_table.table[i].ac_values, num);
+               size += num;
        }
 
        bs = (uint16_t*)&buf[len_pos];