Analog video is still used in many systems today where low latency is crucial. One good example is racing FPV systems.
Due to lack of complete USB On-The-Go (OTG) support in iOS, there is no other way than capture analog video over Wi-Fi through special video encoding device like WIFI AVIN 903W. It receives AV signal on input, encodes video and broadcasts it into Wi-Fi network using a proprietary protocol. WIFI AVIN 903W protocol uses UDP on the transport layer and H264 standard for video compression.
This repository contains sample application that demonstrates work with WIFI AVIN 903W proprietary protocol.
The source code contains 5 major components:
IncomingPacket
andOutgoingPacket
protocols and implementations - represent packets that could be received or sent over WIFI AVIN 903W proprietary protocolSocket
protocol andUDPSocket
class - a simple wrapper around BSD socket. Uses blockingrecvfrom
in a separate thread to receive data and non-blockingsendto
to send.NaluBuffer
protocol andRawH264NaluBuffer
class - buffer that accumulates packets until complete NALU is receivedVideoStreamConverter
protocol andElementaryVideoStreamConverter
class - converts elementary stream (Annex B) to AVCC format and returnsCMSampleBuffers
NetworkVideoStream
protocol andW903NetworkVideoStream
class - composes elements into complete system, analyzes incoming packets and sends appropriate responses
Before use this code in production consider the following steps:
- Move stream parsing and conversion to a background thread (you can configure
UDPSocket
with custom delegationDispatchQueue
for this purpose) - Decrease number of memory allocations/deallocations during packet receiving and conversion (reuse same
UnsafeMutableBufferPointer
) - Consider setting presentation timestamp of resulting
CMSampleBuffers
for smoother video output - Handle player restart on the protocol level (process already stacked frames)
- Add WIFI AVIN 903W settings configuration support
- Improve error handling (remove usage of forced-try at least)
- Make
NaluBuffer
implementation conform toSequence
and/orCollection
protocols to be legitimate Swift citizen
This sample project is distributed under the MIT license. See LICENSE for details.