[FFmpeg-devel] [PATCH v2 1/2] libavcodec/dnxhddec: refactor header prefix parsing
Mark Reid
mindmark at gmail.com
Fri Feb 12 05:41:15 CET 2016
---
libavcodec/dnxhddata.c | 17 +++++++++++++++++
libavcodec/dnxhddata.h | 11 +++++++++++
libavcodec/dnxhddec.c | 11 ++++-------
3 files changed, 32 insertions(+), 7 deletions(-)
diff --git a/libavcodec/dnxhddata.c b/libavcodec/dnxhddata.c
index 82fbfdf..5b909b6 100644
--- a/libavcodec/dnxhddata.c
+++ b/libavcodec/dnxhddata.c
@@ -23,6 +23,13 @@
#include "dnxhddata.h"
#include "libavutil/common.h"
+static const uint8_t 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 */
@@ -1102,6 +1109,16 @@ int avpriv_dnxhd_get_interlaced(int cid)
return ff_dnxhd_cid_table[i].flags & DNXHD_INTERLACED ? 1 : 0;
}
+DNXHD_Header avpriv_dnxhd_parse_prefix(const uint8_t *buf)
+{
+ int i;
+ for (i = 0; i < DNXHD_HEADER_VERSIONS; i++) {
+ if (!memcmp(buf, dnxhd_headers[i], 5))
+ return i;
+ }
+ return DNXHD_HEADER_UNKNOWN;
+}
+
int ff_dnxhd_find_cid(AVCodecContext *avctx, int bit_depth)
{
int i, j;
diff --git a/libavcodec/dnxhddata.h b/libavcodec/dnxhddata.h
index d973888..b388df8 100644
--- a/libavcodec/dnxhddata.h
+++ b/libavcodec/dnxhddata.h
@@ -34,6 +34,16 @@
/** 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_UNKNOWN
+} DNXHD_Header;
+
typedef struct CIDEntry {
int cid;
unsigned int width, height;
@@ -61,5 +71,6 @@ void ff_dnxhd_print_profiles(AVCodecContext *avctx, int loglevel);
int avpriv_dnxhd_get_frame_size(int cid);
int avpriv_dnxhd_get_interlaced(int cid);
+DNXHD_Header avpriv_dnxhd_parse_prefix(const uint8_t *buf);
#endif /* AVCODEC_DNXHDDATA_H */
diff --git a/libavcodec/dnxhddec.c b/libavcodec/dnxhddec.c
index 5c09c64..c111def 100644
--- a/libavcodec/dnxhddec.c
+++ b/libavcodec/dnxhddec.c
@@ -163,10 +163,6 @@ 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;
@@ -176,8 +172,9 @@ 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)) {
+ DNXHD_Header header_prefix = avpriv_dnxhd_parse_prefix(buf);
+
+ if (header_prefix == DNXHD_HEADER_UNKNOWN) {
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]);
@@ -279,7 +276,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 (header_prefix == DNXHD_HEADER_HR2) {
ctx->data_offset = 0x170 + (ctx->mb_height << 2);
} else {
if (ctx->mb_height > 68 ||
--
2.4.1
More information about the ffmpeg-devel
mailing list