[libav-devel] [PATCH 02/11] cbs: Add an explicit type for coded bitstream unit types

Mark Thompson sw at jkqxz.net
Wed Nov 29 23:11:54 CET 2017


Also fix conversion specifiers used for the unit type.
---
 libavcodec/cbs.c       | 12 +++++++-----
 libavcodec/cbs.h       | 19 +++++++++++++++----
 libavcodec/cbs_h2645.c |  2 +-
 libavcodec/cbs_mpeg2.c |  4 ++--
 4 files changed, 25 insertions(+), 12 deletions(-)

diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c
index fd9baa299..e5819afce 100644
--- a/libavcodec/cbs.c
+++ b/libavcodec/cbs.c
@@ -137,10 +137,10 @@ static int cbs_read_fragment_content(CodedBitstreamContext *ctx,
         if (err == AVERROR(ENOSYS)) {
             av_log(ctx->log_ctx, AV_LOG_WARNING,
                    "Decomposition unimplemented for unit %d "
-                   "(type %d).\n", i, frag->units[i].type);
+                   "(type %"PRIu32").\n", i, frag->units[i].type);
         } else if (err < 0) {
             av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to read unit %d "
-                   "(type %d).\n", i, frag->units[i].type);
+                   "(type %"PRIu32").\n", i, frag->units[i].type);
             return err;
         }
     }
@@ -225,7 +225,7 @@ int ff_cbs_write_fragment_data(CodedBitstreamContext *ctx,
         err = ctx->codec->write_unit(ctx, &frag->units[i]);
         if (err < 0) {
             av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to write unit %d "
-                   "(type %d).\n", i, frag->units[i].type);
+                   "(type %"PRIu32").\n", i, frag->units[i].type);
             return err;
         }
     }
@@ -421,7 +421,8 @@ static int cbs_insert_unit(CodedBitstreamContext *ctx,
 
 int ff_cbs_insert_unit_content(CodedBitstreamContext *ctx,
                                CodedBitstreamFragment *frag,
-                               int position, uint32_t type,
+                               int position,
+                               CodedBitstreamUnitType type,
                                void *content)
 {
     int err;
@@ -443,7 +444,8 @@ int ff_cbs_insert_unit_content(CodedBitstreamContext *ctx,
 
 int ff_cbs_insert_unit_data(CodedBitstreamContext *ctx,
                             CodedBitstreamFragment *frag,
-                            int position, uint32_t type,
+                            int position,
+                            CodedBitstreamUnitType type,
                             uint8_t *data, size_t data_size)
 {
     int err;
diff --git a/libavcodec/cbs.h b/libavcodec/cbs.h
index 34ee78be3..85c7b5557 100644
--- a/libavcodec/cbs.h
+++ b/libavcodec/cbs.h
@@ -28,6 +28,15 @@
 struct CodedBitstreamType;
 
 /**
+ * The codec-specific type of a bitstream unit.
+ *
+ * H.264 / AVC: nal_unit_type
+ * H.265 / HEVC: nal_unit_type
+ * MPEG-2: start code value (without prefix)
+ */
+typedef uint32_t CodedBitstreamUnitType;
+
+/**
  * Coded bitstream unit structure.
  *
  * A bitstream unit the the smallest element of a bitstream which
@@ -40,7 +49,7 @@ typedef struct CodedBitstreamUnit {
     /**
      * Codec-specific type of this unit.
      */
-    uint32_t type;
+    CodedBitstreamUnitType type;
 
     /**
      * Pointer to the bitstream form of this unit.
@@ -149,7 +158,7 @@ typedef struct CodedBitstreamContext {
      * Types not in this list will be available in bitstream form only.
      * If NULL, all supported types will be decomposed.
      */
-    uint32_t *decompose_unit_types;
+    CodedBitstreamUnitType *decompose_unit_types;
     /**
      * Length of the decompose_unit_types array.
      */
@@ -250,7 +259,8 @@ void ff_cbs_fragment_uninit(CodedBitstreamContext *ctx,
  */
 int ff_cbs_insert_unit_content(CodedBitstreamContext *ctx,
                                CodedBitstreamFragment *frag,
-                               int position, uint32_t type,
+                               int position,
+                               CodedBitstreamUnitType type,
                                void *content);
 
 /**
@@ -260,7 +270,8 @@ int ff_cbs_insert_unit_content(CodedBitstreamContext *ctx,
  */
 int ff_cbs_insert_unit_data(CodedBitstreamContext *ctx,
                             CodedBitstreamFragment *frag,
-                            int position, uint32_t type,
+                            int position,
+                            CodedBitstreamUnitType type,
                             uint8_t *data, size_t data_size);
 
 /**
diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index 61729ccbb..2006aaa3f 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -1207,7 +1207,7 @@ static int cbs_h265_write_nal_unit(CodedBitstreamContext *ctx,
 
     default:
         av_log(ctx->log_ctx, AV_LOG_ERROR, "Write unimplemented for "
-               "NAL unit type %d.\n", unit->type);
+               "NAL unit type %"PRIu32".\n", unit->type);
         return AVERROR_PATCHWELCOME;
     }
 
diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c
index 3c09377df..3a41e5452 100644
--- a/libavcodec/cbs_mpeg2.c
+++ b/libavcodec/cbs_mpeg2.c
@@ -217,7 +217,7 @@ static int cbs_mpeg2_read_unit(CodedBitstreamContext *ctx,
             START(0xb8, MPEG2RawGroupOfPicturesHeader, group_of_pictures_header);
 #undef START
         default:
-            av_log(ctx->log_ctx, AV_LOG_ERROR, "Unknown start code %02x.\n",
+            av_log(ctx->log_ctx, AV_LOG_ERROR, "Unknown start code %02"PRIx32".\n",
                    unit->type);
             return AVERROR_INVALIDDATA;
         }
@@ -245,7 +245,7 @@ static int cbs_mpeg2_write_header(CodedBitstreamContext *ctx,
 #undef START
     default:
         av_log(ctx->log_ctx, AV_LOG_ERROR, "Write unimplemented for start "
-               "code %02x.\n", unit->type);
+               "code %02"PRIx32".\n", unit->type);
         return AVERROR_PATCHWELCOME;
     }
 
-- 
2.11.0



More information about the libav-devel mailing list