2018-11-13 07:41:15 +01:00
|
|
|
// 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_
|
|
|
|
|
2023-08-30 18:48:23 +02:00
|
|
|
#include "aconfig.h"
|
|
|
|
|
2018-11-13 07:41:15 +01:00
|
|
|
#define _LARGEFILE64_SOURCE
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include <alsa/asoundlib.h>
|
|
|
|
|
2022-12-31 08:03:34 +01:00
|
|
|
#include "os_compat.h"
|
|
|
|
|
2018-11-13 07:41:15 +01:00
|
|
|
enum container_type {
|
|
|
|
CONTAINER_TYPE_PARSER = 0,
|
|
|
|
CONTAINER_TYPE_BUILDER,
|
|
|
|
CONTAINER_TYPE_COUNT,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum container_format {
|
2018-11-13 07:41:16 +01:00
|
|
|
CONTAINER_FORMAT_RIFF_WAVE = 0,
|
2018-11-13 07:41:17 +01:00
|
|
|
CONTAINER_FORMAT_AU,
|
axfer: add support for a container of Creative Tech. voice format
This commit adds support for data of Creative Tech. voice format. In this
data format, values in each of field are represented in little-endian byte
order and available formats of data sample are restricted in little-endian
byte order.
In version 1.10 of this format, sampling rate is represented with
reciprocal number of the rate, thus we cannot calculate original sampling
rate precisely just from its header. For example at 44.1kHz, file header
includes 233 (=256-1,000,000/44,100), but we cannot recover the value just
from the code (43478.2...). For my convenience, this commit adds a
pre-computed table and lookup major rates from the table.
Additionally, this format can includes several blocks with different
sample format. When handling this type of file, we need to start/stop
substream for each of the block, while this brings complicated code.
This type of format is enough ancient and presently quite minor. This
commit takes a compromise and handles a first sample block only.
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2018-11-13 07:41:18 +01:00
|
|
|
CONTAINER_FORMAT_VOC,
|
2018-11-13 07:41:19 +01:00
|
|
|
CONTAINER_FORMAT_RAW,
|
2018-11-13 07:41:15 +01:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2023-08-30 12:35:57 +02:00
|
|
|
const char *container_suffix_from_format(enum container_format format);
|
2018-11-13 07:41:15 +01:00
|
|
|
enum container_format container_format_from_path(const char *path);
|
2021-03-11 06:21:36 +01:00
|
|
|
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);
|
2018-11-13 07:41:15 +01:00
|
|
|
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);
|
2022-12-15 23:04:10 +01:00
|
|
|
int container_seek_offset(struct container_context *cntr, off_t offset);
|
2018-11-13 07:41:15 +01:00
|
|
|
|
2018-11-13 07:41:16 +01:00
|
|
|
extern const struct container_parser container_parser_riff_wave;
|
|
|
|
extern const struct container_builder container_builder_riff_wave;
|
|
|
|
|
2018-11-13 07:41:17 +01:00
|
|
|
extern const struct container_parser container_parser_au;
|
|
|
|
extern const struct container_builder container_builder_au;
|
|
|
|
|
axfer: add support for a container of Creative Tech. voice format
This commit adds support for data of Creative Tech. voice format. In this
data format, values in each of field are represented in little-endian byte
order and available formats of data sample are restricted in little-endian
byte order.
In version 1.10 of this format, sampling rate is represented with
reciprocal number of the rate, thus we cannot calculate original sampling
rate precisely just from its header. For example at 44.1kHz, file header
includes 233 (=256-1,000,000/44,100), but we cannot recover the value just
from the code (43478.2...). For my convenience, this commit adds a
pre-computed table and lookup major rates from the table.
Additionally, this format can includes several blocks with different
sample format. When handling this type of file, we need to start/stop
substream for each of the block, while this brings complicated code.
This type of format is enough ancient and presently quite minor. This
commit takes a compromise and handles a first sample block only.
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2018-11-13 07:41:18 +01:00
|
|
|
extern const struct container_parser container_parser_voc;
|
|
|
|
extern const struct container_builder container_builder_voc;
|
|
|
|
|
2019-04-21 02:13:20 +02:00
|
|
|
extern const struct container_parser container_parser_raw;
|
|
|
|
extern const struct container_builder container_builder_raw;
|
2018-11-13 07:41:19 +01:00
|
|
|
|
2018-11-13 07:41:15 +01:00
|
|
|
#endif
|