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