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 "vsrc_buffer.h"
00034 #include "asrc_abuffer.h"
00035 #include "libavutil/audioconvert.h"
00036 #include "libavutil/avstring.h"
00037 #include "libavutil/fifo.h"
00038 #include "libavutil/imgutils.h"
00039
00040 typedef struct {
00041 AVFifoBuffer *fifo;
00042 AVRational time_base;
00043 int eof;
00044 unsigned nb_failed_requests;
00045
00046
00047 AVFilterContext *scale;
00048 int h, w;
00049 enum PixelFormat pix_fmt;
00050 AVRational sample_aspect_ratio;
00051 char sws_param[256];
00052
00053
00054
00055 int sample_rate;
00056 unsigned int sample_format;
00057 int64_t channel_layout;
00058
00059
00060 AVFilterContext *aconvert;
00061 AVFilterContext *aresample;
00062 } BufferSourceContext;
00063
00064 static void buf_free(AVFilterBuffer *ptr)
00065 {
00066 av_free(ptr);
00067 return;
00068 }
00069
00070 int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter,
00071 AVFilterBufferRef *picref, int flags)
00072 {
00073 return av_buffersrc_add_ref(buffer_filter, picref, 0);
00074 }
00075
00076 #if CONFIG_AVCODEC
00077 #include "avcodec.h"
00078
00079 int av_vsrc_buffer_add_frame(AVFilterContext *buffer_src,
00080 const AVFrame *frame, int flags)
00081 {
00082 return av_buffersrc_add_frame(buffer_src, frame, 0);
00083 }
00084 #endif
00085
00086 unsigned av_vsrc_buffer_get_nb_failed_requests(AVFilterContext *buffer_src)
00087 {
00088 return ((BufferSourceContext *)buffer_src->priv)->nb_failed_requests;
00089 }
00090
00091 int av_asrc_buffer_add_audio_buffer_ref(AVFilterContext *ctx,
00092 AVFilterBufferRef *samplesref,
00093 int av_unused flags)
00094 {
00095 return av_buffersrc_add_ref(ctx, samplesref, AV_BUFFERSRC_FLAG_NO_COPY);
00096 }
00097
00098 int av_asrc_buffer_add_samples(AVFilterContext *ctx,
00099 uint8_t *data[8], int linesize[8],
00100 int nb_samples, int sample_rate,
00101 int sample_fmt, int64_t channel_layout, int planar,
00102 int64_t pts, int av_unused flags)
00103 {
00104 AVFilterBufferRef *samplesref;
00105
00106 samplesref = avfilter_get_audio_buffer_ref_from_arrays(
00107 data, linesize[0], AV_PERM_WRITE,
00108 nb_samples,
00109 sample_fmt, channel_layout);
00110 if (!samplesref)
00111 return AVERROR(ENOMEM);
00112
00113 samplesref->buf->free = buf_free;
00114 samplesref->pts = pts;
00115 samplesref->audio->sample_rate = sample_rate;
00116
00117 AV_NOWARN_DEPRECATED(
00118 return av_asrc_buffer_add_audio_buffer_ref(ctx, samplesref, 0);
00119 )
00120 }
00121
00122 int av_asrc_buffer_add_buffer(AVFilterContext *ctx,
00123 uint8_t *buf, int buf_size, int sample_rate,
00124 int sample_fmt, int64_t channel_layout, int planar,
00125 int64_t pts, int av_unused flags)
00126 {
00127 uint8_t *data[8] = {0};
00128 int linesize[8];
00129 int nb_channels = av_get_channel_layout_nb_channels(channel_layout),
00130 nb_samples = buf_size / nb_channels / av_get_bytes_per_sample(sample_fmt);
00131
00132 av_samples_fill_arrays(data, linesize,
00133 buf, nb_channels, nb_samples,
00134 sample_fmt, 16);
00135
00136 AV_NOWARN_DEPRECATED(
00137 return av_asrc_buffer_add_samples(ctx,
00138 data, linesize, nb_samples,
00139 sample_rate,
00140 sample_fmt, channel_layout, planar,
00141 pts, flags);
00142 )
00143 }