aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/cbs_h2645.c
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2023-09-13 01:01:16 +0200
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2023-10-07 22:35:14 +0200
commit3ba4f9c21e8bd78386738324d8767d74d75eec53 (patch)
treec0c9127edbbeaad333ffb4bcb2e5bc78b7b2c6a7 /libavcodec/cbs_h2645.c
parent3e9b8d14e5d0df72765a1c9ca683c9d0f1d51e1a (diff)
downloadffmpeg-3ba4f9c21e8bd78386738324d8767d74d75eec53.tar.gz
avcodec/cbs_sei: Use RefStruct API for SEI messages
The SEI message code uses the AVBuffer API for its SEI messages and contained buffers (like the extension buffer for HEVC or the user data (un)registered payload buffers). Contrary to the ordinary CBS code (where some of these contained buffer references are actually references to the provided AVPacket's data so that one can't replace them with the RefStruct API), the CBS SEI code never uses outside buffers at all and can therefore be switched entirely to the RefStruct API. This avoids the overhead inherent in the AVBuffer API (namely the separate allocations etc.). Notice that the refcounting here is actually currently unused; the refcounts are always one (or zero in case of no refcounting); its only advantage is the flexibility provided by custom free functions. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavcodec/cbs_h2645.c')
-rw-r--r--libavcodec/cbs_h2645.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index cce3f31d4f..615a7cf5ec 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -331,18 +331,31 @@ static int cbs_h2645_read_more_rbsp_data(GetBitContext *gbc)
#define bit_position(rw) (get_bits_count(rw))
#define byte_alignment(rw) (get_bits_count(rw) % 8)
+/* The CBS SEI code uses the refstruct API for the allocation
+ * of its child buffers. */
#define allocate(name, size) do { \
- name ## _ref = av_buffer_allocz(size + \
+ name = ff_refstruct_allocz(size + \
AV_INPUT_BUFFER_PADDING_SIZE); \
- if (!name ## _ref) \
+ if (!name) \
return AVERROR(ENOMEM); \
- name = name ## _ref->data; \
} while (0)
#define FUNC(name) FUNC_SEI(name)
#include "cbs_sei_syntax_template.c"
#undef FUNC
+#undef allocate
+
+/* The other code uses the refstruct API for the allocation
+ * of its child buffers. */
+#define allocate(name, size) do { \
+ name ## _ref = av_buffer_allocz(size + \
+ AV_INPUT_BUFFER_PADDING_SIZE); \
+ if (!name ## _ref) \
+ return AVERROR(ENOMEM); \
+ name = name ## _ref->data; \
+ } while (0)
+
#define FUNC(name) FUNC_H264(name)
#include "cbs_h264_syntax_template.c"
#undef FUNC