mirror of
https://github.com/alsa-project/alsa-utils
synced 2024-11-10 06:35:41 +01:00
axfer: test: minor code arrangement to use the same file descriptor for mappter-test
In mapper test program, two set of file descriptors open to the same files for container builder and parser contexts, however the same file descriptor is available for the case. This commit arranges to use the same file descriptor for the contexts. Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp> Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
parent
2314d746b9
commit
5ab26fbc14
1 changed files with 34 additions and 39 deletions
|
@ -63,32 +63,20 @@ static int test_demux(struct mapper_trial *trial, snd_pcm_access_t access,
|
||||||
unsigned int frames_per_second,
|
unsigned int frames_per_second,
|
||||||
unsigned int frames_per_buffer,
|
unsigned int frames_per_buffer,
|
||||||
void *frame_buffer, unsigned int frame_count,
|
void *frame_buffer, unsigned int frame_count,
|
||||||
unsigned int cntr_count)
|
int *cntr_fds, unsigned int cntr_count)
|
||||||
{
|
{
|
||||||
struct container_context *cntrs = trial->cntrs;
|
struct container_context *cntrs = trial->cntrs;
|
||||||
enum container_format cntr_format = trial->cntr_format;
|
enum container_format cntr_format = trial->cntr_format;
|
||||||
int *cntr_fds;
|
|
||||||
unsigned int bytes_per_sample;
|
unsigned int bytes_per_sample;
|
||||||
uint64_t total_frame_count;
|
uint64_t total_frame_count;
|
||||||
int i;
|
int i;
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
cntr_fds = calloc(cntr_count, sizeof(*cntr_fds));
|
|
||||||
if (cntr_fds == NULL)
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
for (i = 0; i < cntr_count; ++i) {
|
for (i = 0; i < cntr_count; ++i) {
|
||||||
const char *path = trial->paths[i];
|
|
||||||
snd_pcm_format_t format;
|
snd_pcm_format_t format;
|
||||||
unsigned int channels;
|
unsigned int channels;
|
||||||
unsigned int rate;
|
unsigned int rate;
|
||||||
|
|
||||||
cntr_fds[i] = open(path, O_RDWR | O_CREAT | O_TRUNC, 0644);
|
|
||||||
if (cntr_fds[i] < 0) {
|
|
||||||
err = -errno;
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
|
|
||||||
err = container_builder_init(cntrs + i, cntr_fds[i], cntr_format, 0);
|
err = container_builder_init(cntrs + i, cntr_fds[i], cntr_format, 0);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
goto end;
|
goto end;
|
||||||
|
@ -124,12 +112,8 @@ static int test_demux(struct mapper_trial *trial, snd_pcm_access_t access,
|
||||||
assert(total_frame_count == frame_count);
|
assert(total_frame_count == frame_count);
|
||||||
}
|
}
|
||||||
end:
|
end:
|
||||||
for (i = 0; i < cntr_count; ++i) {
|
for (i = 0; i < cntr_count; ++i)
|
||||||
container_context_destroy(cntrs + i);
|
container_context_destroy(cntrs + i);
|
||||||
close(cntr_fds[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
free(cntr_fds);
|
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -170,31 +154,19 @@ static int test_mux(struct mapper_trial *trial, snd_pcm_access_t access,
|
||||||
unsigned int frames_per_second,
|
unsigned int frames_per_second,
|
||||||
unsigned int frames_per_buffer,
|
unsigned int frames_per_buffer,
|
||||||
void *frame_buffer, unsigned int frame_count,
|
void *frame_buffer, unsigned int frame_count,
|
||||||
unsigned int cntr_count)
|
int *cntr_fds, unsigned int cntr_count)
|
||||||
{
|
{
|
||||||
struct container_context *cntrs = trial->cntrs;
|
struct container_context *cntrs = trial->cntrs;
|
||||||
int *cntr_fds;
|
|
||||||
unsigned int bytes_per_sample;
|
unsigned int bytes_per_sample;
|
||||||
uint64_t total_frame_count;
|
uint64_t total_frame_count;
|
||||||
int i;
|
int i;
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
cntr_fds = calloc(cntr_count, sizeof(*cntr_fds));
|
|
||||||
if (cntr_fds == NULL)
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
for (i = 0; i < cntr_count; ++i) {
|
for (i = 0; i < cntr_count; ++i) {
|
||||||
const char *path = trial->paths[i];
|
|
||||||
snd_pcm_format_t format;
|
snd_pcm_format_t format;
|
||||||
unsigned int channels;
|
unsigned int channels;
|
||||||
unsigned int rate;
|
unsigned int rate;
|
||||||
|
|
||||||
cntr_fds[i] = open(path, O_RDONLY);
|
|
||||||
if (cntr_fds[i] < 0) {
|
|
||||||
err = -errno;
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
|
|
||||||
err = container_parser_init(cntrs + i, cntr_fds[i], 0);
|
err = container_parser_init(cntrs + i, cntr_fds[i], 0);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
goto end;
|
goto end;
|
||||||
|
@ -230,12 +202,8 @@ static int test_mux(struct mapper_trial *trial, snd_pcm_access_t access,
|
||||||
assert(total_frame_count == frame_count);
|
assert(total_frame_count == frame_count);
|
||||||
}
|
}
|
||||||
end:
|
end:
|
||||||
for (i = 0; i < cntr_count; ++i) {
|
for (i = 0; i < cntr_count; ++i)
|
||||||
container_context_destroy(cntrs + i);
|
container_context_destroy(cntrs + i);
|
||||||
close(cntr_fds[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
free(cntr_fds);
|
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -247,6 +215,7 @@ static int test_mapper(struct mapper_trial *trial, snd_pcm_access_t access,
|
||||||
void *check_buffer, unsigned int frame_count,
|
void *check_buffer, unsigned int frame_count,
|
||||||
unsigned int cntr_count)
|
unsigned int cntr_count)
|
||||||
{
|
{
|
||||||
|
int *cntr_fds;
|
||||||
unsigned int frames_per_buffer;
|
unsigned int frames_per_buffer;
|
||||||
int i;
|
int i;
|
||||||
int err;
|
int err;
|
||||||
|
@ -254,18 +223,44 @@ static int test_mapper(struct mapper_trial *trial, snd_pcm_access_t access,
|
||||||
// Use a buffer aligned by typical size of page frame.
|
// Use a buffer aligned by typical size of page frame.
|
||||||
frames_per_buffer = ((frame_count + 4096) / 4096) * 4096;
|
frames_per_buffer = ((frame_count + 4096) / 4096) * 4096;
|
||||||
|
|
||||||
|
cntr_fds = calloc(cntr_count, sizeof(*cntr_fds));
|
||||||
|
if (cntr_fds == NULL)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
for (i = 0; i < cntr_count; ++i) {
|
||||||
|
const char *path = trial->paths[i];
|
||||||
|
|
||||||
|
cntr_fds[i] = open(path, O_RDWR | O_CREAT | O_TRUNC, 0644);
|
||||||
|
if (cntr_fds[i] < 0) {
|
||||||
|
err = -errno;
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
err = test_demux(trial, access, sample_format, samples_per_frame,
|
err = test_demux(trial, access, sample_format, samples_per_frame,
|
||||||
frames_per_second, frames_per_buffer, frame_buffer,
|
frames_per_second, frames_per_buffer, frame_buffer,
|
||||||
frame_count, cntr_count);
|
frame_count, cntr_fds, cntr_count);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
goto end;
|
goto end;
|
||||||
|
|
||||||
|
for (i = 0; i < cntr_count; ++i) {
|
||||||
|
off64_t pos = lseek64(cntr_fds[i], 0, SEEK_SET);
|
||||||
|
if (pos != 0) {
|
||||||
|
err = -EIO;
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
err = test_mux(trial, access, sample_format, samples_per_frame,
|
err = test_mux(trial, access, sample_format, samples_per_frame,
|
||||||
frames_per_second, frames_per_buffer, check_buffer,
|
frames_per_second, frames_per_buffer, check_buffer,
|
||||||
frame_count, cntr_count);
|
frame_count, cntr_fds, cntr_count);
|
||||||
end:
|
end:
|
||||||
for (i = 0; i < cntr_count; ++i)
|
for (i = 0; i < cntr_count; ++i) {
|
||||||
unlink(trial->paths[i]);
|
unlink(trial->paths[i]);
|
||||||
|
close(cntr_fds[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(cntr_fds);
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue