-
Notifications
You must be signed in to change notification settings - Fork 31
/
codec.h
86 lines (73 loc) · 2.44 KB
/
codec.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
* This file is part of dsp.
*
* Copyright (c) 2013-2024 Michael Barbour <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef DSP_CODEC_H
#define DSP_CODEC_H
#include "dsp.h"
enum {
CODEC_MODE_READ = 1<<0,
CODEC_MODE_WRITE = 1<<1,
};
enum {
CODEC_ENDIAN_DEFAULT,
CODEC_ENDIAN_BIG,
CODEC_ENDIAN_LITTLE,
CODEC_ENDIAN_NATIVE,
};
enum {
CODEC_HINT_INTERACTIVE = 1<<0,
CODEC_HINT_CAN_DITHER = 1<<1,
CODEC_HINT_NO_OUT_BUF = 1<<2,
};
struct codec {
struct codec *next;
const char *path, *type, *enc;
int fs, channels, prec, hints;
ssize_t frames;
ssize_t (*read)(struct codec *, sample_t *, ssize_t); /* should be NULL if mode == CODEC_MODE_WRITE */
ssize_t (*write)(struct codec *, sample_t *, ssize_t); /* should be NULL if mode == CODEC_MODE_READ */
ssize_t (*seek)(struct codec *, ssize_t);
ssize_t (*delay)(struct codec *);
void (*drop)(struct codec *); /* drop pending frames */
void (*pause)(struct codec *, int);
void (*destroy)(struct codec *);
void *data;
};
struct codec_list {
struct codec *head;
struct codec *tail;
};
#define CODEC_LIST_INITIALIZER ((struct codec_list) { NULL, NULL })
struct codec_params {
const char *path, *type, *enc;
int fs, channels, endian, mode, block_frames, buf_ratio;
};
#define CODEC_PARAMS_AUTO(path_arg, mode_arg) { \
.path = path_arg, \
.endian = CODEC_ENDIAN_DEFAULT, \
.mode = mode_arg, \
.block_frames = DEFAULT_BLOCK_FRAMES, \
.buf_ratio = DEFAULT_BUF_RATIO, \
}
#define CODEC_DEFAULT_DEVICE "default"
struct codec * init_codec(const struct codec_params *);
void destroy_codec(struct codec *);
void append_codec(struct codec_list *, struct codec *);
void destroy_codec_list_head(struct codec_list *);
void destroy_codec_list(struct codec_list *);
void print_all_codecs(void);
#endif