/*****************************************************************************
* ts.c: Transport Stream input module for VLC.
*****************************************************************************
* Copyright (C) 2004-2005 the VideoLAN team
* $Id: e93ffa9f7bf03963b48a999684f8ab77f97cd6da $
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
* Jean-Paul Saman <jpsaman #_at_# m2x.nl>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
/*****************************************************************************
* Preamble
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <vlc_common.h>
#include <vlc_plugin.h>
#include <ctype.h>
#include <vlc_access.h> /* DVB-specific things */
#include <vlc_demux.h>
#include <vlc_meta.h>
#include <vlc_epg.h>
#include <vlc_iso_lang.h>
#include <vlc_network.h>
#include <vlc_charset.h>
#include "../mux/mpeg/csa.h"
/* Include dvbpsi headers */
#ifdef HAVE_DVBPSI_DR_H
# include <dvbpsi/dvbpsi.h>
# include <dvbpsi/demux.h>
# include <dvbpsi/descriptor.h>
# include <dvbpsi/pat.h>
# include <dvbpsi/pmt.h>
# include <dvbpsi/sdt.h>
# include <dvbpsi/dr.h>
# include <dvbpsi/psi.h>
#else
# include "dvbpsi.h"
# include "demux.h"
# include "descriptor.h"
# include "tables/pat.h"
# include "tables/pmt.h"
# include "tables/sdt.h"
# include "descriptors/dr.h"
# include "psi.h"
#endif
/* EIT support */
#ifdef _DVBPSI_DR_4D_H_
# define TS_USE_DVB_SI 1
# ifdef HAVE_DVBPSI_DR_H
# include <dvbpsi/eit.h>
# else
# include "tables/eit.h"
# endif
#endif
#ifdef HAVE_TIME_H
# include <time.h>
#endif
#undef TS_DEBUG
/* TODO:
* - XXX: do not mark options message to be translated, they are too osbcure for now ...
* - test it
* - ...
*/
/*****************************************************************************
* Callback prototypes
*****************************************************************************/
static int ChangeKeyCallback ( vlc_object_t *, char const *, vlc_value_t, vlc_value_t, void * );
/*****************************************************************************
* Module descriptor
*****************************************************************************/
static int Open ( vlc_object_t * );
static void Close ( vlc_object_t * );
/* TODO
* - Rename "extra pmt" to "user pmt"
* - Update extra pmt description
* pmt_pid[:pmt_number][=pid_description[,pid_description]]
* where pid_description could take 3 forms:
* 1. pid:pcr (to force the pcr pid)
* 2. pid:stream_type
* 3. pid:type=fourcc where type=(video|audio|spu)
*/
#define PMT_TEXT N_("Extra PMT")
#define PMT_LONGTEXT N_( \
"Allows a user to specify an extra pmt (pmt_pid=pid:stream_type[,...])." )
#define PID_TEXT N_("Set id of ES to PID")
#define PID_LONGTEXT N_("Set the internal ID of each elementary stream" \
" handled by VLC to the same value as the PID in" \
" 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 ck")
#define CSA_LONGTEXT N_("Control word for the CSA encryption algorithm")
#define CSA2_TEXT N_("Second CSA Key")
#define CSA2_LONGTEXT N_("The even CSA encryption key. This must be a " \
"16 char string (8 hexadecimal bytes).")
#define SILENT_TEXT N_("Silent mode")
#define SILENT_LONGTEXT N_("Do not complain on encrypted PES.")
#define CAPMT_SYSID_TEXT N_("CAPMT System ID")
#define CAPMT_SYSID_LONGTEXT N_("Only forward descriptors from this SysID to the CAM.")
#define CPKT_TEXT N_("Packet size in bytes to decrypt")
#define CPKT_LONGTEXT N_("Specify the size of the TS packet to decrypt. " \
"The decryption routines subtract the TS-header from the value before " \
"decrypting. " )
#define TSDUMP_TEXT N_("Filename of dump")
#define TSDUMP_LONGTEXT N_("Specify a filename where to dump the TS in.")
#define APPEND_TEXT N_("Append")
#define APPEND_LONGTEXT N_( \
"If the file exists and this option is selected, the existing file " \
"will not be overwritten." )
#define DUMPSIZE_TEXT N_("Dump buffer size")
#define DUMPSIZE_LONGTEXT N_( \
"Tweak the buffer size for reading and writing an integer number of packets." \
"Specify the size of the buffer here and not the number of packets." )
vlc_module_begin();
set_description( N_("MPEG Transport Stream demuxer") );
set_shortname ( "MPEG-TS" );
set_category( CAT_INPUT );
set_subcategory( SUBCAT_INPUT_DEMUX );
add_string( "ts-extra-pmt", NULL, NULL, PMT_TEXT, PMT_LONGTEXT, true );
add_bool( "ts-es-id-pid", 1, NULL, PID_TEXT, PID_LONGTEXT, true );
add_string( "ts-out", NULL, NULL, TSOUT_TEXT, TSOUT_LONGTEXT, true );
add_integer( "ts-out-mtu", 1400, NULL, MTUOUT_TEXT,
MTUOUT_LONGTEXT, true );
add_string( "ts-csa-ck", NULL, NULL, CSA_TEXT, CSA_LONGTEXT, true );
add_string( "ts-csa2-ck", NULL, NULL, CSA_TEXT, CSA_LONGTEXT, true );
add_integer( "ts-csa-pkt", 188, NULL, CPKT_TEXT, CPKT_LONGTEXT, true );
add_bool( "ts-silent", 0, NULL, SILENT_TEXT, SILENT_LONGTEXT, true );
add_file( "ts-dump-file", NULL, NULL, TSDUMP_TEXT, TSDUMP_LONGTEXT, false );
change_unsafe();
add_bool( "ts-dump-append", 0, NULL, APPEND_TEXT, APPEND_LONGTEXT, false );
add_integer( "ts-dump-size", 16384, NULL, DUMPSIZE_TEXT,
DUMPSIZE_LONGTEXT, true );
set_capability( "demux", 10 );
set_callbacks( Open, Close );
add_shortcut( "ts" );
vlc_module_end();
/*****************************************************************************
* Local prototypes
*****************************************************************************/
typedef struct
{
uint8_t i_objectTypeIndication;
uint8_t i_streamType;
bool b_upStream;
uint32_t i_bufferSizeDB;
uint32_t i_maxBitrate;
uint32_t i_avgBitrate;
int i_decoder_specific_info_len;
uint8_t *p_decoder_specific_info;
} decoder_config_descriptor_t;
typedef struct
{
bool b_useAccessUnitStartFlag;
bool b_useAccessUnitEndFlag;
bool b_useRandomAccessPointFlag;
bool b_useRandomAccessUnitsOnlyFlag;
bool b_usePaddingFlag;
bool b_useTimeStampsFlags;
bool b_useIdleFlag;
bool b_durationFlag;
uint32_t i_timeStampResolution;
uint32_t i_OCRResolution;
uint8_t i_timeStampLength;
uint8_t i_OCRLength;
uint8_t i_AU_Length;
uint8_t i_instantBitrateLength;
uint8_t i_degra