1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2001, 2002 VideoLAN
5 * $Id: copy.c,v 1.20 2003/11/22 20:17:14 fenrir Exp $
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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
28 #include <stdlib.h> /* malloc(), free() */
31 #include <vlc/decoder.h>
32 #include <vlc/input.h>
34 /*****************************************************************************
36 *****************************************************************************/
37 static int Open ( vlc_object_t * );
38 static void Close( vlc_object_t * );
41 set_description( _("Copy packetizer") );
42 set_capability( "packetizer", 1 );
43 set_callbacks( Open, Close );
46 /*****************************************************************************
48 *****************************************************************************/
54 static block_t *Packetize ( decoder_t *, block_t ** );
56 /*****************************************************************************
57 * Open: probe the packetizer and return score
58 *****************************************************************************
59 * Tries to launch a decoder and return score so that the interface is able
61 *****************************************************************************/
62 static int Open( vlc_object_t *p_this )
64 decoder_t *p_dec = (decoder_t*)p_this;
67 if( p_dec->fmt_in.i_cat != AUDIO_ES &&
68 p_dec->fmt_in.i_cat != VIDEO_ES &&
69 p_dec->fmt_in.i_cat != SPU_ES )
71 msg_Err( p_dec, "invalid ES type" );
75 p_dec->pf_packetize = Packetize;
77 /* Create the output format */
78 memcpy( &p_dec->fmt_out, &p_dec->fmt_in, sizeof( es_format_t ) );
79 if( p_dec->fmt_in.i_extra > 0 )
81 p_dec->fmt_out.p_extra = malloc( p_dec->fmt_in.i_extra );
82 memcpy( p_dec->fmt_out.p_extra, p_dec->fmt_in.p_extra,
83 p_dec->fmt_in.i_extra );
86 /* Fix the value of the fourcc */
87 switch( p_dec->fmt_in.i_codec )
90 case VLC_FOURCC( 'm', '4', 's', '2'):
91 case VLC_FOURCC( 'M', '4', 'S', '2'):
92 case VLC_FOURCC( 'm', 'p', '4', 's'):
93 case VLC_FOURCC( 'M', 'P', '4', 'S'):
94 case VLC_FOURCC( 'D', 'I', 'V', 'X'):
95 case VLC_FOURCC( 'd', 'i', 'v', 'x'):
96 case VLC_FOURCC( 'X', 'V', 'I', 'D'):
97 case VLC_FOURCC( 'X', 'v', 'i', 'D'):
98 case VLC_FOURCC( 'x', 'v', 'i', 'd'):
99 case VLC_FOURCC( 'D', 'X', '5', '0'):
100 case VLC_FOURCC( 0x04, 0, 0, 0):
101 case VLC_FOURCC( '3', 'I', 'V', '2'):
102 p_dec->fmt_out.i_codec = VLC_FOURCC( 'm', 'p', '4', 'v');
105 case VLC_FOURCC( 'm', 'p', 'g', '1' ):
106 case VLC_FOURCC( 'm', 'p', 'g', '2' ):
107 case VLC_FOURCC( 'm', 'p', '1', 'v' ):
108 case VLC_FOURCC( 'm', 'p', '2', 'v' ):
109 p_dec->fmt_out.i_codec = VLC_FOURCC( 'm', 'p', 'g', 'v' );
112 case VLC_FOURCC( 'd', 'i', 'v', '1' ):
113 case VLC_FOURCC( 'M', 'P', 'G', '4' ):
114 case VLC_FOURCC( 'm', 'p', 'g', '4' ):
115 p_dec->fmt_out.i_codec = VLC_FOURCC( 'D', 'I', 'V', '1' );
118 case VLC_FOURCC( 'd', 'i', 'v', '2' ):
119 case VLC_FOURCC( 'M', 'P', '4', '2' ):
120 case VLC_FOURCC( 'm', 'p', '4', '2' ):
121 p_dec->fmt_out.i_codec = VLC_FOURCC( 'D', 'I', 'V', '2' );
124 case VLC_FOURCC( 'd', 'i', 'v', '3' ):
125 case VLC_FOURCC( 'd', 'i', 'v', '4' ):
126 case VLC_FOURCC( 'D', 'I', 'V', '4' ):
127 case VLC_FOURCC( 'd', 'i', 'v', '5' ):
128 case VLC_FOURCC( 'D', 'I', 'V', '5' ):
129 case VLC_FOURCC( 'd', 'i', 'v', '6' ):
130 case VLC_FOURCC( 'D', 'I', 'V', '6' ):
131 case VLC_FOURCC( 'M', 'P', '4', '3' ):
132 case VLC_FOURCC( 'm', 'p', '4', '3' ):
133 case VLC_FOURCC( 'm', 'p', 'g', '3' ):
134 case VLC_FOURCC( 'M', 'P', 'G', '3' ):
135 case VLC_FOURCC( 'A', 'P', '4', '1' ):
136 p_dec->fmt_out.i_codec = VLC_FOURCC( 'D', 'I', 'V', '3' );
139 case VLC_FOURCC( 'h', '2', '6', '3' ):
140 case VLC_FOURCC( 'U', '2', '6', '3' ):
141 case VLC_FOURCC( 'u', '2', '6', '3' ):
142 p_dec->fmt_out.i_codec = VLC_FOURCC( 'H', '2', '6', '3' );
145 case VLC_FOURCC( 'i', '2', '6', '3' ):
146 p_dec->fmt_out.i_codec = VLC_FOURCC( 'I', '2', '6', '3' );
149 case VLC_FOURCC( 'm', 'j', 'p', 'g' ):
150 case VLC_FOURCC( 'm', 'j', 'p', 'a' ):
151 case VLC_FOURCC( 'j', 'p', 'e', 'g' ):
152 case VLC_FOURCC( 'J', 'P', 'E', 'G' ):
153 case VLC_FOURCC( 'J', 'F', 'I', 'F' ):
154 p_dec->fmt_out.i_codec = VLC_FOURCC( 'M', 'J', 'P', 'G' );
157 case VLC_FOURCC( 'd', 'v', 's', 'd' ):
158 case VLC_FOURCC( 'D', 'V', 'S', 'D' ):
159 case VLC_FOURCC( 'd', 'v', 'h', 'd' ):
160 p_dec->fmt_out.i_codec = VLC_FOURCC( 'd', 'v', 's', 'l' );
164 case VLC_FOURCC( 'a', 'r', 'a', 'w' ):
165 switch( ( p_dec->fmt_in.audio.i_bitspersample + 7 ) / 8 )
168 p_dec->fmt_out.i_codec = VLC_FOURCC('u','8',' ',' ');
171 p_dec->fmt_out.i_codec = VLC_FOURCC('s','1','6','l');
174 p_dec->fmt_out.i_codec = VLC_FOURCC('s','2','4','l');
177 p_dec->fmt_out.i_codec = VLC_FOURCC('s','3','2','l');
180 msg_Err( p_dec, "unknown raw audio sample size !!" );
185 case VLC_FOURCC( 't', 'w', 'o', 's' ):
186 switch( ( p_dec->fmt_in.audio.i_bitspersample + 7 ) / 8 )
189 p_dec->fmt_out.i_codec = VLC_FOURCC('s','8',' ',' ');
192 p_dec->fmt_out.i_codec = VLC_FOURCC('s','1','6','b');
195 p_dec->fmt_out.i_codec = VLC_FOURCC('s','2','4','b');
198 p_dec->fmt_out.i_codec = VLC_FOURCC('s','3','2','b');
201 msg_Err( p_dec, "unknown raw audio sample size !!" );
206 case VLC_FOURCC( 's', 'o', 'w', 't' ):
207 switch( ( p_dec->fmt_in.audio.i_bitspersample + 7 ) / 8 )
210 p_dec->fmt_out.i_codec = VLC_FOURCC('s','8',' ',' ');
213 p_dec->fmt_out.i_codec = VLC_FOURCC('s','1','6','l');
216 p_dec->fmt_out.i_codec = VLC_FOURCC('s','2','4','l');
219 p_dec->fmt_out.i_codec = VLC_FOURCC('s','3','2','l');
222 msg_Err( p_dec, "unknown raw audio sample size !!" );
228 p_dec->p_sys = p_sys = malloc( sizeof( block_t ) );
229 p_sys->p_block = NULL;
234 /*****************************************************************************
236 *****************************************************************************/
237 static void Close( vlc_object_t *p_this )
239 decoder_t *p_dec = (decoder_t*)p_this;
241 if( p_dec->p_sys->p_block )
243 block_ChainRelease( p_dec->p_sys->p_block );
246 free( p_dec->p_sys );
249 /*****************************************************************************
250 * PacketizeStd: packetize an unit (here copy a complete block )
251 *****************************************************************************/
252 static block_t *Packetize ( decoder_t *p_dec, block_t **pp_block )
255 block_t *p_ret = p_dec->p_sys->p_block;
257 if( pp_block == NULL || *pp_block == NULL )
264 if( p_block->i_pts <= 0 )
266 msg_Dbg( p_dec, "need pts > 0" );
267 block_Release( p_block );
271 if( p_ret != NULL && p_block->i_pts > p_ret->i_pts )
273 p_ret->i_length = p_block->i_pts - p_ret->i_pts;
275 p_dec->p_sys->p_block = p_block;