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
27 #include "video_enc_params.h"
29 AVVideoEncParams *av_video_enc_params_alloc(enum AVVideoEncParamsType type,
30 unsigned int nb_blocks, size_t *out_size)
32 AVVideoEncParams *par;
36 if (nb_blocks > SIZE_MAX / sizeof(AVVideoBlockParams) ||
37 nb_blocks * sizeof(AVVideoBlockParams) > SIZE_MAX - size)
39 size += sizeof(AVVideoBlockParams) * nb_blocks;
41 par = av_mallocz(size);
46 par->nb_blocks = nb_blocks;
47 par->block_size = sizeof(AVVideoBlockParams);
48 par->blocks_offset = sizeof(*par);
57 av_video_enc_params_create_side_data(AVFrame *frame, enum AVVideoEncParamsType type,
58 unsigned int nb_blocks)
61 AVVideoEncParams *par;
64 par = av_video_enc_params_alloc(type, nb_blocks, &size);
67 buf = av_buffer_create((uint8_t *)par, size, NULL, NULL, 0);
73 if (!av_frame_new_side_data_from_buf(frame, AV_FRAME_DATA_VIDEO_ENC_PARAMS, buf)) {
74 av_buffer_unref(&buf);