00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00028 #include "avfilter.h"
00029 #include "internal.h"
00030 #include "audio.h"
00031 #include "avcodec.h"
00032 #include "buffersrc.h"
00033 #include "asrc_abuffer.h"
00034 #include "libavutil/audioconvert.h"
00035 #include "libavutil/avstring.h"
00036 #include "libavutil/fifo.h"
00037 #include "libavutil/imgutils.h"
00038
00039 typedef struct {
00040 AVFifoBuffer *fifo;
00041 AVRational time_base;
00042 int eof;
00043 unsigned nb_failed_requests;
00044
00045
00046 AVFilterContext *scale;
00047 int h, w;
00048 enum PixelFormat pix_fmt;
00049 AVRational sample_aspect_ratio;
00050 char sws_param[256];
00051
00052
00053
00054 int sample_rate;
00055 unsigned int sample_format;
00056 int64_t channel_layout;
00057
00058
00059 AVFilterContext *aconvert;
00060 AVFilterContext *aresample;
00061 } BufferSourceContext;
00062
00063 static void buf_free(AVFilterBuffer *ptr)
00064 {
00065 av_free(ptr);
00066 return;
00067 }
00068
00069 int av_asrc_buffer_add_audio_buffer_ref(AVFilterContext *ctx,
00070 AVFilterBufferRef *samplesref,
00071 int av_unused flags)
00072 {
00073 return av_buffersrc_add_ref(ctx, samplesref, AV_BUFFERSRC_FLAG_NO_COPY);
00074 }
00075
00076 int av_asrc_buffer_add_samples(AVFilterContext *ctx,
00077 uint8_t *data[8], int linesize[8],
00078 int nb_samples, int sample_rate,
00079 int sample_fmt, int64_t channel_layout, int planar,
00080 int64_t pts, int av_unused flags)
00081 {
00082 AVFilterBufferRef *samplesref;
00083
00084 samplesref = avfilter_get_audio_buffer_ref_from_arrays(
00085 data, linesize[0], AV_PERM_WRITE,
00086 nb_samples,
00087 sample_fmt, channel_layout);
00088 if (!samplesref)
00089 return AVERROR(ENOMEM);
00090
00091 samplesref->buf->free = buf_free;
00092 samplesref->pts = pts;
00093 samplesref->audio->sample_rate = sample_rate;
00094
00095 AV_NOWARN_DEPRECATED(
00096 return av_asrc_buffer_add_audio_buffer_ref(ctx, samplesref, 0);
00097 )
00098 }
00099
00100 int av_asrc_buffer_add_buffer(AVFilterContext *ctx,
00101 uint8_t *buf, int buf_size, int sample_rate,
00102 int sample_fmt, int64_t channel_layout, int planar,
00103 int64_t pts, int av_unused flags)
00104 {
00105 uint8_t *data[8] = {0};
00106 int linesize[8];
00107 int nb_channels = av_get_channel_layout_nb_channels(channel_layout),
00108 nb_samples = buf_size / nb_channels / av_get_bytes_per_sample(sample_fmt);
00109
00110 av_samples_fill_arrays(data, linesize,
00111 buf, nb_channels, nb_samples,
00112 sample_fmt, 16);
00113
00114 AV_NOWARN_DEPRECATED(
00115 return av_asrc_buffer_add_samples(ctx,
00116 data, linesize, nb_samples,
00117 sample_rate,
00118 sample_fmt, channel_layout, planar,
00119 pts, flags);
00120 )
00121 }