#include <vlc_plugin.h>
#include <vlc_codec.h>
#include <vlc_block.h>
+#include <vlc_bits.h>
/*****************************************************************************
* Module descriptor
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 *PacketizeSub( decoder_t *, block_t ** );
+static void ParseWMV3( decoder_t *, block_t * );
+
/*****************************************************************************
* Open: probe the packetizer and return score
*****************************************************************************
/* Create the output format */
es_format_Copy( &p_dec->fmt_out, &p_dec->fmt_in );
- /* Fix the value of the fourcc */
- switch( p_dec->fmt_in.i_codec )
+ /* Fix the value of the fourcc for audio */
+ if( p_dec->fmt_in.i_cat == AUDIO_ES )
{
- 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_CODEC_U8;
- break;
- case 2:
- p_dec->fmt_out.i_codec = VLC_CODEC_S16L;
- break;
- case 3:
- p_dec->fmt_out.i_codec = VLC_CODEC_S24L;
- break;
- case 4:
- p_dec->fmt_out.i_codec = VLC_CODEC_S32L;
- 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_CODEC_S8;
- break;
- case 2:
- p_dec->fmt_out.i_codec = VLC_CODEC_S16B;
- break;
- case 3:
- p_dec->fmt_out.i_codec = VLC_CODEC_S24B;
- break;
- case 4:
- p_dec->fmt_out.i_codec = VLC_CODEC_S32B;
- 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_CODEC_S8;
- break;
- case 2:
- p_dec->fmt_out.i_codec = VLC_CODEC_S16L;
- break;
- case 3:
- p_dec->fmt_out.i_codec = VLC_CODEC_S24L;
- break;
- case 4:
- p_dec->fmt_out.i_codec = VLC_CODEC_S32L;
- break;
- default:
- msg_Err( p_dec, "unknown raw audio sample size" );
- return VLC_EGENERIC;
- }
- break;
+ 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;
+ }
}
p_dec->p_sys = p_sys = malloc( sizeof(*p_sys) );
p_sys->p_block = NULL;
+ switch( p_dec->fmt_in.i_codec )
+ {
+ case VLC_CODEC_WMV3:
+ p_sys->pf_parse = ParseWMV3;
+ break;
+ default:
+ p_sys->pf_parse = NULL;
+ break;
+ }
return VLC_SUCCESS;
}
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;
}
}
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;
}
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;
}
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;
+}
+