Commit 2226f517 authored by Francois Cartegnie's avatar Francois Cartegnie

demux: ts: fully probe TopField VDR headers and set service id (fix #11034)

parent 665b85ad
......@@ -38,6 +38,7 @@ Demuxers:
* Support WMV and WMAV in MP4/mov, aka Flip4Mac files
* Support bitmap audio channel reordering in MP4/mov
* Support AlbumArtist and DiscNumber metadata
* Fixed selecting recorded program from TopField TS files
Stream filter:
* Added ARIB STD-B25 TS streams decoder
......
......@@ -436,17 +436,79 @@ static void SetPrgFilter( demux_t *, int i_prg, bool b_selected );
#define TS_PACKET_SIZE_204 204
#define TS_PACKET_SIZE_MAX 204
static int DetectPacketSize( demux_t *p_demux, int *pi_header_size )
static int DetectPacketSize( demux_t *p_demux, int *pi_header_size, int i_offset )
{
const uint8_t *p_peek;
if( stream_Peek( p_demux->s,
&p_peek, TS_PACKET_SIZE_MAX ) < TS_PACKET_SIZE_MAX )
&p_peek, i_offset + TS_PACKET_SIZE_MAX ) < i_offset + TS_PACKET_SIZE_MAX )
return -1;
for( int i_sync = 0; i_sync < TS_PACKET_SIZE_MAX; i_sync++ )
{
if( p_peek[i_offset + i_sync] != 0x47 )
continue;
/* Check next 3 sync bytes */
int i_peek = i_offset + TS_PACKET_SIZE_MAX * 3 + i_sync + 1;
if( ( stream_Peek( p_demux->s, &p_peek, i_peek ) ) < i_peek )
{
msg_Err( p_demux, "cannot peek" );
return -1;
}
if( p_peek[i_offset + i_sync + 1 * TS_PACKET_SIZE_188] == 0x47 &&
p_peek[i_offset + i_sync + 2 * TS_PACKET_SIZE_188] == 0x47 &&
p_peek[i_offset + i_sync + 3 * TS_PACKET_SIZE_188] == 0x47 )
{
return TS_PACKET_SIZE_188;
}
else if( p_peek[i_offset + i_sync + 1 * TS_PACKET_SIZE_192] == 0x47 &&
p_peek[i_offset + i_sync + 2 * TS_PACKET_SIZE_192] == 0x47 &&
p_peek[i_offset + i_sync + 3 * TS_PACKET_SIZE_192] == 0x47 )
{
if( i_sync == 4 )
{
*pi_header_size = 4; /* BluRay TS packets have 4-byte header */
}
return TS_PACKET_SIZE_192;
}
else if( p_peek[i_offset + i_sync + 1 * TS_PACKET_SIZE_204] == 0x47 &&
p_peek[i_offset + i_sync + 2 * TS_PACKET_SIZE_204] == 0x47 &&
p_peek[i_offset + i_sync + 3 * TS_PACKET_SIZE_204] == 0x47 )
{
return TS_PACKET_SIZE_204;
}
}
if( p_demux->b_force )
{
msg_Warn( p_demux, "this does not look like a TS stream, continuing" );
return TS_PACKET_SIZE_188;
}
msg_Dbg( p_demux, "TS module discarded (lost sync)" );
return -1;
}
#define TOPFIELD_HEADER_SIZE 3712
static int DetectPVRHeadersAndHeaderSize( demux_t *p_demux, int *pi_header_size, vdr_info_t *p_vdr )
{
const uint8_t *p_peek;
*pi_header_size = 0;
int i_packet_size = -1;
if( memcmp( p_peek, "TFrc", 4 ) == 0 )
if( stream_Peek( p_demux->s,
&p_peek, TS_PACKET_SIZE_MAX ) < TS_PACKET_SIZE_MAX )
return -1;
if( memcmp( p_peek, "TFrc", 4 ) == 0 &&
stream_Peek( p_demux->s, &p_peek, TOPFIELD_HEADER_SIZE + TS_PACKET_SIZE_MAX )
== TOPFIELD_HEADER_SIZE + TS_PACKET_SIZE_MAX )
{
i_packet_size = DetectPacketSize( p_demux, pi_header_size, TOPFIELD_HEADER_SIZE );
if( i_packet_size != -1 )
{
msg_Dbg( p_demux, "this is a topfield file" );
#if 0
/* I used the TF5000PVR 2004 Firmware .doc header documentation,
* http://www.i-topfield.com/data/product/firmware/Structure%20of%20Recorded%20File%20in%20TF5000PVR%20(Feb%2021%202004).doc
......@@ -510,53 +572,14 @@ static int DetectPacketSize( demux_t *p_demux, int *pi_header_size )
msg_Dbg( p_demux, "extended event text=%s", psz_ext_text );
// 52 bytes reserved Bslbf
#endif
msg_Dbg( p_demux, "this is a topfield file" );
return TS_PACKET_SIZE_188;
}
p_vdr->i_service = GetWBE(&p_peek[18]);
for( int i_sync = 0; i_sync < TS_PACKET_SIZE_MAX; i_sync++ )
{
if( p_peek[i_sync] != 0x47 )
continue;
/* Check next 3 sync bytes */
int i_peek = TS_PACKET_SIZE_MAX * 3 + i_sync + 1;
if( ( stream_Peek( p_demux->s, &p_peek, i_peek ) ) < i_peek )
{
msg_Err( p_demux, "cannot peek" );
return -1;
}
if( p_peek[i_sync + 1 * TS_PACKET_SIZE_188] == 0x47 &&
p_peek[i_sync + 2 * TS_PACKET_SIZE_188] == 0x47 &&
p_peek[i_sync + 3 * TS_PACKET_SIZE_188] == 0x47 )
{
return TS_PACKET_SIZE_188;
}
else if( p_peek[i_sync + 1 * TS_PACKET_SIZE_192] == 0x47 &&
p_peek[i_sync + 2 * TS_PACKET_SIZE_192] == 0x47 &&
p_peek[i_sync + 3 * TS_PACKET_SIZE_192] == 0x47 )
{
if( i_sync == 4 )
{
*pi_header_size = 4; /* BluRay TS packets have 4-byte header */
}
return TS_PACKET_SIZE_192;
}
else if( p_peek[i_sync + 1 * TS_PACKET_SIZE_204] == 0x47 &&
p_peek[i_sync + 2 * TS_PACKET_SIZE_204] == 0x47 &&
p_peek[i_sync + 3 * TS_PACKET_SIZE_204] == 0x47 )
{
return TS_PACKET_SIZE_204;
return i_packet_size;
//return TS_PACKET_SIZE_188;
}
}
if( p_demux->b_force )
{
msg_Warn( p_demux, "this does not look like a TS stream, continuing" );
return TS_PACKET_SIZE_188;
}
msg_Dbg( p_demux, "TS module discarded (lost sync)" );
return -1;
return DetectPacketSize( p_demux, pi_header_size, 0 );
}
#if (DVBPSI_VERSION_INT >= DVBPSI_VERSION_WANTED(1,0,0))
......@@ -617,7 +640,7 @@ static int Open( vlc_object_t *p_this )
vdr_info_t vdr = {0};
/* Search first sync byte */
i_packet_size = DetectPacketSize( p_demux, &i_packet_header_size );
i_packet_size = DetectPVRHeadersAndHeaderSize( p_demux, &i_packet_header_size, &vdr );
if( i_packet_size < 0 )
return VLC_EGENERIC;
......
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