21 #include "libavresample/avresample.h"
22 #include "libavutil/attributes.h"
23 #include "libavutil/audio_fifo.h"
24 #include "libavutil/common.h"
25 #include "libavutil/mathematics.h"
26 #include "libavutil/opt.h"
27 #include "libavutil/samplefmt.h"
52 #define OFFSET(x) offsetof(ASyncContext, x)
53 #define A AV_OPT_FLAG_AUDIO_PARAM
56 {
"min_delta",
"Minimum difference between timestamps and audio data "
57 "(in seconds) to trigger padding/trimmin the data.",
OFFSET(min_delta_sec),
AV_OPT_TYPE_FLOAT, { .dbl = 0.1 }, 0, INT_MAX,
A },
58 {
"max_comp",
"Maximum compensation in samples per second.",
OFFSET(max_comp),
AV_OPT_TYPE_INT, { .i64 = 500 }, 0, INT_MAX,
A },
215 out_size = av_clipl_int32((int64_t)out_size + delta);
222 if (comp != s->
comp) {
243 int planes = planar ? nb_channels : 1;
250 nb_channels, buf->
format);
252 for (ch = 0; ch < planes; ch++)
257 for (ch = 0; ch < planes; ch++)
264 delta, nb_channels, buf->
format);
282 if (new_pts > s->
pts) {
326 .priv_class = &async_class,
This structure describes decoded (raw) audio or video data.
static const AVFilterPad avfilter_af_asyncts_inputs[]
const char * name
Filter name.
int min_delta
pad/trim min threshold in samples
void * priv
private data for use by the filter
#define AV_LOG_WARNING
Something somehow does not look correct.
static const AVFilterPad outputs[]
int avresample_read(AVAudioResampleContext *avr, uint8_t **output, int nb_samples)
Read samples from the output FIFO.
uint8_t ** extended_data
pointers to the data planes/channels.
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
int avresample_set_compensation(AVAudioResampleContext *avr, int sample_delta, int compensation_distance)
Set compensation for resampling.
void avresample_free(AVAudioResampleContext **avr)
Free AVAudioResampleContext and associated AVOption values.
static av_cold int init(AVFilterContext *ctx)
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
static av_cold void uninit(AVFilterContext *ctx)
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
#define AVERROR_EOF
End of file.
#define AV_LOG_VERBOSE
Detailed information.
void avresample_close(AVAudioResampleContext *avr)
Close AVAudioResampleContext.
static int request_frame(AVFilterLink *link)
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq) av_const
Rescale a 64-bit integer by 2 rational numbers.
A link between two filters.
int av_samples_set_silence(uint8_t **audio_data, int offset, int nb_samples, int nb_channels, enum AVSampleFormat sample_fmt)
Fill an audio buffer with silence.
int sample_rate
samples per second
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
int comp
current resample compensation
int64_t pts
timestamp in samples of the first sample in fifo
AVAudioResampleContext * avresample_alloc_context(void)
Allocate AVAudioResampleContext and set options.
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link...
AVFilterContext * src
source filter
uint64_t channel_layout
Channel layout of the audio data.
static int config_props(AVFilterLink *link)
AVAudioResampleContext * avr
int first_frame
1 until filter_frame() has processed at least 1 frame with a pts != AV_NOPTS_VALUE ...
int64_t first_pts
user-specified first expected pts, in samples
int format
agreed upon media format
Main libavfilter public API header.
AVFilterLink ** outputs
array of pointers to output links
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
int avresample_get_delay(AVAudioResampleContext *avr)
Return the number of samples currently in the resampling delay buffer.
int avresample_available(AVAudioResampleContext *avr)
Return the number of available samples in the output FIFO.
static int write_to_fifo(ASyncContext *s, AVFrame *buf)
Describe the class of an AVClass context structure.
static const AVFilterPad inputs[]
AVFilterLink ** inputs
array of pointers to input links
rational number numerator/denominator
int avresample_convert(AVAudioResampleContext *avr, uint8_t **output, int out_plane_size, int out_samples, uint8_t **input, int in_plane_size, int in_samples)
Convert input samples and write them to the output FIFO.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
AVFilterContext * dst
dest filter
static int64_t get_delay(ASyncContext *s)
static const AVOption options[]
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
static void handle_trimming(AVFilterContext *ctx)
uint64_t channel_layout
channel layout of current buffer (see libavutil/channel_layout.h)
struct AVFilterPad AVFilterPad
static const AVClass async_class
static const AVFilterPad avfilter_af_asyncts_outputs[]
static void comp(unsigned char *dst, int dst_stride, unsigned char *src, int src_stride, int add)
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
av_default_item_name
Return the context name.
int avresample_open(AVAudioResampleContext *avr)
Initialize AVAudioResampleContext.
int nb_samples
number of audio samples (per channel) described by this frame
#define AV_NOPTS_VALUE
Undefined timestamp value.
static int resample(ResampleContext *c, void *dst, const void *src, int *consumed, int src_size, int dst_size, int update_ctx, int nearest_neighbour)