mirror of
https://github.com/alsa-project/alsa-utils
synced 2024-11-10 04:05:43 +01:00
f330d920bf
Current aplay supports several types of data format for file; Microsoft/IBM RIFF/Wave (.wav), Sparc AU (.au) and Creative Tech. voice (.voc). These formats were designed to handle audio-related data with interleaved frame alignment. This commit adds a common interface to handle the file format, named as 'container' module. This includes several functions to build/parse the format data from any file descriptors. Furthermore, this includes several helper functions for implementations of each builder/parser. Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp> Signed-off-by: Takashi Iwai <tiwai@suse.de>
110 lines
3 KiB
C
110 lines
3 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
//
|
|
// container.h - an interface of parser/builder for formatted files.
|
|
//
|
|
// Copyright (c) 2018 Takashi Sakamoto <o-takashi@sakamocchi.jp>
|
|
//
|
|
// Licensed under the terms of the GNU General Public License, version 2.
|
|
|
|
#ifndef __ALSA_UTILS_AXFER_CONTAINER__H_
|
|
#define __ALSA_UTILS_AXFER_CONTAINER__H_
|
|
|
|
#define _LARGEFILE64_SOURCE
|
|
#include <sys/types.h>
|
|
#include <unistd.h>
|
|
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
|
|
#include <alsa/asoundlib.h>
|
|
|
|
enum container_type {
|
|
CONTAINER_TYPE_PARSER = 0,
|
|
CONTAINER_TYPE_BUILDER,
|
|
CONTAINER_TYPE_COUNT,
|
|
};
|
|
|
|
enum container_format {
|
|
CONTAINER_FORMAT_COUNT,
|
|
};
|
|
|
|
struct container_ops;
|
|
|
|
struct container_context {
|
|
enum container_type type;
|
|
int fd;
|
|
int (*process_bytes)(struct container_context *cntr,
|
|
void *buffer, unsigned int byte_count);
|
|
bool magic_handled;
|
|
bool eof;
|
|
bool interrupted;
|
|
bool stdio;
|
|
|
|
enum container_format format;
|
|
uint64_t max_size;
|
|
char magic[4];
|
|
const struct container_ops *ops;
|
|
void *private_data;
|
|
|
|
// Available after pre-process.
|
|
unsigned int bytes_per_sample;
|
|
unsigned int samples_per_frame;
|
|
unsigned int frames_per_second;
|
|
|
|
unsigned int verbose;
|
|
uint64_t handled_byte_count;
|
|
};
|
|
|
|
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);
|
|
void container_context_destroy(struct container_context *cntr);
|
|
int container_context_pre_process(struct container_context *cntr,
|
|
snd_pcm_format_t *format,
|
|
unsigned int *samples_per_frame,
|
|
unsigned int *frames_per_second,
|
|
uint64_t *frame_count);
|
|
int container_context_process_frames(struct container_context *cntr,
|
|
void *frame_buffer,
|
|
unsigned int *frame_count);
|
|
int container_context_post_process(struct container_context *cntr,
|
|
uint64_t *frame_count);
|
|
|
|
// For internal use in 'container' module.
|
|
|
|
struct container_ops {
|
|
int (*pre_process)(struct container_context *cntr,
|
|
snd_pcm_format_t *format,
|
|
unsigned int *samples_per_frame,
|
|
unsigned int *frames_per_second,
|
|
uint64_t *byte_count);
|
|
int (*post_process)(struct container_context *cntr,
|
|
uint64_t handled_byte_count);
|
|
};
|
|
struct container_parser {
|
|
enum container_format format;
|
|
const char *const magic;
|
|
uint64_t max_size;
|
|
struct container_ops ops;
|
|
unsigned int private_size;
|
|
};
|
|
|
|
struct container_builder {
|
|
enum container_format format;
|
|
const char *const suffix;
|
|
uint64_t max_size;
|
|
struct container_ops ops;
|
|
unsigned int private_size;
|
|
};
|
|
|
|
int container_recursive_read(struct container_context *cntr, void *buf,
|
|
unsigned int byte_count);
|
|
int container_recursive_write(struct container_context *cntr, void *buf,
|
|
unsigned int byte_count);
|
|
int container_seek_offset(struct container_context *cntr, off64_t offset);
|
|
|
|
#endif
|