2 * This file is part of FFmpeg.
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 #ifndef AVUTIL_ENCRYPTION_INFO_H
20 #define AVUTIL_ENCRYPTION_INFO_H
25 typedef struct AVSubsampleEncryptionInfo {
26 /** The number of bytes that are clear. */
27 unsigned int bytes_of_clear_data;
30 * The number of bytes that are protected. If using pattern encryption,
31 * the pattern applies to only the protected bytes; if not using pattern
32 * encryption, all these bytes are encrypted.
34 unsigned int bytes_of_protected_data;
35 } AVSubsampleEncryptionInfo;
38 * This describes encryption info for a packet. This contains frame-specific
39 * info for how to decrypt the packet before passing it to the decoder.
41 * The size of this struct is not part of the public ABI.
43 typedef struct AVEncryptionInfo {
44 /** The fourcc encryption scheme, in big-endian byte order. */
48 * Only used for pattern encryption. This is the number of 16-byte blocks
51 uint32_t crypt_byte_block;
54 * Only used for pattern encryption. This is the number of 16-byte blocks
57 uint32_t skip_byte_block;
60 * The ID of the key used to encrypt the packet. This should always be
61 * 16 bytes long, but may be changed in the future.
67 * The initialization vector. This may have been zero-filled to be the
68 * correct block size. This should always be 16 bytes long, but may be
69 * changed in the future.
75 * An array of subsample encryption info specifying how parts of the sample
76 * are encrypted. If there are no subsamples, then the whole sample is
79 AVSubsampleEncryptionInfo *subsamples;
80 uint32_t subsample_count;
84 * This describes info used to initialize an encryption key system.
86 * The size of this struct is not part of the public ABI.
88 typedef struct AVEncryptionInitInfo {
90 * A unique identifier for the key system this is for, can be NULL if it
91 * is not known. This should always be 16 bytes, but may change in the
95 uint32_t system_id_size;
98 * An array of key IDs this initialization data is for. All IDs are the
99 * same length. Can be NULL if there are no known key IDs.
102 /** The number of key IDs. */
103 uint32_t num_key_ids;
105 * The number of bytes in each key ID. This should always be 16, but may
106 * change in the future.
108 uint32_t key_id_size;
111 * Key-system specific initialization data. This data is copied directly
112 * from the file and the format depends on the specific key system. This
113 * can be NULL if there is no initialization data; in that case, there
114 * will be at least one key ID.
120 * An optional pointer to the next initialization info in the list.
122 struct AVEncryptionInitInfo *next;
123 } AVEncryptionInitInfo;
126 * Allocates an AVEncryptionInfo structure and sub-pointers to hold the given
127 * number of subsamples. This will allocate pointers for the key ID, IV,
128 * and subsample entries, set the size members, and zero-initialize the rest.
130 * @param subsample_count The number of subsamples.
131 * @param key_id_size The number of bytes in the key ID, should be 16.
132 * @param iv_size The number of bytes in the IV, should be 16.
134 * @return The new AVEncryptionInfo structure, or NULL on error.
136 AVEncryptionInfo *av_encryption_info_alloc(uint32_t subsample_count, uint32_t key_id_size, uint32_t iv_size);
139 * Allocates an AVEncryptionInfo structure with a copy of the given data.
140 * @return The new AVEncryptionInfo structure, or NULL on error.
142 AVEncryptionInfo *av_encryption_info_clone(const AVEncryptionInfo *info);
145 * Frees the given encryption info object. This MUST NOT be used to free the
146 * side-data data pointer, that should use normal side-data methods.
148 void av_encryption_info_free(AVEncryptionInfo *info);
151 * Creates a copy of the AVEncryptionInfo that is contained in the given side
152 * data. The resulting object should be passed to av_encryption_info_free()
155 * @return The new AVEncryptionInfo structure, or NULL on error.
157 AVEncryptionInfo *av_encryption_info_get_side_data(const uint8_t *side_data, size_t side_data_size);
160 * Allocates and initializes side data that holds a copy of the given encryption
161 * info. The resulting pointer should be either freed using av_free or given
162 * to av_packet_add_side_data().
164 * @return The new side-data pointer, or NULL.
166 uint8_t *av_encryption_info_add_side_data(
167 const AVEncryptionInfo *info, size_t *side_data_size);
171 * Allocates an AVEncryptionInitInfo structure and sub-pointers to hold the
172 * given sizes. This will allocate pointers and set all the fields.
174 * @return The new AVEncryptionInitInfo structure, or NULL on error.
176 AVEncryptionInitInfo *av_encryption_init_info_alloc(
177 uint32_t system_id_size, uint32_t num_key_ids, uint32_t key_id_size, uint32_t data_size);
180 * Frees the given encryption init info object. This MUST NOT be used to free
181 * the side-data data pointer, that should use normal side-data methods.
183 void av_encryption_init_info_free(AVEncryptionInitInfo* info);
186 * Creates a copy of the AVEncryptionInitInfo that is contained in the given
187 * side data. The resulting object should be passed to
188 * av_encryption_init_info_free() when done.
190 * @return The new AVEncryptionInitInfo structure, or NULL on error.
192 AVEncryptionInitInfo *av_encryption_init_info_get_side_data(
193 const uint8_t* side_data, size_t side_data_size);
196 * Allocates and initializes side data that holds a copy of the given encryption
197 * init info. The resulting pointer should be either freed using av_free or
198 * given to av_packet_add_side_data().
200 * @return The new side-data pointer, or NULL.
202 uint8_t *av_encryption_init_info_add_side_data(
203 const AVEncryptionInitInfo *info, size_t *side_data_size);
205 #endif /* AVUTIL_ENCRYPTION_INFO_H */