I want to send frames of a video stream over a network connection, so I have implemented the AVCaptureVideoDataOutputSampleBufferDelegate function:
func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection)
How should I convert the CMSampleBuffer to Data as the NWConnection function:
func send(content: Data?, contentContext: NWConnection.ContentContext = default, isComplete: Bool = default, completion: NWConnection.SendCompletion)
that I'm using for networking expects Data for its content parameter?
You presumably want to compress the video frames before sending them over the network, because uncompressed video frames might require more bandwidth than you have available. And you'll want to use the hardware compressor for speed.
You can access the hardware compressor and decompressor using the VideoToolbox framework.
You should watch WWDC 2014 session 513, “Direct Access to Video Encoding and Decoding”. Here's a quote from the introduction:
You can find a transcript of the session at ASCIIwwdc.