FFmpeg
movenccenc.c
Go to the documentation of this file.
1 /*
2  * MOV CENC (Common Encryption) writer
3  * Copyright (c) 2015 Eran Kornblau <erankor at gmail dot com>
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 #include "movenccenc.h"
22 #include "libavcodec/av1_parse.h"
23 #include "libavcodec/bytestream.h"
24 #include "libavcodec/cbs_av1.h"
25 #include "libavutil/intreadwrite.h"
26 #include "libavutil/mem.h"
27 #include "avio_internal.h"
28 #include "movenc.h"
29 #include "avc.h"
30 #include "nal.h"
31 
33 {
34  size_t new_alloc_size;
35 
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);
38  if (av_reallocp(&ctx->auxiliary_info, new_alloc_size)) {
39  return AVERROR(ENOMEM);
40  }
41 
42  ctx->auxiliary_info_alloc_size = new_alloc_size;
43  }
44 
45  return 0;
46 }
47 
49  const uint8_t *buf_in, int size)
50 {
51  int ret;
52 
54  if (ret) {
55  return ret;
56  }
57  memcpy(ctx->auxiliary_info + ctx->auxiliary_info_size, buf_in, size);
58  ctx->auxiliary_info_size += size;
59 
60  return 0;
61 }
62 
64  uint16_t clear_bytes, uint32_t encrypted_bytes)
65 {
66  uint8_t* p;
67  int ret;
68 
69  if (!ctx->use_subsamples) {
70  return 0;
71  }
72 
74  if (ret) {
75  return ret;
76  }
77 
78  p = ctx->auxiliary_info + ctx->auxiliary_info_size;
79 
80  AV_WB16(p, clear_bytes);
81  p += sizeof(uint16_t);
82 
83  AV_WB32(p, encrypted_bytes);
84 
85  ctx->auxiliary_info_size += 6;
86  ctx->subsample_count++;
87 
88  return 0;
89 }
90 
91 /**
92  * Encrypt the input buffer and write using avio_write
93  */
95  const uint8_t *buf_in, int size)
96 {
97  uint8_t chunk[4096];
98  const uint8_t* cur_pos = buf_in;
99  int size_left = size;
100  int cur_size;
101 
102  while (size_left > 0) {
103  cur_size = FFMIN(size_left, sizeof(chunk));
104  av_aes_ctr_crypt(ctx->aes_ctr, chunk, cur_pos, cur_size);
105  avio_write(pb, chunk, cur_size);
106  cur_pos += cur_size;
107  size_left -= cur_size;
108  }
109 }
110 
111 /**
112  * Start writing a packet
113  */
115 {
116  int ret;
117 
118  /* write the iv */
120  if (ret) {
121  return ret;
122  }
123 
124  if (!ctx->use_subsamples) {
125  return 0;
126  }
127 
128  /* write a zero subsample count */
129  ctx->auxiliary_info_subsample_start = ctx->auxiliary_info_size;
130  ctx->subsample_count = 0;
131  ret = auxiliary_info_write(ctx, (uint8_t*)&ctx->subsample_count, sizeof(ctx->subsample_count));
132  if (ret) {
133  return ret;
134  }
135 
136  return 0;
137 }
138 
139 /**
140  * Finalize a packet
141  */
143 {
144  size_t new_alloc_size;
145 
146  av_aes_ctr_increment_iv(ctx->aes_ctr);
147 
148  if (!ctx->use_subsamples) {
149  ctx->auxiliary_info_entries++;
150  return 0;
151  }
152 
153  /* add the auxiliary info entry size*/
154  if (ctx->auxiliary_info_entries >= ctx->auxiliary_info_sizes_alloc_size) {
155  new_alloc_size = ctx->auxiliary_info_entries * 2 + 1;
156  if (av_reallocp(&ctx->auxiliary_info_sizes, new_alloc_size)) {
157  return AVERROR(ENOMEM);
158  }
159 
160  ctx->auxiliary_info_sizes_alloc_size = new_alloc_size;
161  }
162  ctx->auxiliary_info_sizes[ctx->auxiliary_info_entries] =
163  AES_CTR_IV_SIZE + ctx->auxiliary_info_size - ctx->auxiliary_info_subsample_start;
164  ctx->auxiliary_info_entries++;
165 
166  /* update the subsample count*/
167  AV_WB16(ctx->auxiliary_info + ctx->auxiliary_info_subsample_start, ctx->subsample_count);
168 
169  return 0;
170 }
171 
173  const uint8_t *buf_in, int size)
174 {
175  int ret;
176 
178  if (ret) {
179  return ret;
180  }
181 
183  if (ret) {
184  return ret;
185  }
186 
187  mov_cenc_write_encrypted(ctx, pb, buf_in, size);
188 
190  if (ret) {
191  return ret;
192  }
193 
194  return 0;
195 }
196 
198  const uint8_t *buf_in, int size)
199 {
200  const uint8_t *p = buf_in;
201  const uint8_t *end = p + size;
202  const uint8_t *nal_start, *nal_end;
203  int ret;
204 
206  if (ret) {
207  return ret;
208  }
209 
210  size = 0;
211  nal_start = ff_nal_find_startcode(p, end);
212  for (;;) {
213  while (nal_start < end && !*(nal_start++));
214  if (nal_start == end)
215  break;
216 
217  nal_end = ff_nal_find_startcode(nal_start, end);
218 
219  avio_wb32(pb, nal_end - nal_start);
220  avio_w8(pb, *nal_start);
221  mov_cenc_write_encrypted(ctx, pb, nal_start + 1, nal_end - nal_start - 1);
222 
223  auxiliary_info_add_subsample(ctx, 5, nal_end - nal_start - 1);
224 
225  size += 4 + nal_end - nal_start;
226  nal_start = nal_end;
227  }
228 
230  if (ret) {
231  return ret;
232  }
233 
234  return size;
235 }
236 
238  int nal_length_size, AVIOContext *pb, const uint8_t *buf_in, int size)
239 {
240  int nalsize;
241  int ret;
242  int j;
243 
245  if (ret) {
246  return ret;
247  }
248 
249  while (size > 0) {
250  /* parse the nal size */
251  if (size < nal_length_size + 1) {
252  av_log(s, AV_LOG_ERROR, "CENC-AVC: remaining size %d smaller than nal length+type %d\n",
253  size, nal_length_size + 1);
254  return -1;
255  }
256 
257  avio_write(pb, buf_in, nal_length_size + 1);
258 
259  nalsize = 0;
260  for (j = 0; j < nal_length_size; j++) {
261  nalsize = (nalsize << 8) | *buf_in++;
262  }
263  size -= nal_length_size;
264 
265  /* encrypt the nal body */
266  if (nalsize <= 0 || nalsize > size) {
267  av_log(s, AV_LOG_ERROR, "CENC-AVC: nal size %d remaining %d\n", nalsize, size);
268  return -1;
269  }
270 
271  mov_cenc_write_encrypted(ctx, pb, buf_in + 1, nalsize - 1);
272  buf_in += nalsize;
273  size -= nalsize;
274 
275  auxiliary_info_add_subsample(ctx, nal_length_size + 1, nalsize - 1);
276  }
277 
279  if (ret) {
280  return ret;
281  }
282 
283  return 0;
284 }
285 
287  const AV1RawFrameHeader *frame_header, const uint8_t *fh_data, size_t fh_data_size,
288  const AV1RawTileGroup *tile_group)
289 {
290  GetByteContext gb;
291  size_t tgh_data_size = tile_group->data_size;
292  int cur_tile_num = frame_header->tile_cols * frame_header->tile_rows;
293  int total = 0;
294 
295  // Get the Frame Header size
296  if (type == AV1_OBU_FRAME)
297  fh_data_size -= tgh_data_size;
298  // Get the Tile Group Header size
299  tgh_data_size -= tile_group->tile_data.data_size;
300 
301  if (ctx->tile_num < cur_tile_num) {
302  int ret = av_reallocp_array(&ctx->tile_group_sizes, cur_tile_num,
303  sizeof(*ctx->tile_group_sizes));
304  if (ret < 0) {
305  ctx->tile_num = 0;
306  return ret;
307  }
308  }
309  ctx->tile_num = cur_tile_num;
310 
311  total = fh_data_size + tgh_data_size;
312  ctx->clear_bytes += total;
313 
314  bytestream2_init(&gb, tile_group->tile_data.data, tile_group->tile_data.data_size);
315 
316  // Build a table with block sizes for encrypted bytes and clear bytes
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;
319 
320  if (tile_num == tile_group->tg_end) {
321  tile_size = bytestream2_get_bytes_left(&gb);
322  encrypted_bytes = tile_size & ~0xFU;
323  ctx->clear_bytes += tile_size & 0xFU;
324 
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 & 0xFU;
328 
329  if (encrypted_bytes)
330  ctx->clear_bytes = 0;
331  total += tile_size;
332 
333  break;
334  }
335 
336  tile_size_bytes = frame_header->tile_size_bytes_minus1 + 1;
337  if (bytestream2_get_bytes_left(&gb) < tile_size_bytes)
338  return AVERROR_INVALIDDATA;
339 
340  for (int i = 0; i < tile_size_bytes; i++)
341  tile_size |= bytestream2_get_byteu(&gb) << 8 * i;
342  if (bytestream2_get_bytes_left(&gb) <= tile_size)
343  return AVERROR_INVALIDDATA;
344  tile_size++;
345 
346  // The spec requires encrypted bytes to be in blocks multiple of 16
347  encrypted_bytes = tile_size & ~0xFU;
348  ctx->clear_bytes += (tile_size & 0xFU) + tile_size_bytes;
349 
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 & 0xFU) + tile_size_bytes;
353 
354  if (encrypted_bytes)
355  ctx->clear_bytes = 0;
356 
357  total += tile_size + tile_size_bytes;
358  bytestream2_skipu(&gb, tile_size);
359  }
360 
361  bytestream2_init(&gb, tile_group->tile_data.data, tile_group->tile_data.data_size);
362 
363  avio_write(pb, fh_data, fh_data_size);
364  avio_write(pb, tile_group->data, tgh_data_size);
365 
366  for (unsigned tile_num = tile_group->tg_start; tile_num <= tile_group->tg_end; tile_num++) {
367  const struct MOVMuxCencAV1TGInfo *sizes = &ctx->tile_group_sizes[tile_num];
368 
369  avio_write(pb, gb.buffer, sizes->write_clear_bytes);
370  bytestream2_skipu(&gb, sizes->write_clear_bytes);
371  mov_cenc_write_encrypted(ctx, pb, gb.buffer, sizes->encrypted_bytes);
372  bytestream2_skipu(&gb, sizes->encrypted_bytes);
373  if (sizes->encrypted_bytes) {
374  unsigned clear_bytes = sizes->aux_clear_bytes;
375  if (clear_bytes > UINT16_MAX) {
376  auxiliary_info_add_subsample(ctx, UINT16_MAX, 0);
377  clear_bytes -= UINT16_MAX;
378  }
379  auxiliary_info_add_subsample(ctx, clear_bytes, sizes->encrypted_bytes);
380  }
381  }
382 
383  return total;
384 }
385 
387  AVIOContext *pb, const AVPacket *pkt)
388 {
389  CodedBitstreamFragment *td = &ctx->temporal_unit;
390  const CodedBitstreamAV1Context *av1 = ctx->cbc->priv_data;
392  const uint8_t *fh_data = NULL;
393  size_t fh_data_size;
394  int out_size = 0, ret;
395 
397  if (ret) {
398  return ret;
399  }
400 
401  ret = ff_lavf_cbs_read_packet(ctx->cbc, td, pkt);
402  if (ret < 0) {
403  av_log(s, AV_LOG_ERROR, "CENC-AV1: Failed to parse temporal unit.\n");
404  return ret;
405  }
406 
407  if (!av1->sequence_header) {
408  av_log(s, AV_LOG_ERROR, "CENC-AV1: No sequence header available\n");
410  goto end;
411  }
412 
413  for (int i = 0; i < td->nb_units; i++) {
414  const CodedBitstreamUnit *unit = &td->units[i];
415  const AV1RawOBU *obu = unit->content;
416 
417  switch (unit->type) {
420  frame_header = &obu->obu.frame_header;
421  fh_data = unit->data;
422  fh_data_size = unit->data_size;
423  break;
424  }
425  // fall-through
427  case AV1_OBU_METADATA:
428  avio_write(pb, unit->data, unit->data_size);
429  ctx->clear_bytes += unit->data_size;
430  out_size += unit->data_size;
431  break;
432  case AV1_OBU_FRAME:
433  frame_header = &obu->obu.frame.header;
434  fh_data = unit->data;
435  fh_data_size = unit->data_size;
436  // fall-through
437  case AV1_OBU_TILE_GROUP:
438  {
439  const AV1RawTileGroup *tile_group;
440 
441  if (!frame_header){
443  goto end;
444  }
445 
446  if (unit->type == AV1_OBU_FRAME)
447  tile_group = &obu->obu.frame.tile_group;
448  else
449  tile_group = &obu->obu.tile_group;
450 
451  ret = write_tiles(s, ctx, pb, unit->type,
452  frame_header, fh_data, fh_data_size, tile_group);
453  if (ret < 0) {
454  av_log(s, AV_LOG_ERROR, "CENC-AV1: Failed to write tiles\n");
455  goto end;
456  }
457  av_assert0(ret == unit->data_size);
458  out_size += unit->data_size;
459  frame_header = NULL;
460  }
461  break;
462  default:
463  break;
464  }
465  }
466 
467  if (ctx->clear_bytes)
468  auxiliary_info_add_subsample(ctx, ctx->clear_bytes, 0);
469  ctx->clear_bytes = 0;
470 
472  if (ret) {
474  goto end;
475  }
476 
477  ret = out_size;
478 end:
479  ff_lavf_cbs_fragment_reset(td);
480  return ret;
481 }
482 
483 /* TODO: reuse this function from movenc.c */
485 {
486  int64_t curpos = avio_tell(pb);
487  avio_seek(pb, pos, SEEK_SET);
488  avio_wb32(pb, curpos - pos); /* rewrite size */
489  avio_seek(pb, curpos, SEEK_SET);
490 
491  return curpos - pos;
492 }
493 
495  int64_t* auxiliary_info_offset)
496 {
497  int64_t pos = avio_tell(pb);
498 
499  avio_wb32(pb, 0); /* size */
500  ffio_wfourcc(pb, "senc");
501  avio_wb32(pb, ctx->use_subsamples ? 0x02 : 0); /* version & flags */
502  avio_wb32(pb, ctx->auxiliary_info_entries); /* entry count */
503  *auxiliary_info_offset = avio_tell(pb);
504  avio_write(pb, ctx->auxiliary_info, ctx->auxiliary_info_size);
505  return update_size(pb, pos);
506 }
507 
508 static int mov_cenc_write_saio_tag(AVIOContext *pb, int64_t auxiliary_info_offset)
509 {
510  int64_t pos = avio_tell(pb);
511  uint8_t version;
512 
513  avio_wb32(pb, 0); /* size */
514  ffio_wfourcc(pb, "saio");
515  version = auxiliary_info_offset > 0xffffffff ? 1 : 0;
516  avio_w8(pb, version);
517  avio_wb24(pb, 0); /* flags */
518  avio_wb32(pb, 1); /* entry count */
519  if (version) {
520  avio_wb64(pb, auxiliary_info_offset);
521  } else {
522  avio_wb32(pb, auxiliary_info_offset);
523  }
524  return update_size(pb, pos);
525 }
526 
528 {
529  int64_t pos = avio_tell(pb);
530  avio_wb32(pb, 0); /* size */
531  ffio_wfourcc(pb, "saiz");
532  avio_wb32(pb, 0); /* version & flags */
533  avio_w8(pb, ctx->use_subsamples ? 0 : AES_CTR_IV_SIZE); /* default size*/
534  avio_wb32(pb, ctx->auxiliary_info_entries); /* entry count */
535  if (ctx->use_subsamples) {
536  avio_write(pb, ctx->auxiliary_info_sizes, ctx->auxiliary_info_entries);
537  }
538  return update_size(pb, pos);
539 }
540 
542  int64_t moof_offset)
543 {
544  int64_t auxiliary_info_offset;
545 
546  mov_cenc_write_senc_tag(ctx, pb, &auxiliary_info_offset);
547  mov_cenc_write_saio_tag(pb, auxiliary_info_offset - moof_offset);
549 }
550 
551 static int mov_cenc_write_schi_tag(AVIOContext *pb, uint8_t* kid)
552 {
553  int64_t pos = avio_tell(pb);
554  avio_wb32(pb, 0); /* size */
555  ffio_wfourcc(pb, "schi");
556 
557  avio_wb32(pb, 32); /* size */
558  ffio_wfourcc(pb, "tenc");
559  avio_wb32(pb, 0); /* version & flags */
560  avio_wb24(pb, 1); /* is encrypted */
561  avio_w8(pb, AES_CTR_IV_SIZE); /* iv size */
562  avio_write(pb, kid, CENC_KID_SIZE);
563 
564  return update_size(pb, pos);
565 }
566 
567 int ff_mov_cenc_write_sinf_tag(MOVTrack* track, AVIOContext *pb, uint8_t* kid)
568 {
569  int64_t pos = avio_tell(pb);
570  avio_wb32(pb, 0); /* size */
571  ffio_wfourcc(pb, "sinf");
572 
573  /* frma */
574  avio_wb32(pb, 12); /* size */
575  ffio_wfourcc(pb, "frma");
576  avio_wl32(pb, track->tag);
577 
578  /* schm */
579  avio_wb32(pb, 20); /* size */
580  ffio_wfourcc(pb, "schm");
581  avio_wb32(pb, 0); /* version & flags */
582  ffio_wfourcc(pb, "cenc"); /* scheme type*/
583  avio_wb32(pb, 0x10000); /* scheme version */
584 
585  /* schi */
586  mov_cenc_write_schi_tag(pb, kid);
587 
588  return update_size(pb, pos);
589 }
590 
597 };
598 
599 int ff_mov_cenc_init(MOVMuxCencContext* ctx, uint8_t* encryption_key,
600  int use_subsamples, enum AVCodecID codec_id, int bitexact)
601 {
602  int ret;
603 
604  ctx->aes_ctr = av_aes_ctr_alloc();
605  if (!ctx->aes_ctr) {
606  return AVERROR(ENOMEM);
607  }
608 
609  ret = av_aes_ctr_init(ctx->aes_ctr, encryption_key);
610  if (ret != 0) {
611  return ret;
612  }
613 
614  if (!bitexact) {
615  av_aes_ctr_set_random_iv(ctx->aes_ctr);
616  }
617 
618  ctx->use_subsamples = use_subsamples;
619 
620  if (codec_id == AV_CODEC_ID_AV1) {
621  ret = ff_lavf_cbs_init(&ctx->cbc, codec_id, NULL);
622  if (ret < 0)
623  return ret;
624 
625  ctx->cbc->decompose_unit_types = decompose_unit_types;
626  ctx->cbc->nb_decompose_unit_types = FF_ARRAY_ELEMS(decompose_unit_types);
627  }
628 
629  return 0;
630 }
631 
633 {
634  av_aes_ctr_free(ctx->aes_ctr);
635  av_freep(&ctx->auxiliary_info);
636  av_freep(&ctx->auxiliary_info_sizes);
637 
638  av_freep(&ctx->tile_group_sizes);
639  ff_lavf_cbs_fragment_free(&ctx->temporal_unit);
640  ff_lavf_cbs_close(&ctx->cbc);
641 }
mov_cenc_write_senc_tag
static int mov_cenc_write_senc_tag(MOVMuxCencContext *ctx, AVIOContext *pb, int64_t *auxiliary_info_offset)
Definition: movenccenc.c:494
AVERROR
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
ffio_wfourcc
static av_always_inline void ffio_wfourcc(AVIOContext *pb, const uint8_t *s)
Definition: avio_internal.h:124
mov_cenc_write_saio_tag
static int mov_cenc_write_saio_tag(AVIOContext *pb, int64_t auxiliary_info_offset)
Definition: movenccenc.c:508
auxiliary_info_alloc_size
static int auxiliary_info_alloc_size(MOVMuxCencContext *ctx, int size)
Definition: movenccenc.c:32
GetByteContext
Definition: bytestream.h:33
mov_cenc_write_encrypted
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.
Definition: movenccenc.c:94
CodedBitstreamUnit::content
void * content
Pointer to the decomposed form of this unit.
Definition: cbs.h:114
bytestream2_skipu
static av_always_inline void bytestream2_skipu(GetByteContext *g, unsigned int size)
Definition: bytestream.h:174
int64_t
long long int64_t
Definition: coverity.c:34
out_size
int out_size
Definition: movenc.c:56
MOVTrack::tag
int tag
stsd fourcc
Definition: movenc.h:108
AV1RawTileGroup::tg_end
uint16_t tg_end
Definition: cbs_av1.h:313
mov_cenc_end_packet
static int mov_cenc_end_packet(MOVMuxCencContext *ctx)
Finalize a packet.
Definition: movenccenc.c:142
CodedBitstreamUnit::type
CodedBitstreamUnitType type
Codec-specific type of this unit.
Definition: cbs.h:81
av_aes_ctr_set_random_iv
void av_aes_ctr_set_random_iv(struct AVAESCTR *a)
Generate a random iv.
Definition: aes_ctr.c:61
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
mov_cenc_start_packet
static int mov_cenc_start_packet(MOVMuxCencContext *ctx)
Start writing a packet.
Definition: movenccenc.c:114
AV1_OBU_TEMPORAL_DELIMITER
@ AV1_OBU_TEMPORAL_DELIMITER
Definition: av1.h:31
AV1RawTileData::data
uint8_t * data
Definition: cbs_av1.h:301
CodedBitstreamUnit
Coded bitstream unit structure.
Definition: cbs.h:77
AV1RawFrame::header
AV1RawFrameHeader header
Definition: cbs_av1.h:319
MOVTrack
Definition: movenc.h:86
av1_parse.h
AV1_OBU_FRAME_HEADER
@ AV1_OBU_FRAME_HEADER
Definition: av1.h:32
avio_tell
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:494
AV1_OBU_Type
AV1_OBU_Type
Definition: av1.h:28
type
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
Definition: writing_filters.txt:86
CodedBitstreamUnit::data
uint8_t * data
Pointer to the directly-parsable bitstream form of this unit.
Definition: cbs.h:88
CENC_KID_SIZE
#define CENC_KID_SIZE
Definition: movenccenc.h:30
ff_mov_cenc_free
void ff_mov_cenc_free(MOVMuxCencContext *ctx)
Free a CENC context.
Definition: movenccenc.c:632
CodedBitstreamFragment::units
CodedBitstreamUnit * units
Pointer to an array of units of length nb_units_allocated.
Definition: cbs.h:175
mov_cenc_write_schi_tag
static int mov_cenc_write_schi_tag(AVIOContext *pb, uint8_t *kid)
Definition: movenccenc.c:551
cbs_av1.h
pkt
AVPacket * pkt
Definition: movenc.c:60
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:209
MOVMuxCencAV1TGInfo
Definition: movenccenc.h:34
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
movenccenc.h
CodedBitstreamFragment
Coded bitstream fragment structure, combining one or more units.
Definition: cbs.h:129
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:198
update_size
static int64_t update_size(AVIOContext *pb, int64_t pos)
Definition: movenccenc.c:484
GetByteContext::buffer
const uint8_t * buffer
Definition: bytestream.h:34
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
CodedBitstreamUnitType
uint32_t CodedBitstreamUnitType
The codec-specific type of a bitstream unit.
Definition: cbs.h:54
ctx
AVFormatContext * ctx
Definition: movenc.c:49
av_aes_ctr_get_iv
const uint8_t * av_aes_ctr_get_iv(struct AVAESCTR *a)
Get the current iv.
Definition: aes_ctr.c:56
codec_id
enum AVCodecID codec_id
Definition: vaapi_decode.c:410
AVFormatContext
Format I/O context.
Definition: avformat.h:1265
AV1RawOBU
Definition: cbs_av1.h:413
NULL
#define NULL
Definition: coverity.c:32
sizes
static const int sizes[][2]
Definition: img2dec.c:60
AV_CODEC_ID_AV1
@ AV_CODEC_ID_AV1
Definition: codec_id.h:284
AV1RawFrameHeader
Definition: cbs_av1.h:174
AV_WB16
#define AV_WB16(p, v)
Definition: intreadwrite.h:401
av_aes_ctr_alloc
struct AVAESCTR * av_aes_ctr_alloc(void)
Allocate an AVAESCTR context.
Definition: aes_ctr.c:40
ff_mov_cenc_avc_write_nal_units
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 ...
Definition: movenccenc.c:237
AV1RawTileData::data_size
size_t data_size
Definition: cbs_av1.h:303
avc.h
CodedBitstreamUnit::data_size
size_t data_size
The number of bytes in the bitstream (including any padding bits in the final byte).
Definition: cbs.h:93
AV1_OBU_TILE_GROUP
@ AV1_OBU_TILE_GROUP
Definition: av1.h:33
avio_w8
void avio_w8(AVIOContext *s, int b)
Definition: aviobuf.c:179
bytestream2_get_bytes_left
static av_always_inline int bytestream2_get_bytes_left(GetByteContext *g)
Definition: bytestream.h:158
movenc.h
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:49
AV_WB32
#define AV_WB32(p, v)
Definition: intreadwrite.h:415
AV1_OBU_FRAME
@ AV1_OBU_FRAME
Definition: av1.h:35
AVIOContext
Bytestream IO Context.
Definition: avio.h:160
ff_mov_cenc_av1_write_obus
int ff_mov_cenc_av1_write_obus(AVFormatContext *s, MOVMuxCencContext *ctx, AVIOContext *pb, const AVPacket *pkt)
Definition: movenccenc.c:386
AV1RawOBU::obu
union AV1RawOBU::@67 obu
av_aes_ctr_init
int av_aes_ctr_init(struct AVAESCTR *a, const uint8_t *key)
Initialize an AVAESCTR context.
Definition: aes_ctr.c:71
ff_mov_cenc_write_stbl_atoms
void ff_mov_cenc_write_stbl_atoms(MOVMuxCencContext *ctx, AVIOContext *pb, int64_t moof_offset)
Write the cenc atoms that should reside inside stbl.
Definition: movenccenc.c:541
mov_cenc_write_saiz_tag
static int mov_cenc_write_saiz_tag(MOVMuxCencContext *ctx, AVIOContext *pb)
Definition: movenccenc.c:527
ff_mov_cenc_write_packet
int ff_mov_cenc_write_packet(MOVMuxCencContext *ctx, AVIOContext *pb, const uint8_t *buf_in, int size)
Write a fully encrypted packet.
Definition: movenccenc.c:172
size
int size
Definition: twinvq_data.h:10344
av_reallocp
int av_reallocp(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory through a pointer to a pointer.
Definition: mem.c:188
AV1_OBU_SEQUENCE_HEADER
@ AV1_OBU_SEQUENCE_HEADER
Definition: av1.h:30
avio_write
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:201
avio_wb32
void avio_wb32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:365
av_reallocp_array
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
Allocate, reallocate an array through a pointer to a pointer.
Definition: mem.c:225
avio_wl32
void avio_wl32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:357
version
version
Definition: libkvazaar.c:315
AV1RawOBU::frame_header
AV1RawFrameHeader frame_header
Definition: cbs_av1.h:420
av_aes_ctr_free
void av_aes_ctr_free(struct AVAESCTR *a)
Release an AVAESCTR context.
Definition: aes_ctr.c:80
auxiliary_info_write
static int auxiliary_info_write(MOVMuxCencContext *ctx, const uint8_t *buf_in, int size)
Definition: movenccenc.c:48
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
avio_internal.h
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
ff_mov_cenc_init
int ff_mov_cenc_init(MOVMuxCencContext *ctx, uint8_t *encryption_key, int use_subsamples, enum AVCodecID codec_id, int bitexact)
Initialize a CENC context.
Definition: movenccenc.c:599
AV1RawTileGroup::data
uint8_t * data
Definition: cbs_av1.h:307
AV1RawTileGroup::tg_start
uint16_t tg_start
Definition: cbs_av1.h:312
nal.h
AV1RawOBU::tile_group
AV1RawTileGroup tile_group
Definition: cbs_av1.h:422
AV1RawTileGroup::tile_data
AV1RawTileData tile_data
Definition: cbs_av1.h:315
ret
ret
Definition: filter_design.txt:187
avio_seek
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:231
ff_mov_cenc_write_sinf_tag
int ff_mov_cenc_write_sinf_tag(MOVTrack *track, AVIOContext *pb, uint8_t *kid)
Write the sinf atom, contained inside stsd.
Definition: movenccenc.c:567
auxiliary_info_add_subsample
static int auxiliary_info_add_subsample(MOVMuxCencContext *ctx, uint16_t clear_bytes, uint32_t encrypted_bytes)
Definition: movenccenc.c:63
pos
unsigned int pos
Definition: spdifenc.c:414
U
#define U(x)
Definition: vpx_arith.h:37
CodedBitstreamAV1Context::sequence_header
AV1RawSequenceHeader * sequence_header
Definition: cbs_av1.h:460
frame_header
Definition: truemotion1.c:88
write_tiles
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)
Definition: movenccenc.c:286
av_aes_ctr_increment_iv
void av_aes_ctr_increment_iv(struct AVAESCTR *a)
Increment the top 64 bit of the iv (performed after each frame)
Definition: aes_ctr.c:91
AV1RawTileGroup
Definition: cbs_av1.h:306
av_aes_ctr_crypt
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.
Definition: aes_ctr.c:97
avio_wb64
void avio_wb64(AVIOContext *s, uint64_t val)
Definition: aviobuf.c:431
AV1RawFrameHeader::show_existing_frame
uint8_t show_existing_frame
Definition: cbs_av1.h:175
AV1RawOBU::frame
AV1RawFrame frame
Definition: cbs_av1.h:421
mem.h
decompose_unit_types
static const CodedBitstreamUnitType decompose_unit_types[]
Definition: movenccenc.c:591
AV1RawFrame::tile_group
AV1RawTileGroup tile_group
Definition: cbs_av1.h:320
MOVMuxCencContext
Definition: movenccenc.h:40
avio_wb24
void avio_wb24(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:455
AVPacket
This structure stores compressed data.
Definition: packet.h:512
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
AES_CTR_IV_SIZE
#define AES_CTR_IV_SIZE
Definition: aes_ctr.h:36
bytestream.h
bytestream2_init
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition: bytestream.h:137
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
ff_mov_cenc_avc_parse_nal_units
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...
Definition: movenccenc.c:197
ff_nal_find_startcode
const uint8_t * ff_nal_find_startcode(const uint8_t *p, const uint8_t *end)
Definition: nal.c:68
AVFormatContext::priv_data
void * priv_data
Format private data.
Definition: avformat.h:1293
AV1_OBU_METADATA
@ AV1_OBU_METADATA
Definition: av1.h:34
CodedBitstreamFragment::nb_units
int nb_units
Number of units in this fragment.
Definition: cbs.h:160
AV1RawTileGroup::data_size
size_t data_size
Definition: cbs_av1.h:309
CodedBitstreamAV1Context
Definition: cbs_av1.h:457