return 0;
}
-int container_parser_init(struct container_context *cntr,
- const char *const path, unsigned int verbose)
+int container_parser_init(struct container_context *cntr, int fd,
+ unsigned int verbose)
{
const struct container_parser *parsers[] = {
[CONTAINER_FORMAT_RIFF_WAVE] = &container_parser_riff_wave,
[CONTAINER_FORMAT_AU] = &container_parser_au,
[CONTAINER_FORMAT_VOC] = &container_parser_voc,
};
- int fd;
const struct container_parser *parser;
unsigned int size;
int i;
int err;
assert(cntr);
- assert(path);
- assert(path[0] != '\0');
+ assert(fd >= 0);
// Detect forgotten to destruct.
assert(cntr->fd == 0);
memset(cntr, 0, sizeof(*cntr));
- // Open a target descriptor.
- if (!strcmp(path, "-")) {
- fd = fileno(stdin);
- } else {
- fd = open(path, O_RDONLY);
- if (fd < 0)
- return -errno;
- }
cntr->fd = fd;
cntr->stdio = (cntr->fd == fileno(stdin));
return 0;
}
-int container_builder_init(struct container_context *cntr,
- const char *const path, enum container_format format,
- unsigned int verbose)
+int container_builder_init(struct container_context *cntr, int fd,
+ enum container_format format, unsigned int verbose)
{
const struct container_builder *builders[] = {
[CONTAINER_FORMAT_RIFF_WAVE] = &container_builder_riff_wave,
[CONTAINER_FORMAT_VOC] = &container_builder_voc,
[CONTAINER_FORMAT_RAW] = &container_builder_raw,
};
- int fd;
const struct container_builder *builder;
int err;
assert(cntr);
- assert(path);
- assert(path[0] != '\0');
+ assert(fd >= 0);
// Detect forgotten to destruct.
assert(cntr->fd == 0);
memset(cntr, 0, sizeof(*cntr));
- // Open a target descriptor.
- if (path == NULL || *path == '\0')
- return -EINVAL;
- if (!strcmp(path, "-")) {
- fd = fileno(stdout);
- } else {
- fd = open(path, O_RDWR | O_CREAT | O_TRUNC, 0644);
- if (fd < 0)
- return -errno;
- }
cntr->fd = fd;
cntr->stdio = (cntr->fd == fileno(stdout));
const char *const container_suffix_from_format(enum container_format format);
enum container_format container_format_from_path(const char *path);
-int container_parser_init(struct container_context *cntr,
- const char *const path, unsigned int verbose);
-int container_builder_init(struct container_context *cntr,
- const char *const path, enum container_format format,
- unsigned int verbose);
+int container_parser_init(struct container_context *cntr, int fd,
+ unsigned int verbose);
+int container_builder_init(struct container_context *cntr, int fd,
+ enum container_format format, unsigned int verbose);
void container_context_destroy(struct container_context *cntr);
int container_context_pre_process(struct container_context *cntr,
snd_pcm_format_t *format,
*total_frame_count = 0;
for (i = 0; i < ctx->cntr_count; ++i) {
+ const char *path = ctx->xfer.paths[i];
+ int fd;
uint64_t frame_count;
- err = container_builder_init(ctx->cntrs + i,
- ctx->xfer.paths[i],
+ if (!strcmp(path, "-")) {
+ fd = fileno(stdout);
+ } else {
+ fd = open(path, O_RDWR | O_CREAT | O_TRUNC, 0644);
+ if (fd < 0)
+ return -errno;
+ }
+
+ err = container_builder_init(ctx->cntrs + i, fd,
ctx->xfer.cntr_format,
ctx->xfer.verbose > 1);
if (err < 0)
return err;
for (i = 0; i < ctx->cntr_count; ++i) {
+ const char *path = ctx->xfer.paths[i];
+ int fd;
snd_pcm_format_t format;
unsigned int channels;
unsigned int rate;
uint64_t frame_count;
- err = container_parser_init(ctx->cntrs + i,
- ctx->xfer.paths[i],
+ if (!strcmp(path, "-")) {
+ fd = fileno(stdin);
+ } else {
+ fd = open(path, O_RDONLY);
+ if (fd < 0)
+ return -errno;
+ }
+
+ err = container_parser_init(ctx->cntrs + i, fd,
ctx->xfer.verbose > 1);
if (err < 0)
return err;
void *frame_buffer, unsigned int frame_count,
bool verbose)
{
+ int fd;
snd_pcm_format_t sample;
unsigned int channels;
unsigned int rate;
uint64_t total_frame_count;
int err;
- err = container_builder_init(cntr, name, format, verbose);
+ fd = open(name, O_RDWR | O_CREAT | O_TRUNC, 0644);
+ assert(fd >= 0);
+
+ err = container_builder_init(cntr, fd, format, verbose);
assert(err == 0);
sample = sample_format;
void *frame_buffer, unsigned int frame_count,
bool verbose)
{
+ int fd;
snd_pcm_format_t sample;
unsigned int channels;
unsigned int rate;
unsigned int handled_frame_count;
int err;
- err = container_parser_init(cntr, name, verbose);
+ fd = open(name, O_RDONLY);
+ assert(fd >= 0);
+
+ err = container_parser_init(cntr, fd, verbose);
assert(err == 0);
sample = sample_format;
unsigned int cntr_count)
{
struct container_context *cntrs = trial->cntrs;
- char **paths = trial->paths;
enum container_format cntr_format = trial->cntr_format;
unsigned int bytes_per_sample;
uint64_t total_frame_count;
int err = 0;
for (i = 0; i < cntr_count; ++i) {
+ const char *path = trial->paths[i];
+ int fd;
snd_pcm_format_t format;
unsigned int channels;
unsigned int rate;
- err = container_builder_init(cntrs + i, paths[i], cntr_format,
- 0);
+ fd = open(path, O_RDWR | O_CREAT | O_TRUNC, 0644);
+ if (fd < 0)
+ return -errno;
+
+ err = container_builder_init(cntrs + i, fd, cntr_format, 0);
if (err < 0)
goto end;
unsigned int cntr_count)
{
struct container_context *cntrs = trial->cntrs;
- char **paths = trial->paths;
unsigned int bytes_per_sample;
uint64_t total_frame_count;
int i;
int err = 0;
for (i = 0; i < cntr_count; ++i) {
+ const char *path = trial->paths[i];
+ int fd;
snd_pcm_format_t format;
unsigned int channels;
unsigned int rate;
- err = container_parser_init(cntrs + i, paths[i], 0);
+ fd = open(path, O_RDONLY);
+ if (fd < 0)
+ return -errno;
+
+ err = container_parser_init(cntrs + i, fd, 0);
if (err < 0)
goto end;