mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-01-24 13:56:33 +02:00
avutil/tests/audio_fifo.c: pass by reference for efficiency and change datatype to const
Signed-off-by: Thomas Turner <thomastdt@googlemail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
This commit is contained in:
parent
1d4d0ee4b0
commit
08fdf965c9
@ -29,7 +29,7 @@ typedef struct TestStruct {
|
||||
const enum AVSampleFormat format;
|
||||
const int nb_ch;
|
||||
void const *data_planes[MAX_CHANNELS];
|
||||
int nb_samples_pch;
|
||||
const int nb_samples_pch;
|
||||
} TestStruct;
|
||||
|
||||
static const uint8_t data_U8 [] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
|
||||
@ -102,55 +102,55 @@ static int read_samples_from_audio_fifo(AVAudioFifo* afifo, void ***output, int
|
||||
return av_audio_fifo_read(afifo, *output, nb_samples);
|
||||
}
|
||||
|
||||
static int write_samples_to_audio_fifo(AVAudioFifo* afifo, const TestStruct test_sample,
|
||||
static int write_samples_to_audio_fifo(AVAudioFifo* afifo, const TestStruct *test_sample,
|
||||
int nb_samples, int offset)
|
||||
{
|
||||
int offset_size, i;
|
||||
void *data_planes[MAX_CHANNELS];
|
||||
|
||||
if(nb_samples > test_sample.nb_samples_pch - offset){
|
||||
if(nb_samples > test_sample->nb_samples_pch - offset){
|
||||
return 0;
|
||||
}
|
||||
if(offset >= test_sample.nb_samples_pch){
|
||||
if(offset >= test_sample->nb_samples_pch){
|
||||
return 0;
|
||||
}
|
||||
offset_size = offset * afifo->sample_size;
|
||||
|
||||
for (i = 0; i < afifo->nb_buffers ; ++i){
|
||||
data_planes[i] = (uint8_t*)test_sample.data_planes[i] + offset_size;
|
||||
data_planes[i] = (uint8_t*)test_sample->data_planes[i] + offset_size;
|
||||
}
|
||||
|
||||
return av_audio_fifo_write(afifo, data_planes, nb_samples);
|
||||
}
|
||||
|
||||
static void test_function(const TestStruct test_sample)
|
||||
static void test_function(const TestStruct *test_sample)
|
||||
{
|
||||
int ret, i;
|
||||
void **output_data = NULL;
|
||||
AVAudioFifo *afifo = av_audio_fifo_alloc(test_sample.format, test_sample.nb_ch,
|
||||
test_sample.nb_samples_pch);
|
||||
AVAudioFifo *afifo = av_audio_fifo_alloc(test_sample->format, test_sample->nb_ch,
|
||||
test_sample->nb_samples_pch);
|
||||
if (!afifo) {
|
||||
ERROR("ERROR: av_audio_fifo_alloc returned NULL!");
|
||||
}
|
||||
ret = write_samples_to_audio_fifo(afifo, test_sample, test_sample.nb_samples_pch, 0);
|
||||
ret = write_samples_to_audio_fifo(afifo, test_sample, test_sample->nb_samples_pch, 0);
|
||||
if (ret < 0){
|
||||
ERROR("ERROR: av_audio_fifo_write failed!");
|
||||
}
|
||||
printf("written: %d\n", ret);
|
||||
|
||||
ret = write_samples_to_audio_fifo(afifo, test_sample, test_sample.nb_samples_pch, 0);
|
||||
ret = write_samples_to_audio_fifo(afifo, test_sample, test_sample->nb_samples_pch, 0);
|
||||
if (ret < 0){
|
||||
ERROR("ERROR: av_audio_fifo_write failed!");
|
||||
}
|
||||
printf("written: %d\n", ret);
|
||||
printf("remaining samples in audio_fifo: %d\n\n", av_audio_fifo_size(afifo));
|
||||
|
||||
ret = read_samples_from_audio_fifo(afifo, &output_data, test_sample.nb_samples_pch);
|
||||
ret = read_samples_from_audio_fifo(afifo, &output_data, test_sample->nb_samples_pch);
|
||||
if (ret < 0){
|
||||
ERROR("ERROR: av_audio_fifo_read failed!");
|
||||
}
|
||||
printf("read: %d\n", ret);
|
||||
print_audio_bytes(&test_sample, output_data, ret);
|
||||
print_audio_bytes(test_sample, output_data, ret);
|
||||
printf("remaining samples in audio_fifo: %d\n\n", av_audio_fifo_size(afifo));
|
||||
|
||||
/* test av_audio_fifo_peek */
|
||||
@ -159,7 +159,7 @@ static void test_function(const TestStruct test_sample)
|
||||
ERROR("ERROR: av_audio_fifo_peek failed!");
|
||||
}
|
||||
printf("peek:\n");
|
||||
print_audio_bytes(&test_sample, output_data, ret);
|
||||
print_audio_bytes(test_sample, output_data, ret);
|
||||
printf("\n");
|
||||
|
||||
/* test av_audio_fifo_peek_at */
|
||||
@ -170,7 +170,7 @@ static void test_function(const TestStruct test_sample)
|
||||
ERROR("ERROR: av_audio_fifo_peek_at failed!");
|
||||
}
|
||||
printf("%d:\n", i);
|
||||
print_audio_bytes(&test_sample, output_data, ret);
|
||||
print_audio_bytes(test_sample, output_data, ret);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
@ -194,7 +194,7 @@ int main(void)
|
||||
|
||||
for (t = 0; t < tests; ++t){
|
||||
printf("\nTEST: %d\n\n", t+1);
|
||||
test_function(test_struct[t]);
|
||||
test_function(&test_struct[t]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user