#include <vlc_plugin.h>
#include <assert.h>
+#include <time.h>
#include <vlc_access.h> /* DVB-specific things */
#include <vlc_demux.h>
#include <vlc_meta.h>
#include <vlc_epg.h>
#include <vlc_charset.h> /* FromCharset, for EIT */
-
-#include <vlc_network.h> /* net_ for ts-out mode */
+#include <vlc_bits.h>
#include "../mux/mpeg/csa.h"
# include <dvbpsi/tot.h>
#include "../mux/mpeg/dvbpsi_compat.h"
+#include "../mux/mpeg/streams.h"
+#include "../mux/mpeg/tsutil.h"
+#include "../mux/mpeg/tables.h"
+
+#include "../codec/opus_header.h"
+
+#include "opus.h"
#undef TS_DEBUG
VLC_FORMAT(1, 2) static void ts_debug(const char *format, ...)
#endif
}
+#ifdef HAVE_ARIBB24
+ #include <aribb24/aribb24.h>
+ #include <aribb24/decoder.h>
+#endif
+
+typedef enum arib_modes_e
+{
+ ARIBMODE_AUTO = -1,
+ ARIBMODE_DISABLED = 0,
+ ARIBMODE_ENABLED = 1
+} arib_modes_e;
+
/*****************************************************************************
* Module descriptor
*****************************************************************************/
" the TS stream, instead of 1, 2, 3, etc. Useful to" \
" do \'#duplicate{..., select=\"es=<pid>\"}\'.")
-#define TSOUT_TEXT N_("Fast udp streaming")
-#define TSOUT_LONGTEXT N_( \
- "Sends TS to specific ip:port by udp (you must know what you are doing).")
-
-#define MTUOUT_TEXT N_("MTU for out mode")
-#define MTUOUT_LONGTEXT N_("MTU for out mode.")
-
#define CSA_TEXT N_("CSA Key")
#define CSA_LONGTEXT N_("CSA encryption key. This must be a " \
"16 char string (8 hexadecimal bytes).")
#define PCR_TEXT N_("Trust in-stream PCR")
#define PCR_LONGTEXT N_("Use the stream PCR as a reference.")
+static const int const arib_mode_list[] =
+ { ARIBMODE_AUTO, ARIBMODE_ENABLED, ARIBMODE_DISABLED };
+static const char *const arib_mode_list_text[] =
+ { N_("Auto"), N_("Enabled"), N_("Disabled") };
+
+#define SUPPORT_ARIB_TEXT N_("ARIB STD-B24 mode")
+#define SUPPORT_ARIB_LONGTEXT N_( \
+ "Forces ARIB STD-B24 mode for decoding characters." \
+ "This feature affects EPG information and subtitles." )
+
vlc_module_begin ()
set_description( N_("MPEG Transport Stream demuxer") )
set_shortname ( "MPEG-TS" )
change_safe()
add_bool( "ts-es-id-pid", true, PID_TEXT, PID_LONGTEXT, true )
change_safe()
- add_string( "ts-out", NULL, TSOUT_TEXT, TSOUT_LONGTEXT, true )
- add_integer( "ts-out-mtu", 1400, MTUOUT_TEXT,
- MTUOUT_LONGTEXT, true )
-
+ add_obsolete_string( "ts-out" ) /* since 2.2.0 */
+ add_obsolete_integer( "ts-out-mtu" ) /* since 2.2.0 */
add_string( "ts-csa-ck", NULL, CSA_TEXT, CSA_LONGTEXT, true )
change_safe()
add_string( "ts-csa2-ck", NULL, CSA2_TEXT, CSA2_LONGTEXT, true )
add_bool( "ts-split-es", true, SPLIT_ES_TEXT, SPLIT_ES_LONGTEXT, false )
add_bool( "ts-seek-percent", false, SEEK_PERCENT_TEXT, SEEK_PERCENT_LONGTEXT, true )
+ add_integer( "ts-arib", ARIBMODE_AUTO, SUPPORT_ARIB_TEXT, SUPPORT_ARIB_LONGTEXT, false )
+ change_integer_list( arib_mode_list, arib_mode_list_text )
+
add_obsolete_bool( "ts-silent" );
set_capability( "demux", 10 )
} es_mpeg4_descriptor_t;
+#define ES_DESCRIPTOR_COUNT 255
typedef struct
{
/* IOD */
char *psz_url;
- es_mpeg4_descriptor_t es_descr[255];
+ es_mpeg4_descriptor_t es_descr[ES_DESCRIPTOR_COUNT];
} iod_descriptor_t;
TS_ES_DATA_TABLE_SECTION
} ts_es_data_type_t;
+typedef enum
+{
+ TS_PMT_REGISTRATION_NONE = 0,
+ TS_PMT_REGISTRATION_HDMV
+} ts_pmt_registration_type_t;
+
typedef struct
{
es_format_t fmt;
ts_es_t **extra_es;
int i_extra_es;
+ struct
+ {
+ vlc_fourcc_t i_fourcc;
+ int i_type;
+ bool b_haspcr;
+ } probed;
} ts_pid_t;
+typedef struct
+{
+ int i_service;
+} vdr_info_t;
+
+#define MIN_ES_PID 4 /* Should be 32.. broken muxers */
+#define MAX_ES_PID 8190
+
struct demux_sys_t
{
+ stream_t *stream;
+ bool b_canseek;
vlc_mutex_t csa_lock;
/* TS packet size (188, 192, 204) */
int i_packet_size;
+ /* Additional TS packet header size (BluRay TS packets have 4-byte header before sync byte) */
+ int i_packet_header_size;
+
/* how many TS packet we read at once */
int i_ts_read;
mtime_t *p_pcrs;
int64_t *p_pos;
+ struct
+ {
+ arib_modes_e e_mode;
+#ifdef HAVE_ARIBB24
+ arib_instance_t *p_instance;
+#endif
+ stream_t *b25stream;
+ } arib;
+
/* All pid */
ts_pid_t pid[8192];
int i_pmt;
ts_pid_t **pmt;
int i_pmt_es;
+ bool b_delay_es_creation;
/* */
bool b_es_id_pid;
int i_csa_pkt_size;
bool b_split_es;
- bool b_udp_out;
- int fd; /* udp socket */
- uint8_t *buffer;
bool b_trust_pcr;
+ bool b_disable_pcr;
/* */
bool b_access_control;
int i_current_program;
vlc_list_t programs_list;
+ struct
+ {
+ /* broken PCR handling */
+ bool b_program_pcr_seen;
+ mtime_t i_first_dts;
+ } pcrfix;
+
+ struct
+ {
+ mtime_t i_first_dts; /* first dts encountered for the stream */
+ int i_timesourcepid; /* which pid we saved the dts from */
+ bool b_pat_deadline; /* set if we haven't seen PAT within 140ms */
+ } patfix;
+
+ vdr_info_t vdr;
+
/* */
bool b_start_record;
};
static void PIDInit ( ts_pid_t *pid, bool b_psi, ts_psi_t *p_owner );
static void PIDClean( demux_t *, ts_pid_t *pid );
-static void PIDFillFormat( ts_es_t *es, int i_stream_type );
+static void PIDFillFormat( es_format_t *fmt, int i_stream_type );
static void PATCallBack( void*, dvbpsi_pat_t * );
static void PMTCallBack( void *data, dvbpsi_pmt_t *p_pmt );
}
static bool GatherData( demux_t *p_demux, ts_pid_t *pid, block_t *p_bk );
+static void AddAndCreateES( demux_t *p_demux, ts_pid_t *pid );
static block_t* ReadTSPacket( demux_t *p_demux );
-static mtime_t GetPCR( block_t *p_pkt );
-static int SeekToPCR( demux_t *p_demux, int64_t i_pos );
static int Seek( demux_t *p_demux, double f_percent );
static void GetFirstPCR( demux_t *p_demux );
static void GetLastPCR( demux_t *p_demux );
static void CheckPCR( demux_t *p_demux );
static void PCRHandle( demux_t *p_demux, ts_pid_t *, block_t * );
+static void PCRFixHandle( demux_t *, block_t * );
+static mtime_t AdjustPTSWrapAround( demux_t *, mtime_t );
static void IODFree( iod_descriptor_t * );
#define TS_PACKET_SIZE_192 192
#define TS_PACKET_SIZE_204 204
#define TS_PACKET_SIZE_MAX 204
-#define TS_TOPFIELD_HEADER 1320
-static int DetectPacketSize( demux_t *p_demux )
+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;
- if( memcmp( p_peek, "TFrc", 4 ) == 0 )
- {
-#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
- * but after the filename the offsets seem to be incorrect. - DJ */
- int i_duration, i_name;
- char *psz_name = xmalloc(25);
- char *psz_event_name;
- char *psz_event_text = xmalloc(130);
- char *psz_ext_text = xmalloc(1025);
-
- // 2 bytes version Uimsbf (4,5)
- // 2 bytes reserved (6,7)
- // 2 bytes duration in minutes Uimsbf (8,9(
- i_duration = (int) (p_peek[8] << 8) | p_peek[9];
- msg_Dbg( p_demux, "Topfield recording length: +/- %d minutes", i_duration);
- // 2 bytes service number in channel list (10, 11)
- // 2 bytes service type Bslbf 0=TV 1=Radio Bslb (12, 13)
- // 4 bytes of reserved + tuner info (14,15,16,17)
- // 2 bytes of Service ID Bslbf (18,19)
- // 2 bytes of PMT PID Uimsbf (20,21)
- // 2 bytes of PCR PID Uimsbf (22,23)
- // 2 bytes of Video PID Uimsbf (24,25)
- // 2 bytes of Audio PID Uimsbf (26,27)
- // 24 bytes filename Bslbf
- memcpy( psz_name, &p_peek[28], 24 );
- psz_name[24] = '\0';
- msg_Dbg( p_demux, "recordingname=%s", psz_name );
- // 1 byte of sat index Uimsbf (52)
- // 3 bytes (1 bit of polarity Bslbf +23 bits reserved)
- // 4 bytes of freq. Uimsbf (56,57,58,59)
- // 2 bytes of symbol rate Uimsbf (60,61)
- // 2 bytes of TS stream ID Uimsbf (62,63)
- // 4 bytes reserved
- // 2 bytes reserved
- // 2 bytes duration Uimsbf (70,71)
- //i_duration = (int) (p_peek[70] << 8) | p_peek[71];
- //msg_Dbg( p_demux, "Topfield 2nd duration field: +/- %d minutes", i_duration);
- // 4 bytes EventID Uimsbf (72-75)
- // 8 bytes of Start and End time info (76-83)
- // 1 byte reserved (84)
- // 1 byte event name length Uimsbf (89)
- i_name = (int)(p_peek[89]&~0x81);
- msg_Dbg( p_demux, "event name length = %d", i_name);
- psz_event_name = xmalloc( i_name+1 );
- // 1 byte parental rating (90)
- // 129 bytes of event text
- memcpy( psz_event_name, &p_peek[91], i_name );
- psz_event_name[i_name] = '\0';
- memcpy( psz_event_text, &p_peek[91+i_name], 129-i_name );
- psz_event_text[129-i_name] = '\0';
- msg_Dbg( p_demux, "event name=%s", psz_event_name );
- msg_Dbg( p_demux, "event text=%s", psz_event_text );
- // 12 bytes reserved (220)
- // 6 bytes reserved
- // 2 bytes Event Text Length Uimsbf
- // 4 bytes EventID Uimsbf
- // FIXME We just have 613 bytes. not enough for this entire text
- // 1024 bytes Extended Event Text Bslbf
- memcpy( psz_ext_text, p_peek+372, 1024 );
- psz_ext_text[1024] = '\0';
- 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;
- }
-
for( int i_sync = 0; i_sync < TS_PACKET_SIZE_MAX; i_sync++ )
{
- if( p_peek[i_sync] != 0x47 )
+ if( p_peek[i_offset + i_sync] != 0x47 )
continue;
/* Check next 3 sync bytes */
- int i_peek = TS_PACKET_SIZE_MAX * 3 + i_sync + 1;
+ 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_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 )
+ 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_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 )
+ 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_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 )
+ 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;
}
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( stream_Peek( p_demux->s,
+ &p_peek, TS_PACKET_SIZE_MAX ) < TS_PACKET_SIZE_MAX )
+ return -1;
+
+ if( memcmp( p_peek, "TFrc", 4 ) == 0 &&
+ p_peek[6] == 0 && memcmp( &p_peek[53], "\x80\x00\x00", 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
+ * but after the filename the offsets seem to be incorrect. - DJ */
+ int i_duration, i_name;
+ char *psz_name = xmalloc(25);
+ char *psz_event_name;
+ char *psz_event_text = xmalloc(130);
+ char *psz_ext_text = xmalloc(1025);
+
+ // 2 bytes version Uimsbf (4,5)
+ // 2 bytes reserved (6,7)
+ // 2 bytes duration in minutes Uimsbf (8,9(
+ i_duration = (int) (p_peek[8] << 8) | p_peek[9];
+ msg_Dbg( p_demux, "Topfield recording length: +/- %d minutes", i_duration);
+ // 2 bytes service number in channel list (10, 11)
+ // 2 bytes service type Bslbf 0=TV 1=Radio Bslb (12, 13)
+ // 4 bytes of reserved + tuner info (14,15,16,17)
+ // 2 bytes of Service ID Bslbf (18,19)
+ // 2 bytes of PMT PID Uimsbf (20,21)
+ // 2 bytes of PCR PID Uimsbf (22,23)
+ // 2 bytes of Video PID Uimsbf (24,25)
+ // 2 bytes of Audio PID Uimsbf (26,27)
+ // 24 bytes filename Bslbf
+ memcpy( psz_name, &p_peek[28], 24 );
+ psz_name[24] = '\0';
+ msg_Dbg( p_demux, "recordingname=%s", psz_name );
+ // 1 byte of sat index Uimsbf (52)
+ // 3 bytes (1 bit of polarity Bslbf +23 bits reserved)
+ // 4 bytes of freq. Uimsbf (56,57,58,59)
+ // 2 bytes of symbol rate Uimsbf (60,61)
+ // 2 bytes of TS stream ID Uimsbf (62,63)
+ // 4 bytes reserved
+ // 2 bytes reserved
+ // 2 bytes duration Uimsbf (70,71)
+ //i_duration = (int) (p_peek[70] << 8) | p_peek[71];
+ //msg_Dbg( p_demux, "Topfield 2nd duration field: +/- %d minutes", i_duration);
+ // 4 bytes EventID Uimsbf (72-75)
+ // 8 bytes of Start and End time info (76-83)
+ // 1 byte reserved (84)
+ // 1 byte event name length Uimsbf (89)
+ i_name = (int)(p_peek[89]&~0x81);
+ msg_Dbg( p_demux, "event name length = %d", i_name);
+ psz_event_name = xmalloc( i_name+1 );
+ // 1 byte parental rating (90)
+ // 129 bytes of event text
+ memcpy( psz_event_name, &p_peek[91], i_name );
+ psz_event_name[i_name] = '\0';
+ memcpy( psz_event_text, &p_peek[91+i_name], 129-i_name );
+ psz_event_text[129-i_name] = '\0';
+ msg_Dbg( p_demux, "event name=%s", psz_event_name );
+ msg_Dbg( p_demux, "event text=%s", psz_event_text );
+ // 12 bytes reserved (220)
+ // 6 bytes reserved
+ // 2 bytes Event Text Length Uimsbf
+ // 4 bytes EventID Uimsbf
+ // FIXME We just have 613 bytes. not enough for this entire text
+ // 1024 bytes Extended Event Text Bslbf
+ memcpy( psz_ext_text, p_peek+372, 1024 );
+ psz_ext_text[1024] = '\0';
+ msg_Dbg( p_demux, "extended event text=%s", psz_ext_text );
+ // 52 bytes reserved Bslbf
+#endif
+ p_vdr->i_service = GetWBE(&p_peek[18]);
+
+ return i_packet_size;
+ //return TS_PACKET_SIZE_188;
+ }
+ }
+
+ return DetectPacketSize( p_demux, pi_header_size, 0 );
+}
+
#if (DVBPSI_VERSION_INT >= DVBPSI_VERSION_WANTED(1,0,0))
static void vlc_dvbpsi_reset( demux_t *p_demux )
{
}
#endif
+static inline mtime_t ExtractPESTimestamp( const uint8_t *p_data )
+{
+ return ((mtime_t)(p_data[ 0]&0x0e ) << 29)|
+ (mtime_t)(p_data[1] << 22)|
+ ((mtime_t)(p_data[2]&0xfe) << 14)|
+ (mtime_t)(p_data[3] << 7)|
+ (mtime_t)(p_data[4] >> 1);
+}
+
+static void ProbePES( demux_t *p_demux, ts_pid_t *pid, const uint8_t *p_pesstart, bool b_adaptfield )
+{
+ demux_sys_t *p_sys = p_demux->p_sys;
+ const uint8_t *p_pes = p_pesstart;
+ pid->probed.i_type = -1;
+
+ if( b_adaptfield )
+ {
+ uint8_t len = *p_pes;
+ p_pes++;
+
+ if(len == 0)
+ {
+ p_pes++; /* stuffing */
+ }
+ else
+ {
+ pid->probed.b_haspcr = ( *p_pes >= 7 && (p_pes[1] & 0x10) );
+ p_pes += len;
+ }
+ }
+
+ if( p_pes - p_pesstart >= TS_PACKET_SIZE_188 - 9)
+ return;
+
+ if( p_pes[0] != 0 || p_pes[1] != 0 || p_pes[2] != 1 )
+ return;
+
+ size_t i_pesextoffset = 8;
+ mtime_t i_dts = -1;
+ if( p_pes[7] & 0x80 ) // PTS
+ {
+ i_pesextoffset += 5;
+ i_dts = ExtractPESTimestamp( &p_pes[9] );
+ }
+ if( p_pes[7] & 0x40 ) // DTS
+ {
+ i_pesextoffset += 5;
+ i_dts = ExtractPESTimestamp( &p_pes[14] );
+ }
+ if( p_pes[7] & 0x20 ) // ESCR
+ i_pesextoffset += 6;
+ if( p_pes[7] & 0x10 ) // ESrate
+ i_pesextoffset += 3;
+ if( p_pes[7] & 0x08 ) // DSM
+ i_pesextoffset += 1;
+ if( p_pes[7] & 0x04 ) // CopyInfo
+ i_pesextoffset += 1;
+ if( p_pes[7] & 0x02 ) // PESCRC
+ i_pesextoffset += 2;
+
+ /* HeaderdataLength */
+ const size_t i_payloadoffset = 8 + 1 + p_pes[8];
+ i_pesextoffset += 1;
+
+ if( p_pes[7] & 0x01 ) // PESExt
+ {
+ size_t i_extension2_offset = 1;
+ if ( p_pes[i_pesextoffset] & 0x80 ) // private data
+ i_extension2_offset += 16;
+ if ( p_pes[i_pesextoffset] & 0x40 ) // pack
+ i_extension2_offset += 1;
+ if ( p_pes[i_pesextoffset] & 0x20 ) // seq
+ i_extension2_offset += 2;
+ if ( p_pes[i_pesextoffset] & 0x10 ) // P-STD
+ i_extension2_offset += 2;
+ if ( p_pes[i_pesextoffset] & 0x01 ) // Extension 2
+ {
+ uint8_t i_len = p_pes[i_pesextoffset + i_extension2_offset] & 0x7F;
+ i_extension2_offset += i_len;
+ }
+ }
+ /* (i_payloadoffset - i_pesextoffset) 0xFF stuffing */
+
+ if( &p_pes[i_payloadoffset] - p_pesstart >= TS_PACKET_SIZE_188 - 4)
+ return;
+
+ const uint8_t *p_data = &p_pes[i_payloadoffset];
+ /* AUDIO STREAM */
+ if(p_pes[3] >= 0xC0 && p_pes[3] <= 0xDF)
+ {
+ if( !memcmp( p_data, "\x7F\xFE\x80\x01", 4 ) )
+ {
+ pid->probed.i_type = 0x06;
+ pid->probed.i_fourcc = VLC_CODEC_DTS;
+ }
+ else if( !memcmp( p_data, "\x0B\x77", 2 ) )
+ {
+ pid->probed.i_type = 0x06;
+ pid->probed.i_fourcc = VLC_CODEC_EAC3;
+ }
+ else if( p_data[0] == 0xFF && (p_data[1] & 0xE0) == 0xE0 )
+ {
+ switch(p_data[1] & 18)
+ {
+ /* 10 - MPEG Version 2 (ISO/IEC 13818-3)
+ 11 - MPEG Version 1 (ISO/IEC 11172-3) */
+ case 0x10:
+ pid->probed.i_type = 0x04;
+ break;
+ case 0x18:
+ pid->probed.i_type = 0x03;
+ default:
+ break;
+ }
+
+ switch(p_data[1] & 6)
+ {
+ /* 01 - Layer III
+ 10 - Layer II
+ 11 - Layer I */
+ case 0x06:
+ pid->probed.i_type = 0x04;
+ pid->probed.i_fourcc = VLC_CODEC_MPGA;
+ break;
+ case 0x04:
+ pid->probed.i_type = 0x04;
+ pid->probed.i_fourcc = VLC_CODEC_MP2;
+ break;
+ case 0x02:
+ pid->probed.i_type = 0x04;
+ pid->probed.i_fourcc = VLC_CODEC_MP3;
+ default:
+ break;
+ }
+ }
+ }
+ /* VIDEO STREAM */
+ else if( p_pes[3] >= 0xE0 && p_pes[3] <= 0xEF )
+ {
+ if( !memcmp( p_data, "\x00\x00\x00", 4 ) )
+ {
+ pid->probed.i_type = 0x1b;
+ pid->probed.i_fourcc = VLC_CODEC_H264;
+ }
+ else if( !memcmp( p_data, "\x00\x00\x01", 4 ) )
+ {
+ pid->probed.i_type = 0x02;
+ pid->probed.i_fourcc = VLC_CODEC_MPGV;
+ }
+ }
+
+ /* Track timestamps and flag missing PAT */
+ if( !p_sys->patfix.i_timesourcepid && i_dts > -1 )
+ {
+ p_sys->patfix.i_first_dts = i_dts;
+ p_sys->patfix.i_timesourcepid = pid->i_pid;
+ }
+ else if( p_sys->patfix.i_timesourcepid == pid->i_pid && i_dts > -1 &&
+ !p_sys->patfix.b_pat_deadline )
+ {
+ if( i_dts - p_sys->patfix.i_first_dts > 9 * 140000 / 100 )
+ p_sys->patfix.b_pat_deadline = true;
+ }
+
+}
+
+static void BuildPATCallback( void *p_opaque, block_t *p_block )
+{
+ ts_pid_t *pat_pid = (ts_pid_t *) p_opaque;
+ dvbpsi_PushPacket( pat_pid->psi->handle, p_block->p_buffer );
+}
+
+static void BuildPMTCallback( void *p_opaque, block_t *p_block )
+{
+ ts_pid_t *program_pid = (ts_pid_t *) p_opaque;
+ while( p_block )
+ {
+ for( int i_prg = 0; i_prg < program_pid->psi->i_prg; i_prg++ )
+ {
+ dvbpsi_PushPacket( program_pid->psi->prg[i_prg]->handle,
+ p_block->p_buffer );
+ }
+ p_block = p_block->p_next;
+ }
+}
+
+static void MissingPATPMTFixup( demux_t *p_demux )
+{
+ demux_sys_t *p_sys = p_demux->p_sys;
+ int i_program_number = 1234;
+ int i_program_pid = 1337;
+ int i_pcr_pid = 0x1FFF;
+ int i_num_pes = 0;
+
+ if( p_sys->pid[i_program_pid].b_seen )
+ {
+ /* Find a free one */
+ for( i_program_pid = MIN_ES_PID;
+ i_program_pid < MAX_ES_PID && p_sys->pid[i_program_pid].b_seen;
+ i_program_pid++ );
+ }
+
+ for( int i = MIN_ES_PID; i < MAX_ES_PID; i++ )
+ {
+ if( !p_sys->pid[i].b_seen ||
+ p_sys->pid[i].probed.i_type == -1 )
+ continue;
+
+ if( i_pcr_pid == 0x1FFF && ( p_sys->pid[i].probed.i_type == 0x03 ||
+ p_sys->pid[i].probed.b_haspcr ) )
+ i_pcr_pid = p_sys->pid[i].i_pid;
+
+ i_num_pes++;
+ }
+
+ if( i_num_pes == 0 )
+ return;
+
+ ts_stream_t patstream =
+ {
+ .i_pid = 0,
+ .i_continuity_counter = 0x10,
+ .b_discontinuity = false
+ };
+
+ ts_stream_t pmtprogramstream =
+ {
+ .i_pid = i_program_pid,
+ .i_continuity_counter = 0x0,
+ .b_discontinuity = false
+ };
+
+ BuildPAT( DVBPSI_HANDLE_PARAM(p_sys->pid[0].psi->handle)
+ &p_sys->pid[0], BuildPATCallback,
+ 0, 1,
+ &patstream,
+ 1, &pmtprogramstream, &i_program_number );
+
+ if( !p_sys->pid[i_program_pid].psi )
+ {
+ msg_Err( p_demux, "PAT creation failed" );
+ return;
+ }
+
+ struct esstreams_t
+ {
+ pes_stream_t pes;
+ ts_stream_t ts;
+ };
+ es_format_t esfmt = {0};
+ struct esstreams_t *esstreams = calloc( i_num_pes, sizeof(struct esstreams_t) );
+ pes_mapped_stream_t *mapped = calloc( i_num_pes, sizeof(pes_mapped_stream_t) );
+ if( esstreams && mapped )
+ {
+ int j=0;
+ for( int i = MIN_ES_PID; i < MAX_ES_PID; i++ )
+ {
+ if( !p_sys->pid[i].b_seen ||
+ p_sys->pid[i].probed.i_type == -1 )
+ continue;
+
+ esstreams[j].pes.i_stream_type = p_sys->pid[i].probed.i_type;
+ esstreams[j].pes.i_stream_type = p_sys->pid[i].probed.i_type;
+ esstreams[j].ts.i_pid = p_sys->pid[i].i_pid;
+ mapped[j].pes = &esstreams[j].pes;
+ mapped[j].ts = &esstreams[j].ts;
+ mapped[j].fmt = &esfmt;
+ j++;
+ }
+
+ BuildPMT( DVBPSI_HANDLE_PARAM(p_sys->pid[0].psi->handle) VLC_OBJECT(p_demux),
+ &p_sys->pid[i_program_pid], BuildPMTCallback,
+ 0, 1,
+ i_pcr_pid,
+ NULL,
+ 1, &pmtprogramstream, &i_program_number,
+ i_num_pes, mapped );
+ }
+ free(esstreams);
+ free(mapped);
+}
+
/*****************************************************************************
* Open
*****************************************************************************/
demux_t *p_demux = (demux_t*)p_this;
demux_sys_t *p_sys;
- int i_packet_size;
+ int i_packet_size, i_packet_header_size = 0;
ts_pid_t *pat;
+ vdr_info_t vdr = {0};
/* Search first sync byte */
- i_packet_size = DetectPacketSize( p_demux );
+ i_packet_size = DetectPVRHeadersAndHeaderSize( p_demux, &i_packet_header_size, &vdr );
if( i_packet_size < 0 )
return VLC_EGENERIC;
if( !p_sys )
return VLC_ENOMEM;
memset( p_sys, 0, sizeof( demux_sys_t ) );
- p_sys->i_packet_size = i_packet_size;
vlc_mutex_init( &p_sys->csa_lock );
- p_sys->buffer = NULL;
p_demux->pf_demux = Demux;
p_demux->pf_control = Control;
p_sys->i_dvb_start = 0;
p_sys->i_dvb_length = 0;
+ p_sys->vdr = vdr;
+
+ p_sys->arib.b25stream = NULL;
+ p_sys->stream = p_demux->s;
+
p_sys->b_broken_charset = false;
for( int i = 0; i < 8192; i++ )
pid->i_pid = i;
pid->b_seen = false;
pid->b_valid = false;
+ pid->probed.i_fourcc = 0;
+ pid->probed.i_type = 0;
}
/* PID 8191 is padding */
p_sys->pid[8191].b_seen = true;
p_sys->i_packet_size = i_packet_size;
- p_sys->b_udp_out = false;
- p_sys->fd = -1;
+ p_sys->i_packet_header_size = i_packet_header_size;
p_sys->i_ts_read = 50;
p_sys->csa = NULL;
p_sys->b_start_record = false;
/* Init PMT array */
TAB_INIT( p_sys->i_pmt, p_sys->pmt );
p_sys->i_pmt_es = 0;
+ p_sys->b_delay_es_creation = true;
/* Read config */
p_sys->b_es_id_pid = var_CreateGetBool( p_demux, "ts-es-id-pid" );
p_sys->b_trust_pcr = var_CreateGetBool( p_demux, "ts-trust-pcr" );
- char* psz_string = var_CreateGetString( p_demux, "ts-out" );
- if( psz_string && *psz_string )
- {
- char *psz = strchr( psz_string, ':' );
- int i_port = 0;
-
- p_sys->b_udp_out = true;
-
- if( psz )
- {
- *psz++ = '\0';
- i_port = atoi( psz );
- }
- if( i_port <= 0 ) i_port = 1234;
- msg_Dbg( p_demux, "resend ts to '%s:%d'", psz_string, i_port );
-
- p_sys->fd = net_ConnectUDP( VLC_OBJECT(p_demux), psz_string, i_port, -1 );
- if( p_sys->fd < 0 )
- {
- msg_Err( p_demux, "failed to open udp socket, send disabled" );
- p_sys->b_udp_out = false;
- }
- else
- {
- int i_mtu = var_CreateGetInteger( p_demux, "ts-out-mtu" );
- p_sys->i_ts_read = i_mtu / p_sys->i_packet_size;
- if( p_sys->i_ts_read <= 0 )
- {
- p_sys->i_ts_read = 1500 / p_sys->i_packet_size;
- }
- p_sys->buffer = xmalloc( p_sys->i_packet_size * p_sys->i_ts_read );
- }
- }
- free( psz_string );
-
/* We handle description of an extra PMT */
- psz_string = var_CreateGetString( p_demux, "ts-extra-pmt" );
+ char* psz_string = var_CreateGetString( p_demux, "ts-extra-pmt" );
p_sys->b_user_pmt = false;
if( psz_string && *psz_string )
UserPmt( p_demux, psz_string );
p_sys->b_split_es = var_InheritBool( p_demux, "ts-split-es" );
+ p_sys->b_canseek = false;
p_sys->i_pid_ref_pcr = -1;
p_sys->i_first_pcr = -1;
p_sys->i_current_pcr = -1;
p_sys->p_pcrs = (mtime_t *)calloc( p_sys->i_pcrs_num, sizeof( mtime_t ) );
p_sys->p_pos = (int64_t *)calloc( p_sys->i_pcrs_num, sizeof( int64_t ) );
- bool can_seek = false;
- stream_Control( p_demux->s, STREAM_CAN_FASTSEEK, &can_seek );
- if( can_seek )
+ p_sys->arib.e_mode = var_InheritInteger( p_demux, "ts-arib" );
+
+ if( !p_sys->p_pcrs || !p_sys->p_pos )
{
- GetFirstPCR( p_demux );
- CheckPCR( p_demux );
- GetLastPCR( p_demux );
+ Close( p_this );
+ return VLC_ENOMEM;
}
- if( p_sys->i_first_pcr < 0 || p_sys->i_last_pcr < 0 )
+
+ bool b_can_fastseek = false;
+ stream_Control( p_sys->stream, STREAM_CAN_SEEK, &p_sys->b_canseek );
+ stream_Control( p_sys->stream, STREAM_CAN_FASTSEEK, &b_can_fastseek );
+ if ( p_sys->b_canseek )
{
- p_sys->b_force_seek_per_percent = true;
+ if( b_can_fastseek )
+ {
+ GetFirstPCR( p_demux );
+ CheckPCR( p_demux );
+ GetLastPCR( p_demux );
+ }
+
+ if( p_sys->i_first_pcr < 0 || p_sys->i_last_pcr < 0 )
+ {
+ msg_Dbg( p_demux, "Force Seek Per Percent: PCR's not found,");
+ p_sys->b_force_seek_per_percent = true;
+ }
}
- while( p_sys->i_pmt_es <= 0 && vlc_object_alive( p_demux ) )
+ while( p_sys->i_pmt_es <= 0
+ && (!p_sys->pid[0].b_seen && !p_sys->patfix.b_pat_deadline) )
{
- if( p_demux->pf_demux( p_demux ) != 1 )
+ if( Demux( p_demux ) != 1 )
break;
}
+ /* If we had no PAT within 140ms, create PAT/PMT from probed streams */
+ if( p_sys->i_pmt_es == 0 && !p_sys->pid[0].b_seen )
+ MissingPATPMTFixup( p_demux );
+
return VLC_SUCCESS;
}
free( p_sys->programs_list.p_values );
- /* When streaming, close the port */
- if( p_sys->fd > -1 )
- {
- net_Close( p_sys->fd );
- }
-
- free( p_sys->buffer );
-
free( p_sys->p_pcrs );
free( p_sys->p_pos );
+#ifdef HAVE_ARIBB24
+ if ( p_sys->arib.p_instance )
+ arib_instance_destroy( p_sys->arib.p_instance );
+#endif
+
+ if ( p_sys->arib.b25stream )
+ {
+ p_sys->arib.b25stream->p_source = NULL; /* don't chain kill demuxer's source */
+ stream_Delete( p_sys->arib.b25stream );
+ }
+
vlc_mutex_destroy( &p_sys->csa_lock );
free( p_sys );
}
if( p_sys->b_start_record )
{
/* Enable recording once synchronized */
- stream_Control( p_demux->s, STREAM_SET_RECORD_STATE, true, "ts" );
+ stream_Control( p_sys->stream, STREAM_SET_RECORD_STATE, true, "ts" );
p_sys->b_start_record = false;
}
- if( p_sys->b_udp_out )
- {
- memcpy( &p_sys->buffer[i_pkt * p_sys->i_packet_size],
- p_pkt->p_buffer, p_sys->i_packet_size );
- }
-
/* Parse the TS packet */
ts_pid_t *p_pid = &p_sys->pid[PIDGet( p_pkt )];
+ /* Probe streams to build PAT/PMT after 140ms in case we don't see any PAT */
+ if( !p_sys->pid[0].b_seen &&
+ (p_pid->probed.i_type == 0 || p_pid->i_pid == p_sys->patfix.i_timesourcepid) &&
+ (p_pkt->p_buffer[1] & 0xC0) == 0x40 && /* Payload start but not corrupt */
+ (p_pkt->p_buffer[3] & 0xD0) == 0x10 ) /* Has payload but is not encrypted */
+ {
+ ProbePES( p_demux, p_pid, p_pkt->p_buffer + 4, p_pkt->p_buffer[3] & 0x20 /* Adaptation field */);
+ }
+
if( p_pid->b_valid )
{
if( p_pid->psi )
}
block_Release( p_pkt );
}
- else if( !p_sys->b_udp_out )
- {
- b_frame = GatherData( p_demux, p_pid, p_pkt );
- }
else
{
- PCRHandle( p_demux, p_pid, p_pkt );
- block_Release( p_pkt );
+ if(p_sys->b_delay_es_creation) /* No longer delay ES since that pid's program sends data */
+ AddAndCreateES( p_demux, NULL );
+ b_frame = GatherData( p_demux, p_pid, p_pkt );
}
}
else
break;
}
- if( p_sys->b_udp_out )
- {
- /* Send the complete block */
- net_Write( p_demux, p_sys->fd, NULL, p_sys->buffer,
- p_sys->i_ts_read * p_sys->i_packet_size );
- }
-
demux_UpdateTitleFromStream( p_demux );
return 1;
}
int64_t i_time, i_length;
if( !DVBEventInformation( p_demux, &i_time, &i_length ) && i_length > 0 )
*pf = (double)i_time/(double)i_length;
- else if( (i64 = stream_Size( p_demux->s) ) > 0 )
- *pf = (double)stream_Tell( p_demux->s ) / (double)i64;
+ else if( (i64 = stream_Size( p_sys->stream) ) > 0 )
+ {
+ int64_t offset = stream_Tell( p_sys->stream );
+
+ *pf = (double)offset / (double)i64;
+ }
else
*pf = 0.0;
}
case DEMUX_SET_POSITION:
f = (double) va_arg( args, double );
+ if(!p_sys->b_canseek)
+ return VLC_EGENERIC;
+
if( p_sys->b_force_seek_per_percent ||
(p_sys->b_dvb_meta && p_sys->b_access_control) ||
p_sys->i_last_pcr - p_sys->i_first_pcr <= 0 )
{
- i64 = stream_Size( p_demux->s );
- if( stream_Seek( p_demux->s, (int64_t)(i64 * f) ) )
+ i64 = stream_Size( p_sys->stream );
+ if( stream_Seek( p_sys->stream, (int64_t)(i64 * f) ) )
return VLC_EGENERIC;
}
else
*va_arg( args, int* ) = 0; /* Title offset */
*va_arg( args, int* ) = 0; /* Chapter offset */
- return stream_Control( p_demux->s, STREAM_GET_TITLE_INFO, v, c );
+ return stream_Control( p_sys->stream, STREAM_GET_TITLE_INFO, v, c );
}
case DEMUX_SET_TITLE:
- return stream_vaControl( p_demux->s, STREAM_SET_TITLE, args );
+ return stream_vaControl( p_sys->stream, STREAM_SET_TITLE, args );
case DEMUX_SET_SEEKPOINT:
- return stream_vaControl( p_demux->s, STREAM_SET_SEEKPOINT, args );
+ return stream_vaControl( p_sys->stream, STREAM_SET_SEEKPOINT, args );
case DEMUX_GET_META:
- return stream_vaControl( p_demux->s, STREAM_GET_META, args );
+ return stream_vaControl( p_sys->stream, STREAM_GET_META, args );
case DEMUX_CAN_RECORD:
pb_bool = (bool*)va_arg( args, bool * );
b_bool = (bool)va_arg( args, int );
if( !b_bool )
- stream_Control( p_demux->s, STREAM_SET_RECORD_STATE, false );
+ stream_Control( p_sys->stream, STREAM_SET_RECORD_STATE, false );
p_sys->b_start_record = b_bool;
return VLC_SUCCESS;
case DEMUX_GET_SIGNAL:
- return stream_vaControl( p_demux->s, STREAM_GET_SIGNAL, args );
+ return stream_vaControl( p_sys->stream, STREAM_GET_SIGNAL, args );
default:
return VLC_EGENERIC;
char *psz = psz_dup;
int i_pid;
int i_number;
+ ts_prg_psi_t *prg = NULL;
if( !psz_dup )
return VLC_ENOMEM;
/* */
ts_pid_t *pmt = &p_sys->pid[i_pid];
- ts_prg_psi_t *prg;
msg_Dbg( p_demux, "user pmt specified (pid=%d,number=%d)", i_pid, i_number );
PIDInit( pmt, true, NULL );
else
{
const int i_stream_type = strtol( psz_opt, NULL, 0 );
- PIDFillFormat( pid->es, i_stream_type );
+ PIDFillFormat( &pid->es->fmt, i_stream_type );
}
pid->es->fmt.i_group = i_number;
if( p_sys->b_es_id_pid )
if( !p_sys->b_access_control )
return VLC_EGENERIC;
- return stream_Control( p_demux->s, STREAM_SET_PRIVATE_ID_STATE,
+ return stream_Control( p_sys->stream, STREAM_SET_PRIVATE_ID_STATE,
i_pid, b_selected );
}
ts_prg_psi_t *p_prg = NULL;
int i_pmt_pid = -1;
+ p_sys->b_disable_pcr = !p_sys->b_trust_pcr;
+
/* Search pmt to be unselected */
for( int i = 0; i < p_sys->i_pmt; i++ )
{
pid->b_valid = false;
}
+static int16_t read_opus_flag(uint8_t **buf, size_t *len)
+{
+ if (*len < 2)
+ return -1;
+
+ int16_t ret = ((*buf)[0] << 8) | (*buf)[1];
+
+ *len -= 2;
+ *buf += 2;
+
+ if (ret & (3<<13))
+ ret = -1;
+
+ return ret;
+}
+
+static block_t *Opus_Parse(demux_t *demux, block_t *block)
+{
+ block_t *out = NULL;
+ block_t **last = NULL;
+
+ uint8_t *buf = block->p_buffer;
+ size_t len = block->i_buffer;
+
+ while (len > 3 && ((buf[0] << 3) | (buf[1] >> 5)) == 0x3ff) {
+ int16_t start_trim = 0, end_trim = 0;
+ int start_trim_flag = (buf[1] >> 4) & 1;
+ int end_trim_flag = (buf[1] >> 3) & 1;
+ int control_extension_flag = (buf[1] >> 2) & 1;
+
+ len -= 2;
+ buf += 2;
+
+ unsigned au_size = 0;
+ while (len--) {
+ int c = *buf++;
+ au_size += c;
+ if (c != 0xff)
+ break;
+ }
+
+ if (start_trim_flag) {
+ start_trim = read_opus_flag(&buf, &len);
+ if (start_trim < 0) {
+ msg_Err(demux, "Invalid start trimming flag");
+ }
+ }
+ if (end_trim_flag) {
+ end_trim = read_opus_flag(&buf, &len);
+ if (end_trim < 0) {
+ msg_Err(demux, "Invalid end trimming flag");
+ }
+ }
+ if (control_extension_flag && len) {
+ unsigned l = *buf++; len--;
+ if (l > len) {
+ msg_Err(demux, "Invalid control extension length %d > %zu", l, len);
+ break;
+ }
+ buf += l;
+ len -= l;
+ }
+
+ if (!au_size || au_size > len) {
+ msg_Err(demux, "Invalid Opus AU size %d (PES %zu)", au_size, len);
+ break;
+ }
+
+ block_t *au = block_Alloc(au_size);
+ if (!au)
+ break;
+ memcpy(au->p_buffer, buf, au_size);
+ block_CopyProperties(au, block);
+ au->p_next = NULL;
+
+ if (!out)
+ out = au;
+ else
+ *last = au;
+ last = &au->p_next;
+
+ au->i_nb_samples = opus_frame_duration(buf, au_size);
+ if (end_trim && end_trim <= au->i_nb_samples)
+ au->i_length = end_trim; /* Blatant abuse of the i_length field. */
+ else
+ au->i_length = 0;
+
+ if (start_trim && start_trim < (au->i_nb_samples - au->i_length)) {
+ au->i_nb_samples -= start_trim;
+ if (au->i_nb_samples == 0)
+ au->i_flags |= BLOCK_FLAG_PREROLL;
+ }
+
+ buf += au_size;
+ len -= au_size;
+ }
+
+ block_Release(block);
+ return out;
+}
+
/****************************************************************************
* gathering stuff
****************************************************************************/
/* FIXME find real max size */
/* const int i_max = */ block_ChainExtract( p_pes, header, 34 );
- if( header[0] != 0 || header[1] != 0 || header[2] != 1 )
+ if( pid->b_scrambled || header[0] != 0 || header[1] != 0 || header[2] != 1 )
{
- msg_Warn( p_demux, "invalid header [0x%02x:%02x:%02x:%02x] (pid: %d)",
- header[0], header[1],header[2],header[3], pid->i_pid );
+ if ( !pid->b_scrambled )
+ msg_Warn( p_demux, "invalid header [0x%02x:%02x:%02x:%02x] (pid: %d)",
+ header[0], header[1],header[2],header[3], pid->i_pid );
block_ChainRelease( p_pes );
return;
}
if( header[7]&0x80 ) /* has pts */
{
- i_pts = ((mtime_t)(header[ 9]&0x0e ) << 29)|
- (mtime_t)(header[10] << 22)|
- ((mtime_t)(header[11]&0xfe) << 14)|
- (mtime_t)(header[12] << 7)|
- (mtime_t)(header[13] >> 1);
+ i_pts = ExtractPESTimestamp( &header[9] );
+ i_pts = AdjustPTSWrapAround( p_demux, i_pts );
if( header[7]&0x40 ) /* has dts */
{
- i_dts = ((mtime_t)(header[14]&0x0e ) << 29)|
- (mtime_t)(header[15] << 22)|
- ((mtime_t)(header[16]&0xfe) << 14)|
- (mtime_t)(header[17] << 7)|
- (mtime_t)(header[18] >> 1);
+ i_dts = ExtractPESTimestamp( &header[14] );
+ i_dts = AdjustPTSWrapAround( p_demux, i_dts );
}
}
}
if( header[i_skip]&0x20 )
{
- i_pts = ((mtime_t)(header[i_skip]&0x0e ) << 29)|
- (mtime_t)(header[i_skip+1] << 22)|
- ((mtime_t)(header[i_skip+2]&0xfe) << 14)|
- (mtime_t)(header[i_skip+3] << 7)|
- (mtime_t)(header[i_skip+4] >> 1);
+ i_pts = ExtractPESTimestamp( &header[i_skip] );
if( header[i_skip]&0x10 ) /* has dts */
{
- i_dts = ((mtime_t)(header[i_skip+5]&0x0e ) << 29)|
- (mtime_t)(header[i_skip+6] << 22)|
- ((mtime_t)(header[i_skip+7]&0xfe) << 14)|
- (mtime_t)(header[i_skip+8] << 7)|
- (mtime_t)(header[i_skip+9] >> 1);
- i_skip += 10;
+ i_dts = ExtractPESTimestamp( &header[i_skip+5] );
+ i_skip += 10;
}
else
{
/* Append a \0 */
p_block = block_Realloc( p_block, 0, p_block->i_buffer + 1 );
if( !p_block )
- abort();
+ return;
p_block->p_buffer[p_block->i_buffer -1] = '\0';
}
else if( pid->es->fmt.i_codec == VLC_CODEC_TELETEXT )
}
}
}
-
- for( int i = 0; i < pid->i_extra_es; i++ )
+ else if( pid->es->fmt.i_codec == VLC_CODEC_ARIB_A ||
+ pid->es->fmt.i_codec == VLC_CODEC_ARIB_C )
{
- es_out_Send( p_demux->out, pid->extra_es[i]->id,
- block_Duplicate( p_block ) );
+ if( p_block->i_pts <= VLC_TS_INVALID )
+ {
+ if( i_pes_size > 0 && p_block->i_buffer > i_pes_size )
+ {
+ p_block->i_buffer = i_pes_size;
+ }
+ /* Append a \0 */
+ p_block = block_Realloc( p_block, 0, p_block->i_buffer + 1 );
+ if( !p_block )
+ return;
+ p_block->p_buffer[p_block->i_buffer -1] = '\0';
+ }
+ }
+ else if( pid->es->fmt.i_codec == VLC_CODEC_OPUS)
+ {
+ p_block = Opus_Parse(p_demux, p_block);
}
- if (!p_sys->b_trust_pcr)
- es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block->i_pts);
+ while (p_block) {
+ block_t *p_next = p_block->p_next;
+ p_block->p_next = NULL;
+ for( int i = 0; i < pid->i_extra_es; i++ )
+ {
+ es_out_Send( p_demux->out, pid->extra_es[i]->id,
+ block_Duplicate( p_block ) );
+ }
+
+ PCRFixHandle( p_demux, p_block );
+
+ if ( p_sys->b_disable_pcr && p_block->i_dts > VLC_TS_INVALID )
+ es_out_Control( p_demux->out, ES_OUT_SET_GROUP_PCR,
+ pid->i_owner_number, p_block->i_dts);
- es_out_Send( p_demux->out, pid->es->id, p_block );
+ if( !p_sys->b_disable_pcr && p_block->i_dts > VLC_TS_INVALID &&
+ p_block->i_dts < (VLC_TS_0 + p_sys->i_current_pcr * 100 / 9) )
+ msg_Warn( p_demux, "Broken stream: pid %d sends packets with dts %"PRId64"us later than pcr",
+ pid->i_pid, (p_sys->i_current_pcr * 100 / 9) - p_block->i_dts + VLC_TS_0 );
+
+ es_out_Send( p_demux->out, pid->es->id, p_block );
+
+ p_block = p_next;
+ }
}
else
{
if( p_content->i_buffer > 9 && p_content->p_buffer[0] == 0xc6 )
{
int i_index = 0;
- int i_offset = 4;
+ size_t i_offset = 4;
if( p_content->p_buffer[3] & 0x40 )
{
i_index = ((p_content->p_buffer[7] & 0x0f) << 8) |
p_content->i_pts = VLC_TS_0 + i_date * 100 / 9;
}
es_out_Send( p_demux->out, pid->es->id, p_content );
+
+ PCRFixHandle( p_demux, p_content );
}
static void ParseData( demux_t *p_demux, ts_pid_t *pid )
{
block_t *p_pkt;
/* Get a new TS packet */
- if( !( p_pkt = stream_Block( p_demux->s, p_sys->i_packet_size ) ) )
+ if( !( p_pkt = stream_Block( p_sys->stream, p_sys->i_packet_size ) ) )
{
msg_Dbg( p_demux, "eof ?" );
return NULL;
}
+ /* Skip header (BluRay streams).
+ * re-sync logic would do this (by adjusting packet start), but this would result in losing first and last ts packets.
+ * First packet is usually PAT, and losing it means losing whole first GOP. This is fatal with still-image based menus.
+ */
+ p_pkt->p_buffer += p_sys->i_packet_header_size;
+ p_pkt->i_buffer -= p_sys->i_packet_header_size;
+
/* Check sync byte and re-sync if needed */
if( p_pkt->p_buffer[0] != 0x47 )
{
msg_Warn( p_demux, "lost synchro" );
block_Release( p_pkt );
- while( vlc_object_alive (p_demux) )
+ for( ;; )
{
const uint8_t *p_peek;
int i_peek, i_skip = 0;
- i_peek = stream_Peek( p_demux->s, &p_peek,
+ i_peek = stream_Peek( p_sys->stream, &p_peek,
p_sys->i_packet_size * 10 );
if( i_peek < p_sys->i_packet_size + 1 )
{
while( i_skip < i_peek - p_sys->i_packet_size )
{
- if( p_peek[i_skip] == 0x47 &&
- p_peek[i_skip + p_sys->i_packet_size] == 0x47 )
+ if( p_peek[i_skip + p_sys->i_packet_header_size] == 0x47 &&
+ p_peek[i_skip + p_sys->i_packet_header_size + p_sys->i_packet_size] == 0x47 )
{
break;
}
i_skip++;
}
msg_Dbg( p_demux, "skipping %d bytes of garbage", i_skip );
- stream_Read( p_demux->s, NULL, i_skip );
+ stream_Read( p_sys->stream, NULL, i_skip );
if( i_skip < i_peek - p_sys->i_packet_size )
{
break;
}
}
- if( !( p_pkt = stream_Block( p_demux->s, p_sys->i_packet_size ) ) )
+ if( !( p_pkt = stream_Block( p_sys->stream, p_sys->i_packet_size ) ) )
{
msg_Dbg( p_demux, "eof ?" );
return NULL;
* So, need to add 0x1FFFFFFFF, for calculating duration or current position.
*/
mtime_t i_adjust = 0;
- int64_t i_pos = stream_Tell( p_demux->s );
+ int64_t i_pos = stream_Tell( p_sys->stream );
int i;
for( i = 1; i < p_sys->i_pcrs_num && p_sys->p_pos[i] <= i_pos; ++i )
{
return i_pcr + i_adjust;
}
+static mtime_t AdjustPTSWrapAround( demux_t *p_demux, mtime_t i_pts )
+{
+ demux_sys_t *p_sys = p_demux->p_sys;
+ mtime_t i_pcr = p_sys->i_current_pcr;
+
+ mtime_t i_adjustremain = i_pcr % 0x1FFFFFFFF;
+ mtime_t i_adjustbase = i_pcr - i_adjustremain;
+
+ mtime_t i_pts_adjust = i_adjustbase;
+
+ /* PTS has rolled first */
+ if( i_adjustremain >= 0xFFFFFFFF && i_pts < 0xFFFFFFFF )
+ {
+ i_pts_adjust += 0x1FFFFFFFF;
+ }
+ /* PCR has rolled first (PTS is late!) */
+ else if( i_adjustremain < 0xFFFFFFFF && i_pts >= 0xFFFFFFFF )
+ {
+ if( i_adjustbase >= 0x1FFFFFFFF ) /* we need to remove current roll */
+ i_pts_adjust -= 0x1FFFFFFFF;
+ }
+
+ i_pts += i_pts_adjust;
+ return i_pts;
+}
+
static mtime_t GetPCR( block_t *p_pkt )
{
const uint8_t *p = p_pkt->p_buffer;
demux_sys_t *p_sys = p_demux->p_sys;
mtime_t i_pcr = -1;
- int64_t i_initial_pos = stream_Tell( p_demux->s );
+ const int64_t i_initial_pos = stream_Tell( p_sys->stream );
if( i_pos < 0 )
return VLC_EGENERIC;
- int64_t i_last_pos = i_pos + p_sys->i_packet_size * 4500; //XXX
- if( i_last_pos > stream_Size( p_demux->s ) - p_sys->i_packet_size )
- {
- i_last_pos = stream_Size( p_demux->s ) - p_sys->i_packet_size;
- }
+ int64_t i_last_pos = stream_Size( p_sys->stream ) - p_sys->i_packet_size;
+ if( i_pos > i_last_pos )
+ i_pos = i_last_pos;
- if( stream_Seek( p_demux->s, i_pos ) )
+ if( stream_Seek( p_sys->stream, i_pos ) )
return VLC_EGENERIC;
- while( vlc_object_alive( p_demux ) )
+ for( ;; )
{
- block_t *p_pkt;
+ block_t *p_pkt;
+
if( !( p_pkt = ReadTSPacket( p_demux ) ) )
{
break;
block_Release( p_pkt );
if( i_pcr >= 0 )
break;
- if( stream_Tell( p_demux->s ) >= i_last_pos )
+ if( stream_Tell( p_sys->stream ) >= i_last_pos )
break;
}
- if( i_pcr < 0 )
- {
- stream_Seek( p_demux->s, i_initial_pos );
- return VLC_EGENERIC;
- }
- else
+ if( i_pcr < 0 )
{
- p_sys->i_current_pcr = i_pcr;
- return VLC_SUCCESS;
+ stream_Seek( p_sys->stream, i_initial_pos );
+ assert( i_initial_pos == stream_Tell( p_sys->stream ) );
+ return VLC_EGENERIC;
}
+
+ p_sys->i_current_pcr = i_pcr;
+ return VLC_SUCCESS;
}
static int Seek( demux_t *p_demux, double f_percent )
{
demux_sys_t *p_sys = p_demux->p_sys;
- int64_t i_initial_pos = stream_Tell( p_demux->s );
+ int64_t i_initial_pos = stream_Tell( p_sys->stream );
mtime_t i_initial_pcr = p_sys->i_current_pcr;
/*
mtime_t i_target_pcr = (p_sys->i_last_pcr - p_sys->i_first_pcr) * f_percent + p_sys->i_first_pcr;
int64_t i_head_pos = 0;
- int64_t i_tail_pos = stream_Size( p_demux->s );
+ int64_t i_tail_pos;
{
mtime_t i_adjust = 0;
int i;
break;
}
i_head_pos = p_sys->p_pos[i-1];
- i_tail_pos = ( i < p_sys->i_pcrs_num ) ? p_sys->p_pos[i] : stream_Size( p_demux->s );
+ i_tail_pos = ( i < p_sys->i_pcrs_num ) ? p_sys->p_pos[i] : stream_Size( p_sys->stream );
}
msg_Dbg( p_demux, "Seek():i_head_pos:%"PRId64", i_tail_pos:%"PRId64, i_head_pos, i_tail_pos);
int i_cnt = 0;
while( i_head_pos <= i_tail_pos )
{
+ /* Round i_pos to a multiple of p_sys->i_packet_size */
int64_t i_pos = i_head_pos + (i_tail_pos - i_head_pos) / 2;
+ int64_t i_div = i_pos % p_sys->i_packet_size;
+ i_pos -= i_div;
if( SeekToPCR( p_demux, i_pos ) )
break;
p_sys->i_current_pcr = AdjustPCRWrapAround( p_demux, p_sys->i_current_pcr );
if( !b_found )
{
msg_Dbg( p_demux, "Seek():cannot find a time position. i_cnt:%d", i_cnt );
- stream_Seek( p_demux->s, i_initial_pos );
+ stream_Seek( p_sys->stream, i_initial_pos );
p_sys->i_current_pcr = i_initial_pcr;
return VLC_EGENERIC;
}
else
{
msg_Dbg( p_demux, "Seek():can find a time position. i_cnt:%d", i_cnt );
+ p_demux->p_sys->pcrfix.i_first_dts = 0;
return VLC_SUCCESS;
}
}
{
demux_sys_t *p_sys = p_demux->p_sys;
- int64_t i_initial_pos = stream_Tell( p_demux->s );
+ int64_t i_initial_pos = stream_Tell( p_sys->stream );
- if( stream_Seek( p_demux->s, 0 ) )
+ if( stream_Seek( p_sys->stream, 0 ) )
return;
- while( vlc_object_alive (p_demux) )
+ for( ;; )
{
block_t *p_pkt;
+
if( !( p_pkt = ReadTSPacket( p_demux ) ) )
{
break;
if( p_sys->i_first_pcr >= 0 )
break;
}
- stream_Seek( p_demux->s, i_initial_pos );
+ stream_Seek( p_sys->stream, i_initial_pos );
}
static void GetLastPCR( demux_t *p_demux )
{
demux_sys_t *p_sys = p_demux->p_sys;
- int64_t i_initial_pos = stream_Tell( p_demux->s );
+ const int64_t i_initial_pos = stream_Tell( p_sys->stream );
mtime_t i_initial_pcr = p_sys->i_current_pcr;
- int64_t i_last_pos = stream_Size( p_demux->s ) - p_sys->i_packet_size;
+ int64_t i_stream_size = stream_Size( p_sys->stream );
+ int64_t i_last_pos = i_stream_size - p_sys->i_packet_size;
+ /* Round i_pos to a multiple of p_sys->i_packet_size */
int64_t i_pos = i_last_pos - p_sys->i_packet_size * 4500; /* FIXME if the value is not reasonable, please change it. */
- if( i_pos < 0 )
+ int64_t i_div = i_pos % p_sys->i_packet_size;
+ i_pos -= i_div;
+
+ if( i_pos <= i_initial_pos && i_pos >= i_stream_size )
+ i_pos = i_initial_pos + p_sys->i_packet_size;
+ if( i_pos < 0 && i_pos >= i_stream_size )
return;
- while( vlc_object_alive( p_demux ) )
+ for( ;; )
{
if( SeekToPCR( p_demux, i_pos ) )
break;
p_sys->i_last_pcr = AdjustPCRWrapAround( p_demux, p_sys->i_current_pcr );
- if( ( i_pos = stream_Tell( p_demux->s ) ) >= i_last_pos )
+ if( ( i_pos = stream_Tell( p_sys->stream ) ) >= i_last_pos )
break;
}
- if( p_sys->i_last_pcr >= 0 )
- {
- int64_t i_size = stream_Size( p_demux->s );
- mtime_t i_duration_msec = ( p_sys->i_last_pcr - p_sys->i_first_pcr ) * 100 / 9 / 1000;
- int64_t i_rate = ( i_size < 0 || i_duration_msec <= 0 ) ? 0 : i_size * 1000 * 8 / i_duration_msec;
- const int64_t TS_SUPPOSED_MAXRATE = 55 * 1000 * 1000; //FIXME I think it's enough.
- const int64_t TS_SUPPOSED_MINRATE = 0.5 * 1000 * 1000; //FIXME
- if( i_rate < TS_SUPPOSED_MINRATE || i_rate > TS_SUPPOSED_MAXRATE )
- {
- msg_Dbg( p_demux, "calculated bitrate (%"PRId64"bit/s) is too low or too high. min bitrate (%"PRId64"bit/s) max bitrate (%"PRId64"bit/s)",
- i_rate, TS_SUPPOSED_MINRATE, TS_SUPPOSED_MAXRATE );
- p_sys->i_last_pcr = -1;
- }
- }
- stream_Seek( p_demux->s, i_initial_pos );
+
+ stream_Seek( p_sys->stream, i_initial_pos );
+ assert( i_initial_pos == stream_Tell( p_sys->stream ) );
p_sys->i_current_pcr = i_initial_pcr;
}
{
demux_sys_t *p_sys = p_demux->p_sys;
- int64_t i_initial_pos = stream_Tell( p_demux->s );
+ int64_t i_initial_pos = stream_Tell( p_sys->stream );
mtime_t i_initial_pcr = p_sys->i_current_pcr;
- int64_t i_size = stream_Size( p_demux->s );
+ int64_t i_size = stream_Size( p_sys->stream );
int i = 0;
p_sys->p_pcrs[0] = p_sys->i_first_pcr;
p_sys->p_pos[0] = i_initial_pos;
- for( i = 1; i < p_sys->i_pcrs_num && vlc_object_alive( p_demux ); ++i )
+ for( i = 1; i < p_sys->i_pcrs_num; ++i )
{
+ /* Round i_pos to a multiple of p_sys->i_packet_size */
int64_t i_pos = i_size / p_sys->i_pcrs_num * i;
+ int64_t i_div = i_pos % p_sys->i_packet_size;
+ i_pos -= i_div;
if( SeekToPCR( p_demux, i_pos ) )
break;
p_sys->p_pcrs[i] = p_sys->i_current_pcr;
- p_sys->p_pos[i] = stream_Tell( p_demux->s );
+ p_sys->p_pos[i] = stream_Tell( p_sys->stream );
if( p_sys->p_pcrs[i-1] > p_sys->p_pcrs[i] )
{
msg_Dbg( p_demux, "PCR Wrap Around found between %d%% and %d%% (pcr:%"PRId64"(0x%09"PRIx64") pcr:%"PRId64"(0x%09"PRIx64"))",
p_sys->b_force_seek_per_percent = true;
}
- stream_Seek( p_demux->s, i_initial_pos );
+ stream_Seek( p_sys->stream, i_initial_pos );
p_sys->i_current_pcr = i_initial_pcr;
}
if( i_pcr < 0 )
return;
+ i_pcr = AdjustPCRWrapAround( p_demux, i_pcr );
+
if( p_sys->i_pid_ref_pcr == pid->i_pid )
- p_sys->i_current_pcr = AdjustPCRWrapAround( p_demux, i_pcr );
+ p_sys->i_current_pcr = i_pcr;
/* Search program and set the PCR */
for( int i = 0; i < p_sys->i_pmt; i++ )
+ {
+ int i_group = -1;
for( int i_prg = 0; i_prg < p_sys->pmt[i]->psi->i_prg; i_prg++ )
- if( pid->i_pid == p_sys->pmt[i]->psi->prg[i_prg]->i_pid_pcr )
+ {
+ ts_prg_psi_t *p_prg = p_sys->pmt[i]->psi->prg[i_prg];
+
+ if( p_prg->i_pid_pcr == 0x1FFF ) /* That program has no dedicated PCR pid ISO/IEC 13818-1 2.4.4.9 */
+ {
+ if( pid->p_owner ) /* PCR shall be on pid itself */
+ {
+ p_prg->i_pcr_value = i_pcr; /* ? update PCR for the whole group program */
+ i_group = p_prg->i_number;
+ p_sys->pcrfix.b_program_pcr_seen = true;
+ p_sys->pcrfix.i_first_dts = 0;
+ p_sys->b_disable_pcr = !p_sys->b_trust_pcr;
+ }
+ else
+ {
+ msg_Warn(p_demux, "discarding PCR update from pid %d which has no owner", pid->i_pid);
+ }
+ break;
+ }
+ else /* set PCR provided by current pid to program(s) referencing it */
{
- p_sys->pmt[i]->psi->prg[i_prg]->i_pcr_value = i_pcr;
- if (p_sys->b_trust_pcr)
- es_out_Control( p_demux->out, ES_OUT_SET_GROUP_PCR,
- (int)p_sys->pmt[i]->psi->prg[i_prg]->i_number,
- (int64_t)(VLC_TS_0 + i_pcr * 100 / 9) );
+ /* Can be dedicated PCR pid (no owned then) or another pid (owner == pmt) */
+ if( p_prg->i_pid_pcr == pid->i_pid ) /* If that program references current pid as PCR */
+ {
+ p_prg->i_pcr_value = i_pcr;
+ i_group = p_prg->i_number; /* We've found a target group for update */
+ p_sys->pcrfix.b_program_pcr_seen = true;
+ p_sys->pcrfix.i_first_dts = 0;
+ p_sys->b_disable_pcr = !p_sys->b_trust_pcr;
+ }
}
+ }
+ if ( !p_sys->b_disable_pcr && i_group > 0 && p_sys->i_pmt_es )
+ {
+ es_out_Control( p_demux->out, ES_OUT_SET_GROUP_PCR,
+ i_group, VLC_TS_0 + i_pcr * 100 / 9 );
+ }
+ }
+}
+
+static void PCRFixHandle( demux_t *p_demux, block_t *p_block )
+{
+ demux_sys_t *p_sys = p_demux->p_sys;
+ /* Record the first data packet timestamp in case there wont be any PCR */
+ if( !p_sys->pcrfix.b_program_pcr_seen && !p_sys->b_disable_pcr )
+ {
+ if( !p_sys->pcrfix.i_first_dts )
+ {
+ p_sys->pcrfix.i_first_dts = p_block->i_dts;
+ }
+ else if( p_block->i_dts - p_sys->pcrfix.i_first_dts > CLOCK_FREQ / 10 ) /* "shall not exceed 100ms" */
+ {
+ p_sys->b_disable_pcr = true;
+ msg_Warn( p_demux, "No PCR received for program %d, set up workaround",
+ p_sys->i_current_program );
+ }
+ }
}
static bool GatherData( demux_t *p_demux, ts_pid_t *pid, block_t *p_bk )
i_cc, ( pid->i_cc + 1 )&0x0f, pid->i_pid );
pid->i_cc = i_cc;
- if( pid->es->p_data && pid->es->fmt.i_cat != VIDEO_ES )
+ if( pid->es->p_data && pid->es->fmt.i_cat != VIDEO_ES &&
+ pid->es->fmt.i_cat != AUDIO_ES )
{
- /* Small video artifacts are usually better than
+ /* Small audio/video artifacts are usually better than
* dropping full frames */
pid->es->p_data->i_flags |= BLOCK_FLAG_CORRUPTED;
}
PCRHandle( p_demux, pid, p_bk );
- if( i_skip >= 188 || pid->es->id == NULL || p_demux->p_sys->b_udp_out )
+ if( i_skip >= 188 || pid->es->id == NULL )
{
block_Release( p_bk );
return i_ret;
return i_ret;
}
-static void PIDFillFormat( ts_es_t *es, int i_stream_type )
+static void PIDFillFormat( es_format_t *fmt, int i_stream_type )
{
- es_format_t *fmt = &es->fmt;
-
switch( i_stream_type )
{
case 0x01: /* MPEG-1 video */
case 0x1B: /* H264 <- check transport syntax/needed descriptor */
es_format_Init( fmt, VIDEO_ES, VLC_CODEC_H264 );
break;
+ case 0x24: /* HEVC */
+ es_format_Init( fmt, VIDEO_ES, VLC_CODEC_HEVC );
+ break;
case 0x42: /* CAVS (Chinese AVS) */
es_format_Init( fmt, VIDEO_ES, VLC_CODEC_CAVS );
break;
break;
case 0x82: /* SCTE-27 (sub) */
es_format_Init( fmt, SPU_ES, VLC_CODEC_SCTE_27 );
- es->data_type = TS_ES_DATA_TABLE_SECTION;
- break;
- case 0x83: /* LPCM (audio) */
- es_format_Init( fmt, AUDIO_ES, VLC_CODEC_DVD_LPCM );
break;
case 0x84: /* SDDS (audio) */
es_format_Init( fmt, AUDIO_ES, VLC_CODEC_SDDS );
int i_length = 0;
int i_data_sav = i_data;
uint8_t *p_data_sav = p_data;
- for (int i = 0; i_data > 0 && i < 255; i++)
+ for (int i = 0; i_data > 0 && i < ES_DESCRIPTOR_COUNT; i++)
{
es_mpeg4_descriptor_t *es_descr = &p_iod->es_descr[i];
ts_debug( "\n* ERR missing DecoderConfigDescr" );
continue;
}
+ int i_config_desc_length = IODDescriptorLength( &i_data, &p_data ); /* DecoderConfigDescr_length */
decoder_config_descriptor_t *dec_descr = &es_descr->dec_descr;
dec_descr->i_objectTypeIndication = IODGetBytes( &i_data, &p_data, 1 );
i_flags = IODGetBytes( &i_data, &p_data, 1 );
IODGetBytes( &i_data, &p_data, 4); /* maxBitrate */
IODGetBytes( &i_data, &p_data, 4 ); /* avgBitrate */
- int i_decoderConfigDescr_length = IODDescriptorLength( &i_data, &p_data );
- if( i_decoderConfigDescr_length > 13 && IODGetBytes( &i_data, &p_data, 1 ) == 0x05 )
+ if( i_config_desc_length > 13 && IODGetBytes( &i_data, &p_data, 1 ) == 0x05 )
{
dec_descr->i_extra = IODDescriptorLength( &i_data, &p_data );
if( dec_descr->i_extra > 0 )
#include "dvb-text.h"
-static char *EITConvertToUTF8( const unsigned char *psz_instring,
+static char *EITConvertToUTF8( demux_t *p_demux,
+ const unsigned char *psz_instring,
size_t i_length,
bool b_broken )
{
+ demux_sys_t *p_sys = p_demux->p_sys;
+#ifdef HAVE_ARIBB24
+ if( p_sys->arib.e_mode == ARIBMODE_ENABLED )
+ {
+ if ( !p_sys->arib.p_instance )
+ p_sys->arib.p_instance = arib_instance_new( p_demux );
+ if ( !p_sys->arib.p_instance )
+ return NULL;
+ arib_decoder_t *p_decoder = arib_get_decoder( p_sys->arib.p_instance );
+ if ( !p_decoder )
+ return NULL;
+
+ char *psz_outstring = NULL;
+ size_t i_out;
+
+ i_out = i_length * 4;
+ psz_outstring = (char*) calloc( i_out + 1, sizeof(char) );
+ if( !psz_outstring )
+ return NULL;
+
+ arib_initialize_decoder( p_decoder );
+ i_out = arib_decode_buffer( p_decoder, psz_instring, i_length,
+ psz_outstring, i_out );
+ arib_finalize_decoder( p_decoder );
+
+ return psz_outstring;
+ }
+#else
+ VLC_UNUSED(p_sys);
+#endif
/* Deal with no longer broken providers (no switch byte
but sending ISO_8859-1 instead of ISO_6937) without
removing them from the broken providers table
msg_Dbg( p_demux, "SDTCallBack called" );
- if( sdt->psi->i_sdt_version != -1 &&
- ( !p_sdt->b_current_next ||
- p_sdt->i_version == sdt->psi->i_sdt_version ) )
+ if( p_sys->b_delay_es_creation ||
+ !p_sdt->b_current_next ||
+ p_sdt->i_version == sdt->psi->i_sdt_version )
{
dvbpsi_DeleteSDT( p_sdt );
return;
p_srv->b_eit_present, p_srv->i_running_status,
p_srv->b_free_ca );
+ if( p_sys->vdr.i_service && p_srv->i_service_id != p_sys->vdr.i_service )
+ {
+ msg_Dbg( p_demux, " * service id=%d skipped (not declared in vdr header)",
+ p_sys->vdr.i_service );
+ continue;
+ }
+
p_meta = vlc_meta_New();
for( p_dr = p_srv->p_first_descriptor; p_dr; p_dr = p_dr->p_next )
{
/* FIXME: Digital+ ES also uses ISO8859-1 */
- str1 = EITConvertToUTF8(pD->i_service_provider_name,
+ str1 = EITConvertToUTF8(p_demux,
+ pD->i_service_provider_name,
pD->i_service_provider_name_length,
p_sys->b_broken_charset );
- str2 = EITConvertToUTF8(pD->i_service_name,
+ str2 = EITConvertToUTF8(p_demux,
+ pD->i_service_name,
pD->i_service_name_length,
p_sys->b_broken_charset );
int64_t i_start;
int i_duration;
int i_min_age = 0;
+ int64_t i_tot_time = 0;
i_start = EITConvertStartTime( p_evt->i_start_time );
i_duration = EITConvertDuration( p_evt->i_duration );
+ if( p_sys->arib.e_mode == ARIBMODE_ENABLED )
+ {
+ if( p_sys->i_tdt_delta == 0 )
+ p_sys->i_tdt_delta = CLOCK_FREQ * (i_start + i_duration - 5) - mdate();
+
+ i_tot_time = (mdate() + p_sys->i_tdt_delta) / CLOCK_FREQ;
+
+ tzset(); // JST -> UTC
+ i_start += timezone; // FIXME: what about DST?
+ i_tot_time += timezone;
+
+ if( p_evt->i_running_status == 0x00 &&
+ (i_start - 5 < i_tot_time &&
+ i_tot_time < i_start + i_duration + 5) )
+ {
+ p_evt->i_running_status = 0x04;
+ msg_Dbg( p_demux, " EIT running status 0x00 -> 0x04" );
+ }
+ }
+
msg_Dbg( p_demux, " * event id=%d start_time:%d duration=%d "
"running=%d free_ca=%d",
p_evt->i_event_id, (int)i_start, (int)i_duration,
for( p_dr = p_evt->p_first_descriptor; p_dr; p_dr = p_dr->p_next )
{
- if( p_dr->i_tag == 0x4d )
+ switch(p_dr->i_tag)
+ {
+ case 0x4d:
{
dvbpsi_short_event_dr_t *pE = dvbpsi_DecodeShortEventDr( p_dr );
/* Only take first description, as we don't handle language-info
for epg atm*/
- if( pE && psz_name == NULL)
+ if( pE && psz_name == NULL )
{
- psz_name = EITConvertToUTF8( pE->i_event_name, pE->i_event_name_length,
+ psz_name = EITConvertToUTF8( p_demux,
+ pE->i_event_name, pE->i_event_name_length,
p_sys->b_broken_charset );
- psz_text = EITConvertToUTF8( pE->i_text, pE->i_text_length,
+ free( psz_text );
+ psz_text = EITConvertToUTF8( p_demux,
+ pE->i_text, pE->i_text_length,
p_sys->b_broken_charset );
msg_Dbg( p_demux, " - short event lang=%3.3s '%s' : '%s'",
pE->i_iso_639_code, psz_name, psz_text );
}
}
- else if( p_dr->i_tag == 0x4e )
+ break;
+
+ case 0x4e:
{
dvbpsi_extended_event_dr_t *pE = dvbpsi_DecodeExtendedEventDr( p_dr );
if( pE )
if( pE->i_text_length > 0 )
{
- char *psz_text = EITConvertToUTF8( pE->i_text, pE->i_text_length,
+ char *psz_text = EITConvertToUTF8( p_demux,
+ pE->i_text, pE->i_text_length,
p_sys->b_broken_charset );
if( psz_text )
{
for( int i = 0; i < pE->i_entry_count; i++ )
{
- char *psz_dsc = EITConvertToUTF8( pE->i_item_description[i],
+ char *psz_dsc = EITConvertToUTF8( p_demux,
+ pE->i_item_description[i],
pE->i_item_description_length[i],
p_sys->b_broken_charset );
- char *psz_itm = EITConvertToUTF8( pE->i_item[i], pE->i_item_length[i],
+ char *psz_itm = EITConvertToUTF8( p_demux,
+ pE->i_item[i], pE->i_item_length[i],
p_sys->b_broken_charset );
if( psz_dsc && psz_itm )
}
}
}
- else if( p_dr->i_tag == 0x55 )
+ break;
+
+ case 0x55:
{
dvbpsi_parental_rating_dr_t *pR = dvbpsi_DecodeParentalRatingDr( p_dr );
if ( pR )
{
if ( p_rating->i_rating + 3 > i_min_age )
i_min_age = p_rating->i_rating + 3;
- msg_Dbg( p_demux, "..* event parental control set to %d years",
+ msg_Dbg( p_demux, " - parental control set to %d years",
i_min_age );
}
}
}
}
- else
- {
- msg_Dbg( p_demux, " - tag=0x%x(%d)", p_dr->i_tag, p_dr->i_tag );
+ break;
+
+ default:
+ msg_Dbg( p_demux, " - event unknown dr 0x%x(%d)", p_dr->i_tag, p_dr->i_tag );
+ break;
}
}
/* */
- if( i_start > 0 )
+ if( i_start > 0 && psz_name && psz_text)
vlc_epg_AddEvent( p_epg, i_start, i_duration, psz_name, psz_text,
*psz_extra ? psz_extra : NULL, i_min_age );
/* Update "now playing" field */
- if( p_evt->i_running_status == 0x04 && i_start > 0 )
+ if( p_evt->i_running_status == 0x04 && i_start > 0 && psz_name && psz_text )
vlc_epg_SetCurrent( p_epg, i_start );
free( psz_name );
#endif
}
else if( p_demux->p_sys->pid[0x11].psi->i_sdt_version != -1 &&
- i_table_id == 0x70 ) /* TDT */
+ (i_table_id == 0x70 /* TDT */ || i_table_id == 0x73 /* TOT */) )
{
msg_Dbg( p_demux, "PSINewTableCallBack: table 0x%x(%d) ext=0x%x(%d)",
i_table_id, i_table_id, i_extension, i_extension );
assert( strlen(psz_tag) == 4 );
return !memcmp( p_dr->p_data, psz_tag, 4 );
}
+
+static bool PMTEsHasComponentTag( const dvbpsi_pmt_es_t *p_es,
+ int i_component_tag )
+{
+ dvbpsi_descriptor_t *p_dr = PMTEsFindDescriptor( p_es, 0x52 );
+ if( !p_dr )
+ return false;
+ dvbpsi_stream_identifier_dr_t *p_si = dvbpsi_DecodeStreamIdentifierDr( p_dr );
+ if( !p_si )
+ return false;
+
+ return p_si->i_component_tag == i_component_tag;
+}
+
static void PMTSetupEsISO14496( demux_t *p_demux, ts_pid_t *pid,
const ts_prg_psi_t *prg, const dvbpsi_pmt_es_t *p_es )
{
es_format_t *p_fmt = &pid->es->fmt;
- /* MPEG-4 stream: search SL_DESCRIPTOR */
+ /* MPEG-4 stream: search FMC_DESCRIPTOR (SL Packetized stream) */
dvbpsi_descriptor_t *p_dr = PMTEsFindDescriptor( p_es, 0x1f );
if( p_dr && p_dr->i_length == 2 )
{
const int i_es_id = ( p_dr->p_data[0] << 8 ) | p_dr->p_data[1];
- msg_Warn( p_demux, "found SL_descriptor es_id=%d", i_es_id );
+ msg_Dbg( p_demux, "found FMC_descriptor declaring sl packetization on es_id=%d", i_es_id );
pid->es->p_mpeg4desc = NULL;
- for( int i = 0; i < 255; i++ )
+ for( int i = 0; i < ES_DESCRIPTOR_COUNT; i++ )
{
iod_descriptor_t *iod = prg->iod;
-
- if( iod->es_descr[i].b_ok && iod->es_descr[i].i_es_id == i_es_id )
+ if( iod->es_descr[i].i_es_id == i_es_id )
{
- pid->es->p_mpeg4desc = &iod->es_descr[i];
+ if ( iod->es_descr[i].b_ok )
+ pid->es->p_mpeg4desc = &iod->es_descr[i];
+ else
+ msg_Dbg( p_demux, "MPEG-4 descriptor not yet available on es_id=%d", i_es_id );
break;
}
}
}
if( !pid->es->p_mpeg4desc )
{
- msg_Err( p_demux, "MPEG-4 descriptor not found" );
+ switch( p_es->i_type )
+ {
+ /* non fatal, set by packetizer */
+ case 0x0f: /* ADTS */
+ case 0x11: /* LOAS */
+ msg_Info( p_demux, "MPEG-4 descriptor not found for pid 0x%x type 0x%x",
+ pid->i_pid, p_es->i_type );
+ break;
+ default:
+ msg_Err( p_demux, "MPEG-4 descriptor not found for pid 0x%x type 0x%x",
+ pid->i_pid, p_es->i_type );
+ break;
+ }
return;
}
/* */
const ts_teletext_page_t *p = &p_page[i];
- p_es->fmt.i_priority = (p->i_type == 0x02 || p->i_type == 0x05) ? 0 : -1;
+ p_es->fmt.i_priority = (p->i_type == 0x02 || p->i_type == 0x05) ?
+ ES_PRIORITY_SELECTABLE_MIN : ES_PRIORITY_NOT_DEFAULTABLE;
p_es->fmt.psz_language = strndup( p->p_iso639, 3 );
p_es->fmt.psz_description = strdup(vlc_gettext(ppsz_teletext_type[p->i_type]));
p_es->fmt.subs.teletext.i_magazine = p->i_magazine;
}
}
}
+
+static int vlc_ceil_log2( const unsigned int val )
+{
+ int n = 31 - clz(val);
+ if ((1U << n) != val)
+ n++;
+
+ return n;
+}
+
+static void OpusSetup(demux_t *demux, uint8_t *p, size_t len, es_format_t *p_fmt)
+{
+ OpusHeader h;
+
+ /* default mapping */
+ static const unsigned char map[8] = { 0, 1, 2, 3, 4, 5, 6, 7 };
+ memcpy(h.stream_map, map, sizeof(map));
+
+ int csc, mapping;
+ int channels = 0;
+ int stream_count = 0;
+ int ccc = p[1]; // channel_config_code
+ if (ccc <= 8) {
+ channels = ccc;
+ if (channels)
+ mapping = channels > 2;
+ else {
+ mapping = 255;
+ channels = 2; // dual mono
+ }
+ static const uint8_t p_csc[8] = { 0, 1, 1, 2, 2, 2, 3, 3 };
+ csc = p_csc[channels - 1];
+ stream_count = channels - csc;
+
+ static const uint8_t map[6][7] = {
+ { 2,1 },
+ { 1,2,3 },
+ { 4,1,2,3 },
+ { 4,1,2,3,5 },
+ { 4,1,2,3,5,6 },
+ { 6,1,2,3,4,5,7 },
+ };
+ if (channels > 2)
+ memcpy(&h.stream_map[1], map[channels-3], channels - 1);
+ } else if (ccc == 0x81) {
+ if (len < 4)
+ goto explicit_config_too_short;
+
+ channels = p[2];
+ mapping = p[3];
+ csc = 0;
+ if (mapping) {
+ bs_t s;
+ bs_init(&s, &p[4], len - 4);
+ stream_count = 1;
+ if (channels) {
+ int bits = vlc_ceil_log2(channels);
+ if (s.i_left < bits)
+ goto explicit_config_too_short;
+ stream_count = bs_read(&s, bits) + 1;
+ bits = vlc_ceil_log2(stream_count + 1);
+ if (s.i_left < bits)
+ goto explicit_config_too_short;
+ csc = bs_read(&s, bits);
+ }
+ int channel_bits = vlc_ceil_log2(stream_count + csc + 1);
+ if (s.i_left < channels * channel_bits)
+ goto explicit_config_too_short;
+
+ unsigned char silence = (1U << (stream_count + csc + 1)) - 1;
+ for (int i = 0; i < channels; i++) {
+ unsigned char m = bs_read(&s, channel_bits);
+ if (m == silence)
+ m = 0xff;
+ h.stream_map[i] = m;
+ }
+ }
+ } else if (ccc >= 0x80 && ccc <= 0x88) {
+ channels = ccc - 0x80;
+ if (channels)
+ mapping = 1;
+ else {
+ mapping = 255;
+ channels = 2; // dual mono
+ }
+ csc = 0;
+ stream_count = channels;
+ } else {
+ msg_Err(demux, "Opus channel configuration 0x%.2x is reserved", ccc);
+ }
+
+ if (!channels) {
+ msg_Err(demux, "Opus channel configuration 0x%.2x not supported yet", p[1]);
+ return;
+ }
+
+ opus_prepare_header(channels, 0, &h);
+ h.preskip = 0;
+ h.input_sample_rate = 48000;
+ h.nb_coupled = csc;
+ h.nb_streams = channels - csc;
+ h.channel_mapping = mapping;
+
+ if (h.channels) {
+ opus_write_header((uint8_t**)&p_fmt->p_extra, &p_fmt->i_extra, &h, NULL /* FIXME */);
+ if (p_fmt->p_extra) {
+ p_fmt->i_cat = AUDIO_ES;
+ p_fmt->i_codec = VLC_CODEC_OPUS;
+ p_fmt->audio.i_channels = h.channels;
+ p_fmt->audio.i_rate = 48000;
+ }
+ }
+
+ return;
+
+explicit_config_too_short:
+ msg_Err(demux, "Opus descriptor too short");
+}
+
static void PMTSetupEs0x06( demux_t *p_demux, ts_pid_t *pid,
const dvbpsi_pmt_es_t *p_es )
{
es_format_t *p_fmt = &pid->es->fmt;
+ dvbpsi_descriptor_t *p_subs_dr = PMTEsFindDescriptor( p_es, 0x59 );
+ dvbpsi_descriptor_t *desc;
if( PMTEsHasRegistration( p_demux, p_es, "AC-3" ) ||
PMTEsFindDescriptor( p_es, 0x6a ) ||
p_fmt->i_cat = AUDIO_ES;
p_fmt->i_codec = VLC_CODEC_A52;
}
+ else if( (desc = PMTEsFindDescriptor( p_es, 0x7f ) ) && desc->i_length >= 2 &&
+ PMTEsHasRegistration(p_demux, p_es, "Opus"))
+ {
+ OpusSetup(p_demux, desc->p_data, desc->i_length, p_fmt);
+ }
else if( PMTEsFindDescriptor( p_es, 0x7a ) )
{
/* DVB with stream_type 0x06 (ETS EN 300 468) */
p_fmt->i_cat = AUDIO_ES;
p_fmt->i_codec = VLC_CODEC_DTS;
}
- else if( PMTEsHasRegistration( p_demux, p_es, "BSSD" ) )
+ else if( PMTEsHasRegistration( p_demux, p_es, "BSSD" ) && !p_subs_dr )
{
+ /* BSSD is AES3 DATA, but could also be subtitles
+ * we need to check for secondary descriptor then s*/
p_fmt->i_cat = AUDIO_ES;
p_fmt->b_packetized = true;
p_fmt->i_codec = VLC_CODEC_302M;
}
+ else if( PMTEsHasRegistration( p_demux, p_es, "HEVC" ) )
+ {
+ p_fmt->i_cat = VIDEO_ES;
+ p_fmt->i_codec = VLC_CODEC_HEVC;
+ }
+ else if ( p_demux->p_sys->arib.e_mode == ARIBMODE_ENABLED )
+ {
+ /* Lookup our data component descriptor first ARIB STD B10 6.4 */
+ dvbpsi_descriptor_t *p_dr = PMTEsFindDescriptor( p_es, 0xFD );
+ /* and check that it maps to something ARIB STD B14 Table 5.1/5.2 */
+ if ( p_dr && p_dr->i_length >= 2 )
+ {
+ if( !memcmp( p_dr->p_data, "\x00\x08", 2 ) && (
+ PMTEsHasComponentTag( p_es, 0x30 ) ||
+ PMTEsHasComponentTag( p_es, 0x31 ) ||
+ PMTEsHasComponentTag( p_es, 0x32 ) ||
+ PMTEsHasComponentTag( p_es, 0x33 ) ||
+ PMTEsHasComponentTag( p_es, 0x34 ) ||
+ PMTEsHasComponentTag( p_es, 0x35 ) ||
+ PMTEsHasComponentTag( p_es, 0x36 ) ||
+ PMTEsHasComponentTag( p_es, 0x37 ) ) )
+ {
+ es_format_Init( &pid->es->fmt, SPU_ES, VLC_CODEC_ARIB_A );
+ p_fmt->psz_language = strndup ( "jpn", 3 );
+ p_fmt->psz_description = strdup( _("ARIB subtitles") );
+ }
+ else if( !memcmp( p_dr->p_data, "\x00\x12", 2 ) && (
+ PMTEsHasComponentTag( p_es, 0x87 ) ||
+ PMTEsHasComponentTag( p_es, 0x88 ) ) )
+ {
+ es_format_Init( &pid->es->fmt, SPU_ES, VLC_CODEC_ARIB_C );
+ p_fmt->psz_language = strndup ( "jpn", 3 );
+ p_fmt->psz_description = strdup( _("ARIB subtitles") );
+ }
+ }
+ }
else
{
/* Subtitle/Teletext/VBI fallbacks */
- dvbpsi_descriptor_t *p_dr = PMTEsFindDescriptor( p_es, 0x59 );
-
dvbpsi_subtitling_dr_t *p_sub;
- if( p_dr && ( p_sub = dvbpsi_DecodeSubtitlingDr( p_dr ) ) )
+ if( p_subs_dr && ( p_sub = dvbpsi_DecodeSubtitlingDr( p_subs_dr ) ) )
{
for( int i = 0; i < p_sub->i_subtitles_number; i++ )
{
p_fmt->b_packetized = true;
}
-static void PMTSetupEsHDMV( ts_pid_t *pid, const dvbpsi_pmt_es_t *p_es )
+static void PMTSetupEs0x83( const dvbpsi_pmt_t *p_pmt, ts_pid_t *pid )
+{
+ /* WiDi broadcasts without registration on PMT 0x1, PCR 0x1000 and
+ * with audio track pid being 0x1100..0x11FF */
+ if ( p_pmt->i_program_number == 0x1 &&
+ p_pmt->i_pcr_pid == 0x1000 &&
+ ( pid->i_pid >> 8 ) == 0x11 )
+ {
+ /* Not enough ? might contain 0x83 private descriptor, 2 bytes 0x473F */
+ es_format_Init( &pid->es->fmt, AUDIO_ES, VLC_CODEC_WIDI_LPCM );
+ }
+ else
+ es_format_Init( &pid->es->fmt, AUDIO_ES, VLC_CODEC_DVD_LPCM );
+}
+
+static bool PMTSetupEsHDMV( demux_t *p_demux, ts_pid_t *pid,
+ const dvbpsi_pmt_es_t *p_es )
{
es_format_t *p_fmt = &pid->es->fmt;
p_fmt->i_cat = AUDIO_ES;
p_fmt->i_codec = VLC_CODEC_BD_LPCM;
break;
+ case 0x81:
+ p_fmt->i_cat = AUDIO_ES;
+ p_fmt->i_codec = VLC_CODEC_A52;
+ break;
case 0x82:
case 0x85: /* DTS-HD High resolution audio */
case 0x86: /* DTS-HD Master audio */
break;
case 0x91: /* Interactive graphics */
case 0x92: /* Subtitle */
+ return false;
+ case 0xEA:
+ p_fmt->i_cat = VIDEO_ES;
+ p_fmt->i_codec = VLC_CODEC_VC1;
+ break;
default:
+ msg_Info( p_demux, "HDMV registration not implemented for pid 0x%x type 0x%x",
+ p_es->i_pid, p_es->i_type );
+ return false;
break;
}
+ return true;
}
-static void PMTSetupEsRegistration( demux_t *p_demux, ts_pid_t *pid,
+static bool PMTSetupEsRegistration( demux_t *p_demux, ts_pid_t *pid,
const dvbpsi_pmt_es_t *p_es )
{
static const struct
p_fmt->i_codec = p_regs[i].i_codec;
if (p_es->i_type == 0x87)
p_fmt->i_codec = VLC_CODEC_EAC3;
- return;
+ return true;
}
}
+ return false;
}
static char *GetAudioTypeDesc(demux_t *p_demux, int type)
int type = p_decoded->code[0].i_audio_type;
pid->es->fmt.psz_description = GetAudioTypeDesc(p_demux, type);
if (type == 0)
- pid->es->fmt.i_priority = 1; // prioritize normal audio tracks
+ pid->es->fmt.i_priority = ES_PRIORITY_SELECTABLE_MIN + 1; // prioritize normal audio tracks
pid->es->fmt.i_extra_languages = p_decoded->i_code_count-1;
if( pid->es->fmt.i_extra_languages > 0 )
#endif
}
+static void AddAndCreateES( demux_t *p_demux, ts_pid_t *pid )
+{
+ demux_sys_t *p_sys = p_demux->p_sys;
+ bool b_create_delayed = false;
+
+ if( pid )
+ {
+ if( pid->b_seen && p_sys->b_delay_es_creation )
+ {
+ p_sys->b_delay_es_creation = false;
+ b_create_delayed = true;
+ }
+
+ if( !p_sys->b_delay_es_creation )
+ {
+ pid->es->id = es_out_Add( p_demux->out, &pid->es->fmt );
+ for( int i = 0; i < pid->i_extra_es; i++ )
+ {
+ pid->extra_es[i]->id =
+ es_out_Add( p_demux->out, &pid->extra_es[i]->fmt );
+ }
+ p_sys->i_pmt_es += 1 + pid->i_extra_es;
+ }
+ }
+ else if( p_sys->b_delay_es_creation )
+ {
+ p_sys->b_delay_es_creation = false;
+ b_create_delayed = true;
+ }
+
+ if( b_create_delayed )
+ {
+ for(int i=MIN_ES_PID; i<MAX_ES_PID; i++)
+ {
+ pid = &p_sys->pid[i];
+ if(!pid->es || pid->es->id)
+ continue;
+ pid->es->id = es_out_Add( p_demux->out, &pid->es->fmt );
+ for( int j = 0; j < pid->i_extra_es; j++ )
+ {
+ pid->extra_es[j]->id =
+ es_out_Add( p_demux->out, &pid->extra_es[j]->fmt );
+ }
+ p_sys->i_pmt_es += 1 + pid->i_extra_es;
+ }
+ }
+}
+
static void PMTCallBack( void *data, dvbpsi_pmt_t *p_pmt )
{
demux_t *p_demux = data;
if( ProgramIsSelected( p_demux, prg->i_number ) )
SetPIDFilter( p_demux, prg->i_pid_pcr, true ); /* Set demux filter */
- /* Parse descriptor */
- bool b_hdmv = false;
+ /* Parse PMT descriptors */
+ ts_pmt_registration_type_t registration_type = TS_PMT_REGISTRATION_NONE;
dvbpsi_descriptor_t *p_dr;
+
+ /* First pass for standard detection */
+ if ( p_sys->arib.e_mode == ARIBMODE_AUTO )
+ {
+ int i_arib_flags = 0; /* Descriptors can be repeated */
+ for( p_dr = p_pmt->p_first_descriptor; p_dr != NULL; p_dr = p_dr->p_next )
+ {
+ switch(p_dr->i_tag)
+ {
+ case 0x09:
+ {
+ dvbpsi_ca_dr_t *p_cadr = dvbpsi_DecodeCADr( p_dr );
+ i_arib_flags |= (p_cadr->i_ca_system_id == 0x05);
+ }
+ break;
+ case 0xF6:
+ i_arib_flags |= 1 << 1;
+ break;
+ case 0xC1:
+ i_arib_flags |= 1 << 2;
+ break;
+ default:
+ break;
+ }
+ }
+ if ( i_arib_flags == 0x07 ) //0b111
+ p_sys->arib.e_mode = ARIBMODE_ENABLED;
+ }
+
for( p_dr = p_pmt->p_first_descriptor; p_dr != NULL; p_dr = p_dr->p_next )
+ {
+ /* special descriptors handling */
switch(p_dr->i_tag)
{
case 0x1d: /* We have found an IOD descriptor */
- msg_Dbg( p_demux, " * descriptor : IOD (0x1d)" );
+ msg_Dbg( p_demux, " * PMT descriptor : IOD (0x1d)" );
prg->iod = IODNew( p_dr->i_length, p_dr->p_data );
break;
case 0x9:
- msg_Dbg( p_demux, " * descriptor : CA (0x9) SysID 0x%x",
+ msg_Dbg( p_demux, " * PMT descriptor : CA (0x9) SysID 0x%x",
(p_dr->p_data[0] << 8) | p_dr->p_data[1] );
break;
case 0x5: /* Registration Descriptor */
if( p_dr->i_length != 4 )
{
- msg_Warn( p_demux, "invalid Registration Descriptor" );
+ msg_Warn( p_demux, " * PMT invalid Registration Descriptor" );
}
else
{
- msg_Dbg( p_demux, " * descriptor : registration %4.4s", p_dr->p_data );
+ msg_Dbg( p_demux, " * PMT descriptor : registration %4.4s", p_dr->p_data );
if( !memcmp( p_dr->p_data, "HDMV", 4 ) || !memcmp( p_dr->p_data, "HDPR", 4 ) )
- b_hdmv = true; /* Blu-Ray */
+ registration_type = TS_PMT_REGISTRATION_HDMV; /* Blu-Ray */
}
break;
+ case 0x0f:
+ msg_Dbg( p_demux, " * PMT descriptor : Private Data (0x0f)" );
+ break;
+
+ case 0xC1:
+ msg_Dbg( p_demux, " * PMT descriptor : Digital copy control (0xC1)" );
+ break;
+
+ case 0x88: /* EACEM Simulcast HD Logical channels ordering */
+ msg_Dbg( p_demux, " * descriptor : EACEM Simulcast HD" );
+ /* TODO: apply visibility flags */
+ break;
+
default:
- msg_Dbg( p_demux, " * descriptor : unknown (0x%x)", p_dr->i_tag );
+ msg_Dbg( p_demux, " * PMT descriptor : unknown (0x%x)", p_dr->i_tag );
}
-
+ }
dvbpsi_pmt_es_t *p_es;
for( p_es = p_pmt->p_first_es; p_es != NULL; p_es = p_es->p_next )
{
- ts_pid_t tmp_pid, *old_pid = 0, *pid = &tmp_pid;
+ ts_pid_t tmp_pid = {0}, *old_pid = {0}, *pid = &tmp_pid;
/* Find out if the PID was already declared */
for( int i = 0; i < i_clean; i++ )
if( !old_pid && p_sys->pid[p_es->i_pid].b_valid )
{
- msg_Warn( p_demux, "pmt error: pid=%d already defined",
+ msg_Warn( p_demux, " * PMT error: pid=%d already defined",
p_es->i_pid );
continue;
}
+ char const * psz_typedesc = "";
+ switch(p_es->i_type)
+ {
+ case 0x00:
+ psz_typedesc = "ISO/IEC Reserved";
+ break;
+ case 0x01:
+ psz_typedesc = "ISO/IEC 11172 Video";
+ break;
+ case 0x02:
+ psz_typedesc = "ISO/IEC 13818-2 Video or ISO/IEC 11172-2 constrained parameter video stream";
+ break;
+ case 0x03:
+ psz_typedesc = "ISO/IEC 11172 Audio";
+ break;
+ case 0x04:
+ psz_typedesc = "ISO/IEC 13818-3 Audio";
+ break;
+ case 0x05:
+ psz_typedesc = "ISO/IEC 13818-1 private_sections";
+ break;
+ case 0x06:
+ psz_typedesc = "ISO/IEC 13818-1 PES packets containing private data";
+ break;
+ case 0x07:
+ psz_typedesc = "ISO/IEC 13522 MHEG";
+ break;
+ case 0x08:
+ psz_typedesc = "ISO/IEC 13818-1 Annex A DSM CC";
+ break;
+ case 0x09:
+ psz_typedesc = "ITU-T Rec. H.222.1";
+ break;
+ case 0x0A:
+ psz_typedesc = "ISO/IEC 13818-6 type A";
+ break;
+ case 0x0B:
+ psz_typedesc = "ISO/IEC 13818-6 type B";
+ break;
+ case 0x0C:
+ psz_typedesc = "ISO/IEC 13818-6 type C";
+ break;
+ case 0x0D:
+ psz_typedesc = "ISO/IEC 13818-6 type D";
+ break;
+ case 0x0E:
+ psz_typedesc = "ISO/IEC 13818-1 auxiliary";
+ break;
+ default:
+ if (p_es->i_type >= 0x0F && p_es->i_type <=0x7F)
+ psz_typedesc = "ISO/IEC 13818-1 Reserved";
+ else
+ psz_typedesc = "User Private";
+ }
+
+ msg_Dbg( p_demux, " * pid=%d type=0x%x %s",
+ p_es->i_pid, p_es->i_type, psz_typedesc );
+
for( p_dr = p_es->p_first_descriptor; p_dr != NULL;
p_dr = p_dr->p_next )
{
- msg_Dbg( p_demux, " * es pid=%d type=%d dr->i_tag=0x%x",
- p_es->i_pid, p_es->i_type, p_dr->i_tag );
+ msg_Dbg( p_demux, " - descriptor tag 0x%x",
+ p_dr->i_tag );
}
PIDInit( pid, false, pmt->psi );
- PIDFillFormat( pid->es, p_es->i_type );
+ PIDFillFormat( &pid->es->fmt, p_es->i_type );
pid->i_owner_number = prg->i_number;
pid->i_pid = p_es->i_pid;
pid->b_seen = p_sys->pid[p_es->i_pid].b_seen;
- if( p_es->i_type == 0x10 || p_es->i_type == 0x11 ||
- p_es->i_type == 0x12 || p_es->i_type == 0x0f )
- {
- PMTSetupEsISO14496( p_demux, pid, prg, p_es );
- }
- else if( p_es->i_type == 0x06 )
- {
- PMTSetupEs0x06( p_demux, pid, p_es );
- }
- else if( p_es->i_type == 0xEA )
- {
- PMTSetupEs0xEA( p_demux, pid, p_es );
- }
- else if( p_es->i_type == 0xd1 )
- {
- PMTSetupEs0xD1( p_demux, pid, p_es );
- }
- else if( p_es->i_type == 0xa0 )
- {
- PMTSetupEs0xA0( p_demux, pid, p_es );
- }
- else if( b_hdmv )
+
+ bool b_registration_applied = false;
+ if ( p_es->i_type >= 0x80 ) /* non standard, extensions */
{
- PMTSetupEsHDMV( pid, p_es );
+ if ( registration_type == TS_PMT_REGISTRATION_HDMV )
+ {
+ if (( b_registration_applied = PMTSetupEsHDMV( p_demux, pid, p_es ) ))
+ msg_Dbg( p_demux, " + HDMV registration applied to pid %d type 0x%x",
+ p_es->i_pid, p_es->i_type );
+ }
+ else
+ {
+ if (( b_registration_applied = PMTSetupEsRegistration( p_demux, pid, p_es ) ))
+ msg_Dbg( p_demux, " + registration applied to pid %d type 0x%x",
+ p_es->i_pid, p_es->i_type );
+ }
}
- else if( p_es->i_type >= 0x80 )
+
+ if ( !b_registration_applied )
{
- PMTSetupEsRegistration( p_demux, pid, p_es );
+ switch( p_es->i_type )
+ {
+ case 0x06:
+ /* Handle PES private data */
+ PMTSetupEs0x06( p_demux, pid, p_es );
+ break;
+ /* All other private or reserved types */
+ case 0x0f:
+ case 0x10:
+ case 0x11:
+ case 0x12:
+ PMTSetupEsISO14496( p_demux, pid, prg, p_es );
+ break;
+ case 0x83:
+ /* LPCM (audio) */
+ PMTSetupEs0x83( p_pmt, pid );
+ break;
+ case 0xa0:
+ PMTSetupEs0xA0( p_demux, pid, p_es );
+ break;
+ case 0xd1:
+ PMTSetupEs0xD1( p_demux, pid, p_es );
+ break;
+ case 0xEA:
+ PMTSetupEs0xEA( p_demux, pid, p_es );
+ default:
+ break;
+ }
}
if( pid->es->fmt.i_cat == AUDIO_ES ||
PMTParseEsIso639( p_demux, pid, p_es );
}
+ switch( pid->es->fmt.i_codec )
+ {
+ case VLC_CODEC_SCTE_27:
+ pid->es->data_type = TS_ES_DATA_TABLE_SECTION;
+ break;
+ default:
+ //pid->es->data_type = TS_ES_DATA_PES;
+ break;
+ }
+
pid->es->fmt.i_group = p_pmt->i_program_number;
for( int i = 0; i < pid->i_extra_es; i++ )
pid->extra_es[i]->fmt.i_group = p_pmt->i_program_number;
if( pid->es->fmt.i_cat == UNKNOWN_ES )
{
- msg_Dbg( p_demux, " * es pid=%d type=%d *unknown*",
- p_es->i_pid, p_es->i_type );
+ msg_Dbg( p_demux, " => pid %d content is *unknown*",
+ p_es->i_pid );
}
- else if( !p_sys->b_udp_out )
+ else
{
- msg_Dbg( p_demux, " * es pid=%d type=%d fcc=%4.4s",
- p_es->i_pid, p_es->i_type, (char*)&pid->es->fmt.i_codec );
+ msg_Dbg( p_demux, " => pid %d has now es fcc=%4.4s",
+ p_es->i_pid, (char*)&pid->es->fmt.i_codec );
if( p_sys->b_es_id_pid ) pid->es->fmt.i_id = p_es->i_pid;
}
else
{
- pid->es->id = es_out_Add( p_demux->out, &pid->es->fmt );
- for( int i = 0; i < pid->i_extra_es; i++ )
- {
- pid->extra_es[i]->id =
- es_out_Add( p_demux->out, &pid->extra_es[i]->fmt );
- }
- p_sys->i_pmt_es += 1 + pid->i_extra_es;
+ AddAndCreateES( p_demux, pid );
}
}
p_dr = PMTEsFindDescriptor( p_es, 0x09 );
if( p_dr && p_dr->i_length >= 2 )
{
- msg_Dbg( p_demux, " * descriptor : CA (0x9) SysID 0x%x",
+ msg_Dbg( p_demux, " * PMT descriptor : CA (0x9) SysID 0x%x",
(p_dr->p_data[0] << 8) | p_dr->p_data[1] );
}
- if( ProgramIsSelected( p_demux, prg->i_number ) &&
- ( pid->es->id != NULL || p_sys->b_udp_out ) )
+ if( ProgramIsSelected( p_demux, prg->i_number ) && pid->es->id != NULL )
SetPIDFilter( p_demux, p_es->i_pid, true ); /* Set demux filter */
}
/* Set CAM descrambling */
- if( !ProgramIsSelected( p_demux, prg->i_number )
- || stream_Control( p_demux->s, STREAM_SET_PRIVATE_ID_CA,
- p_pmt ) != VLC_SUCCESS )
+ if( !ProgramIsSelected( p_demux, prg->i_number ) )
+ {
dvbpsi_DeletePMT( p_pmt );
+ }
+ else if( stream_Control( p_sys->stream, STREAM_SET_PRIVATE_ID_CA,
+ p_pmt ) != VLC_SUCCESS )
+ {
+ if ( p_sys->arib.e_mode == ARIBMODE_ENABLED )
+ {
+ p_sys->arib.b25stream = stream_FilterNew( p_demux->s, "aribcam" );
+ p_sys->stream = ( p_sys->arib.b25stream ) ? p_sys->arib.b25stream : p_demux->s;
+ if (!p_sys->arib.b25stream)
+ dvbpsi_DeletePMT( p_pmt );
+ } else dvbpsi_DeletePMT( p_pmt );
+ }
for( int i = 0; i < i_clean; i++ )
{