Blame axfer/test/mapper-test.c

Packit Service a9274b
// SPDX-License-Identifier: GPL-2.0
Packit Service a9274b
//
Packit Service a9274b
// mapper-io.c - a unit test for muxer/demuxer for PCM frames on buffer.
Packit Service a9274b
//
Packit Service a9274b
// Copyright (c) 2018 Takashi Sakamoto <o-takashi@sakamocchi.jp>
Packit Service a9274b
//
Packit Service a9274b
// Licensed under the terms of the GNU General Public License, version 2.
Packit Service a9274b
Packit Service a9274b
#include "../mapper.h"
Packit Service a9274b
#include "../misc.h"
Packit Service a9274b
Packit Service a9274b
#include "generator.h"
Packit Service a9274b
Packit Service a9274b
#include <stdlib.h>
Packit Service a9274b
#include <unistd.h>
Packit Service a9274b
#include <stdbool.h>
Packit Service a9274b
Packit Service a9274b
#include <assert.h>
Packit Service a9274b
Packit Service a9274b
struct mapper_trial {
Packit Service a9274b
	enum container_format cntr_format;
Packit Service a9274b
	struct container_context *cntrs;
Packit Service a9274b
Packit Service a9274b
	char **paths;
Packit Service a9274b
Packit Service a9274b
	struct mapper_context mapper;
Packit Service a9274b
	bool verbose;
Packit Service a9274b
};
Packit Service a9274b
Packit Service a9274b
static void test_demuxer(struct mapper_context *mapper, snd_pcm_access_t access,
Packit Service a9274b
			 unsigned int bytes_per_sample,
Packit Service a9274b
			 unsigned int samples_per_frame,
Packit Service a9274b
			 unsigned int frames_per_buffer,
Packit Service a9274b
			 void *frame_buffer, unsigned int frame_count,
Packit Service a9274b
			 struct container_context *cntrs,
Packit Service a9274b
			 unsigned int cntr_count, bool verbose)
Packit Service a9274b
{
Packit Service a9274b
	unsigned int total_frame_count;
Packit Service a9274b
	int err;
Packit Service a9274b
Packit Service a9274b
	err = mapper_context_init(mapper, MAPPER_TYPE_DEMUXER, cntr_count,
Packit Service a9274b
				  verbose);
Packit Service a9274b
	assert(err == 0);
Packit Service a9274b
Packit Service a9274b
	err = mapper_context_pre_process(mapper, access, bytes_per_sample,
Packit Service a9274b
					 samples_per_frame, frames_per_buffer,
Packit Service a9274b
					 cntrs);
Packit Service a9274b
	assert(err == 0);
Packit Service a9274b
Packit Service a9274b
	total_frame_count = frame_count;
Packit Service a9274b
	err = mapper_context_process_frames(mapper, frame_buffer,
Packit Service a9274b
					    &total_frame_count, cntrs);
Packit Service a9274b
	assert(err == 0);
Packit Service a9274b
	assert(total_frame_count == frame_count);
Packit Service a9274b
Packit Service a9274b
	mapper_context_post_process(mapper);
Packit Service a9274b
	mapper_context_destroy(mapper);
Packit Service a9274b
}
Packit Service a9274b
Packit Service a9274b
static int test_demux(struct mapper_trial *trial, snd_pcm_access_t access,
Packit Service a9274b
		      snd_pcm_format_t sample_format,
Packit Service a9274b
		      unsigned int samples_per_frame,
Packit Service a9274b
		      unsigned int frames_per_second,
Packit Service a9274b
		      unsigned int frames_per_buffer,
Packit Service a9274b
		      void *frame_buffer, unsigned int frame_count,
Packit Service a9274b
		      unsigned int cntr_count)
