OLD | NEW |
| (Empty) |
1 // Copyright 2016 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 MEDIA_REMOTING_REMOTING_CONTROLLER_H_ | |
6 #define MEDIA_REMOTING_REMOTING_CONTROLLER_H_ | |
7 | |
8 #include "base/callback.h" | |
9 #include "base/memory/weak_ptr.h" | |
10 #include "media/base/media_observer.h" | |
11 #include "media/mojo/interfaces/remoting.mojom.h" | |
12 #include "mojo/public/cpp/bindings/binding.h" | |
13 | |
14 namespace base { | |
15 class SingleThreadTaskRunner; | |
16 } | |
17 | |
18 // This class does the following: | |
19 // 1) Sends/Receives messages from/to Remoter; | |
20 // 2) Monitors player events as a MediaObserver; | |
21 // 3) May trigger the switch of the media renderer between local playback | |
22 // and remoting. | |
23 // | |
24 namespace media { | |
25 | |
26 class RemotingController final : public MediaObserver, | |
27 public mojom::RemotingSource { | |
28 public: | |
29 RemotingController(mojom::RemotingSourceRequest source_request, | |
30 mojom::RemoterPtr remoter); | |
31 ~RemotingController() override; | |
32 | |
33 // RemotingSource implementations. | |
34 void OnSinkAvailable() override; | |
35 void OnSinkGone() override; | |
36 void OnStarted() override; | |
37 void OnStartFailed(mojom::RemotingStartFailReason reason) override; | |
38 void OnMessageFromSink(const std::vector<uint8_t>& message) override; | |
39 void OnStopped(mojom::RemotingStopReason reason) override; | |
40 | |
41 // MediaObserver implementations. | |
42 // This is called when the video element or its ancestor enters full screen. | |
43 // We currently use this as an indicator for immersive playback. May add other | |
44 // criteria (e.g. the actual display width/height of the video element) in | |
45 // future. | |
46 void OnEnteredFullscreen() override; | |
47 void OnExitedFullscreen() override; | |
48 void OnSetCdm(CdmContext* cdm_context) override; | |
49 void OnMetadataChanged(const PipelineMetadata& metadata) override; | |
50 | |
51 using SwitchRendererCallback = base::Callback<void()>; | |
52 void SetSwitchRendererCallback(const SwitchRendererCallback& cb); | |
53 | |
54 // Tells which renderer should be used. | |
55 bool is_remoting() const { | |
56 DCHECK(task_runner_->BelongsToCurrentThread()); | |
57 return is_remoting_; | |
58 } | |
59 | |
60 base::WeakPtr<RemotingController> GetWeakPtr() { | |
61 return weak_factory_.GetWeakPtr(); | |
62 } | |
63 | |
64 private: | |
65 bool IsVideoCodecSupported(); | |
66 bool IsAudioCodecSupported(); | |
67 | |
68 // Helper to decide whether to enter or leave Remoting mode. | |
69 bool ShouldBeRemoting(); | |
70 | |
71 // Determines whether to enter or leave Remoting mode and switches if | |
72 // necessary. | |
73 void UpdateAndMaybeSwitch(); | |
74 | |
75 // Indicates if this media element or its ancestor enters full screen. | |
76 bool is_fullscreen_ = false; | |
77 | |
78 // Indicates the remoting sink availablity. | |
79 bool is_sink_available_ = false; | |
80 | |
81 // Indicates if remoting is started. | |
82 bool is_remoting_ = false; | |
83 | |
84 // Indicates whether audio or video is encrypted. | |
85 bool is_encrypted_ = false; | |
86 | |
87 // Current audio/video config. | |
88 VideoDecoderConfig video_decoder_config_; | |
89 AudioDecoderConfig audio_decoder_config_; | |
90 bool has_audio_ = false; | |
91 bool has_video_ = false; | |
92 | |
93 // The callback to switch the media renderer. | |
94 SwitchRendererCallback switch_renderer_cb_; | |
95 | |
96 mojo::Binding<mojom::RemotingSource> binding_; | |
97 mojom::RemoterPtr remoter_; | |
98 | |
99 // TODO(xjz): Add a media thread task runner for the received RPC messages for | |
100 // remoting media renderer in the up-coming change. | |
101 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | |
102 | |
103 base::WeakPtrFactory<RemotingController> weak_factory_; | |
104 | |
105 DISALLOW_COPY_AND_ASSIGN(RemotingController); | |
106 }; | |
107 | |
108 } // namespace media | |
109 | |
110 #endif // MEDIA_REMOTING_REMOTING_CONTROLLER_H_ | |
OLD | NEW |