视频流两个客户端同步

时间:2019-07-05 09:49:07

标签: c++ gstreamer

在此代码中,我需要进行同步。  但是视频无法播放。  此代码有什么问题?  我正在使用VisualStudio2017。  我在不同的vlc播放器上同时播放视频  次。  例如,当我在VLC上播放第10秒的视频时,  我要打开一个新的,这个新的必须从10秒开始而不是从  开始。  我怎样才能做到这一点?

 #include "pch.h"
 #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 <stdio.h>
 #define PORT "8554"


/* called when a stream has received an RTCP packet from the client */
static void on_ssrc_active(GObject * session, GObject * source, 
GstRTSPMedia * media)
 {
 GstStructure *stats;

g_print("source %p in session %p is active", source, session);

g_object_get(source, "stats", &stats, NULL);
if (stats) {
    gchar *sstr;
    sstr = gst_structure_to_string(stats);
    g_print("structure: %s\n", sstr);
    g_free(sstr);
    gst_structure_free(stats);
      }        
}
/* signal callback when the media is prepared for streaming.
* session manager for each of the streams and connect to some signals. */
static void media_prepared_cb(GstRTSPMedia * media)
{
guint i, n_streams;

n_streams = gst_rtsp_media_n_streams(media);

g_print("media %p is prepared and has %u streams", media, n_streams);

for (i = 0; i < n_streams; i++) {
    GstRTSPStream *stream;
    GObject *session;

    stream = gst_rtsp_media_get_stream(media, i);
    if (stream == NULL)
        continue;

    session = gst_rtsp_stream_get_rtpsession(stream);
    g_print("watching session %p on stream %u", session, i);

    g_signal_connect(session, "on-ssrc-active",
        (GCallback)on_ssrc_active, media);
      }
 }

 static void media_configure_cb(GstRTSPMediaFactory * factory, 
  GstRTSPMedia * media)
  {
g_signal_connect(media, "prepared", (GCallback)media_prepared_cb, 
    factory);
  }


   int main(int argc, gchar * argv[])
   {
    GMainLoop *loop;
    GstRTSPServer *server;
    GstRTSPMountPoints *mounts;
    GstRTSPMediaFactory *factory;
    gchar *filepath;
    errno_t err;
    FILE *file;
    gchar *str;

    gst_init(NULL, NULL);


    filepath=g_strdup_printf
   ("C:\\Users\\nisa.erkin\\source\\repos\\RTSP\\Example.mp4")

    err = fopen_s(&file, filepath, "r");
    if (err) {
        g_print("Failed to open file: %s\n", filepath);
        return 1;
    }
    fclose(file);

    g_print("Files exists!\n");
    loop = g_main_loop_new(NULL, FALSE);

    //server yarat
    server = gst_rtsp_server_new();

    //bağlanma noktalarını al
    mounts = gst_rtsp_server_get_mount_points(server);

 str = g_strdup_printf("( filesrc location=%s ! qtdemux name=d d. ! 
 queue ! rtph264pay pt=96 name=pay0 " "d. ! queue ! rtpmp4apay pt=97 
 name=pay1 " ")", filepath);

    /* make a media factory for a test stream. The default media 
       factory can use */
    factory = gst_rtsp_media_factory_new();
    gst_rtsp_media_factory_set_launch(factory, str);
    g_signal_connect(factory, "media-configure", 
            (GCallback)media_configure_cb,factory);
    g_free(str);

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

    /* set the session */
    gst_rtsp_server_set_service(server, "8554");

    /* attach the test factory to the /test url */
    gst_rtsp_mount_points_add_factory(mounts, "/deneme", factory);

    /* don't need the ref to the mapper anymore */
    g_object_unref(mounts);

    /* attach the server to the default maincontext */
    gst_rtsp_server_attach(server, NULL);

    /* start serving */
    g_print("stream ready at rtsp://127.0.0.1:8554/deneme\n");
    g_main_loop_run(loop);

    return 0;
}

0 个答案:

没有答案