#include "uyvy2rgba.h" #include #include #include #include #include #include #include sem_t semIsCall; extern unsigned char* tempBuf; typedef struct { GstElement *pipeline; GstElement *src; GstElement *sink; GstElement *nvvidconv; GstElement *capsfilter; GstCaps *caps_src; GstCaps *caps_RGBA; GMainLoop *loop; }gst_app_t; gst_app_t gst_app; GstFlowReturn new_sample (GstElement *sink, gst_app_t *app) { GstSample *sample; GstBuffer *sampleBuffer; GstMapInfo map; /* Retrieve the buffer */ g_signal_emit_by_name (sink, "pull-sample", &sample); if (sample) { /* The only thing we do in this example is print a * to indicate a received buffer */ sampleBuffer = gst_sample_get_buffer(sample); // g_print ("*"); gst_buffer_map(sampleBuffer, &map, GST_MAP_READ); tempBuf = map.data; gst_sample_unref (sample); sem_post(&semIsCall); return GST_FLOW_OK; } return GST_FLOW_ERROR; } int PushUYVYData(unsigned char *pbuffer , int datasize) { gst_app_t *app = &gst_app; if(app == NULL) { return -1; } GstMapInfo info; GstBuffer *buffer; guint size; GstFlowReturn ret; buffer = gst_buffer_new_allocate(NULL, datasize, NULL); if(gst_buffer_map(buffer, &info, GST_MAP_WRITE)) { memcpy(info.data, pbuffer, datasize); gst_buffer_unmap(buffer, &info); } gst_buffer_ref(buffer); ret = gst_app_src_push_buffer(GST_APP_SRC(app->src), buffer); if( ret != GST_FLOW_OK ) { g_print("error: \n"); } gst_buffer_unref(buffer); return 0; } gboolean bus_callback(GstBus *bus, GstMessage *message, gpointer ptr) { gst_app_t *app = (gst_app_t*)ptr; switch(GST_MESSAGE_TYPE(message)){ case GST_MESSAGE_STATE_CHANGED: { GstState oldstate, newstate; gst_message_parse_state_changed (message, &oldstate, &newstate, NULL); switch (newstate) { case GST_STATE_PLAYING: { printf ("Pipeline running\n"); GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (app->pipeline), GST_DEBUG_GRAPH_SHOW_ALL, "iva-app-playing"); } break; case GST_STATE_PAUSED: if (oldstate == GST_STATE_PLAYING) { printf ("Pipeline paused\n"); } break; case GST_STATE_READY: GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (app->pipeline), GST_DEBUG_GRAPH_SHOW_ALL, "iva-app-ready"); if (oldstate == GST_STATE_NULL) { printf ("Pipeline ready\n"); } else { printf ("Pipeline stopped\n"); } break; default: break; } break; } } return TRUE; } void *uyvy2rgba(void *argv) { gst_app_t *app = &gst_app; GstBus *bus; GstStateChangeReturn state_ret; gst_init (NULL, NULL); app->pipeline = gst_pipeline_new("mypipeline"); // gst_object_unref(bus); app->src = gst_element_factory_make("appsrc", NULL); app->nvvidconv = gst_element_factory_make("nvvidconv",NULL); app->capsfilter =gst_element_factory_make ("capsfilter", NULL); app->sink = gst_element_factory_make ("appsink", NULL); // g_assert(app->src); // g_assert(app->nvvidconv); // g_assert(app->capsfilter); // g_assert(app->sink); app->caps_RGBA=gst_caps_new_simple("video/x-raw", "format", G_TYPE_STRING, "RGBA", "width", G_TYPE_INT, 1920, "height", G_TYPE_INT, 1080, "framerate", GST_TYPE_FRACTION, 25 , 1, NULL); app->caps_src = gst_caps_new_simple("video/x-raw", "format", G_TYPE_STRING, "UYVY", "width", G_TYPE_INT, 1920, "height", G_TYPE_INT, 1080, "framerate", GST_TYPE_FRACTION, 25 , 1, NULL); g_object_set(G_OBJECT(app->src), "caps", app->caps_src, NULL); g_object_set(G_OBJECT(app->src), "stream-type", 0, "is-live", TRUE, "do-timestamp", TRUE, "format", GST_FORMAT_TIME, NULL); g_object_set(G_OBJECT(app->capsfilter), "caps",app->caps_RGBA, NULL); g_object_set(G_OBJECT(app->sink), "sync", false, NULL); g_object_set(G_OBJECT(app->sink), "emit-signals", true, NULL); g_signal_connect (app->sink, "new-sample", G_CALLBACK (new_sample), app); // g_signal_connect(app->src, "need-data", G_CALLBACK(start_feed), app); gst_bin_add_many(GST_BIN(app->pipeline), app->src, app->nvvidconv, app->capsfilter, app->sink, NULL); if(!gst_element_link_many(app->src, app->nvvidconv, app->capsfilter,app->sink, NULL)) { g_printerr ("Elements could not be linked:app->src, app->nvvidconv, app->capsfilter,app->sink.\n"); gst_object_unref (app->pipeline); } app->loop = g_main_loop_new(NULL, FALSE); state_ret = gst_element_set_state((GstElement*)app->pipeline, GST_STATE_PLAYING); g_warning("set state returned %d\n", state_ret); bus = gst_element_get_bus(app->pipeline); gst_bus_add_watch(bus, bus_callback, app); printf("Running main loop\n"); g_main_loop_run(app->loop); gst_object_unref (bus); state_ret = gst_element_set_state(app->pipeline, GST_STATE_NULL); gst_object_unref (app->pipeline); g_warning("set state null returned %d\n", state_ret); } void start_uyvy2rgba_thread(void) { pthread_t tid; int ret; sem_init(&semIsCall,0,0); ret = pthread_create( &tid, NULL,uyvy2rgba, NULL ); }