gst/base/gstbasesink.c: 0 segment values are 0 in any format.

Original commit message from CVS:
* gst/base/gstbasesink.c: (gst_base_sink_handle_object):
0 segment values are 0 in any format.

* gst/base/gstbasetransform.c: (gst_base_transform_event):
* gst/base/gstbasetransform.h:
Parse newsegment correctly in basetransform

* gst/elements/gstidentity.c: (gst_identity_transform_ip):
Sync to clock using updated segment values.
This commit is contained in:
Wim Taymans 2005-11-15 16:47:07 +00:00
parent a594b62809
commit eb29555a92
9 changed files with 174 additions and 44 deletions

View file

@ -1,3 +1,15 @@
2005-11-15 Wim Taymans <wim@fluendo.com>
* gst/base/gstbasesink.c: (gst_base_sink_handle_object):
0 segment values are 0 in any format.
* gst/base/gstbasetransform.c: (gst_base_transform_event):
* gst/base/gstbasetransform.h:
Parse newsegment correctly in basetransform
* gst/elements/gstidentity.c: (gst_identity_transform_ip):
Sync to clock using updated segment values.
2005-11-15 Andy Wingo <wingo@pobox.com>
* check/gst/gstpipeline.c (test_base_time): Add check that the

View file

@ -584,7 +584,6 @@ gst_base_sink_handle_object (GstBaseSink * basesink, GstPad * pad,
gint64 segment_time;
GstClockTime duration;
/* the newsegment event is needed to bring the buffer timestamps to the
* stream time and to drop samples outside of the playback segment. */
gst_event_parse_newsegment (event, &update, &rate, &format,
@ -598,8 +597,10 @@ gst_base_sink_handle_object (GstBaseSink * basesink, GstPad * pad,
GST_DEBUG_OBJECT (basesink,
"non-time newsegment with start 0, coaxing into FORMAT_TIME");
format = GST_FORMAT_TIME;
segment_stop = -1;
segment_time = -1;
if (segment_stop != 0)
segment_stop = -1;
if (segment_time != 0)
segment_time = -1;
}
if (format != GST_FORMAT_TIME) {

View file

@ -1054,6 +1054,14 @@ gst_base_transform_event (GstPad * pad, GstEvent * event)
case GST_EVENT_FLUSH_STOP:
GST_STREAM_LOCK (pad);
unlock = TRUE;
/* we need new segment info after the flush. */
trans->segment_rate = 1.0;
trans->segment_start = -1;
trans->segment_stop = -1;
trans->segment_base = -1;
GST_DEBUG_OBJECT (trans, "reset accum %" GST_TIME_FORMAT,
GST_TIME_ARGS (trans->segment_accum));
trans->segment_accum = 0;
break;
case GST_EVENT_EOS:
GST_STREAM_LOCK (pad);
@ -1067,26 +1075,69 @@ gst_base_transform_event (GstPad * pad, GstEvent * event)
{
GstFormat format;
gdouble rate;
gint64 start, stop, time;
gint64 start, stop, time, duration;
gboolean update;
GST_STREAM_LOCK (pad);
unlock = TRUE;
gst_event_parse_newsegment (event, &update, &rate, &format, &start, &stop,
&time);
/* any other format with 0 also gives time 0, the other values are
* invalid as time though. */
if (format != GST_FORMAT_TIME) {
GST_DEBUG_OBJECT (trans,
"non-time newsegment with start 0, coaxing into FORMAT_TIME");
format = GST_FORMAT_TIME;
if (start != 0)
start = -1;
if (stop != 0)
stop = -1;
if (time != 0)
time = -1;
}
/* check if we really have a new segment or the previous one is
* closed */
if (!update) {
/* the new segment has to be aligned with the old segment.
* We first update the accumulated time of the previous
* segment. the accumulated time is used when syncing to the
* clock. A flush event sets the accumulated time back to 0
*/
if (GST_CLOCK_TIME_IS_VALID (trans->segment_stop)) {
duration = trans->segment_stop - trans->segment_start;
} else {
duration = 0;
}
} else {
if (GST_CLOCK_TIME_IS_VALID (start))
duration = start - trans->segment_start;
else
duration = 0;
}
trans->have_newsegment = TRUE;
trans->segment_accum += gst_gdouble_to_guint64 (
(gst_guint64_to_gdouble (duration) / ABS (trans->segment_rate)));;
trans->segment_rate = rate;
trans->segment_start = start;
trans->segment_stop = stop;
trans->segment_base = time;
if (format == GST_FORMAT_TIME) {
GST_DEBUG_OBJECT (trans, "received NEW_SEGMENT %" GST_TIME_FORMAT
" -- %" GST_TIME_FORMAT ", time %" GST_TIME_FORMAT,
GST_TIME_ARGS (start), GST_TIME_ARGS (stop), GST_TIME_ARGS (time));
trans->have_newsegment = TRUE;
trans->segment_start = start;
trans->segment_stop = stop;
trans->segment_base = time;
trans->segment_rate = rate;
GST_TIME_ARGS (trans->segment_start),
GST_TIME_ARGS (trans->segment_start),
GST_TIME_ARGS (trans->segment_base));
} else {
GST_DEBUG_OBJECT (trans,
"received NEW_SEGMENT in non-time format, ignoring");
GST_DEBUG_OBJECT (trans, "received NEW_SEGMENT %" G_GINT64_FORMAT
" -- %" G_GINT64_FORMAT ", time %" G_GINT64_FORMAT,
trans->segment_start, trans->segment_stop, trans->segment_base);
}
break;
}
default:

View file

@ -78,14 +78,17 @@ struct _GstBaseTransform {
gint64 segment_stop;
gint64 segment_base;
/* FIXME: When adjusting the padding, move this to a nice place in the structure */
/* Set if caps on each pad are equal */
gboolean have_same_caps;
GMutex *transform_lock;
/*< private >*/
gpointer _gst_reserved[GST_PADDING - 2];
union {
/* FIXME: When adjusting the padding, move this to a nice place in the structure */
/* Set if caps on each pad are equal */
struct {
gboolean have_same_caps;
GMutex *transform_lock;
gint64 segment_accum;
};
/*< private >*/
gpointer _gst_reserved[GST_PADDING];
};
};
/**

View file

@ -374,11 +374,15 @@ gst_identity_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
GST_LOCK (identity);
if ((clock = GST_ELEMENT (identity)->clock)) {
GstClockReturn cret;
GstClockTime timestamp;
timestamp = GST_BUFFER_TIMESTAMP (buf) - trans->segment_start;
timestamp += trans->segment_accum;
timestamp += GST_ELEMENT (identity)->base_time;
/* save id if we need to unlock */
/* FIXME: actually unlock this somewhere in the state changes */
identity->clock_id = gst_clock_new_single_shot_id (clock,
GST_BUFFER_TIMESTAMP (buf) + GST_ELEMENT (identity)->base_time);
identity->clock_id = gst_clock_new_single_shot_id (clock, timestamp);
GST_UNLOCK (identity);
cret = gst_clock_id_wait (identity->clock_id, NULL);

View file

@ -584,7 +584,6 @@ gst_base_sink_handle_object (GstBaseSink * basesink, GstPad * pad,
gint64 segment_time;
GstClockTime duration;
/* the newsegment event is needed to bring the buffer timestamps to the
* stream time and to drop samples outside of the playback segment. */
gst_event_parse_newsegment (event, &update, &rate, &format,
@ -598,8 +597,10 @@ gst_base_sink_handle_object (GstBaseSink * basesink, GstPad * pad,
GST_DEBUG_OBJECT (basesink,
"non-time newsegment with start 0, coaxing into FORMAT_TIME");
format = GST_FORMAT_TIME;
segment_stop = -1;
segment_time = -1;
if (segment_stop != 0)
segment_stop = -1;
if (segment_time != 0)
segment_time = -1;
}
if (format != GST_FORMAT_TIME) {

View file

@ -1054,6 +1054,14 @@ gst_base_transform_event (GstPad * pad, GstEvent * event)
case GST_EVENT_FLUSH_STOP:
GST_STREAM_LOCK (pad);
unlock = TRUE;
/* we need new segment info after the flush. */
trans->segment_rate = 1.0;
trans->segment_start = -1;
trans->segment_stop = -1;
trans->segment_base = -1;
GST_DEBUG_OBJECT (trans, "reset accum %" GST_TIME_FORMAT,
GST_TIME_ARGS (trans->segment_accum));
trans->segment_accum = 0;
break;
case GST_EVENT_EOS:
GST_STREAM_LOCK (pad);
@ -1067,26 +1075,69 @@ gst_base_transform_event (GstPad * pad, GstEvent * event)
{
GstFormat format;
gdouble rate;
gint64 start, stop, time;
gint64 start, stop, time, duration;
gboolean update;
GST_STREAM_LOCK (pad);
unlock = TRUE;
gst_event_parse_newsegment (event, &update, &rate, &format, &start, &stop,
&time);
/* any other format with 0 also gives time 0, the other values are
* invalid as time though. */
if (format != GST_FORMAT_TIME) {
GST_DEBUG_OBJECT (trans,
"non-time newsegment with start 0, coaxing into FORMAT_TIME");
format = GST_FORMAT_TIME;
if (start != 0)
start = -1;
if (stop != 0)
stop = -1;
if (time != 0)
time = -1;
}
/* check if we really have a new segment or the previous one is
* closed */
if (!update) {
/* the new segment has to be aligned with the old segment.
* We first update the accumulated time of the previous
* segment. the accumulated time is used when syncing to the
* clock. A flush event sets the accumulated time back to 0
*/
if (GST_CLOCK_TIME_IS_VALID (trans->segment_stop)) {
duration = trans->segment_stop - trans->segment_start;
} else {
duration = 0;
}
} else {
if (GST_CLOCK_TIME_IS_VALID (start))
duration = start - trans->segment_start;
else
duration = 0;
}
trans->have_newsegment = TRUE;
trans->segment_accum += gst_gdouble_to_guint64 (
(gst_guint64_to_gdouble (duration) / ABS (trans->segment_rate)));;
trans->segment_rate = rate;
trans->segment_start = start;
trans->segment_stop = stop;
trans->segment_base = time;
if (format == GST_FORMAT_TIME) {
GST_DEBUG_OBJECT (trans, "received NEW_SEGMENT %" GST_TIME_FORMAT
" -- %" GST_TIME_FORMAT ", time %" GST_TIME_FORMAT,
GST_TIME_ARGS (start), GST_TIME_ARGS (stop), GST_TIME_ARGS (time));
trans->have_newsegment = TRUE;
trans->segment_start = start;
trans->segment_stop = stop;
trans->segment_base = time;
trans->segment_rate = rate;
GST_TIME_ARGS (trans->segment_start),
GST_TIME_ARGS (trans->segment_start),
GST_TIME_ARGS (trans->segment_base));
} else {
GST_DEBUG_OBJECT (trans,
"received NEW_SEGMENT in non-time format, ignoring");
GST_DEBUG_OBJECT (trans, "received NEW_SEGMENT %" G_GINT64_FORMAT
" -- %" G_GINT64_FORMAT ", time %" G_GINT64_FORMAT,
trans->segment_start, trans->segment_stop, trans->segment_base);
}
break;
}
default:

View file

@ -78,14 +78,17 @@ struct _GstBaseTransform {
gint64 segment_stop;
gint64 segment_base;
/* FIXME: When adjusting the padding, move this to a nice place in the structure */
/* Set if caps on each pad are equal */
gboolean have_same_caps;
GMutex *transform_lock;
/*< private >*/
gpointer _gst_reserved[GST_PADDING - 2];
union {
/* FIXME: When adjusting the padding, move this to a nice place in the structure */
/* Set if caps on each pad are equal */
struct {
gboolean have_same_caps;
GMutex *transform_lock;
gint64 segment_accum;
};
/*< private >*/
gpointer _gst_reserved[GST_PADDING];
};
};
/**

View file

@ -374,11 +374,15 @@ gst_identity_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
GST_LOCK (identity);
if ((clock = GST_ELEMENT (identity)->clock)) {
GstClockReturn cret;
GstClockTime timestamp;
timestamp = GST_BUFFER_TIMESTAMP (buf) - trans->segment_start;
timestamp += trans->segment_accum;
timestamp += GST_ELEMENT (identity)->base_time;
/* save id if we need to unlock */
/* FIXME: actually unlock this somewhere in the state changes */
identity->clock_id = gst_clock_new_single_shot_id (clock,
GST_BUFFER_TIMESTAMP (buf) + GST_ELEMENT (identity)->base_time);
identity->clock_id = gst_clock_new_single_shot_id (clock, timestamp);
GST_UNLOCK (identity);
cret = gst_clock_id_wait (identity->clock_id, NULL);