Path: blob/master/dep/ffmpeg/include/libavutil/encryption_info.h
4216 views
/**1* This file is part of FFmpeg.2*3* FFmpeg is free software; you can redistribute it and/or4* modify it under the terms of the GNU Lesser General Public5* License as published by the Free Software Foundation; either6* version 2.1 of the License, or (at your option) any later version.7*8* FFmpeg is distributed in the hope that it will be useful,9* but WITHOUT ANY WARRANTY; without even the implied warranty of10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU11* Lesser General Public License for more details.12*13* You should have received a copy of the GNU Lesser General Public14* License along with FFmpeg; if not, write to the Free Software15* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA16*/1718#ifndef AVUTIL_ENCRYPTION_INFO_H19#define AVUTIL_ENCRYPTION_INFO_H2021#include <stddef.h>22#include <stdint.h>2324typedef struct AVSubsampleEncryptionInfo {25/** The number of bytes that are clear. */26unsigned int bytes_of_clear_data;2728/**29* The number of bytes that are protected. If using pattern encryption,30* the pattern applies to only the protected bytes; if not using pattern31* encryption, all these bytes are encrypted.32*/33unsigned int bytes_of_protected_data;34} AVSubsampleEncryptionInfo;3536/**37* This describes encryption info for a packet. This contains frame-specific38* info for how to decrypt the packet before passing it to the decoder.39*40* The size of this struct is not part of the public ABI.41*/42typedef struct AVEncryptionInfo {43/** The fourcc encryption scheme, in big-endian byte order. */44uint32_t scheme;4546/**47* Only used for pattern encryption. This is the number of 16-byte blocks48* that are encrypted.49*/50uint32_t crypt_byte_block;5152/**53* Only used for pattern encryption. This is the number of 16-byte blocks54* that are clear.55*/56uint32_t skip_byte_block;5758/**59* The ID of the key used to encrypt the packet. This should always be60* 16 bytes long, but may be changed in the future.61*/62uint8_t *key_id;63uint32_t key_id_size;6465/**66* The initialization vector. This may have been zero-filled to be the67* correct block size. This should always be 16 bytes long, but may be68* changed in the future.69*/70uint8_t *iv;71uint32_t iv_size;7273/**74* An array of subsample encryption info specifying how parts of the sample75* are encrypted. If there are no subsamples, then the whole sample is76* encrypted.77*/78AVSubsampleEncryptionInfo *subsamples;79uint32_t subsample_count;80} AVEncryptionInfo;8182/**83* This describes info used to initialize an encryption key system.84*85* The size of this struct is not part of the public ABI.86*/87typedef struct AVEncryptionInitInfo {88/**89* A unique identifier for the key system this is for, can be NULL if it90* is not known. This should always be 16 bytes, but may change in the91* future.92*/93uint8_t* system_id;94uint32_t system_id_size;9596/**97* An array of key IDs this initialization data is for. All IDs are the98* same length. Can be NULL if there are no known key IDs.99*/100uint8_t** key_ids;101/** The number of key IDs. */102uint32_t num_key_ids;103/**104* The number of bytes in each key ID. This should always be 16, but may105* change in the future.106*/107uint32_t key_id_size;108109/**110* Key-system specific initialization data. This data is copied directly111* from the file and the format depends on the specific key system. This112* can be NULL if there is no initialization data; in that case, there113* will be at least one key ID.114*/115uint8_t* data;116uint32_t data_size;117118/**119* An optional pointer to the next initialization info in the list.120*/121struct AVEncryptionInitInfo *next;122} AVEncryptionInitInfo;123124/**125* Allocates an AVEncryptionInfo structure and sub-pointers to hold the given126* number of subsamples. This will allocate pointers for the key ID, IV,127* and subsample entries, set the size members, and zero-initialize the rest.128*129* @param subsample_count The number of subsamples.130* @param key_id_size The number of bytes in the key ID, should be 16.131* @param iv_size The number of bytes in the IV, should be 16.132*133* @return The new AVEncryptionInfo structure, or NULL on error.134*/135AVEncryptionInfo *av_encryption_info_alloc(uint32_t subsample_count, uint32_t key_id_size, uint32_t iv_size);136137/**138* Allocates an AVEncryptionInfo structure with a copy of the given data.139* @return The new AVEncryptionInfo structure, or NULL on error.140*/141AVEncryptionInfo *av_encryption_info_clone(const AVEncryptionInfo *info);142143/**144* Frees the given encryption info object. This MUST NOT be used to free the145* side-data data pointer, that should use normal side-data methods.146*/147void av_encryption_info_free(AVEncryptionInfo *info);148149/**150* Creates a copy of the AVEncryptionInfo that is contained in the given side151* data. The resulting object should be passed to av_encryption_info_free()152* when done.153*154* @return The new AVEncryptionInfo structure, or NULL on error.155*/156AVEncryptionInfo *av_encryption_info_get_side_data(const uint8_t *side_data, size_t side_data_size);157158/**159* Allocates and initializes side data that holds a copy of the given encryption160* info. The resulting pointer should be either freed using av_free or given161* to av_packet_add_side_data().162*163* @return The new side-data pointer, or NULL.164*/165uint8_t *av_encryption_info_add_side_data(166const AVEncryptionInfo *info, size_t *side_data_size);167168169/**170* Allocates an AVEncryptionInitInfo structure and sub-pointers to hold the171* given sizes. This will allocate pointers and set all the fields.172*173* @return The new AVEncryptionInitInfo structure, or NULL on error.174*/175AVEncryptionInitInfo *av_encryption_init_info_alloc(176uint32_t system_id_size, uint32_t num_key_ids, uint32_t key_id_size, uint32_t data_size);177178/**179* Frees the given encryption init info object. This MUST NOT be used to free180* the side-data data pointer, that should use normal side-data methods.181*/182void av_encryption_init_info_free(AVEncryptionInitInfo* info);183184/**185* Creates a copy of the AVEncryptionInitInfo that is contained in the given186* side data. The resulting object should be passed to187* av_encryption_init_info_free() when done.188*189* @return The new AVEncryptionInitInfo structure, or NULL on error.190*/191AVEncryptionInitInfo *av_encryption_init_info_get_side_data(192const uint8_t* side_data, size_t side_data_size);193194/**195* Allocates and initializes side data that holds a copy of the given encryption196* init info. The resulting pointer should be either freed using av_free or197* given to av_packet_add_side_data().198*199* @return The new side-data pointer, or NULL.200*/201uint8_t *av_encryption_init_info_add_side_data(202const AVEncryptionInitInfo *info, size_t *side_data_size);203204#endif /* AVUTIL_ENCRYPTION_INFO_H */205206207