Path: blob/master/dep/ffmpeg/include/libavcodec/bsf.h
4216 views
/*1* Bitstream filters public API2*3* This file is part of FFmpeg.4*5* FFmpeg is free software; you can redistribute it and/or6* modify it under the terms of the GNU Lesser General Public7* License as published by the Free Software Foundation; either8* version 2.1 of the License, or (at your option) any later version.9*10* FFmpeg is distributed in the hope that it will be useful,11* but WITHOUT ANY WARRANTY; without even the implied warranty of12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU13* Lesser General Public License for more details.14*15* You should have received a copy of the GNU Lesser General Public16* License along with FFmpeg; if not, write to the Free Software17* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA18*/1920#ifndef AVCODEC_BSF_H21#define AVCODEC_BSF_H2223#include "libavutil/dict.h"24#include "libavutil/log.h"25#include "libavutil/rational.h"2627#include "codec_id.h"28#include "codec_par.h"29#include "packet.h"3031/**32* @defgroup lavc_bsf Bitstream filters33* @ingroup libavc34*35* Bitstream filters transform encoded media data without decoding it. This36* allows e.g. manipulating various header values. Bitstream filters operate on37* @ref AVPacket "AVPackets".38*39* The bitstream filtering API is centered around two structures:40* AVBitStreamFilter and AVBSFContext. The former represents a bitstream filter41* in abstract, the latter a specific filtering process. Obtain an42* AVBitStreamFilter using av_bsf_get_by_name() or av_bsf_iterate(), then pass43* it to av_bsf_alloc() to create an AVBSFContext. Fill in the user-settable44* AVBSFContext fields, as described in its documentation, then call45* av_bsf_init() to prepare the filter context for use.46*47* Submit packets for filtering using av_bsf_send_packet(), obtain filtered48* results with av_bsf_receive_packet(). When no more input packets will be49* sent, submit a NULL AVPacket to signal the end of the stream to the filter.50* av_bsf_receive_packet() will then return trailing packets, if any are51* produced by the filter.52*53* Finally, free the filter context with av_bsf_free().54* @{55*/5657/**58* The bitstream filter state.59*60* This struct must be allocated with av_bsf_alloc() and freed with61* av_bsf_free().62*63* The fields in the struct will only be changed (by the caller or by the64* filter) as described in their documentation, and are to be considered65* immutable otherwise.66*/67typedef struct AVBSFContext {68/**69* A class for logging and AVOptions70*/71const AVClass *av_class;7273/**74* The bitstream filter this context is an instance of.75*/76const struct AVBitStreamFilter *filter;7778/**79* Opaque filter-specific private data. If filter->priv_class is non-NULL,80* this is an AVOptions-enabled struct.81*/82void *priv_data;8384/**85* Parameters of the input stream. This field is allocated in86* av_bsf_alloc(), it needs to be filled by the caller before87* av_bsf_init().88*/89AVCodecParameters *par_in;9091/**92* Parameters of the output stream. This field is allocated in93* av_bsf_alloc(), it is set by the filter in av_bsf_init().94*/95AVCodecParameters *par_out;9697/**98* The timebase used for the timestamps of the input packets. Set by the99* caller before av_bsf_init().100*/101AVRational time_base_in;102103/**104* The timebase used for the timestamps of the output packets. Set by the105* filter in av_bsf_init().106*/107AVRational time_base_out;108} AVBSFContext;109110typedef struct AVBitStreamFilter {111const char *name;112113/**114* A list of codec ids supported by the filter, terminated by115* AV_CODEC_ID_NONE.116* May be NULL, in that case the bitstream filter works with any codec id.117*/118const enum AVCodecID *codec_ids;119120/**121* A class for the private data, used to declare bitstream filter private122* AVOptions. This field is NULL for bitstream filters that do not declare123* any options.124*125* If this field is non-NULL, the first member of the filter private data126* must be a pointer to AVClass, which will be set by libavcodec generic127* code to this class.128*/129const AVClass *priv_class;130} AVBitStreamFilter;131132/**133* @return a bitstream filter with the specified name or NULL if no such134* bitstream filter exists.135*/136const AVBitStreamFilter *av_bsf_get_by_name(const char *name);137138/**139* Iterate over all registered bitstream filters.140*141* @param opaque a pointer where libavcodec will store the iteration state. Must142* point to NULL to start the iteration.143*144* @return the next registered bitstream filter or NULL when the iteration is145* finished146*/147const AVBitStreamFilter *av_bsf_iterate(void **opaque);148149/**150* Allocate a context for a given bitstream filter. The caller must fill in the151* context parameters as described in the documentation and then call152* av_bsf_init() before sending any data to the filter.153*154* @param filter the filter for which to allocate an instance.155* @param[out] ctx a pointer into which the pointer to the newly-allocated context156* will be written. It must be freed with av_bsf_free() after the157* filtering is done.158*159* @return 0 on success, a negative AVERROR code on failure160*/161int av_bsf_alloc(const AVBitStreamFilter *filter, AVBSFContext **ctx);162163/**164* Prepare the filter for use, after all the parameters and options have been165* set.166*167* @param ctx a AVBSFContext previously allocated with av_bsf_alloc()168*/169int av_bsf_init(AVBSFContext *ctx);170171/**172* Submit a packet for filtering.173*174* After sending each packet, the filter must be completely drained by calling175* av_bsf_receive_packet() repeatedly until it returns AVERROR(EAGAIN) or176* AVERROR_EOF.177*178* @param ctx an initialized AVBSFContext179* @param pkt the packet to filter. The bitstream filter will take ownership of180* the packet and reset the contents of pkt. pkt is not touched if an error occurs.181* If pkt is empty (i.e. NULL, or pkt->data is NULL and pkt->side_data_elems zero),182* it signals the end of the stream (i.e. no more non-empty packets will be sent;183* sending more empty packets does nothing) and will cause the filter to output184* any packets it may have buffered internally.185*186* @return187* - 0 on success.188* - AVERROR(EAGAIN) if packets need to be retrieved from the filter (using189* av_bsf_receive_packet()) before new input can be consumed.190* - Another negative AVERROR value if an error occurs.191*/192int av_bsf_send_packet(AVBSFContext *ctx, AVPacket *pkt);193194/**195* Retrieve a filtered packet.196*197* @param ctx an initialized AVBSFContext198* @param[out] pkt this struct will be filled with the contents of the filtered199* packet. It is owned by the caller and must be freed using200* av_packet_unref() when it is no longer needed.201* This parameter should be "clean" (i.e. freshly allocated202* with av_packet_alloc() or unreffed with av_packet_unref())203* when this function is called. If this function returns204* successfully, the contents of pkt will be completely205* overwritten by the returned data. On failure, pkt is not206* touched.207*208* @return209* - 0 on success.210* - AVERROR(EAGAIN) if more packets need to be sent to the filter (using211* av_bsf_send_packet()) to get more output.212* - AVERROR_EOF if there will be no further output from the filter.213* - Another negative AVERROR value if an error occurs.214*215* @note one input packet may result in several output packets, so after sending216* a packet with av_bsf_send_packet(), this function needs to be called217* repeatedly until it stops returning 0. It is also possible for a filter to218* output fewer packets than were sent to it, so this function may return219* AVERROR(EAGAIN) immediately after a successful av_bsf_send_packet() call.220*/221int av_bsf_receive_packet(AVBSFContext *ctx, AVPacket *pkt);222223/**224* Reset the internal bitstream filter state. Should be called e.g. when seeking.225*/226void av_bsf_flush(AVBSFContext *ctx);227228/**229* Free a bitstream filter context and everything associated with it; write NULL230* into the supplied pointer.231*/232void av_bsf_free(AVBSFContext **ctx);233234/**235* Get the AVClass for AVBSFContext. It can be used in combination with236* AV_OPT_SEARCH_FAKE_OBJ for examining options.237*238* @see av_opt_find().239*/240const AVClass *av_bsf_get_class(void);241242/**243* Structure for chain/list of bitstream filters.244* Empty list can be allocated by av_bsf_list_alloc().245*/246typedef struct AVBSFList AVBSFList;247248/**249* Allocate empty list of bitstream filters.250* The list must be later freed by av_bsf_list_free()251* or finalized by av_bsf_list_finalize().252*253* @return Pointer to @ref AVBSFList on success, NULL in case of failure254*/255AVBSFList *av_bsf_list_alloc(void);256257/**258* Free list of bitstream filters.259*260* @param lst Pointer to pointer returned by av_bsf_list_alloc()261*/262void av_bsf_list_free(AVBSFList **lst);263264/**265* Append bitstream filter to the list of bitstream filters.266*267* @param lst List to append to268* @param bsf Filter context to be appended269*270* @return >=0 on success, negative AVERROR in case of failure271*/272int av_bsf_list_append(AVBSFList *lst, AVBSFContext *bsf);273274/**275* Construct new bitstream filter context given it's name and options276* and append it to the list of bitstream filters.277*278* @param lst List to append to279* @param bsf_name Name of the bitstream filter280* @param options Options for the bitstream filter, can be set to NULL281*282* @return >=0 on success, negative AVERROR in case of failure283*/284int av_bsf_list_append2(AVBSFList *lst, const char * bsf_name, AVDictionary **options);285/**286* Finalize list of bitstream filters.287*288* This function will transform @ref AVBSFList to single @ref AVBSFContext,289* so the whole chain of bitstream filters can be treated as single filter290* freshly allocated by av_bsf_alloc().291* If the call is successful, @ref AVBSFList structure is freed and lst292* will be set to NULL. In case of failure, caller is responsible for293* freeing the structure by av_bsf_list_free()294*295* @param lst Filter list structure to be transformed296* @param[out] bsf Pointer to be set to newly created @ref AVBSFContext structure297* representing the chain of bitstream filters298*299* @return >=0 on success, negative AVERROR in case of failure300*/301int av_bsf_list_finalize(AVBSFList **lst, AVBSFContext **bsf);302303/**304* Parse string describing list of bitstream filters and create single305* @ref AVBSFContext describing the whole chain of bitstream filters.306* Resulting @ref AVBSFContext can be treated as any other @ref AVBSFContext freshly307* allocated by av_bsf_alloc().308*309* @param str String describing chain of bitstream filters in format310* `bsf1[=opt1=val1:opt2=val2][,bsf2]`311* @param[out] bsf Pointer to be set to newly created @ref AVBSFContext structure312* representing the chain of bitstream filters313*314* @return >=0 on success, negative AVERROR in case of failure315*/316int av_bsf_list_parse_str(const char *str, AVBSFContext **bsf);317318/**319* Get null/pass-through bitstream filter.320*321* @param[out] bsf Pointer to be set to new instance of pass-through bitstream filter322*323* @return324*/325int av_bsf_get_null_filter(AVBSFContext **bsf);326327/**328* @}329*/330331#endif // AVCODEC_BSF_H332333334