1 // Copyright 2020 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef MEDIA_REMOTING_RECEIVER_CONTROLLER_H_
6 #define MEDIA_REMOTING_RECEIVER_CONTROLLER_H_
10 #include "base/no_destructor.h"
11 #include "base/task/single_thread_task_runner.h"
12 #include "media/mojo/mojom/remoting.mojom.h"
13 #include "mojo/public/cpp/bindings/pending_remote.h"
14 #include "mojo/public/cpp/bindings/receiver.h"
15 #include "mojo/public/cpp/bindings/remote.h"
16 #include "third_party/openscreen/src/cast/streaming/rpc_messenger.h"
21 // ReceiverController is the bridge that owns |rpc_messenger_| to allow
22 // Receivers and StreamProvider::MediaStreams to communicate with the sender via
25 // It also forwards calls to a |media_remotee_| instance, which will be
26 // implemented the browser process. Currently, the only use case will be on
27 // Chromecast, the Remotee implementation will be implemented in the browser
28 // code on Chromecast.
30 // NOTE: ReceiverController is a singleton per process.
31 class ReceiverController : mojom::RemotingSink {
33 static ReceiverController* GetInstance();
34 void Initialize(mojo::PendingRemote<mojom::Remotee> remotee);
36 // Proxy functions to |media_remotee_|.
37 void OnRendererFlush(uint32_t audio_count, uint32_t video_count);
38 void OnVideoNaturalSizeChange(const gfx::Size& size);
39 void StartDataStreams(
40 mojo::PendingRemote<mojom::RemotingDataStreamReceiver> audio_stream,
41 mojo::PendingRemote<mojom::RemotingDataStreamReceiver> video_stream);
43 openscreen::cast::RpcMessenger* rpc_messenger() { return &rpc_messenger_; }
46 friend base::NoDestructor<ReceiverController>;
47 friend class MockReceiverController;
48 friend void ResetForTesting(ReceiverController* controller);
51 ~ReceiverController() override;
53 // media::mojom::RemotingSink implementation.
54 void OnMessageFromSource(const std::vector<uint8_t>& message) override;
56 // Callback for |rpc_messenger_| to send messages.
57 void OnSendRpc(std::vector<uint8_t> message);
59 openscreen::cast::RpcMessenger rpc_messenger_;
61 const scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;
63 mojo::Remote<media::mojom::Remotee> media_remotee_;
64 mojo::Receiver<media::mojom::RemotingSink> receiver_{this};
67 } // namespace remoting
70 #endif // MEDIA_REMOTING_RECEIVER_CONTROLLER_H_