기록해야 기억에 남는다
WebRTC (4) - Kurento One2ManyCall 본문
1) Kurento 'One2ManyCall' example elements
- Peer (WebRtcEndpoint) (Presenter, Viewer)
- 미디어 송출, 수신 역할
- Kurento Java Client
- API 요청 처리 역할 (signaling, session 생성 등)
- Kurento Media Server
- media stream 중계, 처리
→ Kurento Java Client API를 사용하는 Spring-Boot 기반 애플리케이션 서버를 사용하여 Kurento Media Server 기능을 제어
(즉, Kurento Java Client 는 KMS 기능을 이용하기 위한 API 서버 역할을 수행함)
→ Kurento Media Server의 경우 native c++ 기반의 프로그램이며 여러 가지 설치 방법이 존재
(로컬에 설치, docker에 설치 등 → 현재 docker를 이용하여 실행 하는 중)
2) WebRtcEndpoint & MediaPipeline
→ WebRtcEndpoint는 KMS에 생성된 같은 MediaPipeline을 이용하여 스트림을 주고 받음
→ Kurento 공식 사이트의 'MediaPipeline' 정의:
미디어 파이프라인은 하나의 요소(소스)에서 생성된 출력 스트림이 하나 이상의 다른 요소 입력 스트림(싱크)에 공급되는 미디어 요소 체인입니다.
따라서 파이프라인은 스트림에서 일련의 작업을 수행할 수 있는 "머신"을 나타냅니다.
→ WebRtcEndpoint는 webRTC 스트림을 주고받기 위한 Peer을 나타내는 요소이자 Kurento에서 제공하는 하나의 '모듈' 역할을 수행함
3) Kurento 'One2ManyCall' example flow
- 사용자가 Kurento Java API Server (Kurento Java Client) 에 접속하면 websocket 세션을 생성함
- 웹 소켓 세션 객체와 함께 WebRtcEndpoint 객체 생성
- 두 객체를 묶어 UserSession 객체에 담아 Peer의 세션 관리
- WebRtcEndpoint 객체 생성 시 미디어 송수신을 위한 MediaPipeline 객체를 넣어주어야 하므로
- Presenter가 먼저 미디어 MediaPipeline 생성 요청을 날림 → 요청을 통해 Kurento API Server는 KMS에 요청을 날려 파이프 라인 생성
- Presenter의 WebRtcEndpoint에 해당 MediaPipeline을 추가하며 WebRtcEndpoint 객체 생성
- new WebRtcEndpoint.Builder(pipeline).build()
- Presenter의 WebSocketSession과 WebRtcEndpoint 객체를 이용하여 UserSession 객체 생성 후 presenterUserSession 필드에 할당함
- 정확히는 UserSession 객체를 만들고 WebSocketSession 객체를 먼저 할당한 후 setter 메소드를 콜하며 위 WebRtcEndpoint 생성을 처리함
- Viewer 접속 시 미리 생성된 MediaPipeline을 이용하여 Presenter와 똑같이 WebRtcEndpoint 생성
- Viewer도 Presenter와 마찬가지로 WebSocketSession과 WebRtcEndpoint 객체를 이용하여 UserSession 객체 생성 후 이것을 ConcurrentHashMap에 넣어 관리함
- Presenter가 송출을 stop 하게 되면 pipeline.release()를 호출하여 KMS에 생성된 미디어 파이프라인을 파괴한 후 pipeline, presenterUserSession 변수를 null로 초기화함.
- Viewer가 시청을 stop 하게 되면 webRtcEndpoint.release()를 호출하여 시청중이던 파이프라인에서 빠져나감
4) Kurento 'One2Many' example architecture (SFU)
5) TO-DO
- 라이브 스트리밍 방을 여러 개 만들기 위해 pipeline 여러 개 생성
- presenter의 UserSession 객체와 MediaPipeline, 시청자의 ID ArrayList 등을 담고 있는 LiveStreamRoom 클래스를 선언하여 관리하는 것도 괜찮아 보임
- 현재 WebSocketSession, WebRtcEndpoint 등이 하나의 Kurento JAVA API 서버 메모리에서 관리되고 있으므로 어떻게 확장할 수 있을지 고민해야함.
- 채팅 서버의 경우 별도로 관리하게 되면 라이브 스트리밍 룸과 어떻게 동기화 할 수 있을지 고민해야함.
참고
- Introduction to Kurento: https://doc-kurento.readthedocs.io/en/stable/user/intro.html
'Live-Streaming > WebRTC' 카테고리의 다른 글
WebRTC (6) - Kurento RecorderEndpoint (2) (0) | 2023.03.10 |
---|---|
WebRTC (5) - Kurento RecorderEndpoint (0) | 2023.03.07 |
WebRTC (3) - About Kurento (0) | 2023.03.07 |
WebRTC (2) - SDP, RTP (0) | 2023.03.07 |
WebRTC (1) (0) | 2023.03.07 |