⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ts.c

📁 video linux conference
💻 C
📖 第 1 页 / 共 5 页
字号:
/***************************************************************************** * ts.c: MPEG-II TS Muxer ***************************************************************************** * Copyright (C) 2001, 2002 VideoLAN * $Id: ts.c 11066 2005-05-18 21:46:47Z massiot $ * * Authors: Laurent Aimar <fenrir@via.ecp.fr> *          Eric Petit <titer@videolan.org> * * 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., 59 Temple Place - Suite 330, Boston, MA  02111, USA. *****************************************************************************//***************************************************************************** * Preamble *****************************************************************************/#include <stdlib.h>#include <vlc/vlc.h>#include <vlc/input.h>#include <vlc/sout.h>#include "iso_lang.h"#include "bits.h"#include "pes.h"#include "csa.h"#ifdef HAVE_DVBPSI_DR_H#   include <dvbpsi/dvbpsi.h>#   include <dvbpsi/descriptor.h>#   include <dvbpsi/pat.h>#   include <dvbpsi/pmt.h>#   include <dvbpsi/dr.h>#   include <dvbpsi/psi.h>#else#   include "dvbpsi.h"#   include "descriptor.h"#   include "tables/pat.h"#   include "tables/pmt.h"#   include "descriptors/dr.h"#   include "psi.h"#endif/* * TODO: *  - check PCR frequency requirement *  - check PAT/PMT  "        " *  - check PCR/PCR "soft" *  - check if "registration" descriptor : "AC-3" should be a program *    descriptor or an es one. (xine want an es one) * *  - remove creation of PAT/PMT without dvbpsi *  - ? * FIXME: *  - subtitle support is far from perfect. I expect some subtitles drop *    if they arrive a bit late *    (We cannot rely on the fact that the fifo should be full) *//***************************************************************************** * Module descriptor *****************************************************************************/static int     Open   ( vlc_object_t * );static void    Close  ( vlc_object_t * );#define VPID_TEXT N_("Video PID")#define VPID_LONGTEXT N_("Assigns a fixed PID to the video stream. The PCR " \  "PID will automatically be the video.")#define APID_TEXT N_("Audio PID")#define APID_LONGTEXT N_("Assigns a fixed PID to the audio stream.")#define SPUPID_TEXT N_("SPU PID")#define SPUPID_LONGTEXT N_("Assigns a fixed PID to the SPU.")#define PMTPID_TEXT N_("PMT PID")#define PMTPID_LONGTEXT N_("Assigns a fixed PID to the PMT")#define TSID_TEXT N_("TS ID")#define TSID_LONGTEXT N_("Assigns a fixed Transport Stream ID.")#define PMTPROG_TEXT N_("PMT Program number")#define PMTPROG_LONGTEXT N_("Assigns a program number to the PMT.")#define PID_TEXT N_("Set PID to id of ES")#define PID_LONGTEXT N_("set PID to id of es")#define SHAPING_TEXT N_("Shaping delay (ms)")#define SHAPING_LONGTEXT N_("If enabled, the TS muxer will cut the " \  "stream in slices of the given duration, and ensure a constant bitrate " \  "between the two boundaries. This avoids having huge bitrate peaks for " \  "reference frames, in particular.")#define KEYF_TEXT N_("Use keyframes")#define KEYF_LONGTEXT N_("If enabled, and shaping is specified, " \  "the TS muxer will place the boundaries at the end of I pictures. In " \  "that case, the shaping duration given by the user is a worse case " \  "used when no reference frame is available. This enhances the efficiency " \  "of the shaping algorithm, since I frames are usually the biggest " \  "frames in the stream.")#define PCR_TEXT N_("PCR delay (ms)")#define PCR_LONGTEXT N_("This option allows you to set at which interval " \  "PCRs (Program Clock Reference) will be sent. " \  "This value should be below 100ms. (default is 70)")#define BMIN_TEXT N_( "Minimum B (deprecated)")#define BMIN_LONGTEXT N_( "This setting is deprecated and not used anymore" )#define BMAX_TEXT N_( "Maximum B (deprecated)")#define BMAX_LONGTEXT N_( "This setting is deprecated and not used anymore")#define DTS_TEXT N_("DTS delay (ms)")#define DTS_LONGTEXT N_("This option will delay the DTS (decoding time " \  "stamps) and PTS (presentation timestamps) of the data in the " \  "stream, compared to the PCRs. This allows for some buffering inside " \  "the client decoder.")#define ACRYPT_TEXT N_("Crypt audio")#define ACRYPT_LONGTEXT N_("Crypt audio using CSA")#define CK_TEXT N_("CSA Key")#define CK_LONGTEXT N_("Defines the CSA encryption key. This must be a " \  "16 char string (8 hexadecimal bytes).")#define SOUT_CFG_PREFIX "sout-ts-"vlc_module_begin();    set_description( _("TS muxer (libdvbpsi)") );    set_shortname( "MPEG-TS");    set_category( CAT_SOUT );    set_subcategory( SUBCAT_SOUT_MUX );    set_capability( "sout mux", 120 );    add_shortcut( "ts" );    add_integer( SOUT_CFG_PREFIX "pid-video", 0, NULL,VPID_TEXT, VPID_LONGTEXT,                                  VLC_TRUE );    add_integer( SOUT_CFG_PREFIX "pid-audio", 0, NULL, APID_TEXT,                 APID_LONGTEXT, VLC_TRUE );    add_integer( SOUT_CFG_PREFIX "pid-spu", 0, NULL, SPUPID_TEXT,                 SPUPID_LONGTEXT, VLC_TRUE );    add_integer( SOUT_CFG_PREFIX "pid-pmt", 0, NULL, PMTPID_TEXT,                 PMTPID_LONGTEXT, VLC_TRUE );    add_integer( SOUT_CFG_PREFIX "tsid", 0, NULL, TSID_TEXT,                 TSID_LONGTEXT, VLC_TRUE );    add_integer( SOUT_CFG_PREFIX "program-pmt", 1, NULL, PMTPROG_TEXT,                 PMTPROG_LONGTEXT, VLC_TRUE );    add_bool( SOUT_CFG_PREFIX "es-id-pid", 0, NULL, PID_TEXT, PID_LONGTEXT,              VLC_TRUE );    add_integer( SOUT_CFG_PREFIX "shaping", 200, NULL,SHAPING_TEXT,                 SHAPING_LONGTEXT, VLC_TRUE );    add_bool( SOUT_CFG_PREFIX "use-key-frames", VLC_FALSE, NULL, KEYF_TEXT,              KEYF_LONGTEXT, VLC_TRUE );    add_integer( SOUT_CFG_PREFIX "pcr", 70, NULL, PCR_TEXT, PCR_LONGTEXT,                 VLC_TRUE );    add_integer( SOUT_CFG_PREFIX "bmin", 0, NULL, BMIN_TEXT, BMIN_LONGTEXT,                 VLC_TRUE );    add_integer( SOUT_CFG_PREFIX "bmax", 0, NULL, BMAX_TEXT, BMAX_LONGTEXT,                 VLC_TRUE );    add_integer( SOUT_CFG_PREFIX "dts-delay", 400, NULL, DTS_TEXT,                 DTS_LONGTEXT, VLC_TRUE );    add_bool( SOUT_CFG_PREFIX "crypt-audio", VLC_TRUE, NULL, ACRYPT_TEXT,              ACRYPT_LONGTEXT, VLC_TRUE );    add_string( SOUT_CFG_PREFIX "csa-ck", NULL, NULL, CK_TEXT, CK_LONGTEXT,                VLC_TRUE );    set_callbacks( Open, Close );vlc_module_end();/***************************************************************************** * Local data structures *****************************************************************************/static const char *ppsz_sout_options[] = {    "pid-video", "pid-audio", "pid-spu", "pid-pmt", "tsid", "program-pmt",    "es-id-pid", "shaping", "pcr", "bmin", "bmax", "use-key-frames",    "dts-delay", "csa-ck", "crypt-audio",    NULL};typedef struct{    int     i_depth;    block_t *p_first;    block_t **pp_last;} sout_buffer_chain_t;static inline void BufferChainInit  ( sout_buffer_chain_t *c ){    c->i_depth = 0;    c->p_first = NULL;    c->pp_last = &c->p_first;}static inline void BufferChainAppend( sout_buffer_chain_t *c, block_t *b ){    *c->pp_last = b;    c->i_depth++;    while( b->p_next )    {        b = b->p_next;        c->i_depth++;    }    c->pp_last = &b->p_next;}static inline block_t *BufferChainGet( sout_buffer_chain_t *c ){    block_t *b = c->p_first;    if( b )    {        c->i_depth--;        c->p_first = b->p_next;        if( c->p_first == NULL )        {            c->pp_last = &c->p_first;        }        b->p_next = NULL;    }    return b;}static inline block_t *BufferChainPeek( sout_buffer_chain_t *c ){    block_t *b = c->p_first;    return b;}static inline void BufferChainClean( sout_instance_t *p_sout,                                     sout_buffer_chain_t *c ){    block_t *b;    while( ( b = BufferChainGet( c ) ) )    {        block_Release( b );    }    BufferChainInit( c );}typedef struct ts_stream_t{    int             i_pid;    vlc_fourcc_t    i_codec;    int             i_stream_type;    int             i_stream_id;    int             i_continuity_counter;    /* to be used for carriege of DIV3 */    vlc_fourcc_t    i_bih_codec;    int             i_bih_width, i_bih_height;    /* Specific to mpeg4 in mpeg2ts */    int             i_es_id;    int             i_decoder_specific_info;    uint8_t         *p_decoder_specific_info;    /* language is iso639-2T */    uint8_t         lang[3];    sout_buffer_chain_t chain_pes;    mtime_t             i_pes_dts;    mtime_t             i_pes_length;    int                 i_pes_used;    vlc_bool_t          b_key_frame;} ts_stream_t;struct sout_mux_sys_t{    int             i_pcr_pid;    sout_input_t    *p_pcr_input;    int             i_audio_bound;    int             i_video_bound;    vlc_bool_t      b_es_id_pid;    int             i_pid_video;    int             i_pid_audio;    int             i_pid_spu;    int             i_pid_free; // first usable pid    int             i_tsid;    int             i_pat_version_number;    ts_stream_t     pat;    int             i_pmt_version_number;    ts_stream_t     pmt;        // Up to now only one program    int             i_pmt_program_number;    int             i_mpeg4_streams;    int             i_null_continuity_counter;  /* Needed ? */    /* for TS building */    int64_t             i_bitrate_min;    int64_t             i_bitrate_max;    int64_t             i_shaping_delay;    int64_t             i_pcr_delay;    int64_t             i_dts_delay;    vlc_bool_t          b_use_key_frames;    mtime_t             i_pcr;  /* last PCR emited */    csa_t               *csa;    vlc_bool_t          b_crypt_audio;};/* Reserve a pid and return it */static int  AllocatePID( sout_mux_sys_t *p_sys, int i_cat ){    int i_pid;    if ( i_cat == VIDEO_ES && p_sys->i_pid_video )    {        i_pid = p_sys->i_pid_video;        p_sys->i_pid_video = 0;    }    else if ( i_cat == AUDIO_ES && p_sys->i_pid_audio )    {        i_pid = p_sys->i_pid_audio;        p_sys->i_pid_audio = 0;    }    else if ( i_cat == SPU_ES && p_sys->i_pid_spu )    {        i_pid = p_sys->i_pid_spu;        p_sys->i_pid_spu = 0;    }    else    {        i_pid = ++p_sys->i_pid_free;    }    return i_pid;}/***************************************************************************** * Local prototypes *****************************************************************************/static int Control  ( sout_mux_t *, int, va_list );static int AddStream( sout_mux_t *, sout_input_t * );static int DelStream( sout_mux_t *, sout_input_t * );static int Mux      ( sout_mux_t * );static block_t *FixPES( sout_mux_t *p_mux, block_fifo_t *p_fifo );static void TSSchedule  ( sout_mux_t *p_mux, sout_buffer_chain_t *p_chain_ts,                          mtime_t i_pcr_length, mtime_t i_pcr_dts );static void TSDate      ( sout_mux_t *p_mux, sout_buffer_chain_t *p_chain_ts,                          mtime_t i_pcr_length, mtime_t i_pcr_dts );static void GetPAT( sout_mux_t *p_mux, sout_buffer_chain_t *c );static void GetPMT( sout_mux_t *p_mux, sout_buffer_chain_t *c );static block_t *TSNew( sout_mux_t *p_mux, ts_stream_t *p_stream, vlc_bool_t b_pcr );static void TSSetPCR( block_t *p_ts, mtime_t i_dts );static void PEStoTS  ( sout_instance_t *, sout_buffer_chain_t *, block_t *, ts_stream_t * );/***************************************************************************** * Open: *****************************************************************************/static int Open( vlc_object_t *p_this ){    sout_mux_t          *p_mux =(sout_mux_t*)p_this;    sout_mux_sys_t      *p_sys;    vlc_value_t         val;    msg_Dbg( p_mux, "Open" );    sout_CfgParse( p_mux, SOUT_CFG_PREFIX, ppsz_sout_options, p_mux->p_cfg );    p_sys = malloc( sizeof( sout_mux_sys_t ) );    p_mux->pf_control   = Control;    p_mux->pf_addstream = AddStream;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -