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 <limits.h>
20 #include <stddef.h>
21 #include <stdint.h>
22 
23 #include "buffer.h"
24 #include "common.h"
25 #include "frame.h"
26 #include "mem.h"
27 #include "video_enc_params.h"
28 
30  unsigned int nb_blocks, size_t *out_size)
31 {
32  AVVideoEncParams *par;
33  size_t size;
34 
35  size = sizeof(*par);
36  if (nb_blocks > SIZE_MAX / sizeof(AVVideoBlockParams) ||
37  nb_blocks * sizeof(AVVideoBlockParams) > SIZE_MAX - size)
38  return NULL;
39  size += sizeof(AVVideoBlockParams) * nb_blocks;
40 
41  par = av_mallocz(size);
42  if (!par)
43  return NULL;
44 
45  par->type = type;
46  par->nb_blocks = nb_blocks;
47  par->block_size = sizeof(AVVideoBlockParams);
48  par->blocks_offset = sizeof(*par);
49 
50  if (out_size)
51  *out_size = size;
52 
53  return par;
54 }
55 
58  unsigned int nb_blocks)
59 {
60  AVBufferRef *buf;
61  AVVideoEncParams *par;
62  size_t size;
63 
64  par = av_video_enc_params_alloc(type, nb_blocks, &size);
65  if (!par)
66  return NULL;
67  buf = av_buffer_create((uint8_t *)par, size, NULL, NULL, 0);
68  if (!buf) {
69  av_freep(&par);
70  return NULL;
71  }
72 
74  av_buffer_unref(&buf);
75  return NULL;
76  }
77 
78  return par;
79 }
#define NULL
Definition: coverity.c:32
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:125
This structure describes decoded (raw) audio or video data.
Definition: frame.h:308
size_t blocks_offset
Offset in bytes from the beginning of this structure at which the array of blocks starts...
Memory handling functions.
GLint GLenum type
Definition: opengl_enc.c:104
int out_size
Definition: movenc.c:55
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:237
AVVideoEncParamsType
uint8_t
Data structure for storing block-level encoding information.
ptrdiff_t size
Definition: opengl_enc.c:100
enum AVVideoEncParamsType type
Type of the parameters (the codec they are used with).
AVBufferRef * av_buffer_create(uint8_t *data, int size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
Definition: buffer.c:29
reference-counted frame API
Video encoding parameters for a given frame.
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:707
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.
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
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.
refcounted data buffer API
unsigned int nb_blocks
Number of blocks in the array.
A reference to a data buffer.
Definition: buffer.h:81
common internal and external API header
Encoding parameters for a video frame, as described by AVVideoEncParams.
Definition: frame.h:186
#define av_freep(p)