#include <stdlib.h>
#include <stdio.h>
#include <inttypes.h>
+#include "libavutil/mem.h"
#include "libavutil/audio_fifo.c"
#define MAX_CHANNELS 32
exit(1);
}
-static void* allocate_memory(size_t size)
-{
- void *ptr = malloc(size);
- if (ptr == NULL){
- ERROR("failed to allocate memory!");
- }
- return ptr;
-}
-
static void print_audio_bytes(const TestStruct *test_sample, void **data_planes, int nb_samples)
{
int p, b, f;
int samples = FFMIN(nb_samples, afifo->nb_samples);
int tot_elements = !av_sample_fmt_is_planar(afifo->sample_fmt)
? samples : afifo->channels * samples;
- void **data_planes = allocate_memory(sizeof(void*) * afifo->nb_buffers);
+ void **data_planes = av_malloc_array(afifo->nb_buffers, sizeof(void*));
+ if (!data_planes)
+ ERROR("failed to allocate memory!");
*output = data_planes;
for (i = 0; i < afifo->nb_buffers; ++i){
- data_planes[i] = allocate_memory(afifo->sample_size * tot_elements);
+ data_planes[i] = av_malloc_array(tot_elements, afifo->sample_size);
+ if (!data_planes[i])
+ ERROR("failed to allocate memory!");
}
return av_audio_fifo_read(afifo, *output, nb_samples);
/* deallocate */
for (i = 0; i < afifo->nb_buffers; ++i){
- free(output_data[i]);
+ av_freep(&output_data[i]);
}
- free(output_data);
+ av_freep(&output_data);
av_audio_fifo_free(afifo);
}