[vlc-devel] [RFC] libbluray integration

Rémi Denis-Courmont remi at remlab.net
Thu Jul 8 22:12:05 CEST 2010


Le jeudi 8 juillet 2010 22:56:50 Jean-Baptiste Kempf, vous avez écrit :
> Attached here is a small patch for libbluray integration.
> Libbluray plays non-crypted Blu-Rays.
> 
> This is the first version, rough reviews welcomed.

A review is easier with an inline patch.

+AC_ARG_ENABLE(bluray,
+  AS_HELP_STRING([--enable-bluray],[use library libbluray for Blu-ray disc 
support]))
+if test "${enable_bluray}" != "no"
+then
+    AC_CHECK_HEADERS(libbluray/bluray.h,
+    [ VLC_ADD_PLUGIN([bluray])
+      VLC_ADD_CFLAGS([bluray],[])
+      VLC_ADD_LIBS([bluray],[-lbluray]) ])
+fi

Please use pkg-config. If it's not available, the library needs fixing.

@@ -4714,6 +4727,7 @@ AC_CONFIG_FILES([
   modules/access/Makefile
   modules/access/bd/Makefile
   modules/access/bda/Makefile
+  modules/access/bluray/Makefile

Why yet another directory? More directories = slower build.

+    add_string("debug-mask", "0x0000", NULL,
+	       DEBUGMASK_TEXT, DEBUGMASK_LONGTEXT, false);

Uh? Does VLC not parse hexadecimal values out-of-the box?

+    set_capability( "access", 60 )
+    add_shortcut( "bluray" )
+    add_shortcut( "file" )

Yet another hack on the file scheme :(

+struct access_sys_t
+{
+    void *dl_handle;

Not used anywhere. Move this to another patch if you need to.

+    void *bluray;

Can't this library use typedefs?

+    int i_bd_delay;
+};

+static int blurayOpen( vlc_object_t *object )
+{
+    char *debug_mask = NULL;
+    char *pos_title;
+    int i_title = 0;
+    access_t *p_access = (access_t*)object;
+    access_sys_t *p_sys;
+    char bd_path[512];
+
+    msg_Warn( p_access, "blurayOpen :)" );

Spam.

+    if( !p_access->psz_location || !*p_access->psz_location ) {
+        msg_Warn( p_access, "blurayOpen - not selected" );

Spam.

+        return VLC_EGENERIC;
+    }
+
+    var_Create( p_access, "bluray-caching", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT 
);
+    var_Create( p_access, "debug-mask", VLC_VAR_STRING|VLC_VAR_DOINHERIT );

var_Inherit*???

+    debug_mask = var_GetString(p_access, "debug-mask");
+    if ( debug_mask ) {
+        setenv("BD_DEBUG_MASK", debug_mask, 1);
+    }

setenv()? Is this a second degree joke?

+    /* init access fields */
+    access_InitFields(p_access);
+
+    /* register callback function for communication */
+    ACCESS_SET_CALLBACKS(blurayRead, NULL, blurayControl, bluraySeek);
+
+    p_access->p_sys = p_sys = malloc(sizeof(access_sys_t));
+    if (!p_sys) {

unlikely()

+        msg_Warn( p_access, "cannot alloc access_sys memory");

Please no.

+        return VLC_ENOMEM;
+    }

+    /* store current bd_path */
+    strncpy(bd_path, p_access->psz_location, sizeof bd_path);

strdup()

+    if ( (pos_title = strrchr(bd_path, ':')) ) {
+        /* found character ':' for title information */
+        pos_title[0] = '\0';
+        i_title = atoi(pos_title + 1);
+    }
+
+    p_sys->bluray = bd_open(bd_path, NULL);
+    if ( p_sys->bluray == NULL ) {
+        return VLC_EGENERIC;

Memory leak.

+    }
+
+    /* set start title number */
+    if ( bluraySetTitle(p_access, i_title) != VLC_SUCCESS ) {
+        return VLC_EGENERIC;

Memory leak.

+    }
+
+    p_sys->i_bd_delay = var_GetInteger(p_access, "bluray-caching");
+
+    return VLC_SUCCESS;
+}
+
+
+
+/*****************************************************************************
+ * blurayClose: module destroy function
+ 
*****************************************************************************/
+static void blurayClose( vlc_object_t *object )
+{
+    access_t *p_access = (access_t*)object;
+    access_sys_t *p_sys = p_access->p_sys;
+
+    msg_Warn( p_access, "close bluray");

Spam.

+    if ( p_sys->bluray != NULL ) {

Useless check.

+        bd_close(p_sys->bluray);
+    }
+}
+
+
+/*****************************************************************************
+ * bluraySetTitle: select new BD title
+ 
*****************************************************************************/
+static int bluraySetTitle(access_t *p_access, int i_title)
+{
+    access_sys_t *p_sys = p_access->p_sys;
+ 
+    /* select blue ray title */
+    if ( bd_select_title(p_access->p_sys->bluray, i_title) == 0 ) {
+        msg_Err( p_access, "cannot select bd title '%d'", p_access-
>info.i_title);
+        return VLC_EGENERIC;
+    }
+ 
+    /* read title length and init some values */
+    p_access->info.i_title = i_title;
+    p_access->info.i_size = bd_get_title_size(p_sys->bluray);
+    p_access->info.i_pos = 0;
+    p_access->info.b_eof = false;
+    p_access->info.i_seekpoint = 0;
+
+    return VLC_SUCCESS;
+}
+
+
+/*****************************************************************************
+ * blurayControl: handle the controls
+ 
*****************************************************************************/
+static int blurayControl(access_t *p_access, int query, va_list args)
+{
+    access_sys_t *p_sys = p_access->p_sys;
+    bool     *pb_bool;
+    int64_t  *pi_64;
+    uint32_t pos;
+
+    switch (query) {
+        case ACCESS_CAN_SEEK:
+        case ACCESS_CAN_FASTSEEK: 
+        case ACCESS_CAN_PAUSE:
+             pb_bool = (bool*)va_arg( args, bool * );
+             *pb_bool = true;
+             break;
+
+        case ACCESS_CAN_CONTROL_PACE:
+            pb_bool = (bool*)va_arg( args, bool* );
+            *pb_bool = true;
+            break;
+
+        case ACCESS_GET_PTS_DELAY:
+            pi_64 = (int64_t*)va_arg( args, int64_t * );
+            *pi_64 = p_sys->i_bd_delay;
+            break;
+
+        case ACCESS_SET_PAUSE_STATE:
+            /* Nothing to do */
+            msg_Warn( p_access, "set pause state");

Spam.

+            break;
+
+        case ACCESS_SET_TITLE:
+
+            break;
+
+        case ACCESS_SET_SEEKPOINT:
+            pos = va_arg( args, uint32_t );
+            msg_Warn( p_access, "set seek position '%d'", pos);

Spam??

+            break;
+
+        case ACCESS_GET_META:
+            return VLC_EGENERIC;
+            break;
+
+        case ACCESS_GET_TITLE_INFO:
+        case ACCESS_SET_PRIVATE_ID_STATE:
+        case ACCESS_GET_CONTENT_TYPE:
+            return VLC_EGENERIC;

Those cases could be collected.

+
+        default:
+            msg_Warn( p_access, "unimplemented query (%d) in control", query 
);
+            return VLC_EGENERIC;
+    }
+
+    return VLC_SUCCESS;
+}
+
+
+/*****************************************************************************
+ * bluraySeek: seek to the given position
+ 
*****************************************************************************/
+static int bluraySeek(access_t *p_access, uint64_t position)
+{
+    access_sys_t *p_sys = p_access->p_sys;
+
+    p_access->info.i_pos = bd_seek(p_sys->bluray, position);
+    p_access->info.b_eof = false;
+
+    return VLC_SUCCESS;
+}
+
+
+/*****************************************************************************
+ * blurayRead: read BD data into buffer
+ 
*****************************************************************************/
+static ssize_t blurayRead(access_t *p_access, uint8_t *data, size_t size)
+{
+    access_sys_t *p_sys = p_access->p_sys;
+    int nread;
+
+    if (p_access->info.b_eof) {
+        return 0;
+    }
+
+    /* read data into buffer with given length */
+    nread = bd_read(p_sys->bluray, data, size);
+
+    if( nread == 0 ) {
+        p_access->info.b_eof = true;
+    }
+    else if( nread > 0 ) {
+        p_access->info.i_pos += nread;
+    }
+
+    return nread;
+}
+  
+
-- 
1.7.1


-- 
Rémi Denis-Courmont
http://www.remlab.net/
http://fi.linkedin.com/in/remidenis



More information about the vlc-devel mailing list