| Line | Branch | Exec | Source |
|---|---|---|---|
| 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 | |||
| 22 | #include "libavutil/container_fifo.h" | ||
| 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 | */ | ||
| 33 | AVBitStreamFilter p; | ||
| 34 | |||
| 35 | int priv_data_size; | ||
| 36 | int (*init)(AVBSFContext *ctx); | ||
| 37 | int (*filter)(AVBSFContext *ctx, AVPacket *pkt); | ||
| 38 | void (*close)(AVBSFContext *ctx); | ||
| 39 | void (*flush)(AVBSFContext *ctx); | ||
| 40 | |||
| 41 | // Graph based API | ||
| 42 | |||
| 43 | /** | ||
| 44 | * List of static inputs. | ||
| 45 | */ | ||
| 46 | const struct AVBitStreamFilterPad *inputs; | ||
| 47 | |||
| 48 | /** | ||
| 49 | * List of static outputs. | ||
| 50 | */ | ||
| 51 | const struct AVBitStreamFilterPad *outputs; | ||
| 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 | |||
| 63 | int (*preinit)(AVBitStreamFilterContext *ctx); | ||
| 64 | int (*init2)(AVBitStreamFilterContext *ctx); | ||
| 65 | void (*uninit)(AVBitStreamFilterContext *ctx); | ||
| 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 | */ | ||
| 79 | int (*activate)(AVBitStreamFilterContext *ctx); | ||
| 80 | } FFBitStreamFilter; | ||
| 81 | |||
| 82 | 1375217 | static av_always_inline const FFBitStreamFilter *ff_bsf(const AVBitStreamFilter *bsf) | |
| 83 | { | ||
| 84 | 1375217 | 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 | */ | ||
| 92 | int ff_bsf_get_packet(AVBSFContext *ctx, AVPacket **pkt); | ||
| 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 | */ | ||
| 103 | int ff_bsf_get_packet_ref(AVBSFContext *ctx, AVPacket *pkt); | ||
| 104 | |||
| 105 | const AVClass *ff_bsf_child_class_iterate(void **opaque); | ||
| 106 | |||
| 107 | |||
| 108 | // Graph based API | ||
| 109 | |||
| 110 | typedef struct BitStreamFilterLinkInternal { | ||
| 111 | AVBitStreamFilterLink l; | ||
| 112 | |||
| 113 | /** | ||
| 114 | * Queue of packets waiting to be filtered. | ||
| 115 | */ | ||
| 116 | AVContainerFifo *fifo; | ||
| 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 | */ | ||
| 123 | int packet_blocked_in; | ||
| 124 | |||
| 125 | /** | ||
| 126 | * Link input status. | ||
| 127 | * If not zero, all attempts of filter_packet will fail with the | ||
| 128 | * corresponding code. | ||
| 129 | */ | ||
| 130 | int status_in; | ||
| 131 | |||
| 132 | /** | ||
| 133 | * Timestamp of the input status change. | ||
| 134 | */ | ||
| 135 | int64_t status_in_pts; | ||
| 136 | |||
| 137 | /** | ||
| 138 | * Link output status. | ||
| 139 | * If not zero, all attempts of request_packet will fail with the | ||
| 140 | * corresponding code. | ||
| 141 | */ | ||
| 142 | int status_out; | ||
| 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 | */ | ||
| 149 | int packet_wanted_out; | ||
| 150 | |||
| 151 | /** | ||
| 152 | * Index in the age array. | ||
| 153 | */ | ||
| 154 | int age_index; | ||
| 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; | ||
| 162 | } BitStreamFilterLinkInternal; | ||
| 163 | |||
| 164 | ✗ | static inline BitStreamFilterLinkInternal *ff_link_internal(AVBitStreamFilterLink *link) | |
| 165 | { | ||
| 166 | ✗ | return (BitStreamFilterLinkInternal*)link; | |
| 167 | } | ||
| 168 | |||
| 169 | int ff_bsf_config_links(AVBitStreamFilterContext *filter); | ||
| 170 | |||
| 171 | /** | ||
| 172 | * Run one round of processing on a filter graph. | ||
| 173 | */ | ||
| 174 | int ff_bsf_graph_run_once(AVBitStreamFilterGraph *graph); | ||
| 175 | |||
| 176 | int ff_bsf_activate(AVBitStreamFilterContext *ctx); | ||
| 177 | |||
| 178 | void ff_bsf_graph_update_heap(AVBitStreamFilterGraph *graph, BitStreamFilterLinkInternal *li); | ||
| 179 | |||
| 180 | typedef struct FFBitStreamFilterContext { | ||
| 181 | /** | ||
| 182 | * The public AVBitStreamFilterContext. See bsf.h for it. | ||
| 183 | */ | ||
| 184 | AVBitStreamFilterContext p; | ||
| 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; | ||
| 195 | } FFBitStreamFilterContext; | ||
| 196 | |||
| 197 | ✗ | static inline FFBitStreamFilterContext *ffbsfctx(AVBitStreamFilterContext *ctx) | |
| 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 | */ | ||
| 208 | void ff_bsf_free(AVBitStreamFilterContext *filter); | ||
| 209 | |||
| 210 | typedef struct FFBitStreamFilterGraph { | ||
| 211 | /** | ||
| 212 | * The public AVBitStreamFilterGraph. See bsf.h for it. | ||
| 213 | */ | ||
| 214 | AVBitStreamFilterGraph p; | ||
| 215 | |||
| 216 | struct BitStreamFilterLinkInternal **sink_links; | ||
| 217 | struct BitStreamFilterLinkInternal **source_links; | ||
| 218 | int sink_links_count; | ||
| 219 | int source_links_count; | ||
| 220 | |||
| 221 | size_t max_packet_queue; | ||
| 222 | size_t packets_queued; | ||
| 223 | } FFBitStreamFilterGraph; | ||
| 224 | |||
| 225 | 75 | static inline FFBitStreamFilterGraph *ffbsffiltergraph(AVBitStreamFilterGraph *graph) | |
| 226 | { | ||
| 227 | 75 | return (FFBitStreamFilterGraph*)graph; | |
| 228 | } | ||
| 229 | |||
| 230 | ✗ | static inline const FFBitStreamFilterGraph *cffbsffiltergraph(const AVBitStreamFilterGraph *graph) | |
| 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 | */ | ||
| 250 | void ff_bsf_graph_remove_filter(AVBitStreamFilterGraph *graph, AVBitStreamFilterContext *filter); | ||
| 251 | |||
| 252 | #endif /* AVCODEC_BSF_INTERNAL_H */ | ||
| 253 |