GCKMetalVideoFrameInput Class

GCKMetalVideoFrameInput Class Reference

Overview

Specialization of GCKVideoFrameInput for Metal.

This video frame input makes it easier to integrate a Metal renderer with Remote Display by providing a fast (but somewhat inaccurate) color space conversion pipeline. Apps that wish to have full control over this process must use the session object directly to dequeue video frame buffers and enqueue them for encoding and transmission once rendered.

See also
GCKRemoteDisplaySession

Initialization

Once a Remote Display session has been negotiated, initialize a frame input with it and set the Metal device property. The frame input will synchronously create all of its required resources in the property setter. Finally, set up the Metal rendering code for Remote Display, creating a 2D texture matching the size of the Remote Display video stream as the final render target. The texture format must be color renderable and must support bilinear filtering.

Producing a frame

To produce a Remote Display frame, first render the frame then call encodeFrame:commandBuffer: with the render target texture and the command buffer. The frame input will encode 2 render passes to perform color space conversion and add a command buffer completion block to encode and transmit the frame once the GPU is done rendering.

Inherits GCKVideoFrameInput.

Instance Method Summary

(void) - encodeFrame:commandBuffer:
 Encode commands to process and transmit a frame. More...
 
(instancetype) - initWithSession:
 Initialize a new video frame input bound to the specified session. More...
 
(instancetype) - NS_UNAVAILABLE
 

Properties

id< MTLDevice > device
 The Metal device to use for resource allocations. More...
 
matrix_float3x3 textureCoordinateMatrix
 Transform matrix applied to the texture coordinates of enqueued frames. More...
 
id< GCKRemoteDisplaySessionsession
 Remote Display session the input is bound to. More...
 
uint32_t width
 Width of the session's video stream. More...
 
uint32_t height
 Height of the session's video stream. More...
 

Method Detail

- (void) encodeFrame: (id< MTLTexture >)  texture
commandBuffer: (id< MTLCommandBuffer >)  commandBuffer 

Encode commands to process and transmit a frame.

The frame input will encode 2 render passes in the specified command buffer to convert the frame to Y'CbCr with 4:2:0 chroma subsampling. It will also register a command buffer completion handler that will enqueue the frame for compression and transmission. The presentation timestamp of the frame will be the result of CACurrentMediaTime when the completion handler executes.

If anything goes wrong, such as if the session runs out of video frame buffers or the texture cannot be sampled, the frame is dropped.

The texture's size must match the drawable size and it must support bilinear filtering. The same texture can be used each frame since its content does not need to remain unchanged.

- (instancetype) initWithSession: (id< GCKRemoteDisplaySession >)  session

Initialize a new video frame input bound to the specified session.

Property Documentation

- (id<MTLDevice>) device
readwritenonatomicassign

The Metal device to use for resource allocations.

Changing this property reallocates resources synchronously and can take some amount of time. Setting the device to nil will immediately free all allocated resources.

- (matrix_float3x3) textureCoordinateMatrix
readwritenonatomicassign

Transform matrix applied to the texture coordinates of enqueued frames.

This matrix is applied to the normalized texture coordinates used to sample enqueued frames during the color space conversion rendering passes encoded by this frame input. It can be more efficient to use this property than to perform the transform as a separate rendering pass.

For example, to perform a y-flip, set the following matrix (here as an array of column vectors): { {1.0, 0.0, 0.0}, {0.0, -1.0, 0.0}, {0.0, 1.0, 0.0} }

Defaults to the identity matrix.

- (id<GCKRemoteDisplaySession>) session
readnonatomicweakinherited

Remote Display session the input is bound to.

- (uint32_t) width
readnonatomicassigninherited

Width of the session's video stream.

- (uint32_t) height
readnonatomicassigninherited

Height of the session's video stream.

Google Cast iOS Sender API Reference v 2.10.1 4691