Packit Service a9274b
{
Packit Service a9274b
	struct container_context *cntrs = trial->cntrs;
Packit Service a9274b
	char **paths = trial->paths;
Packit Service a9274b
	enum container_format cntr_format = trial->cntr_format;
Packit Service a9274b
	unsigned int bytes_per_sample;
Packit Service a9274b
	uint64_t total_frame_count;
Packit Service a9274b
	int i;
Packit Service a9274b
	int err = 0;
Packit Service a9274b
Packit Service a9274b
	for (i = 0; i < cntr_count; ++i) {
Packit Service a9274b
		snd_pcm_format_t format;
Packit Service a9274b
		unsigned int channels;
Packit Service a9274b
		unsigned int rate;
Packit Service a9274b
Packit Service a9274b
		err = container_builder_init(cntrs + i, paths[i], cntr_format,
Packit Service a9274b
					     0);
Packit Service a9274b
		if (err < 0)
Packit Service a9274b
			goto end;
Packit Service a9274b
Packit Service a9274b
		format = sample_format;
Packit Service a9274b
		rate = frames_per_second;
Packit Service a9274b
		total_frame_count = frame_count;
Packit Service a9274b
		if (cntr_count > 1)
Packit Service a9274b
			channels = 1;
Packit Service a9274b
		else
Packit Service a9274b
			channels = samples_per_frame;
Packit Service a9274b
		err = container_context_pre_process(cntrs + i, &format,
Packit Service a9274b
						    &channels, &rate,
Packit Service a9274b
						    &total_frame_count);
Packit Service a9274b
		if (err < 0)
Packit Service a9274b
			goto end;
Packit Service a9274b
		assert(format == sample_format);
Packit Service a9274b
		assert(rate == frames_per_second);
Packit Service a9274b
		assert(total_frame_count >= 0);
Packit Service a9274b
		if (cntr_count > 1)
Packit Service a9274b
			assert(channels == 1);
Packit Service a9274b
		else
Packit Service a9274b
			assert(channels == samples_per_frame);
Packit Service a9274b
	}
Packit Service a9274b
Packit Service a9274b
	bytes_per_sample = snd_pcm_format_physical_width(sample_format) / 8;
Packit Service a9274b
	test_demuxer(&trial->mapper, access, bytes_per_sample,
Packit Service a9274b
		     samples_per_frame, frames_per_buffer, frame_buffer,
Packit Service a9274b
		     frame_count, cntrs, cntr_count, trial->verbose);
Packit Service a9274b
Packit Service a9274b
	for (i = 0; i < cntr_count; ++i) {
Packit Service a9274b
		container_context_post_process(cntrs + i, &total_frame_count);
Packit Service a9274b
		assert(total_frame_count == frame_count);
Packit Service a9274b
	}
Packit Service a9274b
end:
Packit Service a9274b
	for (i = 0; i < cntr_count; ++i)
Packit Service a9274b
		container_context_destroy(cntrs + i);
Packit Service a9274b
Packit Service a9274b
	return err;
Packit Service a9274b
}
Packit Service a9274b
Packit Service a9274b
static void test_muxer(struct mapper_context *mapper, snd_pcm_access_t access,
Packit Service a9274b
		       unsigned int bytes_per_sample,
Packit Service a9274b
		       unsigned int samples_per_frame,
Packit Service a9274b
		       unsigned int frames_per_buffer,
Packit Service a9274b
		       void *frame_buffer, unsigned int frame_count,
Packit Service a9274b
		       struct container_context *cntrs,
Packit Service a9274b
		       unsigned int cntr_count, bool verbose)
