Commit 31461ebd authored by Wim Taymans's avatar Wim Taymans
Browse files

gst/: The base class can now sync for us.

Original commit message from CVS:
* 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.
parent 78875532
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):
......
......@@ -116,7 +116,6 @@ static void gst_audiotestsrc_set_property (GObject * object,
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);
......@@ -126,6 +125,8 @@ static gboolean gst_audiotestsrc_src_query (GstPad * pad, GstQuery * query);
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);
......@@ -177,8 +178,8 @@ gst_audiotestsrc_class_init (GstAudioTestSrcClass * klass)
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
......@@ -293,45 +294,6 @@ gst_audiotestsrc_src_query (GstPad * pad, GstQuery * query)
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)
{
......@@ -545,6 +507,29 @@ gst_audiotestsrc_change_wave (GstAudioTestSrc * src)
}
}
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)
......@@ -571,14 +556,6 @@ gst_audiotestsrc_create (GstBaseSrc * basesrc, guint64 offset,
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));
......@@ -598,12 +575,6 @@ gst_audiotestsrc_create (GstBaseSrc * basesrc, guint64 offset,
*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
......
......@@ -71,7 +71,6 @@ static void gst_sinesrc_set_property (GObject * object,
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);
......@@ -79,6 +78,8 @@ 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);
......@@ -129,7 +130,7 @@ gst_sinesrc_class_init (GstSineSrcClass * klass)
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);
}
......@@ -249,43 +250,27 @@ gst_sinesrc_src_query (GstPad * pad, GstQuery * query)
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
......@@ -317,14 +302,6 @@ gst_sinesrc_create (GstBaseSrc * basesrc, guint64 offset,
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));
......@@ -354,12 +331,6 @@ gst_sinesrc_create (GstBaseSrc * basesrc, guint64 offset,
*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
......
......@@ -78,11 +78,10 @@ static void gst_videotestsrc_get_property (GObject * object, guint prop_id,
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);
......@@ -148,10 +147,9 @@ gst_videotestsrc_class_init (GstVideoTestSrcClass * klass)
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;
}
......@@ -346,14 +344,6 @@ gst_videotestsrc_negotiate (GstBaseSrc * bsrc)
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)
{
......@@ -407,43 +397,27 @@ 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
......@@ -466,14 +440,6 @@ gst_videotestsrc_create (GstPushSrc * psrc, GstBuffer ** buffer)
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,
......@@ -502,11 +468,6 @@ gst_videotestsrc_create (GstPushSrc * psrc, GstBuffer ** buffer)
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),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment