aboutsummaryrefslogtreecommitdiffstats
path: root/src/pq_codec.c
blob: 82b79e74ba1a2eec150d2da487fe86e64151af5e (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
/* Process Queue: Codec handling tasks */

/*
 * 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/>.
 */

#include <errno.h>
#include <stdint.h>

#include <gapk/codecs.h>
#include <gapk/formats.h>
#include <gapk/procqueue.h>


int
pq_queue_codec(struct pq *pq, const struct codec_desc *codec, int enc_dec_n)
{
	const struct codec_desc *codec_pcm = codec_get_from_type(CODEC_PCM);
	const struct format_desc *fmt;
	struct pq_item *item;

	item = pq_add_item(pq);
	if (!item)
		return -ENOMEM;

	if (codec->codec_init) {
		item->state = codec->codec_init();
		if (!item->state)
			return -EINVAL;
	}

	if (enc_dec_n) {
		fmt = fmt_get_from_type(codec->codec_enc_format_type);
		if (!fmt)
			return -EINVAL;

		item->len_in  = codec_pcm->canon_frame_len;
		item->len_out = fmt->frame_len;
		item->proc    = codec->codec_encode;
	} else {
		fmt = fmt_get_from_type(codec->codec_dec_format_type);
		if (!fmt)
			return -EINVAL;

		item->len_in  = fmt->frame_len;
		item->len_out = codec_pcm->canon_frame_len;
		item->proc    = codec->codec_decode;
	}

	item->exit = codec->codec_exit;

	if (!item->proc)
		return -ENOTSUP;

	return 0;
}