]> git.sesse.net Git - vlc/blobdiff - modules/access/bd/bd.c
Use VLC_CODEC_S24(B|L)32
[vlc] / modules / access / bd / bd.c
index d4c36fce300a79bd762ca12b7168cc24a3d8ef4f..9c598e24f3b9bbd41e32499c4621741034b42d2a 100644 (file)
@@ -1,24 +1,24 @@
 /*****************************************************************************
  * bd.c: BluRay Disc support (uncrypted)
  *****************************************************************************
- * Copyright (C) 2009 the VideoLAN team
+ * Copyright (C) 2009 VLC authors and VideoLAN
  * $Id$
  *
  * Authors: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * 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 General Public License for more details.
+ * 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 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.
+ * 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.
  *****************************************************************************/
 
 /*****************************************************************************
 # include "config.h"
 #endif
 
-#ifdef HAVE_SYS_STAT_H
-#   include <sys/stat.h>
-#endif
 #include <limits.h>
+#include <sys/stat.h>
 
 #include <vlc_common.h>
 #include <vlc_plugin.h>
 #include <vlc_input.h>
 #include <vlc_access.h>
 #include <vlc_demux.h>
-#include <vlc_charset.h>
+#include <vlc_fs.h>
 #include <vlc_bits.h>
 #include <assert.h>
 
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
-#define CACHING_TEXT N_("Caching value in ms")
-#define CACHING_LONGTEXT N_( \
-    "Caching value for BDs. This "\
-    "value should be set in milliseconds." )
-
 static int  Open ( vlc_object_t * );
 static void Close( vlc_object_t * );
 
 vlc_module_begin ()
     set_shortname( N_("BD") )
-    set_description( N_("BD Input") )
+    set_description( N_("Blu-Ray Disc Input") )
     set_category( CAT_INPUT )
     set_subcategory( SUBCAT_INPUT_ACCESS )
-    add_integer( "bd-caching", DEFAULT_PTS_DELAY / 1000, NULL,
-        CACHING_TEXT, CACHING_LONGTEXT, true );
     set_capability( "access_demux", 60 )
-    add_shortcut( "bd" )
+    add_shortcut( "bd", "file" )
     set_callbacks( Open, Close )
 vlc_module_end ()
 
@@ -83,6 +74,7 @@ vlc_module_end ()
 struct demux_sys_t
 {
     char *psz_base;
+    bool b_shortname;
 
     /* */
     int       i_mpls;
@@ -118,7 +110,7 @@ struct demux_sys_t
 static int Control( demux_t *, int, va_list );
 static int Demux( demux_t * );
 
-static char *FindPathBase( const char * );
+static char *FindPathBase( const char *, bool *pb_shortname );
 
 static int LoadPlaylist( demux_t * );
 static int LoadClip( demux_t * );
@@ -151,11 +143,16 @@ static int Open( vlc_object_t *p_this )
     demux_t     *p_demux = (demux_t*)p_this;
     demux_sys_t *p_sys;
 
-    if( *p_demux->psz_access && strcmp( p_demux->psz_access, "bd" ) )
+    if( p_demux->psz_file == NULL )
+        return VLC_EGENERIC;
+    if( *p_demux->psz_access &&
+        strcmp( p_demux->psz_access, "bd" ) &&
+        strcmp( p_demux->psz_access, "file" ) )
         return VLC_EGENERIC;
 
     /* */
-    char *psz_base = FindPathBase( p_demux->psz_path );
+    bool b_shortname;
+    char *psz_base = FindPathBase( p_demux->psz_file, &b_shortname );
     if( !psz_base )
         return VLC_EGENERIC;
 
@@ -166,6 +163,7 @@ static int Open( vlc_object_t *p_this )
     if( !p_sys )
         return VLC_EGENERIC;
     p_sys->psz_base = psz_base;
+    p_sys->b_shortname = b_shortname;
     TAB_INIT( p_sys->i_mpls, p_sys->pp_mpls );
     TAB_INIT( p_sys->i_clpi, p_sys->pp_clpi );
     TAB_INIT( p_sys->i_title, p_sys->pp_title );
