[FFmpeg-devel] [PATCH v3] libavcodec/dnxhd_parser: add parser and probe support raw 444 and dnxhr formats

2016-02-13 Thread Mark Reid
---
 libavcodec/dnxhd_parser.c |  7 +++
 libavcodec/dnxhddata.c|  8 
 libavcodec/dnxhddata.h| 18 +-
 libavcodec/dnxhddec.c | 12 
 libavformat/dnxhddec.c|  7 ---
 5 files changed, 36 insertions(+), 16 deletions(-)

diff --git a/libavcodec/dnxhd_parser.c b/libavcodec/dnxhd_parser.c
index fffb98f..033b8ee 100644
--- a/libavcodec/dnxhd_parser.c
+++ b/libavcodec/dnxhd_parser.c
@@ -25,8 +25,7 @@
  */
 
 #include "parser.h"
-
-#define DNXHD_HEADER_PREFIX 0x02800100
+#include "dnxhddata.h"
 
 typedef struct {
 ParseContext pc;
@@ -47,7 +46,7 @@ static int dnxhd_find_frame_end(DNXHDParserContext *dctx,
 if (!pic_found) {
 for (i = 0; i < buf_size; i++) {
 state = (state << 8) | buf[i];
-if ((state & 0xff00LL) == DNXHD_HEADER_PREFIX) {
+if (ff_dnxhd_check_header_prefix(state & 0xff00LL) != 0) {
 i++;
 pic_found = 1;
 interlaced = (state&2)>>1; /* byte following the 5-byte header 
prefix */
@@ -62,7 +61,7 @@ static int dnxhd_find_frame_end(DNXHDParserContext *dctx,
 return 0;
 for (; i < buf_size; i++) {
 state = (state << 8) | buf[i];
-if ((state & 0xff00LL) == DNXHD_HEADER_PREFIX) {
+if (ff_dnxhd_check_header_prefix(state & 0xff00LL) != 0) {
 if (!interlaced || dctx->cur_field) {
 pc->frame_start_found = 0;
 pc->state64 = -1;
diff --git a/libavcodec/dnxhddata.c b/libavcodec/dnxhddata.c
index 82fbfdf..6955fd0 100644
--- a/libavcodec/dnxhddata.c
+++ b/libavcodec/dnxhddata.c
@@ -22,6 +22,7 @@
 #include "avcodec.h"
 #include "dnxhddata.h"
 #include "libavutil/common.h"
+#include "libavutil/intreadwrite.h"
 
 /* The quantization tables below are in zigzag order! */
 
@@ -1102,6 +1103,13 @@ int avpriv_dnxhd_get_interlaced(int cid)
 return ff_dnxhd_cid_table[i].flags & DNXHD_INTERLACED ? 1 : 0;
 }
 
+uint64_t avpriv_dnxhd_parse_header_prefix(const uint8_t *buf)
+{
+  uint64_t prefix = AV_RB32(buf);
+  prefix = (prefix << 16) | buf[4] << 8;
+  return ff_dnxhd_check_header_prefix(prefix);
+}
+
 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..11e3204 100644
--- a/libavcodec/dnxhddata.h
+++ b/libavcodec/dnxhddata.h
@@ -31,6 +31,12 @@
 #define DNXHD_MBAFF(1<<1)
 #define DNXHD_444  (1<<2)
 
+/** Frame headers, extra 0x00 added to end for parser */
+#define DNXHD_HEADER_INITIAL 0x02800100
+#define DNXHD_HEADER_444 0x02800200
+#define DNXHD_HEADER_HR1 0x02800300
+#define DNXHD_HEADER_HR2 0x038C0300
+
 /** Indicate that a CIDEntry value must be read in the bitstream */
 #define DNXHD_VARIABLE 0
 
@@ -59,7 +65,17 @@ int ff_dnxhd_get_cid_table(int cid);
 int ff_dnxhd_find_cid(AVCodecContext *avctx, int bit_depth);
 void ff_dnxhd_print_profiles(AVCodecContext *avctx, int loglevel);
 
+static av_always_inline uint64_t ff_dnxhd_check_header_prefix(uint64_t prefix)
+{
+  if (prefix == DNXHD_HEADER_INITIAL ||
+  prefix == DNXHD_HEADER_444 ||
+  prefix == DNXHD_HEADER_HR1 ||
+  prefix == DNXHD_HEADER_HR2)
+return prefix;
+  return 0;
+}
+
 int avpriv_dnxhd_get_frame_size(int cid);
 int avpriv_dnxhd_get_interlaced(int cid);
-
+uint64_t avpriv_dnxhd_parse_header_prefix(const uint8_t *buf);
 #endif /* AVCODEC_DNXHDDATA_H */
diff --git a/libavcodec/dnxhddec.c b/libavcodec/dnxhddec.c
index 5c09c64..1808080 100644
--- a/libavcodec/dnxhddec.c
+++ b/libavcodec/dnxhddec.c
@@ -163,21 +163,17 @@ 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;
-
+uint64_t header_prefix;
 if (buf_size < 0x280) {
 av_log(ctx->avctx, AV_LOG_ERROR,
"buffer too small (%d < 640).\n", buf_size);
 return AVERROR_INVALIDDATA;
 }
 
-if (memcmp(buf, header_prefix, 5) && memcmp(buf, header_prefix444, 5) &&
-memcmp(buf, header_prefixhr1, 5) && memcmp(buf, header_prefixhr2, 5)) {
+header_prefix = avpriv_dnxhd_parse_header_prefix(buf);
+if (header_prefix == 0) {
 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 +275,7 @@ static int dnxhd_decode_header(DNXHDContext *ctx, AVFrame 
*frame,

[FFmpeg-devel] [PATCH v3] libavcodec/dnxhd_parser: add parser and probe support raw 444 and dnxhr formats

2016-02-13 Thread Mark Reid
changes since v2:
removed table and enums, using defines for prefixes instead.
parser now uses a inline function.

Mark Reid (1):
  libavcodec/dnxhd_parser: add parser and probe support raw 444 and
dnxhr formats

 libavcodec/dnxhd_parser.c |  7 +++
 libavcodec/dnxhddata.c|  8 
 libavcodec/dnxhddata.h| 18 +-
 libavcodec/dnxhddec.c | 12 
 libavformat/dnxhddec.c|  7 ---
 5 files changed, 36 insertions(+), 16 deletions(-)

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


Re: [FFmpeg-devel] [PATCH v3] libavcodec/dnxhd_parser: add parser and probe support raw 444 and dnxhr formats

2016-02-13 Thread Michael Niedermayer
On Sat, Feb 13, 2016 at 04:35:24PM -0800, Mark Reid wrote:
> ---
>  libavcodec/dnxhd_parser.c |  7 +++
>  libavcodec/dnxhddata.c|  8 
>  libavcodec/dnxhddata.h| 18 +-
>  libavcodec/dnxhddec.c | 12 
>  libavformat/dnxhddec.c|  7 ---
>  5 files changed, 36 insertions(+), 16 deletions(-)
> 
> diff --git a/libavcodec/dnxhd_parser.c b/libavcodec/dnxhd_parser.c
> index fffb98f..033b8ee 100644
> --- a/libavcodec/dnxhd_parser.c
> +++ b/libavcodec/dnxhd_parser.c
> @@ -25,8 +25,7 @@
>   */
>  
>  #include "parser.h"
> -
> -#define DNXHD_HEADER_PREFIX 0x02800100
> +#include "dnxhddata.h"
>  
>  typedef struct {
>  ParseContext pc;
> @@ -47,7 +46,7 @@ static int dnxhd_find_frame_end(DNXHDParserContext *dctx,
>  if (!pic_found) {
>  for (i = 0; i < buf_size; i++) {
>  state = (state << 8) | buf[i];
> -if ((state & 0xff00LL) == DNXHD_HEADER_PREFIX) {
> +if (ff_dnxhd_check_header_prefix(state & 0xff00LL) != 0) 
> {
>  i++;
>  pic_found = 1;
>  interlaced = (state&2)>>1; /* byte following the 5-byte 
> header prefix */
> @@ -62,7 +61,7 @@ static int dnxhd_find_frame_end(DNXHDParserContext *dctx,
>  return 0;
>  for (; i < buf_size; i++) {
>  state = (state << 8) | buf[i];
> -if ((state & 0xff00LL) == DNXHD_HEADER_PREFIX) {
> +if (ff_dnxhd_check_header_prefix(state & 0xff00LL) != 0) 
> {
>  if (!interlaced || dctx->cur_field) {
>  pc->frame_start_found = 0;
>  pc->state64 = -1;
> diff --git a/libavcodec/dnxhddata.c b/libavcodec/dnxhddata.c
> index 82fbfdf..6955fd0 100644
> --- a/libavcodec/dnxhddata.c
> +++ b/libavcodec/dnxhddata.c
> @@ -22,6 +22,7 @@
>  #include "avcodec.h"
>  #include "dnxhddata.h"
>  #include "libavutil/common.h"
> +#include "libavutil/intreadwrite.h"
>  
>  /* The quantization tables below are in zigzag order! */
>  
> @@ -1102,6 +1103,13 @@ int avpriv_dnxhd_get_interlaced(int cid)
>  return ff_dnxhd_cid_table[i].flags & DNXHD_INTERLACED ? 1 : 0;
>  }
>  
> +uint64_t avpriv_dnxhd_parse_header_prefix(const uint8_t *buf)
> +{
> +  uint64_t prefix = AV_RB32(buf);
> +  prefix = (prefix << 16) | buf[4] << 8;
> +  return ff_dnxhd_check_header_prefix(prefix);
> +}
> +

[...]

> +static av_always_inline uint64_t ff_dnxhd_check_header_prefix(uint64_t 
> prefix)
> +{
> +  if (prefix == DNXHD_HEADER_INITIAL ||
> +  prefix == DNXHD_HEADER_444 ||
> +  prefix == DNXHD_HEADER_HR1 ||
> +  prefix == DNXHD_HEADER_HR2)
> +return prefix;
> +  return 0;
> +}

the indention depth is inconsistent with the existing code

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Dictatorship: All citizens are under surveillance, all their steps and
actions recorded, for the politicians to enforce control.
Democracy: All politicians are under surveillance, all their steps and
actions recorded, for the citizens to enforce control.


signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel