00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <stdlib.h>
00029
00030 #include <vlc/vlc.h>
00031 #include <vlc/decoder.h>
00032 #include <vlc/input.h>
00033
00034
00035
00036
00037 static int Open ( vlc_object_t * );
00038 static void Close( vlc_object_t * );
00039
00040 vlc_module_begin();
00041 set_category( CAT_SOUT );
00042 set_subcategory( SUBCAT_SOUT_PACKETIZER );
00043 set_description( _("Copy packetizer") );
00044 set_capability( "packetizer", 1 );
00045 set_callbacks( Open, Close );
00046 vlc_module_end();
00047
00048
00049
00050
00051 struct decoder_sys_t
00052 {
00053 block_t *p_block;
00054 };
00055
00056 static block_t *Packetize ( decoder_t *, block_t ** );
00057 static block_t *PacketizeSub( decoder_t *, block_t ** );
00058
00059
00060
00061
00062
00063
00064
00065 static int Open( vlc_object_t *p_this )
00066 {
00067 decoder_t *p_dec = (decoder_t*)p_this;
00068 decoder_sys_t *p_sys;
00069
00070 if( p_dec->fmt_in.i_cat != AUDIO_ES &&
00071 p_dec->fmt_in.i_cat != VIDEO_ES &&
00072 p_dec->fmt_in.i_cat != SPU_ES )
00073 {
00074 msg_Err( p_dec, "invalid ES type" );
00075 return VLC_EGENERIC;
00076 }
00077
00078 if( p_dec->fmt_in.i_cat == SPU_ES )
00079 p_dec->pf_packetize = PacketizeSub;
00080 else
00081 p_dec->pf_packetize = Packetize;
00082
00083
00084 es_format_Copy( &p_dec->fmt_out, &p_dec->fmt_in );
00085
00086
00087 switch( p_dec->fmt_in.i_codec )
00088 {
00089
00090 case VLC_FOURCC( 'm', '4', 's', '2'):
00091 case VLC_FOURCC( 'M', '4', 'S', '2'):
00092 case VLC_FOURCC( 'm', 'p', '4', 's'):
00093 case VLC_FOURCC( 'M', 'P', '4', 'S'):
00094 case VLC_FOURCC( 'D', 'I', 'V', 'X'):
00095 case VLC_FOURCC( 'd', 'i', 'v', 'x'):
00096 case VLC_FOURCC( 'X', 'V', 'I', 'D'):
00097 case VLC_FOURCC( 'X', 'v', 'i', 'D'):
00098 case VLC_FOURCC( 'x', 'v', 'i', 'd'):
00099 case VLC_FOURCC( 'D', 'X', '5', '0'):
00100 case VLC_FOURCC( 0x04, 0, 0, 0):
00101 case VLC_FOURCC( '3', 'I', 'V', '2'):
00102 p_dec->fmt_out.i_codec = VLC_FOURCC( 'm', 'p', '4', 'v');
00103 break;
00104
00105 case VLC_FOURCC( 'm', 'p', 'g', '1' ):
00106 case VLC_FOURCC( 'm', 'p', 'g', '2' ):
00107 case VLC_FOURCC( 'm', 'p', '1', 'v' ):
00108 case VLC_FOURCC( 'm', 'p', '2', 'v' ):
00109 p_dec->fmt_out.i_codec = VLC_FOURCC( 'm', 'p', 'g', 'v' );
00110 break;
00111
00112 case VLC_FOURCC( 'd', 'i', 'v', '1' ):
00113 case VLC_FOURCC( 'M', 'P', 'G', '4' ):
00114 case VLC_FOURCC( 'm', 'p', 'g', '4' ):
00115 p_dec->fmt_out.i_codec = VLC_FOURCC( 'D', 'I', 'V', '1' );
00116 break;
00117
00118 case VLC_FOURCC( 'd', 'i', 'v', '2' ):
00119 case VLC_FOURCC( 'M', 'P', '4', '2' ):
00120 case VLC_FOURCC( 'm', 'p', '4', '2' ):
00121 p_dec->fmt_out.i_codec = VLC_FOURCC( 'D', 'I', 'V', '2' );
00122 break;
00123
00124 case VLC_FOURCC( 'd', 'i', 'v', '3' ):
00125 case VLC_FOURCC( 'd', 'i', 'v', '4' ):
00126 case VLC_FOURCC( 'D', 'I', 'V', '4' ):
00127 case VLC_FOURCC( 'd', 'i', 'v', '5' ):
00128 case VLC_FOURCC( 'D', 'I', 'V', '5' ):
00129 case VLC_FOURCC( 'd', 'i', 'v', '6' ):
00130 case VLC_FOURCC( 'D', 'I', 'V', '6' ):
00131 case VLC_FOURCC( 'M', 'P', '4', '3' ):
00132 case VLC_FOURCC( 'm', 'p', '4', '3' ):
00133 case VLC_FOURCC( 'm', 'p', 'g', '3' ):
00134 case VLC_FOURCC( 'M', 'P', 'G', '3' ):
00135 case VLC_FOURCC( 'A', 'P', '4', '1' ):
00136 p_dec->fmt_out.i_codec = VLC_FOURCC( 'D', 'I', 'V', '3' );
00137 break;
00138
00139 case VLC_FOURCC( 'h', '2', '6', '3' ):
00140 case VLC_FOURCC( 'U', '2', '6', '3' ):
00141 case VLC_FOURCC( 'u', '2', '6', '3' ):
00142 p_dec->fmt_out.i_codec = VLC_FOURCC( 'H', '2', '6', '3' );
00143 break;
00144
00145 case VLC_FOURCC( 'i', '2', '6', '3' ):
00146 p_dec->fmt_out.i_codec = VLC_FOURCC( 'I', '2', '6', '3' );
00147 break;
00148
00149 case VLC_FOURCC( 'm', 'j', 'p', 'g' ):
00150 case VLC_FOURCC( 'm', 'j', 'p', 'a' ):
00151 case VLC_FOURCC( 'j', 'p', 'e', 'g' ):
00152 case VLC_FOURCC( 'J', 'P', 'E', 'G' ):
00153 case VLC_FOURCC( 'J', 'F', 'I', 'F' ):
00154 p_dec->fmt_out.i_codec = VLC_FOURCC( 'M', 'J', 'P', 'G' );
00155 break;
00156
00157 case VLC_FOURCC( 'd', 'v', 's', 'd' ):
00158 case VLC_FOURCC( 'D', 'V', 'S', 'D' ):
00159 case VLC_FOURCC( 'd', 'v', 'h', 'd' ):
00160 p_dec->fmt_out.i_codec = VLC_FOURCC( 'd', 'v', 's', 'l' );
00161 break;
00162
00163
00164 case VLC_FOURCC( 'a', 'r', 'a', 'w' ):
00165 switch( ( p_dec->fmt_in.audio.i_bitspersample + 7 ) / 8 )
00166 {
00167 case 1:
00168 p_dec->fmt_out.i_codec = VLC_FOURCC('u','8',' ',' ');
00169 break;
00170 case 2:
00171 p_dec->fmt_out.i_codec = VLC_FOURCC('s','1','6','l');
00172 break;
00173 case 3:
00174 p_dec->fmt_out.i_codec = VLC_FOURCC('s','2','4','l');
00175 break;
00176 case 4:
00177 p_dec->fmt_out.i_codec = VLC_FOURCC('s','3','2','l');
00178 break;
00179 default:
00180 msg_Err( p_dec, "unknown raw audio sample size" );
00181 return VLC_EGENERIC;
00182 }
00183 break;
00184
00185 case VLC_FOURCC( 't', 'w', 'o', 's' ):
00186 switch( ( p_dec->fmt_in.audio.i_bitspersample + 7 ) / 8 )
00187 {
00188 case 1:
00189 p_dec->fmt_out.i_codec = VLC_FOURCC('s','8',' ',' ');
00190 break;
00191 case 2:
00192 p_dec->fmt_out.i_codec = VLC_FOURCC('s','1','6','b');
00193 break;
00194 case 3:
00195 p_dec->fmt_out.i_codec = VLC_FOURCC('s','2','4','b');
00196 break;
00197 case 4:
00198 p_dec->fmt_out.i_codec = VLC_FOURCC('s','3','2','b');
00199 break;
00200 default:
00201 msg_Err( p_dec, "unknown raw audio sample size" );
00202 return VLC_EGENERIC;
00203 }
00204 break;
00205
00206 case VLC_FOURCC( 's', 'o', 'w', 't' ):
00207 switch( ( p_dec->fmt_in.audio.i_bitspersample + 7 ) / 8 )
00208 {
00209 case 1:
00210 p_dec->fmt_out.i_codec = VLC_FOURCC('s','8',' ',' ');
00211 break;
00212 case 2:
00213 p_dec->fmt_out.i_codec = VLC_FOURCC('s','1','6','l');
00214 break;
00215 case 3:
00216 p_dec->fmt_out.i_codec = VLC_FOURCC('s','2','4','l');
00217 break;
00218 case 4:
00219 p_dec->fmt_out.i_codec = VLC_FOURCC('s','3','2','l');
00220 break;
00221 default:
00222 msg_Err( p_dec, "unknown raw audio sample size" );
00223 return VLC_EGENERIC;
00224 }
00225 break;
00226 }
00227
00228 p_dec->p_sys = p_sys = malloc( sizeof( block_t ) );
00229 p_sys->p_block = NULL;
00230
00231 return VLC_SUCCESS;
00232 }
00233
00234
00235
00236
00237 static void Close( vlc_object_t *p_this )
00238 {
00239 decoder_t *p_dec = (decoder_t*)p_this;
00240
00241 if( p_dec->p_sys->p_block )
00242 {
00243 block_ChainRelease( p_dec->p_sys->p_block );
00244 }
00245
00246 free( p_dec->p_sys );
00247 }
00248
00249
00250
00251
00252 static block_t *Packetize ( decoder_t *p_dec, block_t **pp_block )
00253 {
00254 block_t *p_block;
00255 block_t *p_ret = p_dec->p_sys->p_block;
00256
00257 if( pp_block == NULL || *pp_block == NULL )
00258 {
00259 return NULL;
00260 }
00261 p_block = *pp_block;
00262 *pp_block = NULL;
00263
00264 if( p_block->i_dts <= 0 )
00265 {
00266 p_block->i_dts = p_block->i_pts;
00267 }
00268
00269 if( p_block->i_dts <= 0 )
00270 {
00271 msg_Dbg( p_dec, "need dts > 0" );
00272 block_Release( p_block );
00273 return NULL;
00274 }
00275
00276 if( p_ret != NULL && p_block->i_pts > p_ret->i_pts )
00277 {
00278 p_ret->i_length = p_block->i_pts - p_ret->i_pts;
00279 }
00280 p_dec->p_sys->p_block = p_block;
00281
00282 return p_ret;
00283 }
00284
00285
00286
00287
00288 static block_t *PacketizeSub( decoder_t *p_dec, block_t **pp_block )
00289 {
00290 block_t *p_block;
00291
00292 if( pp_block == NULL || *pp_block == NULL )
00293 {
00294 return NULL;
00295 }
00296 p_block = *pp_block;
00297 *pp_block = NULL;
00298
00299 if( p_block->i_dts <= 0 )
00300 {
00301 p_block->i_dts = p_block->i_pts;
00302 }
00303
00304 if( p_block->i_dts <= 0 )
00305 {
00306 msg_Dbg( p_dec, "need dts > 0" );
00307 block_Release( p_block );
00308 return NULL;
00309 }
00310
00311 return p_block;
00312 }