Go to the documentation of this file.
35 size_t new_alloc_size;
37 if (
ctx->auxiliary_info_size +
size >
ctx->auxiliary_info_alloc_size) {
38 new_alloc_size =
FFMAX(
ctx->auxiliary_info_size +
size,
ctx->auxiliary_info_alloc_size * 2);
43 ctx->auxiliary_info_alloc_size = new_alloc_size;
50 const uint8_t *buf_in,
int size)
58 memcpy(
ctx->auxiliary_info +
ctx->auxiliary_info_size, buf_in,
size);
59 ctx->auxiliary_info_size +=
size;
65 uint16_t clear_bytes, uint32_t encrypted_bytes)
70 if (!
ctx->use_subsamples) {
79 p =
ctx->auxiliary_info +
ctx->auxiliary_info_size;
82 p +=
sizeof(uint16_t);
86 ctx->auxiliary_info_size += 6;
87 ctx->subsample_count++;
96 const uint8_t *buf_in,
int size)
99 const uint8_t* cur_pos = buf_in;
100 int size_left =
size;
103 while (size_left > 0) {
104 cur_size =
FFMIN(size_left,
sizeof(chunk));
108 size_left -= cur_size;
125 if (!
ctx->use_subsamples) {
130 ctx->auxiliary_info_subsample_start =
ctx->auxiliary_info_size;
131 ctx->subsample_count = 0;
145 size_t new_alloc_size;
149 if (!
ctx->use_subsamples) {
150 ctx->auxiliary_info_entries++;
155 if (
ctx->auxiliary_info_entries >=
ctx->auxiliary_info_sizes_alloc_size) {
156 new_alloc_size =
ctx->auxiliary_info_entries * 2 + 1;
161 ctx->auxiliary_info_sizes_alloc_size = new_alloc_size;
163 ctx->auxiliary_info_sizes[
ctx->auxiliary_info_entries] =
165 ctx->auxiliary_info_entries++;
168 AV_WB16(
ctx->auxiliary_info +
ctx->auxiliary_info_subsample_start,
ctx->subsample_count);
174 const uint8_t *buf_in,
int size)
199 const uint8_t *buf_in,
int size)
201 const uint8_t *
p = buf_in;
202 const uint8_t *end =
p +
size;
203 const uint8_t *nal_start, *nal_end;
214 while (nal_start < end && !*(nal_start++));
215 if (nal_start == end)
226 size += 4 + nal_end - nal_start;
252 if (
size < nal_length_size + 1) {
254 size, nal_length_size + 1);
261 for (j = 0; j < nal_length_size; j++) {
262 nalsize = (nalsize << 8) | *buf_in++;
264 size -= nal_length_size;
267 if (nalsize <= 0 || nalsize >
size) {
292 size_t tgh_data_size = tile_group->
data_size;
298 fh_data_size -= tgh_data_size;
302 if (
ctx->tile_num < cur_tile_num) {
304 sizeof(*
ctx->tile_group_sizes));
310 ctx->tile_num = cur_tile_num;
312 total = fh_data_size + tgh_data_size;
313 ctx->clear_bytes += total;
318 for (
unsigned tile_num = tile_group->
tg_start; tile_num <= tile_group->tg_end; tile_num++) {
319 uint32_t encrypted_bytes, tile_size_bytes, tile_size = 0;
321 if (tile_num == tile_group->
tg_end) {
323 encrypted_bytes = tile_size & ~0xF
U;
324 ctx->clear_bytes += tile_size & 0xF
U;
326 ctx->tile_group_sizes[tile_num].encrypted_bytes = encrypted_bytes;
327 ctx->tile_group_sizes[tile_num].aux_clear_bytes = encrypted_bytes ?
ctx->clear_bytes : 0;
328 ctx->tile_group_sizes[tile_num].write_clear_bytes = tile_size & 0xF
U;
331 ctx->clear_bytes = 0;
337 tile_size_bytes =
frame_header->tile_size_bytes_minus1 + 1;
341 for (
int i = 0;
i < tile_size_bytes;
i++)
342 tile_size |= bytestream2_get_byteu(&gb) << 8 *
i;
348 encrypted_bytes = tile_size & ~0xF
U;
349 ctx->clear_bytes += (tile_size & 0xF
U) + tile_size_bytes;
351 ctx->tile_group_sizes[tile_num].encrypted_bytes = encrypted_bytes;
352 ctx->tile_group_sizes[tile_num].aux_clear_bytes = encrypted_bytes ?
ctx->clear_bytes : 0;
353 ctx->tile_group_sizes[tile_num].write_clear_bytes = (tile_size & 0xF
U) + tile_size_bytes;
356 ctx->clear_bytes = 0;
358 total += tile_size + tile_size_bytes;
367 for (
unsigned tile_num = tile_group->
tg_start; tile_num <= tile_group->tg_end; tile_num++) {
374 if (
sizes->encrypted_bytes) {
375 unsigned clear_bytes =
sizes->aux_clear_bytes;
376 if (clear_bytes > UINT16_MAX) {
378 clear_bytes -= UINT16_MAX;
393 const uint8_t *fh_data =
NULL;
402 ret = ff_lavf_cbs_read_packet(
ctx->cbc, td,
pkt);
418 switch (unit->
type) {
422 fh_data = unit->
data;
435 fh_data = unit->
data;
468 if (
ctx->clear_bytes)
470 ctx->clear_bytes = 0;
480 ff_lavf_cbs_fragment_reset(td);
496 int64_t* auxiliary_info_offset)
516 version = auxiliary_info_offset > 0xffffffff ? 1 : 0;
536 if (
ctx->use_subsamples) {
619 ctx->use_subsamples = use_subsamples;
635 ctx->auxiliary_info_entries = 0;
636 ctx->auxiliary_info_size = 0;
646 ff_lavf_cbs_fragment_free(&
ctx->temporal_unit);
647 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 int bytestream2_get_bytes_left(const GetByteContext *g)
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.
static AVFormatContext * ctx
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)
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.
#define i(width, name, range_min, range_max)
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)
void ff_mov_cenc_flush(MOVMuxCencContext *ctx)
Clear subsample data.
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)
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
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.