X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fmux%2Fmpeg%2Fpes.c;h=ed199c2be1ccd75acf3afc57fc4a757e04d889c0;hb=99fab9089e9e1709d9c3a4bc5ced0c137ac59134;hp=b342fedb39317dd0914bc462665d87761d9be0f7;hpb=ea92845937166d277eea8dfaf4555cfea48c7a55;p=vlc diff --git a/modules/mux/mpeg/pes.c b/modules/mux/mpeg/pes.c index b342fedb39..ed199c2be1 100644 --- a/modules/mux/mpeg/pes.c +++ b/modules/mux/mpeg/pes.c @@ -1,7 +1,7 @@ /***************************************************************************** * pes.c: PES packetizer used by the MPEG multiplexers ***************************************************************************** - * Copyright (C) 2001, 2002 VideoLAN + * Copyright (C) 2001, 2002 the VideoLAN team * $Id$ * * Authors: Laurent Aimar @@ -19,33 +19,33 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ /***************************************************************************** * Preamble *****************************************************************************/ -#include #include #include -#include #include #include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include -#include -#include +#include +#include #ifdef HAVE_UNISTD_H # include #endif -#include "codecs.h" +#include #include "pes.h" #include "bits.h" -#define PES_PAYLOAD_SIZE_MAX 65500 - static inline int PESHeader( uint8_t *p_hdr, mtime_t i_pts, mtime_t i_dts, int i_es_size, es_format_t *p_fmt, int i_stream_id, int i_private_id, @@ -67,7 +67,6 @@ static inline int PESHeader( uint8_t *p_hdr, mtime_t i_pts, mtime_t i_dts, } } - bits_initwrite( &bits, 50, p_hdr ); /* add start code */ @@ -95,7 +94,8 @@ static inline int PESHeader( uint8_t *p_hdr, mtime_t i_pts, mtime_t i_dts, int i_pts_dts; if( i_pts > 0 && i_dts > 0 && - ( i_pts != i_dts || p_fmt->i_cat == VIDEO_ES ) ) + ( i_pts != i_dts || ( p_fmt->i_cat == VIDEO_ES && + p_fmt->i_codec != VLC_FOURCC('m','p','g','v') ) ) ) { i_pts_dts = 0x03; if ( !i_header_size ) i_header_size = 0xa; @@ -126,7 +126,7 @@ static inline int PESHeader( uint8_t *p_hdr, mtime_t i_pts, mtime_t i_dts, bits_write( &bits, 1, 0x00 ); // dsm trick mode flag bits_write( &bits, 1, 0x00 ); // additional copy info flag bits_write( &bits, 1, 0x00 ); // pes crc flag - bits_write( &bits, 1, 0x00 ); // pes extention flags + bits_write( &bits, 1, 0x00 ); // pes extension flags bits_write( &bits, 8, i_header_size ); // header size -> pts and dts /* write pts */ @@ -232,7 +232,8 @@ static inline int PESHeader( uint8_t *p_hdr, mtime_t i_pts, mtime_t i_dts, int E_( EStoPES )( sout_instance_t *p_sout, block_t **pp_pes, block_t *p_es, es_format_t *p_fmt, int i_stream_id, - int b_mpeg2, int b_data_alignment, int i_header_size ) + int b_mpeg2, int b_data_alignment, int i_header_size, + int i_max_pes_size ) { block_t *p_pes; mtime_t i_pts, i_dts, i_length; @@ -255,6 +256,15 @@ int E_( EStoPES )( sout_instance_t *p_sout, block_t **pp_pes, block_t *p_es, i_stream_id = PES_PRIVATE_STREAM_1; } + if( p_fmt->i_codec == VLC_FOURCC( 'm', 'p','4', 'v' ) && + p_es->i_flags & BLOCK_FLAG_TYPE_I ) + { + /* For MPEG4 video, add VOL before I-frames */ + p_es = block_Realloc( p_es, p_fmt->i_extra, p_es->i_buffer ); + + memcpy( p_es->p_buffer, p_fmt->p_extra, p_fmt->i_extra ); + } + i_pts = p_es->i_pts <= 0 ? 0 : p_es->i_pts * 9 / 100; // 90000 units clock i_dts = p_es->i_dts <= 0 ? 0 : p_es->i_dts * 9 / 100; // 90000 units clock @@ -263,9 +273,14 @@ int E_( EStoPES )( sout_instance_t *p_sout, block_t **pp_pes, block_t *p_es, *pp_pes = p_pes = NULL; +#ifdef DEBUG + memset( header, 0, 50 ); +#endif + do { - i_pes_payload = __MIN( i_size, PES_PAYLOAD_SIZE_MAX ); + i_pes_payload = __MIN( i_size, (i_max_pes_size ? + i_max_pes_size : PES_PAYLOAD_SIZE_MAX) ); i_pes_header = PESHeader( header, i_pts, i_dts, i_pes_payload, p_fmt, i_stream_id, i_private_id, b_mpeg2, b_data_alignment, i_header_size ); @@ -275,6 +290,7 @@ int E_( EStoPES )( sout_instance_t *p_sout, block_t **pp_pes, block_t *p_es, if( p_es ) { p_es = block_Realloc( p_es, i_pes_header, p_es->i_buffer ); + p_data = p_es->p_buffer+i_pes_header; /* reuse p_es for first frame */ *pp_pes = p_pes = p_es; /* don't touch i_dts, i_pts, i_length as are already set :) */ @@ -290,7 +306,7 @@ int E_( EStoPES )( sout_instance_t *p_sout, block_t **pp_pes, block_t *p_es, p_pes->i_length = 0; if( i_pes_payload > 0 ) { - p_sout->p_vlc->pf_memcpy( p_pes->p_buffer + i_pes_header, + p_sout->p_libvlc->pf_memcpy( p_pes->p_buffer + i_pes_header, p_data, i_pes_payload ); } i_pes_count++;