Packit Service a9274b
{
Packit Service a9274b
	unsigned int total_frame_count;
Packit Service a9274b
	int err;
Packit Service a9274b
Packit Service a9274b
	err = mapper_context_init(mapper, MAPPER_TYPE_MUXER, cntr_count,
Packit Service a9274b
				  verbose);
Packit Service a9274b
	assert(err == 0);
Packit Service a9274b
Packit Service a9274b
	err = mapper_context_pre_process(mapper, access, bytes_per_sample,
Packit Service a9274b
					 samples_per_frame, frames_per_buffer,
Packit Service a9274b
					 cntrs);
Packit Service a9274b
	assert(err == 0);
Packit Service a9274b
Packit Service a9274b
	total_frame_count = frame_count;
Packit Service a9274b
	err = mapper_context_process_frames(mapper, frame_buffer,
Packit Service a9274b
					    &total_frame_count, cntrs);
Packit Service a9274b
	assert(err == 0);
Packit Service a9274b
	assert(total_frame_count == frame_count);
Packit Service a9274b
Packit Service a9274b
	mapper_context_post_process(mapper);
Packit Service a9274b
	mapper_context_destroy(mapper);
Packit Service a9274b
}
Packit Service a9274b
Packit Service a9274b
static int test_mux(struct mapper_trial *trial, snd_pcm_access_t access,
Packit Service a9274b
		    snd_pcm_format_t sample_format,
Packit Service a9274b
		    unsigned int samples_per_frame,
Packit Service a9274b
		    unsigned int frames_per_second,
Packit Service a9274b
		    unsigned int frames_per_buffer,
Packit Service a9274b
		    void *frame_buffer, unsigned int frame_count,
Packit Service a9274b
		    unsigned int cntr_count)
Packit Service a9274b
{
Packit Service a9274b
	struct container_context *cntrs = trial->cntrs;
Packit Service a9274b
	char **paths = trial->paths;
Packit Service a9274b
	unsigned int bytes_per_sample;
Packit Service a9274b
	uint64_t total_frame_count;
Packit Service a9274b
	int i;
Packit Service a9274b
	int err = 0;
Packit Service a9274b
Packit Service a9274b
	for (i = 0; i < cntr_count; ++i) {
Packit Service a9274b
		snd_pcm_format_t format;
Packit Service a9274b
		unsigned int channels;
Packit Service a9274b
		unsigned int rate;
Packit Service a9274b
Packit Service a9274b
		err = container_parser_init(cntrs + i, paths[i], 0);
Packit Service a9274b
		if (err < 0)
Packit Service a9274b
			goto end;
Packit Service a9274b
Packit Service a9274b
		format = sample_format;
Packit Service a9274b
		rate = frames_per_second;
Packit Service a9274b
		if (cntr_count > 1)
Packit Service a9274b
			channels = 1;
Packit Service a9274b
		else
Packit Service a9274b
			channels = samples_per_frame;
Packit Service a9274b
		err = container_context_pre_process(cntrs + i, &format,
Packit Service a9274b
						    &channels, &rate,
Packit Service a9274b
						    &total_frame_count);
Packit Service a9274b
		if (err < 0)
Packit Service a9274b
			goto end;
Packit Service a9274b
Packit Service a9274b
		assert(format == sample_format);
Packit Service a9274b
		assert(rate == frames_per_second);
Packit Service a9274b
		assert(total_frame_count == frame_count);
Packit Service a9274b
		if (cntr_count > 1)
Packit Service a9274b
			assert(channels == 1);
Packit Service a9274b
		else
Packit Service a9274b
			assert(channels == samples_per_frame);
Packit Service a9274b
	}
Packit Service a9274b
Packit Service a9274b
	bytes_per_sample = snd_pcm_format_physical_width(sample_format) / 8;
Packit Service a9274b
	test_muxer(&trial->mapper, access, bytes_per_sample, samples_per_frame,
Packit Service a9274b
		   frames_per_buffer, frame_buffer, frame_count, cntrs,
Packit Service a9274b
		   cntr_count, trial->verbose);
Packit Service a9274b
Packit Service a9274b
	for (i = 0; i < cntr_count; ++i) {
Packit Service a9274b
		container_context_post_process(cntrs + i, &total_frame_count);
Packit Service a9274b
		assert(total_frame_count == frame_count);
Packit Service a9274b
	}
Packit Service a9274b
end:
Packit Service a9274b
	for (i = 0; i < cntr_count; ++i)
Packit Service a9274b
		container_context_destroy(cntrs + i);
Packit Service a9274b
Packit Service a9274b
	return err;
Packit Service a9274b
}
Packit Service a9274b
Packit Service a9274b
static int test_mapper(struct mapper_trial *trial, snd_pcm_access_t access,
Packit Service a9274b
		    snd_pcm_format_t sample_format,
Packit Service a9274b
		    unsigned int samples_per_frame,
Packit Service a9274b
		    unsigned int frames_per_second, void *frame_buffer,
Packit Service a9274b
		    void *check_buffer, unsigned int frame_count,
Packit Service a9274b
		    unsigned int cntr_count)
