yading@10: /* yading@10: * This file is part of FFmpeg. yading@10: * yading@10: * FFmpeg is free software; you can redistribute it and/or yading@10: * modify it under the terms of the GNU Lesser General Public yading@10: * License as published by the Free Software Foundation; either yading@10: * version 2.1 of the License, or (at your option) any later version. yading@10: * yading@10: * FFmpeg is distributed in the hope that it will be useful, yading@10: * but WITHOUT ANY WARRANTY; without even the implied warranty of yading@10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU yading@10: * Lesser General Public License for more details. yading@10: * yading@10: * You should have received a copy of the GNU Lesser General Public yading@10: * License along with FFmpeg; if not, write to the Free Software yading@10: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA yading@10: */ yading@10: yading@10: #ifndef AVFILTER_FORMATS_H yading@10: #define AVFILTER_FORMATS_H yading@10: yading@10: #include "avfilter.h" yading@10: yading@10: /** yading@10: * A list of supported formats for one end of a filter link. This is used yading@10: * during the format negotiation process to try to pick the best format to yading@10: * use to minimize the number of necessary conversions. Each filter gives a yading@10: * list of the formats supported by each input and output pad. The list yading@10: * given for each pad need not be distinct - they may be references to the yading@10: * same list of formats, as is often the case when a filter supports multiple yading@10: * formats, but will always output the same format as it is given in input. yading@10: * yading@10: * In this way, a list of possible input formats and a list of possible yading@10: * output formats are associated with each link. When a set of formats is yading@10: * negotiated over a link, the input and output lists are merged to form a yading@10: * new list containing only the common elements of each list. In the case yading@10: * that there were no common elements, a format conversion is necessary. yading@10: * Otherwise, the lists are merged, and all other links which reference yading@10: * either of the format lists involved in the merge are also affected. yading@10: * yading@10: * For example, consider the filter chain: yading@10: * filter (a) --> (b) filter (b) --> (c) filter yading@10: * yading@10: * where the letters in parenthesis indicate a list of formats supported on yading@10: * the input or output of the link. Suppose the lists are as follows: yading@10: * (a) = {A, B} yading@10: * (b) = {A, B, C} yading@10: * (c) = {B, C} yading@10: * yading@10: * First, the first link's lists are merged, yielding: yading@10: * filter (a) --> (a) filter (a) --> (c) filter yading@10: * yading@10: * Notice that format list (b) now refers to the same list as filter list (a). yading@10: * Next, the lists for the second link are merged, yielding: yading@10: * filter (a) --> (a) filter (a) --> (a) filter yading@10: * yading@10: * where (a) = {B}. yading@10: * yading@10: * Unfortunately, when the format lists at the two ends of a link are merged, yading@10: * we must ensure that all links which reference either pre-merge format list yading@10: * get updated as well. Therefore, we have the format list structure store a yading@10: * pointer to each of the pointers to itself. yading@10: */ yading@10: struct AVFilterFormats { yading@10: unsigned format_count; ///< number of formats yading@10: int *formats; ///< list of media formats yading@10: yading@10: unsigned refcount; ///< number of references to this list yading@10: struct AVFilterFormats ***refs; ///< references to this list yading@10: }; yading@10: yading@10: /** yading@10: * A list of supported channel layouts. yading@10: * yading@10: * The list works the same as AVFilterFormats, except for the following yading@10: * differences: yading@10: * - A list with all_layouts = 1 means all channel layouts with a known yading@10: * disposition; nb_channel_layouts must then be 0. yading@10: * - A list with all_counts = 1 means all channel counts, with a known or yading@10: * unknown disposition; nb_channel_layouts must then be 0 and all_layouts 1. yading@10: * - The list must not contain a layout with a known disposition and a yading@10: * channel count with unknown disposition with the same number of channels yading@10: * (e.g. AV_CH_LAYOUT_STEREO and FF_COUNT2LAYOUT(2). yading@10: */ yading@10: typedef struct AVFilterChannelLayouts { yading@10: uint64_t *channel_layouts; ///< list of channel layouts yading@10: int nb_channel_layouts; ///< number of channel layouts yading@10: char all_layouts; ///< accept any known channel layout yading@10: char all_counts; ///< accept any channel layout or count yading@10: yading@10: unsigned refcount; ///< number of references to this list yading@10: struct AVFilterChannelLayouts ***refs; ///< references to this list yading@10: } AVFilterChannelLayouts; yading@10: yading@10: /** yading@10: * Encode a channel count as a channel layout. yading@10: * FF_COUNT2LAYOUT(c) means any channel layout with c channels, with a known yading@10: * or unknown disposition. yading@10: * The result is only valid inside AVFilterChannelLayouts and immediately yading@10: * related functions. yading@10: */ yading@10: #define FF_COUNT2LAYOUT(c) (0x8000000000000000ULL | (c)) yading@10: yading@10: /** yading@10: * Decode a channel count encoded as a channel layout. yading@10: * Return 0 if the channel layout was a real one. yading@10: */ yading@10: #define FF_LAYOUT2COUNT(l) (((l) & 0x8000000000000000ULL) ? \ yading@10: (int)((l) & 0x7FFFFFFF) : 0) yading@10: yading@10: /** yading@10: * Return a channel layouts/samplerates list which contains the intersection of yading@10: * the layouts/samplerates of a and b. Also, all the references of a, all the yading@10: * references of b, and a and b themselves will be deallocated. yading@10: * yading@10: * If a and b do not share any common elements, neither is modified, and NULL yading@10: * is returned. yading@10: */ yading@10: AVFilterChannelLayouts *ff_merge_channel_layouts(AVFilterChannelLayouts *a, yading@10: AVFilterChannelLayouts *b); yading@10: AVFilterFormats *ff_merge_samplerates(AVFilterFormats *a, yading@10: AVFilterFormats *b); yading@10: yading@10: /** yading@10: * Construct an empty AVFilterChannelLayouts/AVFilterFormats struct -- yading@10: * representing any channel layout (with known disposition)/sample rate. yading@10: */ yading@10: AVFilterChannelLayouts *ff_all_channel_layouts(void); yading@10: AVFilterFormats *ff_all_samplerates(void); yading@10: yading@10: /** yading@10: * Construct an AVFilterChannelLayouts coding for any channel layout, with yading@10: * known or unknown disposition. yading@10: */ yading@10: AVFilterChannelLayouts *ff_all_channel_counts(void); yading@10: yading@10: AVFilterChannelLayouts *avfilter_make_format64_list(const int64_t *fmts); yading@10: yading@10: yading@10: /** yading@10: * A helper for query_formats() which sets all links to the same list of channel yading@10: * layouts/sample rates. If there are no links hooked to this filter, the list yading@10: * is freed. yading@10: */ yading@10: void ff_set_common_channel_layouts(AVFilterContext *ctx, yading@10: AVFilterChannelLayouts *layouts); yading@10: void ff_set_common_samplerates(AVFilterContext *ctx, yading@10: AVFilterFormats *samplerates); yading@10: yading@10: /** yading@10: * A helper for query_formats() which sets all links to the same list of yading@10: * formats. If there are no links hooked to this filter, the list of formats is yading@10: * freed. yading@10: */ yading@10: void ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats); yading@10: yading@10: int ff_add_channel_layout(AVFilterChannelLayouts **l, uint64_t channel_layout); yading@10: yading@10: /** yading@10: * Add *ref as a new reference to f. yading@10: */ yading@10: void ff_channel_layouts_ref(AVFilterChannelLayouts *f, yading@10: AVFilterChannelLayouts **ref); yading@10: yading@10: /** yading@10: * Remove a reference to a channel layouts list. yading@10: */ yading@10: void ff_channel_layouts_unref(AVFilterChannelLayouts **ref); yading@10: yading@10: void ff_channel_layouts_changeref(AVFilterChannelLayouts **oldref, yading@10: AVFilterChannelLayouts **newref); yading@10: yading@10: int ff_default_query_formats(AVFilterContext *ctx); yading@10: yading@10: /** yading@10: * Set the formats list to all existing formats. yading@10: * This function behaves like ff_default_query_formats(), except it also yading@10: * accepts channel layouts with unknown disposition. It should only be used yading@10: * with audio filters. yading@10: */ yading@10: int ff_query_formats_all(AVFilterContext *ctx); yading@10: yading@10: yading@10: /** yading@10: * Create a list of supported formats. This is intended for use in yading@10: * AVFilter->query_formats(). yading@10: * yading@10: * @param fmts list of media formats, terminated by -1 yading@10: * @return the format list, with no existing references yading@10: */ yading@10: AVFilterFormats *ff_make_format_list(const int *fmts); yading@10: yading@10: /** yading@10: * Add fmt to the list of media formats contained in *avff. yading@10: * If *avff is NULL the function allocates the filter formats struct yading@10: * and puts its pointer in *avff. yading@10: * yading@10: * @return a non negative value in case of success, or a negative yading@10: * value corresponding to an AVERROR code in case of error yading@10: */ yading@10: int ff_add_format(AVFilterFormats **avff, int64_t fmt); yading@10: yading@10: /** yading@10: * Return a list of all formats supported by FFmpeg for the given media type. yading@10: */ yading@10: AVFilterFormats *ff_all_formats(enum AVMediaType type); yading@10: yading@10: /** yading@10: * Construct a formats list containing all planar sample formats. yading@10: */ yading@10: AVFilterFormats *ff_planar_sample_fmts(void); yading@10: yading@10: /** yading@10: * Return a format list which contains the intersection of the formats of yading@10: * a and b. Also, all the references of a, all the references of b, and yading@10: * a and b themselves will be deallocated. yading@10: * yading@10: * If a and b do not share any common formats, neither is modified, and NULL yading@10: * is returned. yading@10: */ yading@10: AVFilterFormats *ff_merge_formats(AVFilterFormats *a, AVFilterFormats *b, yading@10: enum AVMediaType type); yading@10: yading@10: /** yading@10: * Add *ref as a new reference to formats. yading@10: * That is the pointers will point like in the ascii art below: yading@10: * ________ yading@10: * |formats |<--------. yading@10: * | ____ | ____|___________________ yading@10: * | |refs| | | __|_ yading@10: * | |* * | | | | | | AVFilterLink yading@10: * | |* *--------->|*ref| yading@10: * | |____| | | |____| yading@10: * |________| |________________________ yading@10: */ yading@10: void ff_formats_ref(AVFilterFormats *formats, AVFilterFormats **ref); yading@10: yading@10: /** yading@10: * If *ref is non-NULL, remove *ref as a reference to the format list yading@10: * it currently points to, deallocates that list if this was the last yading@10: * reference, and sets *ref to NULL. yading@10: * yading@10: * Before After yading@10: * ________ ________ NULL yading@10: * |formats |<--------. |formats | ^ yading@10: * | ____ | ____|________________ | ____ | ____|________________ yading@10: * | |refs| | | __|_ | |refs| | | __|_ yading@10: * | |* * | | | | | | AVFilterLink | |* * | | | | | | AVFilterLink yading@10: * | |* *--------->|*ref| | |* | | | |*ref| yading@10: * | |____| | | |____| | |____| | | |____| yading@10: * |________| |_____________________ |________| |_____________________ yading@10: */ yading@10: void ff_formats_unref(AVFilterFormats **ref); yading@10: yading@10: /** yading@10: * yading@10: * Before After yading@10: * ________ ________ yading@10: * |formats |<---------. |formats |<---------. yading@10: * | ____ | ___|___ | ____ | ___|___ yading@10: * | |refs| | | | | | |refs| | | | | NULL yading@10: * | |* *--------->|*oldref| | |* *--------->|*newref| ^ yading@10: * | |* * | | |_______| | |* * | | |_______| ___|___ yading@10: * | |____| | | |____| | | | | yading@10: * |________| |________| |*oldref| yading@10: * |_______| yading@10: */ yading@10: void ff_formats_changeref(AVFilterFormats **oldref, AVFilterFormats **newref); yading@10: yading@10: #endif /* AVFILTER_FORMATS_H */