/* HEADERS */ #include #include #include #include /* VGA=614400 (640*480*2) 720P=1843200 (1280*720*2) */ #define BUFFER_SIZE 1843200 #define QUEUED_FRAMES 3 /* these are the caps we are going to pass through the appsrc */ const gchar *video_caps = "video/mpeg, mpegversion=(int)4, framerate=(fraction)1001/30000, width=(int)1280, height=(int)720"; typedef struct { GstElement *pipeline; GstElement *source; guint source_id; } AppData; static gboolean on_pipeline_message (GstBus * bus, GstMessage * message, AppData * app) { GstState state, pending; switch (GST_MESSAGE_TYPE (message)) { case GST_MESSAGE_EOS: g_print ("Received End of Stream message\n"); break; case GST_MESSAGE_ERROR: g_print ("Received error\n"); break; case GST_MESSAGE_STATE_CHANGED: gst_element_get_state(app->source, &state, &pending, GST_CLOCK_TIME_NONE); /* g_print ("State changed from %i to %i\n", state, pending); */ break; default: break; } return TRUE; } void *writerThrFxn(void *arg) { /* SETTING OF CUSTOM BUFFER PARAMTERS "we" */ AppData *app = NULL; gchar *string = NULL; GstBus *bus = NULL; GstElement *appsrc = NULL; gst_init (NULL, NULL); app = g_new0 (AppData, 1); string = g_strdup_printf ("appsrc is-live=true name=source caps=\"%s\" ! rtpmp4vpay send-config=TRUE ! udpsink host=172.24.136.232 port=5000", video_caps); app->pipeline = gst_parse_launch (string, NULL); g_free (string); if (app->pipeline == NULL) { g_print ("Bad pipeline\n"); } appsrc = gst_bin_get_by_name (GST_BIN (app->pipeline), "source"); g_object_set (appsrc, "format", GST_FORMAT_TIME, NULL); gst_app_src_set_max_bytes((GstAppSrc *)appsrc, QUEUED_FRAMES * BUFFER_SIZE); app->source = appsrc; bus = gst_element_get_bus (app->pipeline); gst_bus_add_watch (bus, (GstBusFunc) on_pipeline_message, app); gst_element_set_state (app->pipeline, GST_STATE_PLAYING); GstBuffer *app_buffer; GstFlowReturn ret; /* CREATING GSTBUFFER TO PASS VOSS AND VOS HEADERS */ GstBuffer *buf; buf = gst_buffer_new(); guint8 ptr[16]; ptr[0]=0x00; ptr[1]=0x00; ptr[2]=0x01; ptr[3]=0xB0; ptr[4]=0x00; ptr[5]=0x00; ptr[6]=0x00; ptr[7]=0x00; ptr[8]=0x00; ptr[9]=0x00; ptr[10]=0x01; ptr[11]=0xB5; ptr[12]=0xB0; ptr[13]=0x00; ptr[14]=0x00; ptr[15]=0x05; gst_buffer_set_data (buf, ptr, 16); gst_buffer_set_caps (buf, gst_caps_from_string (video_caps)); gst_app_src_push_buffer (app->source, buf); DBG("Entering writer main loop.\n"); /* START OF INFINITE LOOP */ while (!gblGetQuit()) { /* GET APPLICATION BUFFER AND STORE IT IN "we" */ app_buffer = gst_app_buffer_new (we.encodedBuffer, we.frameSize, g_free, we.encodedBuffer); gst_buffer_set_caps (app_buffer, gst_caps_from_string (video_caps)); g_signal_emit_by_name (app->source, "push-buffer", app_buffer, &ret); } /* END OF INFINITE LOOP */ gst_app_src_end_of_stream (GST_APP_SRC (app->source)); gst_element_set_state (app->pipeline, GST_STATE_NULL); /* Cleaning up */ gst_object_unref (bus); gst_object_unref (app->source); gst_object_unref (app->pipeline); gst_object_unref (pipe); g_free (app); }