Packit Service a9274b
{
Packit Service a9274b
	unsigned int frames_per_buffer;
Packit Service a9274b
	int i;
Packit Service a9274b
	int err;
Packit Service a9274b
Packit Service a9274b
	// Use a buffer aligned by typical size of page frame.
Packit Service a9274b
	frames_per_buffer = ((frame_count + 4096) / 4096) * 4096;
Packit Service a9274b
Packit Service a9274b
	err = test_demux(trial, access, sample_format, samples_per_frame,
Packit Service a9274b
			 frames_per_second, frames_per_buffer, frame_buffer,
Packit Service a9274b
			 frame_count, cntr_count);
Packit Service a9274b
	if (err < 0)
Packit Service a9274b
		goto end;
Packit Service a9274b
Packit Service a9274b
	err = test_mux(trial, access, sample_format, samples_per_frame,
Packit Service a9274b
		       frames_per_second, frames_per_buffer, check_buffer,
Packit Service a9274b
		       frame_count, cntr_count);
Packit Service a9274b
end:
Packit Service a9274b
	for (i = 0; i < cntr_count; ++i)
Packit Service a9274b
		unlink(trial->paths[i]);
Packit Service a9274b
Packit Service a9274b
	return err;
Packit Service a9274b
}
Packit Service a9274b
Packit Service a9274b
static int test_i_buf(struct mapper_trial *trial, snd_pcm_access_t access,
Packit Service a9274b
		      snd_pcm_format_t sample_format,
Packit Service a9274b
		      unsigned int samples_per_frame,
Packit Service a9274b
		      unsigned int frames_per_second, void *frame_buffer,
Packit Service a9274b
		      unsigned int frame_count, unsigned int cntr_count)
Packit Service a9274b
{
Packit Service a9274b
	unsigned int size;
Packit Service a9274b
	char *buf;
Packit Service a9274b
	int err;
Packit Service a9274b
Packit Service a9274b
	size = frame_count * samples_per_frame *
Packit Service a9274b
			snd_pcm_format_physical_width(sample_format) / 8;
Packit Service a9274b
	buf = malloc(size);
Packit Service a9274b
	if (buf == 0)
Packit Service a9274b
		return -ENOMEM;
Packit Service a9274b
	memset(buf, 0, size);
Packit Service a9274b
Packit Service a9274b
	// Test multiple target.
Packit Service a9274b
	err = test_mapper(trial, access, sample_format, samples_per_frame,
Packit Service a9274b
			  frames_per_second, frame_buffer, buf,
Packit Service a9274b
			  frame_count, cntr_count);
Packit Service a9274b
	if (err < 0)
Packit Service a9274b
		goto end;
Packit Service a9274b
	err = memcmp(frame_buffer, buf, size);
Packit Service a9274b
	assert(err == 0);
Packit Service a9274b
Packit Service a9274b
	// Test single target.
Packit Service a9274b
	err = test_mapper(trial, access, sample_format, samples_per_frame,
Packit Service a9274b
			  frames_per_second, frame_buffer, buf,
Packit Service a9274b
			  frame_count, 1);
Packit Service a9274b
	if (err < 0)
Packit Service a9274b
		goto end;
Packit Service a9274b
	err = memcmp(frame_buffer, buf, size);
Packit Service a9274b
	assert(err == 0);
Packit Service a9274b
end:
Packit Service a9274b
	free(buf);
Packit Service a9274b
Packit Service a9274b
	return err;
Packit Service a9274b
}
Packit Service a9274b
Packit Service a9274b
static int test_vector(struct mapper_trial *trial, snd_pcm_access_t access,
Packit Service a9274b
		       snd_pcm_format_t sample_format,
Packit Service a9274b
		       unsigned int samples_per_frame,
Packit Service a9274b
		       unsigned int frames_per_second, void *frame_buffer,
Packit Service a9274b
		       unsigned int frame_count, unsigned int cntr_count)
