blob: 20892184f6aacf71b9fd52dc3d345c0fc768386e [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
Harald Welte59128482017-05-28 10:20:54 +020029pq_cb_fmt_convert(void *_state, uint8_t *out, const uint8_t *in, unsigned int in_len)
Sylvain Munaut792d0412010-11-11 20:41:50 +010030{
31 fmt_conv_cb_t f = _state;
Harald Welte59128482017-05-28 10:20:54 +020032 return f(out, in, in_len);
Sylvain Munaut792d0412010-11-11 20:41:50 +010033}
34
Harald Weltef3d2ad62017-05-27 16:42:14 +020035/*! Add format conversion to processing queue
36 * \param pq Processing Queue to add conversion to
37 * \param[in] fmt Format description for conversion
38 * \param[in] to_from_n convert to (0) or from (1) specified format */
Sylvain Munaut792d0412010-11-11 20:41:50 +010039int
40pq_queue_fmt_convert(struct pq *pq, const struct format_desc *fmt, int to_from_n)
41{
42 struct pq_item *item;
43 const struct codec_desc *codec = codec_get_from_type(fmt->codec_type);
44
45 if (!codec)
46 return -EINVAL;
47
48 item = pq_add_item(pq);
49 if (!item)
50 return -ENOMEM;
51
52 if (to_from_n) {
53 item->len_in = codec->canon_frame_len;
54 item->len_out = fmt->frame_len;
55 item->state = fmt->conv_from_canon;
56 } else {
57 item->len_in = fmt->frame_len;
58 item->len_out = codec->canon_frame_len;
59 item->state = fmt->conv_to_canon;
60 }
61
62 item->proc = pq_cb_fmt_convert;
63
64 return 0;
65}