Implement query function and use GST_BUFFER_DURATION

Original commit message from CVS:
Implement query function and use GST_BUFFER_DURATION
This commit is contained in:
Ronald S. Bultje 2003-12-14 21:25:32 +00:00
parent 2242dec500
commit 99e7283568

View file

@ -71,6 +71,13 @@ static void gst_videotestsrc_get_property (GObject * object, guint prop_id, GVal
static GstData *gst_videotestsrc_get (GstPad * pad);
static const GstQueryType *
gst_videotestsrc_get_query_types (GstPad *pad);
static gboolean gst_videotestsrc_src_query (GstPad *pad,
GstQueryType type,
GstFormat *format,
gint64 *value);
static GstElementClass *parent_class = NULL;
static GstCaps * gst_videotestsrc_get_capslist (void);
@ -403,6 +410,9 @@ gst_videotestsrc_init (GstVideotestsrc * videotestsrc)
gst_pad_set_get_function (videotestsrc->srcpad, gst_videotestsrc_get);
gst_pad_set_link_function (videotestsrc->srcpad, gst_videotestsrc_src_link);
gst_pad_set_unlink_function (videotestsrc->srcpad, gst_videotestsrc_src_unlink);
gst_pad_set_query_function (videotestsrc->srcpad, gst_videotestsrc_src_query);
gst_pad_set_query_type_function (videotestsrc->srcpad,
gst_videotestsrc_get_query_types);
videotestsrc->pool = NULL;
gst_videotestsrc_set_pattern(videotestsrc, GST_VIDEOTESTSRC_SMPTE);
@ -414,6 +424,49 @@ gst_videotestsrc_init (GstVideotestsrc * videotestsrc)
}
static const GstQueryType *
gst_videotestsrc_get_query_types (GstPad *pad)
{
static const GstQueryType query_types[] = {
GST_QUERY_POSITION,
0,
};
return query_types;
}
static gboolean
gst_videotestsrc_src_query (GstPad *pad,
GstQueryType type,
GstFormat *format,
gint64 *value)
{
gboolean res = FALSE;
GstVideotestsrc *videotestsrc = GST_VIDEOTESTSRC (gst_pad_get_parent (pad));
switch (type) {
case GST_QUERY_POSITION:
switch (*format) {
case GST_FORMAT_TIME:
*value = videotestsrc->n_frames * GST_SECOND / (double) videotestsrc->rate;
res = TRUE;
break;
case GST_FORMAT_DEFAULT: /* frames */
*value = videotestsrc->n_frames;
res = TRUE;
break;
default:
break;
}
break;
default:
break;
}
return res;
}
static GstData *
gst_videotestsrc_get (GstPad * pad)
{
@ -429,7 +482,11 @@ gst_videotestsrc_get (GstPad * pad)
videotestsrc = GST_VIDEOTESTSRC (gst_pad_get_parent (pad));
g_return_val_if_fail (videotestsrc->fourcc != NULL, NULL);
if (videotestsrc->fourcc != NULL) {
gst_element_error (GST_ELEMENT (videotestsrc),
"No color format set - aborting");
return NULL;
}
newsize = (videotestsrc->width * videotestsrc->height * videotestsrc->bpp) >> 3;
g_return_val_if_fail (newsize > 0, NULL);
@ -474,6 +531,7 @@ gst_videotestsrc_get (GstPad * pad)
(videotestsrc->n_frames * GST_SECOND)/(double)videotestsrc->rate;
videotestsrc->n_frames++;
}
GST_BUFFER_DURATION (buf) = GST_SECOND / (double) videotestsrc->rate;
return GST_DATA (buf);
}
@ -593,6 +651,3 @@ GST_PLUGIN_DEFINE (
GST_PACKAGE,
GST_ORIGIN
)