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:
IncomingPacketandOutgoingPacketprotocols and implementations - represent packets that could be received or sent over WIFI AVIN 903W proprietary protocolSocketprotocol andUDPSocketclass - a simple wrapper around BSD socket. Uses blockingrecvfromin a separate thread to receive data and non-blockingsendtoto send.NaluBufferprotocol andRawH264NaluBufferclass - buffer that accumulates packets until complete NALU is receivedVideoStreamConverterprotocol andElementaryVideoStreamConverterclass - converts elementary stream (Annex B) to AVCC format and returnsCMSampleBuffersNetworkVideoStreamprotocol andW903NetworkVideoStreamclass - 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
UDPSocketwith custom delegationDispatchQueuefor this purpose) - Decrease number of memory allocations/deallocations during packet receiving and conversion (reuse same
UnsafeMutableBufferPointer) - Consider setting presentation timestamp of resulting
CMSampleBuffersfor 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
NaluBufferimplementation conform toSequenceand/orCollectionprotocols to be legitimate Swift citizen
This sample project is distributed under the MIT license. See LICENSE for details.

