[vlc-devel] [PATCH 04/11] chromecast: add a demux-filter to display better time
Steve Lhomme
robux4 at videolabs.io
Mon May 2 18:24:03 CEST 2016
Will also wait for the Chromecast to be ready to receive data before sendimg them
---
modules/MODULES_LIST | 1 +
modules/stream_out/Makefile.am | 5 +
modules/stream_out/chromecast/chromecast.h | 4 +
modules/stream_out/chromecast/chromecast_common.h | 45 ++++++++
modules/stream_out/chromecast/chromecast_ctrl.cpp | 8 ++
modules/stream_out/chromecast/chromecast_demux.cpp | 114 +++++++++++++++++++++
6 files changed, 177 insertions(+)
create mode 100644 modules/stream_out/chromecast/chromecast_common.h
create mode 100644 modules/stream_out/chromecast/chromecast_demux.cpp
diff --git a/modules/MODULES_LIST b/modules/MODULES_LIST
index 0e0ceab..e2a61ed 100644
--- a/modules/MODULES_LIST
+++ b/modules/MODULES_LIST
@@ -102,6 +102,7 @@ $Id$
* decomp: Decompression module
* deinterlace: naive deinterlacing filter
* demux_cdg: Demuxer for CD-G files (Karaoke)
+ * demux_chromecast: Internal demux filter to report the playback time on the Chromecast
* demux_stl: EBU STL subtitles demuxer
* demuxdump: Pseudo-demuxer that dumps the stream
* diracsys: BBC Dirac demuxer
diff --git a/modules/stream_out/Makefile.am b/modules/stream_out/Makefile.am
index 361c2a1..a598bcc 100644
--- a/modules/stream_out/Makefile.am
+++ b/modules/stream_out/Makefile.am
@@ -80,6 +80,10 @@ SUFFIXES += .proto .pb.cc
%.pb.h %.pb.cc: %.proto
$(PROTOC) --cpp_out=. -I$(srcdir) $<
+libdemux_chromecast_plugin_la_SOURCES = stream_out/chromecast/chromecast_demux.cpp stream_out/chromecast/chromecast.h \
+ stream_out/chromecast/chromecast_common.h
+libdemux_chromecast_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) -Istream_out/chromecast
+
libstream_out_chromecast_plugin_la_SOURCES = stream_out/chromecast/cast.cpp stream_out/chromecast/chromecast.h \
stream_out/chromecast/cast_channel.proto \
stream_out/chromecast/chromecast_common.h stream_out/chromecast/chromecast_ctrl.cpp \
@@ -93,5 +97,6 @@ if ENABLE_SOUT
if BUILD_CHROMECAST
BUILT_SOURCES += stream_out/chromecast/cast_channel.pb.h
sout_LTLIBRARIES += libstream_out_chromecast_plugin.la
+demux_LTLIBRARIES += libdemux_chromecast_plugin.la
endif
endif
diff --git a/modules/stream_out/chromecast/chromecast.h b/modules/stream_out/chromecast/chromecast.h
index c1684c9..c37728d 100644
--- a/modules/stream_out/chromecast/chromecast.h
+++ b/modules/stream_out/chromecast/chromecast.h
@@ -36,6 +36,7 @@
#include <sstream>
#include "cast_channel.pb.h"
+#include "chromecast_common.h"
#define PACKET_HEADER_LEN 4
@@ -178,6 +179,9 @@ private:
bool has_input;
static void* ChromecastThread(void* p_data);
+
+ /* shared structure with the demux-filter */
+ chromecast_common common;
};
#endif /* VLC_CHROMECAST_H */
diff --git a/modules/stream_out/chromecast/chromecast_common.h b/modules/stream_out/chromecast/chromecast_common.h
new file mode 100644
index 0000000..a0d87b5
--- /dev/null
+++ b/modules/stream_out/chromecast/chromecast_common.h
@@ -0,0 +1,45 @@
+/*****************************************************************************
+ * chromecast.cpp: Chromecast common code between modules for vlc
+ *****************************************************************************
+ * Copyright © 2016 VideoLAN
+ *
+ * Authors: Adrien Maglo <magsoft at videolan.org>
+ * Jean-Baptiste Kempf <jb at videolan.org>
+ * Steve Lhomme <robux4 at videolabs.io>
+ *
+ * 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.
+ *****************************************************************************/
+
+#ifndef VLC_CHROMECAST_COMMON_H
+#define VLC_CHROMECAST_COMMON_H
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+static const char *CC_SHARED_VAR_NAME = "cc_sout";
+
+typedef struct
+{
+ void *p_opaque;
+
+} chromecast_common;
+
+# ifdef __cplusplus
+}
+# endif
+
+#endif // VLC_CHROMECAST_COMMON_H
+
diff --git a/modules/stream_out/chromecast/chromecast_ctrl.cpp b/modules/stream_out/chromecast/chromecast_ctrl.cpp
index 7bfaca4..c2bec9e 100644
--- a/modules/stream_out/chromecast/chromecast_ctrl.cpp
+++ b/modules/stream_out/chromecast/chromecast_ctrl.cpp
@@ -115,6 +115,12 @@ intf_sys_t::intf_sys_t(vlc_object_t * const p_this, int port, std::string device
vlc_mutex_init_recursive(&lock);
vlc_cond_init(&loadCommandCond);
+ common.p_opaque = this;
+
+ assert( var_Type( p_module->p_parent->p_parent, CC_SHARED_VAR_NAME) == 0 );
+ if (var_Create( p_module->p_parent->p_parent, CC_SHARED_VAR_NAME, VLC_VAR_ADDRESS ) == VLC_SUCCESS )
+ var_SetAddress( p_module->p_parent->p_parent, CC_SHARED_VAR_NAME, &common );
+
// Start the Chromecast event thread.
if (vlc_clone(&chromecastThread, ChromecastThread, this,
VLC_THREAD_PRIORITY_LOW))
@@ -127,6 +133,8 @@ intf_sys_t::~intf_sys_t()
{
setHasInput( false );
+ var_Destroy( p_module->p_parent->p_parent, CC_SHARED_VAR_NAME );
+
switch ( conn_status )
{
case CHROMECAST_APP_STARTED:
diff --git a/modules/stream_out/chromecast/chromecast_demux.cpp b/modules/stream_out/chromecast/chromecast_demux.cpp
new file mode 100644
index 0000000..c39691f
--- /dev/null
+++ b/modules/stream_out/chromecast/chromecast_demux.cpp
@@ -0,0 +1,114 @@
+/*****************************************************************************
+ * chromecast.cpp: Chromecast demux filter module for vlc
+ *****************************************************************************
+ * Copyright © 2015 VideoLAN
+ *
+ * Authors: Steve Lhomme <robux4 at videolabs.io>
+ *
+ * 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 "chromecast_common.h"
+
+#include <new>
+
+struct demux_filter_sys_t
+{
+ demux_filter_sys_t(demux_filter_t * const demux, chromecast_common * const renderer)
+ :p_demux(demux)
+ ,p_renderer(renderer)
+ {
+ }
+
+ ~demux_filter_sys_t()
+ {
+ }
+
+ int Demux()
+ {
+ return demux_FilterDemux( p_demux );
+ }
+
+protected:
+ demux_filter_t * const p_demux;
+ chromecast_common * const p_renderer;
+};
+
+static int Demux( demux_filter_t *p_demux_filter )
+{
+ demux_filter_sys_t *p_sys = p_demux_filter->p_sys;
+
+ return p_sys->Demux();
+}
+
+static int Control( demux_filter_t *p_demux_filter, int i_query, va_list args)
+{
+ return demux_FilterControl( p_demux_filter, i_query, args );
+}
+
+int Open(vlc_object_t *p_this)
+{
+ demux_filter_t *p_demux = reinterpret_cast<demux_filter_t*>(p_this);
+ if ( unlikely( p_demux->p_demux == NULL ) )
+ return VLC_EBADVAR;
+
+ chromecast_common *p_renderer = reinterpret_cast<chromecast_common *>(
+ var_InheritAddress( p_demux->p_demux, CC_SHARED_VAR_NAME ) );
+ if ( p_renderer == NULL )
+ {
+ msg_Warn( p_this, "using Chromecast demuxer with no sout" );
+ return VLC_ENOOBJ;
+ }
+
+ demux_filter_sys_t *p_sys = new(std::nothrow) demux_filter_sys_t( p_demux, p_renderer );
+ if (unlikely(p_sys == NULL))
+ return VLC_ENOMEM;
+
+ p_demux->pf_demux = Demux;
+ p_demux->pf_control = Control;
+
+ p_demux->p_sys = p_sys;
+ return VLC_SUCCESS;
+}
+
+void Close(vlc_object_t *p_this)
+{
+ demux_filter_t *p_demux = reinterpret_cast<demux_filter_t*>(p_this);
+ demux_filter_sys_t *p_sys = p_demux->p_sys;
+
+ delete p_sys;
+}
+
+vlc_module_begin ()
+ set_shortname( "cc_demux" )
+ set_category( CAT_INPUT )
+ set_subcategory( SUBCAT_INPUT_DEMUX )
+ set_description( N_( "chromecast demux wrapper" ) )
+ set_capability( "demux_filter", 0 )
+ add_shortcut( "cc_demux" )
+ set_callbacks( Open, Close )
+vlc_module_end ()
--
2.7.0
More information about the vlc-devel
mailing list