FFmpeg
movenccenc.h
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 
22 #ifndef AVFORMAT_MOVENCCENC_H
23 #define AVFORMAT_MOVENCCENC_H
24 
25 #include "libavutil/aes_ctr.h"
26 #include "avformat.h"
27 #include "avio.h"
28 #include "cbs.h"
29 
30 #define CENC_KID_SIZE (16)
31 
32 struct MOVTrack;
33 
35  uint32_t encrypted_bytes;
37  uint32_t aux_clear_bytes;
38 };
39 
40 typedef struct {
41  struct AVAESCTR* aes_ctr;
42  uint8_t* auxiliary_info;
46 
47  /* subsample support */
49  uint16_t subsample_count;
53 
54  /* AV1 */
56  uint32_t clear_bytes;
57  int tile_num;
58  /* CBS */
62 
63 /**
64  * Initialize a CENC context
65  * @param key encryption key, must have a length of AES_CTR_KEY_SIZE
66  * @param use_subsamples when enabled parts of a packet can be encrypted, otherwise the whole packet is encrypted
67  */
68 int ff_mov_cenc_init(MOVMuxCencContext* ctx, uint8_t* encryption_key, int use_subsamples,
69  enum AVCodecID codec_id, int bitexact);
70 
71 /**
72  * Free a CENC context
73  */
75 
76 /**
77  * Write a fully encrypted packet
78  */
79 int ff_mov_cenc_write_packet(MOVMuxCencContext* ctx, AVIOContext *pb, const uint8_t *buf_in, int size);
80 
81 /**
82  * Parse AVC NAL units from annex B format, the nal size and type are written in the clear while the body is encrypted
83  */
84 int ff_mov_cenc_avc_parse_nal_units(MOVMuxCencContext* ctx, AVIOContext *pb, const uint8_t *buf_in, int size);
85 
86 /**
87  * Write AVC NAL units that are in MP4 format, the nal size and type are written in the clear while the body is encrypted
88  */
90  AVIOContext *pb, const uint8_t *buf_in, int size);
91 
93  AVIOContext *pb, const AVPacket *pkt);
94 /**
95  * Write the cenc atoms that should reside inside stbl
96  */
98 
99 /**
100  * Write the sinf atom, contained inside stsd
101  */
102 int ff_mov_cenc_write_sinf_tag(struct MOVTrack* track, AVIOContext *pb, uint8_t* kid);
103 
104 #endif /* AVFORMAT_MOVENCCENC_H */
MOVMuxCencContext::subsample_count
uint16_t subsample_count
Definition: movenccenc.h:49
MOVMuxCencContext::cbc
CodedBitstreamContext * cbc
Definition: movenccenc.h:59
MOVMuxCencContext::tile_group_sizes
struct MOVMuxCencAV1TGInfo * tile_group_sizes
Definition: movenccenc.h:55
MOVMuxCencAV1TGInfo::write_clear_bytes
uint32_t write_clear_bytes
Definition: movenccenc.h:36
int64_t
long long int64_t
Definition: coverity.c:34
CodedBitstreamContext
Context structure for coded bitstream operations.
Definition: cbs.h:226
cbs.h
MOVMuxCencContext::temporal_unit
CodedBitstreamFragment temporal_unit
Definition: movenccenc.h:60
MOVMuxCencContext::tile_num
int tile_num
Definition: movenccenc.h:57
MOVTrack
Definition: movenc.h:86
MOVMuxCencContext::use_subsamples
int use_subsamples
Definition: movenccenc.h:48
MOVMuxCencContext::auxiliary_info_alloc_size
size_t auxiliary_info_alloc_size
Definition: movenccenc.h:44
pkt
AVPacket * pkt
Definition: movenc.c:60
MOVMuxCencAV1TGInfo
Definition: movenccenc.h:34
CodedBitstreamFragment
Coded bitstream fragment structure, combining one or more units.
Definition: cbs.h:129
s
#define s(width, name)
Definition: cbs_vp9.c:198
ctx
AVFormatContext * ctx
Definition: movenc.c:49
codec_id
enum AVCodecID codec_id
Definition: vaapi_decode.c:410
MOVMuxCencContext::auxiliary_info_entries
uint32_t auxiliary_info_entries
Definition: movenccenc.h:45
AVFormatContext
Format I/O context.
Definition: avformat.h:1265
ff_mov_cenc_free
void ff_mov_cenc_free(MOVMuxCencContext *ctx)
Free a CENC context.
Definition: movenccenc.c:632
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:49
AVIOContext
Bytestream IO Context.
Definition: avio.h:160
MOVMuxCencContext::auxiliary_info_size
size_t auxiliary_info_size
Definition: movenccenc.h:43
size
int size
Definition: twinvq_data.h:10344
avio.h
aes_ctr.h
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
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
MOVMuxCencContext::aes_ctr
struct AVAESCTR * aes_ctr
Definition: movenccenc.h:41
avformat.h
MOVMuxCencAV1TGInfo::aux_clear_bytes
uint32_t aux_clear_bytes
Definition: movenccenc.h:37
MOVMuxCencAV1TGInfo::encrypted_bytes
uint32_t encrypted_bytes
Definition: movenccenc.h:35
ff_mov_cenc_write_sinf_tag
int ff_mov_cenc_write_sinf_tag(struct MOVTrack *track, AVIOContext *pb, uint8_t *kid)
Write the sinf atom, contained inside stsd.
Definition: movenccenc.c:567
MOVMuxCencContext::clear_bytes
uint32_t clear_bytes
Definition: movenccenc.h:56
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
MOVMuxCencContext
Definition: movenccenc.h:40
MOVMuxCencContext::auxiliary_info_sizes_alloc_size
size_t auxiliary_info_sizes_alloc_size
Definition: movenccenc.h:52
AVPacket
This structure stores compressed data.
Definition: packet.h:512
MOVMuxCencContext::auxiliary_info
uint8_t * auxiliary_info
Definition: movenccenc.h:42
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
MOVMuxCencContext::auxiliary_info_subsample_start
size_t auxiliary_info_subsample_start
Definition: movenccenc.h:50
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
AVAESCTR
Definition: aes_ctr.c:34
MOVMuxCencContext::auxiliary_info_sizes
uint8_t * auxiliary_info_sizes
Definition: movenccenc.h:51
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