+/*****************************************************************************
+ * Helpers:
+ *****************************************************************************/
+static void PacketizeReset( void *p_private, bool b_broken )
+{
+ decoder_t *p_dec = p_private;
+ decoder_sys_t *p_sys = p_dec->p_sys;
+
+ if( b_broken )
+ {
+ p_sys->b_discontinuity = true;
+ if( p_sys->p_frame )
+ block_ChainRelease( p_sys->p_frame );
+ p_sys->p_frame = NULL;
+ p_sys->pp_last = &p_sys->p_frame;
+ p_sys->b_frame_slice = false;
+ }
+ p_sys->i_dts =
+ p_sys->i_pts =
+ p_sys->i_interpolated_dts =
+ p_sys->i_last_ref_pts = VLC_TS_INVALID;
+}
+
+static block_t *PacketizeParse( void *p_private, bool *pb_ts_used, block_t *p_block )
+{
+ decoder_t *p_dec = p_private;
+
+ /* Check if we have a picture start code */
+ *pb_ts_used = p_block->p_buffer[3] == 0x00;
+
+ return ParseMPEGBlock( p_dec, p_block );
+}
+
+
+static int PacketizeValidate( void *p_private, block_t *p_au )
+{
+ decoder_t *p_dec = p_private;
+ decoder_sys_t *p_sys = p_dec->p_sys;
+
+ /* If a discontinuity has been encountered, then wait till
+ * the next Intra frame before continuing with packetizing */
+ if( p_sys->b_discontinuity &&
+ p_sys->b_sync_on_intra_frame )
+ {
+ if( (p_au->i_flags & BLOCK_FLAG_TYPE_I) == 0 )
+ {
+ msg_Dbg( p_dec, "waiting on intra frame" );
+ return VLC_EGENERIC;
+ }
+ msg_Dbg( p_dec, "synced on intra frame" );
+ p_sys->b_discontinuity = false;
+ p_au->i_flags |= BLOCK_FLAG_DISCONTINUITY;
+ }
+
+ /* We've just started the stream, wait for the first PTS.
+ * We discard here so we can still get the sequence header. */
+ if( p_sys->i_dts <= VLC_TS_INVALID && p_sys->i_pts <= VLC_TS_INVALID &&
+ p_sys->i_interpolated_dts <= VLC_TS_INVALID )
+ {
+ msg_Dbg( p_dec, "need a starting pts/dts" );
+ return VLC_EGENERIC;
+ }
+
+ /* When starting the stream we can have the first frame with
+ * an invalid DTS (i_interpolated_pts is initialized to VLC_TS_INVALID) */
+ if( p_au->i_dts <= VLC_TS_INVALID )
+ p_au->i_dts = p_au->i_pts;
+
+ return VLC_SUCCESS;
+}