Commit 51e76e12 authored by Gildas Bazin's avatar Gildas Bazin

* modules/access/dvdread, modules/access/dvdread.c:

  + major rewrite of the dvdread module.
  + dvdread is now an access_demux module.
parent 9eb3e68f
......@@ -1211,71 +1211,70 @@ if test "${enable_livedotcom}" = "yes"; then
fi
fi
dnl
dnl dnl
dnl dnl dvdread module: check for libdvdread
dnl dnl
dnl AC_ARG_ENABLE(dvdread,
dnl [ --enable-dvdread dvdread input module (default disabled)])
dnl if test "${enable_dvdread}" != "no"
dnl then
dnl AC_ARG_WITH(dvdread,
dnl [ --with-dvdread=PATH libdvdread headers and libraries])
dnl AC_ARG_WITH(dvdread-tree,
dnl [ --with-dvdread-tree=PATH libdvdread tree for static linking])
dnl if test -z "${with_dvdread}"
dnl then
dnl if test -z "${with_dvdread_tree}"
dnl then
dnl AC_CHECK_HEADERS(dvdread/dvd_reader.h,
dnl [ AX_ADD_PLUGINS([dvdread])
dnl AX_ADD_LDFLAGS([dvdread],[-ldvdread ${LDFLAGS_dvdcss}])
dnl ],[
dnl if test -n "${enable_dvdread}"
dnl then
dnl AC_MSG_WARN([Please get libdvdread from http://www.dtek.chalmers.se/groups/dvd/downloads.shtml])
dnl AC_MSG_ERROR([cannot find libdvdread headers])
dnl fi
dnl ])
dnl else
dnl AC_MSG_CHECKING(for libdvdread.a in ${with_dvdread_tree})
dnl real_dvdread_tree="`cd ${with_dvdread_tree} 2>/dev/null && pwd`"
dnl if test -z "${real_dvdread_tree}"
dnl then
dnl dnl The given directory can't be found
dnl AC_MSG_RESULT(no)
dnl AC_MSG_ERROR([cannot cd to ${with_dvdread_tree}])
dnl fi
dnl if test -f "${real_dvdread_tree}/dvdread/.libs/libdvdread.a"
dnl then
dnl dnl Use a custom libdvdread
dnl AC_MSG_RESULT(${real_dvdread_tree}/dvdread/.libs/libdvdread.a)
dnl AX_ADD_BUILTINS([dvdread])
dnl AX_ADD_LDFLAGS([dvdread],[-L${real_dvdread_tree}/dvdread/.libs -ldvdread ${LDFLAGS_dvdcss}])
dnl AX_ADD_CPPFLAGS([dvdread],[-I${real_dvdread_tree}])
dnl else
dnl dnl The given libdvdread wasn't built
dnl AC_MSG_RESULT(no)
dnl AC_MSG_ERROR([cannot find ${real_dvdread_tree}/dvdread/.libs/libdvdread.a, make sure you compiled libdvdread in ${with_dvdread_tree}])
dnl fi
dnl fi
dnl else
dnl AC_MSG_CHECKING(for dvdread headers in ${with_dvdread})
dnl if test -f ${with_dvdread}/include/dvdread/dvd_reader.h
dnl then
dnl dnl Use ${with_dvdread}/include/dvdread/dvd_reader.h
dnl AC_MSG_RESULT(yes)
dnl AX_ADD_PLUGINS([dvdread])
dnl AX_ADD_LDFLAGS([dvdread],[-L${with_dvdread}/lib -ldvdread ${LDFLAGS_dvdcss}])
dnl AX_ADD_CPPFLAGS([dvdread],[-I${with_dvdread}/include])
dnl else
dnl dnl No libdvdread could be found, sorry
dnl AC_MSG_RESULT(no)
dnl AC_MSG_ERROR([cannot find ${with_dvdread}/include/dvdread/dvd_reader.h])
dnl fi
dnl fi
dnl fi
dnl
dnl
dnl dvdread module: check for libdvdread
dnl
AC_ARG_ENABLE(dvdread,
[ --enable-dvdread dvdread input module (default disabled)])
if test "${enable_dvdread}" != "no"
then
AC_ARG_WITH(dvdread,
[ --with-dvdread=PATH libdvdread headers and libraries])
AC_ARG_WITH(dvdread-tree,
[ --with-dvdread-tree=PATH libdvdread tree for static linking])
if test -z "${with_dvdread}"
then
if test -z "${with_dvdread_tree}"
then
AC_CHECK_HEADERS(dvdread/dvd_reader.h,
[ AX_ADD_PLUGINS([dvdread])
AX_ADD_LDFLAGS([dvdread],[-ldvdread ${LDFLAGS_dvdcss}])
],[
if test -n "${enable_dvdread}"
then
AC_MSG_WARN([Please get libdvdread from http://www.dtek.chalmers.se/groups/dvd/downloads.shtml])
AC_MSG_ERROR([cannot find libdvdread headers])
fi
])
else
AC_MSG_CHECKING(for libdvdread.a in ${with_dvdread_tree})
real_dvdread_tree="`cd ${with_dvdread_tree} 2>/dev/null && pwd`"
if test -z "${real_dvdread_tree}"
then
dnl The given directory can't be found
AC_MSG_RESULT(no)
AC_MSG_ERROR([cannot cd to ${with_dvdread_tree}])
fi
if test -f "${real_dvdread_tree}/dvdread/.libs/libdvdread.a"
then
dnl Use a custom libdvdread
AC_MSG_RESULT(${real_dvdread_tree}/dvdread/.libs/libdvdread.a)
AX_ADD_BUILTINS([dvdread])
AX_ADD_LDFLAGS([dvdread],[-L${real_dvdread_tree}/dvdread/.libs -ldvdread ${LDFLAGS_dvdcss}])
AX_ADD_CPPFLAGS([dvdread],[-I${real_dvdread_tree}])
else
dnl The given libdvdread wasn't built
AC_MSG_RESULT(no)
AC_MSG_ERROR([cannot find ${real_dvdread_tree}/dvdread/.libs/libdvdread.a, make sure you compiled libdvdread in ${with_dvdread_tree}])
fi
fi
else
AC_MSG_CHECKING(for dvdread headers in ${with_dvdread})
if test -f ${with_dvdread}/include/dvdread/dvd_reader.h
then
dnl Use ${with_dvdread}/include/dvdread/dvd_reader.h
AC_MSG_RESULT(yes)
AX_ADD_PLUGINS([dvdread])
AX_ADD_LDFLAGS([dvdread],[-L${with_dvdread}/lib -ldvdread ${LDFLAGS_dvdcss}])
AX_ADD_CPPFLAGS([dvdread],[-I${with_dvdread}/include])
else
dnl No libdvdread could be found, sorry
AC_MSG_RESULT(no)
AC_MSG_ERROR([cannot find ${with_dvdread}/include/dvdread/dvd_reader.h])
fi
fi
fi
dnl
dnl libdvdnav plugin
......
......@@ -4,8 +4,8 @@ SOURCES_access_udp = udp.c
SOURCES_access_tcp = tcp.c
SOURCES_access_http = http.c
SOURCES_access_ftp = ftp.c
SOURCES_dvdread = dvdread.c
SOURCES_slp = slp.c
SOURCES_access2 = access2.c
SOURCES_cdda = \
cdda.c \
vcd/cdrom.c \
......
/*****************************************************************************
* dvdread.c : DvdRead input module for vlc
*****************************************************************************
* Copyright (C) 2001-2004 VideoLAN
* $Id$
*
* Authors: Stphane Borel <stef@via.ecp.fr>
* Gildas Bazin <gbazin@videolan.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
* (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.
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
/*****************************************************************************
* Preamble
*****************************************************************************/
#include <stdio.h>
#include <stdlib.h> /* malloc(), free() */
#include <string.h> /* strdup() */
#include <vlc/vlc.h>
#include <vlc/input.h>
#include "iso_lang.h"
#include "../demux/ps.h"
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <dvdread/dvd_reader.h>
#include <dvdread/ifo_types.h>
#include <dvdread/ifo_read.h>
#include <dvdread/nav_read.h>
#include <dvdread/nav_print.h>
/*****************************************************************************
* Module descriptor
*****************************************************************************/
#define CACHING_TEXT N_("caching value in ms")
#define CACHING_LONGTEXT N_( \
"Allows you to modify the default caching value for DVDread streams. " \
"This value should be set in millisecond units." )
#define CSSMETHOD_TEXT N_("Method used by libdvdcss for decryption")
#define CSSMETHOD_LONGTEXT N_( \
"Set the method used by libdvdcss for key decryption.\n" \
"title: decrypted title key is guessed from the encrypted sectors of " \
"the stream. Thus it should work with a file as well as the " \
"DVD device. But it sometimes takes much time to decrypt a title " \
"key and may even fail. With this method, the key is only checked "\
"at the beginning of each title, so it won't work if the key " \
"changes in the middle of a title.\n" \
"disc: the disc key is first cracked, then all title keys can be " \
"decrypted instantly, which allows us to check them often.\n" \
"key: the same as \"disc\" if you don't have a file with player keys " \
"at compilation time. If you do, the decryption of the disc key " \
"will be faster with this method. It is the one that was used by " \
"libcss.\n" \
"The default method is: key.")
static char *psz_css_list[] = { "title", "disc", "key" };
static char *psz_css_list_text[] = { N_("title"), N_("Disc"), N_("Key") };
static int Open ( vlc_object_t * );
static void Close( vlc_object_t * );
vlc_module_begin();
set_description( _("DVDRead Input") );
add_integer( "dvdread-caching", DEFAULT_PTS_DELAY / 1000, NULL,
CACHING_TEXT, CACHING_LONGTEXT, VLC_TRUE );
add_string( "dvdread-css-method", NULL, NULL, CSSMETHOD_TEXT,
CSSMETHOD_LONGTEXT, VLC_TRUE );
change_string_list( psz_css_list, psz_css_list_text, 0 );
set_capability( "access_demux", 0 );
add_shortcut( "dvd" );
add_shortcut( "dvdread" );
set_callbacks( Open, Close );
vlc_module_end();
/* how many blocks DVDRead will read in each loop */
#define DVD_BLOCK_READ_ONCE 64
/*****************************************************************************
* Local prototypes
*****************************************************************************/
struct demux_sys_t
{
/* DVDRead state */
dvd_reader_t *p_dvdread;
dvd_file_t *p_title;
ifo_handle_t *p_vmg_file;
ifo_handle_t *p_vts_file;
unsigned int i_title;
unsigned int i_chapter, i_chapters;
unsigned int i_angle, i_angles;
tt_srpt_t *p_tt_srpt;
pgc_t *p_cur_pgc;
dsi_t dsi_pack;
int i_ttn;
unsigned int i_pack_len;
unsigned int i_cur_block;
unsigned int i_next_vobu;
/* Current title start/end blocks */
unsigned int i_title_start_block;
unsigned int i_title_end_block;
unsigned int i_title_blocks;
unsigned int i_title_offset;
unsigned int i_title_start_cell;
unsigned int i_cur_cell;
unsigned int i_next_cell;
/* track */
ps_track_t tk[PS_TK_COUNT];
/* for spu variables */
input_thread_t *p_input;
/* FIXME */
uint8_t alpha[4];
uint32_t clut[16];
/* */
int i_aspect;
int i_titles;
input_title_t **titles;
};
static char *ParseCL( vlc_object_t *, char *, vlc_bool_t, int *, int *, int *);
static int Control ( demux_t *, int, va_list );
static int Demux ( demux_t * );
static int DemuxBlock( demux_t *, uint8_t *, int );
enum
{
AR_SQUARE_PICTURE = 1, /* square pixels */
AR_3_4_PICTURE = 2, /* 3:4 picture (TV) */
AR_16_9_PICTURE = 3, /* 16:9 picture (wide screen) */
AR_221_1_PICTURE = 4, /* 2.21:1 picture (movie) */
};
static void DemuxTitles( demux_t *, int *, int *, int * );
static void ESNew( demux_t *, int, int );
static int DvdReadSetArea ( demux_t *, int, int, int );
static void DvdReadSeek ( demux_t *, int );
static void DvdReadHandleDSI( demux_t *, uint8_t * );
static void DvdReadFindCell ( demux_t * );
/*****************************************************************************
* Open:
*****************************************************************************/
static int Open( vlc_object_t *p_this )
{
demux_t *p_demux = (demux_t*)p_this;
demux_sys_t *p_sys;
int i_title, i_chapter, i_angle;
char *psz_name;
char *psz_dvdcss_env;
dvd_reader_t *p_dvdread;
ifo_handle_t *p_vmg_file;
psz_name = ParseCL( VLC_OBJECT(p_demux), p_demux->psz_path, VLC_TRUE,
&i_title, &i_chapter, &i_angle );
if( !psz_name )
{
return VLC_EGENERIC;
}
/* Override environment variable DVDCSS_METHOD with config option
* (FIXME: this creates a small memory leak) */
psz_dvdcss_env = config_GetPsz( p_demux, "dvdread-css-method" );
if( psz_dvdcss_env && *psz_dvdcss_env )
{
char *psz_env;
psz_env = malloc( strlen("DVDCSS_METHOD=") +
strlen( psz_dvdcss_env ) + 1 );
if( !psz_env )
{
free( psz_dvdcss_env );
return VLC_ENOMEM;
}
sprintf( psz_env, "%s%s", "DVDCSS_METHOD=", psz_dvdcss_env );
putenv( psz_env );
}
if( psz_dvdcss_env ) free( psz_dvdcss_env );
/* Open dvdread */
if( !(p_dvdread = DVDOpen( psz_name )) )
{
msg_Err( p_demux, "DVDRead cannot open source: %s", psz_name );
free( psz_name );
return VLC_EGENERIC;
}
free( psz_name );
/* Ifo allocation & initialisation */
if( !( p_vmg_file = ifoOpen( p_dvdread, 0 ) ) )
{
msg_Warn( p_demux, "cannot open VMG info" );
return VLC_EGENERIC;
}
msg_Dbg( p_demux, "VMG opened" );
/* Fill p_demux field */
p_demux->pf_demux = Demux;
p_demux->pf_control = Control;
p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
memset( p_sys, 0, sizeof( demux_sys_t ) );
ps_track_init( p_sys->tk );
p_sys->i_aspect = -1;
p_sys->p_dvdread = p_dvdread;
p_sys->p_vmg_file = p_vmg_file;
p_sys->p_title = NULL;
p_sys->p_vts_file = NULL;
p_sys->i_title = p_sys->i_chapter = -1;
p_sys->i_angle = i_angle;
DemuxTitles( p_demux, &i_title, &i_chapter, &i_angle );
DvdReadSetArea( p_demux, i_title - 1, i_chapter, i_angle );
/* Update default_pts to a suitable value for dvdread access */
var_Create( p_demux, "dvdread-caching",
VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
return VLC_SUCCESS;
}
/*****************************************************************************
* Close:
*****************************************************************************/
static void Close( vlc_object_t *p_this )
{
demux_t *p_demux = (demux_t*)p_this;
demux_sys_t *p_sys = p_demux->p_sys;
int i;
for( i = 0; i < PS_TK_COUNT; i++ )
{
ps_track_t *tk = &p_sys->tk[i];
if( tk->b_seen )
{
es_format_Clean( &tk->fmt );
if( tk->es ) es_out_Del( p_demux->out, tk->es );
}
}
/* Close libdvdread */
if( p_sys->p_title ) DVDCloseFile( p_sys->p_title );
if( p_sys->p_vts_file ) ifoClose( p_sys->p_vts_file );
if( p_sys->p_vmg_file ) ifoClose( p_sys->p_vmg_file );
DVDClose( p_sys->p_dvdread );
free( p_sys );
}
/*****************************************************************************
* Control:
*****************************************************************************/
static int Control( demux_t *p_demux, int i_query, va_list args )
{
demux_sys_t *p_sys = p_demux->p_sys;
double f, *pf;
vlc_bool_t *pb;
int64_t *pi64;
input_title_t ***ppp_title;
int *pi_int;
int i;
switch( i_query )
{
case DEMUX_GET_POSITION:
{
pf = (double*) va_arg( args, double* );
if( p_sys->i_title_blocks > 0 )
*pf = (double)p_sys->i_title_offset / p_sys->i_title_blocks;
else
*pf = 0.0;
return VLC_SUCCESS;
}
case DEMUX_SET_POSITION:
{
f = (double)va_arg( args, double );
DvdReadSeek( p_demux, f * p_sys->i_title_blocks );
return VLC_SUCCESS;
}
/* Special for access_demux */
case DEMUX_CAN_PAUSE:
case DEMUX_CAN_CONTROL_PACE:
/* TODO */
pb = (vlc_bool_t*)va_arg( args, vlc_bool_t * );
*pb = VLC_TRUE;
return VLC_SUCCESS;
case DEMUX_SET_PAUSE_STATE:
return VLC_SUCCESS;
case DEMUX_GET_TITLE_INFO:
ppp_title = (input_title_t***)va_arg( args, input_title_t*** );
pi_int = (int*)va_arg( args, int* );
/* Duplicate title infos */
*pi_int = p_sys->i_titles;
*ppp_title = malloc( sizeof(input_title_t **) * p_sys->i_titles );
for( i = 0; i < p_sys->i_titles; i++ )
{
(*ppp_title)[i] = vlc_input_title_Duplicate(p_sys->titles[i]);
}
return VLC_SUCCESS;
case DEMUX_SET_TITLE:
i = (int)va_arg( args, int );
if( DvdReadSetArea( p_demux, i, 0, -1 ) != VLC_SUCCESS )
{
msg_Warn( p_demux, "cannot set title/chapter" );
return VLC_EGENERIC;
}
p_demux->info.i_update |=
INPUT_UPDATE_TITLE | INPUT_UPDATE_SEEKPOINT;
p_demux->info.i_title = i;
p_demux->info.i_seekpoint = 0;
return VLC_SUCCESS;
case DEMUX_SET_SEEKPOINT:
i = (int)va_arg( args, int );
if( DvdReadSetArea( p_demux, -1, i, -1 ) != VLC_SUCCESS )
{
msg_Warn( p_demux, "cannot set title/chapter" );
return VLC_EGENERIC;
}
p_demux->info.i_update |= INPUT_UPDATE_SEEKPOINT;
p_demux->info.i_seekpoint = i;
return VLC_SUCCESS;
case DEMUX_GET_PTS_DELAY:
pi64 = (int64_t*)va_arg( args, int64_t * );
*pi64 = (int64_t)var_GetInteger( p_demux, "dvdread-caching" )*1000;
return VLC_SUCCESS;
/* TODO implement others */
default:
return VLC_EGENERIC;
}
}
/*****************************************************************************
* Demux:
*****************************************************************************/
static int Demux( demux_t *p_demux )
{
demux_sys_t *p_sys = p_demux->p_sys;
uint8_t p_buffer[DVD_VIDEO_LB_LEN * DVD_BLOCK_READ_ONCE];
int i_blocks_once, i_read;
int i;
/*
* Playback by cell in this pgc, starting at the cell for our chapter.
*/
/*
* Check end of pack, and select the following one
*/
if( !p_sys->i_pack_len )
{
/* Read NAV packet */
if( DVDReadBlocks( p_sys->p_title, p_sys->i_next_vobu,
1, p_buffer ) != 1 )
{
msg_Err( p_demux, "read failed for block %d", p_sys->i_next_vobu );
return -1;
}
/* Basic check to be sure we don't have a empty title
* go to next title if so */
//assert( p_buffer[41] == 0xbf && p_buffer[1027] == 0xbf );
/* Parse the contained dsi packet */
DvdReadHandleDSI( p_demux, p_buffer );
/* End of title */
if( p_sys->i_next_vobu > p_sys->i_title_end_block )
{
if( p_sys->i_title + 1 >= p_sys->i_titles ) return 0; /* EOF */
DvdReadSetArea( p_demux, p_sys->i_title + 1, 0, -1 );
}
if( p_sys->i_pack_len <= 0 )
{
msg_Err( p_demux, "i_pack_len <= 0. This shouldn't happen!" );
return 0; /* EOF */
}
/* FIXME: Ugly kludge: we send the pack block to the input for it
* sometimes has a zero scr and restart the sync */
p_sys->i_cur_block++;
p_sys->i_title_offset++;
DemuxBlock( p_demux, p_buffer, DVD_VIDEO_LB_LEN );
}
if( p_sys->i_cur_block > p_sys->i_title_end_block )
{
if( p_sys->i_title + 1 >= p_sys->i_titles ) return 0; /* EOF */
DvdReadSetArea( p_demux, p_sys->i_title + 1, 0, -1 );
}
/*
* Read actual data
*/
i_blocks_once = __MIN( p_sys->i_pack_len, DVD_BLOCK_READ_ONCE );
p_sys->i_pack_len -= i_blocks_once;
/* Reads from DVD */
i_read = DVDReadBlocks( p_sys->p_title, p_sys->i_cur_block,
i_blocks_once, p_buffer );
if( i_read != i_blocks_once )
{
msg_Err( p_demux, "read failed for %d/%d blocks at 0x%02x",
i_read, i_blocks_once, p_sys->i_cur_block );
return -1;
}
p_sys->i_cur_block += i_read;
p_sys->i_title_offset += i_read;
#if 0
msg_Dbg( p_demux, "i_blocks: %d len: %d current: 0x%02x",
i_read, p_sys->i_pack_len, p_sys->i_cur_block );
#endif
for( i = 0; i < i_read; i++ )
{
DemuxBlock( p_demux, p_buffer + i * DVD_VIDEO_LB_LEN,
DVD_VIDEO_LB_LEN );
}
#undef p_pgc
return 1;
}