Turning this gst-launch-1.0 command into a C++ app?

rick b rick_blacker at hotmail.com
Thu Nov 10 04:31:12 UTC 2016


I've made SOME headway

Again, i'm trying to recreate this command line app in C/C++
gst-launch-1.0 v4l2src device=/dev/video13 do-timestamp=true ! video/x-raw,
format=YUY2, width=640, height=480, framerate=30/1 ! autovideoconvert !
vaapih264enc ! rtph264pay ! udpsink host=192.168.1.2 port=5600


I've setup all my elements, however, I'm getting an internal data flow error
and I'm not sure why. Any help will be AWESOME!!!
Thanks




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

GMainLoop 	*loop;

// Contain all the elements into a nice struct.
typedef struct _CustomData
{
	GstElement *pipeline;
	GstElement *videoSource;
	GstElement *videoConvert;
	GstElement *videoEncoder;
	GstElement *rtph264pay;
	GstElement *autoVideoSink;
	GstElement *uUpSink;
} CustomData;



// Constructs the elements in the pipeline
static bool build_elements( CustomData& data );

// Validates the elements in the pipeline
static bool check_elements( CustomData& data );

// Bus message handler
static gboolean my_bus_callback( GstBus *bus, GstMessage *message, gpointer
data );





// Main app entry point.
int main( int argc, char *argv[ ] )
{
	CustomData pipe;
	GstBus 		*bus;
	guint 		bus_watch_id;
	GstElement	*filter;

	// init
	gst_init( &argc, &argv );

	// create elements
	if( !build_elements( pipe ) )
		g_print( "Failed to create elements\n" );

	// check to ensure the elements were created properly
	if( !check_elements( pipe ) )
		g_print( "Failed to create elements\n" );

	// I've tried it WITH and WITHOUT the caps filter whic is not making any
difference.
	//filter = gst_element_factory_make ( "capsfilter", NULL);
	//gst_util_set_object_arg( G_OBJECT( filter ), "caps", "video/x-raw,
width=640, height=480, " "format={ YUY2 }" );

	// put together a pipeline
	gst_bin_add_many( GST_BIN ( pipe.pipeline ), pipe.videoSource,
pipe.videoConvert, pipe.videoEncoder, pipe.rtph264pay, pipe.uUpSink, NULL );

	bus 			= gst_pipeline_get_bus( GST_PIPELINE( pipe.pipeline ) );
	bus_watch_id 	= gst_bus_add_watch( bus, my_bus_callback, NULL );
	gst_object_unref( bus );


	if( !gst_element_link_many( pipe.videoSource, pipe.videoEncoder,
pipe.rtph264pay, pipe.uUpSink, NULL ) )
		g_print( "Failed to link elements\n" );


	// listen for newly created pads
	// start the pipeline
	gst_element_set_state( GST_ELEMENT( pipe.pipeline ), GST_STATE_PLAYING );
	loop = g_main_loop_new( NULL, FALSE );
	g_main_loop_run( loop );

	return 0;
}




// Constructs the elements for the pipe.
static bool build_elements( CustomData& pipe )
{
	bool retVal = true;
	try
	{
		pipe.pipeline		= gst_pipeline_new( "aero_pipeline" );
		pipe.videoSource 	= gst_element_factory_make( "v4l2src", 			"videoSource"
);
		pipe.videoConvert	= gst_element_factory_make( "videoconvert", 
"videoConvert" );
		pipe.videoEncoder	= gst_element_factory_make( "vaapih264enc", 
"videoEncoder" );
		pipe.rtph264pay		= gst_element_factory_make( "rtph264pay", 		"h264Pay" );
		pipe.uUpSink		= gst_element_factory_make( "udpsink", 			"uUpSink" );
		pipe.autoVideoSink	= gst_element_factory_make( "autovideosink", 
"videoSink" );


		// Set the properties on the video source and the udp sink
		g_object_set( pipe.videoSource,  "device", "/dev/video13", NULL );
		g_object_set( pipe.uUpSink,  "host", "192.168.1.2", NULL );
		g_object_set( pipe.uUpSink,  "port", 5600, NULL );

		gint port;
		gchar *value;

		g_object_get( G_OBJECT( pipe.videoSource), "device", &value, NULL );
		g_print( "\n\n~~~~~~~~~~~~~~~~~ video device = %s \n", value );
		g_free( value );

		g_object_get( G_OBJECT( pipe.uUpSink), "host", &value, NULL );
		g_print( "~~~~~~~~~~~~~~~~~ udp sink host = %s \n", value );
		g_free( value );

		g_object_get( G_OBJECT( pipe.uUpSink ), "port", &port, NULL );
		g_print( "~~~~~~~~~~~~~~~~~ udp sink port = %u \n\n\n", port );

	}
	catch( ... )
	{
		retVal = false;
	}
	return retVal;
}


// Checks to ensure all the elements where successfully created.
static bool check_elements( CustomData& data )
{
	bool retVal = true;
	if (!data.pipeline )
	{
		g_printerr ("Failed to create pipeline .\n");
		retVal = false;
	}
	if( !data.videoSource )
	{
		g_printerr ("Failed to create data source.\n");
		retVal = false;
	}
	if( !data.videoConvert )
	{
		g_printerr ("Failed to create video_convert.\n");
		retVal = false;
	}
	if ( !data.videoEncoder )
	{
		g_printerr ("Failed to create avdec_h264 video encoder.\n");
		retVal = false;
	}
	if( !data.rtph264pay )
	{
		g_printerr ("Failed to create rtph264pay .\n");
		retVal = false;
	}
	if( !data.uUpSink )
	{
		g_printerr ("Failed to create udpsink .\n");
		retVal = false;
	}
	return retVal;
}





static gboolean my_bus_callback( GstBus *bus, GstMessage *message, gpointer
data )
{
	return true;
	g_print( "Got %s message\n", GST_MESSAGE_TYPE_NAME( message ) );

	switch( GST_MESSAGE_TYPE( message ) )
	{
    	case GST_MESSAGE_ERROR:
    	{
			GError *err;
			gchar *debug;

			gst_message_parse_error( message, &err, &debug );
			g_print( "Error: %s\n", err->message );
			g_error_free( err );
			g_free( debug );
			g_main_loop_quit( loop );
			break;
    	}
    	case GST_MESSAGE_EOS:

    		// end-of-stream
    		g_main_loop_quit (loop);
    		break;
    	default:
    		// unhandled message
    		break;
	}

  // we want to be notified again the next time there is a message
   // on the bus, so returning TRUE (FALSE means we want to stop watching
  // for messages on the bus and our callback should not be called again)

  return TRUE;
}




--
View this message in context: http://gstreamer-devel.966125.n4.nabble.com/Turning-this-gst-launch-1-0-command-into-a-C-app-tp4680502p4680587.html
Sent from the GStreamer-devel mailing list archive at Nabble.com.


More information about the gstreamer-devel mailing list