Go to the documentation of this file.
30 size_t new_alloc_size;
32 if (
ctx->auxiliary_info_size +
size >
ctx->auxiliary_info_alloc_size) {
33 new_alloc_size =
FFMAX(
ctx->auxiliary_info_size +
size,
ctx->auxiliary_info_alloc_size * 2);
38 ctx->auxiliary_info_alloc_size = new_alloc_size;
45 const uint8_t *buf_in,
int size)
53 memcpy(
ctx->auxiliary_info +
ctx->auxiliary_info_size, buf_in,
size);
54 ctx->auxiliary_info_size +=
size;
60 uint16_t clear_bytes, uint32_t encrypted_bytes)
65 if (!
ctx->use_subsamples) {
74 p =
ctx->auxiliary_info +
ctx->auxiliary_info_size;
77 p +=
sizeof(uint16_t);
81 ctx->auxiliary_info_size += 6;
82 ctx->subsample_count++;
91 const uint8_t *buf_in,
int size)
94 const uint8_t* cur_pos = buf_in;
98 while (size_left > 0) {
99 cur_size =
FFMIN(size_left,
sizeof(chunk));
103 size_left -= cur_size;
120 if (!
ctx->use_subsamples) {
125 ctx->auxiliary_info_subsample_start =
ctx->auxiliary_info_size;
126 ctx->subsample_count = 0;
140 size_t new_alloc_size;
144 if (!
ctx->use_subsamples) {
145 ctx->auxiliary_info_entries++;
150 if (
ctx->auxiliary_info_entries >=
ctx->auxiliary_info_sizes_alloc_size) {
151 new_alloc_size =
ctx->auxiliary_info_entries * 2 + 1;
156 ctx->auxiliary_info_sizes_alloc_size = new_alloc_size;
158 ctx->auxiliary_info_sizes[
ctx->auxiliary_info_entries] =
160 ctx->auxiliary_info_entries++;
163 AV_WB16(
ctx->auxiliary_info +
ctx->auxiliary_info_subsample_start,
ctx->subsample_count);
169 const uint8_t *buf_in,
int size)
194 const uint8_t *buf_in,
int size)
196 const uint8_t *p = buf_in;
197 const uint8_t *end = p +
size;
198 const uint8_t *nal_start, *nal_end;
209 while (nal_start < end && !*(nal_start++));
210 if (nal_start == end)
221 size += 4 + nal_end - nal_start;
247 if (
size < nal_length_size + 1) {
249 size, nal_length_size + 1);
256 for (j = 0; j < nal_length_size; j++) {
257 nalsize = (nalsize << 8) | *buf_in++;
259 size -= nal_length_size;
262 if (nalsize <= 0 || nalsize >
size) {
294 int64_t* auxiliary_info_offset)
314 version = auxiliary_info_offset > 0xffffffff ? 1 : 0;
334 if (
ctx->use_subsamples) {
342 int64_t auxiliary_info_offset;
390 int use_subsamples,
int bitexact)
408 ctx->use_subsamples = use_subsamples;
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.
static int mov_cenc_end_packet(MOVMuxCencContext *ctx)
Finalize a packet.
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.
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
void ff_mov_cenc_free(MOVMuxCencContext *ctx)
Free a CENC context.
static int mov_cenc_write_schi_tag(AVIOContext *pb, uint8_t *kid)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int64_t update_size(AVIOContext *pb, int64_t pos)
const uint8_t * av_aes_ctr_get_iv(struct AVAESCTR *a)
Get the current iv.
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 ...
void avio_w8(AVIOContext *s, int b)
int ff_mov_cenc_init(MOVMuxCencContext *ctx, uint8_t *encryption_key, int use_subsamples, int bitexact)
Initialize a CENC context.
int av_aes_ctr_init(struct AVAESCTR *a, const uint8_t *key)
Initialize an AVAESCTR context.
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.
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
void avio_wb32(AVIOContext *s, unsigned int val)
void avio_wl32(AVIOContext *s, unsigned int val)
void ff_mov_cenc_write_stbl_atoms(MOVMuxCencContext *ctx, AVIOContext *pb)
Write the cenc atoms that should reside inside stbl.
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)
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)
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)
void avio_wb24(AVIOContext *s, unsigned int val)
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_avc_find_startcode(const uint8_t *p, const uint8_t *end)