Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

copy.c

00001 /*****************************************************************************
00002  * copy.c
00003  *****************************************************************************
00004  * Copyright (C) 2001, 2002 the VideoLAN team
00005  * $Id: copy.c 11664 2005-07-09 06:17:09Z courmisch $
00006  *
00007  * Authors: Laurent Aimar <[email protected]>
00008  *          Eric Petit <[email protected]>
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00023  *****************************************************************************/
00024 
00025 /*****************************************************************************
00026  * Preamble
00027  *****************************************************************************/
00028 #include <stdlib.h>                                      /* malloc(), free() */
00029 
00030 #include <vlc/vlc.h>
00031 #include <vlc/decoder.h>
00032 #include <vlc/input.h>
00033 
00034 /*****************************************************************************
00035  * Module descriptor
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  * Local prototypes
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  * Open: probe the packetizer and return score
00061  *****************************************************************************
00062  * Tries to launch a decoder and return score so that the interface is able
00063  * to choose.
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     /* Create the output format */
00084     es_format_Copy( &p_dec->fmt_out, &p_dec->fmt_in );
00085 
00086     /* Fix the value of the fourcc */
00087     switch( p_dec->fmt_in.i_codec )
00088     {
00089         /* video */
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         /* audio */
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  * Close:
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  * Packetize: packetize an unit (here copy a complete block )
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  * PacketizeSub: packetize an unit (here copy a complete block )
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 }

Generated on Tue Dec 20 10:14:49 2005 for vlc-0.8.4a by  doxygen 1.4.2