1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2001, 2002, 2006 the VideoLAN team
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8 * Eric Petit <titer@videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
33 #include <vlc_common.h>
34 #include <vlc_plugin.h>
35 #include <vlc_codec.h>
36 #include <vlc_block.h>
38 /*****************************************************************************
40 *****************************************************************************/
41 static int Open ( vlc_object_t * );
42 static void Close( vlc_object_t * );
45 set_category( CAT_SOUT )
46 set_subcategory( SUBCAT_SOUT_PACKETIZER )
47 set_description( N_("Copy packetizer") )
48 set_capability( "packetizer", 1 )
49 set_callbacks( Open, Close )
52 /*****************************************************************************
54 *****************************************************************************/
60 static block_t *Packetize ( decoder_t *, block_t ** );
61 static block_t *PacketizeSub( decoder_t *, block_t ** );
63 /*****************************************************************************
64 * Open: probe the packetizer and return score
65 *****************************************************************************
66 * Tries to launch a decoder and return score so that the interface is able
68 *****************************************************************************/
69 static int Open( vlc_object_t *p_this )
71 decoder_t *p_dec = (decoder_t*)p_this;
74 if( p_dec->fmt_in.i_cat != AUDIO_ES &&
75 p_dec->fmt_in.i_cat != VIDEO_ES &&
76 p_dec->fmt_in.i_cat != SPU_ES )
78 msg_Err( p_dec, "invalid ES type" );
82 if( p_dec->fmt_in.i_cat == SPU_ES )
83 p_dec->pf_packetize = PacketizeSub;
85 p_dec->pf_packetize = Packetize;
87 /* Create the output format */
88 es_format_Copy( &p_dec->fmt_out, &p_dec->fmt_in );
90 /* Fix the value of the fourcc */
91 switch( p_dec->fmt_in.i_codec )
93 case VLC_FOURCC( 'a', 'r', 'a', 'w' ):
94 switch( ( p_dec->fmt_in.audio.i_bitspersample + 7 ) / 8 )
97 p_dec->fmt_out.i_codec = VLC_CODEC_U8;
100 p_dec->fmt_out.i_codec = VLC_CODEC_S16L;
103 p_dec->fmt_out.i_codec = VLC_CODEC_S24L;
106 p_dec->fmt_out.i_codec = VLC_CODEC_S32L;
109 msg_Err( p_dec, "unknown raw audio sample size" );
114 case VLC_FOURCC( 't', 'w', 'o', 's' ):
115 switch( ( p_dec->fmt_in.audio.i_bitspersample + 7 ) / 8 )
118 p_dec->fmt_out.i_codec = VLC_CODEC_S8;
121 p_dec->fmt_out.i_codec = VLC_CODEC_S16B;
124 p_dec->fmt_out.i_codec = VLC_CODEC_S24B;
127 p_dec->fmt_out.i_codec = VLC_CODEC_S32B;
130 msg_Err( p_dec, "unknown raw audio sample size" );
135 case VLC_FOURCC( 's', 'o', 'w', 't' ):
136 switch( ( p_dec->fmt_in.audio.i_bitspersample + 7 ) / 8 )
139 p_dec->fmt_out.i_codec = VLC_CODEC_S8;
142 p_dec->fmt_out.i_codec = VLC_CODEC_S16L;
145 p_dec->fmt_out.i_codec = VLC_CODEC_S24L;
148 p_dec->fmt_out.i_codec = VLC_CODEC_S32L;
151 msg_Err( p_dec, "unknown raw audio sample size" );
157 p_dec->p_sys = p_sys = malloc( sizeof(*p_sys) );
158 p_sys->p_block = NULL;
163 /*****************************************************************************
165 *****************************************************************************/
166 static void Close( vlc_object_t *p_this )
168 decoder_t *p_dec = (decoder_t*)p_this;
170 if( p_dec->p_sys->p_block )
172 block_ChainRelease( p_dec->p_sys->p_block );
175 es_format_Clean( &p_dec->fmt_out );
176 free( p_dec->p_sys );
179 /*****************************************************************************
180 * Packetize: packetize an unit (here copy a complete block )
181 *****************************************************************************/
182 static block_t *Packetize ( decoder_t *p_dec, block_t **pp_block )
185 block_t *p_ret = p_dec->p_sys->p_block;
187 if( pp_block == NULL || *pp_block == NULL )
189 if( (*pp_block)->i_flags&(BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) )
191 block_Release( *pp_block );
198 if( p_block->i_dts <= 0 )
200 p_block->i_dts = p_block->i_pts;
203 if( p_block->i_dts <= 0 )
205 msg_Dbg( p_dec, "need dts > 0" );
206 block_Release( p_block );
210 if( p_ret != NULL && p_block->i_pts > p_ret->i_pts )
212 p_ret->i_length = p_block->i_pts - p_ret->i_pts;
214 p_dec->p_sys->p_block = p_block;
219 /*****************************************************************************
220 * PacketizeSub: packetize an unit (here copy a complete block )
221 *****************************************************************************/
222 static block_t *PacketizeSub( decoder_t *p_dec, block_t **pp_block )
226 if( pp_block == NULL || *pp_block == NULL )
228 if( (*pp_block)->i_flags&(BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) )
230 block_Release( *pp_block );
237 if( p_block->i_dts <= 0 )
239 p_block->i_dts = p_block->i_pts;
242 if( p_block->i_dts <= 0 )
244 msg_Dbg( p_dec, "need dts > 0" );
245 block_Release( p_block );