Coverage Report

Created: 2026-01-25 07:18

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ffmpeg/libavcodec/encode.h
Line
Count
Source
1
/*
2
 * generic encoding-related code
3
 *
4
 * This file is part of FFmpeg.
5
 *
6
 * FFmpeg is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU Lesser General Public
8
 * License as published by the Free Software Foundation; either
9
 * version 2.1 of the License, or (at your option) any later version.
10
 *
11
 * FFmpeg is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 * Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public
17
 * License along with FFmpeg; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
 */
20
21
#ifndef AVCODEC_ENCODE_H
22
#define AVCODEC_ENCODE_H
23
24
#include "libavutil/frame.h"
25
26
#include "avcodec.h"
27
#include "packet.h"
28
29
/**
30
 * Used by some encoders as upper bound for the length of headers.
31
 * TODO: Use proper codec-specific upper bounds.
32
 */
33
#define FF_INPUT_BUFFER_MIN_SIZE 16384
34
35
/**
36
 * Called by encoders to get the next frame for encoding.
37
 *
38
 * @param frame An empty frame to be filled with data.
39
 * @return 0 if a new reference has been successfully written to frame
40
 *         AVERROR(EAGAIN) if no data is currently available
41
 *         AVERROR_EOF if end of stream has been reached, so no more data
42
 *                     will be available
43
 */
44
int ff_encode_get_frame(AVCodecContext *avctx, AVFrame *frame);
45
46
/**
47
 * Get a buffer for a packet. This is a wrapper around
48
 * AVCodecContext.get_encode_buffer() and should be used instead calling get_encode_buffer()
49
 * directly.
50
 */
51
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags);
52
53
/**
54
 * Allocate buffers for a frame. Encoder equivalent to ff_get_buffer().
55
 */
56
int ff_encode_alloc_frame(AVCodecContext *avctx, AVFrame *frame);
57
58
/**
59
 * Check AVPacket size and allocate data.
60
 *
61
 * Encoders of type FF_CODEC_CB_TYPE_ENCODE can use this as a convenience to
62
 * obtain a big enough buffer for the encoded bitstream.
63
 *
64
 * @param avctx   the AVCodecContext of the encoder
65
 * @param avpkt   The AVPacket: on success, avpkt->data will point to a buffer
66
 *                of size at least `size`; the packet will not be refcounted.
67
 *                This packet must be initially blank.
68
 * @param size    an upper bound of the size of the packet to encode
69
 * @return        non negative on success, negative error code on failure
70
 */
71
int ff_alloc_packet(AVCodecContext *avctx, AVPacket *avpkt, int64_t size);
72
73
/**
74
 * Propagate user opaque values from the frame to avctx/pkt as needed.
75
 */
76
int ff_encode_reordered_opaque(AVCodecContext *avctx,
77
                               AVPacket *pkt, const AVFrame *frame);
78
79
int ff_encode_encode_cb(AVCodecContext *avctx, AVPacket *avpkt,
80
                        AVFrame *frame, int *got_packet);
81
82
/**
83
 * Add a CPB properties side data to an encoding context.
84
 */
85
AVCPBProperties *ff_encode_add_cpb_side_data(AVCodecContext *avctx);
86
87
int ff_encode_add_stats_side_data(AVPacket *pkt, int quality, const int64_t error[],
88
                                  int error_count, enum AVPictureType pict_type);
89
90
/**
91
 * Rescale from sample rate to AVCodecContext.time_base.
92
 */
93
static av_always_inline int64_t ff_samples_to_time_base(const AVCodecContext *avctx,
94
                                                        int64_t samples)
95
0
{
96
0
    if (samples == AV_NOPTS_VALUE)
97
0
        return AV_NOPTS_VALUE;
98
0
    return av_rescale_q(samples, (AVRational){ 1, avctx->sample_rate },
99
0
                        avctx->time_base);
100
0
}
101
102
/**
103
 * Check if the elements of codec context matrices (intra_matrix, inter_matrix or
104
 * chroma_intra_matrix) are within the specified range.
105
 */
106
#define FF_MATRIX_TYPE_INTRA        (1U << 0)
107
#define FF_MATRIX_TYPE_INTER        (1U << 1)
108
#define FF_MATRIX_TYPE_CHROMA_INTRA (1U << 2)
109
int ff_check_codec_matrices(AVCodecContext *avctx, unsigned types, uint16_t min, uint16_t max);
110
111
#endif /* AVCODEC_ENCODE_H */