mpegdemux: refactor init and reset

This commit is contained in:
Mark Nauwelaerts 2012-10-11 11:30:44 +02:00
parent 08d2fff2fd
commit aca6237b3e

View file

@ -170,6 +170,9 @@ static inline void gst_flups_demux_send_segment_updates (GstFluPSDemux * demux,
GstClockTime new_time);
static inline void gst_flups_demux_clear_times (GstFluPSDemux * demux);
static void gst_flups_demux_reset_psm (GstFluPSDemux * demux);
static void gst_flups_demux_flush (GstFluPSDemux * demux);
static GstElementClass *parent_class = NULL;
static void gst_segment_set_position (GstSegment * segment, GstFormat format,
@ -272,6 +275,10 @@ gst_flups_demux_init (GstFluPSDemux * demux)
g_malloc0 (sizeof (GstFluPSStream *) * (GST_FLUPS_DEMUX_MAX_STREAMS));
demux->found_count = 0;
demux->adapter = gst_adapter_new ();
demux->rev_adapter = gst_adapter_new ();
gst_flups_demux_reset (demux);
}
static void
@ -281,6 +288,9 @@ gst_flups_demux_finalize (GstFluPSDemux * demux)
g_free (demux->streams);
g_free (demux->streams_found);
g_object_unref (demux->adapter);
g_object_unref (demux->rev_adapter);
G_OBJECT_CLASS (parent_class)->finalize (G_OBJECT (demux));
}
@ -308,6 +318,27 @@ gst_flups_demux_reset (GstFluPSDemux * demux)
p_ev = &demux->lang_codes;
gst_event_replace (p_ev, NULL);
gst_adapter_clear (demux->adapter);
gst_adapter_clear (demux->rev_adapter);
demux->adapter_offset = G_MAXUINT64;
demux->first_scr = G_MAXUINT64;
demux->last_scr = G_MAXUINT64;
demux->current_scr = G_MAXUINT64;
demux->base_time = G_MAXUINT64;
demux->scr_rate_n = G_MAXUINT64;
demux->scr_rate_d = G_MAXUINT64;
demux->first_pts = G_MAXUINT64;
demux->last_pts = G_MAXUINT64;
demux->mux_rate = G_MAXUINT64;
demux->next_pts = G_MAXUINT64;
demux->next_dts = G_MAXUINT64;
demux->need_no_more_pads = TRUE;
gst_flups_demux_reset_psm (demux);
gst_segment_init (&demux->sink_segment, GST_FORMAT_UNDEFINED);
gst_segment_init (&demux->src_segment, GST_FORMAT_TIME);
gst_flups_demux_flush (demux);
}
static GstFluPSStream *
@ -2994,41 +3025,14 @@ gst_flups_demux_change_state (GstElement * element, GstStateChange transition)
switch (transition) {
case GST_STATE_CHANGE_NULL_TO_READY:
demux->adapter = gst_adapter_new ();
demux->rev_adapter = gst_adapter_new ();
demux->adapter_offset = G_MAXUINT64;
gst_pes_filter_init (&demux->filter, demux->adapter,
&demux->adapter_offset);
gst_pes_filter_set_callbacks (&demux->filter,
(GstPESFilterData) gst_flups_demux_data_cb,
(GstPESFilterResync) gst_flups_demux_resync_cb, demux);
demux->filter.gather_pes = TRUE;
demux->first_scr = G_MAXUINT64;
demux->last_scr = G_MAXUINT64;
demux->current_scr = G_MAXUINT64;
demux->base_time = G_MAXUINT64;
demux->scr_rate_n = G_MAXUINT64;
demux->scr_rate_d = G_MAXUINT64;
demux->first_pts = G_MAXUINT64;
demux->last_pts = G_MAXUINT64;
break;
case GST_STATE_CHANGE_READY_TO_PAUSED:
demux->current_scr = G_MAXUINT64;
demux->mux_rate = G_MAXUINT64;
demux->next_pts = G_MAXUINT64;
demux->next_dts = G_MAXUINT64;
demux->first_scr = G_MAXUINT64;
demux->last_scr = G_MAXUINT64;
demux->base_time = G_MAXUINT64;
demux->scr_rate_n = G_MAXUINT64;
demux->scr_rate_d = G_MAXUINT64;
demux->need_no_more_pads = TRUE;
demux->first_pts = G_MAXUINT64;
demux->last_pts = G_MAXUINT64;
gst_flups_demux_reset_psm (demux);
gst_segment_init (&demux->sink_segment, GST_FORMAT_UNDEFINED);
gst_segment_init (&demux->src_segment, GST_FORMAT_TIME);
gst_flups_demux_flush (demux);
break;
default:
break;
@ -3042,10 +3046,6 @@ gst_flups_demux_change_state (GstElement * element, GstStateChange transition)
break;
case GST_STATE_CHANGE_READY_TO_NULL:
gst_pes_filter_uninit (&demux->filter);
g_object_unref (demux->adapter);
demux->adapter = NULL;
g_object_unref (demux->rev_adapter);
demux->rev_adapter = NULL;
break;
default:
break;