/* $Id: dvd.c,v 1.12 2005/11/25 15:05:25 titer Exp $
This file is part of the HandBrake source code.
- Homepage: <http://handbrake.m0k.org/>.
+ Homepage: <http://handbrake.fr/>.
It may be used under the terms of the GNU General Public License. */
#include "hb.h"
/* Open device */
if( !( d->reader = DVDOpen( path ) ) )
{
- hb_error( "dvd: DVDOpen failed (%s)", path );
+ /*
+ * Not an error, may be a stream - which we'll try in a moment.
+ */
+ hb_log( "dvd: not a dvd - trying as a stream/file instead" );
goto fail;
}
hb_error("Invalid VTS (title set) number: %i", title->vts);
goto fail;
}
-
+
hb_log( "scan: opening IFO for VTS %d", title->vts );
if( !( vts = ifoOpen( d->reader, title->vts ) ) )
{
hb_error( "scan: pgc not valid, skipping" );
goto fail;
}
-
+
+ if( pgn <= 0 || pgn > 99 )
+ {
+ hb_error( "scan: pgn %d not valid, skipping", pgn );
+ goto fail;
+ }
+
/* Start cell */
title->cell_start = d->pgc->program_map[pgn-1] - 1;
title->block_start = d->pgc->cell_playback[title->cell_start].first_sector;
{
case 0x00:
audio->id = ( ( 0x80 + position ) << 8 ) | 0xbd;
- audio->codec = HB_ACODEC_AC3;
+ audio->config.in.codec = HB_ACODEC_AC3;
break;
case 0x02:
case 0x03:
audio->id = 0xc0 + position;
- audio->codec = HB_ACODEC_MPGA;
+ audio->config.in.codec = HB_ACODEC_MPGA;
break;
case 0x04:
audio->id = ( ( 0xa0 + position ) << 8 ) | 0xbd;
- audio->codec = HB_ACODEC_LPCM;
+ audio->config.in.codec = HB_ACODEC_LPCM;
break;
case 0x06:
audio->id = ( ( 0x88 + position ) << 8 ) | 0xbd;
- audio->codec = HB_ACODEC_DCA;
+ audio->config.in.codec = HB_ACODEC_DCA;
break;
default:
audio->id = 0;
- audio->codec = 0;
+ audio->config.in.codec = 0;
hb_log( "scan: unknown audio codec (%x)",
audio_format );
break;
lang = lang_for_code( vts->vtsi_mat->vts_audio_attr[i].lang_code );
- snprintf( audio->lang, sizeof( audio->lang ), "%s (%s)",
+ snprintf( audio->config.lang.description, sizeof( audio->config.lang.description ), "%s (%s)",
strlen(lang->native_name) ? lang->native_name : lang->eng_name,
- audio->codec == HB_ACODEC_AC3 ? "AC3" : ( audio->codec ==
- HB_ACODEC_DCA ? "DTS" : ( audio->codec ==
+ audio->config.in.codec == HB_ACODEC_AC3 ? "AC3" : ( audio->config.in.codec ==
+ HB_ACODEC_DCA ? "DTS" : ( audio->config.in.codec ==
HB_ACODEC_MPGA ? "MPEG" : "LPCM" ) ) );
- snprintf( audio->lang_simple, sizeof( audio->lang_simple ), "%s",
+ snprintf( audio->config.lang.simple, sizeof( audio->config.lang.simple ), "%s",
strlen(lang->native_name) ? lang->native_name : lang->eng_name );
- snprintf( audio->iso639_2, sizeof( audio->iso639_2 ), "%s",
+ snprintf( audio->config.lang.iso639_2, sizeof( audio->config.lang.iso639_2 ), "%s",
lang->iso639_2);
hb_log( "scan: id=%x, lang=%s, 3cc=%s", audio->id,
- audio->lang, audio->iso639_2 );
+ audio->config.lang.description, audio->config.lang.iso639_2 );
+ audio->config.in.track = i;
hb_list_add( title->list_audio, audio );
}
switch( vts->vtsi_mat->vts_video_attr.display_aspect_ratio )
{
case 0:
- title->aspect = HB_ASPECT_BASE * 4 / 3;
+ title->container_aspect = 4. / 3.;
break;
case 3:
- title->aspect = HB_ASPECT_BASE * 16 / 9;
+ title->container_aspect = 16. / 9.;
break;
default:
hb_log( "scan: unknown aspect" );
goto fail;
}
- hb_log( "scan: aspect = %d", title->aspect );
+ hb_log( "scan: aspect = %g", title->aspect );
/* This title is ok so far */
goto cleanup;
int is_nav_pack( unsigned char *buf )
{
/*
- * The NAV Pack is comprised of the PCI Packet and DSI Packet, both
+ * The NAV Pack is comprised of the PCI Packet and DSI Packet, both
* of these start at known offsets and start with a special identifier.
*
* NAV = {
// should check and discover we're at eof.
if ( d->cell_cur > d->cell_end )
return 0;
-
+
for( ;; )
{
int block, pack_len, next_vobu, read_retry;
continue;
}
- if ( !is_nav_pack( b->data ) ) {
+ if ( !is_nav_pack( b->data ) ) {
(d->next_vobu)++;
if( d->in_sync == 1 ) {
- hb_log("dvd: Lost sync, searching for NAV pack at blk %d",
+ hb_log("dvd: Lost sync, searching for NAV pack at blk %d",
d->next_vobu);
d->in_sync = 0;
}
}
navRead_DSI( &dsi_pack, &b->data[DSI_START_BYTE] );
-
+
if ( d->in_sync == 0 && d->cur_cell_id &&
(d->cur_vob_id != dsi_pack.dsi_gi.vobu_vob_idn ||
d->cur_cell_id != dsi_pack.dsi_gi.vobu_c_idn ) )
if ( d->pgc->cell_playback[d->cell_cur].first_sector < dsi_pack.dsi_gi.nv_pck_lbn &&
d->pgc->cell_playback[d->cell_cur].last_sector >= dsi_pack.dsi_gi.nv_pck_lbn )
{
- hb_log( "dvd: null prev_vobu in cell %d at block %d", d->cell_cur,
+ hb_log( "dvd: null prev_vobu in cell %d at block %d", d->cell_cur,
d->block );
// treat like end-of-cell then go directly to start of next cell.
d->cell_cur = d->cell_next;
}
else
{
- hb_log( "dvd: Beginning of Cell (%d) at block %d", d->cell_cur,
- d->block );
+ if ( d->block != d->pgc->cell_playback[d->cell_cur].first_sector )
+ {
+ hb_log( "dvd: beginning of cell %d at block %d", d->cell_cur,
+ d->block );
+ }
if( d->in_cell )
{
- hb_error( "dvd: Assuming missed End of Cell (%d)", d->cell_cur );
+ hb_error( "dvd: assuming missed end of cell %d", d->cell_cur );
d->cell_cur = d->cell_next;
d->next_vobu = d->pgc->cell_playback[d->cell_cur].first_sector;
FindNextCell( d );
if( ( dsi_pack.vobu_sri.next_vobu & (1 << 31 ) ) == 0 ||
( dsi_pack.vobu_sri.next_vobu & 0x3fffffff ) == 0x3fffffff )
- {
- hb_log( "dvd: End of Cell (%d) at block %d", d->cell_cur,
- d->block );
+ {
+ if ( d->block <= d->pgc->cell_playback[d->cell_cur].first_sector ||
+ d->block > d->pgc->cell_playback[d->cell_cur].last_sector )
+ {
+ hb_log( "dvd: end of cell %d at block %d", d->cell_cur,
+ d->block );
+ }
d->cell_cur = d->cell_next;
d->in_cell = 0;
d->next_vobu = d->pgc->cell_playback[d->cell_cur].first_sector;
FindNextCell( d );
d->cell_overlap = 1;
-
+
}
}
else
/***********************************************************************
* hb_dvd_is_break
***********************************************************************
- * Returns 1 if the current block is a new chapter start
+ * Returns chapter number if the current block is a new chapter start
**********************************************************************/
int hb_dvd_is_break( hb_dvd_t * d )
{
int nr_of_ptts = d->ifo->vts_ptt_srpt->title[d->ttn-1].nr_of_ptts;
pgc_t * pgc;
int cell;
-
+
for( i = nr_of_ptts - 1;
i > 0;
i-- )
// This must not match against the start cell.
if( pgc->cell_playback[cell].first_sector == d->block && cell != d->cell_start )
{
- hb_log("dvd: Chapter Break Cell Found");
- return 1;
+ return i + 1;
}
}
-
+
return 0;
}
i++;
}
d->cell_next = d->cell_cur + i + 1;
- hb_log( "dvd: Skipping multi-angle cells %d-%d",
- d->cell_cur,
+ hb_log( "dvd: Skipping multi-angle cells %d-%d",
+ d->cell_cur,
d->cell_next - 1 );
}
else