Commit 16faa457 authored by Gildas Bazin's avatar Gildas Bazin

* include/codecs.h, modules/demux/wav.c: patch by Matthew Romaine to handle...

* include/codecs.h, modules/demux/wav.c: patch by Matthew Romaine to handle WAVEFORMATEXTENSIBLE files more robustly.
parent 2d5322c3
......@@ -185,6 +185,22 @@ typedef struct
#define WAVE_FORMAT_EXTENSIBLE 0xFFFE /* Microsoft */
#endif
/* GUID SubFormat IDs */
/* We need both b/c const variables are not compile-time constants in C, giving
* us an error if we use the const GUID in an enum */
#ifndef _KSDATAFORMAT_SUBTYPE_PCM_
#define _KSDATAFORMAT_SUBTYPE_PCM_ {0x00000001, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}}
static const GUID VLC_KSDATAFORMAT_SUBTYPE_PCM = {0xE923AABF, 0xCB58, 0x4471, {0xA1, 0x19, 0xFF, 0xFA, 0x01, 0xE4, 0xCE, 0x62}};
#define KSDATAFORMAT_SUBTYPE_PCM VLC_KSDATAFORMAT_SUBTYPE_PCM
#endif
#ifndef _KSDATAFORMAT_SUBTYPE_UNKNOWN_
#define _KSDATAFORMAT_SUBTYPE_UNKNOWN_ {0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}
static const GUID VLC_KSDATAFORMAT_SUBTYPE_UNKNOWN = {0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};
#define KSDATAFORMAT_SUBTYPE_UNKNOWN VLC_KSDATAFORMAT_SUBTYPE_UNKNOWN
#endif
/* Microsoft speaker definitions */
#define WAVE_SPEAKER_FRONT_LEFT 0x1
#define WAVE_SPEAKER_FRONT_RIGHT 0x2
......@@ -258,6 +274,43 @@ static inline void fourcc_to_wf_tag( vlc_fourcc_t fcc, uint16_t *pi_tag )
if( pi_tag ) *pi_tag = wave_format_tag_to_fourcc[i].i_tag;
}
/* If wFormatTag is WAVEFORMATEXTENSIBLE, we must look at the SubFormat tag
* to determine the actual format. Microsoft has stopped giving out wFormatTag
* assignments in lieu of letting 3rd parties generate their own GUIDs
*/
static struct
{
GUID guid_tag;
vlc_fourcc_t i_fourcc;
char *psz_name;
}
sub_format_tag_to_fourcc[] =
{
{ _KSDATAFORMAT_SUBTYPE_PCM_, VLC_FOURCC( 'p', 'c', 'm', ' ' ), "PCM" },
{ _KSDATAFORMAT_SUBTYPE_UNKNOWN_, VLC_FOURCC( 'u', 'n', 'd', 'f' ), "Unknown" }
};
/* compares two GUIDs, returns 1 if identical, 0 otherwise */
static inline int guidcmp( const GUID *s1, const GUID *s2 )
{
return( s1->Data1 == s2->Data1 && s1->Data2 == s2->Data2 &&
s1->Data3 == s2->Data3 && !memcmp( s1->Data4, s2->Data4, 8 ) );
}
static inline void sf_tag_to_fourcc( GUID *guid_tag,
vlc_fourcc_t *fcc, char **ppsz_name )
{
int i;
for( i = 0; !guidcmp( &sub_format_tag_to_fourcc[i].guid_tag,
&KSDATAFORMAT_SUBTYPE_UNKNOWN ); i++ )
{
if( guidcmp( &sub_format_tag_to_fourcc[i].guid_tag, guid_tag ) ) break;
}
if( fcc ) *fcc = sub_format_tag_to_fourcc[i].i_fourcc;
if( ppsz_name ) *ppsz_name = sub_format_tag_to_fourcc[i].psz_name;
}
/**
* Structure to hold information concerning subtitles.
* Used between demuxers and decoders of subtitles.
......
......@@ -166,13 +166,21 @@ static int Open( vlc_object_t * p_this )
i_extended = 0;
/* Handle new WAVE_FORMAT_EXTENSIBLE wav files */
/* see the following link for more information:
* http://www.microsoft.com/whdc/device/audio/multichaud.mspx#EFAA */
if( GetWLE( &p_wf->wFormatTag ) == WAVE_FORMAT_EXTENSIBLE &&
i_size >= sizeof( WAVEFORMATEXTENSIBLE ) )
{
int i, i_channel_mask;
GUID guid_subformat;
guid_subformat = p_wf_ext->SubFormat;
guid_subformat.Data1 = GetDWLE( &p_wf_ext->SubFormat.Data1 );
guid_subformat.Data2 = GetWLE( &p_wf_ext->SubFormat.Data2 );
guid_subformat.Data3 = GetWLE( &p_wf_ext->SubFormat.Data3 );
sf_tag_to_fourcc( &guid_subformat, &p_sys->fmt.i_codec, &psz_name );
wf_tag_to_fourcc( GetWLE( &p_wf_ext->SubFormat ),
&p_sys->fmt.i_codec, &psz_name );
i_extended = sizeof( WAVEFORMATEXTENSIBLE ) - sizeof( WAVEFORMATEX );
p_sys->fmt.i_extra -= i_extended;
......
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