1 /*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include <stdlib.h>
20 #include <stdio.h>
21 #include <inttypes.h>
24
25 #define MAX_CHANNELS 32
26
27
34
35 static const uint8_t data_U8 [] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
36 static const int16_t
data_S16[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
37 static const float data_FLT[] = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0};
38
46 };
47
49 {
50 int i;
53 }
55 }
56
57 static void ERROR(
const char *str)
58 {
59 fprintf(stderr, "%s\n", str);
60 exit(1);
61 }
62
64 {
68 ? test_sample->
nb_ch : 1;
69 int line_size = (buffers > 1) ? nb_samples * byte_offset
70 : nb_samples * byte_offset * test_sample->
nb_ch;
72 for(b = 0; b < line_size; b+=byte_offset){
73 for (f = 0; f < byte_offset; f++){
74 int order = !HAVE_BIGENDIAN ? (byte_offset - f - 1) : f;
75 printf(
"%02x", *((
uint8_t*)data_planes[p] + b + order));
76 }
77 putchar(' ');
78 }
79 putchar('\n');
80 }
81 }
82
84 {
85 int i;
88 ? samples : afifo->
channels * samples;
90 if (!data_planes)
91 ERROR(
"failed to allocate memory!");
92 if (*output)
94 *output = data_planes;
95
98 if (!data_planes[i])
99 ERROR(
"failed to allocate memory!");
100 }
101
103 }
104
106 int nb_samples,
int offset)
107 {
108 int offset_size, i;
110
112 return 0;
113 }
115 return 0;
116 }
118
121 }
122
124 }
125
127 {
128 int ret, i;
132 if (!afifo) {
133 ERROR(
"ERROR: av_audio_fifo_alloc returned NULL!");
134 }
136 if (ret < 0){
137 ERROR(
"ERROR: av_audio_fifo_write failed!");
138 }
139 printf("written: %d\n", ret);
140
142 if (ret < 0){
143 ERROR(
"ERROR: av_audio_fifo_write failed!");
144 }
145 printf("written: %d\n", ret);
147
149 if (ret < 0){
150 ERROR(
"ERROR: av_audio_fifo_read failed!");
151 }
152 printf("read: %d\n", ret);
155
156 /* test av_audio_fifo_peek */
158 if (ret < 0){
159 ERROR(
"ERROR: av_audio_fifo_peek failed!");
160 }
161 printf("peek:\n");
163 printf("\n");
164
165 /* test av_audio_fifo_peek_at */
166 printf("peek_at:\n");
169 if (ret < 0){
170 ERROR(
"ERROR: av_audio_fifo_peek_at failed!");
171 }
172 printf("%d:\n", i);
174 }
175 printf("\n");
176
177 /* test av_audio_fifo_drain */
179 if (ret < 0){
180 ERROR(
"ERROR: av_audio_fifo_drain failed!");
181 }
183 ERROR(
"drain failed to flush all samples in audio_fifo!");
184 }
185
186 /* deallocate */
189 }
190
192 {
194
195 for (t = 0; t <
tests; ++t){
196 printf("\nTEST: %d\n\n", t+1);
198 }
199 return 0;
200 }
AVAudioFifo * av_audio_fifo_alloc(enum AVSampleFormat sample_fmt, int channels, int nb_samples)
Allocate an AVAudioFifo.
int av_audio_fifo_read(AVAudioFifo *af, void **data, int nb_samples)
Read data from an AVAudioFifo.
Memory handling functions.
void av_audio_fifo_free(AVAudioFifo *af)
Free an AVAudioFifo.
void const * data_planes[MAX_CHANNELS]
enum AVSampleFormat sample_fmt
sample format
static void ERROR(const char *str)
static void test_function(const TestStruct *test_sample)
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
static int write_samples_to_audio_fifo(AVAudioFifo *afifo, const TestStruct *test_sample, int nb_samples, int offset)
static const uint8_t offset[127][2]
Context for an Audio FIFO Buffer.
int nb_buffers
number of buffers
int av_audio_fifo_size(AVAudioFifo *af)
Get the current number of samples in the AVAudioFifo available for reading.
static int output_data(MLPDecodeContext *m, unsigned int substr, AVFrame *frame, int *got_frame_ptr)
Write the audio data into the output buffer.
static const uint8_t data_U8[]
int nb_samples
number of samples currently in the FIFO
AVSampleFormat
Audio sample formats.
int channels
number of channels
static const float data_FLT[]
enum AVSampleFormat format
static const TestStruct test_struct[]
static void free_data_planes(AVAudioFifo *afifo, void **output_data)
int sample_size
size, in bytes, of one sample in a buffer
static void print_audio_bytes(const TestStruct *test_sample, void **data_planes, int nb_samples)
static int read_samples_from_audio_fifo(AVAudioFifo *afifo, void ***output, int nb_samples)
int av_audio_fifo_write(AVAudioFifo *af, void **data, int nb_samples)
Write data to an AVAudioFifo.
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
int av_audio_fifo_drain(AVAudioFifo *af, int nb_samples)
Drain data from an AVAudioFifo.
int av_audio_fifo_peek(AVAudioFifo *af, void **data, int nb_samples)
Peek data from an AVAudioFifo.
#define av_malloc_array(a, b)
static const int16_t data_S16[]
int av_audio_fifo_peek_at(AVAudioFifo *af, void **data, int nb_samples, int offset)
Peek data from an AVAudioFifo.