From cd4572dbed6331ff3971ca4d1593382a5e96da5c Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Mon, 16 Sep 2002 21:01:42 +0000 Subject: [PATCH] Add the convert functions to the source pads of the video4linux and video4linux2 source plugins Original commit message from CVS: Add the convert functions to the source pads of the video4linux and video4linux2 source plugins --- sys/v4l/gstv4lmjpegsrc.c | 65 ++++++++++++++++++++++++++++++++++++++++ sys/v4l/gstv4lsrc.c | 65 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 130 insertions(+) diff --git a/sys/v4l/gstv4lmjpegsrc.c b/sys/v4l/gstv4lmjpegsrc.c index e608092fa8..c3534bed82 100644 --- a/sys/v4l/gstv4lmjpegsrc.c +++ b/sys/v4l/gstv4lmjpegsrc.c @@ -57,6 +57,11 @@ static void gst_v4lmjpegsrc_class_init (GstV4lMjpegSrcClass * static void gst_v4lmjpegsrc_init (GstV4lMjpegSrc *v4lmjpegsrc); /* pad/buffer functions */ +static gboolean gst_v4lmjpegsrc_srcconvert (GstPad *pad, + GstFormat src_format, + gint64 src_value, + GstFormat *dest_format, + gint64 *dest_value); static GstPadConnectReturn gst_v4lmjpegsrc_srcconnect (GstPad *pad, GstCaps *caps); static GstBuffer* gst_v4lmjpegsrc_get (GstPad *pad); @@ -182,6 +187,7 @@ gst_v4lmjpegsrc_init (GstV4lMjpegSrc *v4lmjpegsrc) gst_pad_set_get_function (v4lmjpegsrc->srcpad, gst_v4lmjpegsrc_get); gst_pad_set_connect_function (v4lmjpegsrc->srcpad, gst_v4lmjpegsrc_srcconnect); + gst_pad_set_convert_function (v4lmjpegsrc->srcpad, gst_v4lmjpegsrc_srcconvert); v4lmjpegsrc->bufferpool = gst_buffer_pool_new( NULL, @@ -209,6 +215,65 @@ gst_v4lmjpegsrc_init (GstV4lMjpegSrc *v4lmjpegsrc) } +static gboolean +gst_v4lmjpegsrc_srcconvert (GstPad *pad, + GstFormat src_format, + gint64 src_value, + GstFormat *dest_format, + gint64 *dest_value) +{ + GstV4lMjpegSrc *v4lmjpegsrc; + gint norm; + gdouble fps; + + v4lmjpegsrc = GST_V4LMJPEGSRC (gst_pad_get_parent (pad)); + + if (!GST_V4L_IS_OPEN(GST_V4LELEMENT(v4lmjpegsrc))) + return FALSE; + + if (!gst_v4l_get_chan_norm(GST_V4LELEMENT(v4lmjpegsrc), NULL, &norm)) + return FALSE; + + if (norm == VIDEO_MODE_NTSC) + fps = 30000/1001; + else + fps = 25.; + + switch (src_format) { + case GST_FORMAT_TIME: + switch (*dest_format) { + case GST_FORMAT_DEFAULT: + *dest_format = GST_FORMAT_UNITS; + /* fall-through */ + case GST_FORMAT_UNITS: + *dest_value = src_value * fps / GST_SECOND; + break; + default: + return FALSE; + } + break; + + case GST_FORMAT_UNITS: + switch (*dest_format) { + case GST_FORMAT_DEFAULT: + *dest_format = GST_FORMAT_TIME; + /* fall-through */ + case GST_FORMAT_TIME: + *dest_value = src_value * GST_SECOND / fps; + break; + default: + return FALSE; + } + break; + + default: + return FALSE; + } + + return TRUE; +} + + static GstPadConnectReturn gst_v4lmjpegsrc_srcconnect (GstPad *pad, GstCaps *caps) diff --git a/sys/v4l/gstv4lsrc.c b/sys/v4l/gstv4lsrc.c index 18778506bd..c32613e01b 100644 --- a/sys/v4l/gstv4lsrc.c +++ b/sys/v4l/gstv4lsrc.c @@ -54,6 +54,11 @@ static void gst_v4lsrc_class_init (GstV4lSrcClass *klass); static void gst_v4lsrc_init (GstV4lSrc *v4lsrc); /* pad/buffer functions */ +static gboolean gst_v4lsrc_srcconvert (GstPad *pad, + GstFormat src_format, + gint64 src_value, + GstFormat *dest_format, + gint64 *dest_value); static GstPadConnectReturn gst_v4lsrc_srcconnect (GstPad *pad, GstCaps *caps); static GstBuffer* gst_v4lsrc_get (GstPad *pad); @@ -160,6 +165,7 @@ gst_v4lsrc_init (GstV4lSrc *v4lsrc) gst_pad_set_get_function (v4lsrc->srcpad, gst_v4lsrc_get); gst_pad_set_connect_function (v4lsrc->srcpad, gst_v4lsrc_srcconnect); + gst_pad_set_convert_function (v4lsrc->srcpad, gst_v4lsrc_srcconvert); v4lsrc->bufferpool = gst_buffer_pool_new( NULL, @@ -176,6 +182,65 @@ gst_v4lsrc_init (GstV4lSrc *v4lsrc) } +static gboolean +gst_v4lsrc_srcconvert (GstPad *pad, + GstFormat src_format, + gint64 src_value, + GstFormat *dest_format, + gint64 *dest_value) +{ + GstV4lSrc *v4lsrc; + gint norm; + gdouble fps; + + v4lsrc = GST_V4LSRC (gst_pad_get_parent (pad)); + + if (!GST_V4L_IS_OPEN(GST_V4LELEMENT(v4lsrc))) + return FALSE; + + if (!gst_v4l_get_chan_norm(GST_V4LELEMENT(v4lsrc), NULL, &norm)) + return FALSE; + + if (norm == VIDEO_MODE_NTSC) + fps = 30000/1001; + else + fps = 25.; + + switch (src_format) { + case GST_FORMAT_TIME: + switch (*dest_format) { + case GST_FORMAT_DEFAULT: + *dest_format = GST_FORMAT_UNITS; + /* fall-through */ + case GST_FORMAT_UNITS: + *dest_value = src_value * fps / GST_SECOND; + break; + default: + return FALSE; + } + break; + + case GST_FORMAT_UNITS: + switch (*dest_format) { + case GST_FORMAT_DEFAULT: + *dest_format = GST_FORMAT_TIME; + /* fall-through */ + case GST_FORMAT_TIME: + *dest_value = src_value * GST_SECOND / fps; + break; + default: + return FALSE; + } + break; + + default: + return FALSE; + } + + return TRUE; +} + + static GstPadConnectReturn gst_v4lsrc_srcconnect (GstPad *pad, GstCaps *vscapslist)