The test application and the plgind error messages has been improved.

Original commit message from CVS:
The test application and the plgind error messages has been improved.
This commit is contained in:
Edgard Lima 2006-09-15 19:11:00 +00:00
parent 5b377ab143
commit 346fe9f6cf
8 changed files with 343 additions and 223 deletions

View file

@ -1,3 +1,13 @@
2006-09-15 Edgard Lima <edgard.lima@indt.org.br>
* sys/v4l2/gstv4l2src.c:
* sys/v4l2/gstv4l2src.h:
* sys/v4l2/gstv4l2xoverlay.c:
* sys/v4l2/v4l2_calls.c:
* sys/v4l2/v4l2src_calls.c:
* tests/icles/v4l2src-test.c:
The test application and the plgind error messages has been improved.
2006-09-12 Stefan Kost <ensonic@users.sf.net>
* gst/spectrum/gstspectrum.c: (gst_spectrum_class_init),

2
common

@ -1 +1 @@
Subproject commit d287125f93da692bc25d53b0b7b0e2f90424a212
Subproject commit a8c15b7a2c75fc2bd83850cb17cb05a1ee84ecaf

View file

@ -899,7 +899,6 @@ gst_v4l2src_get_read (GstV4l2Src * v4l2src, GstBuffer ** buf)
do {
*buf = gst_v4l2src_buffer_new (v4l2src, buffersize, NULL, NULL);
GST_BUFFER_OFFSET (*buf) = GST_BUFFER_OFFSET_NONE;
amount =
read (v4l2src->v4l2object->video_fd, GST_BUFFER_DATA (*buf),
@ -910,10 +909,9 @@ gst_v4l2src_get_read (GstV4l2Src * v4l2src, GstBuffer ** buf)
if (errno == EAGAIN || errno == EINTR) {
continue;
} else {
GST_ELEMENT_ERROR (v4l2src, RESOURCE, SYNC, (NULL),
("error read()ing %d bytes on device %s: %d - %s",
buffersize, v4l2src->v4l2object->videodev, errno,
g_strerror (errno)));
GST_ELEMENT_ERROR (v4l2src, RESOURCE, SYNC,
(_("error read()ing %d bytes on device %s"),
buffersize, v4l2src->v4l2object->videodev), GST_ERROR_SYSTEM);
gst_buffer_unref (*buf);
return GST_FLOW_ERROR;
}
@ -974,8 +972,8 @@ gst_v4l2src_create (GstPushSrc * src, GstBuffer ** buf)
GstFlowReturn ret;
if (v4l2src->use_fixed_fps && v4l2src->fps_n == 0) {
GST_ELEMENT_ERROR (v4l2src, RESOURCE, SETTINGS, (NULL),
("could not get frame rate for element, try to set use-fixed-fps property to false"));
GST_ELEMENT_ERROR (v4l2src, RESOURCE, SETTINGS,
(_("could not get frame rate for %s, try to set use-fixed-fps property to false"), v4l2src->v4l2object->videodev), (NULL));
return GST_FLOW_ERROR;
}

View file

@ -99,7 +99,7 @@ struct _GstV4l2Src
/* True if we want to stop */
gboolean quit, is_capturing;
gint offset;
guint64 offset;
/* how are we going to push buffers? */
guint fps_n, fps_d;

View file

@ -99,8 +99,8 @@ gst_v4l2_xoverlay_open (GstV4l2Object * v4l2object)
}
if (fstat (v4l2object->video_fd, &s) < 0) {
GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, NOT_FOUND,
(_("Cannot identify device '%s': %s\n"), v4l2object->videodev,
g_strerror (errno)), GST_ERROR_SYSTEM);
(_("Cannot identify device '%s'"), v4l2object->videodev),
GST_ERROR_SYSTEM);
XCloseDisplay (dpy);
return;
}

View file

