FFmpeg
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
src_buffer.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008 Vitor Sessak
3  * Copyright (c) 2010 S.N. Hemanth Meenakshisundaram
4  * Copyright (c) 2011 Mina Nagy Zaki
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 /**
24  * @file
25  * memory buffer source filter
26  */
27 
28 #include "avfilter.h"
29 #include "internal.h"
30 #include "audio.h"
31 #include "avcodec.h"
32 #include "buffersrc.h"
33 #include "asrc_abuffer.h"
34 #include "libavutil/avstring.h"
36 #include "libavutil/fifo.h"
37 #include "libavutil/imgutils.h"
38 
39 typedef struct {
40  AVFifoBuffer *fifo;
41  AVRational time_base; ///< time_base to set in the output link
42  int eof;
43  unsigned nb_failed_requests;
44 
45  /* Video only */
47  int h, w;
50  char sws_param[256];
51 
52  /* Audio only */
53  // Audio format of incoming buffers
54  int sample_rate;
55  unsigned int sample_format;
56  int64_t channel_layout;
57 
58  // Normalization filters
62 
63 static void buf_free(AVFilterBuffer *ptr)
64 {
65  av_free(ptr);
66  return;
67 }
68 
70  AVFilterBufferRef *samplesref,
71  int av_unused flags)
72 {
73  return av_buffersrc_add_ref(ctx, samplesref, AV_BUFFERSRC_FLAG_NO_COPY);
74 }
75 
77  uint8_t *data[8], int linesize[8],
78  int nb_samples, int sample_rate,
79  int sample_fmt, int64_t channel_layout, int planar,
80  int64_t pts, int av_unused flags)
81 {
82  AVFilterBufferRef *samplesref;
83 
84  if (!channel_layout)
85  return AVERROR(EINVAL);
87  data, linesize[0], AV_PERM_WRITE,
88  nb_samples,
89  sample_fmt, channel_layout);
90  if (!samplesref)
91  return AVERROR(ENOMEM);
92 
93  samplesref->buf->free = buf_free;
94  samplesref->pts = pts;
95  samplesref->audio->sample_rate = sample_rate;
96 
98  return av_asrc_buffer_add_audio_buffer_ref(ctx, samplesref, 0);
99  )
100 }
101 
103  uint8_t *buf, int buf_size, int sample_rate,
104  int sample_fmt, int64_t channel_layout, int planar,
105  int64_t pts, int av_unused flags)
106 {
107  uint8_t *data[8] = {0};
108  int linesize[8];
109  int nb_channels = av_get_channel_layout_nb_channels(channel_layout),
110  nb_samples = buf_size / nb_channels / av_get_bytes_per_sample(sample_fmt);
111 
112  av_samples_fill_arrays(data, linesize,
113  buf, nb_channels, nb_samples,
114  sample_fmt, 16);
115 
117  return av_asrc_buffer_add_samples(ctx,
118  data, linesize, nb_samples,
119  sample_rate,
120  sample_fmt, channel_layout, planar,
121  pts, flags);
122  )
123 }