xref: /aosp_15_r20/external/openscreen/cast/standalone_receiver/simple_remoting_receiver.h (revision 3f982cf4871df8771c9d4abe6e9a6f8d829b2736)
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_RECEIVER_SIMPLE_REMOTING_RECEIVER_H_
6 #define CAST_STANDALONE_RECEIVER_SIMPLE_REMOTING_RECEIVER_H_
7 
8 #include <functional>
9 #include <memory>
10 
11 #include "cast/streaming/constants.h"
12 #include "cast/streaming/rpc_messenger.h"
13 
14 namespace openscreen {
15 namespace cast {
16 
17 // This class behaves like a pared-down version of Chrome's DemuxerStreamAdapter
18 // (see
19 // https://source.chromium.org/chromium/chromium/src/+/main:/media/remoting/demuxer_stream_adapter.h
20 // ). Instead of providing a full adapter implementation, it just provides a
21 // callback register that can be used to notify a component when the
22 // RemotingProvider sends an initialization message with audio and video codec
23 // information.
24 //
25 // Due to the sheer complexity of remoting, we don't have a fully functional
26 // implementation of remoting in the standalone_* components, instead Chrome is
27 // the reference implementation and we have these simple classes to exercise
28 // the public APIs.
29 class SimpleRemotingReceiver {
30  public:
31   explicit SimpleRemotingReceiver(RpcMessenger* messenger);
32   ~SimpleRemotingReceiver();
33 
34   // The flow here closely mirrors the remoting.proto. The standalone receiver
35   // indicates it is ready for initialization by calling
36   // |SendInitializeMessage|, then this class sends an initialize message to the
37   // sender. The sender then replies with an initialization message containing
38   // configurations, which is passed to |initialize_cb|.
39   using InitializeCallback = std::function<void(AudioCodec, VideoCodec)>;
40   void SendInitializeMessage(InitializeCallback initialize_cb);
41 
42   // The speed at which the content is decoded is synchronized with the
43   // playback rate. Pausing is a special case with a playback rate of 0.0.
44   void SendPlaybackRateMessage(double playback_rate);
45 
46  private:
47   void OnInitializeCallbackMessage(std::unique_ptr<RpcMessage> message);
48 
49   RpcMessenger* messenger_;
50   InitializeCallback initialize_cb_;
51 };
52 
53 }  // namespace cast
54 }  // namespace openscreen
55 
56 #endif  // CAST_STANDALONE_RECEIVER_SIMPLE_REMOTING_RECEIVER_H_
57