[FFmpeg-devel] [PATCH v2 1/9] cbs: Add entrypoint for parser use

Mark Thompson sw at jkqxz.net
Tue Apr 2 02:39:32 EEST 2019


This can avoid copying due to lack of refcounting in parsers.
---
 libavcodec/cbs.c          |  9 +++++++++
 libavcodec/cbs.h          | 14 ++++++++++++++
 libavcodec/cbs_internal.h |  4 ++++
 3 files changed, 27 insertions(+)

diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c
index c388be896b..ff98a1e8f4 100644
--- a/libavcodec/cbs.c
+++ b/libavcodec/cbs.c
@@ -280,6 +280,15 @@ int ff_cbs_read(CodedBitstreamContext *ctx,
     return cbs_read_fragment_content(ctx, frag);
 }
 
+int ff_cbs_parse_headers(CodedBitstreamContext *ctx, void *header,
+                         const uint8_t *data, size_t size)
+{
+    if (!ctx->codec->parse_headers)
+        return AVERROR(ENOSYS);
+
+    return ctx->codec->parse_headers(ctx, header, data, size);
+}
+
 
 int ff_cbs_write_fragment_data(CodedBitstreamContext *ctx,
                                CodedBitstreamFragment *frag)
diff --git a/libavcodec/cbs.h b/libavcodec/cbs.h
index 967dcd1468..be965ae258 100644
--- a/libavcodec/cbs.h
+++ b/libavcodec/cbs.h
@@ -278,6 +278,20 @@ int ff_cbs_read(CodedBitstreamContext *ctx,
                 CodedBitstreamFragment *frag,
                 const uint8_t *data, size_t size);
 
+/**
+ * Parse headers from a bitstream from a memory region, updating state
+ * but not storing intermediate results.
+ *
+ * If header is not NULL, the decomposition of the header of the last
+ * displayed unit in the stream is written there.  The type and size of
+ * this is codec-dependent.
+ *
+ * This is intended for use in parsers where only header parsing is
+ * required and the input is not refcounted.
+ */
+int ff_cbs_parse_headers(CodedBitstreamContext *ctx, void *header,
+                         const uint8_t *data, size_t size);
+
 
 /**
  * Write the content of the fragment to its own internal buffer.
diff --git a/libavcodec/cbs_internal.h b/libavcodec/cbs_internal.h
index 53f2e5d187..9783555292 100644
--- a/libavcodec/cbs_internal.h
+++ b/libavcodec/cbs_internal.h
@@ -55,6 +55,10 @@ typedef struct CodedBitstreamType {
 
     // Free the codec internal state.
     void (*close)(CodedBitstreamContext *ctx);
+
+    // Parse headers only.
+    int (*parse_headers)(CodedBitstreamContext *ctx, void *header,
+                         const uint8_t *data, size_t size);
 } CodedBitstreamType;
 
 
-- 
2.20.1



More information about the ffmpeg-devel mailing list