From: Thomas Vander Stichele Date: Mon, 3 May 2004 17:26:43 +0000 (+0000) Subject: query v4lsrc device for fps (which works for webcams) X-Git-Tag: BRANCH-GSTREAMER-0_8-ROOT~1188 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7da21bd2e8420010db825667cff5208a52e59ed4;p=platform%2Fupstream%2Fgst-plugins-base.git query v4lsrc device for fps (which works for webcams) Original commit message from CVS: query v4lsrc device for fps (which works for webcams) --- diff --git a/ChangeLog b/ChangeLog index baa8e95..bbae2f1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2004-05-03 Thomas Vander Stichele + + * sys/v4l/gstv4lelement.h: + * sys/v4l/gstv4lmjpegsrc.c: (gst_v4lmjpegsrc_class_init): + * sys/v4l/gstv4lsrc.c: (gst_v4lsrc_get_fps), (gst_v4lsrc_getcaps), + (gst_v4lsrc_buffer_free): + * sys/v4l/v4l_calls.c: (gst_v4l_get_capabilities): + * sys/v4l/v4lsrc_calls.c: (gst_v4lsrc_queue_frame), + (gst_v4lsrc_sync_frame), (gst_v4lsrc_grab_frame), + (gst_v4lsrc_requeue_frame): + move some debugging categories around + query for fps index and set accordingly if found + 2004-05-03 Stephane Loeuillet * ext/lame/gstlame.c: diff --git a/sys/v4l/gstv4lelement.h b/sys/v4l/gstv4lelement.h index 1b13c79..ad9bb58 100644 --- a/sys/v4l/gstv4lelement.h +++ b/sys/v4l/gstv4lelement.h @@ -70,9 +70,12 @@ struct _GstV4lElement { /* the video buffer (mmap()'ed) */ guint8 *buffer; - /* the video-device's capabilities */ + /* the video device's capabilities */ struct video_capability vcap; + /* the video device's window properties */ + struct video_window vwin; + /* some more info about the current input's capabilities */ struct video_channel vchan; diff --git a/sys/v4l/gstv4lmjpegsrc.c b/sys/v4l/gstv4lmjpegsrc.c index a0c7d28..53f11ca 100644 --- a/sys/v4l/gstv4lmjpegsrc.c +++ b/sys/v4l/gstv4lmjpegsrc.c @@ -187,7 +187,7 @@ gst_v4lmjpegsrc_class_init (GstV4lMjpegSrcClass * klass) g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_USE_FIXED_FPS, g_param_spec_boolean ("use_fixed_fps", "Use Fixed FPS", "Drop/Insert frames to reach a certain FPS (TRUE) " - "or adapt FPS to suit the number of frabbed frames", + "or adapt FPS to suit the number of grabbed frames", TRUE, G_PARAM_READWRITE)); /* signals */ diff --git a/sys/v4l/gstv4lsrc.c b/sys/v4l/gstv4lsrc.c index b1f2c7f..88e8eab 100644 --- a/sys/v4l/gstv4lsrc.c +++ b/sys/v4l/gstv4lsrc.c @@ -277,7 +277,18 @@ static gfloat gst_v4lsrc_get_fps (GstV4lSrc * v4lsrc) { gint norm; + gint fps_index; gfloat fps; + struct video_window *vwin = &GST_V4LELEMENT (v4lsrc)->vwin; + + /* check if we have vwin window properties giving a framerate, + * as is done for webcams + * See http://www.smcc.demon.nl/webcam/api.html + * which is used for the Philips and qce-ga drivers */ + fps_index = (vwin->flags >> 16) & 0x3F; /* 6 bit index for framerate */ + if (fps_index != 0) + /* index of 16 corresponds to 15 fps */ + return fps_index * 15.0 / 16; if (!v4lsrc->use_fixed_fps && v4lsrc->clock != NULL && v4lsrc->handled > 0) { /* try to get time from clock master and calculate fps */ @@ -622,6 +633,8 @@ gst_v4lsrc_getcaps (GstPad * pad) return gst_caps_new_any (); } + fps = gst_v4lsrc_get_fps (v4lsrc); + list = gst_caps_new_empty (); for (item = v4lsrc->colourspaces; item != NULL; item = item->next) { GstCaps *one; @@ -629,7 +642,6 @@ gst_v4lsrc_getcaps (GstPad * pad) one = gst_v4lsrc_palette_to_caps (GPOINTER_TO_INT (item->data)); if (!one) g_print ("Palette %d gave no caps\n", GPOINTER_TO_INT (item->data)); - fps = gst_v4lsrc_get_fps (v4lsrc); GST_DEBUG_OBJECT (v4lsrc, "Device reports w: %d-%d, h: %d-%d, fps: %f for palette %d", vcap->minwidth, vcap->maxwidth, vcap->minheight, vcap->maxheight, fps, @@ -895,14 +907,14 @@ gst_v4lsrc_buffer_free (GstBuffer * buf) g_free (v4lsrc_private); GST_BUFFER_PRIVATE (buf) = 0; - GST_DEBUG_OBJECT (v4lsrc, "freeing buffer %p with refcount %d for frame %d", + GST_LOG_OBJECT (v4lsrc, "freeing buffer %p with refcount %d for frame %d", buf, GST_BUFFER_REFCOUNT_VALUE (buf), num); if (gst_element_get_state (GST_ELEMENT (v4lsrc)) != GST_STATE_PLAYING) return; /* we've already cleaned up ourselves */ v4lsrc->use_num_times[num]--; if (v4lsrc->use_num_times[num] <= 0) { - GST_DEBUG_OBJECT (v4lsrc, "requeueing frame %d", num); + GST_LOG_OBJECT (v4lsrc, "requeueing frame %d", num); gst_v4lsrc_requeue_frame (v4lsrc, num); } } diff --git a/sys/v4l/v4l_calls.c b/sys/v4l/v4l_calls.c index 66af9dd..ea07da7 100644 --- a/sys/v4l/v4l_calls.c +++ b/sys/v4l/v4l_calls.c @@ -94,6 +94,13 @@ gst_v4l_get_capabilities (GstV4lElement * v4lelement) return FALSE; } + if (ioctl (v4lelement->video_fd, VIDIOCGWIN, &(v4lelement->vwin)) < 0) { + GST_ELEMENT_ERROR (v4lelement, RESOURCE, SETTINGS, (NULL), + ("error getting window properties %s of from device %s", + g_strerror (errno), v4lelement->videodev)); + return FALSE; + } + return TRUE; } diff --git a/sys/v4l/v4lsrc_calls.c b/sys/v4l/v4lsrc_calls.c index 577082d..6c01f05 100644 --- a/sys/v4l/v4lsrc_calls.c +++ b/sys/v4l/v4lsrc_calls.c @@ -48,6 +48,11 @@ GST_DEBUG_CATEGORY_EXTERN (v4l_debug); GST_DEBUG_OBJECT (\ GST_ELEMENT(v4lsrc), \ "V4LSRC: " format, ##args) +#define LOG(format, args...) \ + GST_LOG_OBJECT (\ + GST_ELEMENT(v4lsrc), \ + "V4LSRC: " format, ##args) + /* palette names */ static const char *palette_name[] = { @@ -80,7 +85,7 @@ static const char *palette_name[] = { static gboolean gst_v4lsrc_queue_frame (GstV4lSrc * v4lsrc, gint num) { - DEBUG ("queueing frame %d", num); + LOG ("queueing frame %d", num); if (v4lsrc->frame_queue_state[num] != QUEUE_STATE_READY_FOR_QUEUE) { return FALSE; @@ -110,7 +115,7 @@ gst_v4lsrc_queue_frame (GstV4lSrc * v4lsrc, gint num) static gboolean gst_v4lsrc_sync_frame (GstV4lSrc * v4lsrc, gint num) { - DEBUG ("Syncing on frame %d", num); + LOG ("Syncing on frame %d", num); if (v4lsrc->frame_queue_state[num] != QUEUE_STATE_QUEUED) { return FALSE; @@ -271,7 +276,7 @@ gst_v4lsrc_capture_start (GstV4lSrc * v4lsrc) gboolean gst_v4lsrc_grab_frame (GstV4lSrc * v4lsrc, gint * num) { - DEBUG ("grabbing frame"); + LOG ("grabbing frame"); GST_V4L_CHECK_OPEN (GST_V4LELEMENT (v4lsrc)); GST_V4L_CHECK_ACTIVE (GST_V4LELEMENT (v4lsrc)); @@ -306,7 +311,7 @@ gst_v4lsrc_grab_frame (GstV4lSrc * v4lsrc, gint * num) } v4lsrc->sync_frame = (v4lsrc->sync_frame + 1) % v4lsrc->mbuf.frames; - GST_DEBUG ("grabbed frame %d", *num); + GST_LOG ("grabbed frame %d", *num); g_mutex_unlock (v4lsrc->mutex_queue_state); @@ -343,7 +348,7 @@ gst_v4lsrc_get_buffer (GstV4lSrc * v4lsrc, gint num) gboolean gst_v4lsrc_requeue_frame (GstV4lSrc * v4lsrc, gint num) { - DEBUG ("requeueing frame %d", num); + LOG ("requeueing frame %d", num); GST_V4L_CHECK_OPEN (GST_V4LELEMENT (v4lsrc)); GST_V4L_CHECK_ACTIVE (GST_V4LELEMENT (v4lsrc));