aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/cbs.h
diff options
context:
space:
mode:
authorMark Thompson <sw@jkqxz.net>2023-09-11 15:52:26 +0800
committerHaihao Xiang <haihao.xiang@intel.com>2023-09-22 13:15:00 +0800
commitabe16daea1b72323e3544cb6ec12bec010b6ba54 (patch)
tree11f6d79648bf2b85829d4f95fc029d8ff22dc1a2 /libavcodec/cbs.h
parent6c3a5d625f917631d1c8bab31ed65ebe26d14f47 (diff)
downloadffmpeg-abe16daea1b72323e3544cb6ec12bec010b6ba54.tar.gz
cbs: Make tracing more general
Turn tracing into callbacks for each syntax element, with default callbacks to match current trace_headers behaviour for debug. Move the construction of bit strings into the trace callback, which simplifies all of the read and write functions. Signed-off-by: Fei Wang <fei.w.wang@intel.com> Reviewed-by: Neal Gompa <ngompa13@gmail.com>
Diffstat (limited to 'libavcodec/cbs.h')
-rw-r--r--libavcodec/cbs.h88
1 files changed, 87 insertions, 1 deletions
diff --git a/libavcodec/cbs.h b/libavcodec/cbs.h
index b4131db5fe..ffb2797761 100644
--- a/libavcodec/cbs.h
+++ b/libavcodec/cbs.h
@@ -168,6 +168,51 @@ typedef struct CodedBitstreamFragment {
CodedBitstreamUnit *units;
} CodedBitstreamFragment;
+
+struct CodedBitstreamContext;
+struct GetBitContext;
+struct PutBitContext;
+
+/**
+ * Callback type for read tracing.
+ *
+ * @param ctx User-set trace context.
+ * @param gbc A GetBitContext set at the start of the syntax
+ * element. This is a copy, the callee does not
+ * need to preserve it.
+ * @param length Length in bits of the syntax element.
+ * @param name String name of the syntax elements.
+ * @param subscripts If the syntax element is an array, a pointer to
+ * an array of subscripts into the array.
+ * @param value Parsed value of the syntax element.
+ */
+typedef void (*CBSTraceReadCallback)(void *trace_context,
+ struct GetBitContext *gbc,
+ int start_position,
+ const char *name,
+ const int *subscripts,
+ int64_t value);
+
+/**
+ * Callback type for write tracing.
+ *
+ * @param ctx User-set trace context.
+ * @param pbc A PutBitContext set at the end of the syntax
+ * element. The user must not modify this, but may
+ * inspect it to determine state.
+ * @param length Length in bits of the syntax element.
+ * @param name String name of the syntax elements.
+ * @param subscripts If the syntax element is an array, a pointer to
+ * an array of subscripts into the array.
+ * @param value Written value of the syntax element.
+ */
+typedef void (*CBSTraceWriteCallback)(void *trace_context,
+ struct PutBitContext *pbc,
+ int start_position,
+ const char *name,
+ const int *subscripts,
+ int64_t value);
+
/**
* Context structure for coded bitstream operations.
*/
@@ -211,11 +256,29 @@ typedef struct CodedBitstreamContext {
*/
int trace_enable;
/**
- * Log level to use for trace output.
+ * Log level to use for default trace output.
*
* From AV_LOG_*; defaults to AV_LOG_TRACE.
*/
int trace_level;
+ /**
+ * User context pointer to pass to trace callbacks.
+ */
+ void *trace_context;
+ /**
+ * Callback for read tracing.
+ *
+ * If tracing is enabled then this is called once for each syntax
+ * element parsed.
+ */
+ CBSTraceReadCallback trace_read_callback;
+ /**
+ * Callback for write tracing.
+ *
+ * If tracing is enabled then this is called once for each syntax
+ * element written.
+ */
+ CBSTraceWriteCallback trace_write_callback;
/**
* Write buffer. Used as intermediate buffer when writing units.
@@ -450,4 +513,27 @@ void ff_cbs_discard_units(CodedBitstreamContext *ctx,
enum AVDiscard skip,
int flags);
+
+/**
+ * Helper function for read tracing which formats the syntax element
+ * and logs the result.
+ *
+ * Trace context should be set to the CodedBitstreamContext.
+ */
+void ff_cbs_trace_read_log(void *trace_context,
+ struct GetBitContext *gbc, int length,
+ const char *str, const int *subscripts,
+ int64_t value);
+
+/**
+ * Helper function for write tracing which formats the syntax element
+ * and logs the result.
+ *
+ * Trace context should be set to the CodedBitstreamContext.
+ */
+void ff_cbs_trace_write_log(void *trace_context,
+ struct PutBitContext *pbc, int length,
+ const char *str, const int *subscripts,
+ int64_t value);
+
#endif /* AVCODEC_CBS_H */