aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/gapk/procqueue.h4
-rw-r--r--src/Makefile.am2
-rw-r--r--src/pq_file.c99
3 files changed, 104 insertions, 1 deletions
diff --git a/include/gapk/procqueue.h b/include/gapk/procqueue.h
index 59f567e..18a644f 100644
--- a/include/gapk/procqueue.h
+++ b/include/gapk/procqueue.h
@@ -40,4 +40,8 @@ struct pq_item * pq_add_item(struct pq *pq);
int pq_prepare(struct pq *pq);
int pq_execute(struct pq *pq);
+/* File */
+int pq_queue_file_input(struct pq *pq, FILE *src, unsigned int block_len);
+int pq_queue_file_output(struct pq *pq, FILE *dst, unsigned int block_len);
+
#endif /* __GAPK_PROCQUEUE_H__ */
diff --git a/src/Makefile.am b/src/Makefile.am
index 1a0531f..43d046e 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 \
+ procqueue.c pq_file.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_file.c b/src/pq_file.c
new file mode 100644
index 0000000..4b16555
--- /dev/null
+++ b/src/pq_file.c
@@ -0,0 +1,99 @@
+/* Process Queue: File 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 <stdio.h>
+#include <stdlib.h>
+
+#include <gapk/codecs.h>
+#include <gapk/formats.h>
+#include <gapk/procqueue.h>
+
+
+struct pq_state_file {
+ FILE *fh;
+ unsigned int blk_len;
+};
+
+
+static int
+pq_cb_file_input(void *_state, uint8_t *out, const uint8_t *in)
+{
+ struct pq_state_file *state = _state;
+ int rv;
+ rv = fread(out, state->blk_len, 1, state->fh);
+ return rv == 1 ? 0 : -1;
+}
+
+static int
+pq_cb_file_output(void *_state, uint8_t *out, const uint8_t *in)
+{
+ struct pq_state_file *state = _state;
+ int rv;
+ rv = fwrite(in, state->blk_len, 1, state->fh);
+ return rv == 1 ? 0 : -1;
+}
+
+static void
+pq_cb_file_exit(void *_state)
+{
+ free(_state);
+}
+
+static int
+pq_queue_file_op(struct pq *pq, FILE *fh, unsigned int blk_len, int in_out_n)
+{
+ struct pq_item *item;
+ struct pq_state_file *state;
+
+ state = calloc(1, sizeof(struct pq_state_file));
+ if (!state)
+ return -ENOMEM;
+
+ state->fh = fh;
+ state->blk_len = blk_len;
+
+ item = pq_add_item(pq);
+ if (!item) {
+ free(state);
+ return -ENOMEM;
+ }
+
+ item->len_in = in_out_n ? 0 : blk_len;
+ item->len_out = in_out_n ? blk_len : 0;
+ item->state = state;
+ item->proc = in_out_n ? pq_cb_file_input : pq_cb_file_output;
+ item->exit = pq_cb_file_exit;
+
+ return 0;
+}
+
+
+int
+pq_queue_file_input(struct pq *pq, FILE *src, unsigned int blk_len)
+{
+ return pq_queue_file_op(pq, src, blk_len, 1);
+}
+
+int
+pq_queue_file_output(struct pq *pq, FILE *dst, unsigned int blk_len)
+{
+ return pq_queue_file_op(pq, dst, blk_len, 0);
+}