Go to the documentation of this file.
34 size_t new_alloc_size;
36 if (
ctx->auxiliary_info_size +
size >
ctx->auxiliary_info_alloc_size) {
37 new_alloc_size =
FFMAX(
ctx->auxiliary_info_size +
size,
ctx->auxiliary_info_alloc_size * 2);
42 ctx->auxiliary_info_alloc_size = new_alloc_size;
49 const uint8_t *buf_in,
int size)
57 memcpy(
ctx->auxiliary_info +
ctx->auxiliary_info_size, buf_in,
size);
58 ctx->auxiliary_info_size +=
size;
64 uint16_t clear_bytes, uint32_t encrypted_bytes)
69 if (!
ctx->use_subsamples) {
78 p =
ctx->auxiliary_info +
ctx->auxiliary_info_size;
81 p +=
sizeof(uint16_t);
85 ctx->auxiliary_info_size += 6;
86 ctx->subsample_count++;
95 const uint8_t *buf_in,
int size)
98 const uint8_t* cur_pos = buf_in;
102 while (size_left > 0) {
103 cur_size =
FFMIN(size_left,
sizeof(chunk));
107 size_left -= cur_size;
124 if (!
ctx->use_subsamples) {
129 ctx->auxiliary_info_subsample_start =
ctx->auxiliary_info_size;
130 ctx->subsample_count = 0;
144 size_t new_alloc_size;
148 if (!
ctx->use_subsamples) {
149 ctx->auxiliary_info_entries++;
154 if (
ctx->auxiliary_info_entries >=
ctx->auxiliary_info_sizes_alloc_size) {
155 new_alloc_size =
ctx->auxiliary_info_entries * 2 + 1;
160 ctx->auxiliary_info_sizes_alloc_size = new_alloc_size;
162 ctx->auxiliary_info_sizes[
ctx->auxiliary_info_entries] =
164 ctx->auxiliary_info_entries++;
167 AV_WB16(
ctx->auxiliary_info +
ctx->auxiliary_info_subsample_start,
ctx->subsample_count);
173 const uint8_t *buf_in,
int size)
198 const uint8_t *buf_in,
int size)
200 const uint8_t *p = buf_in;
201 const uint8_t *end = p +
size;
202 const uint8_t *nal_start, *nal_end;
213 while (nal_start < end && !*(nal_start++));
214 if (nal_start == end)
225 size += 4 + nal_end - nal_start;
251 if (
size < nal_length_size + 1) {
253 size, nal_length_size + 1);
260 for (j = 0; j < nal_length_size; j++) {
261 nalsize = (nalsize << 8) | *buf_in++;
263 size -= nal_length_size;
266 if (nalsize <= 0 || nalsize >
size) {
291 size_t tgh_data_size = tile_group->
data_size;
297 fh_data_size -= tgh_data_size;
301 if (
ctx->tile_num < cur_tile_num) {
303 sizeof(*
ctx->tile_group_sizes));
309 ctx->tile_num = cur_tile_num;
311 total = fh_data_size + tgh_data_size;
312 ctx->clear_bytes += total;
317 for (
unsigned tile_num = tile_group->
tg_start; tile_num <= tile_group->tg_end; tile_num++) {
318 uint32_t encrypted_bytes, tile_size_bytes, tile_size = 0;
320 if (tile_num == tile_group->
tg_end) {
322 encrypted_bytes = tile_size & ~0xF
U;
323 ctx->clear_bytes += tile_size & 0xF
U;
325 ctx->tile_group_sizes[tile_num].encrypted_bytes = encrypted_bytes;
326 ctx->tile_group_sizes[tile_num].aux_clear_bytes = encrypted_bytes ?
ctx->clear_bytes : 0;
327 ctx->tile_group_sizes[tile_num].write_clear_bytes = tile_size & 0xF
U;
330 ctx->clear_bytes = 0;
336 tile_size_bytes =
frame_header->tile_size_bytes_minus1 + 1;
340 for (
int i = 0;
i < tile_size_bytes;
i++)
341 tile_size |= bytestream2_get_byteu(&gb) << 8 *
i;
347 encrypted_bytes = tile_size & ~0xF
U;
348 ctx->clear_bytes += (tile_size & 0xF
U) + tile_size_bytes;
350 ctx->tile_group_sizes[tile_num].encrypted_bytes = encrypted_bytes;
351 ctx->tile_group_sizes[tile_num].aux_clear_bytes = encrypted_bytes ?
ctx->clear_bytes : 0;
352 ctx->tile_group_sizes[tile_num].write_clear_bytes = (tile_size & 0xF
U) + tile_size_bytes;
355 ctx->clear_bytes = 0;
357 total += tile_size + tile_size_bytes;
366 for (
unsigned tile_num = tile_group->
tg_start; tile_num <= tile_group->tg_end; tile_num++) {
373 if (
sizes->encrypted_bytes) {
374 unsigned clear_bytes =
sizes->aux_clear_bytes;
375 if (clear_bytes > UINT16_MAX) {
377 clear_bytes -= UINT16_MAX;
392 const uint8_t *fh_data =
NULL;
401 ret = ff_lavf_cbs_read_packet(
ctx->cbc, td,
pkt);
417 switch (unit->
type) {
421 fh_data = unit->
data;
434 fh_data = unit->
data;
467 if (
ctx->clear_bytes)
469 ctx->clear_bytes = 0;
479 ff_lavf_cbs_fragment_reset(td);
495 int64_t* auxiliary_info_offset)
515 version = auxiliary_info_offset > 0xffffffff ? 1 : 0;
535 if (
ctx->use_subsamples) {
618 ctx->use_subsamples = use_subsamples;
639 ff_lavf_cbs_fragment_free(&
ctx->temporal_unit);
640 ff_lavf_cbs_close(&
ctx->cbc);
static int mov_cenc_write_senc_tag(MOVMuxCencContext *ctx, AVIOContext *pb, int64_t *auxiliary_info_offset)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
static av_always_inline void ffio_wfourcc(AVIOContext *pb, const uint8_t *s)
static int mov_cenc_write_saio_tag(AVIOContext *pb, int64_t auxiliary_info_offset)
static int auxiliary_info_alloc_size(MOVMuxCencContext *ctx, int size)
static void mov_cenc_write_encrypted(MOVMuxCencContext *ctx, AVIOContext *pb, const uint8_t *buf_in, int size)
Encrypt the input buffer and write using avio_write.
void * content
Pointer to the decomposed form of this unit.
static av_always_inline void bytestream2_skipu(GetByteContext *g, unsigned int size)
static int mov_cenc_end_packet(MOVMuxCencContext *ctx)
Finalize a packet.
CodedBitstreamUnitType type
Codec-specific type of this unit.
void av_aes_ctr_set_random_iv(struct AVAESCTR *a)
Generate a random iv.
static int mov_cenc_start_packet(MOVMuxCencContext *ctx)
Start writing a packet.
@ AV1_OBU_TEMPORAL_DELIMITER
Coded bitstream unit structure.
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
uint8_t * data
Pointer to the directly-parsable bitstream form of this unit.
void ff_mov_cenc_free(MOVMuxCencContext *ctx)
Free a CENC context.
CodedBitstreamUnit * units
Pointer to an array of units of length nb_units_allocated.
static int mov_cenc_write_schi_tag(AVIOContext *pb, uint8_t *kid)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
Coded bitstream fragment structure, combining one or more units.
static int64_t update_size(AVIOContext *pb, int64_t pos)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
uint32_t CodedBitstreamUnitType
The codec-specific type of a bitstream unit.
const uint8_t * av_aes_ctr_get_iv(struct AVAESCTR *a)
Get the current iv.
static const int sizes[][2]
struct AVAESCTR * av_aes_ctr_alloc(void)
Allocate an AVAESCTR context.
int ff_mov_cenc_avc_write_nal_units(AVFormatContext *s, MOVMuxCencContext *ctx, int nal_length_size, AVIOContext *pb, const uint8_t *buf_in, int size)
Write AVC NAL units that are in MP4 format, the nal size and type are written in the clear while the ...
size_t data_size
The number of bytes in the bitstream (including any padding bits in the final byte).
void avio_w8(AVIOContext *s, int b)
static av_always_inline int bytestream2_get_bytes_left(GetByteContext *g)
AVCodecID
Identify the syntax and semantics of the bitstream.
int ff_mov_cenc_av1_write_obus(AVFormatContext *s, MOVMuxCencContext *ctx, AVIOContext *pb, const AVPacket *pkt)
int av_aes_ctr_init(struct AVAESCTR *a, const uint8_t *key)
Initialize an AVAESCTR context.
void ff_mov_cenc_write_stbl_atoms(MOVMuxCencContext *ctx, AVIOContext *pb, int64_t moof_offset)
Write the cenc atoms that should reside inside stbl.
static int mov_cenc_write_saiz_tag(MOVMuxCencContext *ctx, AVIOContext *pb)
int ff_mov_cenc_write_packet(MOVMuxCencContext *ctx, AVIOContext *pb, const uint8_t *buf_in, int size)
Write a fully encrypted packet.
int av_reallocp(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory through a pointer to a pointer.
@ AV1_OBU_SEQUENCE_HEADER
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
void avio_wb32(AVIOContext *s, unsigned int val)
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
Allocate, reallocate an array through a pointer to a pointer.
void avio_wl32(AVIOContext *s, unsigned int val)
AV1RawFrameHeader frame_header
void av_aes_ctr_free(struct AVAESCTR *a)
Release an AVAESCTR context.
static int auxiliary_info_write(MOVMuxCencContext *ctx, const uint8_t *buf_in, int size)
#define i(width, name, range_min, range_max)
int ff_mov_cenc_init(MOVMuxCencContext *ctx, uint8_t *encryption_key, int use_subsamples, enum AVCodecID codec_id, int bitexact)
Initialize a CENC context.
AV1RawTileGroup tile_group
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
int ff_mov_cenc_write_sinf_tag(MOVTrack *track, AVIOContext *pb, uint8_t *kid)
Write the sinf atom, contained inside stsd.
static int auxiliary_info_add_subsample(MOVMuxCencContext *ctx, uint16_t clear_bytes, uint32_t encrypted_bytes)
AV1RawSequenceHeader * sequence_header
static int write_tiles(AVFormatContext *s, MOVMuxCencContext *ctx, AVIOContext *pb, AV1_OBU_Type type, const AV1RawFrameHeader *frame_header, const uint8_t *fh_data, size_t fh_data_size, const AV1RawTileGroup *tile_group)
void av_aes_ctr_increment_iv(struct AVAESCTR *a)
Increment the top 64 bit of the iv (performed after each frame)
void av_aes_ctr_crypt(struct AVAESCTR *a, uint8_t *dst, const uint8_t *src, int count)
Process a buffer using a previously initialized context.
void avio_wb64(AVIOContext *s, uint64_t val)
static const CodedBitstreamUnitType decompose_unit_types[]
AV1RawTileGroup tile_group
void avio_wb24(AVIOContext *s, unsigned int val)
This structure stores compressed data.
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
int ff_mov_cenc_avc_parse_nal_units(MOVMuxCencContext *ctx, AVIOContext *pb, const uint8_t *buf_in, int size)
Parse AVC NAL units from annex B format, the nal size and type are written in the clear while the bod...
const uint8_t * ff_nal_find_startcode(const uint8_t *p, const uint8_t *end)
void * priv_data
Format private data.
int nb_units
Number of units in this fragment.