FFmpeg
Loading...
Searching...
No Matches
filters.h
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#ifndef AVCODEC_BSF_FILTERS_H
20#define AVCODEC_BSF_FILTERS_H
21
22#include "libavutil/log.h"
23#include "libavutil/rational.h"
24
25#include "libavcodec/bsf.h"
27#include "libavcodec/packet.h"
28
29/**
30 * Special return code when activate() did not do anything.
31 */
32#define FFERROR_BSF_NOT_READY FFERRTAG('N','R','D','Y')
33#define FFERROR_SOURCE_EMPTY FFERRTAG('M','P','T','Y')
34
36 /**
37 * Pad name. The name is unique among inputs and among outputs, but an
38 * input may have the same name as an output. This may be NULL if this
39 * pad has no need to ever be referenced by name.
40 */
41 const char *name;
42
43 /**
44 * A list of codec ids supported by the pad, terminated by
45 * AV_CODEC_ID_NONE.
46 * May be NULL, in that case the pad works with any codec id.
47 */
48 const enum AVCodecID *codec_ids;
49
50 /**
51 * The filter expects writable packets from its input link,
52 * duplicating data buffers if needed.
53 *
54 * input pads only.
55 */
56#define FF_BSF_PAD_FLAG_NEEDS_WRITABLE (1 << 0)
57
58 /**
59 * The pad's name is allocated and should be freed generically.
60 */
61#define FF_BSF_PAD_FLAG_FREE_NAME (1 << 1)
62
63 /**
64 * A combination of FF_BSF_PAD_FLAG_* flags.
65 */
66 int flags;
67
68 /**
69 * Filtering callback. This is where a filter receives a packet with
70 * audio/video data and should do its processing.
71 *
72 * Input pads only.
73 *
74 * @return >= 0 on success, a negative AVERROR on error. This function
75 * must ensure that packet is properly unreferenced on error if it
76 * hasn't been passed on to another filter.
77 */
79
80 /**
81 * Packet request callback. A call to this should result in some progress
82 * towards producing output over the given link. This should return zero
83 * on success, and another value on error.
84 *
85 * Output pads only.
86 */
88
89 /**
90 * Link configuration callback.
91 *
92 * For output pads, this should set the link properties such as
93 * width/height.
94 *
95 * For input pads, this should check the properties of the link, and update
96 * the filter's internal state as necessary.
97 *
98 * For both input and output filters, this should return zero on success,
99 * and another value on error.
100 */
102};
103
104/**
105 * Link properties exposed to filter code, but not external callers.
106 */
107typedef struct AVBitStreamFilterLink {
108 AVBitStreamFilterContext *src; ///< source filter
109 AVBitStreamFilterPad *srcpad; ///< output pad on the source filter
110
111 AVBitStreamFilterContext *dst; ///< dest filter
112 AVBitStreamFilterPad *dstpad; ///< input pad on the dest filter
113
114 /**
115 * Graph the filter belongs to.
116 */
118
119
121
123
124 /**
125 * Current timestamp of the link, as defined by the most recent
126 * packet(s), in link time_base units.
127 */
129
130 /**
131 * Current timestamp of the link, as defined by the most recent
132 * packet(s), in AV_TIME_BASE units.
133 */
135
136 /**
137 * Number of past packets sent through the link.
138 */
141
142#define BSFILTER_INOUTPADS(inout, array) \
143 .inout = array, \
144 .nb_ ## inout = FF_ARRAY_ELEMS(array)
145#define BSFILTER_INPUTS(array) BSFILTER_INOUTPADS(inputs, (array))
146#define BSFILTER_OUTPUTS(array) BSFILTER_INOUTPADS(outputs, (array))
147
149
150#define BSF_DEFINE_CLASS_EXT(name, desc, options) \
151 static const AVClass name##_class = { \
152 .class_name = desc, \
153 .item_name = av_default_item_name, \
154 .option = options, \
155 .version = LIBAVUTIL_VERSION_INT, \
156 .category = AV_CLASS_CATEGORY_BITSTREAM_FILTER, \
157 }
158#define BSF_DEFINE_CLASS(fname) \
159 BSF_DEFINE_CLASS_EXT(fname, #fname, fname##_options)
160
161/**
162 * Mark a filter ready and schedule it for activation.
163 *
164 * This is automatically done when something happens to the filter (queued
165 * packet, status change, request on output).
166 * Filters implementing the activate callback can call it directly to
167 * perform one more round of processing later.
168 * It is also useful for filters reacting to external or asynchronous
169 * events.
170 */
171void ff_bsf_set_ready(AVBitStreamFilterContext *filter, unsigned priority);
172
173/**
174 * Send a packet of data to the next filter.
175 *
176 * @param link the output link over which the data is being sent
177 * @param pkt a reference to the buffer of data being sent. The
178 * receiving filter will free this reference when it no longer
179 * needs it or pass it on to the next filter.
180 *
181 * @return >= 0 on success, a negative AVERROR on error. The receiving filter
182 * is responsible for unreferencing pkt in case of error.
183 */
185
187
189
191
193
195
197
198void ff_bsf_inlink_set_status(AVBitStreamFilterLink *link, int status);
199
201
203
205
206/**
207 * Get the number of failed requests.
208 *
209 * A failed request is when the request_packet method is called while no
210 * packet is present in the buffer.
211 * The number is reset when a packet is added.
212 */
214
215#endif /* AVCODEC_BSF_FILTERS_H */
const AVBitStreamFilterPad ff_default_bsf_pad[1]
long long int64_t
Definition coverity.c:34
static AVPacket * pkt
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition codec_id.h:47
void ff_bsf_set_ready(AVBitStreamFilterContext *filter, unsigned priority)
Mark a filter ready and schedule it for activation.
int ff_bsf_inlink_acknowledge_status(AVBitStreamFilterLink *link, int *rstatus, int64_t *rpts)
unsigned ff_bsf_source_get_nb_failed_requests(const AVBitStreamFilterContext *src)
Get the number of failed requests.
Definition source.c:161
int ff_bsf_outlink_packet_wanted(AVBitStreamFilterLink *link)
int ff_bsf_inlink_consume_packet(AVBitStreamFilterLink *link, AVPacket **pkt)
int ff_bsf_filter_packet(AVBitStreamFilterLink *link, AVPacket *pkt)
Send a packet of data to the next filter.
int ff_bsf_outlink_get_status(AVBitStreamFilterLink *link)
void ff_bsf_link_set_in_status(AVBitStreamFilterLink *link, int status, int64_t pts)
void ff_bsf_inlink_set_status(AVBitStreamFilterLink *link, int status)
size_t ff_bsf_inlink_queued_packets(AVBitStreamFilterLink *link)
int ff_bsf_request_packet(AVBitStreamFilterLink *link)
void ff_bsf_inlink_request_packet(AVBitStreamFilterLink *link)
int ff_bsf_inlink_check_available_packet(AVBitStreamFilterLink *link)
Utilities for rational number calculation.
An instance of a filter.
Definition bsf.h:347
A filter pad used for either input or output.
Definition filters.h:35
const char * name
Pad name.
Definition filters.h:41
int(* config_props)(AVBitStreamFilterLink *link)
Link configuration callback.
Definition filters.h:101
int(* filter)(AVBitStreamFilterLink *link, AVPacket *pkt)
Filtering callback.
Definition filters.h:78
int flags
A combination of FF_BSF_PAD_FLAG_* flags.
Definition filters.h:66
enum AVCodecID * codec_ids
A list of codec ids supported by the pad, terminated by AV_CODEC_ID_NONE.
Definition filters.h:48
int(* request_packet)(AVBitStreamFilterLink *link)
Packet request callback.
Definition filters.h:87
This struct describes the properties of an encoded stream.
Definition codec_par.h:49
This structure stores compressed data.
Definition packet.h:580
Rational number (pair of numerator and denominator).
Definition rational.h:58
void(* filter)(uint8_t *src, ptrdiff_t stride, int qscale)
Definition h263dsp.c:29
#define src
Definition vp8dsp.c:248
static int64_t pts