1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2001, 2002 VideoLAN
5 * $Id: pes.c,v 1.1 2002/12/14 21:32:41 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 *****************************************************************************/
29 #include <sys/types.h>
36 #include <vlc/input.h>
41 #elif defined( _MSC_VER ) && defined( _WIN32 ) && !defined( UNDER_CE )
49 int EStoPES( sout_instance_t *p_sout,
50 sout_buffer_t **pp_pes,
61 i_pts = p_es->i_pts * 9 / 100; // 90000 units clock
62 i_dts = p_es->i_dts * 9 / 100; // 90000 units clock
64 i_size = p_es->i_size;
65 p_data = p_es->p_buffer;
67 *pp_pes = p_pes = NULL;
73 i_copy = __MIN( i_size, 65500 );
77 *pp_pes = p_pes = sout_BufferNew( p_sout, 100 + i_copy);
78 p_pes->i_dts = p_es->i_dts;
79 p_pes->i_pts = p_es->i_pts;
80 p_pes->i_length = p_es->i_length;
84 p_pes->p_next = sout_BufferNew( p_sout, 100 + i_copy );
85 p_pes = p_pes->p_next;
95 bits_initwrite( &bits, 100, p_pes->p_buffer );
97 /* first 4 bytes common pes header */
98 /* add start code for pes 0x000001 */
99 bits_write( &bits, 24, 0x01 );
101 bits_write( &bits, 8, i_stream_id );
103 switch( i_stream_id )
105 case PES_PROGRAM_STREAM_MAP:
107 case PES_PRIVATE_STREAM_2:
110 case PES_PROGRAM_STREAM_DIRECTORY:
111 case PES_DSMCC_STREAM:
112 case PES_ITU_T_H222_1_TYPE_E_STREAM:
113 /* add pes data size */
114 bits_write( &bits, 16, i_copy );
119 /* arg, a little more difficult */
126 bits_write( &bits, 16, i_copy + 13 );
131 bits_write( &bits, 16, i_copy + 8 );
135 bits_write( &bits, 2, 0x02 ); // mpeg2 id
136 bits_write( &bits, 2, 0x00 ); // pes scrambling control
137 bits_write( &bits, 1, 0x00 ); // pes priority
138 bits_write( &bits, 1, 0x00 ); // data alignement indicator
139 bits_write( &bits, 1, 0x00 ); // copyright
140 bits_write( &bits, 1, 0x00 ); // original or copy
142 bits_write( &bits, 2, i_pts_dts ); // pts_dts flags
143 bits_write( &bits, 1, 0x00 ); // escr flags
144 bits_write( &bits, 1, 0x00 ); // es rate flag
145 bits_write( &bits, 1, 0x00 ); // dsm trick mode flag
146 bits_write( &bits, 1, 0x00 ); // additional copy info flag
147 bits_write( &bits, 1, 0x00 ); // pes crc flag
148 bits_write( &bits, 1, 0x00 ); // pes extention flags
149 if( i_pts_dts & 0x01 )
151 bits_write( &bits, 8, 0x0a ); // header size -> pts and dts
155 bits_write( &bits, 8, 0x05 ); // header size -> pts
159 bits_write( &bits, 4, i_pts_dts ); // '0010' or '0011'
160 bits_write( &bits, 3, i_pts >> 30 );
161 bits_write( &bits, 1, 0x01 ); // marker
162 bits_write( &bits, 15, i_pts >> 15 );
163 bits_write( &bits, 1, 0x01 ); // marker
164 bits_write( &bits, 15, i_pts );
165 bits_write( &bits, 1, 0x01 ); // marker
168 if( i_pts_dts & 0x01 )
170 bits_write( &bits, 4, 0x01 ); // '0001'
171 bits_write( &bits, 3, i_dts >> 30 );
172 bits_write( &bits, 1, 0x01 ); // marker
173 bits_write( &bits, 15, i_dts >> 15 );
174 bits_write( &bits, 1, 0x01 ); // marker
175 bits_write( &bits, 15, i_dts );
176 bits_write( &bits, 1, 0x01 ); // marker
178 i_dts = 0; // write dts only once
184 msg_Warn( p_sout, "es isn't mpeg2 -->corrupted pes" );
186 /* now should be stuffing */
187 /* and then pes data */
195 memcpy( p_pes->p_buffer + bits.i_data, p_data, i_copy );
200 p_pes->i_size = bits.i_data + i_copy;
203 } while( i_size > 0 );
205 sout_BufferDelete( p_sout, p_es );