Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Side by Side Diff: media/remoting/remoting_controller.h

Issue 2389473002: Media Remoting: Add RemotingController. (Closed)
Patch Set: Use BUILDFLAG. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 OnMetadata(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 IsVideoConfigSupported();
66 bool IsAudioConfigSupported();
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 // Current audio/video config.
85 VideoDecoderConfig video_decoder_config_;
86 AudioDecoderConfig audio_decoder_config_;
87 bool has_audio_ = false;
88 bool has_video_ = false;
89
90 // The callback to switch the media renderer.
91 SwitchRendererCallback switch_renderer_cb_;
92
93 mojo::Binding<mojom::RemotingSource> binding_;
94 mojom::RemoterPtr remoter_;
95
96 // TODO(xjz): Add a media thread task runner for the received RPC messages for
97 // remoting media renderer in the up-coming change.
98 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
99
100 base::WeakPtrFactory<RemotingController> weak_factory_;
101
102 DISALLOW_COPY_AND_ASSIGN(RemotingController);
103 };
104
105 } // namespace media
106
107 #endif // MEDIA_REMOTING_REMOTING_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698