Commit 6926039e authored by Stéphane Borel's avatar Stéphane Borel

I have polioted once more with a bad file in the commit. It should work

better now. :p
parent 17a54d55
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* -dvd_udf to find files * -dvd_udf to find files
***************************************************************************** *****************************************************************************
* Copyright (C) 1998-2001 VideoLAN * Copyright (C) 1998-2001 VideoLAN
* $Id: input_dvd.c,v 1.19 2001/02/22 08:44:45 stef Exp $ * $Id: input_dvd.c,v 1.20 2001/02/22 08:59:54 stef Exp $
* *
* Author: Stphane Borel <stef@via.ecp.fr> * Author: Stphane Borel <stef@via.ecp.fr>
* *
...@@ -793,74 +793,67 @@ static void DVDEnd( input_thread_t * p_input ) ...@@ -793,74 +793,67 @@ static void DVDEnd( input_thread_t * p_input )
static int DVDRead( input_thread_t * p_input, static int DVDRead( input_thread_t * p_input,
data_packet_t ** pp_packets ) data_packet_t ** pp_packets )
{ {
byte_t p_header[6];
data_packet_t * p_data;
size_t i_packet_size;
int i_packet, i_error;
thread_dvd_data_t * p_method; thread_dvd_data_t * p_method;
netlist_t * p_netlist;
struct iovec * p_vec;
struct data_packet_s * p_data;
u8 * pi_cur;
int i_packet_size;
int i_packet;
int i_pos;
int i;
boolean_t b_first_packet;
p_method = (thread_dvd_data_t *)p_input->p_plugin_data; p_method = ( thread_dvd_data_t * ) p_input->p_plugin_data;
p_netlist = ( netlist_t * ) p_input->p_method_data;
memset( pp_packets, 0, INPUT_READ_ONCE * sizeof(data_packet_t *) ); /* Get an iovec pointer */
for( i_packet = 0; i_packet < INPUT_READ_ONCE; i_packet++ ) if( ( p_vec = input_NetlistGetiovec( p_netlist ) ) == NULL )
{
/* Read what we believe to be a packet header. */
if( (i_error = SafeRead( p_input, p_header, 6 )) )
{ {
return( i_error ); intf_ErrMsg( "DVD: read error" );
return -1;
} }
if( (U32_AT(p_header) & 0xFFFFFF00) != 0x100L ) /* Reads from DVD */
{ readv( p_input->i_handle, p_vec, p_method->i_read_once );
/* This is not the startcode of a packet. Read the stream
* until we find one. */
u32 i_startcode = U32_AT(p_header);
int i_nb;
byte_t i_dummy;
if( i_startcode ) if( p_method->b_encrypted )
{
/* It is common for MPEG-1 streams to pad with zeros
* (although it is forbidden by the recommendation), so
* don't bother everybody in this case. */
intf_WarnMsg( 1, "Garbage at input (%x)", i_startcode );
}
while( (i_startcode & 0xFFFFFF00) != 0x100L )
{ {
i_startcode <<= 8; for( i=0 ; i<p_method->i_read_once ; i++ )
if( (i_nb = SafeRead( p_input, &i_dummy, 1 )) != 0 )
{ {
i_startcode |= i_dummy; CSSDescrambleSector( p_method->css.pi_title_key,
} p_vec[i].iov_base );
else ((u8*)(p_vec[i].iov_base))[0x14] &= 0x8F;
{
return( 1 );
} }
} }
/* Packet found. */ /* Update netlist indexes */
*(u32 *)p_header = U32_AT(&i_startcode); input_NetlistMviovec( p_netlist, p_method->i_read_once, &p_data );
if( (i_error = SafeRead( p_input, p_header + 4, 2 )) )
{
return( i_error );
}
}
if( U32_AT(p_header) != 0x1BA ) i_packet = 0;
/* Read headers to compute payload length */
for( i = 0 ; i < p_method->i_read_once ; i++ )
{
i_pos = 0;
b_first_packet = 1;
while( i_pos < p_netlist->i_buffer_size )
{
pi_cur = (u8*)(p_vec[i].iov_base + i_pos);
/*default header */
if( U32_AT( pi_cur ) != 0x1BA )
{ {
/* That's the case for all packets, except pack header. */ /* That's the case for all packets, except pack header. */
i_packet_size = U16_AT(&p_header[4]); i_packet_size = U16_AT( pi_cur + 4 );
} }
else else
{ {
/* Pack header. */ /* Pack header. */
if( (p_header[4] & 0xC0) == 0x40 ) if( ( pi_cur[4] & 0xC0 ) == 0x40 )
{ {
/* MPEG-2 */ /* MPEG-2 */
i_packet_size = 8; i_packet_size = 8;
} }
else if( (p_header[4] & 0xF0) == 0x20 ) else if( ( pi_cur[4] & 0xF0 ) == 0x20 )
{ {
/* MPEG-1 */ /* MPEG-1 */
i_packet_size = 6; i_packet_size = 6;
...@@ -871,42 +864,31 @@ static int DVDRead( input_thread_t * p_input, ...@@ -871,42 +864,31 @@ static int DVDRead( input_thread_t * p_input,
return( -1 ); return( -1 );
} }
} }
if( b_first_packet )
/* Fetch a packet of the appropriate size. */
if( (p_data = NewPacket( p_input, i_packet_size + 6 )) == NULL )
{ {
intf_ErrMsg( "Out of memory" ); p_data->b_discard_payload = 0;
return( -1 ); b_first_packet = 0;
} }
else
/* Copy the header we already read. */
memcpy( p_data->p_buffer, p_header, 6 );
/* Read the remaining of the packet. */
if( i_packet_size && (i_error =
SafeRead( p_input, p_data->p_buffer + 6, i_packet_size )) )
{ {
return( i_error ); p_data = input_NetlistNewPacket( p_netlist ,
i_packet_size + 6 );
memcpy( p_data->p_buffer,
p_vec[i].iov_base + i_pos , i_packet_size + 6 );
} }
/* In MPEG-2 pack headers we still have to read stuffing bytes. */ p_data->p_payload_end = p_data->p_payload_start + i_packet_size + 6;
if( U32_AT(p_header) == 0x1BA ) pp_packets[i_packet] = p_data;
{ i_packet++;
if( i_packet_size == 8 && (p_data->p_buffer[13] & 0x7) != 0 ) i_pos += i_packet_size + 6;
{
/* MPEG-2 stuffing bytes */
byte_t p_garbage[8];
if( (i_error = SafeRead( p_input, p_garbage,
p_data->p_buffer[13] & 0x7)) )
{
return( i_error );
}
} }
} }
pp_packets[i_packet] = NULL;
/* Give the packet to the other input stages. */ vlc_mutex_lock( &p_input->stream.stream_lock );
pp_packets[i_packet] = p_data; p_input->stream.p_selected_area->i_tell +=
} p_method->i_read_once *DVD_LB_SIZE;
vlc_mutex_unlock( &p_input->stream.stream_lock );
return( 0 ); return( 0 );
} }
...@@ -945,3 +927,6 @@ static void DVDSeek( input_thread_t * p_input, off_t i_off ) ...@@ -945,3 +927,6 @@ static void DVDSeek( input_thread_t * p_input, off_t i_off )
return; return;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment