How can I fix synchronization problem in gstreamer?

老子叫甜甜 提交于 2019-12-02 22:15:08

问题


In my code when I open the 2nd vlc 1st one starts from the beginning with 2nd one. But it must be like that: While the first client is still running, the second/third/etc client should start at approximately the same position as the first client currently has. What should I add to my code for that problem. I am working with Windows VisualStudio.

#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>

#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[])
{
 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 = 
    "C://Users//nisa.erkin//Downloads//SampleVideo_360x240_20mb.mp4";

 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_media_factory_set_shared(GST_RTSP_MEDIA_FACTORY(factory), 
    TRUE);

 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;
}

来源:https://stackoverflow.com/questions/56967035/how-can-i-fix-synchronization-problem-in-gstreamer

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!