summaryrefslogtreecommitdiff
path: root/libavcodec/cbs.h
diff options
context:
space:
mode:
authorMark Thompson <sw@jkqxz.net>2018-02-11 00:51:33 +0000
committerMark Thompson <sw@jkqxz.net>2018-02-20 22:04:12 +0000
commitce5870a3a8f2b10668ee4f04c2ae0287f66f31b2 (patch)
tree612022db516c9a96d051e9a55c89b503b99d5112 /libavcodec/cbs.h
parent13ca5d34ba5c473211daaae0a101123bcaada3e6 (diff)
cbs: Refcount all the things!
This makes it easier for users of the CBS API to get alloc/free right - all subelements use the buffer API so that it's clear how to free them. It also allows eliding some redundant copies: the packet -> fragment copy disappears after this change if the input packet is refcounted, and more codec-specific cases are now possible (but not included in this patch).
Diffstat (limited to 'libavcodec/cbs.h')
-rw-r--r--libavcodec/cbs.h51
1 files changed, 42 insertions, 9 deletions
diff --git a/libavcodec/cbs.h b/libavcodec/cbs.h
index ffeca057ab..6505386708 100644
--- a/libavcodec/cbs.h
+++ b/libavcodec/cbs.h
@@ -22,6 +22,8 @@
#include <stddef.h>
#include <stdint.h>
+#include "libavutil/buffer.h"
+
#include "avcodec.h"
@@ -81,6 +83,11 @@ typedef struct CodedBitstreamUnit {
* This supports non-byte-aligned bitstreams.
*/
size_t data_bit_padding;
+ /**
+ * If data is reference counted, a reference to the buffer containing
+ * data. Null if data is not reference counted.
+ */
+ AVBufferRef *data_ref;
/**
* Pointer to the decomposed form of this unit.
@@ -91,11 +98,10 @@ typedef struct CodedBitstreamUnit {
*/
void *content;
/**
- * Whether the content was supplied externally.
- *
- * If so, it should not be freed when freeing the unit.
+ * If content is reference counted, a reference to the buffer containing
+ * content. Null if content is not reference counted.
*/
- int content_external;
+ AVBufferRef *content_ref;
} CodedBitstreamUnit;
/**
@@ -123,6 +129,11 @@ typedef struct CodedBitstreamFragment {
* The number of bits which should be ignored in the final byte.
*/
size_t data_bit_padding;
+ /**
+ * If data is reference counted, a reference to the buffer containing
+ * data. Null if data is not reference counted.
+ */
+ AVBufferRef *data_ref;
/**
* Number of units in this fragment.
@@ -279,27 +290,49 @@ void ff_cbs_fragment_uninit(CodedBitstreamContext *ctx,
/**
+ * Allocate a new internal content buffer of the given size in the unit.
+ *
+ * The content will be zeroed.
+ */
+int ff_cbs_alloc_unit_content(CodedBitstreamContext *ctx,
+ CodedBitstreamUnit *unit,
+ size_t size,
+ void (*free)(void *unit, uint8_t *content));
+
+/**
+ * Allocate a new internal data buffer of the given size in the unit.
+ *
+ * The data buffer will have input padding.
+ */
+int ff_cbs_alloc_unit_data(CodedBitstreamContext *ctx,
+ CodedBitstreamUnit *unit,
+ size_t size);
+
+/**
* Insert a new unit into a fragment with the given content.
*
- * The content structure continues to be owned by the caller, and
- * will not be freed when the unit is.
+ * The content structure continues to be owned by the caller if
+ * content_buf is not supplied.
*/
int ff_cbs_insert_unit_content(CodedBitstreamContext *ctx,
CodedBitstreamFragment *frag,
int position,
CodedBitstreamUnitType type,
- void *content);
+ void *content,
+ AVBufferRef *content_buf);
/**
* Insert a new unit into a fragment with the given data bitstream.
*
- * The data buffer will be owned by the unit after this operation.
+ * If data_buf is not supplied then data must have been allocated with
+ * av_malloc() and will become owned by the unit after this call.
*/
int ff_cbs_insert_unit_data(CodedBitstreamContext *ctx,
CodedBitstreamFragment *frag,
int position,
CodedBitstreamUnitType type,
- uint8_t *data, size_t data_size);
+ uint8_t *data, size_t data_size,
+ AVBufferRef *data_buf);
/**
* Delete a unit from a fragment and free all memory it uses.