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

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

Issue 2406483002: WIP - Add EME (Closed)
Patch Set: Addressed miu's comments. Added more tests. Created 4 years, 1 month 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MEDIA_REMOTING_REMOTING_CONTROLLER_H_ 5 #ifndef MEDIA_REMOTING_REMOTING_RENDERER_CONTROLLER_H_
6 #define MEDIA_REMOTING_REMOTING_CONTROLLER_H_ 6 #define MEDIA_REMOTING_REMOTING_RENDERER_CONTROLLER_H_
7 7
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
10 #include "media/base/media_observer.h" 10 #include "media/base/media_observer.h"
11 #include "media/mojo/interfaces/remoting.mojom.h" 11 #include "media/remoting/remoting_source_impl.h"
12 #include "mojo/public/cpp/bindings/binding.h"
13 12
14 namespace base { 13 namespace media {
15 class SingleThreadTaskRunner; 14 struct PipelineMetadata;
16 } 15 }
17 16
18 // This class does the following: 17 namespace media {
19 // 1) Sends/Receives messages from/to Remoter; 18
19 // This class:
20 // 1) Implements the RemotingSourceImpl::Client;
20 // 2) Monitors player events as a MediaObserver; 21 // 2) Monitors player events as a MediaObserver;
21 // 3) May trigger the switch of the media renderer between local playback 22 // 3) May trigger the switch of the media renderer between local playback
22 // and remoting. 23 // and remoting.
23 // 24 class RemotingRendererController final : public RemotingSourceImpl::Client,
24 namespace media { 25 public MediaObserver {
26 public:
27 explicit RemotingRendererController(
28 scoped_refptr<RemotingSourceImpl> remoting_source);
29 ~RemotingRendererController() override;
25 30
26 class RemotingController final : public MediaObserver, 31 // RemotingSourceImpl::Client implemenations.
27 public mojom::RemotingSource { 32 void OnStarted(bool success) override;
28 public: 33 void OnSessionStateChanged() override;
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 34
41 // MediaObserver implementations. 35 // 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; 36 void OnEnteredFullscreen() override;
47 void OnExitedFullscreen() override; 37 void OnExitedFullscreen() override;
48 void OnSetCdm(CdmContext* cdm_context) override; 38 void OnSetCdm(CdmContext* cdm_context) override;
49 void OnMetadataChanged(const PipelineMetadata& metadata) override; 39 void OnMetadataChanged(const PipelineMetadata& metadata) override;
50 40
51 using SwitchRendererCallback = base::Callback<void()>; 41 void SetSwitchRendererCallback(const base::Closure& cb);
52 void SetSwitchRendererCallback(const SwitchRendererCallback& cb);
53 42
54 // Tells which renderer should be used. 43 base::WeakPtr<RemotingRendererController> GetWeakPtr() {
55 bool is_remoting() const { 44 return weak_factory_.GetWeakPtr();
56 DCHECK(task_runner_->BelongsToCurrentThread());
57 return is_remoting_;
58 } 45 }
59 46
60 base::WeakPtr<RemotingController> GetWeakPtr() { 47 // Used by RemotingRendererFactory to query whether to create Media Remoting
61 return weak_factory_.GetWeakPtr(); 48 // Renderer.
62 } 49 bool IsRenderingRemotely() const;
50
51 // Used by RemotingRendererFactory to query whether the remoting session is
52 // permanently terminated.
53 bool IsTerminated() const;
63 54
64 private: 55 private:
65 bool IsVideoCodecSupported(); 56 bool IsVideoCodecSupported();
66 bool IsAudioCodecSupported(); 57 bool IsAudioCodecSupported();
67 58
68 // Helper to decide whether to enter or leave Remoting mode. 59 // Helper to decide whether to enter or leave Remoting mode.
69 bool ShouldBeRemoting(); 60 bool ShouldBeRemoting();
70 61
71 // Determines whether to enter or leave Remoting mode and switches if 62 // Determines whether to enter or leave Remoting mode and switches if
72 // necessary. 63 // necessary.
73 void UpdateAndMaybeSwitch(); 64 void UpdateAndMaybeSwitch();
74 65
75 // Indicates if this media element or its ancestor enters full screen. 66 // Indicates whether this media element or its ancestor is in full screen.
76 bool is_fullscreen_ = false; 67 bool is_fullscreen_ = false;
77 68
78 // Indicates the remoting sink availablity. 69 // Indicates whether remoting is started.
79 bool is_sink_available_ = false; 70 bool remote_rendering_started_ = false;
80 71
81 // Indicates if remoting is started. 72 // Indicates whether the remoting session is permanently terminated.
82 bool is_remoting_ = false; 73 bool session_permanently_terminated_ = false;
74
75 // Indicates whether remoting session can be started.
76 bool session_can_remote_ = false;
83 77
84 // Indicates whether audio or video is encrypted. 78 // Indicates whether audio or video is encrypted.
85 bool is_encrypted_ = false; 79 bool is_encrypted_ = false;
86 80
87 // Current audio/video config. 81 // Current audio/video config.
88 VideoDecoderConfig video_decoder_config_; 82 VideoDecoderConfig video_decoder_config_;
89 AudioDecoderConfig audio_decoder_config_; 83 AudioDecoderConfig audio_decoder_config_;
90 bool has_audio_ = false; 84 bool has_audio_ = false;
91 bool has_video_ = false; 85 bool has_video_ = false;
92 86
93 // The callback to switch the media renderer. 87 // The callback to switch the media renderer.
94 SwitchRendererCallback switch_renderer_cb_; 88 base::Closure switch_renderer_cb_;
95 89
96 mojo::Binding<mojom::RemotingSource> binding_; 90 // This is initially the RemotingSourceImpl passed to the ctor, and might be
97 mojom::RemoterPtr remoter_; 91 // replaced with a different instance later if OnSetCdm() is called.
92 scoped_refptr<RemotingSourceImpl> remoting_source_;
98 93
99 // TODO(xjz): Add a media thread task runner for the received RPC messages for 94 // This is used to check all the methods are called on the current thread in
100 // remoting media renderer in the up-coming change. 95 // debug builds.
101 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 96 base::ThreadChecker thread_checker_;
102 97
103 base::WeakPtrFactory<RemotingController> weak_factory_; 98 base::WeakPtrFactory<RemotingRendererController> weak_factory_;
104 99
105 DISALLOW_COPY_AND_ASSIGN(RemotingController); 100 DISALLOW_COPY_AND_ASSIGN(RemotingRendererController);
106 }; 101 };
107 102
108 } // namespace media 103 } // namespace media
109 104
110 #endif // MEDIA_REMOTING_REMOTING_CONTROLLER_H_ 105 #endif // MEDIA_REMOTING_REMOTING_RENDERER_CONTROLLER_H_
OLDNEW
« no previous file with comments | « media/remoting/remoting_controller_unittest.cc ('k') | media/remoting/remoting_renderer_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698