Packit Service a9274b
{
Packit Service a9274b
	unsigned int size;
Packit Service a9274b
	char **bufs;
Packit Service a9274b
	int i;
Packit Service a9274b
	int err;
Packit Service a9274b
Packit Service a9274b
	bufs = calloc(cntr_count, sizeof(*bufs));
Packit Service a9274b
	if (bufs == NULL)
Packit Service a9274b
		return -ENOMEM;
Packit Service a9274b
Packit Service a9274b
	size = frame_count * snd_pcm_format_physical_width(sample_format) / 8;
Packit Service a9274b
Packit Service a9274b
	for (i = 0; i < cntr_count; ++i) {
Packit Service a9274b
		bufs[i] = malloc(size);
Packit Service a9274b
		if (bufs[i] == NULL) {
Packit Service a9274b
			err = -ENOMEM;
Packit Service a9274b
			goto end;
Packit Service a9274b
		}
Packit Service a9274b
		memset(bufs[i], 0, size);
Packit Service a9274b
	}
Packit Service a9274b
Packit Service a9274b
	// Test multiple target.
Packit Service a9274b
	err = test_mapper(trial, access, sample_format, samples_per_frame,
Packit Service a9274b
			  frames_per_second, frame_buffer, bufs,
Packit Service a9274b
			  frame_count, cntr_count);
Packit Service a9274b
	if (err < 0)
Packit Service a9274b
		goto end;
Packit Service a9274b
	for (i = 0; i < cntr_count; ++i) {
Packit Service a9274b
		char **target = frame_buffer;
Packit Service a9274b
		err = memcmp(target[i], bufs[i], size);
Packit Service a9274b
		assert(err == 0);
Packit Service a9274b
	}
Packit Service a9274b
Packit Service a9274b
	// Test single target.
Packit Service a9274b
	err = test_mapper(trial, access, sample_format, samples_per_frame,
Packit Service a9274b
			  frames_per_second, frame_buffer, bufs,
Packit Service a9274b
			  frame_count, 1);
Packit Service a9274b
	if (err < 0)
Packit Service a9274b
		goto end;
Packit Service a9274b
	for (i = 0; i < cntr_count; ++i) {
Packit Service a9274b
		char **target = frame_buffer;
Packit Service a9274b
		err = memcmp(target[i], bufs[i], size);
Packit Service a9274b
		assert(err == 0);
Packit Service a9274b
	}
Packit Service a9274b
end:
Packit Service a9274b
	for (i = 0; i < cntr_count; ++i) {
Packit Service a9274b
		if (bufs[i])
Packit Service a9274b
			free(bufs[i]);
Packit Service a9274b
	}
Packit Service a9274b
	free(bufs);
Packit Service a9274b
Packit Service a9274b
	return err;
Packit Service a9274b
}
Packit Service a9274b
Packit Service a9274b
static int test_n_buf(struct mapper_trial *trial, snd_pcm_access_t access,
Packit Service a9274b
		      snd_pcm_format_t sample_format,
Packit Service a9274b
		      unsigned int samples_per_frame,
Packit Service a9274b
		      unsigned int frames_per_second, void *frame_buffer,
Packit Service a9274b
		      unsigned int frame_count, unsigned int cntr_count)
