我需要在gstreamer中进行同步

时间:2019-07-04 05:28:11

标签: c++ gstreamer

这是我在RTSP中通过网络进行视频流传输的代码。当我打开第二个Vlc并再次开始播放视频时,但是我想进行同步,例如,第一个视频是在20秒内,第二个应该从20秒开始。我必须做的是处理同步。

   #include "pch.h"
   #include <iostream>
   #include <gst/gst.h>
   #include <gst/rtsp-server/rtsp-media.h>
   #include <gst/rtsp-server/rtsp-server.h>
   #include <gst/rtsp-server/rtsp-media-factory-uri.h>
   #include <stdlib.h>
   #include <stdio.h>
   #include <vector>
   #include <stdarg.h>
   #include <stddef.h>
   #include <string.h>
   #define PORT "8554"
   static char *port = (char *)PORT;

    static GOptionEntry entries[] = {
   {"port",'p', 0, G_OPTION_ARG_STRING, &port,"Port " PORT "", "PORT"}, 
   {NULL} };



   int main(int argc, gchar * argv[])
   {
GstElement *pipeline;
GMainLoop *loop;
GstRTSPServer *server;
GstRTSPMountPoints *mounts;
GstRTSPMediaFactoryURI *factory;
GOptionContext *sample;
GError *error = NULL;
gchar *uri;


sample = g_option_context_new("<uri> - Test RTSP Server, URI");
g_option_context_add_main_entries(sample, entries, NULL);
g_option_context_add_group(sample, gst_init_get_option_group());
if (!g_option_context_parse(sample, &argc, &argv, &error)) {
    return -1;
}
loop = g_main_loop_new(NULL, FALSE);

server = gst_rtsp_server_new();
g_object_set(server, "service", port, NULL);

mounts = gst_rtsp_server_get_mount_points(server);

factory = gst_rtsp_media_factory_uri_new();


const char* streamUri = 
   "https://www.freedesktop.org/software/gstreamer- 
   sdk/data/media/sintel_trailer-480p.webm";
pipeline = gst_parse_launch(streamUri,NULL);



if (gst_uri_is_valid(streamUri)) {
    uri = g_strdup(streamUri);
}
else if (g_file_test(streamUri, G_FILE_TEST_EXISTS)) {
    uri = gst_filename_to_uri(streamUri, NULL);
}
else {
    printf("There is no uri");
    return -1;
}

gst_rtsp_media_factory_uri_set_uri(factory, uri);
g_free(uri);

gst_rtsp_mount_points_add_factory(mounts, "/deneme", 
    GST_RTSP_MEDIA_FACTORY(factory));

g_object_unref(mounts);

if (gst_rtsp_server_attach(server, NULL) == 0)
    printf("FAILED!");

g_print("stream ready at rtsp://127.0.0.1:%s/deneme\n", port);



g_main_loop_run(loop);

return 0;

}

1 个答案:

答案 0 :(得分:0)

您需要将工厂设置为共享,您可以通过调用以下函数来做到这一点:

[HttpGet]
    public ActionResult UpdateUser(string username = "")
    {
        if (string.IsNullOrEmpty(username))
        {
            return View(new DP_User());
        }
        else
        {
            using (DBModel db = new DBModel())
            {
                return View(db.DP_User.Where(x => x.Username == username).FirstOrDefault<DP_User>());
            }
        }
    }

以下是我挑选(https://github.com/freedesktop/gstreamer-gst-rtsp-server/blob/master/examples/),修改和测试的示例

/* make the factory shared as we will stream same data */
gst_rtsp_media_factory_set_shared(factory, TRUE);