赞
踩
gst-launch命令转换为C代码(gstreamer框架)
gst-launch-1.0 udpsrc port=5004 buffer-size=60000000 caps=“application/x-rtp, media=video, clock-rate=90000, payload=96, encoding-name=H264” ! rtpjitterbuffer latency=7 ! rtph264depay ! h264parse ! video/x-h264, alignment=nal ! omxh264dec low-latency=1 internal-entropy-buffers=5 ! video/x-raw ! queue max-size-bytes=0 ! kmssink bus-id=fd4a0000.zynqmp-display fullscreen-overlay=1
gst-launch-1.0 udpsrc port=5004 buffer-size=60000000 caps=“application/x-rtp, media=video, clock-rate=90000, payload=96, encoding-name=H265” ! rtpjitterbuffer latency=7 ! rtph265depay ! h265parse ! video/x-h265, alignment=nal ! omxh265dec low-latency=1 internal-entropy-buffers=5 ! video/x-raw ! queue max-size-bytes=0 ! kmssink bus-id=fd4a0000.zynqmp-display fullscreen-overlay=1
typedef struct _CustomData{ GstElement *pipeline; GstElement *source; GstElement *depay; GstElement *parse; GstElement *decode; GstElement *capsf; GstElement *conv1; GstElement *mcells; GstElement *conv2; GstElement *sink; GstElement *fsink; GstElement *fsource; } CustomData; static CustomData data; static guint bus_watch_id; static int g_rtp_port=0, g_format=0; static GMainLoop *loop; static int g_play_stauts = 0; static gboolean bus_call (GstBus * bus, GstMessage * msg, gpointer data) { static int mvalue[2] = {0, 0}, cnt =0, flag = 0; static int aa=0, bb=0; 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_printerr ("ERROR from element %s: %s\n", GST_OBJECT_NAME (msg->src), error->message); g_free (debug); g_printerr ("Error: %s\n", error->message); g_error_free (error); g_main_loop_quit (loop); break; } default: //printf("msg == 0x%0x\n", GST_MESSAGE_TYPE (msg)); break; } } int gst_start_play(int rtp_port, int format){ //GstMessage *msg; //gboolean terminate = FALSE; GstCaps *caps; GstBus *bus = NULL; printf("gst_start_play rtp_port === %d\n", rtp_port); if(g_play_stauts) { return -1; } g_rtp_port = rtp_port; g_format = format; loop = g_main_loop_new (NULL, FALSE); /*init gstreamer*/ //gst_init(&argc, &argv); gst_init(NULL, NULL); /*create elements*/ data.source = gst_element_factory_make("udpsrc","source"); data.depay = gst_element_factory_make("rtpjitterbuffer","depay"); if(format == 1) { data.parse = gst_element_factory_make("rtph265depay","parse"); data.decode = gst_element_factory_make("h265parse","decode"); }else { data.parse = gst_element_factory_make("rtph264depay","parse"); data.decode = gst_element_factory_make("h264parse","decode"); } data.capsf = gst_element_factory_make("capsfilter", "capsf"); if(format == 1) { data.conv1 = gst_element_factory_make("omxh265dec","conv1"); }else { data.conv1 = gst_element_factory_make("omxh264dec","conv1"); } data.mcells = gst_element_factory_make("capsfilter","mcells"); data.conv2 = gst_element_factory_make("queue", "conv2"); data.sink = gst_element_factory_make("kmssink", "sink"); //create pipeline data.pipeline = gst_pipeline_new("pipeline"); if(!data.pipeline || !data.source || !data.depay || !data.parse || !data.decode || !data.capsf || !data.conv1 || !data.mcells || !data.conv2 || !data.sink){ g_printerr("Not all elements created\n"); return -1; } //set rtsp src g_object_set(G_OBJECT (data.source), "port", rtp_port, NULL); g_object_set(G_OBJECT (data.source), "buffer-size", 60000000, NULL); //set capsf if(format == 1) { caps = gst_caps_from_string("application/x-rtp, media=video, clock-rate=90000, payload=96, encoding-name=H265"); }else { caps = gst_caps_from_string("application/x-rtp, media=video, clock-rate=90000, payload=96, encoding-name=H264"); } g_object_set(G_OBJECT(data.source), "caps", caps, NULL); g_object_set(G_OBJECT (data.depay), "latency", 7, NULL); //set capsf if(format == 1) { caps = gst_caps_from_string("video/x-h265, alignment=nal"); }else { caps = gst_caps_from_string("video/x-h264, alignment=nal"); } g_object_set(G_OBJECT(data.capsf), "caps", caps, NULL); g_object_set(G_OBJECT (data.conv1), "low-latency", 1, NULL); g_object_set(G_OBJECT (data.conv1), "internal-entropy-buffers", 5, NULL); //set capsf caps = gst_caps_from_string("video/x-raw"); g_object_set(G_OBJECT(data.mcells), "caps", caps, NULL); g_object_set(G_OBJECT (data.conv2), "max-size-bytes", 0, NULL); g_object_set(G_OBJECT (data.sink), "bus-id", "fd4a0000.zynqmp-display", NULL); g_object_set(G_OBJECT (data.sink), "fullscreen-overlay", 1, NULL); /* Add a message handler */ bus = gst_pipeline_get_bus (GST_PIPELINE (data.pipeline)); bus_watch_id = gst_bus_add_watch (bus, bus_call, loop); gst_object_unref (bus); //build the pipeline gst_bin_add_many(GST_BIN(data.pipeline), data.source, data.depay, data.parse, data.decode, data.capsf, data.conv1, data.mcells , data.conv2, data.sink, NULL); gst_element_link_many(data.source, data.depay, data.parse, data.decode, data.capsf, data.conv1, data.mcells, data.conv2, data.sink, NULL); /* play */ gst_element_set_state (data.pipeline, GST_STATE_PLAYING); g_play_stauts = 1; g_print("Playing...\n"); g_main_loop_run (loop); } int gst_stop_play() { if(!g_play_stauts) { return -1; } g_main_loop_quit (loop); /* clean up */ gst_element_set_state (data.pipeline, GST_STATE_NULL); gst_object_unref (GST_OBJECT (data.pipeline)); g_source_remove (bus_watch_id); g_main_loop_unref (loop); g_play_stauts = 0; return 0; }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。