blob: 876ac19f88905df775a1b175ae77008016a68f3c [file] [log] [blame]
Sylvain Munaut792d0412010-11-11 20:41:50 +01001/* Process Queue: Format handling tasks */
2
3/*
4 * This file is part of gapk (GSM Audio Pocket Knife).
5 *
6 * gapk is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * gapk is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with gapk. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <errno.h>
21#include <stdint.h>
22
23#include <gapk/codecs.h>
24#include <gapk/formats.h>
25#include <gapk/procqueue.h>
26
27
28static int
29pq_cb_fmt_convert(void *_state, uint8_t *out, const uint8_t *in)
30{
31 fmt_conv_cb_t f = _state;
32 return f(out, in);
33}
34
35int
36pq_queue_fmt_convert(struct pq *pq, const struct format_desc *fmt, int to_from_n)
37{
38 struct pq_item *item;
39 const struct codec_desc *codec = codec_get_from_type(fmt->codec_type);
40
41 if (!codec)
42 return -EINVAL;
43
44 item = pq_add_item(pq);
45 if (!item)
46 return -ENOMEM;
47
48 if (to_from_n) {
49 item->len_in = codec->canon_frame_len;
50 item->len_out = fmt->frame_len;
51 item->state = fmt->conv_from_canon;
52 } else {
53 item->len_in = fmt->frame_len;
54 item->len_out = codec->canon_frame_len;
55 item->state = fmt->conv_to_canon;
56 }
57
58 item->proc = pq_cb_fmt_convert;
59
60 return 0;
61}