aboutsummaryrefslogtreecommitdiffstats
path: root/include/osmocom/gapk/procqueue.h
blob: 82c1cf99e505cd66cb4b4f7fc3983446204c87ff (plain)
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/* Processing Queue Management */

/*
 * This file is part of gapk (GSM Audio Pocket Knife).
 *
 * gapk is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * gapk is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with gapk.  If not, see <http://www.gnu.org/licenses/>.
 */

#pragma once

#include <stdint.h>
#include <stdio.h> /* for FILE */

#include <osmocom/core/linuxlist.h>

enum osmo_gapk_pq_item_type {
	OSMO_GAPK_ITEM_TYPE_SOURCE,
	OSMO_GAPK_ITEM_TYPE_SINK,
	OSMO_GAPK_ITEM_TYPE_PROC,
};

#define OSMO_GAPK_CAT_NAME_SOURCE	"source"
#define OSMO_GAPK_CAT_NAME_SINK	"sink"
#define OSMO_GAPK_CAT_NAME_PROC	"proc"

struct osmo_gapk_pq_item {
	/*! input frame size (in bytes). '0' in case of variable frames */
	unsigned int len_in;
	/*! output frame size (in bytes). '0' in case of variable frames */
	unsigned int len_out;
	/*! opaque state */
	void *state;
	/*! buffer for output data */
	uint8_t *buf;
	/*! call-back for actual format conversion function
	 *  \param[in] state opaque state pointer
	 *  \param[out] out caller-allocated buffer for output data
	 *  \param[in] in input data
	 *  \param[in] in_len length of input data \a in
	 *  \returns number of output bytes written to \a out; negative on error */
	int  (*proc)(void *state, uint8_t *out, const uint8_t *in, unsigned int in_len);
	int  (*wait)(void *state);
	void (*exit)(void *state);

	/*! \brief link to a processing queue */
	struct llist_head list;
	/*! \brief type of item */
	enum osmo_gapk_pq_item_type type;
	/*! \brief category name (src, format, codec, sink) */
	const char *cat_name;
	/*! \brief sub-category name (file, rtp-amr, amr, alsa) */
	const char *sub_name;
};

#define VAR_BUF_SIZE	320

struct osmo_gapk_pq {
	struct llist_head items;
	unsigned n_items;

	/*! \brief human-readable name */
	const char *name;
};

/* Processing queue management */
struct osmo_gapk_pq *osmo_gapk_pq_create(const char *name);
int osmo_gapk_pq_check(struct osmo_gapk_pq *pq, int strict);
int osmo_gapk_pq_prepare(struct osmo_gapk_pq *pq);
int osmo_gapk_pq_execute(struct osmo_gapk_pq *pq);
void osmo_gapk_pq_destroy(struct osmo_gapk_pq *pq);
char *osmo_gapk_pq_describe(struct osmo_gapk_pq *pq);

/* Processing queue item management */
struct osmo_gapk_pq_item *osmo_gapk_pq_add_item(struct osmo_gapk_pq *pq);

/* File */
int osmo_gapk_pq_queue_file_input(struct osmo_gapk_pq *pq, FILE *src, unsigned int block_len);
int osmo_gapk_pq_queue_file_output(struct osmo_gapk_pq *pq, FILE *dst, unsigned int block_len);

/* RTP */
int osmo_gapk_pq_queue_rtp_input(struct osmo_gapk_pq *pq, int rtp_fd,
	unsigned int block_len, uint8_t pt);
int osmo_gapk_pq_queue_rtp_output(struct osmo_gapk_pq *pq, int rtp_fd,
	unsigned int block_len, uint8_t pt);

/* ALSA */
int osmo_gapk_pq_queue_alsa_input(struct osmo_gapk_pq *pq, const char *hwdev, unsigned int blk_len);
int osmo_gapk_pq_queue_alsa_output(struct osmo_gapk_pq *pq, const char *hwdev, unsigned int blk_len);

/* Format */
struct osmo_gapk_format_desc;
int osmo_gapk_pq_queue_fmt_convert(struct osmo_gapk_pq *pq, const struct osmo_gapk_format_desc *fmt, int to_from_n);

/* Codec */
struct osmo_gapk_codec_desc;
int osmo_gapk_pq_queue_codec(struct osmo_gapk_pq *pq, const struct osmo_gapk_codec_desc *codec, int encode);

/* ECU (Error Concealment Unit) */
int osmo_gapk_pq_queue_ecu(struct osmo_gapk_pq *pq, const struct osmo_gapk_codec_desc *codec);