当前位置:   article > 正文

gst-launch命令转换为C代码(gstreamer框架)_gst-launch-1.0 转成代码

gst-launch-1.0 转成代码

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;
}
                   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/644228
推荐阅读
相关标签
  

闽ICP备14008679号