[vlc-devel] [PATCH] demux: add ADF demuxer (Fixes #17501)
Tristan Matthews
tmatth at videolan.org
Sat Oct 22 21:11:50 CEST 2016
---
modules/demux/Makefile.am | 3 +
modules/demux/adf.c | 174 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 177 insertions(+)
create mode 100644 modules/demux/adf.c
diff --git a/modules/demux/Makefile.am b/modules/demux/Makefile.am
index 857f732..4429bc1 100644
--- a/modules/demux/Makefile.am
+++ b/modules/demux/Makefile.am
@@ -28,6 +28,9 @@ demux_LTLIBRARIES += libau_plugin.la
librawaud_plugin_la_SOURCES = demux/rawaud.c
demux_LTLIBRARIES += librawaud_plugin.la
+libadf_plugin_la_SOURCES = demux/adf.c
+demux_LTLIBRARIES += libadf_plugin.la
+
libwav_plugin_la_SOURCES = demux/wav.c demux/windows_audio_commons.h
demux_LTLIBRARIES += libwav_plugin.la
diff --git a/modules/demux/adf.c b/modules/demux/adf.c
new file mode 100644
index 0000000..435d26d
--- /dev/null
+++ b/modules/demux/adf.c
@@ -0,0 +1,174 @@
+/*****************************************************************************
+ * adf.c : ADF demuxer module for vlc
+ *****************************************************************************
+ * Copyright (C) 2016 VLC authors and VideoLAN
+ *
+ * Authors: Tristan Matthews <tmatth at videolan.org>
+ * Based on flac.c by: Gildas Bazin <gbazin at netcourrier.com>
+ * Laurent Aimar <fenrir at via.ecp.fr>
+ *
+ * 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.
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Preamble
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
+#include <vlc_demux.h>
+#include <vlc_codec.h>
+
+/*****************************************************************************
+ * Module descriptor
+ *****************************************************************************/
+static int Open ( vlc_object_t * );
+static void Close( vlc_object_t * );
+
+vlc_module_begin();
+ set_description( N_("ADF demuxer") );
+ set_capability( "demux", 100 );
+ set_category( CAT_INPUT );
+ set_subcategory( SUBCAT_INPUT_DEMUX );
+ set_callbacks( Open, Close );
+ add_shortcut( "adf" );
+vlc_module_end();
+
+/*****************************************************************************
+ * Definitions of structures used by this plugin
+ *****************************************************************************/
+struct demux_sys_t
+{
+ bool b_start;
+ int64_t i_pts;
+ es_out_id_t *p_es;
+ decoder_t *p_packetizer;
+};
+
+/*****************************************************************************
+ * Local prototypes
+ *****************************************************************************/
+static int Demux( demux_t * );
+static int Control( demux_t *, int, va_list );
+
+/*****************************************************************************
+ * Open: initializes adf demuxer
+ *****************************************************************************/
+static int Open( vlc_object_t * p_this )
+{
+ demux_t *p_demux = (demux_t*)p_this;
+ demux_sys_t *p_sys;
+ es_format_t fmt;
+
+ p_sys = malloc( sizeof( demux_sys_t ) );
+ if( unlikely(p_sys == NULL) )
+ return VLC_ENOMEM;
+
+ p_demux->pf_demux = Demux;
+ p_demux->pf_control = Control;
+ p_demux->p_sys = p_sys;
+ p_sys->b_start = true;
+ p_sys->i_pts = 0;
+ p_sys->p_es = NULL;
+
+ /* Load the packetizer */
+ es_format_Init( &fmt, AUDIO_ES, VLC_CODEC_MP3 );
+ p_sys->p_packetizer = demux_PacketizerNew( p_demux, &fmt, "adf" );
+ if( !p_sys->p_packetizer )
+ {
+ free( p_sys );
+ return VLC_ENOMEM;
+ }
+
+ return VLC_SUCCESS;
+}
+
+/*****************************************************************************
+ * Close: frees unused data
+ *****************************************************************************/
+static void Close( vlc_object_t *p_this )
+{
+ demux_t *p_demux = (demux_t*)p_this;
+ demux_sys_t *p_sys = p_demux->p_sys;
+
+ demux_PacketizerDestroy( p_sys->p_packetizer );
+ free( p_sys );
+}
+
+#define ADF_PACKET_SIZE 8192
+
+/*****************************************************************************
+ * Demux: reads and demuxes data packets
+ *****************************************************************************
+ * Returns 0 in case of EOF, 1 otherwise
+ *****************************************************************************/
+static int Demux( demux_t *p_demux )
+{
+ demux_sys_t *p_sys = p_demux->p_sys;
+ block_t *p_block_out;
+
+ block_t *p_block_in = vlc_stream_Block( p_demux->s, ADF_PACKET_SIZE );
+ bool b_eof = p_block_in == NULL;
+
+ if ( p_block_in )
+ {
+ static const unsigned char ADF_XOR_MASK = 34;
+ p_block_in->i_pts = p_block_in->i_dts = p_sys->b_start ? VLC_TS_0 : VLC_TS_INVALID;
+ p_sys->b_start = false;
+ for (size_t i = 0; i < p_block_in->i_buffer; i++)
+ p_block_in->p_buffer[i] ^= ADF_XOR_MASK;
+ }
+
+ while( (p_block_out = p_sys->p_packetizer->pf_packetize(
+ p_sys->p_packetizer, (p_block_in) ? &p_block_in : NULL )) )
+ {
+ while( p_block_out )
+ {
+ block_t *p_next = p_block_out->p_next;
+
+ p_block_out->p_next = NULL;
+
+ if( p_sys->p_es == NULL )
+ {
+ p_sys->p_packetizer->fmt_out.b_packetized = true;
+ p_sys->p_es = es_out_Add( p_demux->out, &p_sys->p_packetizer->fmt_out);
+ }
+
+ p_sys->i_pts = p_block_out->i_dts;
+
+ /* set PCR */
+ es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block_out->i_dts );
+
+ es_out_Send( p_demux->out, p_sys->p_es, p_block_out );
+
+ p_block_out = p_next;
+ }
+ }
+ return !b_eof;
+}
+
+static int Control( demux_t *p_demux, int i_query, va_list args )
+{
+ if( i_query == DEMUX_SET_TIME )
+ return VLC_EGENERIC;
+ else
+ return demux_vaControlHelper( p_demux->s,
+ 0, -1,
+ 0, 1, i_query, args );
+}
--
2.9.3
More information about the vlc-devel
mailing list