1*3f982cf4SFabien Sanglard // Copyright 2021 The Chromium Authors. All rights reserved. 2*3f982cf4SFabien Sanglard // Use of this source code is governed by a BSD-style license that can be 3*3f982cf4SFabien Sanglard // found in the LICENSE file. 4*3f982cf4SFabien Sanglard 5*3f982cf4SFabien Sanglard #ifndef CAST_STANDALONE_SENDER_REMOTING_SENDER_H_ 6*3f982cf4SFabien Sanglard #define CAST_STANDALONE_SENDER_REMOTING_SENDER_H_ 7*3f982cf4SFabien Sanglard 8*3f982cf4SFabien Sanglard #include <memory> 9*3f982cf4SFabien Sanglard 10*3f982cf4SFabien Sanglard #include "cast/streaming/constants.h" 11*3f982cf4SFabien Sanglard #include "cast/streaming/rpc_messenger.h" 12*3f982cf4SFabien Sanglard 13*3f982cf4SFabien Sanglard namespace openscreen { 14*3f982cf4SFabien Sanglard namespace cast { 15*3f982cf4SFabien Sanglard 16*3f982cf4SFabien Sanglard // This class behaves like a pared-down version of Chrome's StreamProvider (see 17*3f982cf4SFabien Sanglard // https://source.chromium.org/chromium/chromium/src/+/main:media/remoting/stream_provider.h 18*3f982cf4SFabien Sanglard // ). Instead of fully managing a media::DemuxerStream however, it just provides 19*3f982cf4SFabien Sanglard // an RPC initialization routine that notifies the standalone receiver's 20*3f982cf4SFabien Sanglard // SimpleRemotingReceiver instance (if configured) that initialization has been 21*3f982cf4SFabien Sanglard // complete and what codecs were selected. 22*3f982cf4SFabien Sanglard // 23*3f982cf4SFabien Sanglard // Due to the sheer complexity of remoting, we don't have a fully functional 24*3f982cf4SFabien Sanglard // implementation of remoting in the standalone_* components, instead Chrome is 25*3f982cf4SFabien Sanglard // the reference implementation and we have these simple classes to exercise 26*3f982cf4SFabien Sanglard // the public APIs. 27*3f982cf4SFabien Sanglard class RemotingSender { 28*3f982cf4SFabien Sanglard public: 29*3f982cf4SFabien Sanglard // The remoting sender expects a valid client to handle received messages. 30*3f982cf4SFabien Sanglard class Client { 31*3f982cf4SFabien Sanglard public: 32*3f982cf4SFabien Sanglard virtual ~Client(); 33*3f982cf4SFabien Sanglard 34*3f982cf4SFabien Sanglard // Executed when we receive the initialize message from the receiver. 35*3f982cf4SFabien Sanglard virtual void OnReady() = 0; 36*3f982cf4SFabien Sanglard 37*3f982cf4SFabien Sanglard // Executed when we receive a playback rate message from the receiver. 38*3f982cf4SFabien Sanglard virtual void OnPlaybackRateChange(double rate) = 0; 39*3f982cf4SFabien Sanglard }; 40*3f982cf4SFabien Sanglard 41*3f982cf4SFabien Sanglard RemotingSender(RpcMessenger* messenger, 42*3f982cf4SFabien Sanglard AudioCodec audio_codec, 43*3f982cf4SFabien Sanglard VideoCodec video_codec, 44*3f982cf4SFabien Sanglard Client* client); 45*3f982cf4SFabien Sanglard ~RemotingSender(); 46*3f982cf4SFabien Sanglard 47*3f982cf4SFabien Sanglard private: 48*3f982cf4SFabien Sanglard // Helper for parsing any received RPC messages. 49*3f982cf4SFabien Sanglard void OnMessage(const RpcMessage& message); 50*3f982cf4SFabien Sanglard void OnInitializeMessage(const RpcMessage& message); 51*3f982cf4SFabien Sanglard void OnPlaybackRateMessage(const RpcMessage& message); 52*3f982cf4SFabien Sanglard 53*3f982cf4SFabien Sanglard // The messenger is the only caller of OnInitializeMessage, so there are no 54*3f982cf4SFabien Sanglard // lifetime concerns. However, if this class outlives |messenger_|, it will 55*3f982cf4SFabien Sanglard // no longer receive initialization messages. 56*3f982cf4SFabien Sanglard RpcMessenger* messenger_; 57*3f982cf4SFabien Sanglard 58*3f982cf4SFabien Sanglard // Unlike in Chrome, here we should know the video and audio codecs before any 59*3f982cf4SFabien Sanglard // of the remoting code gets set up, and for simplicity's sake we can only 60*3f982cf4SFabien Sanglard // populate the AudioDecoderConfig and VideoDecoderConfig objects with the 61*3f982cf4SFabien Sanglard // codecs and use the rest of the fields as-is from the OFFER/ANSWER exchange. 62*3f982cf4SFabien Sanglard const AudioCodec audio_codec_; 63*3f982cf4SFabien Sanglard const VideoCodec video_codec_; 64*3f982cf4SFabien Sanglard 65*3f982cf4SFabien Sanglard Client* client_; 66*3f982cf4SFabien Sanglard 67*3f982cf4SFabien Sanglard // The initialization message from the receiver contains the handle the 68*3f982cf4SFabien Sanglard // callback should go to. 69*3f982cf4SFabien Sanglard RpcMessenger::Handle receiver_handle_ = RpcMessenger::kInvalidHandle; 70*3f982cf4SFabien Sanglard }; 71*3f982cf4SFabien Sanglard 72*3f982cf4SFabien Sanglard } // namespace cast 73*3f982cf4SFabien Sanglard } // namespace openscreen 74*3f982cf4SFabien Sanglard 75*3f982cf4SFabien Sanglard #endif // CAST_STANDALONE_SENDER_REMOTING_SENDER_H_ 76