Commit 40e2844f authored by Francois Cartegnie's avatar Francois Cartegnie

demux: mp4: add support for gsm/quicktime builtin

Some quicktime mov have invalid sample tables, requiring
quicktime "built-in" support, aka figure out.

The agsm atom must also not be used as codec as it is
apple GSM which has different block size and sample count
than the MS GSM codec (33,160/65,320).

refs samples/A-codecs/GSM/sample-gsm-8000.mov
parent e740f598
......@@ -485,6 +485,9 @@ int SetupAudioES( demux_t *p_demux, mp4_track_t *p_track, MP4_Box_t *p_sample )
/* It's a little ugly but .. there are special cases */
switch( p_sample->i_type )
{
case ATOM_agsm: /* Apple gsm 33 bytes != MS GSM (agsm fourcc, 65 bytes) */
p_track->fmt.i_codec = VLC_CODEC_GSM;
break;
case( VLC_FOURCC( '.', 'm', 'p', '3' ) ):
case( VLC_FOURCC( 'm', 's', 0x00, 0x55 ) ):
{
......
......@@ -3736,6 +3736,7 @@ static const struct
/* for codecs */
{ ATOM_soun, MP4_ReadBox_sample_soun, MP4_FreeBox_sample_soun, ATOM_stsd },
{ ATOM_agsm, MP4_ReadBox_sample_soun, MP4_FreeBox_sample_soun, ATOM_stsd },
{ ATOM_ac3, MP4_ReadBox_sample_soun, MP4_FreeBox_sample_soun, ATOM_stsd },
{ ATOM_eac3, MP4_ReadBox_sample_soun, MP4_FreeBox_sample_soun, ATOM_stsd },
{ ATOM_lpcm, MP4_ReadBox_sample_soun, MP4_FreeBox_sample_soun, ATOM_stsd },
......
......@@ -150,6 +150,7 @@
#define ATOM_samr VLC_FOURCC( 's', 'a', 'm', 'r' )
#define ATOM_sawb VLC_FOURCC( 's', 'a', 'w', 'b' )
#define ATOM_OggS VLC_FOURCC( 'O', 'g', 'g', 'S' )
#define ATOM_agsm VLC_FOURCC( 'a', 'g', 's', 'm' )
#define ATOM_alac VLC_FOURCC( 'a', 'l', 'a', 'c' )
#define ATOM_ac3 VLC_FOURCC( 'a', 'c', '-', '3' )
#define ATOM_eac3 VLC_FOURCC( 'e', 'c', '-', '3' )
......
......@@ -3009,16 +3009,28 @@ static int MP4_TrackSeek( demux_t *p_demux, mp4_track_t *p_track,
static inline uint32_t MP4_GetFixedSampleSize( const mp4_track_t *p_track,
const MP4_Box_data_sample_soun_t *p_soun )
{
uint32_t i_size = 0;
uint32_t i_size = p_track->i_sample_size;
assert( p_track->i_sample_size != 0 );
/* broken stsz sample size == 1 */
if ( p_track->fmt.i_cat == AUDIO_ES &&
p_track->i_sample_size == 1 && p_soun->i_samplesize > p_track->i_sample_size * 8 )
i_size = p_soun->i_samplesize * p_soun->i_channelcount / 8;
else
i_size = p_track->i_sample_size;
/* QuickTime "built-in" support case fixups */
if( p_track->fmt.i_cat == AUDIO_ES &&
p_soun->i_compressionid == 0 && p_track->i_sample_size == 1 )
{
switch( p_track->fmt.i_codec )
{
case VLC_CODEC_GSM:
i_size = p_soun->i_channelcount;
break;
case ATOM_twos:
case ATOM_sowt:
case ATOM_raw:
i_size = p_soun->i_samplesize * p_soun->i_channelcount / 8;
break;
default:
break;
}
}
return i_size;
}
......@@ -3105,6 +3117,21 @@ static uint32_t MP4_TrackGetReadSize( mp4_track_t *p_track, uint32_t *pi_nb_samp
/* uncompressed v0 (qt) or... not (ISO) */
/* Quicktime built-in support handling */
if( p_soun->i_compressionid == 0 && p_track->i_sample_size == 1 )
{
switch( p_track->fmt.i_codec )
{
/* sample size is not integer */
case VLC_CODEC_GSM:
*pi_nb_samples = 160 * p_track->fmt.audio.i_channels;
return 33 * p_track->fmt.audio.i_channels;
default:
break;
}
}
/* More regular V0 cases */
uint32_t i_max_v0_samples;
switch( p_track->fmt.i_codec )
{
......@@ -3162,6 +3189,21 @@ static uint64_t MP4_TrackGetPos( mp4_track_t *p_track )
MP4_Box_data_sample_soun_t *p_soun =
p_track->p_sample->data.p_sample_soun;
/* Quicktime builtin support, _must_ ignore sample tables */
if( p_track->fmt.i_cat == AUDIO_ES && p_soun->i_compressionid == 0 &&
p_track->i_sample_size == 1 )
{
switch( p_track->fmt.i_codec )
{
case VLC_CODEC_GSM: /* # Samples > data size */
i_pos += ( p_track->i_sample -
p_track->chunk[p_track->i_chunk].i_sample_first ) / 160 * 33;
return i_pos;
default:
break;
}
}
if( p_track->fmt.i_cat != AUDIO_ES || p_soun->i_qt_version == 0 ||
p_track->fmt.audio.i_blockalign <= 1 ||
p_soun->i_sample_per_packet * p_soun->i_bytes_per_frame == 0 )
......
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