@ -58,7 +58,9 @@ gst_v4l2_get_capabilities (GstV4l2Object * v4l2object)
if (ioctl (v4l2object->video_fd, VIDIOC_QUERYCAP, &(v4l2object->vcap)) < 0) {
GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, SETTINGS,
(_("Error getting capabilities for device '%s': %s. It isn't a v4l2 driver. Check if it is a v4l1 driver\n"), v4l2object->videodev, g_strerror (errno)), GST_ERROR_SYSTEM);
(_("Error getting capabilities for device '%s':"
" It isn't a v4l2 driver. Check if it is a v4l1 driver"),
v4l2object->videodev), GST_ERROR_SYSTEM);
return FALSE;
}
@ -100,9 +102,9 @@ gst_v4l2_fill_lists (GstV4l2Object * v4l2object)
if (errno == EINVAL)
break; /* end of enumeration */
else {
GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, SETTINGS, (NULL),
("Failed to get %d in input enumeration for %s: %s",
n, v4l2object->videodev, g_strerror (errno)));
GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, SETTINGS,
("Failed to get %d in input enumeration for %s",
n, v4l2object->videodev), GST_ERROR_SYSTEM);
return FALSE;
}
}
@ -120,9 +122,9 @@ gst_v4l2_fill_lists (GstV4l2Object * v4l2object)
vtun.index = input.tuner;
if (ioctl (v4l2object->video_fd, VIDIOC_G_TUNER, &vtun) < 0) {
GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, SETTINGS, (NULL),
("Failed to get tuner %d settings on %s: %s",
input.tuner, v4l2object->videodev, g_strerror (errno)));
GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, SETTINGS,
("Failed to get tuner %d settings on %s",
input.tuner, v4l2object->videodev), GST_ERROR_SYSTEM);
g_object_unref (G_OBJECT (channel));
return FALSE;
}
@ -158,9 +160,10 @@ gst_v4l2_fill_lists (GstV4l2Object * v4l2object)
if (errno == EINVAL)
break; /* end of enumeration */
else {
GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, SETTINGS, (NULL),
("Failed to get %d in output enumeration for %s: %s",
n, v4l2object->videodev, g_strerror (errno)));
GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, SETTINGS,
("Failed to get %d in output enumeration for %s",
n, v4l2object->videodev)
, GST_ERROR_SYSTEM);
return FALSE;
}
}
@ -196,9 +199,9 @@ gst_v4l2_fill_lists (GstV4l2Object * v4l2object)
if (errno == EINVAL)
break; /* end of enumeration */
else {
GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, SETTINGS, (NULL),
("Failed to get %d in norm enumeration for %s: %s",
n, v4l2object->videodev, g_strerror (errno)));
GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, SETTINGS,
("Failed to get %d in norm enumeration for %s",
n, v4l2object->videodev), GST_ERROR_SYSTEM);
return FALSE;
}
}
@ -222,7 +225,7 @@ gst_v4l2_fill_lists (GstV4l2Object * v4l2object)
/* when we reached the last official CID, continue with private CIDs */
if (n == V4L2_CID_LASTP1) {
GST_DEBUG_OBJECT (v4l2object->element, "chhecking private CIDs");
GST_DEBUG_OBJECT (v4l2object->element, "checking private CIDs");
n = V4L2_CID_PRIVATE_BASE;
}
@ -235,9 +238,9 @@ gst_v4l2_fill_lists (GstV4l2Object * v4l2object)
else
break;
} else {
GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, SETTINGS, (NULL),
("Failed to get %d in control enumeration for %s: %s",
n, v4l2object->videodev, g_strerror (errno)));
GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, SETTINGS,
("Failed to get %d in control enumeration for %s",
n, v4l2object->videodev), GST_ERROR_SYSTEM);
return FALSE;
}
}
@ -276,7 +279,7 @@ gst_v4l2_fill_lists (GstV4l2Object * v4l2object)
channel->label = g_strdup ((const gchar *) control.name);
v4l2channel->id = n;
#if 0
#if 0 /* FIXME: will be be need just when handling private controls */
if (control.type == V4L2_CTRL_TYPE_MENU) {
struct v4l2_querymenu menu, *mptr;
int i;
@ -288,9 +291,9 @@ gst_v4l2_fill_lists (GstV4l2Object * v4l2object)
if (errno == EINVAL)
break; /* end of enumeration */
else {
GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, SETTINGS, (NULL),
("Failed to get %d in menu enumeration for %s: %s",
n, v4l2object->videodev, g_strerror (errno)));
GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, SETTINGS,
("Failed to get %d in menu enumeration for %s",
n, v4l2object->videodev), GST_ERROR_SYSTEM);
return FALSE;
}
}
@ -312,6 +315,7 @@ gst_v4l2_fill_lists (GstV4l2Object * v4l2object)
channel->max_value = TRUE;
break;
default:
/* FIX ME we should find out how to handle V4L2_CTRL_TYPE_BUTTON */
GST_DEBUG_OBJECT (v4l2object->element,
"No range for ControlID %s (%x), type=%d",
control.name, n, control.type);
@ -368,14 +372,14 @@ gst_v4l2_open (GstV4l2Object * v4l2object)
/* check if it is a device */
if (-1 == stat (v4l2object->videodev, &st)) {
GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, NOT_FOUND,
(_("Cannot identify device '%s': %s\n"), v4l2object->videodev,
g_strerror (errno)), GST_ERROR_SYSTEM);
(_("Cannot identify device '%s'"), v4l2object->videodev),
GST_ERROR_SYSTEM);
goto error;
}
if (!S_ISCHR (st.st_mode)) {
GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, NOT_FOUND,
(_("This isn't a device '%s': %s\n"), v4l2object->videodev,
g_strerror (errno)), GST_ERROR_SYSTEM);
(_("This isn't a device '%s'"), v4l2object->videodev),
GST_ERROR_SYSTEM);
goto error;
}
@ -400,8 +404,8 @@ gst_v4l2_open (GstV4l2Object * v4l2object)
!(v4l2object->vcap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) {
GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, NOT_FOUND,
(_("Device \"%s\" is not a capture device."),
v4l2object->videodev), ("Capabilities: 0x%x",
v4l2object->vcap.capabilities));
v4l2object->videodev),
("Capabilities: 0x%x", v4l2object->vcap.capabilities));
goto error;
}
@ -410,8 +414,8 @@ gst_v4l2_open (GstV4l2Object * v4l2object)
goto error;
GST_INFO_OBJECT (v4l2object->element,
"Opened device '%s' (%s) successfully\n", v4l2object->vcap.card,
v4l2object->videodev);
"Opened device '%s' (%s) successfully",
v4l2object->vcap.card, v4l2object->videodev);
return TRUE;
@ -467,9 +471,9 @@ gst_v4l2_get_norm (GstV4l2Object * v4l2object, v4l2_std_id * norm)
return FALSE;
if (ioctl (v4l2object->video_fd, VIDIOC_G_STD, norm) < 0) {
GST_WARNING_OBJECT (v4l2object->element,
"Failed to get the current norm for device %s: %s",
v4l2object->videodev, g_strerror (errno));
GST_ELEMENT_WARNING (v4l2object->element, RESOURCE, SETTINGS,
(_("Failed to get the current norm for device %s"),
v4l2object->videodev), GST_ERROR_SYSTEM);
return FALSE;
}
@ -493,9 +497,9 @@ gst_v4l2_set_norm (GstV4l2Object * v4l2object, v4l2_std_id norm)
return FALSE;
if (ioctl (v4l2object->video_fd, VIDIOC_S_STD, &norm) < 0) {
GST_WARNING_OBJECT (v4l2object->element,
"Failed to set norm 0x%llx for device %s: %s", norm,
v4l2object->videodev, g_strerror (errno));
GST_ELEMENT_WARNING (v4l2object->element, RESOURCE, SETTINGS,
(_("Failed to set norm 0x%llx for device %s: %s"),
norm, v4l2object->videodev), GST_ERROR_SYSTEM);
return FALSE;
}
@ -523,9 +527,9 @@ gst_v4l2_get_frequency (GstV4l2Object * v4l2object,
freq.tuner = tunernum;
if (ioctl (v4l2object->video_fd, VIDIOC_G_FREQUENCY, &freq) < 0) {
GST_WARNING_OBJECT (v4l2object->element,
"Failed to get current tuner frequency for device %s: %s",
v4l2object->videodev, g_strerror (errno));
GST_ELEMENT_WARNING (v4l2object->element, RESOURCE, SETTINGS,
(_("Failed to get current tuner frequency for device %s"),
v4l2object->videodev), GST_ERROR_SYSTEM);
return FALSE;
}
@ -561,9 +565,9 @@ gst_v4l2_set_frequency (GstV4l2Object * v4l2object,
freq.frequency = frequency / channel->freq_multiplicator;
if (ioctl (v4l2object->video_fd, VIDIOC_S_FREQUENCY, &freq) < 0) {
GST_WARNING_OBJECT (v4l2object->element,
"Failed to set current tuner frequency for device %s to %lu: %s",
v4l2object->videodev, frequency, g_strerror (errno));
GST_ELEMENT_WARNING (v4l2object->element, RESOURCE, SETTINGS,
(_("Failed to set current tuner frequency for device %s to %lu"),
v4l2object->videodev, frequency), GST_ERROR_SYSTEM);
return FALSE;
}
@ -589,9 +593,9 @@ gst_v4l2_signal_strength (GstV4l2Object * v4l2object,
tuner.index = tunernum;
if (ioctl (v4l2object->video_fd, VIDIOC_G_TUNER, &tuner) < 0) {
GST_WARNING_OBJECT (v4l2object->element,
"Failed to get signal strength for device %s: %s",
v4l2object->videodev, g_strerror (errno));
GST_ELEMENT_WARNING (v4l2object->element, RESOURCE, SETTINGS,
(_("Failed to get signal strength for device %s"),
v4l2object->videodev), GST_ERROR_SYSTEM);
return FALSE;
}
@ -622,9 +626,9 @@ gst_v4l2_get_attribute (GstV4l2Object * v4l2object,
control.id = attribute_num;
if (ioctl (v4l2object->video_fd, VIDIOC_G_CTRL, &control) < 0) {
GST_WARNING_OBJECT (v4l2object->element,
"Failed to get value for control %d on device %s: %s",
attribute_num, v4l2object->videodev, g_strerror (errno));
GST_ELEMENT_WARNING (v4l2object->element, RESOURCE, SETTINGS,
(_("Failed to get value for control %d on device %s"),
attribute_num, v4l2object->videodev), GST_ERROR_SYSTEM);
return FALSE;
}
@ -656,9 +660,9 @@ gst_v4l2_set_attribute (GstV4l2Object * v4l2object,
control.value = value;
if (ioctl (v4l2object->video_fd, VIDIOC_S_CTRL, &control) < 0) {
GST_WARNING_OBJECT (v4l2object->element,
"Failed to set value %d for control %d on device %s: %s",
value, attribute_num, v4l2object->videodev, g_strerror (errno));
GST_ELEMENT_WARNING (v4l2object->element, RESOURCE, SETTINGS,
(_("Failed to set value %d for control %d on device %s"),
value, attribute_num, v4l2object->videodev), GST_ERROR_SYSTEM);
return FALSE;
}
@ -675,9 +679,9 @@ gst_v4l2_get_input (GstV4l2Object * v4l2object, gint * input)
return FALSE;
if (ioctl (v4l2object->video_fd, VIDIOC_G_INPUT, &n) < 0) {
GST_WARNING_OBJECT (v4l2object->element,
"Failed to get current input on device %s: %s",
v4l2object->videodev, g_strerror (errno));
GST_ELEMENT_WARNING (v4l2object->element, RESOURCE, SETTINGS,
(_("Failed to get current input on device %s"),
v4l2object->videodev), GST_ERROR_SYSTEM);
return FALSE;
}
@ -694,9 +698,9 @@ gst_v4l2_set_input (GstV4l2Object * v4l2object, gint input)
return FALSE;
if (ioctl (v4l2object->video_fd, VIDIOC_S_INPUT, &input) < 0) {
GST_WARNING_OBJECT (v4l2object->element,
"Failed to set input %d on device %s: %s", input, v4l2object->videodev,
g_strerror (errno));
GST_ELEMENT_WARNING (v4l2object->element, RESOURCE, SETTINGS,
(_("Failed to set input %d on device %s"),
input, v4l2object->videodev), GST_ERROR_SYSTEM);
return FALSE;
}
@ -704,7 +708,7 @@ gst_v4l2_set_input (GstV4l2Object * v4l2object, gint input)
}
#if 0 /* output not handled by now */
#if 0 /* output not handled by now, Indeed it will be another element */
gboolean
gst_v4l2_get_output (GstV4l2Object * v4l2object, gint * output)
@ -716,9 +720,9 @@ gst_v4l2_get_output (GstV4l2Object * v4l2object, gint * output)
return FALSE;
if (ioctl (v4l2object->video_fd, VIDIOC_G_OUTPUT, &n) < 0) {
GST_WARNING_OBJECT (v4l2object->element,
"Failed to get current output on device %s: %s",
v4l2object->videodev, g_strerror (errno));
GST_ELEMENT_WARNING (v4l2object->element, RESOURCE, SETTINGS,
(_("Failed to get current output on device %s"),
v4l2object->videodev), GST_ERROR_SYSTEM);
return FALSE;
}
@ -737,13 +741,13 @@ gst_v4l2_set_output (GstV4l2Object * v4l2object, gint output)
return FALSE;
if (ioctl (v4l2object->video_fd, VIDIOC_S_OUTPUT, &output) < 0) {
GST_WARNING_OBJECT (v4l2object->element,
"Failed to set current output on device %s to %d: %s",
v4l2object->videodev, output, g_strerror (errno));
GST_ELEMENT_WARNING (v4l2object->element, RESOURCE, SETTINGS,
(_("Failed to set current output on device %s to %d"),
v4l2object->videodev, output), GST_ERROR_SYSTEM);
return FALSE;
}
return TRUE;
}
#endif /* #if 0 - output not handled by now */
#endif /* #if 0 - output not handled by now , Indeed it will be another element */

View file

@ -80,9 +80,9 @@ gst_v4l2src_fill_format_list (GstV4l2Src * v4l2src)
if (errno == EINVAL) {
break; /* end of enumeration */
} else {
GST_ELEMENT_ERROR (v4l2src, RESOURCE, SETTINGS, (NULL),
("failed to get number %d in pixelformat enumeration for %s: %s",
n, v4l2src->v4l2object->videodev, g_strerror (errno)));
GST_ELEMENT_ERROR (v4l2src, RESOURCE, SETTINGS,
(_("failed to get number %d in pixelformat enumeration for %s: %s"),
n, v4l2src->v4l2object->videodev), GST_ERROR_SYSTEM);
g_free (format);
return FALSE;
}
@ -129,7 +129,8 @@ gst_v4l2src_queue_frame (GstV4l2Src * v4l2src, guint i)
GST_ELEMENT_ERROR (v4l2src, RESOURCE, WRITE,
(_("Could not write to device '%s'."),
v4l2src->v4l2object->videodev),
("Error queueing buffer %u on device %s", i, g_strerror (errno)));
("Error queueing buffer %u on device %s. system error: %s", i,
v4l2src->v4l2object->videodev, g_strerror (errno)));
return FALSE;
}
@ -156,39 +157,40 @@ gst_v4l2src_grab_frame (GstV4l2Src * v4l2src)
/* if the sync() got interrupted, we can retry */
switch (errno) {
case EAGAIN:
GST_ELEMENT_ERROR (v4l2src, RESOURCE, SYNC, (NULL),
("Non-blocking I/O has been selected using O_NONBLOCK and"
" no buffer was in the outgoing queue. device %s: %s",
v4l2src->v4l2object->videodev, g_strerror (errno)));
GST_DEBUG_OBJECT (v4l2src,
"Non-blocking I/O has been selected using O_NONBLOCK and"
" no buffer was in the outgoing queue. device %s",
v4l2src->v4l2object->videodev);
break;
case EINVAL:
GST_ELEMENT_ERROR (v4l2src, RESOURCE, SYNC, (NULL),
("The buffer type is not supported, or the index is out of bounds,"
" or no buffers have been allocated yet, or the userptr"
" or length are invalid. device %s: %s",
v4l2src->v4l2object->videodev, g_strerror (errno)));
GST_ELEMENT_ERROR (v4l2src, RESOURCE, FAILED,
(_("Failed trying to get frames from device %s"),
v4l2src->v4l2object->videodev),
(_("The buffer type is not supported, or the index is out of bounds," " or no buffers have been allocated yet, or the userptr" " or length are invalid. device %s"), v4l2src->v4l2object->videodev));
break;
case ENOMEM:
GST_ELEMENT_ERROR (v4l2src, RESOURCE, SYNC, (NULL),
("isufficient memory to enqueue a user pointer buffer. device %s: %s",
v4l2src->v4l2object->videodev, g_strerror (errno)));
GST_ELEMENT_ERROR (v4l2src, RESOURCE, FAILED,
(_("Failed trying to get frames from device %s. Not enough memory"),
v4l2src->v4l2object->videodev),
(_("isufficient memory to enqueue a user pointer buffer. device %s"), v4l2src->v4l2object->videodev));
break;
case EIO:
GST_WARNING_OBJECT (v4l2src,
GST_DEBUG_OBJECT (v4l2src,
"VIDIOC_DQBUF failed due to an internal error."
" Can also indicate temporary problems like signal loss."
" Note the driver might dequeue an (empty) buffer despite"
" returning an error, or even stop capturing."
" device %s: %s",
v4l2src->v4l2object->videodev, g_strerror (errno));
" device %s", v4l2src->v4l2object->videodev);
break;
case EINTR:
GST_ELEMENT_ERROR (v4l2src, RESOURCE, SYNC, (NULL),
("could not sync on a buffer on device %s: %s",
v4l2src->v4l2object->videodev, g_strerror (errno)));
GST_DEBUG_OBJECT (v4l2src,
"could not sync on a buffer on device %s",
v4l2src->v4l2object->videodev);
break;
default:
GST_DEBUG_OBJECT (v4l2src, "grab got interrupted");
GST_ELEMENT_WARNING (v4l2src, RESOURCE, FAILED,
(_("Grabbing frame got interrupted on %s. No expected reason"),
v4l2src->v4l2object->videodev), GST_ERROR_SYSTEM);
break;
}
@ -225,9 +227,9 @@ gst_v4l2src_get_capture (GstV4l2Src * v4l2src)
memset (&v4l2src->format, 0, sizeof (struct v4l2_format));
v4l2src->format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
if (ioctl (v4l2src->v4l2object->video_fd, VIDIOC_G_FMT, &v4l2src->format) < 0) {
GST_ELEMENT_ERROR (v4l2src, RESOURCE, SETTINGS, (NULL),
("failed to get pixelformat for device %s: %s",
v4l2src->v4l2object->videodev, g_strerror (errno)));
GST_ELEMENT_ERROR (v4l2src, RESOURCE, SETTINGS,
(_("failed to get pixelformat for device %s"),
v4l2src->v4l2object->videodev), GST_ERROR_SYSTEM);
return FALSE;
}
@ -267,10 +269,10 @@ gst_v4l2src_set_capture (GstV4l2Src * v4l2src,
v4l2src->format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
if (ioctl (v4l2src->v4l2object->video_fd, VIDIOC_S_FMT, &v4l2src->format) < 0) {
GST_ELEMENT_ERROR (v4l2src, RESOURCE, SETTINGS, (NULL),
("failed to set pixelformat to %s @ %dx%d for device %s: %s",
fmt->description, *width, *height,
v4l2src->v4l2object->videodev, g_strerror (errno)));
GST_ELEMENT_ERROR (v4l2src, RESOURCE, SETTINGS,
(_("failed to set pixelformat to %s @ %dx%d for device %s: %s"),
fmt->description, *width, *height, v4l2src->v4l2object->videodev),
GST_ERROR_SYSTEM);
goto fail;
}
@ -287,10 +289,10 @@ gst_v4l2src_set_capture (GstV4l2Src * v4l2src,
}
if (fmt->pixelformat != v4l2src->format.fmt.pix.pixelformat) {
GST_ELEMENT_ERROR (v4l2src, RESOURCE, SETTINGS, (NULL),
("failed to set pixelformat to %s @ %dx%d for device %s: %s",
fmt->description, *width, *height,
v4l2src->v4l2object->videodev, g_strerror (errno)));
GST_ELEMENT_ERROR (v4l2src, RESOURCE, SETTINGS,
(_("failed to set pixelformat to %s @ %dx%d for device %s: %s"),
fmt->description, *width, *height, v4l2src->v4l2object->videodev),
GST_ERROR_SYSTEM);
goto fail;
}
@ -357,7 +359,7 @@ gst_v4l2src_capture_init (GstV4l2Src * v4l2src)
GST_ELEMENT_ERROR (v4l2src, RESOURCE, READ,
(_("Could not get buffers from device '%s'."),
v4l2src->v4l2object->videodev),
("error requesting %d buffers: %s",
("error requesting %d buffers. system error: %s",
v4l2src->breq.count, g_strerror (errno)));
return FALSE;
}
@ -395,7 +397,7 @@ gst_v4l2src_capture_init (GstV4l2Src * v4l2src)
g_object_notify (G_OBJECT (v4l2src), "num_buffers");
GST_INFO_OBJECT (v4l2src,
"Got %d buffers (%" GST_FOURCC_FORMAT ") of size %d KB\n",
"Got %d buffers (%" GST_FOURCC_FORMAT ") of size %d KB",
v4l2src->breq.count,
GST_FOURCC_ARGS (v4l2src->format.fmt.pix.pixelformat),
v4l2src->format.fmt.pix.sizeimage / 1024);
@ -421,9 +423,9 @@ gst_v4l2src_capture_init (GstV4l2Src * v4l2src)
if (ioctl (v4l2src->v4l2object->video_fd, VIDIOC_QUERYBUF,
&buffer->buffer) < 0) {
GST_ELEMENT_ERROR (v4l2src, RESOURCE, READ, (NULL),
("Could not get buffer properties of buffer %d: %s",
n, g_strerror (errno)));
GST_ELEMENT_ERROR (v4l2src, RESOURCE, READ,
(_("Could not get buffer properties of buffer %d"), n),
GST_ERROR_SYSTEM);
gst_v4l2src_capture_deinit (v4l2src);
return FALSE;
}
@ -431,8 +433,8 @@ gst_v4l2src_capture_init (GstV4l2Src * v4l2src)
mmap (0, buffer->buffer.length, PROT_READ | PROT_WRITE, MAP_SHARED,
v4l2src->v4l2object->video_fd, buffer->buffer.m.offset);
if (buffer->start == MAP_FAILED) {
GST_ELEMENT_ERROR (v4l2src, RESOURCE, READ, (NULL),
("Could not mmap video buffer %d: %s", n, g_strerror (errno)));
GST_ELEMENT_ERROR (v4l2src, RESOURCE, READ,
(_("Could not mmap video buffer %d: %s"), n), GST_ERROR_SYSTEM);
buffer->start = 0;
gst_v4l2src_capture_deinit (v4l2src);
return FALSE;
@ -477,9 +479,9 @@ gst_v4l2src_capture_start (GstV4l2Src * v4l2src)
if (v4l2src->breq.memory != 0) {
if (ioctl (v4l2src->v4l2object->video_fd, VIDIOC_STREAMON, &type) < 0) {
GST_ELEMENT_ERROR (v4l2src, RESOURCE, OPEN_READ, (NULL),
("Error starting streaming capture from device %s: %s",
v4l2src->v4l2object->videodev, g_strerror (errno)));
GST_ELEMENT_ERROR (v4l2src, RESOURCE, OPEN_READ,
(_("Error starting streaming capture from device %s"),
v4l2src->v4l2object->videodev), GST_ERROR_SYSTEM);
return FALSE;
}
}
@ -509,9 +511,9 @@ gst_v4l2src_capture_stop (GstV4l2Src * v4l2src)
/* we actually need to sync on all queued buffers but not
* on the non-queued ones */
if (ioctl (v4l2src->v4l2object->video_fd, VIDIOC_STREAMOFF, &type) < 0) {
GST_ELEMENT_ERROR (v4l2src, RESOURCE, CLOSE, (NULL),
("Error stopping streaming capture from device %s: %s",
v4l2src->v4l2object->videodev, g_strerror (errno)));
GST_ELEMENT_ERROR (v4l2src, RESOURCE, CLOSE,
(_("Error stopping streaming capture from device %s: %s"),
v4l2src->v4l2object->videodev), GST_ERROR_SYSTEM);
return FALSE;
}
}
@ -586,9 +588,9 @@ gst_v4l2src_capture_deinit (GstV4l2Src * v4l2src)
if (g_atomic_int_dec_and_test (&v4l2src->pool->buffers[i].refcount)) {
if (ioctl (v4l2src->v4l2object->video_fd, VIDIOC_DQBUF,
&v4l2src->pool->buffers[i].buffer) < 0)
GST_WARNING_OBJECT (v4l2src,
"Could not dequeue buffer on uninitialization: %s - will try reinit instead",
g_strerror (errno));
GST_DEBUG_OBJECT (v4l2src,
"Could not dequeue buffer on uninitialization."
"system error: %s. Will try reinit instead", g_strerror (errno));
try_reinit = TRUE;
}
}
@ -647,8 +649,8 @@ gst_v4l2src_get_size_limits (GstV4l2Src * v4l2src,
*min_w = fmt.fmt.pix.width;
if (min_h)
*min_h = fmt.fmt.pix.height;
GST_LOG_OBJECT (v4l2src, "got min size %dx%d", fmt.fmt.pix.width,
fmt.fmt.pix.height);
GST_LOG_OBJECT (v4l2src,
"got min size %dx%d", fmt.fmt.pix.width, fmt.fmt.pix.height);
fmt.fmt.pix.width = 4096;
fmt.fmt.pix.height = 4096;
@ -660,8 +662,8 @@ gst_v4l2src_get_size_limits (GstV4l2Src * v4l2src,
*max_w = fmt.fmt.pix.width;
if (max_h)
*max_h = fmt.fmt.pix.height;
GST_LOG_OBJECT (v4l2src, "got max size %dx%d", fmt.fmt.pix.width,
fmt.fmt.pix.height);
GST_LOG_OBJECT (v4l2src,
"got max size %dx%d", fmt.fmt.pix.width, fmt.fmt.pix.height);
return TRUE;
}
@ -721,8 +723,8 @@ gst_v4l2src_get_fps (GstV4l2Src * v4l2src, guint * fps_n, guint * fps_d)
/* Note: V4L2 gives us the frame interval, we need the frame rate */
*fps_n = stream.parm.capture.timeperframe.denominator;
*fps_d = stream.parm.capture.timeperframe.numerator;
GST_DEBUG_OBJECT (v4l2src, "frame rate returned by G_PARM: %d/%d fps",
*fps_n, *fps_d);
GST_DEBUG_OBJECT (v4l2src,
"frame rate returned by G_PARM: %d/%d fps", *fps_n, *fps_d);
return TRUE;
}
@ -739,8 +741,8 @@ gst_v4l2src_get_fps (GstV4l2Src * v4l2src, guint * fps_n, guint * fps_d)
*fps_d =
gst_value_get_fraction_denominator (&GST_TUNER_NORM (v4l2norm)->
framerate);
GST_DEBUG_OBJECT (v4l2src, "frame rate returned by get_norm: %d/%d fps",
*fps_n, *fps_d);
GST_DEBUG_OBJECT (v4l2src,
"frame rate returned by get_norm: %d/%d fps", *fps_n, *fps_d);
return TRUE;
}
}
@ -748,70 +750,6 @@ gst_v4l2src_get_fps (GstV4l2Src * v4l2src, guint * fps_n, guint * fps_d)
}
#if 0
/* get a list of possible framerates
* this is only done for webcams;
* other devices return NULL here.
* this function takes a LONG time to execute.
*/
GValue *
gst_v4l2src_get_fps_list (GstV4l2Src * v4l2src)
{
gint fps_index;
struct video_window *vwin = &v4l2src->v4l2object->vwin;
GstV4l2Object *v4l2object = v4l2src->v4l2object;
/* 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 */
/* webcams have a non-zero fps_index */
if (fps_index == 0) {
GST_DEBUG_OBJECT (v4l2src, "fps_index is 0, no webcam");
return NULL;
}
GST_DEBUG_OBJECT (v4l2src, "fps_index is %d, so webcam", fps_index);
{
int i;
GValue *list = NULL;
GValue value = { 0 };
/* webcam detected, so try all framerates and return a list */
list = g_new0 (GValue, 1);
g_value_init (list, GST_TYPE_LIST);
/* index of 16 corresponds to 15 fps */
GST_DEBUG_OBJECT (v4l2src, "device reports fps of %d/%d (%.4f)",
fps_index * 15, 16, fps_index * 15.0 / 16);
for (i = 0; i < 63; ++i) {
/* set bits 16 to 21 to 0 */
vwin->flags &= (0x3F00 - 1);
/* set bits 16 to 21 to the index */
vwin->flags |= i << 16;
if (gst_v4l2_set_window_properties (v4l2object)) {
/* setting it succeeded. FIXME: get it and check. */
g_value_init (&value, GST_TYPE_FRACTION);
gst_value_set_fraction (&value, i * 15, 16);
gst_value_list_append_value (list, &value);
g_value_unset (&value);
}
}
/* FIXME: set back the original fps_index */
vwin->flags &= (0x3F00 - 1);
vwin->flags |= fps_index << 16;
gst_v4l2_set_window_properties (v4l2object);
return list;
}
return NULL;
}
#endif
#define GST_TYPE_V4L2SRC_BUFFER (gst_v4l2src_buffer_get_type())
#define GST_IS_V4L2SRC_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_V4L2SRC_BUFFER))
#define GST_V4L2SRC_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_V4L2SRC_BUFFER, GstV4l2SrcBuffer))
@ -904,8 +842,8 @@ gst_v4l2src_buffer_new (GstV4l2Src * v4l2src, guint size, guint8 * data,
buf = (GstBuffer *) gst_mini_object_new (GST_TYPE_V4L2SRC_BUFFER);
GST_BUFFER_DATA (buf) = data;
GST_V4L2SRC_BUFFER (buf)->buf = srcbuf;
GST_LOG_OBJECT (v4l2src, "creating buffer %p (nr. %d)",
srcbuf, srcbuf->buffer.index);
GST_LOG_OBJECT (v4l2src,
"creating buffer %p (nr. %d)", srcbuf, srcbuf->buffer.index);
}
@ -915,6 +853,7 @@ gst_v4l2src_buffer_new (GstV4l2Src * v4l2src, guint size, guint8 * data,
GST_BUFFER_TIMESTAMP (buf) =
gst_clock_get_time (GST_ELEMENT (v4l2src)->clock);
GST_BUFFER_TIMESTAMP (buf) -= GST_ELEMENT (v4l2src)->base_time;
GST_BUFFER_OFFSET (buf) = v4l2src->offset++;
GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_READONLY);
if (v4l2src->fps_n > 0) {

View file

@ -1,3 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <gst/gst.h>
#include <gst/interfaces/tuner.h>
@ -10,10 +13,9 @@ volatile int exit_read = 0;
void
print_options ()
{
printf
("\nLaunch \"./v4l2src-test.c devname\" to choose the device (default: /dev/video0)\n");
printf ("\nf - to change the fequency\n");
printf ("i - to change the input\n");
printf ("n - to change the norm\n");
printf ("c - list color balance\n");
printf ("e - to exit\n");
}
@ -25,16 +27,58 @@ run_options (char opt)
case 'f':
{
GstTuner *tuner = GST_TUNER (source);
GstTunerChannel *channel = gst_tuner_get_channel (tuner);
GstTunerChannel *channel;
guint freq;
printf ("type the new frequency (current = %lu) (-1 to cancel): ",
gst_tuner_get_frequency (tuner, channel));
channel = gst_tuner_get_channel (tuner);
freq = gst_tuner_get_frequency (tuner, channel);
printf ("type the new frequency (current = %lu) (-1 to cancel): ", freq);
scanf ("%u", &freq);
if (freq != -1)
gst_tuner_set_frequency (tuner, channel, freq);
}
break;
case 'n':
{
GstTuner *tuner = GST_TUNER (source);
const GList *item, *list;
const GstTunerNorm *current_norm;
GstTunerNorm *norm = NULL;
gint index, next_norm;
list = gst_tuner_list_norms (tuner);
current_norm = gst_tuner_get_norm (tuner);
printf ("\nlist of norms:\n");
for (item = list, index = 0; item != NULL; item = item->next, ++index) {
norm = item->data;
if (current_norm == norm) {
printf (" * %u - %s\n", index, norm->label);
} else {
printf (" %u - %s\n", index, norm->label);
}
}
printf ("\ntype the number of norm you want (-1 to cancel): ");
scanf ("%d", &next_norm);
if (next_norm < 0) {
break;
}
if (index <= next_norm) {
printf ("Norm %d not available\n", next_norm);
break;
}
for (item = list, index = 0; item != NULL && index <= next_norm;
item = item->next, ++index) {
norm = item->data;
}
if (norm)
gst_tuner_set_norm (tuner, norm);
}
break;
case 'i':
{
GstTuner *tuner = GST_TUNER (source);
@ -43,7 +87,9 @@ run_options (char opt)
GstTunerChannel *channel = NULL;
gint index, next_channel;
list = gst_tuner_list_channels (tuner);
current_channel = gst_tuner_get_channel (tuner);
printf ("\nlist of inputs:\n");
@ -57,7 +103,11 @@ run_options (char opt)
}
printf ("\ntype the number of input you want (-1 to cancel): ");
scanf ("%d", &next_channel);
if (next_channel < 0 || index <= next_channel) {
if (next_channel < 0) {
break;
}
if (index <= next_channel) {
printf ("Input %d not available\n", next_channel);
break;
}
for (item = list, index = 0; item != NULL && index <= next_channel;
@ -77,11 +127,18 @@ run_options (char opt)
case 'c':
{
GstColorBalance *balance = GST_COLOR_BALANCE (source);
const GList *controls = gst_color_balance_list_channels (balance);
const GList *controls;
GstColorBalanceChannel *channel;
const GList *item;
gint index, new_value;
controls = gst_color_balance_list_channels (balance);
if (controls == NULL) {
printf ("There is no list of colorbalance controls\n");
goto done;
}
if (controls) {
printf ("\nlist of controls:\n");
for (item = controls, index = 0; item != NULL;
@ -99,7 +156,7 @@ run_options (char opt)
item = item->next, ++index) {
channel = item->data;
}
printf (" %u - %s (%d - %d) = %d, type the new value: ", index,
printf (" %u - %s (%d - %d) = %d, type the new value: ", index - 1,
channel->label, channel->min_value, channel->max_value,
gst_color_balance_get_value (balance, channel));
scanf ("%d", &new_value);
@ -115,6 +172,10 @@ run_options (char opt)
break;
}
done:
return;
}
gpointer
@ -127,10 +188,12 @@ read_user (gpointer data)
print_options ();
opt = getchar ();
if (exit_read) {
break;
}
do {
opt = getchar ();
if (exit_read) {
break;
}
} while (opt == '\n');
run_options (opt);
@ -150,12 +213,14 @@ my_bus_callback (GstBus * bus, GstMessage * message, gpointer data)
gchar *debug;
gst_message_parse_error (message, &err, &debug);
g_print ("Error: %s - element %s\n", err->message,
gst_element_get_name (message->src));
g_print ("%s error: %s\n",
gst_element_get_name (message->src), err->message);
g_print ("Debug: %s\n", debug);
g_error_free (err);
g_free (debug);
printf ("presse any key to exit\n");
printf ("presse <ENTER> key to exit\n");
exit_read = 1;
g_main_loop_quit (loop);
break;
@ -177,6 +242,105 @@ main (int argc, char *argv[])
{
GThread *input_thread;
gint numbuffers = -1;
gchar device[128] = { '\0' };
gchar input[128] = { '\0' };
gulong frequency = 0;
gboolean nofixedfps = TRUE;
/* see for input option */
int c;
while (1) {
static char long_options_desc[][64] = {
{"Number of buffers to output before sending EOS"},
{"Device location. Common in /dev/video0"},
{"input/output (channel) to switch to"},
{"frequency to tune to (in Hz)"},
{"set use-fixed-fps to FALSE"},
{0, 0, 0, 0}
};
static struct option long_options[] = {
{"numbuffers", 1, 0, 'n'},
{"device", 1, 0, 'd'},
{"input", 1, 0, 'i'},
{"frequency", 1, 0, 'f'},
{"nofixedfps", 0, 0, 's'},
{0, 0, 0, 0}
};
/* getopt_long stores the option index here. */
int option_index = 0;
c = getopt_long (argc, argv, "n:d:i:f:sh:", long_options, &option_index);
/* Detect the end of the options. */
if (c == -1) {
printf ("tip: use -h to see help message.\n");
break;
}
switch (c) {
case 0:
/* If this option set a flag, do nothing else now. */
if (long_options[option_index].flag != 0)
break;
printf ("option %s", long_options[option_index].name);
if (optarg)
printf (" with arg %s", optarg);
printf ("\n");
break;
case 'n':
numbuffers = atoi (optarg);
break;
case 'd':
strncpy (device, optarg, sizeof (device) / sizeof (device[0]));
break;
case 'i':
strncpy (input, optarg, sizeof (input) / sizeof (input[0]));
break;
case 'f':
frequency = atol (optarg);
break;
case 's':
nofixedfps = FALSE;
break;
case 'h':
printf ("Usage: v4l2src-test [OPTION]...\n");
for (c = 0; long_options[c].name; ++c) {
printf ("-%c, --%s\r\t\t\t\t%s\n", long_options[c].val,
long_options[c].name, long_options_desc[c]);
}
exit (0);
break;
case '?':
/* getopt_long already printed an error message. */
printf ("Use -h to see help message.\n");
break;
default:
abort ();
}
}
/* Print any remaining command line arguments (not options). */
if (optind < argc) {
printf ("Use -h to see help message.\n" "non-option ARGV-elements: ");
while (optind < argc)
printf ("%s ", argv[optind++]);
putchar ('\n');
}
/* init */
gst_init (&argc, &argv);
@ -199,10 +363,20 @@ main (int argc, char *argv[])
return -1;
}
if (argc < 2) {
g_object_set (source, "device", "/dev/video0", NULL);
} else {
g_object_set (source, "device", argv[1], NULL);
if (numbuffers > -1) {
g_object_set (source, "num-buffers", numbuffers, NULL);
}
if (device[0]) {
g_object_set (source, "device", device, NULL);
}
if (input[0]) {
g_object_set (source, "input", input, NULL);
}
if (frequency) {
g_object_set (source, "frequency", frequency, NULL);
}
if (!nofixedfps) {
g_object_set (source, "use-fixed-fps", nofixedfps, NULL);
}
/* you would normally check that the elements were created properly */
@ -222,11 +396,6 @@ main (int argc, char *argv[])
return -1;
}
if (argc < 2)
printf
("\nOpening /dev/video0. Launch ./v4l2src-test.c devname to try another one\n");
g_main_loop_run (loop);
g_thread_join (input_thread);