1cabdff1aSopenharmony_ci/* 2cabdff1aSopenharmony_ci * MOV CENC (Common Encryption) writer 3cabdff1aSopenharmony_ci * Copyright (c) 2015 Eran Kornblau <erankor at gmail dot com> 4cabdff1aSopenharmony_ci * 5cabdff1aSopenharmony_ci * This file is part of FFmpeg. 6cabdff1aSopenharmony_ci * 7cabdff1aSopenharmony_ci * FFmpeg is free software; you can redistribute it and/or 8cabdff1aSopenharmony_ci * modify it under the terms of the GNU Lesser General Public 9cabdff1aSopenharmony_ci * License as published by the Free Software Foundation; either 10cabdff1aSopenharmony_ci * version 2.1 of the License, or (at your option) any later version. 11cabdff1aSopenharmony_ci * 12cabdff1aSopenharmony_ci * FFmpeg is distributed in the hope that it will be useful, 13cabdff1aSopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of 14cabdff1aSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15cabdff1aSopenharmony_ci * Lesser General Public License for more details. 16cabdff1aSopenharmony_ci * 17cabdff1aSopenharmony_ci * You should have received a copy of the GNU Lesser General Public 18cabdff1aSopenharmony_ci * License along with FFmpeg; if not, write to the Free Software 19cabdff1aSopenharmony_ci * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20cabdff1aSopenharmony_ci */ 21cabdff1aSopenharmony_ci 22cabdff1aSopenharmony_ci#ifndef AVFORMAT_MOVENCCENC_H 23cabdff1aSopenharmony_ci#define AVFORMAT_MOVENCCENC_H 24cabdff1aSopenharmony_ci 25cabdff1aSopenharmony_ci#include "libavutil/aes_ctr.h" 26cabdff1aSopenharmony_ci#include "avformat.h" 27cabdff1aSopenharmony_ci#include "avio.h" 28cabdff1aSopenharmony_ci 29cabdff1aSopenharmony_ci#define CENC_KID_SIZE (16) 30cabdff1aSopenharmony_ci 31cabdff1aSopenharmony_cistruct MOVTrack; 32cabdff1aSopenharmony_ci 33cabdff1aSopenharmony_citypedef struct { 34cabdff1aSopenharmony_ci struct AVAESCTR* aes_ctr; 35cabdff1aSopenharmony_ci uint8_t* auxiliary_info; 36cabdff1aSopenharmony_ci size_t auxiliary_info_size; 37cabdff1aSopenharmony_ci size_t auxiliary_info_alloc_size; 38cabdff1aSopenharmony_ci uint32_t auxiliary_info_entries; 39cabdff1aSopenharmony_ci 40cabdff1aSopenharmony_ci /* subsample support */ 41cabdff1aSopenharmony_ci int use_subsamples; 42cabdff1aSopenharmony_ci uint16_t subsample_count; 43cabdff1aSopenharmony_ci size_t auxiliary_info_subsample_start; 44cabdff1aSopenharmony_ci uint8_t* auxiliary_info_sizes; 45cabdff1aSopenharmony_ci size_t auxiliary_info_sizes_alloc_size; 46cabdff1aSopenharmony_ci} MOVMuxCencContext; 47cabdff1aSopenharmony_ci 48cabdff1aSopenharmony_ci/** 49cabdff1aSopenharmony_ci * Initialize a CENC context 50cabdff1aSopenharmony_ci * @param key encryption key, must have a length of AES_CTR_KEY_SIZE 51cabdff1aSopenharmony_ci * @param use_subsamples when enabled parts of a packet can be encrypted, otherwise the whole packet is encrypted 52cabdff1aSopenharmony_ci */ 53cabdff1aSopenharmony_ciint ff_mov_cenc_init(MOVMuxCencContext* ctx, uint8_t* encryption_key, int use_subsamples, int bitexact); 54cabdff1aSopenharmony_ci 55cabdff1aSopenharmony_ci/** 56cabdff1aSopenharmony_ci * Free a CENC context 57cabdff1aSopenharmony_ci */ 58cabdff1aSopenharmony_civoid ff_mov_cenc_free(MOVMuxCencContext* ctx); 59cabdff1aSopenharmony_ci 60cabdff1aSopenharmony_ci/** 61cabdff1aSopenharmony_ci * Write a fully encrypted packet 62cabdff1aSopenharmony_ci */ 63cabdff1aSopenharmony_ciint ff_mov_cenc_write_packet(MOVMuxCencContext* ctx, AVIOContext *pb, const uint8_t *buf_in, int size); 64cabdff1aSopenharmony_ci 65cabdff1aSopenharmony_ci/** 66cabdff1aSopenharmony_ci * Parse AVC NAL units from annex B format, the nal size and type are written in the clear while the body is encrypted 67cabdff1aSopenharmony_ci */ 68cabdff1aSopenharmony_ciint ff_mov_cenc_avc_parse_nal_units(MOVMuxCencContext* ctx, AVIOContext *pb, const uint8_t *buf_in, int size); 69cabdff1aSopenharmony_ci 70cabdff1aSopenharmony_ci/** 71cabdff1aSopenharmony_ci * Write AVC NAL units that are in MP4 format, the nal size and type are written in the clear while the body is encrypted 72cabdff1aSopenharmony_ci */ 73cabdff1aSopenharmony_ciint ff_mov_cenc_avc_write_nal_units(AVFormatContext *s, MOVMuxCencContext* ctx, int nal_length_size, 74cabdff1aSopenharmony_ci AVIOContext *pb, const uint8_t *buf_in, int size); 75cabdff1aSopenharmony_ci 76cabdff1aSopenharmony_ci/** 77cabdff1aSopenharmony_ci * Write the cenc atoms that should reside inside stbl 78cabdff1aSopenharmony_ci */ 79cabdff1aSopenharmony_civoid ff_mov_cenc_write_stbl_atoms(MOVMuxCencContext* ctx, AVIOContext *pb); 80cabdff1aSopenharmony_ci 81cabdff1aSopenharmony_ci/** 82cabdff1aSopenharmony_ci * Write the sinf atom, contained inside stsd 83cabdff1aSopenharmony_ci */ 84cabdff1aSopenharmony_ciint ff_mov_cenc_write_sinf_tag(struct MOVTrack* track, AVIOContext *pb, uint8_t* kid); 85cabdff1aSopenharmony_ci 86cabdff1aSopenharmony_ci#endif /* AVFORMAT_MOVENCCENC_H */ 87