* H.264 / AVC: nal_unit_type
* H.265 / HEVC: nal_unit_type
* MPEG-2: start code value (without prefix)
+ * VP9: unused, set to zero (every unit is a frame)
*/
typedef uint32_t CodedBitstreamUnitType;
*/
size_t data_bit_padding;
/**
- * If data is reference counted, a reference to the buffer containing
- * data. Null if data is not reference counted.
+ * A reference to the buffer containing data.
+ *
+ * Must be set if data is not NULL.
*/
AVBufferRef *data_ref;
*/
size_t data_bit_padding;
/**
- * If data is reference counted, a reference to the buffer containing
- * data. Null if data is not reference counted.
+ * A reference to the buffer containing data.
+ *
+ * Must be set if data is not NULL.
*/
AVBufferRef *data_ref;
* and has not been decomposed.
*/
int nb_units;
+
+ /**
+ * Number of allocated units.
+ *
+ * Must always be >= nb_units; designed for internal use by cbs.
+ */
+ int nb_units_allocated;
+
/**
- * Pointer to an array of units of length nb_units.
+ * Pointer to an array of units of length nb_units_allocated.
+ * Only the first nb_units are valid.
*
- * Must be NULL if nb_units is zero.
+ * Must be NULL if nb_units_allocated is zero.
*/
CodedBitstreamUnit *units;
} CodedBitstreamFragment;
* This also updates the internal state, so will need to be called for
* codecs with extradata to read parameter sets necessary for further
* parsing even if the fragment itself is not desired.
+ *
+ * The fragment must have been zeroed or reset via ff_cbs_fragment_reset
+ * before use.
*/
int ff_cbs_read_extradata(CodedBitstreamContext *ctx,
CodedBitstreamFragment *frag,
* This also updates the internal state of the coded bitstream context
* with any persistent data from the fragment which may be required to
* read following fragments (e.g. parameter sets).
+ *
+ * The fragment must have been zeroed or reset via ff_cbs_fragment_reset
+ * before use.
*/
int ff_cbs_read_packet(CodedBitstreamContext *ctx,
CodedBitstreamFragment *frag,
* This also updates the internal state of the coded bitstream context
* with any persistent data from the fragment which may be required to
* read following fragments (e.g. parameter sets).
+ *
+ * The fragment must have been zeroed or reset via ff_cbs_fragment_reset
+ * before use.
*/
int ff_cbs_read(CodedBitstreamContext *ctx,
CodedBitstreamFragment *frag,
/**
* Write the bitstream of a fragment to the extradata in codec parameters.
*
- * This replaces any existing extradata in the structure.
+ * Modifies context and fragment as ff_cbs_write_fragment_data does and
+ * replaces any existing extradata in the structure.
*/
int ff_cbs_write_extradata(CodedBitstreamContext *ctx,
AVCodecParameters *par,
/**
* Write the bitstream of a fragment to a packet.
+ *
+ * Modifies context and fragment as ff_cbs_write_fragment_data does.
+ *
+ * On success, the packet's buf is unreferenced and its buf, data and
+ * size fields are set to the corresponding values from the newly updated
+ * fragment; other fields are not touched. On failure, the packet is not
+ * touched at all.
*/
int ff_cbs_write_packet(CodedBitstreamContext *ctx,
AVPacket *pkt,
/**
- * Free all allocated memory in a fragment.
+ * Free the units contained in a fragment as well as the fragment's
+ * own data buffer, but not the units array itself.
*/
-void ff_cbs_fragment_uninit(CodedBitstreamContext *ctx,
+void ff_cbs_fragment_reset(CodedBitstreamContext *ctx,
CodedBitstreamFragment *frag);
+/**
+ * Free the units array of a fragment in addition to what
+ * ff_cbs_fragment_reset does.
+ */
+void ff_cbs_fragment_free(CodedBitstreamContext *ctx,
+ CodedBitstreamFragment *frag);
/**
* Allocate a new internal content buffer of the given size in the unit.