【问题标题】:Kurento, One to many; being able to change the sourceKurento,一对多;能够改变来源
【发布时间】:2018-09-14 14:52:55
【问题描述】:

我只需要一名演示者向许多观众流式传输,但在某些时候,这些观众中的一个可以成为演示者,而无需断开整个管道。

这可能吗?我正在查看文档和示例,但在任何地方都看不到这个用例

【问题讨论】:

    标签: java video-streaming webrtc kurento


    【解决方案1】:

    回答我自己的问题,您可以使用“DispatcherOneToMany”,然后在您想要切换“Presenter”角色时更改调度程序的来源。它就像一个魅力。

    创建调度程序并向其添加新客户端的示例:

        private void start(final WebSocketSession session, JsonObject jsonMessage)
    {
        // ---- Media pipeline
        log.info("[Handler::start] Adding a new client!");
    
        final UserSession user = new UserSession();
        users.put(session.getId(), user);
    
        if(pipeline==null){
            log.info("[Handler::start] Create Media Pipeline");
            pipeline = kurento.createMediaPipeline();
            dispatcher = new DispatcherOneToMany.Builder(pipeline).build();
        }
    
        final WebRtcEndpoint webRtcEp = new WebRtcEndpoint.Builder(pipeline).build();
        user.setWebRtcEndpoint(webRtcEp);
    
        HubPort hubPort = new HubPort.Builder(dispatcher).build();
        user.setHubPort(hubPort);
        hubPort.connect(webRtcEp);
        webRtcEp.connect(hubPort);
    
        if(users.size()==1) {
            log.info("[Handler::start] It's first user, then set it as source");
            dispatcher.setSource(hubPort);
        }
    [...]
    

    然后根据需要切换源,为此添加一条新消息并以这种方式进行:

            UserSession user = users.get(sessionId);
    
        if (user != null) {
            log.info("[Handler::presenterSwitch] Switching presenter to: {} ", sessionId);
            dispatcher.setSource(user.getHubPort());
        }else{
            log.error("[Handler::presenterSwitch] Trying to switch to an no-existent session: {}", sessionId);
        }
    

    我希望这对某人有所帮助,编码愉快。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-09-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-15
      • 1970-01-01
      • 2021-05-03
      • 2019-03-30
      相关资源
      最近更新 更多