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_BUFFERSINK_H yading@10: #define AVFILTER_BUFFERSINK_H yading@10: yading@10: /** yading@10: * @file yading@10: * memory buffer sink API for audio and video yading@10: */ yading@10: yading@10: #include "avfilter.h" yading@10: yading@10: #if FF_API_AVFILTERBUFFER yading@10: /** yading@10: * Get an audio/video buffer data from buffer_sink and put it in bufref. yading@10: * yading@10: * This function works with both audio and video buffer sinks. yading@10: * yading@10: * @param buffer_sink pointer to a buffersink or abuffersink context yading@10: * @param flags a combination of AV_BUFFERSINK_FLAG_* flags yading@10: * @return >= 0 in case of success, a negative AVERROR code in case of yading@10: * failure yading@10: */ yading@10: attribute_deprecated yading@10: int av_buffersink_get_buffer_ref(AVFilterContext *buffer_sink, yading@10: AVFilterBufferRef **bufref, int flags); yading@10: yading@10: /** yading@10: * Get the number of immediately available frames. yading@10: */ yading@10: attribute_deprecated yading@10: int av_buffersink_poll_frame(AVFilterContext *ctx); yading@10: yading@10: /** yading@10: * Get a buffer with filtered data from sink and put it in buf. yading@10: * yading@10: * @param ctx pointer to a context of a buffersink or abuffersink AVFilter. yading@10: * @param buf pointer to the buffer will be written here if buf is non-NULL. buf yading@10: * must be freed by the caller using avfilter_unref_buffer(). yading@10: * Buf may also be NULL to query whether a buffer is ready to be yading@10: * output. yading@10: * yading@10: * @return >= 0 in case of success, a negative AVERROR code in case of yading@10: * failure. yading@10: */ yading@10: attribute_deprecated yading@10: int av_buffersink_read(AVFilterContext *ctx, AVFilterBufferRef **buf); yading@10: yading@10: /** yading@10: * Same as av_buffersink_read, but with the ability to specify the number of yading@10: * samples read. This function is less efficient than av_buffersink_read(), yading@10: * because it copies the data around. yading@10: * yading@10: * @param ctx pointer to a context of the abuffersink AVFilter. yading@10: * @param buf pointer to the buffer will be written here if buf is non-NULL. buf yading@10: * must be freed by the caller using avfilter_unref_buffer(). buf yading@10: * will contain exactly nb_samples audio samples, except at the end yading@10: * of stream, when it can contain less than nb_samples. yading@10: * Buf may also be NULL to query whether a buffer is ready to be yading@10: * output. yading@10: * yading@10: * @warning do not mix this function with av_buffersink_read(). Use only one or yading@10: * the other with a single sink, not both. yading@10: */ yading@10: attribute_deprecated yading@10: int av_buffersink_read_samples(AVFilterContext *ctx, AVFilterBufferRef **buf, yading@10: int nb_samples); yading@10: #endif yading@10: yading@10: /** yading@10: * Get a frame with filtered data from sink and put it in frame. yading@10: * yading@10: * @param ctx pointer to a buffersink or abuffersink filter context. yading@10: * @param frame pointer to an allocated frame that will be filled with data. yading@10: * The data must be freed using av_frame_unref() / av_frame_free() yading@10: * @param flags a combination of AV_BUFFERSINK_FLAG_* flags yading@10: * yading@10: * @return >= 0 in for success, a negative AVERROR code for failure. yading@10: */ yading@10: int av_buffersink_get_frame_flags(AVFilterContext *ctx, AVFrame *frame, int flags); yading@10: yading@10: /** yading@10: * Tell av_buffersink_get_buffer_ref() to read video/samples buffer yading@10: * reference, but not remove it from the buffer. This is useful if you yading@10: * need only to read a video/samples buffer, without to fetch it. yading@10: */ yading@10: #define AV_BUFFERSINK_FLAG_PEEK 1 yading@10: yading@10: /** yading@10: * Tell av_buffersink_get_buffer_ref() not to request a frame from its input. yading@10: * If a frame is already buffered, it is read (and removed from the buffer), yading@10: * but if no frame is present, return AVERROR(EAGAIN). yading@10: */ yading@10: #define AV_BUFFERSINK_FLAG_NO_REQUEST 2 yading@10: yading@10: /** yading@10: * Struct to use for initializing a buffersink context. yading@10: */ yading@10: typedef struct { yading@10: const enum AVPixelFormat *pixel_fmts; ///< list of allowed pixel formats, terminated by AV_PIX_FMT_NONE yading@10: } AVBufferSinkParams; yading@10: yading@10: /** yading@10: * Create an AVBufferSinkParams structure. yading@10: * yading@10: * Must be freed with av_free(). yading@10: */ yading@10: AVBufferSinkParams *av_buffersink_params_alloc(void); yading@10: yading@10: /** yading@10: * Struct to use for initializing an abuffersink context. yading@10: */ yading@10: typedef struct { yading@10: const enum AVSampleFormat *sample_fmts; ///< list of allowed sample formats, terminated by AV_SAMPLE_FMT_NONE yading@10: const int64_t *channel_layouts; ///< list of allowed channel layouts, terminated by -1 yading@10: const int *channel_counts; ///< list of allowed channel counts, terminated by -1 yading@10: int all_channel_counts; ///< if not 0, accept any channel count or layout yading@10: int *sample_rates; ///< list of allowed sample rates, terminated by -1 yading@10: } AVABufferSinkParams; yading@10: yading@10: /** yading@10: * Create an AVABufferSinkParams structure. yading@10: * yading@10: * Must be freed with av_free(). yading@10: */ yading@10: AVABufferSinkParams *av_abuffersink_params_alloc(void); yading@10: yading@10: /** yading@10: * Set the frame size for an audio buffer sink. yading@10: * yading@10: * All calls to av_buffersink_get_buffer_ref will return a buffer with yading@10: * exactly the specified number of samples, or AVERROR(EAGAIN) if there is yading@10: * not enough. The last buffer at EOF will be padded with 0. yading@10: */ yading@10: void av_buffersink_set_frame_size(AVFilterContext *ctx, unsigned frame_size); yading@10: yading@10: /** yading@10: * Get the frame rate of the input. yading@10: */ yading@10: AVRational av_buffersink_get_frame_rate(AVFilterContext *ctx); yading@10: yading@10: /** yading@10: * Get a frame with filtered data from sink and put it in frame. yading@10: * yading@10: * @param ctx pointer to a context of a buffersink or abuffersink AVFilter. yading@10: * @param frame pointer to an allocated frame that will be filled with data. yading@10: * The data must be freed using av_frame_unref() / av_frame_free() yading@10: * yading@10: * @return >= 0 in case of success, a negative AVERROR code in case of yading@10: * failure. yading@10: */ yading@10: int av_buffersink_get_frame(AVFilterContext *ctx, AVFrame *frame); yading@10: yading@10: /** yading@10: * Same as av_buffersink_get_frame(), but with the ability to specify the number yading@10: * of samples read. This function is less efficient than yading@10: * av_buffersink_get_frame(), because it copies the data around. yading@10: * yading@10: * @param ctx pointer to a context of the abuffersink AVFilter. yading@10: * @param frame pointer to an allocated frame that will be filled with data. yading@10: * The data must be freed using av_frame_unref() / av_frame_free() yading@10: * frame will contain exactly nb_samples audio samples, except at yading@10: * the end of stream, when it can contain less than nb_samples. yading@10: * yading@10: * @warning do not mix this function with av_buffersink_get_frame(). Use only one or yading@10: * the other with a single sink, not both. yading@10: */ yading@10: int av_buffersink_get_samples(AVFilterContext *ctx, AVFrame *frame, int nb_samples); yading@10: yading@10: #endif /* AVFILTER_BUFFERSINK_H */