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" )
64 add_shortcut( "mp4a" )
70 add_shortcut( "eac3" )
78 set_description( N_("MPEG-4 video" ) )
79 set_capability( "demux", 0 )
80 set_callbacks( OpenVideo, Close )
81 add_float( "es-fps", 25, NULL, FPS_TEXT, FPS_LONGTEXT, false )
84 add_shortcut( "mp4v" )
87 /*****************************************************************************
89 *****************************************************************************/
90 static int Demux ( demux_t * );
91 static int Control( demux_t *, int, va_list );
98 int (*pf_probe)( demux_t *p_demux, int64_t *pi_offset );
99 int (*pf_init)( demux_t *p_demux );
109 decoder_t *p_packetizer;
112 mtime_t i_time_offset;
116 bool b_estimate_bitrate;
117 int i_bitrate_avg; /* extracted from Xing header */
119 bool b_initial_sync_failed;
123 int64_t i_stream_offset;
137 static int MpgaProbe( demux_t *p_demux, int64_t *pi_offset );
138 static int MpgaInit( demux_t *p_demux );
140 static int AacProbe( demux_t *p_demux, int64_t *pi_offset );
141 static int AacInit( demux_t *p_demux );
143 static int EA52Probe( demux_t *p_demux, int64_t *pi_offset );
144 static int A52Probe( demux_t *p_demux, int64_t *pi_offset );
145 static int A52Init( demux_t *p_demux );
147 static int DtsProbe( demux_t *p_demux, int64_t *pi_offset );
148 static int DtsInit( demux_t *p_demux );
150 static int MlpProbe( demux_t *p_demux, int64_t *pi_offset );
151 static int MlpInit( demux_t *p_demux );
153 static const codec_t p_codecs[] = {
154 { VLC_CODEC_MP4A, false, "mp4 audio", AacProbe, AacInit },
155 { VLC_CODEC_MPGA, false, "mpeg audio", MpgaProbe, MpgaInit },
156 { VLC_CODEC_A52, true, "a52 audio", A52Probe, A52Init },
157 { VLC_CODEC_EAC3, true, "eac3 audio", EA52Probe, A52Init },
158 { VLC_CODEC_DTS, false, "dts audio", DtsProbe, DtsInit },
159 { VLC_CODEC_TRUEHD, false, "mlp audio", MlpProbe, MlpInit },
161 { 0, false, NULL, NULL, NULL }
164 static int VideoInit( demux_t *p_demux );
166 static const codec_t codec_m4v = {
167 VLC_CODEC_MP4V, false, "mp4 video", NULL, VideoInit
170 /*****************************************************************************
171 * OpenCommon: initializes demux structures
172 *****************************************************************************/
173 static int OpenCommon( demux_t *p_demux,
174 int i_cat, const codec_t *p_codec, int64_t i_bs_offset )
180 DEMUX_INIT_COMMON(); p_sys = p_demux->p_sys;
181 memset( p_sys, 0, sizeof( demux_sys_t ) );
182 p_sys->codec = *p_codec;
184 p_sys->b_start = true;
185 p_sys->i_stream_offset = i_bs_offset;
186 p_sys->b_estimate_bitrate = true;
187 p_sys->i_bitrate_avg = 0;
188 p_sys->b_big_endian = false;
189 p_sys->f_fps = var_InheritFloat( p_demux, "es-fps" );
191 if( stream_Seek( p_demux->s, p_sys->i_stream_offset ) )
197 if( p_sys->codec.pf_init( p_demux ) )
203 msg_Dbg( p_demux, "detected format %4.4s", (const char*)&p_sys->codec.i_codec );
205 /* Load the audio packetizer */
206 es_format_Init( &fmt, i_cat, p_sys->codec.i_codec );
207 p_sys->p_packetizer = demux_PacketizerNew( p_demux, &fmt, p_sys->codec.psz_name );
208 if( !p_sys->p_packetizer )
215 static int OpenAudio( vlc_object_t *p_this )
217 demux_t *p_demux = (demux_t*)p_this;
218 for( int i = 0; p_codecs[i].i_codec != 0; i++ )
221 if( !p_codecs[i].pf_probe( p_demux, &i_offset ) )
222 return OpenCommon( p_demux, AUDIO_ES, &p_codecs[i], i_offset );
226 static int OpenVideo( vlc_object_t *p_this )
228 demux_t *p_demux = (demux_t*)p_this;
230 /* Only m4v is supported for the moment */
231 bool b_m4v_ext = demux_IsPathExtension( p_demux, ".m4v" );
232 bool b_m4v_forced = demux_IsForced( p_demux, "m4v" ) ||
233 demux_IsForced( p_demux, "mp4v" );
234 if( !b_m4v_ext && !b_m4v_forced )
237 const uint8_t *p_peek;
238 if( stream_Peek( p_demux->s, &p_peek, 4 ) < 4 )
240 if( p_peek[0] != 0x00 || p_peek[1] != 0x00 || p_peek[2] != 0x01 )
245 "this doesn't look like an MPEG ES stream, continuing anyway" );
247 return OpenCommon( p_demux, VIDEO_ES, &codec_m4v, 0 );
249 /*****************************************************************************
250 * Demux: reads and demuxes data packets
251 *****************************************************************************
252 * Returns -1 in case of error, 0 in case of EOF, 1 otherwise
253 *****************************************************************************/
254 static int Demux( demux_t *p_demux )
256 demux_sys_t *p_sys = p_demux->p_sys;
257 block_t *p_block_in, *p_block_out;
259 if( p_sys->codec.b_use_word )
261 /* Make sure we are word aligned */
262 int64_t i_pos = stream_Tell( p_demux->s );
264 stream_Read( p_demux->s, NULL, 1 );
267 if( ( p_block_in = stream_Block( p_demux->s, p_sys->i_packet_size ) ) == NULL )
270 if( p_sys->codec.b_use_word && !p_sys->b_big_endian && p_block_in->i_buffer > 0 )
272 /* Convert to big endian */
273 swab( p_block_in->p_buffer, p_block_in->p_buffer, p_block_in->i_buffer );
276 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;
277 p_sys->b_initial_sync_failed = p_sys->b_start; /* Only try to resync once */
279 while( ( p_block_out = p_sys->p_packetizer->pf_packetize( p_sys->p_packetizer, &p_block_in ) ) )
281 p_sys->b_initial_sync_failed = false;
284 block_t *p_next = p_block_out->p_next;
288 p_sys->p_packetizer->fmt_out.b_packetized = true;
289 p_sys->p_es = es_out_Add( p_demux->out,
290 &p_sys->p_packetizer->fmt_out);
293 /* Try the xing header */
294 if( p_sys->xing.i_bytes && p_sys->xing.i_frames &&
295 p_sys->xing.i_frame_samples )
297 p_sys->i_bitrate_avg = p_sys->xing.i_bytes * INT64_C(8) *
298 p_sys->p_packetizer->fmt_out.audio.i_rate /
299 p_sys->xing.i_frames / p_sys->xing.i_frame_samples;
301 if( p_sys->i_bitrate_avg > 0 )
302 p_sys->b_estimate_bitrate = false;
304 /* Use the bitrate as initual value */
305 if( p_sys->b_estimate_bitrate )
306 p_sys->i_bitrate_avg = p_sys->p_packetizer->fmt_out.i_bitrate;
308 if( p_sys->p_packetizer->fmt_out.i_cat == VIDEO_ES )
310 if( p_block_out->i_pts <= VLC_TS_INVALID &&
311 p_block_out->i_dts <= VLC_TS_INVALID )
312 p_block_out->i_dts = VLC_TS_0 + p_sys->i_pts + 1000000 / p_sys->f_fps;
313 if( p_block_out->i_dts > VLC_TS_INVALID )
314 p_sys->i_pts = p_block_out->i_dts - VLC_TS_0;
318 p_sys->i_pts = p_block_out->i_pts - VLC_TS_0;
321 /* Re-estimate bitrate */
322 if( p_sys->b_estimate_bitrate && p_sys->i_pts > INT64_C(500000) )
323 p_sys->i_bitrate_avg = 8*INT64_C(1000000)*p_sys->i_bytes/(p_sys->i_pts-1);
324 p_sys->i_bytes += p_block_out->i_buffer;
326 /* Correct timestamp */
327 if( p_block_out->i_pts > VLC_TS_INVALID )
329 p_block_out->i_pts += p_sys->i_time_offset;
331 if( p_block_out->i_dts > VLC_TS_INVALID )
333 p_block_out->i_dts += p_sys->i_time_offset;
334 es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block_out->i_dts );
337 es_out_Send( p_demux->out, p_sys->p_es, p_block_out );
339 p_block_out = p_next;
343 if( p_sys->b_initial_sync_failed )
344 msg_Dbg( p_demux, "did not sync on first block" );
345 p_sys->b_start = false;
349 /*****************************************************************************
350 * Close: frees unused data
351 *****************************************************************************/
352 static void Close( vlc_object_t * p_this )
354 demux_t *p_demux = (demux_t*)p_this;
355 demux_sys_t *p_sys = p_demux->p_sys;
357 demux_PacketizerDestroy( p_sys->p_packetizer );
361 /*****************************************************************************
363 *****************************************************************************/
364 static int Control( demux_t *p_demux, int i_query, va_list args )
366 demux_sys_t *p_sys = p_demux->p_sys;
372 va_copy ( args_save, args );
376 case DEMUX_HAS_UNSUPPORTED_META:
377 pb_bool = (bool*)va_arg( args, bool* );
382 pi64 = (int64_t*)va_arg( args, int64_t * );
383 *pi64 = p_sys->i_pts + p_sys->i_time_offset;
386 case DEMUX_GET_LENGTH:
387 i_ret = demux_vaControlHelper( p_demux->s, p_sys->i_stream_offset, -1,
388 p_sys->i_bitrate_avg, 1, i_query,
390 /* No bitrate, we can't have it precisely, but we can compute
391 * a raw approximation with time/position */
392 if( i_ret && !p_sys->i_bitrate_avg )
394 float f_pos = (double)(uint64_t)( stream_Tell( p_demux->s ) ) /
395 (double)(uint64_t)( stream_Size( p_demux->s ) );
396 /* The first few seconds are guaranteed to be very whacky,
397 * don't bother trying ... Too bad */
399 (p_sys->i_pts + p_sys->i_time_offset) < 8000000 )
402 pi64 = (int64_t *)va_arg( args_save, int64_t * );
403 *pi64 = (p_sys->i_pts + p_sys->i_time_offset) / f_pos;
410 /* FIXME TODO: implement a high precision seek (with mp3 parsing)
411 * needed for multi-input */
413 i_ret = demux_vaControlHelper( p_demux->s, p_sys->i_stream_offset, -1,
414 p_sys->i_bitrate_avg, 1, i_query,
416 if( !i_ret && p_sys->i_bitrate_avg > 0 &&
417 (i_query == DEMUX_SET_POSITION || i_query == DEMUX_SET_TIME) )
419 int64_t i_time = INT64_C(8000000) * ( stream_Tell(p_demux->s) - p_sys->i_stream_offset ) /
420 p_sys->i_bitrate_avg;
422 /* Fix time_offset */
424 p_sys->i_time_offset = i_time - p_sys->i_pts;
430 /*****************************************************************************
432 *****************************************************************************/
433 #define WAV_PROBE_SIZE (512*1024)
434 static int WavSkipHeader( demux_t *p_demux, int *pi_skip, const int pi_format[] )
436 const uint8_t *p_peek;
442 /* Check if we are dealing with a WAV file */
443 if( stream_Peek( p_demux->s, &p_peek, 12+8 ) != 12 + 8 )
446 if( memcmp( p_peek, "RIFF", 4 ) || memcmp( &p_peek[8], "WAVE", 4 ) )
449 /* Find the wave format header */
451 while( memcmp( p_peek + i_peek - 8, "fmt ", 4 ) )
453 uint32_t i_len = GetDWLE( p_peek + i_peek - 4 );
454 if( i_len > WAV_PROBE_SIZE || i_peek + i_len > WAV_PROBE_SIZE )
458 if( stream_Peek( p_demux->s, &p_peek, i_peek ) != i_peek )
462 /* Sanity check the wave format header */
463 uint32_t i_len = GetDWLE( p_peek + i_peek - 4 );
464 if( i_len > WAV_PROBE_SIZE )
468 if( stream_Peek( p_demux->s, &p_peek, i_peek ) != i_peek )
470 const int i_format = GetWLE( p_peek + i_peek - i_len - 8 /* wFormatTag */ );
472 for( i_format_idx = 0; pi_format[i_format_idx] != WAVE_FORMAT_UNKNOWN; i_format_idx++ )
474 if( i_format == pi_format[i_format_idx] )
477 if( pi_format[i_format_idx] == WAVE_FORMAT_UNKNOWN )
480 if( i_format == WAVE_FORMAT_PCM )
482 if( GetWLE( p_peek + i_peek - i_len - 6 /* nChannels */ ) != 2 )
484 if( GetDWLE( p_peek + i_peek - i_len - 4 /* nSamplesPerSec */ ) !=
489 /* Skip the wave header */
490 while( memcmp( p_peek + i_peek - 8, "data", 4 ) )
492 uint32_t i_len = GetDWLE( p_peek + i_peek - 4 );
493 if( i_len > WAV_PROBE_SIZE || i_peek + i_len > WAV_PROBE_SIZE )
497 if( stream_Peek( p_demux->s, &p_peek, i_peek ) != i_peek )
504 static int GenericProbe( demux_t *p_demux, int64_t *pi_offset,
505 const char * ppsz_name[],
506 int (*pf_check)( const uint8_t *, int * ), int i_check_size,
507 const int pi_wav_format[] )
512 const uint8_t *p_peek;
515 b_forced_demux = false;
516 for( int i = 0; ppsz_name[i] != NULL; i++ )
518 b_forced_demux |= demux_IsForced( p_demux, ppsz_name[i] );
521 i_offset = stream_Tell( p_demux->s );
523 if( WavSkipHeader( p_demux, &i_skip, pi_wav_format ) )
525 if( !b_forced_demux )
528 const bool b_wav = i_skip > 0;
531 * It is common that wav files have some sort of garbage at the begining
532 * We suppose that 8000 will be larger than any frame (for which pf_check
535 const int i_probe = i_skip + i_check_size + 8000 + ( b_wav ? 8000 : 0);
536 const int i_peek = stream_Peek( p_demux->s, &p_peek, i_probe );
537 if( i_peek < i_skip + i_check_size )
539 msg_Err( p_demux, "cannot peek" );
544 if( i_skip + i_check_size > i_peek )
546 if( !b_forced_demux )
551 int i_size = pf_check( &p_peek[i_skip], &i_samples );
557 /* If we have the frame size, check the next frame for
559 * The second test is because some .wav have paddings
562 for( int t = 0; t < 1 + !!b_wav; t++ )
565 i_size = i_samples * 2 * 2;
566 if( i_skip + i_check_size + i_size <= i_peek )
568 b_ok = pf_check( &p_peek[i_skip+i_size], NULL ) >= 0;
577 if( !b_wav && !b_forced_demux )
581 *pi_offset = i_offset + i_skip;
585 /*****************************************************************************
587 *****************************************************************************/
588 static int MpgaCheckSync( const uint8_t *p_peek )
590 uint32_t h = GetDWBE( p_peek );
592 if( ((( h >> 21 )&0x07FF) != 0x07FF ) /* header sync */
593 || (((h >> 17)&0x03) == 0 ) /* valid layer ?*/
594 || (((h >> 12)&0x0F) == 0x0F )
595 || (((h >> 12)&0x0F) == 0x00 ) /* valid bitrate ? */
596 || (((h >> 10) & 0x03) == 0x03 ) /* valide sampling freq ? */
597 || ((h & 0x03) == 0x02 )) /* valid emphasis ? */
604 #define MPGA_VERSION( h ) ( 1 - (((h)>>19)&0x01) )
605 #define MPGA_MODE(h) (((h)>> 6)&0x03)
607 static int MpgaGetFrameSamples( uint32_t h )
609 const int i_layer = 3 - (((h)>>17)&0x03);
617 return MPGA_VERSION(h) ? 576 : 1152;
623 static int MpgaProbe( demux_t *p_demux, int64_t *pi_offset )
625 const int pi_wav[] = { WAVE_FORMAT_MPEG, WAVE_FORMAT_MPEGLAYER3, WAVE_FORMAT_UNKNOWN };
630 const uint8_t *p_peek;
633 b_forced = demux_IsPathExtension( p_demux, ".mp3" );
634 b_forced_demux = demux_IsForced( p_demux, "mp3" ) ||
635 demux_IsForced( p_demux, "mpga" );
637 i_offset = stream_Tell( p_demux->s );
639 if( WavSkipHeader( p_demux, &i_skip, pi_wav ) )
641 if( !b_forced_demux )
647 if( stream_Peek( p_demux->s, &p_peek, i_skip + 4 ) < i_skip + 4 )
650 if( !MpgaCheckSync( &p_peek[i_skip] ) )
655 if( !b_forced_demux && !b_forced )
658 i_peek = stream_Peek( p_demux->s, &p_peek, i_skip + 8096 );
659 while( i_skip + 4 < i_peek )
661 if( MpgaCheckSync( &p_peek[i_skip] ) )
668 if( !b_ok && !b_forced_demux )
671 *pi_offset = i_offset + i_skip;
675 static void MpgaXingSkip( const uint8_t **pp_xing, int *pi_xing, int i_count )
677 if(i_count > *pi_xing )
680 (*pp_xing) += i_count;
681 (*pi_xing) -= i_count;
684 static uint32_t MpgaXingGetDWBE( const uint8_t **pp_xing, int *pi_xing, uint32_t i_default )
689 uint32_t v = GetDWBE( *pp_xing );
691 MpgaXingSkip( pp_xing, pi_xing, 4 );
696 static int MpgaInit( demux_t *p_demux )
698 demux_sys_t *p_sys = p_demux->p_sys;
700 const uint8_t *p_peek;
704 p_sys->i_packet_size = 1024;
706 /* Load a potential xing header */
707 i_peek = stream_Peek( p_demux->s, &p_peek, 4 + 1024 );
708 if( i_peek < 4 + 21 )
711 const uint32_t header = GetDWBE( p_peek );
712 if( !MpgaCheckSync( p_peek ) )
716 const uint8_t *p_xing = p_peek;
720 if( MPGA_VERSION( header ) == 0 )
721 i_skip = MPGA_MODE( header ) != 3 ? 36 : 21;
723 i_skip = MPGA_MODE( header ) != 3 ? 21 : 13;
725 if( i_skip + 8 >= i_xing || memcmp( &p_xing[i_skip], "Xing", 4 ) )
728 const uint32_t i_flags = GetDWBE( &p_xing[i_skip+4] );
730 MpgaXingSkip( &p_xing, &i_xing, i_skip + 8 );
733 p_sys->xing.i_frames = MpgaXingGetDWBE( &p_xing, &i_xing, 0 );
735 p_sys->xing.i_bytes = MpgaXingGetDWBE( &p_xing, &i_xing, 0 );
736 if( i_flags&0x04 ) /* TODO Support XING TOC to improve seeking accuracy */
737 MpgaXingSkip( &p_xing, &i_xing, 100 );
740 /* FIXME: doesn't return the right bitrage average, at least
742 p_sys->xing.i_bitrate_avg = MpgaXingGetDWBE( &p_xing, &i_xing, 0 );
743 msg_Dbg( p_demux, "xing vbr value present (%d)",
744 p_sys->xing.i_bitrate_avg );
747 if( p_sys->xing.i_frames > 0 && p_sys->xing.i_bytes > 0 )
749 p_sys->xing.i_frame_samples = MpgaGetFrameSamples( header );
750 msg_Dbg( p_demux, "xing frames&bytes value present "
751 "(%d bytes, %d frames, %d samples/frame)",
752 p_sys->xing.i_bytes, p_sys->xing.i_frames,
753 p_sys->xing.i_frame_samples );
758 /*****************************************************************************
760 *****************************************************************************/
761 static int AacProbe( demux_t *p_demux, int64_t *pi_offset )
767 const uint8_t *p_peek;
769 b_forced = demux_IsPathExtension( p_demux, ".aac" ) ||
770 demux_IsPathExtension( p_demux, ".aacp" );
771 b_forced_demux = demux_IsForced( p_demux, "m4a" ) ||
772 demux_IsForced( p_demux, "aac" ) ||
773 demux_IsForced( p_demux, "mp4a" );
775 if( !b_forced_demux && !b_forced )
778 i_offset = stream_Tell( p_demux->s );
780 /* peek the begining (10 is for adts header) */
781 if( stream_Peek( p_demux->s, &p_peek, 10 ) < 10 )
783 msg_Err( p_demux, "cannot peek" );
786 if( !strncmp( (char *)p_peek, "ADIF", 4 ) )
788 msg_Err( p_demux, "ADIF file. Not yet supported. (Please report)" );
792 *pi_offset = i_offset;
795 static int AacInit( demux_t *p_demux )
797 demux_sys_t *p_sys = p_demux->p_sys;
799 p_sys->i_packet_size = 4096;
805 /*****************************************************************************
807 *****************************************************************************/
808 static int A52CheckSync( const uint8_t *p_peek, bool *p_big_endian, int *pi_samples, bool b_eac3 )
810 vlc_a52_header_t header;
811 uint8_t p_tmp[VLC_A52_HEADER_SIZE];
813 *p_big_endian = p_peek[0] == 0x0b && p_peek[1] == 0x77;
816 swab( p_peek, p_tmp, VLC_A52_HEADER_SIZE );
820 if( vlc_a52_header_Parse( &header, p_peek, VLC_A52_HEADER_SIZE ) )
823 if( !header.b_eac3 != !b_eac3 )
826 *pi_samples = header.i_samples;
827 return header.i_size;
829 static int EA52CheckSyncProbe( const uint8_t *p_peek, int *pi_samples )
832 return A52CheckSync( p_peek, &b_dummy, pi_samples, true );
835 static int EA52Probe( demux_t *p_demux, int64_t *pi_offset )
837 const char *ppsz_name[] = { "eac3", NULL };
838 const int pi_wav[] = { WAVE_FORMAT_PCM, WAVE_FORMAT_A52, WAVE_FORMAT_UNKNOWN };
840 return GenericProbe( p_demux, pi_offset, ppsz_name, EA52CheckSyncProbe, VLC_A52_HEADER_SIZE, pi_wav );
843 static int A52CheckSyncProbe( const uint8_t *p_peek, int *pi_samples )
846 return A52CheckSync( p_peek, &b_dummy, pi_samples, false );
849 static int A52Probe( demux_t *p_demux, int64_t *pi_offset )
851 const char *ppsz_name[] = { "a52", "ac3", NULL };
852 const int pi_wav[] = { WAVE_FORMAT_PCM, WAVE_FORMAT_A52, WAVE_FORMAT_UNKNOWN };
854 return GenericProbe( p_demux, pi_offset, ppsz_name, A52CheckSyncProbe, VLC_A52_HEADER_SIZE, pi_wav );
857 static int A52Init( demux_t *p_demux )
859 demux_sys_t *p_sys = p_demux->p_sys;
861 p_sys->b_big_endian = false;
862 p_sys->i_packet_size = 1024;
864 const uint8_t *p_peek;
866 /* peek the begining */
867 if( stream_Peek( p_demux->s, &p_peek, VLC_A52_HEADER_SIZE ) >= VLC_A52_HEADER_SIZE )
869 A52CheckSync( p_peek, &p_sys->b_big_endian, NULL, true );
874 /*****************************************************************************
876 *****************************************************************************/
877 static int DtsCheckSync( const uint8_t *p_peek, int *pi_samples )
879 /* TODO return frame size for robustness */
881 /* 14 bits, little endian version of the bitstream */
882 if( p_peek[0] == 0xff && p_peek[1] == 0x1f &&
883 p_peek[2] == 0x00 && p_peek[3] == 0xe8 &&
884 (p_peek[4] & 0xf0) == 0xf0 && p_peek[5] == 0x07 )
888 /* 14 bits, big endian version of the bitstream */
889 else if( p_peek[0] == 0x1f && p_peek[1] == 0xff &&
890 p_peek[2] == 0xe8 && p_peek[3] == 0x00 &&
891 p_peek[4] == 0x07 && (p_peek[5] & 0xf0) == 0xf0)
895 /* 16 bits, big endian version of the bitstream */
896 else if( p_peek[0] == 0x7f && p_peek[1] == 0xfe &&
897 p_peek[2] == 0x80 && p_peek[3] == 0x01 )
901 /* 16 bits, little endian version of the bitstream */
902 else if( p_peek[0] == 0xfe && p_peek[1] == 0x7f &&
903 p_peek[2] == 0x01 && p_peek[3] == 0x80 )
908 VLC_UNUSED(pi_samples);
912 static int DtsProbe( demux_t *p_demux, int64_t *pi_offset )
914 const char *ppsz_name[] = { "dts", NULL };
915 const int pi_wav[] = { WAVE_FORMAT_PCM, WAVE_FORMAT_DTS, WAVE_FORMAT_UNKNOWN };
917 return GenericProbe( p_demux, pi_offset, ppsz_name, DtsCheckSync, 11, pi_wav );
919 static int DtsInit( demux_t *p_demux )
921 demux_sys_t *p_sys = p_demux->p_sys;
923 p_sys->i_packet_size = 16384;
928 /*****************************************************************************
930 *****************************************************************************/
931 static int MlpCheckSync( const uint8_t *p_peek, int *pi_samples )
933 if( p_peek[4+0] != 0xf8 || p_peek[4+1] != 0x72 || p_peek[4+2] != 0x6f )
936 if( p_peek[4+3] != 0xba && p_peek[4+3] != 0xbb )
939 /* TODO checksum and real size for robustness */
940 VLC_UNUSED(pi_samples);
943 static int MlpProbe( demux_t *p_demux, int64_t *pi_offset )
945 const char *ppsz_name[] = { "mlp", "thd", NULL };
946 const int pi_wav[] = { WAVE_FORMAT_PCM, WAVE_FORMAT_UNKNOWN };
948 return GenericProbe( p_demux, pi_offset, ppsz_name, MlpCheckSync, 4+28+16*4, pi_wav );
950 static int MlpInit( demux_t *p_demux )
953 demux_sys_t *p_sys = p_demux->p_sys;
955 p_sys->i_packet_size = 4096;
960 /*****************************************************************************
962 *****************************************************************************/
963 static int VideoInit( demux_t *p_demux )
965 demux_sys_t *p_sys = p_demux->p_sys;
967 p_sys->i_packet_size = 4096;