Packit Service a9274b
{
Packit Service a9274b
	char *test_buf = frame_buffer;
Packit Service a9274b
	unsigned int size;
Packit Service a9274b
	char **test_vec;
Packit Service a9274b
	int i;
Packit Service a9274b
	int err;
Packit Service a9274b
Packit Service a9274b
	size = frame_count * snd_pcm_format_physical_width(sample_format) / 8;
Packit Service a9274b
Packit Service a9274b
	test_vec = calloc(cntr_count * 2, sizeof(*test_vec));
Packit Service a9274b
	if (test_vec == NULL)
Packit Service a9274b
		return -ENOMEM;
Packit Service a9274b
Packit Service a9274b
	for (i = 0; i < cntr_count; ++i)
Packit Service a9274b
		test_vec[i] = test_buf + size * i;
Packit Service a9274b
Packit Service a9274b
	err = test_vector(trial, access, sample_format, samples_per_frame,
Packit Service a9274b
			  frames_per_second, test_vec, frame_count, cntr_count);
Packit Service a9274b
	free(test_vec);
Packit Service a9274b
Packit Service a9274b
	return err;
Packit Service a9274b
}
Packit Service a9274b
Packit Service a9274b
static int callback(struct test_generator *gen, snd_pcm_access_t access,
Packit Service a9274b
		    snd_pcm_format_t sample_format,
Packit Service a9274b
		    unsigned int samples_per_frame, void *frame_buffer,
Packit Service a9274b
		    unsigned int frame_count)
