Camerabin - how to specify size of image for capture
Ian Davidson
id012c3076 at blueyonder.co.uk
Sun Feb 16 06:34:06 PST 2014
I have upgraded my computer to use Fedora 20 and have the 1.2.3 version
of gstreamer installed. My program (below) still crashes with a 'not
negotiated' if I try to specify the image size.
Would the fixes that were pushed to git on 30th January have made it
into release 1.2.3?
Ian
/* JustTheCamera.c */
#include <gtk/gtk.h>
#include <gst/gst.h>
#include <glib.h>
GtkWidget *startsnapbutton;
GtkWidget *snapbutton;
GtkWidget *stopsnapbutton;
static GstElement *camPipeline;
GstElement *cambin;
GstBus *cambus;
GMainLoop *camloop;
guint cam_bus_watch_id;
static gboolean
bus_call (GstBus *bus,
GstMessage *msg,
gpointer data)
{
GMainLoop *loop = (GMainLoop *) data;
switch (GST_MESSAGE_TYPE (msg)) {
case GST_MESSAGE_EOS:
g_print ("End of stream\n");
g_main_loop_quit (loop);
break;
case GST_MESSAGE_ERROR: {
gchar *debug;
GError *error;
gst_message_parse_error (msg, &error, &debug);
g_free (debug);
g_printerr ("Error: %s\n", error->message);
g_error_free (error);
g_main_loop_quit (loop);
break;
}
case GST_MESSAGE_APPLICATION:{
const GstStructure *s;
s = gst_message_get_structure (msg);
if (gst_structure_has_name (s, "GstLaunchInterrupt")) {
/* this application message is posted when we caught an interrupt and
* we need to stop the pipeline. */
g_print ("Interrupt: Stopping pipeline ...\n");
/* gst_element_send_event (camPipeline, gst_event_new_eos ()); */
gst_element_set_state (camPipeline, GST_STATE_NULL);
g_main_loop_quit (loop);
}
break;
}
/* case GST_MESSAGE_STATE_CHANGED: {
GstState old_state, new_state;
gst_message_parse_state_changed (msg, &old_state, &new_state, NULL);
g_print ("Element %s changed state from %s to %s.\n",
GST_OBJECT_NAME (msg->src),
gst_element_state_get_name (old_state),
gst_element_state_get_name (new_state));
break;
} */
default:
break;
}
return TRUE;
}
gint delete_event( GtkWidget *widget,
GdkEvent *event,
gpointer data )
{
g_print ("Delete_Event called\n");
return(FALSE);
}
/* Start the Camera - Set up camerabin. */
void snapButtonPressed( GtkWidget *widget,
gpointer data )
{
GstCaps *caps;
gtk_widget_set_sensitive(startsnapbutton, FALSE);
gtk_widget_set_sensitive(snapbutton, TRUE);
gtk_widget_set_sensitive(stopsnapbutton, TRUE);
camPipeline = gst_pipeline_new ("camera");
cambin = gst_element_factory_make ("camerabin", "cambin1");
camloop = g_main_loop_new (NULL, FALSE);
if (!camPipeline || !cambin ) {
g_printerr ("One element could not be created. Exiting.\n");
return;
}
/* Set up the pipeline */
g_print ("Watch for the bus\n");
cambus = gst_pipeline_get_bus (GST_PIPELINE (camPipeline));
cam_bus_watch_id = gst_bus_add_watch (cambus, bus_call, camloop);
g_print ("Set the picture size\n");
caps = gst_caps_from_string("video/x-raw, width=(int)800, height=(int)600");
g_object_set (G_OBJECT (cambin), "image-capture-caps", caps, NULL);
gst_caps_unref (caps); /* This unref seems to cause problems and may need to be commented out */
g_print ("Add the element to the pipeline\n");
gst_bin_add_many (GST_BIN (camPipeline), cambin, NULL);
gst_element_set_state (camPipeline, GST_STATE_PLAYING);
/* Iterate */
g_main_loop_run (camloop);
/* Out of the main loop, clean up nicely */
g_print ("Returned, Camera Off\n");
gst_element_set_state (camPipeline, GST_STATE_NULL);
gst_object_unref (GST_OBJECT (camPipeline));
g_source_remove (cam_bus_watch_id);
g_main_loop_unref (camloop);
gtk_main_quit();
return;
}
void snapNow( GtkWidget *widget,
gpointer data )
{
guint lbIdle;
g_print ("Take a picture\n");
g_object_get(cambin, "idle", &lbIdle, NULL);
if (lbIdle) {
g_print("Camera is Idle\n");
} else {
g_print("Camera is Busy\n");
}
g_signal_emit_by_name (cambin, "start-capture", NULL);
}
void snapOff( GtkWidget *widget,
gpointer data )
{
g_print ("We want to stop\n");
gst_element_post_message (GST_ELEMENT (camPipeline),
gst_message_new_application (GST_OBJECT (camPipeline),
gst_structure_new ("GstLaunchInterrupt",
"message", G_TYPE_STRING, "Pipeline interrupted", NULL)));
}
int main( int argc,
char *argv[] )
{
/* GtkWidget is the storage type for widgets */
GtkWidget *window;
GtkWidget *grid;
/* This is called in all GTK applications. Arguments are parsed
* from the command line and are returned to the application. */
gtk_init (&argc, &argv);
gst_init (&argc, &argv);
/* Create a new window */
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "Camera");
/* Here we just set a handler for delete_event that immediately
* exits GTK. */
g_signal_connect (window, "destroy",
G_CALLBACK (delete_event), NULL);
/* Sets the border width of the window. */
gtk_container_set_border_width (GTK_CONTAINER (window), 10);
/* Use a grid for the buttons */
grid = gtk_grid_new();
/* Put the grid into the main window. */
gtk_container_add (GTK_CONTAINER (window), grid);
/* Snapshot Buttons. */
startsnapbutton = gtk_button_new_with_label ("Start Camera");
g_signal_connect (startsnapbutton, "clicked",
G_CALLBACK (snapButtonPressed), "Snapshot");
gtk_grid_attach(GTK_GRID(grid), startsnapbutton, 0, 1, 1, 1);
gtk_widget_show(startsnapbutton);
snapbutton = gtk_button_new_with_label ("Take Snap");
g_signal_connect (snapbutton, "clicked",
G_CALLBACK (snapNow), "Snapshot");
gtk_grid_attach(GTK_GRID(grid), snapbutton, 0, 2, 1, 1);
gtk_widget_show(snapbutton);
gtk_widget_set_sensitive(snapbutton, FALSE);
stopsnapbutton = gtk_button_new_with_label ("Stop Camera");
g_signal_connect (stopsnapbutton, "clicked",
G_CALLBACK (snapOff), "Snapshot");
gtk_grid_attach(GTK_GRID(grid), stopsnapbutton, 0, 3, 1, 1);
gtk_widget_show(stopsnapbutton);
gtk_widget_set_sensitive(stopsnapbutton, FALSE);
gtk_widget_show(grid);
gtk_widget_show (window);
/* Rest in gtk_main and wait for the fun to begin! */
gtk_main ();
return(0);
}
/* JustTheCamera-end */
trace.txt
Watch for the bus
Set the picture size
Add the element to the pipeline
Returned, Camera Off
33m 2444[00m 0x92ec060 [32;01mFIXME [00m [00;04m default gstutils.c:3648:gst_pad_create_stream_id_printf_valist:<preview-appsrc:src>[00m Creating random stream-id, consider implementing a deterministic way of creating a stream-id
0:00:04.719934133 [333m 2444[00m 0x92ebf80 [33;01mWARN [00m [00;01;31;41m GST_PADS gstpad.c:3669:gst_pad_peer_query:<src-capsfilter:src>[00m could not send sticky events
0:00:04.999635762 [333m 2444[00m 0x92ebf80 [33;01mWARN [00m [00m basetransform gstbasetransform.c:1373:gst_base_transform_setcaps:<src-videoconvert>[00m transform could not transform video/x-raw, format=(string)I420, width=(int)352, height=(int)292, pixel-aspect-ratio=(fraction)1/1, interlace-mode=(string)progressive, framerate=(fraction)100/1 in anything we support
0:00:05.000725976 [333m 2444[00m 0x92ebf80 [33;01mWARN [00m [00m basetransform gstbasetransform.c:2115:gst_base_transform_handle_buffer:<src-videoconvert>[00m warning: not negotiated
0:00:05.000787104 [333m 2444[00m 0x92ebf80 [33;01mWARN [00m [00m basetransform gstbasetransform.c:2115:gst_base_transform_handle_buffer:<src-videoconvert>[00m warning: not negotiated
0:00:05.001194337 [333m 2444[00m 0x92ebf80 [33;01mWARN [00m [00m bufferpool gstbufferpool.c:632:gst_buffer_pool_set_config:<v4l2bufferpool0>[00m can't change config, we are active
0:00:05.001261875 [333m 2444[00m 0x92ebf80 [33;01mWARN [00m [00m bufferpool gstbufferpool.c:632:gst_buffer_pool_set_config:<v4l2bufferpool0>[00m can't change config, we are active
0:00:05.117358001 [333m 2444[00m 0x92ebf80 [33;01mWARN [00m [00m basetransform gstbasetransform.c:1373:gst_base_transform_setcaps:<src-capsfilter>[00m transform could not transform video/x-raw, format=(string)I420, width=(int)352, height=(int)292, pixel-aspect-ratio=(fraction)1/1, interlace-mode=(string)progressive, framerate=(fraction)100/1 in anything we support
0:00:05.117696734 [333m 2444[00m 0x92ebf80 [33;01mWARN [00m [00m basetransform gstbasetransform.c:2115:gst_base_transform_handle_buffer:<src-capsfilter>[00m warning: not negotiated
0:00:05.117730388 [333m 2444[00m 0x92ebf80 [33;01mWARN [00m [00m basetransform gstbasetransform.c:2115:gst_base_transform_handle_buffer:<src-capsfilter>[00m warning: not negotiated
0:00:05.118095014 [333m 2444[00m 0x92ebf80 [33;01mWARN [00m [00m basesrc gstbasesrc.c:2865:gst_base_src_loop:<camerasrc-real-src-actual-src-v4l>[00m error: Internal data flow error.
0:00:05.118136171 [333m 2444[00m 0x92ebf80 [33;01mWARN [00m [00m basesrc gstbasesrc.c:2865:gst_base_src_loop:<camerasrc-real-src-actual-src-v4l>[00m error: streaming task paused, reason not-negotiated (-4)
Error: Internal data flow error.
On 31/01/2014 14:51, Thiago Santos wrote:
> On 01/31/2014 05:15 AM, Ian Davidson wrote:
>> To clarify - I have not used the git master before and I don't know
>> the process.
>
> You will need to clone and build the gstreamer modules. Check the
> developer instructions at http://gstreamer.freedesktop.org/dev/
>
> and use git to clone the modules you need, I'd recommend using a
> gst-uninstalled setup so that you don't have to install the binaries
> to your system. You can find instructions about it at the 'scripts'
> dir on the core gstreamer module or at
> http://cgit.freedesktop.org/gstreamer/gstreamer/tree/scripts, look for
> gst-uninstalled and create-uninstalled-setup.sh
>
> Then you just need to build the modules from the uninstalled setup.
> Build by running './autogen.sh' from the module, remember to check the
> final output listing the plugins that are enabled and the ones that
> aren't. If a plugin you need/want is disabled, check if its build
> dependencies are installed on your system and run autogen.sh again.
> Then just run make and it should build.
>
> If you have a sample application/script that shows the problem, you
> can send it to the list for other devels to look if it is correctly
> using camerabin.
>
> --
> Thiago
>
>>
>> On 30/01/2014 21:59, Ian Davidson wrote:
>>> OK. What do I have to download from which website?
>>>
>>> Ian
>>>
>>>> Some fixes have been pushed to gstreamer core and -base that are
>>>> related to camerabin issues (yesterday and today). Can you give it
>>>> a try with latest git gstreamer?
>>>>
>>>> If it still doesn't work for you, can you provide a small sample
>>>> application to reproduce the issue in a bug filled at
>>>> https://bugzilla.gnome.org/enter_bug.cgi?product=GStreamer
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/gstreamer-devel/attachments/20140216/ca970e02/attachment-0001.html>
More information about the gstreamer-devel
mailing list