Libav
internal.h
Go to the documentation of this file.
1 /*
2  * This file is part of Libav.
3  *
4  * Libav 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  * Libav 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 Libav; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
24 #ifndef AVCODEC_INTERNAL_H
25 #define AVCODEC_INTERNAL_H
26 
27 #include <stdint.h>
28 
29 #include "libavutil/buffer.h"
31 #include "libavutil/mathematics.h"
32 #include "libavutil/pixfmt.h"
33 #include "avcodec.h"
34 #include "config.h"
35 
40 #define FF_CODEC_CAP_INIT_THREADSAFE (1 << 0)
41 
48 #define FF_CODEC_CAP_INIT_CLEANUP (1 << 1)
49 
55 #define FF_CODEC_CAP_SETS_PKT_DTS (1 << 2)
56 
57 #ifdef DEBUG
58 # define ff_dlog(ctx, ...) av_log(ctx, AV_LOG_DEBUG, __VA_ARGS__)
59 #else
60 # define ff_dlog(ctx, ...) do { } while (0)
61 #endif
62 
63 #ifdef TRACE
64 # define ff_tlog(ctx, ...) av_log(ctx, AV_LOG_TRACE, __VA_ARGS__)
65 #else
66 # define ff_tlog(ctx, ...) do { } while (0)
67 #endif
68 
69 
70 #if !FF_API_QUANT_BIAS
71 #define FF_DEFAULT_QUANT_BIAS 999999
72 #endif
73 
74 #define FF_SANE_NB_CHANNELS 63U
75 
76 #define FF_SIGNBIT(x) (x >> CHAR_BIT * sizeof(x) - 1)
77 
78 typedef struct FramePool {
84 
85  /*
86  * Pool parameters
87  */
88  int format;
89  int width, height;
91  int linesize[4];
92  int planes;
93  int channels;
94  int samples;
95 } FramePool;
96 
97 typedef struct AVCodecInternal {
104  int is_copy;
105 
120 
126 
128 
130 
131  void *thread_ctx;
132 
138 
143 
147  int draining;
148 
153  int buffer_pkt_valid; // encoding: packet without data can be valid
157 
159  const uint8_t *key;
160  const uint8_t *value;
161 };
162 
167 int ff_match_2uint16(const uint16_t (*tab)[2], int size, int a, int b);
168 
169 unsigned int avpriv_toupper4(unsigned int x);
170 
171 int avpriv_lock_avformat(void);
172 int avpriv_unlock_avformat(void);
173 
179 #define FF_MAX_EXTRADATA_SIZE ((1 << 28) - AV_INPUT_BUFFER_PADDING_SIZE)
180 
197 int ff_alloc_packet(AVPacket *avpkt, int size);
198 
203  int64_t samples)
204 {
205  return av_rescale_q(samples, (AVRational){ 1, avctx->sample_rate },
206  avctx->time_base);
207 }
208 
214 int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags);
215 
220 int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame);
221 
223  const uint8_t *end,
224  uint32_t *restrict state);
225 
230 int ff_set_dimensions(AVCodecContext *s, int width, int height);
231 
236 int ff_set_sar(AVCodecContext *avctx, AVRational sar);
237 
242  enum AVMatrixEncoding matrix_encoding);
243 
249 int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt);
250 
254 int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame);
255 
260 
261 #endif /* AVCODEC_INTERNAL_H */
#define AV_NUM_DATA_POINTERS
Definition: frame.h:141
int size
This structure describes decoded (raw) audio or video data.
Definition: frame.h:140
int avpriv_unlock_avformat(void)
Definition: utils.c:2638
int stride_align[AV_NUM_DATA_POINTERS]
Definition: internal.h:90
AVFrame * to_free
Definition: internal.h:127
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
Definition: utils.c:134
int width
Definition: internal.h:89
AVPacket * pkt
Current packet as passed into the decoder, to avoid having to pass the packet into every function...
Definition: internal.h:137
int samples
Definition: internal.h:94
AVBufferPool * pools[4]
Pools for each data plane.
Definition: internal.h:83
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avcodec.h:1535
int height
Definition: internal.h:89
uint8_t
void * thread_ctx
Definition: internal.h:131
#define b
Definition: input.c:52
int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame)
Set various frame properties from the codec context / packet data.
Definition: utils.c:534
int planes
Definition: internal.h:92
static int flags
Definition: log.c:50
int ff_set_sar(AVCodecContext *avctx, AVRational sar)
Check that the provided sample aspect ratio is valid and set it on the codec context.
Definition: utils.c:146
The buffer pool.
FramePool * pool
Definition: internal.h:129
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:99
int is_copy
Whether the parent AVCodecContext is a copy of the context which had init() called on it...
Definition: internal.h:104
AVFrame * buffer_frame
Definition: internal.h:154
int avpriv_lock_avformat(void)
Definition: utils.c:2629
int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame)
Identical in function to av_frame_make_writable(), except it uses ff_get_buffer() to allocate the buf...
Definition: utils.c:672
audio channel layout utility functions
int channels
Definition: internal.h:93
int ff_alloc_packet(AVPacket *avpkt, int size)
Check AVPacket size and/or allocate data.
Definition: utils.c:1211
int draining
checks API usage: after codec draining, flush is required to resume operation
Definition: internal.h:147
int linesize[4]
Definition: internal.h:91
int ff_side_data_update_matrix_encoding(AVFrame *frame, enum AVMatrixEncoding matrix_encoding)
Add or update AV_FRAME_DATA_MATRIXENCODING side data.
Definition: utils.c:161
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format.
Definition: utils.c:785
This structure describes the bitrate properties of an encoded bitstream.
Definition: avcodec.h:1140
Libavcodec external API header.
int sample_rate
samples per second
Definition: avcodec.h:2152
main external API structure.
Definition: avcodec.h:1409
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: utils.c:589
unsigned int avpriv_toupper4(unsigned int x)
Definition: utils.c:2647
rational number numerator/denominator
Definition: rational.h:43
int buffer_pkt_valid
Definition: internal.h:153
refcounted data buffer API
int allocate_progress
Whether to allocate progress for frame threading.
Definition: internal.h:119
const uint8_t * key
Definition: internal.h:159
const uint8_t * avpriv_find_start_code(const uint8_t *restrict p, const uint8_t *end, uint32_t *restrict state)
Definition: utils.c:2707
const uint8_t * value
Definition: internal.h:160
AVPacket * buffer_pkt
buffers for using new encode/decode API through legacy API
Definition: internal.h:152
static struct @174 state
void * hwaccel_priv_data
hwaccel-specific private data
Definition: internal.h:142
AVCPBProperties * ff_add_cpb_side_data(AVCodecContext *avctx)
Add a CPB properties side data to an encoding context.
Definition: utils.c:2754
pixel format definitions
static const struct twinvq_data tab
#define restrict
Definition: config.h:8
#define av_always_inline
Definition: attributes.h:40
static av_always_inline int64_t ff_samples_to_time_base(AVCodecContext *avctx, int64_t samples)
Rescale from sample rate to AVCodecContext.time_base.
Definition: internal.h:202
AVMatrixEncoding
int format
Definition: internal.h:88
AVPixelFormat
Pixel format.
Definition: pixfmt.h:57
This structure stores compressed data.
Definition: avcodec.h:1323
int ff_match_2uint16(const uint16_t(*tab)[2], int size, int a, int b)
Return the index into tab at which {a,b} match elements {[0],[1]} of tab.
Definition: utils.c:2545
int last_audio_frame
An audio frame with less than required samples has been submitted and padded with silence...
Definition: internal.h:125