Packit Service a9274b
{
Packit Service a9274b
Packit Service a9274b
	int (*handler)(struct mapper_trial *trial, snd_pcm_access_t access,
Packit Service a9274b
		       snd_pcm_format_t sample_format,
Packit Service a9274b
		       unsigned int samples_per_frame,
Packit Service a9274b
		       unsigned int frames_per_second, void *frame_buffer,
Packit Service a9274b
		       unsigned int frame_count, unsigned int cntr_count);
Packit Service a9274b
	struct mapper_trial *trial = gen->private_data;
Packit Service a9274b
Packit Service a9274b
	if (access == SND_PCM_ACCESS_RW_NONINTERLEAVED)
Packit Service a9274b
		handler = test_vector;
Packit Service a9274b
	else if (access == SND_PCM_ACCESS_MMAP_NONINTERLEAVED)
Packit Service a9274b
		handler = test_n_buf;
Packit Service a9274b
	else
Packit Service a9274b
		handler = test_i_buf;
Packit Service a9274b
Packit Service a9274b
	return handler(trial, access, sample_format, samples_per_frame, 48000,
Packit Service a9274b
		       frame_buffer, frame_count, samples_per_frame);
Packit Service a9274b
};
Packit Service a9274b
Packit Service a9274b
int main(int argc, const char *argv[])
Packit Service a9274b
{
Packit Service a9274b
	// Test 8/16/18/20/24/32/64 bytes per sample.
Packit Service a9274b
	static const uint64_t sample_format_mask =
Packit Service a9274b
			(1ull << SND_PCM_FORMAT_U8) |
Packit Service a9274b
			(1ull << SND_PCM_FORMAT_S16_LE) |
Packit Service a9274b
			(1ull << SND_PCM_FORMAT_S18_3LE) |
Packit Service a9274b
			(1ull << SND_PCM_FORMAT_S20_3LE) |
Packit Service a9274b
			(1ull << SND_PCM_FORMAT_S24_LE) |
Packit Service a9274b
			(1ull << SND_PCM_FORMAT_S32_LE) |
Packit Service a9274b
			(1ull << SND_PCM_FORMAT_FLOAT64_LE);
Packit Service a9274b
	uint64_t access_mask;
Packit Service a9274b
	struct test_generator gen = {0};
Packit Service a9274b
	struct mapper_trial *trial;
Packit Service a9274b
	struct container_context *cntrs;
Packit Service a9274b
	unsigned int samples_per_frame;
Packit Service a9274b
	char **paths = NULL;
Packit Service a9274b
	snd_pcm_access_t access;
Packit Service a9274b
	bool verbose;
Packit Service a9274b
	int i;
Packit Service a9274b
	int err;
Packit Service a9274b
Packit Service a9274b
	// Test up to 32 channels.
Packit Service a9274b
	samples_per_frame = 32;
Packit Service a9274b
	cntrs = calloc(samples_per_frame, sizeof(*cntrs));
Packit Service a9274b
	if (cntrs == NULL)
Packit Service a9274b
		return -ENOMEM;
Packit Service a9274b
Packit Service a9274b
	paths = calloc(samples_per_frame, sizeof(*paths));
Packit Service a9274b
	if (paths == NULL) {
Packit Service a9274b
		err = -ENOMEM;
Packit Service a9274b
		goto end;
Packit Service a9274b
	}
Packit Service a9274b
	for (i = 0; i < samples_per_frame; ++i) {
Packit Service a9274b
		paths[i] = malloc(8);
Packit Service a9274b
		if (paths[i] == NULL) {
Packit Service a9274b
			err = -ENOMEM;
Packit Service a9274b
			goto end;
Packit Service a9274b
		}
Packit Service a9274b
		snprintf(paths[i], 8, "hoge%d", i);
Packit Service a9274b
	}
Packit Service a9274b
Packit Service a9274b
	if (argc > 1) {
Packit Service a9274b
		char *term;
Packit Service a9274b
		access = strtol(argv[1], &term, 10);
Packit Service a9274b
		if (errno != 0 || *term != '\0') {
Packit Service a9274b
			err = -EINVAL;;
Packit Service a9274b
			goto end;
Packit Service a9274b
		}
Packit Service a9274b
		if (access < SND_PCM_ACCESS_MMAP_INTERLEAVED &&
Packit Service a9274b
		    access > SND_PCM_ACCESS_RW_NONINTERLEAVED) {
Packit Service a9274b
			err = -EINVAL;
Packit Service a9274b
			goto end;
Packit Service a9274b
		}
Packit Service a9274b
		if (access == SND_PCM_ACCESS_MMAP_COMPLEX) {
Packit Service a9274b
			err = -EINVAL;
Packit Service a9274b
			goto end;
Packit Service a9274b
		}
Packit Service a9274b
Packit Service a9274b
		access_mask = 1ull << access;
Packit Service a9274b
		verbose = true;
Packit Service a9274b
	} else {
Packit Service a9274b
		access_mask = (1ull << SND_PCM_ACCESS_MMAP_INTERLEAVED) |
Packit Service a9274b
			      (1ull << SND_PCM_ACCESS_MMAP_NONINTERLEAVED) |
Packit Service a9274b
			      (1ull << SND_PCM_ACCESS_RW_INTERLEAVED) |
Packit Service a9274b
			      (1ull << SND_PCM_ACCESS_RW_NONINTERLEAVED);
Packit Service a9274b
		verbose = false;
Packit Service a9274b
	}
Packit Service a9274b
Packit Service a9274b
	err = generator_context_init(&gen, access_mask, sample_format_mask,
Packit Service a9274b
				     1, samples_per_frame,
Packit Service a9274b
				     23, 4500, 1024,
Packit Service a9274b
				     sizeof(struct mapper_trial));
Packit Service a9274b
	if (err < 0)
Packit Service a9274b
		goto end;
Packit Service a9274b
Packit Service a9274b
	trial = gen.private_data;
Packit Service a9274b
	trial->cntrs = cntrs;
Packit Service a9274b
	trial->cntr_format = CONTAINER_FORMAT_RIFF_WAVE;
Packit Service a9274b
	trial->paths = paths;
Packit Service a9274b
	trial->verbose = verbose;
Packit Service a9274b
	err = generator_context_run(&gen, callback);
Packit Service a9274b
Packit Service a9274b
	generator_context_destroy(&gen;;
Packit Service a9274b
end:
Packit Service a9274b
	if (paths) {
Packit Service a9274b
		for (i = 0; i < samples_per_frame; ++i)
Packit Service a9274b
			free(paths[i]);
Packit Service a9274b
		free(paths);
Packit Service a9274b
	}
Packit Service a9274b
	free(cntrs);
Packit Service a9274b
Packit Service a9274b
	if (err < 0) {
Packit Service a9274b
		printf("%s\n", strerror(-err));
Packit Service a9274b
		return EXIT_FAILURE;
Packit Service a9274b
	}
Packit Service a9274b
Packit Service a9274b
	return EXIT_SUCCESS;
Packit Service a9274b
}