다시 데이터 전송과 네트워크 불확실성으로 돌아와서 간단한 실험을 진행하고자합니다.
앞서 정의한 불확실성의 척도를 결정하는 요소는 대역폭, 딜레이, 패킷 유실률로 구성되어 있습니다.
이 글에서는 실험의 복잡도를 낮추기 위해서 패킷 유실률에 대해서 가용 대역폭의 변화를 살펴보고자 합니다.
리눅스에서 구동하는 iproute2를 활용한다면 원하는 네트워크 상태를 에뮬레이션 할 수 있습니다.
$ sudo tc qdisc add dev eno1 root netem loss 10%
실험이 끝난 후에 에뮬레이션한 값을 삭제하기 위해서는 del 파라미터를 사용해야 합니다.
$ sudo tc qdisc del dev eno1 root netem loss 10%
로컬 네트워크에서 패킷 유실률을 0%에서 10%까지 증가시켰을때 HTTP를 이용한 다운로드시에 사용한 대역폭의 변화는 다음 그래프와 같이 나타납니다.
실제 사용하는 네트워크 환경에서 10%까지의 패킷 유실률이 발생할 수 있을지는 의문이지만, 주목할만한 것은 패킷 유실률이 3%임에도
거의 1/2 수준으로 가용 대역폭이 줄어드는 것을 알수 있습니다.
이러한 급격한 변화는 TCP 네트워크의 혼잡제어(Congestion Control) 방식과 관련이 있습니다.
TCP 내부에서는 전송한 패킷에 대하여 ACK가 확인되지 않거나 NACK가 발생하는 경우 해당 패킷을 재전송하게 되며,
일정 시간동안 재전송 패킷을 수신할 수 있도록 ‘윈도우’라고 불리는 내부 버퍼의 크기를 증가시키고 대기하게 됩니다.
이렇게 온전한 데이터를 수신할 때까지 추가된 재전송 및 대기 시간 때문에 결과적으로 단위 시간당 전송할 수 있는
패킷의 수가 줄어들게 되며, 이는 대역폭의 감소 현상으로 보이게 되는 것입니다.
실시간 고해상도 영상 전송
영상 파일을 전송하고, 온전한 영상 파일을 획득한 이후 시청한다고 하면 일반적인
파일 전송과 다를바 없습니다. 그러나 영상을 전송하면서 동시에 시청하고자 한다면
사용자가 인지하는 영상 재생 품질의 확보 때문에 영상 전송에서 네트워크 불확실성의
극복은 앞으로도 계속해서 이슈가 될 것으로 생각됩니다.
지연시간, 패킷 유실률, 가용대역폭을 개선하여 네트워크의 불확실성을 줄인다고
하더라도 또 다시 문제가 되는 부분은 고해상도와 고품질이라고 정의한 영상이
얼마나 더 많은 대역폭을 앞으로 요구할 것인가를 알수 없다는 것입니다.
앞선 실험에서 확인한바와 같이 네트워크 혼잡도가 증가하는 경우에는 최종적으로
가용 대역폭의 축소로 나타나며, 수신부에서는 영상 재생에 필요한 데이터를 충분히
확보하지 못하고 버퍼가 비어있는 Underrun 현상이 발생하게 됩니다.
Underrun 상태에서 어떠한 이유로 인하여 혼잡도가 해소 된다면 줄어든 대역폭 때문에
수신부까지 도달하지 못했던 패킷들이 다시 도착을 해서 순서대로 버퍼를 채우다보면
가용한 버퍼의 크기를 초과하는 Overrun 현상을 초래하게 됩니다.
Overrun 상태에서 버퍼의 크기를 초과한 데이터 패킷은 버려지게 되고, 버려진
패킷만큼 또다시 버퍼가 비워지는 상황이 됩니다. 만약 버려진 패킷에 대해서
재전송 요청을 하였다면, 요청된 패킷을 전송하기 위해서 더 많은 대역폭을 사용하게
됩니다. 즉, Overrun과 Underrun의 발생은 무엇이 먼저 발생을 하였던 서로간의
트리거로 작용을 하게 됩니다.
실시간 영상 전송 중에 발생한 Underrun과 Overrun은 단순히 영상 품질의 저하
뿐만아니라 영상 재생 자체가 단절되는 현상으로 나타나며, 이를 방지하기 위한
방법은 불확실성 척도를 결정하는 요소와 관련된 문제를 해소하는 것입니다.
그러나 대역폭, 딜레이, 패킷 유실률 이 세가지 요소 중에 딜레이 요소는 네트워크
인프라스트럭처와 관련된 항목이기 때문에 소프트웨어 입장에서는 개선점을 찾기란
쉽지 않으며, 대역폭은 영상 품질, 패킷 유실률은 실시간성과 관련되는 요소이기
때문에 실시간 고해상도 영상 전송이라는 과제는 상반된 성질의 요구사항을
수용해야하는 문제라고 정의할 수 있습니다.
대역폭 확보: 낮은 bitrate의 영상 송출 (저해상도/저품질)
패킷 유실률: 재전송을 위한 충분한 버퍼 확보 (지연시간 증가)
혼잡제어 개선과 실시간 고해상도 영상 전송
불확실성 척도의 요소 중 대역폭과 패킷 유실률에 대해서 좀더 고민을 해본다면
대역폭의 변화는 결국 유실한 패킷에 대한 처리 방법 때문에 발생하는 것이라고
단순화할 수 있습니다. 또한 영상 전송에 한정하여 본다면 앞서 제시한대로 유실한
패킷을 모두 온전하게 다시 받아와야하는 것은 아니고, 경우에 따라서는 무시하고
진행을 할수 있다는 것이 결국 실시간 고해상도 영상 전송의 실마리가 됩니다.
UDP 기반의 SRT(Secure Reliable Transport)는
자체적인 혼잡 제어 방식을 가지고 있는 데이터 전송 프로토콜 중에 하나입니다.
SRT가 혼잡 제어에 공헌하고 있는 방식은 크게 두가지 입니다. 첫번째는 사용자가
인지하는 지연 시간 내에서 전송 버퍼를 운용하는 방법이고, 두번째는 유실된 패킷을
전송하는 전략입니다.
SRT에서 사용하고 있는 전송 단위는 헤더를 포함하여 1,472 bytes 이며 이를 Chunk의
값으로 사용하였습니다. 계산결과에 따르면 FCW는 25,475 packets 로 나타나고, 이는 약
300 Mbits (≈ 25,475 packets * 1472 bytes / packet * 8 bits / byte)를 의미합니다
즉, 이 네트워크의 경우 송신자가 데이터를 보내고, ACK를 수신하기 전까지
300Mbits의 데이터가 네트워크 상에 머무르고 있다는 것을 의미하며, 한번에 최대
300Mbits의 연속된 데이터를 전송과정에서 유실할 수 있다는 것을 의미하기도 합니다.
그렇기 때문에 SRT는 유실한 패킷을 재전송하기 위해 최소 버퍼로 FCW 크기보다 더 큰
값의 전송 버퍼를 유지할 것을 권장하고 있습니다.
Packet delivery
SRT 전송 방법은 패킷을 유실한 경우에 TSBPD(TimeStamp-Based Packet Delivery)와
TLPD(Too-Late Packet Drop)라는 두가지 전략을 통해서 패킷을 재전송하거나 재전송을
포기하는 방식을 취할 수 있습니다.
이 두가지 전송 전략은 실시간 영상 전송에 매우 효과적인 방식으로, 전송하는
데이터(패킷)을 원하는 시간에 사용할 수 있는가를 지표로 동작하도록
설계되어있습니다.
영상은 프레임 단위로 디코딩을 하게 되며, 하나의 프레임을 완성할 수 있을 때까지
데이터를 버퍼에 보관하고 있습니다. 한 프레임을 구성하는 패킷 중 일부가 유실된
경우, 해당 프레임을 재생할때까지 남은 시간보다 재 전송 시간이 짧으면 재전송을
요구하여 온전한 프레임을 구성하고, 반대의 경우라면 재전송 자체를 포기하거나
재전송이 진행 중에 있더라도 도착한 패킷을 버리는 전략을 수행하여 송/수신 버퍼를
효율적으로 운영하고 있습니다.
TSBPD: Timestamp-based packet delivery
TLPD: Too-Late packet drop
고해상도 영상 전송 실험
다음은 5%의 패킷 유실 환경에서 각기 다른 프로토콜을 이용하여 4K 영상을 송출한
결과입니다.
왼쪽 상단부터 시계방향으로 1)원본, 2)SRT 전송, 3)WebRTC(STUN), 4)RTSP 전송에
따른 영상 품질 결과 입니다. 패킷 유실률이 5%인 경우 SRT를 이용한 전송만 유일하게
영상 식별이 가능함을 알수 있습니다.
또한 SRT를 기반으로 하는 실시간 영상 전송 플랫폼인 황새울
프로젝트의 데모에서는
실제 비행하는 드론에서 RTSP와 SRT를 이용하여 동시에 영상을 전송하였을 응답
속도와 영상 품질 확보면에서 SRT가 유리함을 보여주고 있습니다.
TCP/IP의 특성상 데이터를 전송할 때, 각 패킷이 목적지까지 도달하기까지 어떠한 경로를 이용하는지 알기는 쉽지 않습니다. 목적지가 정해진 경우에는 대개 ping 명령을 이용하여 ICMP(Internet Control Message Protocol)를 통해 간단한 테스트를 수행할 수는 있으나, 명칭에서 유추할 수 있듯, 데이터가 전달되는 프로토콜인 UDP 혹은 TCP와는 별개의 프로토콜을 사용하는 것이기 때문에 실제 데이터를 전송할때 특성은 ping에서 보여준 결과와 다르게 나타날 수 있습니다. 이러한 경우를 종단간 (end-to-end) 네트워크 상태에 대해서 예측이 불가능하다고 이야기하고 있으며 대게 다음과 같은 조건에서 불확실성은 더 높아지게 됩니다.
대역폭이 현저하게 큰 경우 (>= 1Gbps)
네트워크 경로가 긴 경우 (Hop의 수가 많아 패킷 도달 시간이 늘어나는 경우)
경로 내에 불특정 다수가 사용하는 무선 네트워크가 포함된 경우
불안정한 네트워크라는 추상적인 용어는 결국, 전달하고자 하는 데이터가 원하는 시간안에 도착하지 못함을 의미하게 됩니다. 네트워크 상에 가용한 대역폭이 증가하면서 예상치 못한 문제들이 발생하게 되는데, 이 문제는 이미 BDP(Bandwidth-Delay Product)로 정의되어 ACK 혹은 NACK 없이 네트워크 상에 떠돌게 되는 데이터의 양이 불확실성을 야기한다고 설명하고 있습니다.
본 글에서는 네트워크 상태를 판단할때 패킷 유실율을 고려하여 불확실성의 척도를 정의하고자 합니다. 불확실성의 척도는 위 세가지 조건을 각각 대역폭(B), 딜레이(D), 패킷 유실률(L)로 단순화하여 그 세기(Strength) 값으로 환산할 수 있습니다.
불확실성 척도 = B × D × w (1 + L)
위와 같이 정의한 불확실성의 척도를 이용하여 두 네트워크 상태를 비교한다면 다음과 같이 됩니다.
경로 A
경로 B
대역폭 (B)
1 Gbps
500Mbps
딜레이 (D)
20 ms
30 ms
패킷유실률 (L)
1%
2%
불확실성 척도
20,200
15,300
패킷 유실률을 얼마나 큰 요소로 간주할 것이냐에 따라 가중치인 w 값을 조절할 수 있으나, 문제를 단순화하기 위해서 1의 값을 가지는 것으로 하였습니다.
위 테이블에서 계산된 값은 경로 A가 경로 B보다 더 큰값을 가지게 되는데 이를 정의한 불확실성의 척도 개념에서 해석하자면, 경로 A가 좀 더 강한 세기의 불확실성을 가지고 있다고 말할 수 있습니다.
이 값은 통상적으로 대역폭이 높고 종단간 딜레이가 적다는 것이 데이터 전송에 유리할 것으로 여겨지는 것과는 상반되는 내용일 수 있습니다. 그러나 여기서 주의해야할 점은 불확실성의 척도는 단순히 두 네트워크의 상태를 비교하기 위한 개념일뿐이며, 상태의 좋고 나쁨을 의미하는 것은 아니라는 것입니다.
전송 관점에서 고품질 영상
영상 전송이 원할하게 잘 되고 있다는 판단을 할때는 시각적으로 보여지는 정보에 따라 주관적으로 판단하는 경우가 많습니다. 예를들어 FHD와 UHD, 혹은 10fps와 60fps 라는 단순 영상 속성 정보를 제공했을때, 당연하게도 해상도가 더 큰 UHD와 움직임이 부드럽게 보일것이라고 예상되는 60fps가 더 높은 품질의 영상일 것이라고 예상할 수 있습니다.
그러나 실시간 영상 송출하는 경우에는 영상 속성으로는 품질을 정의할 수 없는 한계가 있습니다.
위 두 명령은 각각 ffmpeg과 GStreamer를 이용하여, Apple Mac의 카메라 인터페이스를 이용하여 영상을 획득하고 x264 라이브러리를 이용하여 H.264로 영상 압축을 수행한 뒤 mp4 포맷으로 레코딩을 수행하는 것입니다.
ffmpeg의 경우에는 약간 모호하지만, GStreamer 명령을 통해서 본다면 영상의 해상도, 프레임 수는 카메라에서 원본 영상을 얻는 것과 관련 있는 속성임을 쉽게 유추할 수 있습니다. 다만 주목할 만한 것은 인코딩 부분의 bitrate 입니다. 위 두 명령모두 2Mbps를 대역폭으로 설정하였는데, 이는 영상 인코딩 후 출력 대역폭을 의미합니다.
즉, 카메라 부분의 해상도, 프레임 수 등의 변경은 인코더의 입력 데이터 양과 관련이 있기 때문에, 인코더 출력 대역폭 설정을 변경하지 않고 해상도 등의 속성을 변경한다면 높은 해상도에서도 낮은 품질의 영상을 얻게 됩니다. 반면에 카메라의 속성을 변경하지 않고 인코더의 출력 대역폭을 증가시키면 보다 원본에 가까운 고품질의 영상을 획득 할 수 있습니다.
여러가지 복잡한 상황을 모두 제외하고 단순화한다면, 고품질 영상을 전송한다는 것은 더 많은 데이터를 전송해야한다는 것을 의미하게 됩니다.
It’s been almost a year and half since Jakub posted the installation document of Hwangsaeul (a.k.a H8L) project. The project members are still rush to develop the project for the various use cases. Although the H8L project is originally designed to support the massive deployment of video surveillance cameras which enable SRT transmission, we found that there is much more potential when we switch the domain to UAV(Unmanned Areial Viehicle) and UGV(Unmanned Ground Vehicle). Therefore, we had to change the overall shape of H8L to optimize for the new targets.
Deprecation of Messages Queue
The major architecture change for the second version of H8L is to remove the dependency on message queue by the deprecation of Chamge. Although the module is good for exchanging complex messages among service components, it is an overkill architecture for real-time video streaming that focuses on video quality and ultra-low latency. In addition, there are lots of message queue based platform so we decided not to keep developing duplicated effort. Instead, we re-designed that each component provides D-Bus API and local settings. Since we removed this component, unfortunately, ABI compatibility with the previous version will not be guaranteed while this project is on-going.
Gaeul: Umbrella repository for streaming agents
Another change is done on the Gaeul. In the previous version, the module was in charge of edge streaming only. However, from the second version, it becomes a set of streaming agents; video source, relay, and even protocol conversion including transcoding. By analogy from the meaning of the word, it would be a very natural change for this module to handle the stream of data and video because Gaeul means babbling brook in Korean.
New Architecture
In new H8L, there are three major repositories; Gaeul, Hwangsae, and Gaeguli.
Hwangsae: SRT relay library
Gaeguli: Video stream source library
Gaeul: A set of video streaming services
Since Gaeul provides all of streaming agents, it will always require Hwangsae and Gaeguli depending on the feature it uses.
Running H8L
Nightly builds are available as binary packages for Ubuntu 20.04.
Note that the PPA provides important packages; libsrt and gst-plugins-bad. Since Ubuntu 20.04 provides slightly old version of those packages, some features like stream-id and SRT option strings are not supported. SRT(=1.4.2) and gst-plugins-bad with some patches that will be provided by newer version of GStreamer should be installed before using H8L features. Using PPA may be more convenient to test and have experience of H8L than building from scratch. Surely, some enhancement patches of SRT and GStreamer are already submitted to the upstream and most of them are landed onto master branch or ready for landing. If you’d like to check the patches, you can refer to our forked repositories; libsrt and gst-plugins-bad.
Source
The first agent of Gaeul is gaeul2-source-agent that is nomally simlilar to stream generator(or simply called as encoder).
$ sudo apt-get install gaeul2-source-agent
Settings
Before running the source agent, we need to set configurations to specify video parameters and SRT options. The settings are consist of two parts; one main configuration and multiple channel configurations.
Main Configuration
This configuration file is an entry point that provide capture device informations to the source agent. For the stream authentication, Stream ID is mandatory for H8L’s source agent and uid will be used for stream-id prefix for channels.
channel-configs option takes a list of absolute file paths that are channel configurations.
This sub-configuration describes what type of SRT stream will be sent from which video capture device. In theory, the source agent can have an infinite number of channel configurations, but it will be limited by hardware performance. Normally, it shouldn’t exceed 2 channels encoding for 4K 30fps, or equivalent video encoding parameters.
The below is an example of a channel configuration.
With uid of a main configuration, name option will be used to compose a stream-id for this channel stream. if device0 is given for the uid and channel0 is for the name, this video channel will have device0_channel0 stream id.
Running
Now, it’s time to run the source agent. If the configurations are provided correctly, user can choose D-Bus mode; session, system and none.
If none is used, the agent will not try to acquire d-bus name. Regardless --dbus-type, it will send stream or trying to connect to the given target-uri of a channel configuration until SRT stream receiver is ready.
If it is suspicious that the source agent sends a stream or not, the easiest way to check is to get log messages. Since all of H8L components follows GLib and GStreamer conventions, it shows log messages by setting two major environmental variables.
Then, now user can get log messages on their console.
Relay
The relay agent plays a role to distribute SRT stream from source to users. It provides stream authentication option to distinguish SRT session by stream-id. Surely, the authentication option can be disabled when it requires the compatiblity with the legacy SRT equipment or software.
Settings
Unlike the source agent, the relay agent has a main configuration only.
uid: a unique id, it is used for identifying each relay service.
sink-port: a network port to be connected from a source agent.
source-port: a network port to be connected from a user or video stream consumer.
sink-latency, source-latency: SRT latency value for each connection.
external-ip: usually, it is used for VM in cloud service that has an external address.
authentication: an option to inteprete SRT streamid or not.
Running
If a configuration file is ready, it can be run with the below command. In a relay service, D-Bus API should be enabled to use a stream authentication feature. Here, it assumes that it uses session-wide D-Bus API.
The relay is relatively simple because of SRT-nature; content agnostic. However, it plays very important role as a live stream distributor. In current implmentation, the relay agent supports only SRT’s live mode.
The relay provides a whitelist-based stream authentication mechanism. That means, the agent should know streamid before attempting to connect. Otherwise, the agent will reject stream connection.
To allow a connection from source agent, the stream-id of source agent must be registered. Here, it assumed that the source agent uses device0_channel0 as its stream-id.
Then, if a user who has the unique id, admin0, wants to get a video stream of the source agent, device0_channel0, a source token should be registered too.
H8L is not all about streaming video over SRT. It is actually designed to overcome unpredictable network in two major concerns. The first is how to stream high-quality video over high bandwidth capable network, and the second is to prevent video stuttering at a discernable level even if the quality is dropped. SRT dealt with the first issue very well by congestion control, but the second issue is complicated. Without media processing and network status prediction, it will be difficult to find solution. Here, we sugguest network adaptive streaming of H8L.
TCP/IP의 특성상 데이터를 전송할 때, 각 패킷이 목적지까지 도달하기까지 어떠한 경로를 이용하는지 알기는 쉽지 않습니다. 목적지가 정해진 경우에는 대개 ping 명령을 이용하여 ICMP(Internet Control Message Protocol)를 통해 간단한 테스트를 수행할 수는 있으나, 명칭에서 유추할 수 있듯, 데이터가 전달되는 프로토콜인 UDP 혹은 TCP와는 별개의 프로토콜을 사용하는 것이기 때문에 실제 데이터를 전송할때 특성은 ping에서 보여준 결과와 다르게 나타날 수 있습니다. 이러한 경우를 종단간 (end-to-end) 네트워크 상태에 대해서 예측이 불가능하다고 이야기하고 있으며 대게 다음과 같은 조건에서 불확실성은 더 높아지게 됩니다.