Commit 4b029f25 authored by Gildas Bazin's avatar Gildas Bazin

* modules/demux/dts.c: improved detection of wav dts files.
parent 69ddcc65
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* dts.c : raw DTS stream input module for vlc * dts.c : raw DTS stream input module for vlc
***************************************************************************** *****************************************************************************
* Copyright (C) 2001 VideoLAN * Copyright (C) 2001 VideoLAN
* $Id: dts.c,v 1.8 2004/02/17 13:13:32 gbazin Exp $ * $Id: dts.c,v 1.9 2004/02/24 19:23:11 gbazin Exp $
* *
* Authors: Gildas Bazin <gbazin@netcourrier.com> * Authors: Gildas Bazin <gbazin@netcourrier.com>
* *
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include <vlc_codec.h> #include <vlc_codec.h>
#define DTS_PACKET_SIZE 16384 #define DTS_PACKET_SIZE 16384
#define DTS_PROBE_SIZE (DTS_PACKET_SIZE * 4)
#define DTS_MAX_HEADER_SIZE 11 #define DTS_MAX_HEADER_SIZE 11
/***************************************************************************** /*****************************************************************************
...@@ -111,25 +112,53 @@ static int Open( vlc_object_t * p_this ) ...@@ -111,25 +112,53 @@ static int Open( vlc_object_t * p_this )
p_input->pf_rewind = NULL; p_input->pf_rewind = NULL;
/* Check if we are dealing with a WAV file */ /* Check if we are dealing with a WAV file */
if( input_Peek( p_input, &p_peek, 12 ) == 12 && if( input_Peek( p_input, &p_peek, 20 ) == 20 &&
!strncmp( p_peek, "RIFF", 4 ) && !strncmp( &p_peek[8], "WAVE", 4 ) ) !strncmp( p_peek, "RIFF", 4 ) && !strncmp( &p_peek[8], "WAVE", 4 ) )
{ {
/* Skip the wave header */ int i_size;
i_peek = 12 + 8;
while( input_Peek( p_input, &p_peek, i_peek ) == i_peek && /* Find the wave format header */
strncmp( p_peek + i_peek - 8, "data", 4 ) ) i_peek = 20;
while( strncmp( p_peek + i_peek - 8, "fmt ", 4 ) )
{ {
i_peek += GetDWLE( p_peek + i_peek - 4 ) + 8; i_size = GetDWLE( p_peek + i_peek - 4 );
if( i_size + i_peek > DTS_PROBE_SIZE ) return VLC_EGENERIC;
i_peek += i_size + 8;
if( input_Peek( p_input, &p_peek, i_peek ) != i_peek )
return VLC_EGENERIC;
} }
/* TODO: should check wave format and sample_rate */ /* Sanity check the wave format header */
i_size = GetDWLE( p_peek + i_peek - 4 );
if( i_size + i_peek > DTS_PROBE_SIZE ) return VLC_EGENERIC;
i_peek += i_size + 8;
if( input_Peek( p_input, &p_peek, i_peek ) != i_peek )
return VLC_EGENERIC;
if( GetWLE( p_peek + i_peek - i_size - 8 /* wFormatTag */ ) !=
1 /* WAVE_FORMAT_PCM */ )
return VLC_EGENERIC;
if( GetWLE( p_peek + i_peek - i_size - 6 /* nChannels */ ) != 2 )
return VLC_EGENERIC;
if( GetDWLE( p_peek + i_peek - i_size - 4 /* nSamplesPerSec */ ) !=
44100 )
return VLC_EGENERIC;
/* Skip the wave header */
while( strncmp( p_peek + i_peek - 8, "data", 4 ) )
{
i_size = GetDWLE( p_peek + i_peek - 4 );
if( i_size + i_peek > DTS_PROBE_SIZE ) return VLC_EGENERIC;
i_peek += i_size + 8;
if( input_Peek( p_input, &p_peek, i_peek ) != i_peek )
return VLC_EGENERIC;
}
/* Some DTS wav files don't begin with a sync code so we do a more /* Some DTS wav files don't begin with a sync code so we do a more
* extensive search */ * extensive search */
if( input_Peek( p_input, &p_peek, i_peek + DTS_PACKET_SIZE * 2) == i_size = input_Peek( p_input, &p_peek, DTS_PROBE_SIZE );
i_peek + DTS_PACKET_SIZE * 2) i_size -= DTS_MAX_HEADER_SIZE;
{
int i_size = i_peek + DTS_PACKET_SIZE * 2 - DTS_MAX_HEADER_SIZE;
while( i_peek < i_size ) while( i_peek < i_size )
{ {
...@@ -140,7 +169,6 @@ static int Open( vlc_object_t * p_this ) ...@@ -140,7 +169,6 @@ static int Open( vlc_object_t * p_this )
break; break;
} }
} }
}
/* Have a peep at the show. */ /* Have a peep at the show. */
if( input_Peek( p_input, &p_peek, i_peek + DTS_MAX_HEADER_SIZE * 2 ) < if( input_Peek( p_input, &p_peek, i_peek + DTS_MAX_HEADER_SIZE * 2 ) <
......
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