The Cast protocol involves a sequence of interactions between a Sender device and a Receiver device to establish a connection, launch an application, and stream media. This document provides a high-level overview of this flow.
The key stages are:
The following diagram illustrates the typical message flow.
+--------------+ +----------------+ | Sender Device| | Receiver Device| +--------------+ +----------------+ | | |------------- 1. Discovery (mDNS) ----------------->| | (sends mDNS query for Cast devices) | | | |<--------------- (responds with mDNS record) -------| | | |------------ 2. Connection Establishment ---------->| | (establishes TCP connection) | | | |--------------- (TLS Handshake) ------------------->| |<-------------- (TLS Handshake) --------------------| | | |---------- (CastV2 Channel Handshake) ------------->| | (Auth, Device Capabilities) | | | |--------- 3. Application Launch ------------------->| | (sends LAUNCH message) | | +---| | (launches app) | | +-->| |<----------- (reports App status, session ID) ------| | | |------------ 4. Streaming Setup ------------------->| | (sends OFFER message) | | | |<----------- (responds with ANSWER message) --------| | | |-------------- 5. Media Streaming ----------------->| | (streams RTP/RTCP packets via UDP) | | | | | |<-------------- (sends RTCP feedback) --------------| | | |------------ (Ongoing Control Messages) ----------->| | (e.g., PAUSE) | | | |----------------- 6. Teardown --------------------->| | (sends STOP message or disconnects) | | +---| | (ends session) | | +---|
_googlecast._tcp.local.A minimal mDNS record for a Cast device, named Living Room, is shown below. For more details on how this record is parsed, see DnsSdInstanceEndpointToReceiverInfo() in cast/common/public/receiver_info.cc.
_googlecast._tcp.local. 86400 IN PTR LivingRoom.local. LivingRoom.local. 86400 IN SRV 0 0 8009 LivingRoom.local. LivingRoom.local. 86400 IN A 192.168.1.100 LivingRoom.local. 86400 IN TXT "id=<unique_id>" "ve=02" "ca=5" "fn=Living Room" "st=0" "md=Chromecast"
LAUNCH message to the Receiver, requesting it to start a specific application (identified by an App ID).sessionId.OFFER/ANSWER exchange.STOP message to terminate the application on the Receiver, or simply closes the connection.