[vlc-commits] mux: add extradata builder helper
Francois Cartegnie
git at videolan.org
Fri Dec 21 11:09:00 CET 2018
vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Thu Dec 20 11:44:11 2018 +0100| [50ee8803414b024411674ffcba2cf0ba495c7258] | committer: Francois Cartegnie
mux: add extradata builder helper
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=50ee8803414b024411674ffcba2cf0ba495c7258
---
modules/mux/Makefile.am | 3 ++
modules/mux/extradata.c | 122 ++++++++++++++++++++++++++++++++++++++++++++++++
modules/mux/extradata.h | 26 +++++++++++
3 files changed, 151 insertions(+)
diff --git a/modules/mux/Makefile.am b/modules/mux/Makefile.am
index eb63724015..b3f916bae5 100644
--- a/modules/mux/Makefile.am
+++ b/modules/mux/Makefile.am
@@ -1,5 +1,8 @@
muxdir = $(pluginsdir)/mux
+extradata_builder_SOURCES = mux/extradata.c mux/extradata.h \
+ packetizer/av1_obu.c
+
libmux_dummy_plugin_la_SOURCES = mux/dummy.c
libmux_asf_plugin_la_SOURCES = mux/asf.c demux/asf/libasf_guid.h
diff --git a/modules/mux/extradata.c b/modules/mux/extradata.c
new file mode 100644
index 0000000000..79076cc23e
--- /dev/null
+++ b/modules/mux/extradata.c
@@ -0,0 +1,122 @@
+/*****************************************************************************
+ * extradata.c: Muxing extradata builder/gatherer
+ *****************************************************************************
+ * Copyright (C) 2018 VideoLabs, VLC authors and VideoLAN
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_codec.h>
+
+#include "extradata.h"
+#include "../packetizer/av1_obu.h"
+
+struct mux_extradata_builder_cb
+{
+ int (*pf_init)(mux_extradata_builder_t *);
+ void (*pf_feed)(mux_extradata_builder_t *, const uint8_t *, size_t);
+ void (*pf_deinit)(mux_extradata_builder_t *);
+};
+
+struct mux_extradata_builder_t
+{
+ struct mux_extradata_builder_cb cb;
+ void *priv;
+ uint8_t *p_extra;
+ size_t i_extra;
+ vlc_fourcc_t fcc;
+};
+
+static void av1_extradata_builder_Feed(mux_extradata_builder_t *m,
+ const uint8_t *p_data, size_t i_data)
+{
+ if(m->i_extra)
+ return;
+
+ AV1_OBU_iterator_ctx_t ctx;
+ AV1_OBU_iterator_init(&ctx, p_data, i_data);
+ const uint8_t *p_obu; size_t i_obu;
+ while(AV1_OBU_iterate_next(&ctx, &p_obu, &i_obu))
+ {
+ enum av1_obu_type_e OBUtype = AV1_OBUGetType(p_obu);
+ if(OBUtype != AV1_OBU_SEQUENCE_HEADER)
+ continue;
+ av1_OBU_sequence_header_t *p_sh = AV1_OBU_parse_sequence_header(p_obu, i_obu);
+ if(p_sh)
+ {
+ m->i_extra = AV1_create_DecoderConfigurationRecord(&m->p_extra, p_sh,
+ 1, (const uint8_t **)&p_obu, &i_obu);
+ AV1_release_sequence_header(p_sh);
+ }
+ break;
+ }
+}
+
+const struct mux_extradata_builder_cb av1_cb =
+{
+ NULL,
+ av1_extradata_builder_Feed,
+ NULL,
+};
+
+void mux_extradata_builder_Delete(mux_extradata_builder_t *m)
+{
+ if(m->cb.pf_deinit)
+ m->cb.pf_deinit(m);
+ free(m->p_extra);
+ free(m);
+}
+
+mux_extradata_builder_t * mux_extradata_builder_New(vlc_fourcc_t fcc)
+{
+ const struct mux_extradata_builder_cb *cb;
+ switch(fcc)
+ {
+ case VLC_CODEC_AV1:
+ cb = &av1_cb;
+ break;
+ default:
+ return NULL;
+ }
+
+ mux_extradata_builder_t *m = calloc(1, sizeof(*m));
+ if(m)
+ {
+ m->fcc = fcc;
+ m->cb = *cb;
+ if(m->cb.pf_init && m->cb.pf_init(m) != 0)
+ {
+ free(m);
+ m = NULL;
+ }
+ }
+ return m;
+}
+
+size_t mux_extradata_builder_Get(mux_extradata_builder_t *m, const uint8_t **a)
+{
+ *a = m->p_extra;
+ return m->i_extra;
+}
+
+void mux_extradata_builder_Feed(mux_extradata_builder_t *m,
+ const uint8_t *p_data, size_t i_data)
+{
+ m->cb.pf_feed(m, p_data, i_data);
+}
diff --git a/modules/mux/extradata.h b/modules/mux/extradata.h
new file mode 100644
index 0000000000..6754f84294
--- /dev/null
+++ b/modules/mux/extradata.h
@@ -0,0 +1,26 @@
+/*****************************************************************************
+ * extradata.h: Muxing extradata builder/gatherer
+ *****************************************************************************
+ * Copyright (C) 2018 VideoLabs, VLC authors and VideoLAN
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+typedef struct mux_extradata_builder_t mux_extradata_builder_t;
+
+mux_extradata_builder_t * mux_extradata_builder_New(vlc_fourcc_t);
+void mux_extradata_builder_Delete(mux_extradata_builder_t *);
+void mux_extradata_builder_Feed(mux_extradata_builder_t *, const uint8_t *, size_t);
+size_t mux_extradata_builder_Get(mux_extradata_builder_t *, const uint8_t **);
More information about the vlc-commits
mailing list