+2005-11-10 Wim Taymans <wim@fluendo.com>
+
+ * gst/audiotestsrc/gstaudiotestsrc.c:
+ (gst_audiotestsrc_class_init), (gst_audiotestsrc_get_times),
+ (gst_audiotestsrc_create):
+ * gst/sine/gstsinesrc.c: (gst_sinesrc_class_init),
+ (gst_sinesrc_get_times), (gst_sinesrc_create):
+ * gst/videotestsrc/gstvideotestsrc.c:
+ (gst_videotestsrc_class_init), (gst_videotestsrc_get_times),
+ (gst_videotestsrc_create):
+ The base class can now sync for us.
+
2005-11-10 Thomas Vander Stichele <thomas at apestaart dot org>
* sys/v4l/gstv4lsrc.c: (gst_v4lsrc_fixate):
guint prop_id, const GValue * value, GParamSpec * pspec);
static void gst_audiotestsrc_get_property (GObject * object,
guint prop_id, GValue * value, GParamSpec * pspec);
-static gboolean gst_audiotestsrc_unlock (GstBaseSrc * bsrc);
static gboolean gst_audiotestsrc_setcaps (GstBaseSrc * basesrc, GstCaps * caps);
static void gst_audiotestsrc_src_fixate (GstPad * pad, GstCaps * caps);
static void gst_audiotestsrc_change_wave (GstAudioTestSrc * src);
+static void gst_audiotestsrc_get_times (GstBaseSrc * basesrc,
+ GstBuffer * buffer, GstClockTime * start, GstClockTime * end);
static GstFlowReturn gst_audiotestsrc_create (GstBaseSrc * basesrc,
guint64 offset, guint length, GstBuffer ** buffer);
static gboolean gst_audiotestsrc_start (GstBaseSrc * basesrc);
gstbasesrc_class->set_caps = GST_DEBUG_FUNCPTR (gst_audiotestsrc_setcaps);
gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_audiotestsrc_start);
+ gstbasesrc_class->get_times = GST_DEBUG_FUNCPTR (gst_audiotestsrc_get_times);
gstbasesrc_class->create = GST_DEBUG_FUNCPTR (gst_audiotestsrc_create);
- gstbasesrc_class->unlock = GST_DEBUG_FUNCPTR (gst_audiotestsrc_unlock);
}
static void
return res;
}
-/* with STREAM_LOCK */
-static GstClockReturn
-gst_audiotestsrc_wait (GstAudioTestSrc * src, GstClockTime time)
-{
- GstClockReturn ret;
- GstClockTime base_time;
-
- GST_LOCK (src);
- /* clock_id should be NULL outside of this function */
- g_assert (src->clock_id == NULL);
- g_assert (GST_CLOCK_TIME_IS_VALID (time));
- base_time = GST_ELEMENT (src)->base_time;
- src->clock_id = gst_clock_new_single_shot_id (GST_ELEMENT_CLOCK (src),
- time + base_time);
- GST_UNLOCK (src);
-
- ret = gst_clock_id_wait (src->clock_id, NULL);
-
- GST_LOCK (src);
- gst_clock_id_unref (src->clock_id);
- src->clock_id = NULL;
- GST_UNLOCK (src);
-
- return ret;
-}
-
-static gboolean
-gst_audiotestsrc_unlock (GstBaseSrc * bsrc)
-{
- GstAudioTestSrc *src = GST_AUDIOTESTSRC (bsrc);
-
- GST_LOCK (src);
- if (src->clock_id)
- gst_clock_id_unschedule (src->clock_id);
- GST_UNLOCK (src);
-
- return TRUE;
-}
-
static void
gst_audiotestsrc_create_sine (GstAudioTestSrc * src, gint16 * samples)
{
}
}
+static void
+gst_audiotestsrc_get_times (GstBaseSrc * basesrc, GstBuffer * buffer,
+ GstClockTime * start, GstClockTime * end)
+{
+ /* for live sources, sync on the timestamp of the buffer */
+ if (gst_base_src_is_live (basesrc)) {
+ GstClockTime timestamp = GST_BUFFER_TIMESTAMP (buffer);
+
+ if (GST_CLOCK_TIME_IS_VALID (timestamp)) {
+ /* get duration to calculate end time */
+ GstClockTime duration = GST_BUFFER_DURATION (buffer);
+
+ if (GST_CLOCK_TIME_IS_VALID (duration)) {
+ *end = timestamp + duration;
+ }
+ *start = timestamp;
+ }
+ } else {
+ *start = -1;
+ *end = -1;
+ }
+}
+
static GstFlowReturn
gst_audiotestsrc_create (GstBaseSrc * basesrc, guint64 offset,
guint length, GstBuffer ** buffer)
tdiff = src->samples_per_buffer * GST_SECOND / src->samplerate;
- if (gst_base_src_is_live (basesrc)) {
- GstClockReturn ret;
-
- ret = gst_audiotestsrc_wait (src, src->timestamp + src->timestamp_offset);
- if (ret == GST_CLOCK_UNSCHEDULED)
- goto unscheduled;
- }
-
buf = gst_buffer_new_and_alloc (src->samples_per_buffer * sizeof (gint16));
gst_buffer_set_caps (buf, GST_PAD_CAPS (basesrc->srcpad));
*buffer = buf;
return GST_FLOW_OK;
-
-unscheduled:
- {
- GST_DEBUG_OBJECT (src, "Unscheduled while waiting for clock");
- return GST_FLOW_WRONG_STATE; /* is this the right return? */
- }
}
static void
guint prop_id, const GValue * value, GParamSpec * pspec);
static void gst_sinesrc_get_property (GObject * object,
guint prop_id, GValue * value, GParamSpec * pspec);
-static gboolean gst_sinesrc_unlock (GstBaseSrc * bsrc);
static gboolean gst_sinesrc_setcaps (GstBaseSrc * basesrc, GstCaps * caps);
static void gst_sinesrc_src_fixate (GstPad * pad, GstCaps * caps);
static const GstQueryType *gst_sinesrc_get_query_types (GstPad * pad);
static gboolean gst_sinesrc_src_query (GstPad * pad, GstQuery * query);
+static void gst_sinesrc_get_times (GstBaseSrc * basesrc, GstBuffer * buffer,
+ GstClockTime * start, GstClockTime * end);
static GstFlowReturn gst_sinesrc_create (GstBaseSrc * basesrc, guint64 offset,
guint length, GstBuffer ** buffer);
static gboolean gst_sinesrc_start (GstBaseSrc * basesrc);
gstbasesrc_class->set_caps = GST_DEBUG_FUNCPTR (gst_sinesrc_setcaps);
gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_sinesrc_start);
gstbasesrc_class->create = GST_DEBUG_FUNCPTR (gst_sinesrc_create);
- gstbasesrc_class->unlock = GST_DEBUG_FUNCPTR (gst_sinesrc_unlock);
+ gstbasesrc_class->get_times = GST_DEBUG_FUNCPTR (gst_sinesrc_get_times);
gstbasesrc_class->newsegment = GST_DEBUG_FUNCPTR (gst_sinesrc_newsegment);
}
return res;
}
-/* with STREAM_LOCK */
-static GstClockReturn
-gst_sinesrc_wait (GstSineSrc * src, GstClockTime time)
-{
- GstClockReturn ret;
- GstClockTime base_time;
-
- GST_LOCK (src);
- /* clock_id should be NULL outside of this function */
- g_assert (src->clock_id == NULL);
- g_assert (GST_CLOCK_TIME_IS_VALID (time));
- base_time = GST_ELEMENT (src)->base_time;
- src->clock_id = gst_clock_new_single_shot_id (GST_ELEMENT_CLOCK (src),
- time + base_time);
- GST_UNLOCK (src);
-
- ret = gst_clock_id_wait (src->clock_id, NULL);
-
- GST_LOCK (src);
- gst_clock_id_unref (src->clock_id);
- src->clock_id = NULL;
- GST_UNLOCK (src);
-
- return ret;
-}
-
-static gboolean
-gst_sinesrc_unlock (GstBaseSrc * bsrc)
+static void
+gst_sinesrc_get_times (GstBaseSrc * basesrc, GstBuffer * buffer,
+ GstClockTime * start, GstClockTime * end)
{
- GstSineSrc *src = GST_SINESRC (bsrc);
+ /* for live sources, sync on the timestamp of the buffer */
+ if (gst_base_src_is_live (basesrc)) {
+ GstClockTime timestamp = GST_BUFFER_TIMESTAMP (buffer);
- GST_LOCK (src);
- if (src->clock_id)
- gst_clock_id_unschedule (src->clock_id);
- GST_UNLOCK (src);
+ if (GST_CLOCK_TIME_IS_VALID (timestamp)) {
+ /* get duration to calculate end time */
+ GstClockTime duration = GST_BUFFER_DURATION (buffer);
- return TRUE;
+ if (GST_CLOCK_TIME_IS_VALID (duration)) {
+ *end = timestamp + duration;
+ }
+ *start = timestamp;
+ }
+ } else {
+ *start = -1;
+ *end = -1;
+ }
}
static GstFlowReturn
tdiff = src->samples_per_buffer * GST_SECOND / src->samplerate;
- if (gst_base_src_is_live (basesrc)) {
- GstClockReturn ret;
-
- ret = gst_sinesrc_wait (src, src->timestamp + src->timestamp_offset);
- if (ret == GST_CLOCK_UNSCHEDULED)
- goto unscheduled;
- }
-
buf = gst_buffer_new_and_alloc (src->samples_per_buffer * sizeof (gint16));
gst_buffer_set_caps (buf, GST_PAD_CAPS (basesrc->srcpad));
*buffer = buf;
return GST_FLOW_OK;
-
-unscheduled:
- {
- GST_DEBUG_OBJECT (src, "Unscheduled while waiting for clock");
- return GST_FLOW_WRONG_STATE; /* is this the right return? */
- }
}
static void
static GstCaps *gst_videotestsrc_getcaps (GstBaseSrc * bsrc);
static gboolean gst_videotestsrc_setcaps (GstBaseSrc * bsrc, GstCaps * caps);
static gboolean gst_videotestsrc_negotiate (GstBaseSrc * bsrc);
-static void gst_videotestsrc_get_times (GstBaseSrc * src, GstBuffer * buffer,
- GstClockTime * start, GstClockTime * end);
static gboolean gst_videotestsrc_event (GstBaseSrc * bsrc, GstEvent * event);
-static gboolean gst_videotestsrc_unlock (GstBaseSrc * bsrc);
+static void gst_videotestsrc_get_times (GstBaseSrc * basesrc,
+ GstBuffer * buffer, GstClockTime * start, GstClockTime * end);
static GstFlowReturn gst_videotestsrc_create (GstPushSrc * psrc,
GstBuffer ** buffer);
gstbasesrc_class->get_caps = gst_videotestsrc_getcaps;
gstbasesrc_class->set_caps = gst_videotestsrc_setcaps;
gstbasesrc_class->negotiate = gst_videotestsrc_negotiate;
- gstbasesrc_class->get_times = gst_videotestsrc_get_times;
gstbasesrc_class->event = gst_videotestsrc_event;
- gstbasesrc_class->unlock = gst_videotestsrc_unlock;
+ gstbasesrc_class->get_times = gst_videotestsrc_get_times;
gstpushsrc_class->create = gst_videotestsrc_create;
}
return result;
}
-static void
-gst_videotestsrc_get_times (GstBaseSrc * src, GstBuffer * buffer,
- GstClockTime * start, GstClockTime * end)
-{
- *start = GST_CLOCK_TIME_NONE;
- *end = GST_CLOCK_TIME_NONE;
-}
-
static gboolean
gst_videotestsrc_event (GstBaseSrc * bsrc, GstEvent * event)
{
return res;
}
-/* with STREAM_LOCK */
-static GstClockReturn
-gst_videotestsrc_wait (GstVideoTestSrc * src, GstClockTime time)
-{
- GstClockReturn ret;
- GstClockTime base_time;
-
- GST_LOCK (src);
- /* clock_id should be NULL outside of this function */
- g_assert (src->clock_id == NULL);
- g_assert (GST_CLOCK_TIME_IS_VALID (time));
- base_time = GST_ELEMENT (src)->base_time;
- src->clock_id = gst_clock_new_single_shot_id (GST_ELEMENT_CLOCK (src),
- time + base_time);
- GST_UNLOCK (src);
-
- ret = gst_clock_id_wait (src->clock_id, NULL);
-
- GST_LOCK (src);
- gst_clock_id_unref (src->clock_id);
- src->clock_id = NULL;
- GST_UNLOCK (src);
-
- return ret;
-}
-
-static gboolean
-gst_videotestsrc_unlock (GstBaseSrc * bsrc)
+static void
+gst_videotestsrc_get_times (GstBaseSrc * basesrc, GstBuffer * buffer,
+ GstClockTime * start, GstClockTime * end)
{
- GstVideoTestSrc *src = GST_VIDEOTESTSRC (bsrc);
+ /* for live sources, sync on the timestamp of the buffer */
+ if (gst_base_src_is_live (basesrc)) {
+ GstClockTime timestamp = GST_BUFFER_TIMESTAMP (buffer);
- GST_LOCK (src);
- if (src->clock_id)
- gst_clock_id_unschedule (src->clock_id);
- GST_UNLOCK (src);
+ if (GST_CLOCK_TIME_IS_VALID (timestamp)) {
+ /* get duration to calculate end time */
+ GstClockTime duration = GST_BUFFER_DURATION (buffer);
- return TRUE;
+ if (GST_CLOCK_TIME_IS_VALID (duration)) {
+ *end = timestamp + duration;
+ }
+ *start = timestamp;
+ }
+ } else {
+ *start = -1;
+ *end = -1;
+ }
}
static GstFlowReturn
GST_LOG_OBJECT (src, "creating buffer of %ld bytes for %dx%d image",
newsize, src->width, src->height);
- if (gst_base_src_is_live (GST_BASE_SRC (src))) {
- GstClockReturn ret;
-
- ret =
- gst_videotestsrc_wait (src, src->running_time + src->timestamp_offset);
- if (ret == GST_CLOCK_UNSCHEDULED)
- goto unscheduled;
- }
#ifdef USE_PEER_BUFFERALLOC
res =
gst_pad_alloc_buffer (GST_BASE_SRC_PAD (psrc), GST_BUFFER_OFFSET_NONE,
return GST_FLOW_OK;
-unscheduled:
- {
- GST_DEBUG_OBJECT (src, "Unscheduled while waiting for clock");
- return GST_FLOW_WRONG_STATE;
- }
not_negotiated:
{
GST_ELEMENT_ERROR (src, CORE, NEGOTIATION, (NULL),