[vlc-devel] [PATCH 20/21] demux/bluray: do not depend on demux_t::s during initialization

Filip Roséen filip at atch.se
Sun Jul 31 22:42:29 CEST 2016


Given that modules with "demux" and "demux_access" now always have an
associated source stream, this module shall not depend on the value of
demux_t::s during initialization.

Instead this patch introduces two different entry points, one for each
type of demuxer, and adds an argument to the original callback to
conditionally enable functionality associated with one, but no the
other.
---
 modules/access/bluray.c | 34 +++++++++++++++++++++++++---------
 1 file changed, 25 insertions(+), 9 deletions(-)

diff --git a/modules/access/bluray.c b/modules/access/bluray.c
index 64dfcb4..cd792ff 100644
--- a/modules/access/bluray.c
+++ b/modules/access/bluray.c
@@ -84,8 +84,16 @@ static const char *const ppsz_region_code_text[] = {
 # define BLURAY_DEMUX
 #endif
 
+typedef enum {
+    DEMUX_TYPE_REGULAR,
+    DEMUX_TYPE_ACCESS
+} demux_type_e;
+
 /* Callbacks */
-static int  blurayOpen (vlc_object_t *);
+static int blurayOpen(vlc_object_t*, demux_type_e e_type );
+static int blurayAccessOpen(vlc_object_t *);
+static int blurayDemuxOpen(vlc_object_t *);
+
 static void blurayClose(vlc_object_t *);
 
 vlc_module_begin ()
@@ -101,7 +109,7 @@ vlc_module_begin ()
 
     add_shortcut("bluray", "file")
 
-    set_callbacks(blurayOpen, blurayClose)
+    set_callbacks(blurayAccessOpen, blurayClose)
 
 #ifdef BLURAY_DEMUX
     /* demux module */
@@ -110,7 +118,7 @@ vlc_module_begin ()
         set_category( CAT_INPUT )
         set_subcategory( SUBCAT_INPUT_DEMUX )
         set_capability( "demux", 5 )
-        set_callbacks( blurayOpen, blurayClose )
+        set_callbacks( blurayDemuxOpen, blurayClose )
 #endif
 
 vlc_module_end ()
@@ -517,8 +525,6 @@ static int blurayReadBlock(void *object, void *buf, int lba, int num_blocks)
     demux_sys_t *p_sys = p_demux->p_sys;
     int result = -1;
 
-    assert(p_demux->s != NULL);
-
     vlc_mutex_lock(&p_sys->read_block_lock);
 
     if (vlc_stream_Seek( p_demux->s, lba * INT64_C(2048) ) == VLC_SUCCESS) {
@@ -616,7 +622,17 @@ bailout:
 /*****************************************************************************
  * blurayOpen: module init function
  *****************************************************************************/
-static int blurayOpen(vlc_object_t *object)
+static int blurayAccessOpen(vlc_object_t* object)
+{
+    return blurayOpen(object, DEMUX_TYPE_ACCESS);
+}
+
+static int blurayDemuxOpen(vlc_object_t* object)
+{
+    return blurayOpen(object, DEMUX_TYPE_REGULAR);
+}
+
+static int blurayOpen(vlc_object_t *object, demux_type_e e_type)
 {
     demux_t *p_demux = (demux_t*)object;
     demux_sys_t *p_sys;
@@ -628,7 +644,7 @@ static int blurayOpen(vlc_object_t *object)
 
     forced = !strcasecmp(p_demux->psz_access, "bluray");
 
-    if (p_demux->s) {
+    if (e_type == DEMUX_TYPE_REGULAR) {
         if (p_demux->psz_access == NULL || !strcasecmp(p_demux->psz_access, "file")) {
             /* use access_demux for local files */
             return VLC_EGENERIC;
@@ -674,7 +690,7 @@ static int blurayOpen(vlc_object_t *object)
 
     /* Open BluRay */
 #ifdef BLURAY_DEMUX
-    if (p_demux->s) {
+    if (e_type == DEMUX_TYPE_REGULAR) {
         i_init_pos = vlc_stream_Tell(p_demux->s);
 
         p_sys->bluray = bd_init();
@@ -845,7 +861,7 @@ error:
         vlc_dialog_display_error(p_demux, _("Blu-ray error"), "%s", error_msg);
     blurayClose(object);
 
-    if (p_demux->s != NULL) {
+    if (e_type == DEMUX_TYPE_ACCESS) {
         /* restore stream position */
         if (vlc_stream_Seek(p_demux->s, i_init_pos) != VLC_SUCCESS) {
             msg_Err(p_demux, "Failed to seek back to stream start");
-- 
2.9.2



More information about the vlc-devel mailing list