1 /*****************************************************************************
2 * es.c : Generic audio ES input module for vlc
3 *****************************************************************************
4 * Copyright (C) 2001-2008 the VideoLAN team
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8 * Gildas Bazin <gbazin@videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
33 #include <vlc_common.h>
34 #include <vlc_plugin.h>
35 #include <vlc_demux.h>
36 #include <vlc_codec.h>
37 #include <vlc_codecs.h>
38 #include <vlc_input.h>
40 #include "../../codec/a52.h"
42 /*****************************************************************************
44 *****************************************************************************/
45 static int OpenAudio( vlc_object_t * );
46 static int OpenVideo( vlc_object_t * );
47 static void Close ( vlc_object_t * );
49 #define FPS_TEXT N_("Frames per Second")
50 #define FPS_LONGTEXT N_("This is the frame rate used as a fallback when " \
51 "playing MPEG video elementary streams.")
54 set_category( CAT_INPUT )
55 set_subcategory( SUBCAT_INPUT_DEMUX )
56 set_description( N_("MPEG-I/II/4 / A52 / DTS / MLP audio" ) )
57 set_capability( "demux", 155 )
58 set_callbacks( OpenAudio, Close )
60 add_shortcut( "mpga", "mp3",
68 set_description( N_("MPEG-4 video" ) )
69 set_capability( "demux", 0 )
70 set_callbacks( OpenVideo, Close )
71 add_float( "es-fps", 25, NULL, FPS_TEXT, FPS_LONGTEXT, false )
74 add_shortcut( "mp4v" )
77 /*****************************************************************************
79 *****************************************************************************/
80 static int Demux ( demux_t * );
81 static int Control( demux_t *, int, va_list );
88 int (*pf_probe)( demux_t *p_demux, int64_t *pi_offset );
89 int (*pf_init)( demux_t *p_demux );
99 decoder_t *p_packetizer;
102 mtime_t i_time_offset;
106 bool b_estimate_bitrate;
107 int i_bitrate_avg; /* extracted from Xing header */
109 bool b_initial_sync_failed;
113 int64_t i_stream_offset;
127 static int MpgaProbe( demux_t *p_demux, int64_t *pi_offset );
128 static int MpgaInit( demux_t *p_demux );
130 static int AacProbe( demux_t *p_demux, int64_t *pi_offset );
131 static int AacInit( demux_t *p_demux );
133 static int EA52Probe( demux_t *p_demux, int64_t *pi_offset );
134 static int A52Probe( demux_t *p_demux, int64_t *pi_offset );
135 static int A52Init( demux_t *p_demux );
137 static int DtsProbe( demux_t *p_demux, int64_t *pi_offset );
138 static int DtsInit( demux_t *p_demux );
140 static int MlpProbe( demux_t *p_demux, int64_t *pi_offset );
141 static int MlpInit( demux_t *p_demux );
143 static const codec_t p_codecs[] = {
144 { VLC_CODEC_MP4A, false, "mp4 audio", AacProbe, AacInit },
145 { VLC_CODEC_MPGA, false, "mpeg audio", MpgaProbe, MpgaInit },
146 { VLC_CODEC_A52, true, "a52 audio", A52Probe, A52Init },
147 { VLC_CODEC_EAC3, true, "eac3 audio", EA52Probe, A52Init },
148 { VLC_CODEC_DTS, false, "dts audio", DtsProbe, DtsInit },
149 { VLC_CODEC_TRUEHD, false, "mlp audio", MlpProbe, MlpInit },
151 { 0, false, NULL, NULL, NULL }
154 static int VideoInit( demux_t *p_demux );
156 static const codec_t codec_m4v = {
157 VLC_CODEC_MP4V, false, "mp4 video", NULL, VideoInit
160 /*****************************************************************************
161 * OpenCommon: initializes demux structures
162 *****************************************************************************/
163 static int OpenCommon( demux_t *p_demux,
164 int i_cat, const codec_t *p_codec, int64_t i_bs_offset )
170 DEMUX_INIT_COMMON(); p_sys = p_demux->p_sys;
171 memset( p_sys, 0, sizeof( demux_sys_t ) );
172 p_sys->codec = *p_codec;
174 p_sys->b_start = true;
175 p_sys->i_stream_offset = i_bs_offset;
176 p_sys->b_estimate_bitrate = true;
177 p_sys->i_bitrate_avg = 0;
178 p_sys->b_big_endian = false;
179 p_sys->f_fps = var_InheritFloat( p_demux, "es-fps" );
181 if( stream_Seek( p_demux->s, p_sys->i_stream_offset ) )
187 if( p_sys->codec.pf_init( p_demux ) )
193 msg_Dbg( p_demux, "detected format %4.4s", (const char*)&p_sys->codec.i_codec );
195 /* Load the audio packetizer */
196 es_format_Init( &fmt, i_cat, p_sys->codec.i_codec );
197 p_sys->p_packetizer = demux_PacketizerNew( p_demux, &fmt, p_sys->codec.psz_name );
198 if( !p_sys->p_packetizer )
205 static int OpenAudio( vlc_object_t *p_this )
207 demux_t *p_demux = (demux_t*)p_this;
208 for( int i = 0; p_codecs[i].i_codec != 0; i++ )
211 if( !p_codecs[i].pf_probe( p_demux, &i_offset ) )
212 return OpenCommon( p_demux, AUDIO_ES, &p_codecs[i], i_offset );
216 static int OpenVideo( vlc_object_t *p_this )
218 demux_t *p_demux = (demux_t*)p_this;
220 /* Only m4v is supported for the moment */
221 bool b_m4v_ext = demux_IsPathExtension( p_demux, ".m4v" );
222 bool b_m4v_forced = demux_IsForced( p_demux, "m4v" ) ||
223 demux_IsForced( p_demux, "mp4v" );
224 if( !b_m4v_ext && !b_m4v_forced )
227 const uint8_t *p_peek;
228 if( stream_Peek( p_demux->s, &p_peek, 4 ) < 4 )
230 if( p_peek[0] != 0x00 || p_peek[1] != 0x00 || p_peek[2] != 0x01 )
235 "this doesn't look like an MPEG ES stream, continuing anyway" );
237 return OpenCommon( p_demux, VIDEO_ES, &codec_m4v, 0 );
239 /*****************************************************************************
240 * Demux: reads and demuxes data packets
241 *****************************************************************************
242 * Returns -1 in case of error, 0 in case of EOF, 1 otherwise
243 *****************************************************************************/
244 static int Demux( demux_t *p_demux )
246 demux_sys_t *p_sys = p_demux->p_sys;
247 block_t *p_block_in, *p_block_out;
249 if( p_sys->codec.b_use_word )
251 /* Make sure we are word aligned */
252 int64_t i_pos = stream_Tell( p_demux->s );
254 stream_Read( p_demux->s, NULL, 1 );
257 if( ( p_block_in = stream_Block( p_demux->s, p_sys->i_packet_size ) ) == NULL )
260 if( p_sys->codec.b_use_word && !p_sys->b_big_endian && p_block_in->i_buffer > 0 )
262 /* Convert to big endian */
263 swab( p_block_in->p_buffer, p_block_in->p_buffer, p_block_in->i_buffer );
266 p_block_in->i_pts = p_block_in->i_dts = p_sys->b_start || p_sys->b_initial_sync_failed ? VLC_TS_0 : VLC_TS_INVALID;
267 p_sys->b_initial_sync_failed = p_sys->b_start; /* Only try to resync once */
269 while( ( p_block_out = p_sys->p_packetizer->pf_packetize( p_sys->p_packetizer, &p_block_in ) ) )
271 p_sys->b_initial_sync_failed = false;
274 block_t *p_next = p_block_out->p_next;
278 p_sys->p_packetizer->fmt_out.b_packetized = true;
279 p_sys->p_es = es_out_Add( p_demux->out,
280 &p_sys->p_packetizer->fmt_out);
283 /* Try the xing header */
284 if( p_sys->xing.i_bytes && p_sys->xing.i_frames &&
285 p_sys->xing.i_frame_samples )
287 p_sys->i_bitrate_avg = p_sys->xing.i_bytes * INT64_C(8) *
288 p_sys->p_packetizer->fmt_out.audio.i_rate /
289 p_sys->xing.i_frames / p_sys->xing.i_frame_samples;
291 if( p_sys->i_bitrate_avg > 0 )
292 p_sys->b_estimate_bitrate = false;
294 /* Use the bitrate as initual value */
295 if( p_sys->b_estimate_bitrate )
296 p_sys->i_bitrate_avg = p_sys->p_packetizer->fmt_out.i_bitrate;
298 if( p_sys->p_packetizer->fmt_out.i_cat == VIDEO_ES )
300 if( p_block_out->i_pts <= VLC_TS_INVALID &&
301 p_block_out->i_dts <= VLC_TS_INVALID )
302 p_block_out->i_dts = VLC_TS_0 + p_sys->i_pts + 1000000 / p_sys->f_fps;
303 if( p_block_out->i_dts > VLC_TS_INVALID )
304 p_sys->i_pts = p_block_out->i_dts - VLC_TS_0;
308 p_sys->i_pts = p_block_out->i_pts - VLC_TS_0;
311 /* Re-estimate bitrate */
312 if( p_sys->b_estimate_bitrate && p_sys->i_pts > INT64_C(500000) )
313 p_sys->i_bitrate_avg = 8*INT64_C(1000000)*p_sys->i_bytes/(p_sys->i_pts-1);
314 p_sys->i_bytes += p_block_out->i_buffer;
316 /* Correct timestamp */
317 if( p_block_out->i_pts > VLC_TS_INVALID )
319 p_block_out->i_pts += p_sys->i_time_offset;
321 if( p_block_out->i_dts > VLC_TS_INVALID )
323 p_block_out->i_dts += p_sys->i_time_offset;
324 es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block_out->i_dts );
327 es_out_Send( p_demux->out, p_sys->p_es, p_block_out );
329 p_block_out = p_next;
333 if( p_sys->b_initial_sync_failed )
334 msg_Dbg( p_demux, "did not sync on first block" );
335 p_sys->b_start = false;
339 /*****************************************************************************
340 * Close: frees unused data
341 *****************************************************************************/
342 static void Close( vlc_object_t * p_this )
344 demux_t *p_demux = (demux_t*)p_this;
345 demux_sys_t *p_sys = p_demux->p_sys;
347 demux_PacketizerDestroy( p_sys->p_packetizer );
351 /*****************************************************************************
353 *****************************************************************************/
354 static int Control( demux_t *p_demux, int i_query, va_list args )
356 demux_sys_t *p_sys = p_demux->p_sys;
362 va_copy ( args_save, args );
366 case DEMUX_HAS_UNSUPPORTED_META:
367 pb_bool = (bool*)va_arg( args, bool* );
372 pi64 = (int64_t*)va_arg( args, int64_t * );
373 *pi64 = p_sys->i_pts + p_sys->i_time_offset;
376 case DEMUX_GET_LENGTH:
377 i_ret = demux_vaControlHelper( p_demux->s, p_sys->i_stream_offset, -1,
378 p_sys->i_bitrate_avg, 1, i_query,
380 /* No bitrate, we can't have it precisely, but we can compute
381 * a raw approximation with time/position */
382 if( i_ret && !p_sys->i_bitrate_avg )
384 float f_pos = (double)(uint64_t)( stream_Tell( p_demux->s ) ) /
385 (double)(uint64_t)( stream_Size( p_demux->s ) );
386 /* The first few seconds are guaranteed to be very whacky,
387 * don't bother trying ... Too bad */
389 (p_sys->i_pts + p_sys->i_time_offset) < 8000000 )
392 pi64 = (int64_t *)va_arg( args_save, int64_t * );
393 *pi64 = (p_sys->i_pts + p_sys->i_time_offset) / f_pos;
400 /* FIXME TODO: implement a high precision seek (with mp3 parsing)
401 * needed for multi-input */
403 i_ret = demux_vaControlHelper( p_demux->s, p_sys->i_stream_offset, -1,
404 p_sys->i_bitrate_avg, 1, i_query,
406 if( !i_ret && p_sys->i_bitrate_avg > 0 &&
407 (i_query == DEMUX_SET_POSITION || i_query == DEMUX_SET_TIME) )
409 int64_t i_time = INT64_C(8000000) * ( stream_Tell(p_demux->s) - p_sys->i_stream_offset ) /
410 p_sys->i_bitrate_avg;
412 /* Fix time_offset */
414 p_sys->i_time_offset = i_time - p_sys->i_pts;
420 /*****************************************************************************
422 *****************************************************************************/
423 #define WAV_PROBE_SIZE (512*1024)
424 static int WavSkipHeader( demux_t *p_demux, int *pi_skip, const int pi_format[] )
426 const uint8_t *p_peek;
432 /* Check if we are dealing with a WAV file */
433 if( stream_Peek( p_demux->s, &p_peek, 12+8 ) != 12 + 8 )
436 if( memcmp( p_peek, "RIFF", 4 ) || memcmp( &p_peek[8], "WAVE", 4 ) )
439 /* Find the wave format header */
441 while( memcmp( p_peek + i_peek - 8, "fmt ", 4 ) )
443 uint32_t i_len = GetDWLE( p_peek + i_peek - 4 );
444 if( i_len > WAV_PROBE_SIZE || i_peek + i_len > WAV_PROBE_SIZE )
448 if( stream_Peek( p_demux->s, &p_peek, i_peek ) != i_peek )
452 /* Sanity check the wave format header */
453 uint32_t i_len = GetDWLE( p_peek + i_peek - 4 );
454 if( i_len > WAV_PROBE_SIZE )
458 if( stream_Peek( p_demux->s, &p_peek, i_peek ) != i_peek )
460 const int i_format = GetWLE( p_peek + i_peek - i_len - 8 /* wFormatTag */ );
462 for( i_format_idx = 0; pi_format[i_format_idx] != WAVE_FORMAT_UNKNOWN; i_format_idx++ )
464 if( i_format == pi_format[i_format_idx] )
467 if( pi_format[i_format_idx] == WAVE_FORMAT_UNKNOWN )
470 if( i_format == WAVE_FORMAT_PCM )
472 if( GetWLE( p_peek + i_peek - i_len - 6 /* nChannels */ ) != 2 )
474 if( GetDWLE( p_peek + i_peek - i_len - 4 /* nSamplesPerSec */ ) !=
479 /* Skip the wave header */
480 while( memcmp( p_peek + i_peek - 8, "data", 4 ) )
482 uint32_t i_len = GetDWLE( p_peek + i_peek - 4 );
483 if( i_len > WAV_PROBE_SIZE || i_peek + i_len > WAV_PROBE_SIZE )
487 if( stream_Peek( p_demux->s, &p_peek, i_peek ) != i_peek )
494 static int GenericProbe( demux_t *p_demux, int64_t *pi_offset,
495 const char * ppsz_name[],
496 int (*pf_check)( const uint8_t *, int * ), int i_check_size,
497 const int pi_wav_format[] )
502 const uint8_t *p_peek;
505 b_forced_demux = false;
506 for( int i = 0; ppsz_name[i] != NULL; i++ )
508 b_forced_demux |= demux_IsForced( p_demux, ppsz_name[i] );
511 i_offset = stream_Tell( p_demux->s );
513 if( WavSkipHeader( p_demux, &i_skip, pi_wav_format ) )
515 if( !b_forced_demux )
518 const bool b_wav = i_skip > 0;
521 * It is common that wav files have some sort of garbage at the begining
522 * We will accept probing 0.5s of data in this case.
524 const int i_probe = i_skip + i_check_size + 8000 + ( b_wav ? (44000/2*2*2) : 0);
525 const int i_peek = stream_Peek( p_demux->s, &p_peek, i_probe );
526 if( i_peek < i_skip + i_check_size )
528 msg_Err( p_demux, "cannot peek" );
533 if( i_skip + i_check_size > i_peek )
535 if( !b_forced_demux )
540 int i_size = pf_check( &p_peek[i_skip], &i_samples );
546 /* If we have the frame size, check the next frame for
548 * The second test is because some .wav have paddings
551 for( int t = 0; t < 1 + !!b_wav; t++ )
554 i_size = i_samples * 2 * 2;
555 if( i_skip + i_check_size + i_size <= i_peek )
557 b_ok = pf_check( &p_peek[i_skip+i_size], NULL ) >= 0;
566 if( !b_wav && !b_forced_demux )
570 *pi_offset = i_offset + i_skip;
574 /*****************************************************************************
576 *****************************************************************************/
577 static int MpgaCheckSync( const uint8_t *p_peek )
579 uint32_t h = GetDWBE( p_peek );
581 if( ((( h >> 21 )&0x07FF) != 0x07FF ) /* header sync */
582 || (((h >> 17)&0x03) == 0 ) /* valid layer ?*/
583 || (((h >> 12)&0x0F) == 0x0F )
584 || (((h >> 12)&0x0F) == 0x00 ) /* valid bitrate ? */
585 || (((h >> 10) & 0x03) == 0x03 ) /* valide sampling freq ? */
586 || ((h & 0x03) == 0x02 )) /* valid emphasis ? */
593 #define MPGA_VERSION( h ) ( 1 - (((h)>>19)&0x01) )
594 #define MPGA_MODE(h) (((h)>> 6)&0x03)
596 static int MpgaGetFrameSamples( uint32_t h )
598 const int i_layer = 3 - (((h)>>17)&0x03);
606 return MPGA_VERSION(h) ? 576 : 1152;
612 static int MpgaProbe( demux_t *p_demux, int64_t *pi_offset )
614 const int pi_wav[] = { WAVE_FORMAT_MPEG, WAVE_FORMAT_MPEGLAYER3, WAVE_FORMAT_UNKNOWN };
619 const uint8_t *p_peek;
622 b_forced = demux_IsPathExtension( p_demux, ".mp3" );
623 b_forced_demux = demux_IsForced( p_demux, "mp3" ) ||
624 demux_IsForced( p_demux, "mpga" );
626 i_offset = stream_Tell( p_demux->s );
628 if( WavSkipHeader( p_demux, &i_skip, pi_wav ) )
630 if( !b_forced_demux )
636 if( stream_Peek( p_demux->s, &p_peek, i_skip + 4 ) < i_skip + 4 )
639 if( !MpgaCheckSync( &p_peek[i_skip] ) )
644 if( !b_forced_demux && !b_forced )
647 i_peek = stream_Peek( p_demux->s, &p_peek, i_skip + 8096 );
648 while( i_skip + 4 < i_peek )
650 if( MpgaCheckSync( &p_peek[i_skip] ) )
657 if( !b_ok && !b_forced_demux )
660 *pi_offset = i_offset + i_skip;
664 static void MpgaXingSkip( const uint8_t **pp_xing, int *pi_xing, int i_count )
666 if(i_count > *pi_xing )
669 (*pp_xing) += i_count;
670 (*pi_xing) -= i_count;
673 static uint32_t MpgaXingGetDWBE( const uint8_t **pp_xing, int *pi_xing, uint32_t i_default )
678 uint32_t v = GetDWBE( *pp_xing );
680 MpgaXingSkip( pp_xing, pi_xing, 4 );
685 static int MpgaInit( demux_t *p_demux )
687 demux_sys_t *p_sys = p_demux->p_sys;
689 const uint8_t *p_peek;
693 p_sys->i_packet_size = 1024;
695 /* Load a potential xing header */
696 i_peek = stream_Peek( p_demux->s, &p_peek, 4 + 1024 );
697 if( i_peek < 4 + 21 )
700 const uint32_t header = GetDWBE( p_peek );
701 if( !MpgaCheckSync( p_peek ) )
705 const uint8_t *p_xing = p_peek;
709 if( MPGA_VERSION( header ) == 0 )
710 i_skip = MPGA_MODE( header ) != 3 ? 36 : 21;
712 i_skip = MPGA_MODE( header ) != 3 ? 21 : 13;
714 if( i_skip + 8 >= i_xing || memcmp( &p_xing[i_skip], "Xing", 4 ) )
717 const uint32_t i_flags = GetDWBE( &p_xing[i_skip+4] );
719 MpgaXingSkip( &p_xing, &i_xing, i_skip + 8 );
722 p_sys->xing.i_frames = MpgaXingGetDWBE( &p_xing, &i_xing, 0 );
724 p_sys->xing.i_bytes = MpgaXingGetDWBE( &p_xing, &i_xing, 0 );
725 if( i_flags&0x04 ) /* TODO Support XING TOC to improve seeking accuracy */
726 MpgaXingSkip( &p_xing, &i_xing, 100 );
729 /* FIXME: doesn't return the right bitrage average, at least
731 p_sys->xing.i_bitrate_avg = MpgaXingGetDWBE( &p_xing, &i_xing, 0 );
732 msg_Dbg( p_demux, "xing vbr value present (%d)",
733 p_sys->xing.i_bitrate_avg );
736 if( p_sys->xing.i_frames > 0 && p_sys->xing.i_bytes > 0 )
738 p_sys->xing.i_frame_samples = MpgaGetFrameSamples( header );
739 msg_Dbg( p_demux, "xing frames&bytes value present "
740 "(%d bytes, %d frames, %d samples/frame)",
741 p_sys->xing.i_bytes, p_sys->xing.i_frames,
742 p_sys->xing.i_frame_samples );
747 /*****************************************************************************
749 *****************************************************************************/
750 static int AacProbe( demux_t *p_demux, int64_t *pi_offset )
756 const uint8_t *p_peek;
758 b_forced = demux_IsPathExtension( p_demux, ".aac" ) ||
759 demux_IsPathExtension( p_demux, ".aacp" );
760 b_forced_demux = demux_IsForced( p_demux, "m4a" ) ||
761 demux_IsForced( p_demux, "aac" ) ||
762 demux_IsForced( p_demux, "mp4a" );
764 if( !b_forced_demux && !b_forced )
767 i_offset = stream_Tell( p_demux->s );
769 /* peek the begining (10 is for adts header) */
770 if( stream_Peek( p_demux->s, &p_peek, 10 ) < 10 )
772 msg_Err( p_demux, "cannot peek" );
775 if( !strncmp( (char *)p_peek, "ADIF", 4 ) )
777 msg_Err( p_demux, "ADIF file. Not yet supported. (Please report)" );
781 *pi_offset = i_offset;
784 static int AacInit( demux_t *p_demux )
786 demux_sys_t *p_sys = p_demux->p_sys;
788 p_sys->i_packet_size = 4096;
794 /*****************************************************************************
796 *****************************************************************************/
797 static int A52CheckSync( const uint8_t *p_peek, bool *p_big_endian, int *pi_samples, bool b_eac3 )
799 vlc_a52_header_t header;
800 uint8_t p_tmp[VLC_A52_HEADER_SIZE];
802 *p_big_endian = p_peek[0] == 0x0b && p_peek[1] == 0x77;
805 swab( p_peek, p_tmp, VLC_A52_HEADER_SIZE );
809 if( vlc_a52_header_Parse( &header, p_peek, VLC_A52_HEADER_SIZE ) )
812 if( !header.b_eac3 != !b_eac3 )
815 *pi_samples = header.i_samples;
816 return header.i_size;
818 static int EA52CheckSyncProbe( const uint8_t *p_peek, int *pi_samples )
821 return A52CheckSync( p_peek, &b_dummy, pi_samples, true );
824 static int EA52Probe( demux_t *p_demux, int64_t *pi_offset )
826 const char *ppsz_name[] = { "eac3", NULL };
827 const int pi_wav[] = { WAVE_FORMAT_PCM, WAVE_FORMAT_A52, WAVE_FORMAT_UNKNOWN };
829 return GenericProbe( p_demux, pi_offset, ppsz_name, EA52CheckSyncProbe, VLC_A52_HEADER_SIZE, pi_wav );
832 static int A52CheckSyncProbe( const uint8_t *p_peek, int *pi_samples )
835 return A52CheckSync( p_peek, &b_dummy, pi_samples, false );
838 static int A52Probe( demux_t *p_demux, int64_t *pi_offset )
840 const char *ppsz_name[] = { "a52", "ac3", NULL };
841 const int pi_wav[] = { WAVE_FORMAT_PCM, WAVE_FORMAT_A52, WAVE_FORMAT_UNKNOWN };
843 return GenericProbe( p_demux, pi_offset, ppsz_name, A52CheckSyncProbe, VLC_A52_HEADER_SIZE, pi_wav );
846 static int A52Init( demux_t *p_demux )
848 demux_sys_t *p_sys = p_demux->p_sys;
850 p_sys->b_big_endian = false;
851 p_sys->i_packet_size = 1024;
853 const uint8_t *p_peek;
855 /* peek the begining */
856 if( stream_Peek( p_demux->s, &p_peek, VLC_A52_HEADER_SIZE ) >= VLC_A52_HEADER_SIZE )
858 A52CheckSync( p_peek, &p_sys->b_big_endian, NULL, true );
863 /*****************************************************************************
865 *****************************************************************************/
866 static int DtsCheckSync( const uint8_t *p_peek, int *pi_samples )
868 /* TODO return frame size for robustness */
870 /* 14 bits, little endian version of the bitstream */
871 if( p_peek[0] == 0xff && p_peek[1] == 0x1f &&
872 p_peek[2] == 0x00 && p_peek[3] == 0xe8 &&
873 (p_peek[4] & 0xf0) == 0xf0 && p_peek[5] == 0x07 )
877 /* 14 bits, big endian version of the bitstream */
878 else if( p_peek[0] == 0x1f && p_peek[1] == 0xff &&
879 p_peek[2] == 0xe8 && p_peek[3] == 0x00 &&
880 p_peek[4] == 0x07 && (p_peek[5] & 0xf0) == 0xf0)
884 /* 16 bits, big endian version of the bitstream */
885 else if( p_peek[0] == 0x7f && p_peek[1] == 0xfe &&
886 p_peek[2] == 0x80 && p_peek[3] == 0x01 )
890 /* 16 bits, little endian version of the bitstream */
891 else if( p_peek[0] == 0xfe && p_peek[1] == 0x7f &&
892 p_peek[2] == 0x01 && p_peek[3] == 0x80 )
897 VLC_UNUSED(pi_samples);
901 static int DtsProbe( demux_t *p_demux, int64_t *pi_offset )
903 const char *ppsz_name[] = { "dts", NULL };
904 const int pi_wav[] = { WAVE_FORMAT_PCM, WAVE_FORMAT_DTS, WAVE_FORMAT_UNKNOWN };
906 return GenericProbe( p_demux, pi_offset, ppsz_name, DtsCheckSync, 11, pi_wav );
908 static int DtsInit( demux_t *p_demux )
910 demux_sys_t *p_sys = p_demux->p_sys;
912 p_sys->i_packet_size = 16384;
917 /*****************************************************************************
919 *****************************************************************************/
920 static int MlpCheckSync( const uint8_t *p_peek, int *pi_samples )
922 if( p_peek[4+0] != 0xf8 || p_peek[4+1] != 0x72 || p_peek[4+2] != 0x6f )
925 if( p_peek[4+3] != 0xba && p_peek[4+3] != 0xbb )
928 /* TODO checksum and real size for robustness */
929 VLC_UNUSED(pi_samples);
932 static int MlpProbe( demux_t *p_demux, int64_t *pi_offset )
934 const char *ppsz_name[] = { "mlp", "thd", NULL };
935 const int pi_wav[] = { WAVE_FORMAT_PCM, WAVE_FORMAT_UNKNOWN };
937 return GenericProbe( p_demux, pi_offset, ppsz_name, MlpCheckSync, 4+28+16*4, pi_wav );
939 static int MlpInit( demux_t *p_demux )
942 demux_sys_t *p_sys = p_demux->p_sys;
944 p_sys->i_packet_size = 4096;
949 /*****************************************************************************
951 *****************************************************************************/
952 static int VideoInit( demux_t *p_demux )
954 demux_sys_t *p_sys = p_demux->p_sys;
956 p_sys->i_packet_size = 4096;