• Janus库简介


    一 Janus是C语言的库,SFU的服务器。按照插件接口写,新增插件。

    服务器和客户端通信方式支持:http、ws、RabbitMQ--消息队列。

    插件接口如下:初始化、销毁、创建会话、处理消息--跟client通信、开始媒体、处理rtp包、rtcp包、结束媒体、销毁会话等。

    1. /* Plugin setup */
    2. static janus_plugin janus_videoroom_plugin =
    3. JANUS_PLUGIN_INIT (
    4. .init = janus_videoroom_init,
    5. .destroy = janus_videoroom_destroy,
    6. ...
    7. .create_session = janus_videoroom_create_session,
    8. .handle_message = janus_videoroom_handle_message,
    9. .setup_media = janus_videoroom_setup_media,
    10. .incoming_rtp = janus_videoroom_incoming_rtp,
    11. .incoming_rtcp = janus_videoroom_incoming_rtcp,
    12. .incoming_data = janus_videoroom_incoming_data,
    13. .slow_link = janus_videoroom_slow_link,
    14. .hangup_media = janus_videoroom_hangup_media,
    15. .destroy_session = janus_videoroom_destroy_session,
    16. );

     P2P用了libnice库,创建线程、请求消息放到队列,用了glib库。

    二 线程模型:多线程

    主线程、"timeout watchdog"--2秒检测session存活周期、"sessions requests"--派发请求、

    线程池--处理"message"消息,新起线程。(是处理sdp复杂,需要起线程?)

    比如:{"janus":"message","body":{"audio":true,"video":true,"videocodec":"h264"},"transaction":"f4p3bK72QD3e","jsep":{"type":"offer","sdp":"v=..."}

    一般请求,直接处理了。

    janus_ice_handle_thread:janus.jcfg的event_loops,默认是注掉的。

    收到attach消息,新起一个janus_ice_handle_thread。

    个数也可以限制。实际中当然要限制个数啊,比如100个用户就100个线程。

    三 业务处理之自问自答

    创建Room,插入队列:g_hash_table_insert(rooms, videoroom->room_id_str,videoroom);

    创建会话,获得session_id,插入队列:g_hash_table_insert(sessions, handle, session);

    传入session_id,会获取ice的handle_id,处理音视频流的。

    handle_id = janus_ice_handle_create(session, opaque_id, token_value);

    在一个Room,如何区分发送的流,和接收的多路流?

    {GHashTable *participants;

    }janus_videoroom;

    1. typedef struct janus_videoroom_session {
    2. janus_plugin_session *handle;
    3. janus_videoroom_p_type participant_type;
    4. gpointer participant;
    5. ...
    6. janus_mutex mutex;
    7. janus_refcount ref;
    8. } janus_videoroom_session;
    9. typedef struct janus_videoroom_publisher {
    10. janus_videoroom_session *session;
    11. janus_videoroom *room;
    12. ...
    13. }janus_videoroom_publisher;
    14. typedef struct janus_videoroom {
    15. guint64 room_id;
    16. }
    17. typedef struct janus_videoroom_publisher_stream {
    18. janus_videoroom_publisher *publisher; /* Publisher instance this stream belongs to */
    19. janus_videoroom_media type;
    20. ...
    21. GHashTable *rtp_forwarders;
    22. }
    23. typedef struct janus_videoroom_subscriber {
    24. janus_videoroom_session *session;
    25. janus_videoroom *room; /* Room */
    26. }
    27. typedef struct janus_videoroom_subscriber_stream {
    28. janus_videoroom_subscriber *subscriber; /* Subscriber instance this stream belongs to */
    29. GSList *publisher_streams;
    30. }

    四 SFU服务器难在那呢?

    1 单端口的问题:所有推拉流,DTLS和音视频流都用一个端口。

    因为暴露多个端口不安全,而且多端口不好负载均衡。

    用ice-ufrag、ice-pwd区分音视频的流。如果用ssrc,一般音视频ssrc不同。

    2 集群:信令和媒体需要分离。

    容错处理、负载均衡、级联。

  • 相关阅读:
    增长黑客营销方式
    jenkins全局配置问题
    jupyter notebook连接不上内核
    电脑商城系统
    BeanFactory和ApplicationContext的区别
    【Spring Security 系列】(三)剖析基础组件之授权功能
    OpenGL光照之基础光照
    21天算法打卡系列(6)——冒泡排序和快速排序
    GFS 分布式文件系统
    【前端】webpack打包去除console.log
  • 原文地址:https://blog.csdn.net/chenquangobeijing/article/details/126680599