FFmpeg
video_enc_params.c
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
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.
8  *
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.
13  *
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
17  */
18 
19 #include <stddef.h>
20 #include <stdint.h>
21 
22 #include "buffer.h"
23 #include "frame.h"
24 #include "mem.h"
25 #include "video_enc_params.h"
26 
28  unsigned int nb_blocks, size_t *out_size)
29 {
30  struct TestStruct {
33  };
34  const size_t blocks_offset = offsetof(struct TestStruct, b);
35  size_t size = blocks_offset;
36  AVVideoEncParams *par;
37 
38  if (nb_blocks > (SIZE_MAX - size) / sizeof(AVVideoBlockParams))
39  return NULL;
40  size += sizeof(AVVideoBlockParams) * nb_blocks;
41 
42  par = av_mallocz(size);
43  if (!par)
44  return NULL;
45 
46  par->type = type;
47  par->nb_blocks = nb_blocks;
48  par->block_size = sizeof(AVVideoBlockParams);
49  par->blocks_offset = blocks_offset;
50 
51  if (out_size)
52  *out_size = size;
53 
54  return par;
55 }
56 
59  unsigned int nb_blocks)
60 {
61  AVBufferRef *buf;
62  AVVideoEncParams *par;
63  size_t size;
64 
65  par = av_video_enc_params_alloc(type, nb_blocks, &size);
66  if (!par)
67  return NULL;
68  buf = av_buffer_create((uint8_t *)par, size, NULL, NULL, 0);
69  if (!buf) {
70  av_freep(&par);
71  return NULL;
72  }
73 
75  av_buffer_unref(&buf);
76  return NULL;
77  }
78 
79  return par;
80 }
AVVideoEncParams::blocks_offset
size_t blocks_offset
Offset in bytes from the beginning of this structure at which the array of blocks starts.
Definition: video_enc_params.h:86
out_size
int out_size
Definition: movenc.c:55
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:375
b
#define b
Definition: input.c:41
TestStruct
Definition: audio_fifo.c:29
av_video_enc_params_alloc
AVVideoEncParams * av_video_enc_params_alloc(enum AVVideoEncParamsType type, unsigned int nb_blocks, size_t *out_size)
Allocates memory for AVVideoEncParams of the given type, plus an array of.
Definition: video_enc_params.c:27
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
AVVideoEncParams
Video encoding parameters for a given frame.
Definition: video_enc_params.h:73
AVVideoEncParamsType
AVVideoEncParamsType
Definition: video_enc_params.h:28
AVVideoEncParams::type
enum AVVideoEncParamsType type
Type of the parameters (the codec they are used with).
Definition: video_enc_params.h:95
frame
static AVFrame * frame
Definition: demux_decode.c:54
NULL
#define NULL
Definition: coverity.c:32
av_buffer_unref
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Definition: buffer.c:139
av_frame_new_side_data_from_buf
AVFrameSideData * av_frame_new_side_data_from_buf(AVFrame *frame, enum AVFrameSideDataType type, AVBufferRef *buf)
Add a new side data to a frame from an existing AVBufferRef.
Definition: frame.c:777
AVVideoEncParams::block_size
size_t block_size
Definition: video_enc_params.h:90
av_buffer_create
AVBufferRef * av_buffer_create(uint8_t *data, size_t size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
Definition: buffer.c:55
av_video_enc_params_create_side_data
AVVideoEncParams * av_video_enc_params_create_side_data(AVFrame *frame, enum AVVideoEncParamsType type, unsigned int nb_blocks)
Allocates memory for AVEncodeInfoFrame plus an array of.
Definition: video_enc_params.c:58
size
int size
Definition: twinvq_data.h:10344
AVVideoEncParams::nb_blocks
unsigned int nb_blocks
Number of blocks in the array.
Definition: video_enc_params.h:81
frame.h
buffer.h
AVVideoBlockParams
Data structure for storing block-level encoding information.
Definition: video_enc_params.h:120
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:254
AV_FRAME_DATA_VIDEO_ENC_PARAMS
@ AV_FRAME_DATA_VIDEO_ENC_PARAMS
Encoding parameters for a video frame, as described by AVVideoEncParams.
Definition: frame.h:170
mem.h
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
video_enc_params.h