X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;ds=sidebyside;f=modules%2Fpacketizer%2Fcopy.c;h=dbaa96b321c033f1850019817af4db1fe7d1d7bf;hb=c12acbd7d48431d7b5029d765e69e87378aca7a2;hp=87537475d66729919b2e3b0e04626c0607a25ee2;hpb=6c955787f04e378771f64a66332218c522e7810e;p=vlc diff --git a/modules/packetizer/copy.c b/modules/packetizer/copy.c index 87537475d6..dbaa96b321 100644 --- a/modules/packetizer/copy.c +++ b/modules/packetizer/copy.c @@ -1,7 +1,7 @@ /***************************************************************************** * copy.c ***************************************************************************** - * Copyright (C) 2001, 2002 VideoLAN + * Copyright (C) 2001, 2002, 2006 the VideoLAN team * $Id$ * * Authors: Laurent Aimar @@ -19,17 +19,22 @@ * * 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 /* malloc(), free() */ -#include -#include -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include +#include +#include +#include /***************************************************************************** * Module descriptor @@ -37,11 +42,13 @@ static int Open ( vlc_object_t * ); static void Close( vlc_object_t * ); -vlc_module_begin(); - set_description( _("Copy packetizer") ); - set_capability( "packetizer", 1 ); - set_callbacks( Open, Close ); -vlc_module_end(); +vlc_module_begin () + set_category( CAT_SOUT ) + set_subcategory( SUBCAT_SOUT_PACKETIZER ) + set_description( N_("Copy packetizer") ) + set_capability( "packetizer", 1 ) + set_callbacks( Open, Close ) +vlc_module_end () /***************************************************************************** * Local prototypes @@ -49,9 +56,13 @@ vlc_module_end(); struct decoder_sys_t { block_t *p_block; + void (*pf_parse)( decoder_t *, block_t * ); }; -static block_t *Packetize ( decoder_t *, block_t ** ); +static block_t *Packetize ( decoder_t *, block_t ** ); +static block_t *PacketizeSub( decoder_t *, block_t ** ); + +static void ParseWMV3( decoder_t *, block_t * ); /***************************************************************************** * Open: probe the packetizer and return score @@ -72,162 +83,38 @@ static int Open( vlc_object_t *p_this ) return VLC_EGENERIC; } - p_dec->pf_packetize = Packetize; + if( p_dec->fmt_in.i_cat == SPU_ES ) + p_dec->pf_packetize = PacketizeSub; + else + p_dec->pf_packetize = Packetize; /* Create the output format */ - memcpy( &p_dec->fmt_out, &p_dec->fmt_in, sizeof( es_format_t ) ); - if( p_dec->fmt_in.i_extra > 0 ) + es_format_Copy( &p_dec->fmt_out, &p_dec->fmt_in ); + + /* Fix the value of the fourcc for audio */ + if( p_dec->fmt_in.i_cat == AUDIO_ES ) { - p_dec->fmt_out.p_extra = malloc( p_dec->fmt_in.i_extra ); - memcpy( p_dec->fmt_out.p_extra, p_dec->fmt_in.p_extra, - p_dec->fmt_in.i_extra ); + p_dec->fmt_out.i_codec = vlc_fourcc_GetCodecAudio( p_dec->fmt_in.i_codec, + p_dec->fmt_in.audio.i_bitspersample ); + if( !p_dec->fmt_out.i_codec ) + { + msg_Err( p_dec, "unknown raw audio sample size" ); + return VLC_EGENERIC; + } } - /* Fix the value of the fourcc */ + p_dec->p_sys = p_sys = malloc( sizeof(*p_sys) ); + p_sys->p_block = NULL; switch( p_dec->fmt_in.i_codec ) { - /* video */ - case VLC_FOURCC( 'm', '4', 's', '2'): - case VLC_FOURCC( 'M', '4', 'S', '2'): - case VLC_FOURCC( 'm', 'p', '4', 's'): - case VLC_FOURCC( 'M', 'P', '4', 'S'): - case VLC_FOURCC( 'D', 'I', 'V', 'X'): - case VLC_FOURCC( 'd', 'i', 'v', 'x'): - case VLC_FOURCC( 'X', 'V', 'I', 'D'): - case VLC_FOURCC( 'X', 'v', 'i', 'D'): - case VLC_FOURCC( 'x', 'v', 'i', 'd'): - case VLC_FOURCC( 'D', 'X', '5', '0'): - case VLC_FOURCC( 0x04, 0, 0, 0): - case VLC_FOURCC( '3', 'I', 'V', '2'): - p_dec->fmt_out.i_codec = VLC_FOURCC( 'm', 'p', '4', 'v'); - break; - - case VLC_FOURCC( 'm', 'p', 'g', '1' ): - case VLC_FOURCC( 'm', 'p', 'g', '2' ): - case VLC_FOURCC( 'm', 'p', '1', 'v' ): - case VLC_FOURCC( 'm', 'p', '2', 'v' ): - p_dec->fmt_out.i_codec = VLC_FOURCC( 'm', 'p', 'g', 'v' ); - break; - - case VLC_FOURCC( 'd', 'i', 'v', '1' ): - case VLC_FOURCC( 'M', 'P', 'G', '4' ): - case VLC_FOURCC( 'm', 'p', 'g', '4' ): - p_dec->fmt_out.i_codec = VLC_FOURCC( 'D', 'I', 'V', '1' ); - break; - - case VLC_FOURCC( 'd', 'i', 'v', '2' ): - case VLC_FOURCC( 'M', 'P', '4', '2' ): - case VLC_FOURCC( 'm', 'p', '4', '2' ): - p_dec->fmt_out.i_codec = VLC_FOURCC( 'D', 'I', 'V', '2' ); - break; - - case VLC_FOURCC( 'd', 'i', 'v', '3' ): - case VLC_FOURCC( 'd', 'i', 'v', '4' ): - case VLC_FOURCC( 'D', 'I', 'V', '4' ): - case VLC_FOURCC( 'd', 'i', 'v', '5' ): - case VLC_FOURCC( 'D', 'I', 'V', '5' ): - case VLC_FOURCC( 'd', 'i', 'v', '6' ): - case VLC_FOURCC( 'D', 'I', 'V', '6' ): - case VLC_FOURCC( 'M', 'P', '4', '3' ): - case VLC_FOURCC( 'm', 'p', '4', '3' ): - case VLC_FOURCC( 'm', 'p', 'g', '3' ): - case VLC_FOURCC( 'M', 'P', 'G', '3' ): - case VLC_FOURCC( 'A', 'P', '4', '1' ): - p_dec->fmt_out.i_codec = VLC_FOURCC( 'D', 'I', 'V', '3' ); - break; - - case VLC_FOURCC( 'h', '2', '6', '3' ): - case VLC_FOURCC( 'U', '2', '6', '3' ): - case VLC_FOURCC( 'u', '2', '6', '3' ): - p_dec->fmt_out.i_codec = VLC_FOURCC( 'H', '2', '6', '3' ); - break; - - case VLC_FOURCC( 'i', '2', '6', '3' ): - p_dec->fmt_out.i_codec = VLC_FOURCC( 'I', '2', '6', '3' ); - break; - - case VLC_FOURCC( 'm', 'j', 'p', 'g' ): - case VLC_FOURCC( 'm', 'j', 'p', 'a' ): - case VLC_FOURCC( 'j', 'p', 'e', 'g' ): - case VLC_FOURCC( 'J', 'P', 'E', 'G' ): - case VLC_FOURCC( 'J', 'F', 'I', 'F' ): - p_dec->fmt_out.i_codec = VLC_FOURCC( 'M', 'J', 'P', 'G' ); - break; - - case VLC_FOURCC( 'd', 'v', 's', 'd' ): - case VLC_FOURCC( 'D', 'V', 'S', 'D' ): - case VLC_FOURCC( 'd', 'v', 'h', 'd' ): - p_dec->fmt_out.i_codec = VLC_FOURCC( 'd', 'v', 's', 'l' ); - break; - - /* audio */ - case VLC_FOURCC( 'a', 'r', 'a', 'w' ): - switch( ( p_dec->fmt_in.audio.i_bitspersample + 7 ) / 8 ) - { - case 1: - p_dec->fmt_out.i_codec = VLC_FOURCC('u','8',' ',' '); - break; - case 2: - p_dec->fmt_out.i_codec = VLC_FOURCC('s','1','6','l'); - break; - case 3: - p_dec->fmt_out.i_codec = VLC_FOURCC('s','2','4','l'); - break; - case 4: - p_dec->fmt_out.i_codec = VLC_FOURCC('s','3','2','l'); - break; - default: - msg_Err( p_dec, "unknown raw audio sample size" ); - return VLC_EGENERIC; - } - break; - - case VLC_FOURCC( 't', 'w', 'o', 's' ): - switch( ( p_dec->fmt_in.audio.i_bitspersample + 7 ) / 8 ) - { - case 1: - p_dec->fmt_out.i_codec = VLC_FOURCC('s','8',' ',' '); - break; - case 2: - p_dec->fmt_out.i_codec = VLC_FOURCC('s','1','6','b'); - break; - case 3: - p_dec->fmt_out.i_codec = VLC_FOURCC('s','2','4','b'); - break; - case 4: - p_dec->fmt_out.i_codec = VLC_FOURCC('s','3','2','b'); - break; - default: - msg_Err( p_dec, "unknown raw audio sample size" ); - return VLC_EGENERIC; - } - break; - - case VLC_FOURCC( 's', 'o', 'w', 't' ): - switch( ( p_dec->fmt_in.audio.i_bitspersample + 7 ) / 8 ) - { - case 1: - p_dec->fmt_out.i_codec = VLC_FOURCC('s','8',' ',' '); - break; - case 2: - p_dec->fmt_out.i_codec = VLC_FOURCC('s','1','6','l'); - break; - case 3: - p_dec->fmt_out.i_codec = VLC_FOURCC('s','2','4','l'); - break; - case 4: - p_dec->fmt_out.i_codec = VLC_FOURCC('s','3','2','l'); - break; - default: - msg_Err( p_dec, "unknown raw audio sample size" ); - return VLC_EGENERIC; - } - break; + case VLC_CODEC_WMV3: + p_sys->pf_parse = ParseWMV3; + break; + default: + p_sys->pf_parse = NULL; + break; } - p_dec->p_sys = p_sys = malloc( sizeof( block_t ) ); - p_sys->p_block = NULL; - return VLC_SUCCESS; } @@ -243,11 +130,12 @@ static void Close( vlc_object_t *p_this ) block_ChainRelease( p_dec->p_sys->p_block ); } + es_format_Clean( &p_dec->fmt_out ); free( p_dec->p_sys ); } /***************************************************************************** - * PacketizeStd: packetize an unit (here copy a complete block ) + * Packetize: packetize an unit (here copy a complete block ) *****************************************************************************/ static block_t *Packetize ( decoder_t *p_dec, block_t **pp_block ) { @@ -255,20 +143,24 @@ static block_t *Packetize ( decoder_t *p_dec, block_t **pp_block ) block_t *p_ret = p_dec->p_sys->p_block; if( pp_block == NULL || *pp_block == NULL ) + return NULL; + if( (*pp_block)->i_flags&(BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) ) { + block_Release( *pp_block ); return NULL; } + p_block = *pp_block; *pp_block = NULL; - if( p_block->i_dts <= 0 ) + if( p_block->i_dts <= VLC_TS_INVALID ) { p_block->i_dts = p_block->i_pts; } - if( p_block->i_dts <= 0 ) + if( p_block->i_dts <= VLC_TS_INVALID ) { - msg_Dbg( p_dec, "need dts > 0" ); + msg_Dbg( p_dec, "need valid dts" ); block_Release( p_block ); return NULL; } @@ -279,5 +171,73 @@ static block_t *Packetize ( decoder_t *p_dec, block_t **pp_block ) } p_dec->p_sys->p_block = p_block; + if( p_ret && p_dec->p_sys->pf_parse ) + p_dec->p_sys->pf_parse( p_dec, p_ret ); return p_ret; } + +/***************************************************************************** + * PacketizeSub: packetize an unit (here copy a complete block ) + *****************************************************************************/ +static block_t *PacketizeSub( decoder_t *p_dec, block_t **pp_block ) +{ + block_t *p_block; + + if( pp_block == NULL || *pp_block == NULL ) + return NULL; + if( (*pp_block)->i_flags&(BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) ) + { + block_Release( *pp_block ); + return NULL; + } + + p_block = *pp_block; + *pp_block = NULL; + + if( p_block->i_dts <= VLC_TS_INVALID ) + { + p_block->i_dts = p_block->i_pts; + } + + if( p_block->i_dts <= VLC_TS_INVALID ) + { + msg_Dbg( p_dec, "need valid dts" ); + block_Release( p_block ); + return NULL; + } + + return p_block; +} + +/* Parse WMV3 packet and extract frame type information */ +static void ParseWMV3( decoder_t *p_dec, block_t *p_block ) +{ + bs_t s; + + /* Parse Sequence header */ + bs_init( &s, p_dec->fmt_in.p_extra, p_dec->fmt_in.i_extra ); + if( bs_read( &s, 2 ) == 3 ) + return; + bs_skip( &s, 22 ); + const bool b_range_reduction = bs_read( &s, 1 ); + const bool b_has_frames = bs_read( &s, 3 ) > 0; + bs_skip( &s, 2 ); + const bool b_frame_interpolation = bs_read( &s, 1 ); + if( bs_eof( &s ) ) + return; + + /* Parse frame type */ + bs_init( &s, p_block->p_buffer, p_block->i_buffer ); + bs_skip( &s, b_frame_interpolation + + 2 + + b_range_reduction ); + + p_block->i_flags &= ~BLOCK_FLAG_TYPE_MASK; + if( bs_read( &s, 1 ) ) + p_block->i_flags |= BLOCK_FLAG_TYPE_P; + else if( !b_has_frames || bs_read( &s, 1 ) ) + p_block->i_flags |= BLOCK_FLAG_TYPE_I; + else + p_block->i_flags |= BLOCK_FLAG_TYPE_B; +} +