+ case DEMUX_HAS_UNSUPPORTED_META:
+ pb_bool = (bool*)va_arg( args, bool* );
+ *pb_bool = true;
+ return VLC_SUCCESS;
+
+ case DEMUX_GET_TIME:
+ pi64 = (int64_t*)va_arg( args, int64_t * );
+ *pi64 = p_sys->i_pts + p_sys->i_time_offset;
+ return VLC_SUCCESS;
+
+ case DEMUX_GET_LENGTH:
+ i_ret = demux_vaControlHelper( p_demux->s, p_sys->i_stream_offset, -1,
+ p_sys->i_bitrate_avg, 1, i_query,
+ args );
+ /* No bitrate, we can't have it precisely, but we can compute
+ * a raw approximation with time/position */
+ if( i_ret && !p_sys->i_bitrate_avg )
+ {
+ float f_pos = (double)(uint64_t)( stream_Tell( p_demux->s ) ) /
+ (double)(uint64_t)( stream_Size( p_demux->s ) );
+ /* The first few seconds are guaranteed to be very whacky,
+ * don't bother trying ... Too bad */
+ if( f_pos < 0.01 ||
+ (p_sys->i_pts + p_sys->i_time_offset) < 8000000 )
+ return VLC_EGENERIC;
+
+ pi64 = (int64_t *)va_arg( args_save, int64_t * );
+ *pi64 = (p_sys->i_pts + p_sys->i_time_offset) / f_pos;
+ return VLC_SUCCESS;
+ }
+ va_end( args_save );
+ return i_ret;
+
+ case DEMUX_SET_TIME:
+ /* FIXME TODO: implement a high precision seek (with mp3 parsing)
+ * needed for multi-input */
+ default:
+ i_ret = demux_vaControlHelper( p_demux->s, p_sys->i_stream_offset, -1,
+ p_sys->i_bitrate_avg, 1, i_query,
+ args );
+ if( !i_ret && p_sys->i_bitrate_avg > 0 &&
+ (i_query == DEMUX_SET_POSITION || i_query == DEMUX_SET_TIME) )
+ {
+ int64_t i_time = INT64_C(8000000) * ( stream_Tell(p_demux->s) - p_sys->i_stream_offset ) /
+ p_sys->i_bitrate_avg;
+
+ /* Fix time_offset */
+ if( i_time >= 0 )
+ p_sys->i_time_offset = i_time - p_sys->i_pts;
+ }
+ return i_ret;
+ }
+}
+
+/*****************************************************************************
+ * Mpeg I/II Audio
+ *****************************************************************************/
+static int MpgaCheckSync( const uint8_t *p_peek )
+{
+ uint32_t h = GetDWBE( p_peek );
+
+ if( ((( h >> 21 )&0x07FF) != 0x07FF ) /* header sync */
+ || (((h >> 17)&0x03) == 0 ) /* valid layer ?*/
+ || (((h >> 12)&0x0F) == 0x0F )
+ || (((h >> 12)&0x0F) == 0x00 ) /* valid bitrate ? */
+ || (((h >> 10) & 0x03) == 0x03 ) /* valide sampling freq ? */
+ || ((h & 0x03) == 0x02 )) /* valid emphasis ? */
+ {
+ return false;
+ }
+ return true;
+}
+
+#define MPGA_VERSION( h ) ( 1 - (((h)>>19)&0x01) )
+#define MPGA_MODE(h) (((h)>> 6)&0x03)
+
+static int MpgaGetFrameSamples( uint32_t h )
+{
+ const int i_layer = 3 - (((h)>>17)&0x03);
+ switch( i_layer )
+ {
+ case 0:
+ return 384;
+ case 1:
+ return 1152;
+ case 2:
+ return MPGA_VERSION(h) ? 576 : 1152;
+ default:
+ return 0;
+ }
+}
+
+static int MpgaProbe( demux_t *p_demux, int64_t *pi_offset )
+{
+ bool b_forced;
+ bool b_forced_demux;
+ int64_t i_offset;
+
+ const uint8_t *p_peek;
+
+ b_forced = demux_IsPathExtension( p_demux, ".mp3" );
+ b_forced_demux = demux_IsForced( p_demux, "mp3" ) ||
+ demux_IsForced( p_demux, "mpga" );
+
+ i_offset = stream_Tell( p_demux->s );
+ if( stream_Peek( p_demux->s, &p_peek, 4 ) < 4 )
+ return VLC_EGENERIC;
+
+ if( !MpgaCheckSync( p_peek ) )
+ {
+ bool b_ok = false;
+ int i_peek;
+
+ if( !b_forced_demux && !b_forced )
+ return VLC_EGENERIC;
+
+ i_peek = stream_Peek( p_demux->s, &p_peek, 8096 );
+ while( i_peek > 4 )