Hi,

2016-02-08 8:15 GMT+01:00 Christophe Gisquet <christophe.gisq...@gmail.com>:
> At this point, I'd say the encoder would better use that prefix.
> That's what the attached patch does (rebased but not tested). You may
> consider building on top of it for that purpose.

Which I haven't attached... So here's one /not/ rebased, but that
should provide the same information, should that interest you.

BR,
-- 
Christophe
From 89e2da58de95af055b16c513de746a0cb64dd33c Mon Sep 17 00:00:00 2001
From: Christophe Gisquet <christophe.gisq...@gmail.com>
Date: Fri, 2 Oct 2015 10:38:22 +0200
Subject: [PATCH 2/7] dnxhd: add and use header version

This makes it somewhat easier to extend and cleaner. The DNxHR
versions are not very well defined for lack of specs.

This also allows writing the correct header for CIDs 1256 to 1260.
---
 libavcodec/dnxhddata.c | 45 ++++++++++++++++++++++++++-------------------
 libavcodec/dnxhddata.h | 13 +++++++++++++
 libavcodec/dnxhddec.c  | 16 +++++++++-------
 libavcodec/dnxhdenc.c  |  3 +--
 4 files changed, 49 insertions(+), 28 deletions(-)

diff --git a/libavcodec/dnxhddata.c b/libavcodec/dnxhddata.c
index 82fbfdf..a1b452d 100644
--- a/libavcodec/dnxhddata.c
+++ b/libavcodec/dnxhddata.c
@@ -23,6 +23,13 @@
 #include "dnxhddata.h"
 #include "libavutil/common.h"
 
+const uint8_t ff_dnxhd_headers[DNXHD_HEADER_VERSIONS][5] = {
+    { 0x00, 0x00, 0x02, 0x80, 0x01 },
+    { 0x00, 0x00, 0x02, 0x80, 0x02 },
+    { 0x00, 0x00, 0x02, 0x80, 0x03 },
+    { 0x00, 0x00, 0x03, 0x8C, 0x03 },
+};
+
 /* The quantization tables below are in zigzag order! */
 
 /* Used in CID 1235, 1256, 1270 */
