FFmpeg
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"
26 #include "libavcodec/codec_par.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  */
107 typedef 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  */
171 void 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 
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 */
AVCodecParameters
This struct describes the properties of an encoded stream.
Definition: codec_par.h:49
rational.h
int64_t
long long int64_t
Definition: coverity.c:34
AVBitStreamFilterPad
A filter pad used for either input or output.
Definition: filters.h:35
filter
void(* filter)(uint8_t *src, int stride, int qscale)
Definition: h263dsp.c:29
ff_bsf_set_ready
void ff_bsf_set_ready(AVBitStreamFilterContext *filter, unsigned priority)
Mark a filter ready and schedule it for activation.
Definition: bitstreamfilter.c:400
bsf.h
ff_bsf_inlink_set_status
void ff_bsf_inlink_set_status(AVBitStreamFilterLink *link, int status)
Definition: bitstreamfilter.c:875
pts
static int64_t pts
Definition: transcode_aac.c:649
AVBitStreamFilterPad::flags
int flags
A combination of FF_BSF_PAD_FLAG_* flags.
Definition: filters.h:66
AVBitStreamFilterPad::request_packet
int(* request_packet)(AVBitStreamFilterLink *link)
Packet request callback.
Definition: filters.h:87
ff_bsf_outlink_packet_wanted
int ff_bsf_outlink_packet_wanted(AVBitStreamFilterLink *link)
Definition: bitstreamfilter.c:901
AVBitStreamFilterPad::codec_ids
enum AVCodecID * codec_ids
A list of codec ids supported by the pad, terminated by AV_CODEC_ID_NONE.
Definition: filters.h:48
ff_bsf_inlink_check_available_packet
int ff_bsf_inlink_check_available_packet(AVBitStreamFilterLink *link)
Definition: bitstreamfilter.c:832
link
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a link
Definition: filter_design.txt:23
ff_bsf_outlink_get_status
int ff_bsf_outlink_get_status(AVBitStreamFilterLink *link)
Definition: bitstreamfilter.c:895
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
ff_bsf_inlink_consume_packet
int ff_bsf_inlink_consume_packet(AVBitStreamFilterLink *link, AVPacket **pkt)
Definition: bitstreamfilter.c:844
ff_bsf_inlink_request_packet
void ff_bsf_inlink_request_packet(AVBitStreamFilterLink *link)
Definition: bitstreamfilter.c:866
ff_bsf_inlink_queued_packets
size_t ff_bsf_inlink_queued_packets(AVBitStreamFilterLink *link)
Definition: bitstreamfilter.c:826
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:47
ff_bsf_source_get_nb_failed_requests
unsigned ff_bsf_source_get_nb_failed_requests(const AVBitStreamFilterContext *src)
Get the number of failed requests.
Definition: source.c:161
ff_bsf_inlink_acknowledge_status
int ff_bsf_inlink_acknowledge_status(AVBitStreamFilterLink *link, int *rstatus, int64_t *rpts)
Definition: bitstreamfilter.c:810
ff_bsf_link_set_in_status
void ff_bsf_link_set_in_status(AVBitStreamFilterLink *link, int status, int64_t pts)
Definition: bitstreamfilter.c:420
AVBitStreamFilterPad::config_props
int(* config_props)(AVBitStreamFilterLink *link)
Link configuration callback.
Definition: filters.h:101
log.h
packet.h
status
ov_status_e status
Definition: dnn_backend_openvino.c:100
ff_default_bsf_pad
const AVBitStreamFilterPad ff_default_bsf_pad[1]
Definition: bitstreamfilter.c:907
AVBitStreamFilterPad::name
const char * name
Pad name.
Definition: filters.h:41
codec_par.h
AVPacket
This structure stores compressed data.
Definition: packet.h:580
ff_bsf_request_packet
int ff_bsf_request_packet(AVBitStreamFilterLink *link)
Definition: bitstreamfilter.c:568
AVBitStreamFilterContext
An instance of a filter.
Definition: bsf.h:347
pkt
static AVPacket * pkt
Definition: demux_decode.c:55
AVBitStreamFilterGraph
Definition: bsf.h:477
ff_bsf_filter_packet
int ff_bsf_filter_packet(AVBitStreamFilterLink *link, AVPacket *pkt)
Send a packet of data to the next filter.
Definition: bitstreamfilter.c:666
src
#define src
Definition: vp8dsp.c:248
AVBitStreamFilterPad::filter
int(* filter)(AVBitStreamFilterLink *link, AVPacket *pkt)
Filtering callback.
Definition: filters.h:78