FFmpeg
bsf_internal.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_INTERNAL_H
20 #define AVCODEC_BSF_INTERNAL_H
21 
23 #include "libavutil/log.h"
24 
25 #include "bsf.h"
26 #include "packet.h"
27 #include "bsf/filters.h"
28 
29 typedef struct FFBitStreamFilter {
30  /**
31  * The public AVBitStreamFilter. See bsf.h for it.
32  */
34 
36  int (*init)(AVBSFContext *ctx);
38  void (*close)(AVBSFContext *ctx);
39  void (*flush)(AVBSFContext *ctx);
40 
41  // Graph based API
42 
43  /**
44  * List of static inputs.
45  */
47 
48  /**
49  * List of static outputs.
50  */
52 
53  /**
54  * The number of entries in the list of inputs.
55  */
56  uint8_t nb_inputs;
57 
58  /**
59  * The number of entries in the list of outputs.
60  */
61  uint8_t nb_outputs;
62 
66 
67  /**
68  * Filter activation function.
69  *
70  * Called when any processing is needed from the filter, instead of any
71  * filter_packet and request_packet on pads.
72  *
73  * The function must examine inlinks and outlinks and perform a single
74  * step of processing. If there is nothing to do, the function must do
75  * nothing and not return an error. If more steps are or may be
76  * possible, it must use ff_filter_set_ready() to schedule another
77  * activation.
78  */
81 
83 {
84  return (const FFBitStreamFilter*)bsf;
85 }
86 
87 /**
88  * Called by the bitstream filters to get the next packet for filtering.
89  * The filter is responsible for either freeing the packet or passing it to the
90  * caller.
91  */
93 
94 /**
95  * Called by bitstream filters to get packet for filtering.
96  * The reference to packet is moved to provided packet structure.
97  *
98  * @param ctx pointer to AVBSFContext of filter
99  * @param pkt pointer to packet to move reference to
100  *
101  * @return 0 on success, negative AVERROR in case of failure
102  */
104 
105 const AVClass *ff_bsf_child_class_iterate(void **opaque);
106 
107 
108 // Graph based API
109 
112 
113  /**
114  * Queue of packets waiting to be filtered.
115  */
117 
118  /**
119  * If set, the source filter can not generate a packet as is.
120  * The goal is to avoid repeatedly calling the request_packet() method on
121  * the same link.
122  */
124 
125  /**
126  * Link input status.
127  * If not zero, all attempts of filter_packet will fail with the
128  * corresponding code.
129  */
131 
132  /**
133  * Timestamp of the input status change.
134  */
136 
137  /**
138  * Link output status.
139  * If not zero, all attempts of request_packet will fail with the
140  * corresponding code.
141  */
143 
144  /**
145  * True if a packet is currently wanted on the output of this filter.
146  * Set when ff_request_packet() is called by the output,
147  * cleared when a packet is filtered.
148  */
150 
151  /**
152  * Index in the age array.
153  */
155 
156  /** stage of the initialization of the link properties (dimensions, etc) */
157  enum {
158  AVLINK_UNINIT = 0, ///< not started
159  AVLINK_STARTINIT, ///< started, but incomplete
160  AVLINK_INIT ///< complete
161  } init_state;
163 
165 {
167 }
168 
170 
171 /**
172  * Run one round of processing on a filter graph.
173  */
175 
177 
179 
180 typedef struct FFBitStreamFilterContext {
181  /**
182  * The public AVBitStreamFilterContext. See bsf.h for it.
183  */
185 
186  // AV_CLASS_STATE_FLAG_*
187  unsigned state_flags;
188 
189  /**
190  * Ready status of the filter.
191  * A non-0 value means that the filter needs activating;
192  * a higher value suggests a more urgent activation.
193  */
194  unsigned ready;
196 
198 {
199  return (FFBitStreamFilterContext*)ctx;
200 }
201 
202 /**
203  * Free a filter context. This will also remove the filter from its
204  * filtergraph's list of filters.
205  *
206  * @param filter the filter to free
207  */
209 
210 typedef struct FFBitStreamFilterGraph {
211  /**
212  * The public AVBitStreamFilterGraph. See bsf.h for it.
213  */
215 
220 
224 
226 {
227  return (FFBitStreamFilterGraph*)graph;
228 }
229 
231 {
232  return (const FFBitStreamFilterGraph*)graph;
233 }
234 
235 /**
236  * Allocate a new filter context and return it.
237  *
238  * @param[in] filter what filter to create an instance of
239  * @param[in] inst_name name to give to the new filter context
240  * @param[out] ctx a pointer into which the pointer to the newly-allocated context
241  * will be written
242  *
243  * @return 0 on success, an AVERROR code on failure
244  */
245 int ff_bsf_alloc(const AVBitStreamFilter *filter, const char *inst_name, AVBitStreamFilterContext **ctx);
246 
247 /**
248  * Remove a filter from a graph;
249  */
251 
252 #endif /* AVCODEC_BSF_INTERNAL_H */
ff_bsf
static const av_always_inline FFBitStreamFilter * ff_bsf(const AVBitStreamFilter *bsf)
Definition: bsf_internal.h:82
BitStreamFilterLinkInternal::status_out
int status_out
Link output status.
Definition: bsf_internal.h:142
FFBitStreamFilter::uninit
void(* uninit)(AVBitStreamFilterContext *ctx)
Definition: bsf_internal.h:65
cffbsffiltergraph
static const FFBitStreamFilterGraph * cffbsffiltergraph(const AVBitStreamFilterGraph *graph)
Definition: bsf_internal.h:230
int64_t
long long int64_t
Definition: coverity.c:34
AVBitStreamFilterPad
A filter pad used for either input or output.
Definition: filters.h:35
FFBitStreamFilter::preinit
int(* preinit)(AVBitStreamFilterContext *ctx)
Definition: bsf_internal.h:63
FFBitStreamFilterContext::ready
unsigned ready
Ready status of the filter.
Definition: bsf_internal.h:194
container_fifo.h
BitStreamFilterLinkInternal::init_state
enum BitStreamFilterLinkInternal::@85 init_state
stage of the initialization of the link properties (dimensions, etc)
FFBitStreamFilterGraph::source_links
struct BitStreamFilterLinkInternal ** source_links
Definition: bsf_internal.h:217
FFBitStreamFilterGraph::sink_links
struct BitStreamFilterLinkInternal ** sink_links
Definition: bsf_internal.h:216
FFBitStreamFilter::nb_inputs
uint8_t nb_inputs
The number of entries in the list of inputs.
Definition: bsf_internal.h:56
ff_bsf_graph_run_once
int ff_bsf_graph_run_once(AVBitStreamFilterGraph *graph)
Run one round of processing on a filter graph.
Definition: bsfgraph.c:361
filter
void(* filter)(uint8_t *src, int stride, int qscale)
Definition: h263dsp.c:29
BitStreamFilterLinkInternal::packet_blocked_in
int packet_blocked_in
If set, the source filter can not generate a packet as is.
Definition: bsf_internal.h:123
BitStreamFilterLinkInternal::status_in
int status_in
Link input status.
Definition: bsf_internal.h:130
AVBSFContext
The bitstream filter state.
Definition: bsf.h:68
BitStreamFilterLinkInternal::packet_wanted_out
int packet_wanted_out
True if a packet is currently wanted on the output of this filter.
Definition: bsf_internal.h:149
av_always_inline
#define av_always_inline
Definition: attributes.h:76
bsf.h
ff_bsf_get_packet_ref
int ff_bsf_get_packet_ref(AVBSFContext *ctx, AVPacket *pkt)
Called by bitstream filters to get packet for filtering.
Definition: bsf.c:254
BitStreamFilterLinkInternal::fifo
AVContainerFifo * fifo
Queue of packets waiting to be filtered.
Definition: bsf_internal.h:116
BitStreamFilterLinkInternal::AVLINK_STARTINIT
@ AVLINK_STARTINIT
started, but incomplete
Definition: bsf_internal.h:159
FFBitStreamFilter::priv_data_size
int priv_data_size
Definition: bsf_internal.h:35
FFBitStreamFilter::activate
int(* activate)(AVBitStreamFilterContext *ctx)
Filter activation function.
Definition: bsf_internal.h:79
ctx
static AVFormatContext * ctx
Definition: movenc.c:49
BitStreamFilterLinkInternal::AVLINK_UNINIT
@ AVLINK_UNINIT
not started
Definition: bsf_internal.h:158
ff_bsf_alloc
int ff_bsf_alloc(const AVBitStreamFilter *filter, const char *inst_name, AVBitStreamFilterContext **ctx)
Allocate a new filter context and return it.
Definition: bitstreamfilter.c:54
AVContainerFifo
AVContainerFifo is a FIFO for "containers" - dynamically allocated reusable structs (e....
Definition: container_fifo.c:27
FFBitStreamFilterContext::p
AVBitStreamFilterContext p
The public AVBitStreamFilterContext.
Definition: bsf_internal.h:184
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
filters.h
FFBitStreamFilterGraph::packets_queued
size_t packets_queued
Definition: bsf_internal.h:222
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:76
FFBitStreamFilter
Definition: bsf_internal.h:29
FFBitStreamFilter::init
int(* init)(AVBSFContext *ctx)
Definition: bsf_internal.h:36
ff_bsf_activate
int ff_bsf_activate(AVBitStreamFilterContext *ctx)
Definition: bitstreamfilter.c:797
FFBitStreamFilterGraph::source_links_count
int source_links_count
Definition: bsf_internal.h:219
BitStreamFilterLinkInternal::age_index
int age_index
Index in the age array.
Definition: bsf_internal.h:154
FFBitStreamFilter::p
AVBitStreamFilter p
The public AVBitStreamFilter.
Definition: bsf_internal.h:33
ff_bsf_config_links
int ff_bsf_config_links(AVBitStreamFilterContext *filter)
Definition: bitstreamfilter.c:452
ff_link_internal
static BitStreamFilterLinkInternal * ff_link_internal(AVBitStreamFilterLink *link)
Definition: bsf_internal.h:164
FFBitStreamFilter::flush
void(* flush)(AVBSFContext *ctx)
Definition: bsf_internal.h:39
FFBitStreamFilterContext::state_flags
unsigned state_flags
Definition: bsf_internal.h:187
FFBitStreamFilter::outputs
const struct AVBitStreamFilterPad * outputs
List of static outputs.
Definition: bsf_internal.h:51
FFBitStreamFilter::filter
int(* filter)(AVBSFContext *ctx, AVPacket *pkt)
Definition: bsf_internal.h:37
log.h
ff_bsf_graph_update_heap
void ff_bsf_graph_update_heap(AVBitStreamFilterGraph *graph, BitStreamFilterLinkInternal *li)
Definition: bsfgraph.c:353
packet.h
FFBitStreamFilterGraph::p
AVBitStreamFilterGraph p
The public AVBitStreamFilterGraph.
Definition: bsf_internal.h:214
FFBitStreamFilter::inputs
const struct AVBitStreamFilterPad * inputs
List of static inputs.
Definition: bsf_internal.h:46
FFBitStreamFilterContext
Definition: bsf_internal.h:180
FFBitStreamFilterGraph::max_packet_queue
size_t max_packet_queue
Definition: bsf_internal.h:221
ff_bsf_free
void ff_bsf_free(AVBitStreamFilterContext *filter)
Free a filter context.
Definition: bitstreamfilter.c:226
AVBitStreamFilter
Definition: bsf.h:111
FFBitStreamFilter::close
void(* close)(AVBSFContext *ctx)
Definition: bsf_internal.h:38
ff_bsf_child_class_iterate
const AVClass * ff_bsf_child_class_iterate(void **opaque)
Definition: bitstream_filters.c:116
FFBitStreamFilterGraph
Definition: bsf_internal.h:210
FFBitStreamFilterGraph::sink_links_count
int sink_links_count
Definition: bsf_internal.h:218
BitStreamFilterLinkInternal
Definition: bsf_internal.h:110
BitStreamFilterLinkInternal::status_in_pts
int64_t status_in_pts
Timestamp of the input status change.
Definition: bsf_internal.h:135
ffbsffiltergraph
static FFBitStreamFilterGraph * ffbsffiltergraph(AVBitStreamFilterGraph *graph)
Definition: bsf_internal.h:225
ff_bsf_get_packet
int ff_bsf_get_packet(AVBSFContext *ctx, AVPacket **pkt)
Called by the bitstream filters to get the next packet for filtering.
Definition: bsf.c:233
AVPacket
This structure stores compressed data.
Definition: packet.h:580
FFBitStreamFilter::nb_outputs
uint8_t nb_outputs
The number of entries in the list of outputs.
Definition: bsf_internal.h:61
FFBitStreamFilter::init2
int(* init2)(AVBitStreamFilterContext *ctx)
Definition: bsf_internal.h:64
ff_bsf_graph_remove_filter
void ff_bsf_graph_remove_filter(AVBitStreamFilterGraph *graph, AVBitStreamFilterContext *filter)
Remove a filter from a graph;.
Definition: bsfgraph.c:64
BitStreamFilterLinkInternal::AVLINK_INIT
@ AVLINK_INIT
complete
Definition: bsf_internal.h:160
BitStreamFilterLinkInternal::l
AVBitStreamFilterLink l
Definition: bsf_internal.h:111
AVBitStreamFilterContext
An instance of a filter.
Definition: bsf.h:347
pkt
static AVPacket * pkt
Definition: demux_decode.c:55
AVBitStreamFilterGraph
Definition: bsf.h:477
ffbsfctx
static FFBitStreamFilterContext * ffbsfctx(AVBitStreamFilterContext *ctx)
Definition: bsf_internal.h:197