📄 ps.c
字号:
/***************************************************************************** * ps.c: MPEG PS (ISO/IEC 13818-1) / MPEG SYSTEM (ISO/IEC 1172-1) * multiplexer module for vlc ***************************************************************************** * Copyright (C) 2001, 2002 VideoLAN * $Id: ps.c,v 1.15 2003/08/02 01:33:53 fenrir Exp $ * * Authors: Laurent Aimar <fenrir@via.ecp.fr> * Eric Petit <titer@videolan.org> * Gildas Bazin <gbazin@netcourrier.com> * * * 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 "codecs.h"#include "bits.h"#include "pes.h"/* TODO: * - test support of DTS, LPCM * *//***************************************************************************** * Module descriptor *****************************************************************************/static int Open ( vlc_object_t * );static void Close ( vlc_object_t * );vlc_module_begin(); set_description( _("PS muxer") ); set_capability( "sout mux", 50 ); add_shortcut( "ps" ); add_shortcut( "mpeg1" ); set_callbacks( Open, Close );vlc_module_end();/***************************************************************************** * Exported prototypes *****************************************************************************/static int Capability(sout_mux_t *, int, void *, void * );static int AddStream( sout_mux_t *, sout_input_t * );static int DelStream( sout_mux_t *, sout_input_t * );static int Mux ( sout_mux_t * );/***************************************************************************** * Local prototypes *****************************************************************************/static int MuxGetStream ( sout_mux_t *, int *, mtime_t * );static void MuxWritePackHeader ( sout_mux_t *, sout_buffer_t **, mtime_t );static void MuxWriteSystemHeader( sout_mux_t *, sout_buffer_t ** );static void StreamIdInit ( vlc_bool_t *id, int i_range );static int StreamIdGet ( vlc_bool_t *id, int i_id_min, int i_id_max );static void StreamIdRelease ( vlc_bool_t *id, int i_id_min, int i_id );typedef struct ps_stream_s{ int i_stream_id;} ps_stream_t;struct sout_mux_sys_t{ /* Which id are unused */ vlc_bool_t stream_id_mpga[16]; /* 0xc0 -> 0xcf */ vlc_bool_t stream_id_mpgv[16]; /* 0xe0 -> 0xef */ vlc_bool_t stream_id_a52[8]; /* 0x80 -> 0x87 <- FIXME I'm not sure */ vlc_bool_t stream_id_spu[32]; /* 0x20 -> 0x3f */ vlc_bool_t stream_id_dts[8]; /* 0x88 -> 0x8f */ vlc_bool_t stream_id_lpcm[16]; /* 0xa0 -> 0xaf */ int i_audio_bound; int i_video_bound; int i_pes_count; int i_system_header; vlc_bool_t b_mpeg2;};/***************************************************************************** * 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; msg_Info( p_mux, "Open" ); p_mux->pf_capacity = Capability; p_mux->pf_addstream = AddStream; p_mux->pf_delstream = DelStream; p_mux->pf_mux = Mux; p_mux->i_preheader = 30; // really enough for a pes header p_mux->p_sys = p_sys = malloc( sizeof( sout_mux_sys_t ) ); /* Init free stream id */ StreamIdInit( p_sys->stream_id_a52, 8 ); StreamIdInit( p_sys->stream_id_dts, 8 ); StreamIdInit( p_sys->stream_id_mpga, 16 ); StreamIdInit( p_sys->stream_id_mpgv, 16 ); StreamIdInit( p_sys->stream_id_lpcm, 16 ); StreamIdInit( p_sys->stream_id_spu, 32 ); p_sys->i_audio_bound = 0; p_sys->i_video_bound = 0; p_sys->i_system_header = 0; p_sys->i_pes_count = 0; p_sys->b_mpeg2 = !(p_mux->psz_mux && !strcmp( p_mux->psz_mux, "mpeg1" )); return VLC_SUCCESS;}/***************************************************************************** * Close: *****************************************************************************/static void Close( vlc_object_t * p_this ){ sout_mux_t *p_mux = (sout_mux_t*)p_this; sout_mux_sys_t *p_sys = p_mux->p_sys; sout_buffer_t *p_end; msg_Info( p_mux, "Close" ); p_end = sout_BufferNew( p_mux->p_sout, 4 ); p_end->p_buffer[0] = 0x00; p_end->p_buffer[1] = 0x00; p_end->p_buffer[2] = 0x01; p_end->p_buffer[3] = 0xb9; sout_AccessOutWrite( p_mux->p_access, p_end ); free( p_sys );}/***************************************************************************** * Capability: *****************************************************************************/static int Capability( sout_mux_t *p_mux, int i_query, void *p_args, void *p_answer ){ switch( i_query ) { case SOUT_MUX_CAP_GET_ADD_STREAM_ANY_TIME: *(vlc_bool_t*)p_answer = VLC_TRUE; return( SOUT_MUX_CAP_ERR_OK ); default: return( SOUT_MUX_CAP_ERR_UNIMPLEMENTED ); }}/***************************************************************************** * AddStream: *****************************************************************************/static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input ){ sout_mux_sys_t *p_sys = p_mux->p_sys; ps_stream_t *p_stream; msg_Dbg( p_mux, "adding input codec=%4.4s", (char*)&p_input->p_fmt->i_fourcc ); p_input->p_sys = (void*)p_stream = malloc( sizeof( ps_stream_t ) ); /* Init this new stream */ switch( p_input->p_fmt->i_fourcc ) { case VLC_FOURCC( 'm', 'p', 'g', 'v' ): p_stream->i_stream_id = StreamIdGet( p_sys->stream_id_mpgv, 0xe0, 0xef ); break; case VLC_FOURCC( 'l', 'p', 'c', 'm' ): p_stream->i_stream_id = 0xbd00|StreamIdGet( p_sys->stream_id_lpcm, 0xa0, 0xaf ); break; case VLC_FOURCC( 'd', 't', 's', ' ' ): p_stream->i_stream_id = 0xbd00|StreamIdGet( p_sys->stream_id_dts, 0x88, 0x8f ); break; case VLC_FOURCC( 'a', '5', '2', ' ' ): p_stream->i_stream_id = 0xbd00|StreamIdGet( p_sys->stream_id_a52, 0x80, 0x87 ); break; case VLC_FOURCC( 'm', 'p', 'g', 'a' ): p_stream->i_stream_id = StreamIdGet( p_sys->stream_id_mpga, 0xc0, 0xcf ); break; case VLC_FOURCC( 's', 'p', 'u', ' ' ): p_stream->i_stream_id = 0xbd00|StreamIdGet( p_sys->stream_id_spu, 0x20, 0x3f ); break; default: goto error; } if( p_stream->i_stream_id < 0 ) { goto error; } if( p_input->p_fmt->i_cat == AUDIO_ES ) { p_sys->i_audio_bound++; } else if( p_input->p_fmt->i_cat == VIDEO_ES ) { p_sys->i_video_bound++; } return VLC_SUCCESS;error: free( p_stream ); return VLC_EGENERIC;}/***************************************************************************** * DelStream: *****************************************************************************/static int DelStream( sout_mux_t *p_mux, sout_input_t *p_input ){ sout_mux_sys_t *p_sys = p_mux->p_sys; ps_stream_t *p_stream =(ps_stream_t*)p_input->p_sys; msg_Dbg( p_mux, "removing input" ); switch( p_input->p_fmt->i_fourcc ) { case VLC_FOURCC( 'm', 'p', 'g', 'v' ): StreamIdRelease( p_sys->stream_id_mpgv, 0xe0, p_stream->i_stream_id); break; case VLC_FOURCC( 'l', 'p', 'c', 'm' ): StreamIdRelease( p_sys->stream_id_lpcm, 0xa0, p_stream->i_stream_id&0xff ); break; case VLC_FOURCC( 'd', 't', 's', ' ' ): StreamIdRelease( p_sys->stream_id_dts, 0x88, p_stream->i_stream_id&0xff ); break; case VLC_FOURCC( 'a', '5', '2', ' ' ): StreamIdRelease( p_sys->stream_id_a52, 0x80, p_stream->i_stream_id&0xff ); break; case VLC_FOURCC( 'm', 'p', 'g', 'a' ): StreamIdRelease( p_sys->stream_id_mpga, 0xc0, p_stream->i_stream_id ); break; case VLC_FOURCC( 's', 'p', 'u', ' ' ): StreamIdRelease( p_sys->stream_id_spu, 0x20, p_stream->i_stream_id&0xff ); break; default: /* Never reached */ break; } if( p_input->p_fmt->i_cat == AUDIO_ES ) { p_sys->i_audio_bound--; } else if( p_input->p_fmt->i_cat == VIDEO_ES ) { p_sys->i_video_bound--; } free( p_stream ); return VLC_SUCCESS;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -