V4L2 webcam and dfbvideosink

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

V4L2 webcam and dfbvideosink

StyveA
Hi,

I'm actually trying to render a webcam video output through the framebuffer via dfbvideosink..

I've tried it on X11 before and it works fine with the command bellow :
gst-launch v4l2src device=/dev/video0 ! xvimagesink

then I've tried to change xvimagesink by dfbvideosink (with a program code and not a command to create the directfb surface).. But it does'nt work...

I've some error like :
gstV4l2src has no property named video-sink

My Webcam is a Philips SPC1330NC.

Here is the code if anyone could help me :

#include <directfb.h>
#include <stdio.h>
#include <gst/gst.h>
#include <glib.h>

static IDirectFB *dfb = NULL;
static IDirectFBSurface *primary = NULL;
static GMainLoop *loop;
static GstElement *play;
#define DFBCHECK(x...)                                         \
  {                                                            \
    DFBResult err = x;                                         \
                                                               \
    if (err != DFB_OK)                                         \
      {                                                        \
        fprintf( stderr, "%s <%d>:\n\t", __FILE__, __LINE__ ); \
        DirectFBErrorFatal( #x, err );                         \
      }                                                        \
  }


static gboolean
get_me_out (gpointer data) 
{
  g_main_loop_quit (loop);
  return FALSE;
}


static gboolean
my_bus_callback (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;
     }
   default:
   break;
   }
return TRUE;
}


static IDirectFBEventBuffer *buffer = NULL;
int
main (int argc, char *argv[])
{
  DFBSurfaceDescription dsc;
  GstElement *video;
  GstBus *bus;
   int quitter = 0;
   int i;
  /* Init both GStreamer and DirectFB */
  DFBCHECK (DirectFBInit (&argc, &argv));
  gst_init (&argc, &argv);

  /* Creates DirectFB main context and set it to fullscreen layout */
  DFBCHECK (DirectFBCreate (&dfb));
  DFBCHECK (dfb->SetCooperativeLevel (dfb, DFSCL_FULLSCREEN));

  /* We want a double buffered primary surface */
  dsc.flags = DSDESC_CAPS;
  dsc.caps = DSCAPS_PRIMARY | DSCAPS_FLIPPING;

  DFBCHECK (dfb->CreateSurface (dfb, &dsc, &primary));
  DFBCHECK (primary->SetColor (primary,0x00, 0x00, 0x00,0x00));

  /* Creating our pipeline : videotestsrc ! dfbvideosink */
   play = gst_element_factory_make ("v4l2src", "play");
   video = gst_element_factory_make ("dfbvideosink", "video");

  /* That's the interesting part, giving the primary surface to dfbvideosink */
   g_object_set (video, "surface", primary, NULL);
   g_object_set (G_OBJECT (play), "device","/dev/video0" , NULL); // 3 = argv[1]
   g_object_set (G_OBJECT (play), "video-sink", video, NULL);

   bus = gst_pipeline_get_bus (GST_PIPELINE (play));
   gst_bus_add_watch (bus, my_bus_callback, loop);
   gst_object_unref (bus);

 
  /* Let's play ! */
  gst_element_set_state (play, GST_STATE_PLAYING);

  /* we need to run a GLib main loop to get out of here */
  loop = g_main_loop_new (NULL, FALSE);
  
  /* Get us out after 5 seconds */
  g_timeout_add (10000, get_me_out, NULL);
  g_main_loop_run (loop);



  /* Release elements and stop playback */
  gst_element_set_state (play, GST_STATE_NULL);

  /* Free the main loop */
  g_main_loop_unref (loop);
   gst_object_unref (GST_OBJECT (play));
  /* Release DirectFB context and surface */

  primary->Release (primary);
  dfb->Release (dfb);

  return 0;
}



Thanks !