@@ -347,7 +345,9 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
     case DEMUX_GET_PTS_DELAY:
     {
         int64_t *pi_delay = (int64_t*)va_arg( args, int64_t * );
-        *pi_delay = var_GetInteger( p_demux, "bd-caching" ) * INT64_C(1000);
+
+        *pi_delay =
+            INT64_C(1000) * var_InheritInteger( p_demux, "disc-caching" );
         return VLC_SUCCESS;
     }
 
@@ -409,7 +409,7 @@ static int Demux( demux_t *p_demux )
     /* XXX
      * we ensure that the TS packet start at the begining of the buffer,
      * it ensure proper TS parsing */
-    block_t *p_block = block_New( p_demux, i_packets * BD_TS_PACKET_SIZE + BD_TS_PACKET_HEADER );
+    block_t *p_block = block_Alloc( i_packets * BD_TS_PACKET_SIZE + BD_TS_PACKET_HEADER );
     if( !p_block )
         return -1;
 
@@ -616,7 +616,8 @@ static int SetPlayItem( demux_t *p_demux, int i_mpls, int i_play_item )
     if( !b_same_clpi )
     {
         char *psz_m2ts;
-        if( asprintf( &psz_m2ts, "%s/STREAM/%05d.m2ts", p_sys->psz_base, p_mpls_clpi->i_id ) < 0 )
+        if( asprintf( &psz_m2ts, "%s/STREAM/%05d.%s",
+                      p_sys->psz_base, p_mpls_clpi->i_id, p_sys->b_shortname ? "MTS" : "m2ts" ) < 0 )
             return VLC_EGENERIC;
 
         p_m2ts = stream_UrlNew( p_demux, psz_m2ts );
@@ -927,8 +928,26 @@ static void ReorderPlaylist( demux_t *p_demux )
 /*****************************************************************************
  * Helpers:
  *****************************************************************************/
+static int CheckFileList( const char *psz_base, const char *ppsz_name[] )
+{
+    for( int i = 0; ppsz_name[i] != NULL ; i++ )
+    {
+        struct stat s;
+        char *psz_tmp;
+
+        if( asprintf( &psz_tmp, "%s/%s", psz_base, ppsz_name[i] ) < 0 )
+            return VLC_EGENERIC;
+
+        bool b_ok = vlc_stat( psz_tmp, &s ) == 0 && S_ISREG( s.st_mode );
+
+        free( psz_tmp );
+        if( !b_ok )
+            return VLC_EGENERIC;
+    }
+    return VLC_SUCCESS;
+}
 /* */
-static char *FindPathBase( const char *psz_path )
+static char *FindPathBase( const char *psz_path, bool *pb_shortname )
 {
     struct stat s;
     char *psz_tmp;
@@ -943,13 +962,13 @@ static char *FindPathBase( const char *psz_path )
         psz_base[strlen(psz_base)-1] = '\0';
 
     /* */
-    if( utf8_stat( psz_base, &s ) || !S_ISDIR( s.st_mode ) )
+    if( vlc_stat( psz_base, &s ) || !S_ISDIR( s.st_mode ) )
         goto error;
 
     /* Check BDMV */
     if( asprintf( &psz_tmp, "%s/BDMV", psz_base ) < 0 )
         goto error;
-    if( !utf8_stat( psz_tmp, &s ) && S_ISDIR( s.st_mode ) )
+    if( !vlc_stat( psz_tmp, &s ) && S_ISDIR( s.st_mode ) )
     {
         free( psz_base );
         psz_base = psz_tmp;
@@ -960,26 +979,23 @@ static char *FindPathBase( const char *psz_path )
     }
 
     /* Check presence of mandatory files */
-    for( int i = 0;; i++ )
+    static const char *ppsz_name_long[] = {
+        "index.bdmv",
+        "MovieObject.bdmv",
+        NULL
+    };
+    static const char *ppsz_name_short[] = {
+        "INDEX.BDM",
+        "MOVIEOBJ.BDM",
+        NULL
+    };
+    *pb_shortname = false;
+    if( CheckFileList( psz_base, ppsz_name_long ) )
     {
-        static const char *ppsz_name[] = {
-            "index.bdmv",
-            "MovieObject.bdmv",
-            NULL
-        };
-        if( !ppsz_name[i] )
-            break;
-
-        if( asprintf( &psz_tmp, "%s/%s", psz_base, ppsz_name[i] ) < 0 )
-            goto error;
-
-        bool b_ok = utf8_stat( psz_tmp, &s ) == 0 && S_ISREG( s.st_mode );
-
-        free( psz_tmp );
-        if( !b_ok )
+        if( CheckFileList( psz_base, ppsz_name_short ) )
             goto error;
+        *pb_shortname = true;
     }
-
     return psz_base;
 
 error:
@@ -1006,11 +1022,16 @@ static block_t *LoadBlock( demux_t *p_demux, const char *psz_name )
 }
 
 /* */
-static int FilterMpls( const char *psz_name )
+static int FilterMplsLong( const char *psz_name )
 {
     return strlen( psz_name ) == strlen( "xxxxx.mpls" ) &&
            !strcmp( &psz_name[5], ".mpls" );
 }
+static int FilterMplsShort( const char *psz_name )
+{
+    return strlen( psz_name ) == strlen( "xxxxx.MPL" ) &&
+           !strcmp( &psz_name[5], ".MPL" );
+}
 
 static void LoadMpls( demux_t *p_demux, const char *psz_name, int i_id )
 {
@@ -1095,11 +1116,16 @@ error:
 }
 
 /* */
-static int FilterClpi( const char *psz_name )
+static int FilterClpiLong( const char *psz_name )
 {
     return strlen( psz_name ) == strlen( "xxxxx.clpi" ) &&
            !strcmp( &psz_name[5], ".clpi" );
 }
+static int FilterClpiShort( const char *psz_name )
+{
+    return strlen( psz_name ) == strlen( "xxxxx.CPI" ) &&
+           !strcmp( &psz_name[5], ".CPI" );
+}
 
 static void LoadClpi( demux_t *p_demux, const char *psz_name, int i_id )
 {
@@ -1180,7 +1206,7 @@ static int Load( demux_t *p_demux,
 
     char **ppsz_list;
 
-    int i_list = utf8_scandir( psz_playlist, &ppsz_list, pf_filter, ScanSort );
+    int i_list = vlc_scandir( psz_playlist, &ppsz_list, pf_filter, ScanSort );
 
     for( int i = 0; i < i_list; i++ )
     {
@@ -1205,11 +1231,13 @@ static int Load( demux_t *p_demux,
 
 static int LoadPlaylist( demux_t *p_demux )
 {
-    return Load( p_demux, "PLAYLIST", FilterMpls, LoadMpls );
+    return Load( p_demux, "PLAYLIST",
+                 p_demux->p_sys->b_shortname ? FilterMplsShort : FilterMplsLong, LoadMpls );
 }
 static int LoadClip( demux_t *p_demux )
 {
-    return Load( p_demux, "CLIPINF", FilterClpi, LoadClpi );
+    return Load( p_demux, "CLIPINF",
+                 p_demux->p_sys->b_shortname ? FilterClpiShort : FilterClpiLong, LoadClpi );
 }
 
 /* */
@@ -1270,7 +1298,7 @@ static es_out_id_t *EsOutAdd( es_out_t *p_out, const es_format_t *p_fmt )
         break;
     }
     if( fmt.i_priority < 0 )
-        msg_Dbg( p_demux, "Hidding one stream (pid=%d)", fmt.i_id );
+        msg_Dbg( p_demux, "Hiding one stream (pid=%d)", fmt.i_id );
 
     /* */
     es_out_id_t *p_es = es_out_Add( p_demux->out, &fmt );
@@ -1309,7 +1337,6 @@ static es_out_t *EsOutNew( demux_t *p_demux )
     p_out->pf_del     = EsOutDel;
     p_out->pf_control = EsOutControl;
     p_out->pf_destroy = EsOutDestroy;
-    p_out->b_sout = false;
 
     p_out->p_sys = p_sys = malloc( sizeof(*p_sys) );
     if( !p_sys )