diff options
author | Takashi Sakamoto <o-takashi@sakamocchi.jp> | 2021-03-11 14:21:35 +0900 |
---|---|---|
committer | Jaroslav Kysela <perex@perex.cz> | 2021-03-11 09:28:12 +0100 |
commit | 4bf9e269b2ca6509612db7e8edbd0939226f827c (patch) | |
tree | 8c62ab28a0b45cdfc0c2ef47726ab63f669c387e /axfer | |
parent | 85ab708f50915cb9f5c23704f51b8e9a7a020911 (diff) | |
download | alsa-utils-4bf9e269b2ca6509612db7e8edbd0939226f827c.tar.gz |
axfer: minor code arrangement to allocate containers
This commit unifies duplicated code to allocate for container structure.
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Diffstat (limited to 'axfer')
-rw-r--r-- | axfer/subcmd-transfer.c | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/axfer/subcmd-transfer.c b/axfer/subcmd-transfer.c index 8746e6f..6962208 100644 --- a/axfer/subcmd-transfer.c +++ b/axfer/subcmd-transfer.c @@ -146,6 +146,16 @@ static int context_init(struct context *ctx, snd_pcm_stream_t direction, return xfer_context_init(&ctx->xfer, xfer_type, direction, argc, argv); } +static int allocate_containers(struct context *ctx, unsigned int count) +{ + ctx->cntrs = calloc(count, sizeof(*ctx->cntrs)); + if (ctx->cntrs == NULL) + return -ENOMEM; + ctx->cntr_count = count; + + return 0; +} + static int capture_pre_process(struct context *ctx, snd_pcm_access_t *access, snd_pcm_uframes_t *frames_per_buffer, uint64_t *total_frame_count) @@ -164,10 +174,9 @@ static int capture_pre_process(struct context *ctx, snd_pcm_access_t *access, return err; // Prepare for containers. - ctx->cntrs = calloc(ctx->xfer.path_count, sizeof(*ctx->cntrs)); - if (ctx->cntrs == NULL) - return -ENOMEM; - ctx->cntr_count = ctx->xfer.path_count; + err = allocate_containers(ctx, ctx->xfer.path_count); + if (err < 0) + return err; if (ctx->cntr_count > 1) channels = 1; @@ -212,10 +221,9 @@ static int playback_pre_process(struct context *ctx, snd_pcm_access_t *access, int err; // Prepare for containers. - ctx->cntrs = calloc(ctx->xfer.path_count, sizeof(*ctx->cntrs)); - if (ctx->cntrs == NULL) - return -ENOMEM; - ctx->cntr_count = ctx->xfer.path_count; + err = allocate_containers(ctx, ctx->xfer.path_count); + if (err < 0) + return err; for (i = 0; i < ctx->cntr_count; ++i) { snd_pcm_format_t format; |