@@ -932,7 +939,7 @@ static const uint8_t dnxhd_1250_run[62] = {
 
 const CIDEntry ff_dnxhd_cid_table[] = {
     { 1235, 1920, 1080, 917504, 917504,
-      0, 6, 10, 4,
+      DNXHD_HEADER_INITIAL, 0, 6, 10, 4,
       dnxhd_1235_luma_weight, dnxhd_1235_chroma_weight,
       dnxhd_1235_dc_codes, dnxhd_1235_dc_bits,
       dnxhd_1235_ac_codes, dnxhd_1235_ac_bits, dnxhd_1235_ac_info,
@@ -940,7 +947,7 @@ const CIDEntry ff_dnxhd_cid_table[] = {
       { 175, 185, 365, 440 },
       { { 24000, 1001 }, { 25, 1 }, { 50, 1 }, { 60000, 1001 } } },
     { 1237, 1920, 1080, 606208, 606208,
-      0, 4, 8, 3,
+      DNXHD_HEADER_INITIAL, 0, 4, 8, 3,
       dnxhd_1237_luma_weight, dnxhd_1237_chroma_weight,
       dnxhd_1237_dc_codes, dnxhd_1237_dc_bits,
       dnxhd_1237_ac_codes, dnxhd_1237_ac_bits, dnxhd_1237_ac_info,
@@ -948,7 +955,7 @@ const CIDEntry ff_dnxhd_cid_table[] = {
       { 115, 120, 145, 240, 290 },
       { { 24000, 1001 }, { 25, 1 }, { 30000, 1001 }, { 50, 1 }, { 60000, 1001 } } },
     { 1238, 1920, 1080, 917504, 917504,
-      0, 4, 8, 4,
+      DNXHD_HEADER_INITIAL, 0, 4, 8, 4,
       dnxhd_1238_luma_weight, dnxhd_1238_chroma_weight,
       dnxhd_1237_dc_codes, dnxhd_1237_dc_bits,
       dnxhd_1238_ac_codes, dnxhd_1238_ac_bits, dnxhd_1238_ac_info,
@@ -956,7 +963,7 @@ const CIDEntry ff_dnxhd_cid_table[] = {
       { 175, 185, 220, 365, 440 },
       { { 24000, 1001 }, { 25, 1 }, { 30000, 1001 }, { 50, 1 }, { 60000, 1001 } } },
     { 1241, 1920, 1080, 917504, 458752,
-      DNXHD_INTERLACED, 6, 10, 4,
+      DNXHD_HEADER_INITIAL, DNXHD_INTERLACED, 6, 10, 4,
       dnxhd_1241_luma_weight, dnxhd_1241_chroma_weight,
       dnxhd_1235_dc_codes, dnxhd_1235_dc_bits,
       dnxhd_1235_ac_codes, dnxhd_1235_ac_bits, dnxhd_1235_ac_info,
@@ -964,7 +971,7 @@ const CIDEntry ff_dnxhd_cid_table[] = {
       { 185, 220 },
       { { 25, 1 }, { 30000, 1001 } } },
     { 1242, 1920, 1080, 606208, 303104,
-      DNXHD_INTERLACED, 4, 8, 3,
+      DNXHD_HEADER_INITIAL, DNXHD_INTERLACED, 4, 8, 3,
       dnxhd_1242_luma_weight, dnxhd_1242_chroma_weight,
       dnxhd_1237_dc_codes, dnxhd_1237_dc_bits,
       dnxhd_1237_ac_codes, dnxhd_1237_ac_bits, dnxhd_1237_ac_info,
@@ -972,7 +979,7 @@ const CIDEntry ff_dnxhd_cid_table[] = {
       { 120, 145 },
       { { 25, 1 }, { 30000, 1001 } } },
     { 1243, 1920, 1080, 917504, 458752,
-      DNXHD_INTERLACED, 4, 8, 4,
+      DNXHD_HEADER_INITIAL, DNXHD_INTERLACED, 4, 8, 4,
       dnxhd_1243_luma_weight, dnxhd_1243_chroma_weight,
       dnxhd_1237_dc_codes, dnxhd_1237_dc_bits,
       dnxhd_1238_ac_codes, dnxhd_1238_ac_bits, dnxhd_1238_ac_info,
@@ -980,7 +987,7 @@ const CIDEntry ff_dnxhd_cid_table[] = {
       { 185, 220 },
       { { 25, 1 }, { 30000, 1001 } } },
     { 1250, 1280,  720, 458752, 458752,
-      0, 6, 10, 4,
+      DNXHD_HEADER_INITIAL, 0, 6, 10, 4,
       dnxhd_1250_luma_weight, dnxhd_1250_chroma_weight,
       dnxhd_1235_dc_codes, dnxhd_1235_dc_bits,
       dnxhd_1250_ac_codes, dnxhd_1250_ac_bits, dnxhd_1250_ac_info,
@@ -988,7 +995,7 @@ const CIDEntry ff_dnxhd_cid_table[] = {
       { 90, 90, 180, 220 },
       { { 24000, 1001 }, { 25, 1 }, { 50, 1 }, { 60000, 1001 } } },
     { 1251, 1280,  720, 458752, 458752,
-      0, 4, 8, 4,
+      DNXHD_HEADER_INITIAL, 0, 4, 8, 4,
       dnxhd_1251_luma_weight, dnxhd_1251_chroma_weight,
       dnxhd_1237_dc_codes, dnxhd_1237_dc_bits,
       dnxhd_1251_ac_codes, dnxhd_1251_ac_bits, dnxhd_1251_ac_info,
@@ -996,7 +1003,7 @@ const CIDEntry ff_dnxhd_cid_table[] = {
       { 90, 90, 110, 180, 220 },
       { { 24000, 1001 }, { 25, 1 }, { 30000, 1001 }, { 50, 1 }, { 60000, 1001 } } },
     { 1252, 1280,  720, 303104, 303104,
-      0, 4, 8, 5,
+      DNXHD_HEADER_INITIAL, 0, 4, 8, 5,
       dnxhd_1252_luma_weight, dnxhd_1252_chroma_weight,
       dnxhd_1237_dc_codes, dnxhd_1237_dc_bits,
       dnxhd_1252_ac_codes, dnxhd_1252_ac_bits, dnxhd_1252_ac_info,
@@ -1004,7 +1011,7 @@ const CIDEntry ff_dnxhd_cid_table[] = {
       { 60, 60, 75, 120, 145 },
       { { 24000, 1001 }, { 25, 1 }, { 30000, 1001 }, { 50, 1 }, { 60000, 1001 } } },
     { 1253, 1920, 1080, 188416, 188416,
-      0, 4, 8, 3,
+      DNXHD_HEADER_INITIAL, 0, 4, 8, 3,
       dnxhd_1237_luma_weight, dnxhd_1237_chroma_weight,
       dnxhd_1237_dc_codes, dnxhd_1237_dc_bits,
       dnxhd_1237_ac_codes, dnxhd_1237_ac_bits, dnxhd_1237_ac_info,
@@ -1012,7 +1019,7 @@ const CIDEntry ff_dnxhd_cid_table[] = {
       { 36, 36, 45, 75, 90 },
       { { 24000, 1001 }, { 25, 1 }, { 30000, 1001 }, { 50, 1 }, { 60000, 1001 } } },
     { 1256, 1920, 1080, 1835008, 1835008,
-      DNXHD_444, 6, 10, 4,
+      DNXHD_HEADER_444, DNXHD_444, 6, 10, 4,
       dnxhd_1235_luma_weight, dnxhd_1235_luma_weight,
       dnxhd_1235_dc_codes, dnxhd_1235_dc_bits,
       dnxhd_1235_ac_codes, dnxhd_1235_ac_bits, dnxhd_1235_ac_info,
@@ -1020,56 +1027,56 @@ const CIDEntry ff_dnxhd_cid_table[] = {
       { 350, 390, 440, 730, 880 },
       { { 24000, 1001 }, { 25, 1 }, { 30000, 1001 }, { 50, 1 }, { 60000, 1001 } } },
     { 1258, 960, 720, 212992, 212992,
-      0, 4, 8, 5,
+      DNXHD_HEADER_444, 0, 4, 8, 5,
       dnxhd_1252_luma_weight, dnxhd_1252_chroma_weight,
       dnxhd_1237_dc_codes, dnxhd_1237_dc_bits,
       dnxhd_1252_ac_codes, dnxhd_1252_ac_bits, dnxhd_1252_ac_info,
       dnxhd_1250_run_codes, dnxhd_1250_run_bits, dnxhd_1250_run,
       { 42, 60, 75, 115 } },
     { 1259, 1440, 1080, 417792, 417792,
-      0, 4, 8, 3,
+      DNXHD_HEADER_444, 0, 4, 8, 3,
       dnxhd_1237_luma_weight, dnxhd_1237_chroma_weight,
       dnxhd_1237_dc_codes, dnxhd_1237_dc_bits,
       dnxhd_1237_ac_codes, dnxhd_1237_ac_bits, dnxhd_1237_ac_info,
       dnxhd_1237_run_codes, dnxhd_1237_run_bits, dnxhd_1237_run,
       { 63, 84, 100, 110 } },
     { 1260, 1440, 1080, 835584, 417792,
-      DNXHD_INTERLACED | DNXHD_MBAFF, 4, 8, 3,
+      DNXHD_HEADER_444, DNXHD_INTERLACED | DNXHD_MBAFF, 4, 8, 3,
       dnxhd_1260_luma_weight, dnxhd_1260_chroma_weight,
       dnxhd_1237_dc_codes, dnxhd_1237_dc_bits,
       dnxhd_1237_ac_codes, dnxhd_1237_ac_bits, dnxhd_1237_ac_info,
       dnxhd_1237_run_codes, dnxhd_1237_run_bits, dnxhd_1237_run,
       { 80, 90, 100, 110 } },
     { 1270, DNXHD_VARIABLE, DNXHD_VARIABLE, DNXHD_VARIABLE, DNXHD_VARIABLE,
-      DNXHD_444, 6, DNXHD_VARIABLE, 4,
+      DNXHD_HEADER_HR2, DNXHD_444, 6, DNXHD_VARIABLE, 4,
       dnxhd_1235_luma_weight, dnxhd_1235_luma_weight,
       dnxhd_1235_dc_codes, dnxhd_1235_dc_bits,
       dnxhd_1235_ac_codes, dnxhd_1235_ac_bits, dnxhd_1235_ac_info,
       dnxhd_1235_run_codes, dnxhd_1235_run_bits, dnxhd_1235_run,
       { 0 } },
     { 1271, DNXHD_VARIABLE, DNXHD_VARIABLE, DNXHD_VARIABLE, DNXHD_VARIABLE,
-      0, 6, DNXHD_VARIABLE, 4,
+      DNXHD_HEADER_HR2, 0, 6, DNXHD_VARIABLE, 4,
       dnxhd_1241_luma_weight, dnxhd_1241_chroma_weight,
       dnxhd_1235_dc_codes, dnxhd_1235_dc_bits,
       dnxhd_1235_ac_codes, dnxhd_1235_ac_bits, dnxhd_1235_ac_info,
       dnxhd_1235_run_codes, dnxhd_1235_run_bits, dnxhd_1235_run,
       { 0 } },
     { 1272, DNXHD_VARIABLE, DNXHD_VARIABLE, DNXHD_VARIABLE, DNXHD_VARIABLE,
-      0, 4, 8, 4,
+      DNXHD_HEADER_HR2, 0, 4, 8, 4,
       dnxhd_1238_luma_weight, dnxhd_1238_chroma_weight,
       dnxhd_1237_dc_codes, dnxhd_1237_dc_bits,
       dnxhd_1238_ac_codes, dnxhd_1238_ac_bits, dnxhd_1238_ac_info,
       dnxhd_1235_run_codes, dnxhd_1235_run_bits, dnxhd_1238_run,
       { 0 } },
     { 1273, DNXHD_VARIABLE, DNXHD_VARIABLE, DNXHD_VARIABLE, DNXHD_VARIABLE,
-      0, 4, 8, 3,
+      DNXHD_HEADER_HR2, 0, 4, 8, 3,
       dnxhd_1237_luma_weight, dnxhd_1237_chroma_weight,
       dnxhd_1237_dc_codes, dnxhd_1237_dc_bits,
       dnxhd_1237_ac_codes, dnxhd_1237_ac_bits, dnxhd_1237_ac_info,
       dnxhd_1237_run_codes, dnxhd_1237_run_bits, dnxhd_1237_run,
       { 0 } },
     { 1274, DNXHD_VARIABLE, DNXHD_VARIABLE, DNXHD_VARIABLE, DNXHD_VARIABLE,
-      0, 4, 8, 3,
+      DNXHD_HEADER_HR2, 0, 4, 8, 3,
       dnxhd_1237_luma_weight, dnxhd_1237_chroma_weight,
       dnxhd_1237_dc_codes, dnxhd_1237_dc_bits,
       dnxhd_1237_ac_codes, dnxhd_1237_ac_bits, dnxhd_1237_ac_info,
diff --git a/libavcodec/dnxhddata.h b/libavcodec/dnxhddata.h
index d973888..1146005 100644
--- a/libavcodec/dnxhddata.h
+++ b/libavcodec/dnxhddata.h
@@ -34,11 +34,24 @@
 /** Indicate that a CIDEntry value must be read in the bitstream */
 #define DNXHD_VARIABLE 0
 
+/** Known header versions */
+typedef enum {
+    DNXHD_HEADER_INITIAL    = 0,
+    DNXHD_HEADER_444        = 1,
+    DNXHD_HEADER_HR1        = 2,
+    DNXHD_HEADER_HR2        = 3,
+    DNXHD_HEADER_VERSIONS
+} DNxHD_Header;
+
+/** Known header version strings */
+extern const uint8_t ff_dnxhd_headers[DNXHD_HEADER_VERSIONS][5];
+
 typedef struct CIDEntry {
     int cid;
     unsigned int width, height;
     unsigned int frame_size;
     unsigned int coding_unit_size;
+    DNxHD_Header version;
     uint16_t flags;
     int index_bits;
     int bit_depth;
diff --git a/libavcodec/dnxhddec.c b/libavcodec/dnxhddec.c
index 2eb07ec..3131c91 100644
--- a/libavcodec/dnxhddec.c
+++ b/libavcodec/dnxhddec.c
@@ -158,13 +158,10 @@ static int dnxhd_decode_header(DNXHDContext *ctx, AVFrame *frame,
                                const uint8_t *buf, int buf_size,
                                int first_field)
 {
-    static const uint8_t header_prefix[]    = { 0x00, 0x00, 0x02, 0x80, 0x01 };
-    static const uint8_t header_prefix444[] = { 0x00, 0x00, 0x02, 0x80, 0x02 };
-    static const uint8_t header_prefixhr1[] = { 0x00, 0x00, 0x02, 0x80, 0x03 };
-    static const uint8_t header_prefixhr2[] = { 0x00, 0x00, 0x03, 0x8C, 0x03 };
     int i, cid, ret;
     int old_bit_depth = ctx->bit_depth, bitdepth;
     int old_mb_height = ctx->mb_height;
+    int version = -1;
 
     if (buf_size < 0x280) {
         av_log(ctx->avctx, AV_LOG_ERROR,
@@ -172,8 +169,13 @@ static int dnxhd_decode_header(DNXHDContext *ctx, AVFrame *frame,
         return AVERROR_INVALIDDATA;
     }
 
-    if (memcmp(buf, header_prefix, 5) && memcmp(buf, header_prefix444, 5) &&
-        memcmp(buf, header_prefixhr1, 5) && memcmp(buf, header_prefixhr2, 5)) {
+    for (i = 0; i < DNXHD_HEADER_VERSIONS; i++) {
+        if (!memcmp(buf, ff_dnxhd_headers[i], 5)) {
+            version = i;
+            break;
+        }
+    }
+    if (version == -1) {
         av_log(ctx->avctx, AV_LOG_ERROR,
                "unknown header 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X\n",
                buf[0], buf[1], buf[2], buf[3], buf[4]);
@@ -275,7 +277,7 @@ static int dnxhd_decode_header(DNXHDContext *ctx, AVFrame *frame,
            ctx->bit_depth, ctx->mbaff, ctx->act);
 
     // Newer format supports variable mb_scan_index sizes
-    if (!memcmp(buf, header_prefixhr2, 5)) {
+    if (version == DNXHD_HEADER_HR2) {
         ctx->data_offset = 0x170 + (ctx->mb_height << 2);
     } else {
         if (ctx->mb_height > 68 ||
diff --git a/libavcodec/dnxhdenc.c b/libavcodec/dnxhdenc.c
index ea1230e..4bbbb72 100644
--- a/libavcodec/dnxhdenc.c
+++ b/libavcodec/dnxhdenc.c
@@ -430,11 +430,10 @@ fail:  // for FF_ALLOCZ_OR_GOTO
 static int dnxhd_write_header(AVCodecContext *avctx, uint8_t *buf)
 {
     DNXHDEncContext *ctx = avctx->priv_data;
-    static const uint8_t header_prefix[5] = { 0x00, 0x00, 0x02, 0x80, 0x01 };
 
     memset(buf, 0, 640);
 
-    memcpy(buf, header_prefix, 5);
+    memcpy(buf, ff_dnxhd_headers[ctx->cid_table->version], 5);
     buf[5] = ctx->interlaced ? ctx->cur_field + 2 : 0x01;
     buf[6] = 0x80; // crc flag off
     buf[7] = 0xa0; // reserved
-- 
2.6.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Reply via email to