stream: replace input_thread_t by input_item_t
[vlc.git] / modules / demux / playlist / bdmv.c
blob7eb5fa25a2a2e4279938742d8ad058df9904ec30
1 /*****************************************************************************
2 * bdmv.c: Dummy bdmv demux - opens BluRays rips via index.bdmv
3 *****************************************************************************
4 * Copyright (C) 2018 VLC authors and VideoLAN
5 * $Id$
7 * Authors: Shaya Potter <spotter@gmail.com>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
25 * Preamble
26 *****************************************************************************/
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
31 #include <vlc_common.h>
32 #include <vlc_access.h>
33 #include <vlc_url.h>
34 #include <assert.h>
36 #include "playlist.h"
38 /*****************************************************************************
39 * Local prototypes
40 *****************************************************************************/
41 static int ReadBR( stream_t *, input_item_node_t * );
43 static const char *StreamLocation( const stream_t *s )
45 return s->psz_filepath ? s->psz_filepath : s->psz_url;
48 /*****************************************************************************
49 * Import_BDMV: main import function
50 *****************************************************************************/
51 int Import_BDMV( vlc_object_t *p_this )
53 stream_t *p_stream = (stream_t *)p_this;
55 CHECK_FILE(p_stream);
57 if( !stream_HasExtension( p_stream, ".BDMV" ) )
58 return VLC_EGENERIC;
60 const char *psz_location = StreamLocation( p_stream );
61 if( psz_location == NULL )
62 return VLC_EGENERIC;
64 size_t len = strlen( psz_location );
65 if( len < 15 )
66 return VLC_EGENERIC;
68 const char *psz_probe;
69 const char *psz_file = &psz_location[len - 10];
70 /* Valid filenames are :
71 * - INDEX.BDMV
73 if( !strncasecmp( psz_file, "INDEX", 5 ) )
75 psz_probe = "INDX0200";
76 p_stream->pf_readdir = ReadBR;
78 else
79 return VLC_EGENERIC;
81 const uint8_t *p_peek;
82 ssize_t i_peek = vlc_stream_Peek( p_stream->s, &p_peek, 8 );
83 if( i_peek < 8 || memcmp( p_peek, psz_probe, 8 ) )
84 return VLC_EGENERIC;
86 p_stream->pf_control = access_vaDirectoryControlHelper;
88 return VLC_SUCCESS;
91 static int ReadBR( stream_t *p_stream, input_item_node_t *node )
93 const char *psz_loc = StreamLocation(p_stream);
95 // 10 character in INDEX.BDMV, 5 character in BDMV/, subtract 15
96 char *psz_url = strndup( psz_loc, strlen( psz_loc) - 15 );
97 if( !psz_url )
98 return VLC_ENOMEM;
100 input_item_t *p_input = input_item_New( psz_url, psz_url );
101 input_item_AddOption( p_input, "demux=bluray", VLC_INPUT_OPTION_TRUSTED );
102 input_item_node_AppendItem( node, p_input );
103 input_item_Release( p_input );
105 free( psz_url );
107 return VLC_SUCCESS;