rendered paste body#include <Ecore.h>#include <Ecore_Evas.h>#include <Ecore_X.h>#include <Evas.h>#include <gst/gst.h>#include <string.h>typedef struct _MainWin MainWin;struct _MainWin{ void *data; int w; int h; Ecore_Evas *ecore_evas; Evas *evas; Evas_Object *o;};static int_main_signal_exit_cb(void *data, int ev_type, void *ev){ ecore_main_loop_quit(); return 0;}static void_main_delete_request_cb(Ecore_Evas *ee){ ecore_main_loop_quit();}static void_yuv_rows_get(unsigned char *data, int w, int h, unsigned char **yrows, unsigned char **urows, unsigned char **vrows){ int i; for (i = 0; i < h; i++) yrows[i] = &data[i * w]; for (i = 0; i < (h / 2); i++) urows[i] = &data[h * w + i * (w / 2) ]; for (i = 0; i < (h / 2); i++) vrows[i] = &data[h * w + h * (w /4) + i * (w / 2)];}static void_streamer_handoff_cb(GstElement *element, GstBuffer *buffer, GstPad *pad, MainWin *win){ Evas_Object *obj; int iw, ih; unsigned char **rows; obj = win->o; iw = win->w; ih = win->h; rows = evas_object_image_data_get(obj, 1); if (rows) { _yuv_rows_get(GST_BUFFER_DATA(buffer), iw, ih, rows, &rows[ih], &rows[ih + (ih / 2)]); evas_object_image_data_update_add(obj, 0, 0, iw, ih); evas_object_image_data_set(obj, rows); }}int main(int argc, char* argv[]){ Ecore_Evas *ecore_evas; Evas *evas; Evas_Object *o; MainWin *win; GstElement *pipeline; GstElement *v4l2src; GstElement *ffmpegcolorspace; GstElement *sink; GstCaps *caps; gst_init(&argc, &argv); ecore_init(); ecore_app_args_set(argc, (const char **)argv); ecore_event_handler_add(ECORE_EVENT_SIGNAL_EXIT, _main_signal_exit_cb, NULL); ecore_evas_init(); win = g_new0 (MainWin, 1); win->data = NULL; win->w = 320; win->h = 240; ecore_evas = ecore_evas_software_x11_new(NULL, 0, 0, 0, win->w, win->h); ecore_evas_callback_delete_request_set(ecore_evas, _main_delete_request_cb); ecore_evas_title_set(ecore_evas, "v4l2 Test Program"); ecore_evas_name_class_set(ecore_evas, "evas_v4l2_test", "main"); ecore_evas_show(ecore_evas); win->ecore_evas = ecore_evas; evas = ecore_evas_get(ecore_evas); evas_image_cache_set(evas, 8 * 1024 * 1024); win->evas = evas; o = evas_object_image_add(evas); evas_object_move(o, 0, 0); evas_object_resize(o, win->w, win->h); evas_object_layer_set(o, -999); evas_object_show(o); evas_object_focus_set(o, 1); evas_object_image_colorspace_set(o, EVAS_COLORSPACE_YCBCR422P601_PL); evas_object_image_alpha_set(o, 0); evas_object_image_size_set(o, win->w, win->h); evas_object_image_fill_set(o, 0, 0, win->w, win->h); win->o = o; pipeline = gst_pipeline_new ("pipeline"); v4l2src = gst_element_factory_make ("v4l2src", "v4l2src"); ffmpegcolorspace = gst_element_factory_make ("ffmpegcolorspace", "ffmpegcolorspace"); sink = gst_element_factory_make ("fakesink", "sink"); gst_bin_add_many (GST_BIN (pipeline), v4l2src, ffmpegcolorspace, sink, NULL); caps = gst_caps_new_simple ("video/x-raw-yuv", "format", GST_TYPE_FOURCC, GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y'), "width", G_TYPE_INT, win->w, "height", G_TYPE_INT, win->h, NULL); gst_element_link_filtered (v4l2src, ffmpegcolorspace, caps); gst_caps_unref (caps); caps = gst_caps_new_simple ("video/x-raw-yuv", "format", GST_TYPE_FOURCC, GST_MAKE_FOURCC ('I', '4', '2', '0'), NULL); gst_element_link_filtered (ffmpegcolorspace, sink, caps); gst_caps_unref (caps); g_object_set (G_OBJECT (sink), "signal-handoffs", TRUE, NULL); g_signal_connect (sink, "handoff", G_CALLBACK (_streamer_handoff_cb), win); gst_element_set_state (pipeline, GST_STATE_PLAYING); ecore_main_loop_begin(); return 0;}