diff options
author | erankor <eran.kornblau@kaltura.com> | 2015-12-07 12:01:09 +0200 |
---|---|---|
committer | Michael Niedermayer <michael@niedermayer.cc> | 2015-12-15 14:16:28 +0100 |
commit | 4469e8ebb2f370794c88aa51d528d1d899d29ddc (patch) | |
tree | a8507e8eb328c0aee020809be37941bd37882844 /libavformat/movenccenc.h | |
parent | 23ac99dc17b0c4ff43bb56c1f8cbe7feb34bada5 (diff) | |
download | ffmpeg-4469e8ebb2f370794c88aa51d528d1d899d29ddc.tar.gz |
movenc: support cenc (common encryption)
support writing encrypted mp4 using aes-ctr, conforming to ISO/IEC
23001-7.
3 new parameters were added:
- encryption_scheme - allowed values are none (default) and cenc-aes-ctr
- encryption_key - 128 bit encryption key (hex)
- encryption_kid - 128 bit encryption key identifier (hex)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
Diffstat (limited to 'libavformat/movenccenc.h')
-rw-r--r-- | libavformat/movenccenc.h | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/libavformat/movenccenc.h b/libavformat/movenccenc.h new file mode 100644 index 0000000000..6f9e70e905 --- /dev/null +++ b/libavformat/movenccenc.h @@ -0,0 +1,86 @@ +/* + * MOV CENC (Common Encryption) writer + * Copyright (c) 2015 Eran Kornblau <erankor at gmail dot com> + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVFORMAT_MOVENCCENC_H +#define AVFORMAT_MOVENCCENC_H + +#include "libavutil/aes_ctr.h" +#include "avformat.h" +#include "avio.h" + +#define CENC_KID_SIZE (16) + +struct MOVTrack; + +typedef struct { + struct AVAESCTR* aes_ctr; + uint8_t* auxiliary_info; + size_t auxiliary_info_size; + size_t auxiliary_info_alloc_size; + uint32_t auxiliary_info_entries; + + /* subsample support */ + int use_subsamples; + uint16_t subsample_count; + size_t auxiliary_info_subsample_start; + uint8_t* auxiliary_info_sizes; + size_t auxiliary_info_sizes_alloc_size; +} MOVMuxCencContext; + +/** + * Initialize a CENC context + * @param key encryption key, must have a length of AES_CTR_KEY_SIZE + * @param use_subsamples when enabled parts of a packet can be encrypted, otherwise the whole packet is encrypted + */ +int ff_mov_cenc_init(MOVMuxCencContext* ctx, uint8_t* encryption_key, int use_subsamples, int bitexact); + +/** + * Free a CENC context + */ +void ff_mov_cenc_free(MOVMuxCencContext* ctx); + +/** + * Write a fully encrypted packet + */ +int ff_mov_cenc_write_packet(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 body is encrypted + */ +int ff_mov_cenc_avc_parse_nal_units(MOVMuxCencContext* ctx, 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 body is encrypted + */ +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 the cenc atoms that should reside inside stbl + */ +void ff_mov_cenc_write_stbl_atoms(MOVMuxCencContext* ctx, AVIOContext *pb); + +/** + * Write the sinf atom, contained inside stsd + */ +int ff_mov_cenc_write_sinf_tag(struct MOVTrack* track, AVIOContext *pb, uint8_t* kid); + +#endif /* AVFORMAT_MOVENCCENC_H */ |