[vlc-devel] [PATCH 04/12] bluray: Preparing menu handling.

Hugo Beauzée-Luyssen beauze.h at gmail.com
Sun Jan 22 00:30:59 CET 2012


---
 modules/access/bluray.c |   72 ++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 59 insertions(+), 13 deletions(-)

diff --git a/modules/access/bluray.c b/modules/access/bluray.c
index 179c51a..94840f1 100644
--- a/modules/access/bluray.c
+++ b/modules/access/bluray.c
@@ -35,11 +35,16 @@
 
 #include <libbluray/bluray.h>
 #include <libbluray/meta_data.h>
+#include <libbluray/overlay.h>
 
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
 
+#define BD_MENU_TEXT        N_( "Bluray menus" )
+#define BD_MENU_LONGTEXT    N_( "Use bluray menus. If disabled, "\
+                                "the movie will start directly" )
+
 /* Callbacks */
 static int  blurayOpen ( vlc_object_t * );
 static void blurayClose( vlc_object_t * );
@@ -51,6 +56,7 @@ vlc_module_begin ()
     set_category( CAT_INPUT )
     set_subcategory( SUBCAT_INPUT_ACCESS )
     set_capability( "access_demux", 200)
+    add_bool( "bluray-menu", true, BD_MENU_TEXT, BD_MENU_LONGTEXT, false )
 
     add_shortcut( "bluray", "file" )
 
@@ -75,7 +81,8 @@ struct demux_sys_t
  * Local prototypes
  *****************************************************************************/
 static int     blurayControl(demux_t *, int, va_list);
-static int     blurayDemux  (demux_t *);
+static int     blurayDemux(demux_t *);
+static int     blurayDemuxMenu(demux_t *);
 
 static int     blurayInitTitles(demux_t *p_demux );
 static int     bluraySetTitle(demux_t *p_demux, int i_title);
@@ -175,17 +182,26 @@ static int blurayOpen( vlc_object_t *object )
     //Initialize the event queue, so we can receive then in Read later.
     bd_get_event( p_sys->bluray, NULL );
 
-    /* get title request */
-    if ((pos_title = strrchr(bd_path, ':'))) {
-        /* found character ':' for title information */
-        *(pos_title++) = '\0';
-        i_title = atoi(pos_title);
+    bool    b_menu = var_CreateGetBool( p_demux, "bluray-menu" );
+    if ( b_menu )
+    {
+        //Starting playback from main menu
+        bd_play( p_sys->bluray );
     }
+    else
+    {
+        /* get title request */
+        if ((pos_title = strrchr(bd_path, ':'))) {
+            /* found character ':' for title information */
+            *(pos_title++) = '\0';
+            i_title = atoi(pos_title);
+        }
 
-    /* set start title number */
-    if (bluraySetTitle(p_demux, i_title) != VLC_SUCCESS) {
-        msg_Err( p_demux, "Could not set the title %d", i_title );
-        goto error;
+        /* set start title number */
+        if (bluraySetTitle(p_demux, i_title) != VLC_SUCCESS) {
+            msg_Err( p_demux, "Could not set the title %d", i_title );
+            goto error;
+        }
     }
 
     p_sys->p_parser   = stream_DemuxNew(p_demux, "ts", p_demux->out);
@@ -195,7 +211,7 @@ static int blurayOpen( vlc_object_t *object )
     }
 
     p_demux->pf_control = blurayControl;
-    p_demux->pf_demux   = blurayDemux;
+    p_demux->pf_demux   = b_menu ? blurayDemuxMenu : blurayDemux;
 
     return VLC_SUCCESS;
 
@@ -486,18 +502,48 @@ static int blurayDemux(demux_t *p_demux)
     if (!p_block) {
         return -1;
     }
+    int nread;
 
+    //Handle events first.
     blurayHandleEvents( p_demux );
-    int nread = bd_read(p_sys->bluray, p_block->p_buffer,
+
+    nread = bd_read(p_sys->bluray, p_block->p_buffer,
                         NB_TS_PACKETS * BD_TS_PACKET_SIZE);
+
     if (nread < 0) {
         block_Release(p_block);
         return nread;
     }
-
     p_block->i_buffer = nread;
 
     stream_DemuxSend( p_sys->p_parser, p_block );
+    return 1;
+}
+
+static int blurayDemuxMenu( demux_t *p_demux )
+{
+    demux_sys_t *p_sys = p_demux->p_sys;
+    BD_EVENT    e;
 
+    block_t     *p_block = block_New(p_demux, NB_TS_PACKETS * (int64_t)BD_TS_PACKET_SIZE);
+    int         nread = bd_read_ext( p_sys->bluray, p_block->p_buffer,
+                                      NB_TS_PACKETS * BD_TS_PACKET_SIZE, &e );
+    if ( nread == 0 ) //We need to handle events before doing anything
+    {
+        if ( e.event == BD_EVENT_NONE )
+            msg_Info( p_demux, "We reached the end of a title" );
+        else
+            blurayHandleEvent( p_demux, &e );
+        block_Release(p_block);
+        return 1;
+    }
+    if (nread < 0)
+    {
+        block_Release(p_block);
+        return nread;
+    }
+    p_block->i_buffer = nread;
+
+    stream_DemuxSend( p_sys->p_parser, p_block );
     return 1;
 }
-- 
1.7.8.4




More information about the vlc-devel mailing list