diff options
author | Sylvain Munaut <tnt@246tNt.com> | 2010-11-11 20:42:09 +0100 |
---|---|---|
committer | Sylvain Munaut <tnt@246tNt.com> | 2010-11-11 20:45:24 +0100 |
commit | 9843418a3375ee93197cf9647397aa3e05cd21b8 (patch) | |
tree | f46806cdc68d231386faee2cfcf11dde4e940ac6 | |
parent | 792d04135e06b688b318f5410f9cc466e40a41c7 (diff) |
procqueue: Add Codec tasks
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
-rw-r--r-- | include/gapk/procqueue.h | 4 | ||||
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/pq_codec.c | 69 |
3 files changed, 74 insertions, 1 deletions
diff --git a/include/gapk/procqueue.h b/include/gapk/procqueue.h index 2b1f1d1..ba1e2fa 100644 --- a/include/gapk/procqueue.h +++ b/include/gapk/procqueue.h @@ -48,4 +48,8 @@ int pq_queue_file_output(struct pq *pq, FILE *dst, unsigned int block_len); struct format_desc; int pq_queue_fmt_convert(struct pq *pq, const struct format_desc *fmt, int to_from_n); +/* Codec */ +struct codec_desc; +int pq_queue_codec(struct pq *pq, const struct codec_desc *codec, int encode); + #endif /* __GAPK_PROCQUEUE_H__ */ diff --git a/src/Makefile.am b/src/Makefile.am index 7eed04d..116985c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -4,6 +4,6 @@ AM_LDFLAGS=$(LIBOSMOCODEC_LIBS) ${OPENCORE_AMRNB_LIBS} ${LIBGSM_LIBS} bin_PROGRAMS = gapk gapk_SOURCES = main.c \ - procqueue.c pq_file.c pq_format.c \ + procqueue.c pq_file.c pq_format.c pq_codec.c \ formats.c fmt_amr.c fmt_gsm.c fmt_hr_ref.c fmt_racal.c \ codecs.c codec_pcm.c codec_hr.c codec_fr.c codec_efr.c diff --git a/src/pq_codec.c b/src/pq_codec.c new file mode 100644 index 0000000..82b79e7 --- /dev/null +++ b/src/pq_codec.c @@ -0,0 +1,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; +} |