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

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

Issue 2457563002: Media Remoting: Add remoting control logic for encrypted contents. (Closed)
Patch Set: Addressed comments. 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 {
56 DCHECK(task_runner_->BelongsToCurrentThread());
57 return is_remoting_;
58 }
59
60 base::WeakPtr<RemotingController> GetWeakPtr() {
61 return weak_factory_.GetWeakPtr(); 44 return weak_factory_.GetWeakPtr();
62 } 45 }
63 46
47 // Used by RemotingRendererFactory to query whether to create Media Remoting
48 // Renderer.
49 bool remote_rendering_started() const {
50 DCHECK(thread_checker_.CalledOnValidThread());
51 return remote_rendering_started_;
52 }
53
54 // Used by RemotingRendererImpl to query the session state.
55 RemotingSourceImpl* remoting_source() const {
56 DCHECK(thread_checker_.CalledOnValidThread());
57 return remoting_source_.get();
58 }
59
64 private: 60 private:
65 bool IsVideoCodecSupported(); 61 bool IsVideoCodecSupported();
66 bool IsAudioCodecSupported(); 62 bool IsAudioCodecSupported();
67 63
68 // Helper to decide whether to enter or leave Remoting mode. 64 // Helper to decide whether to enter or leave Remoting mode.
69 bool ShouldBeRemoting(); 65 bool ShouldBeRemoting();
70 66
71 // Determines whether to enter or leave Remoting mode and switches if 67 // Determines whether to enter or leave Remoting mode and switches if
72 // necessary. 68 // necessary.
73 void UpdateAndMaybeSwitch(); 69 void UpdateAndMaybeSwitch();
74 70
75 // Indicates if this media element or its ancestor enters full screen. 71 // Indicates whether this media element or its ancestor is in full screen.
76 bool is_fullscreen_ = false; 72 bool is_fullscreen_ = false;
77 73
78 // Indicates the remoting sink availablity. 74 // Indicates whether remoting is started.
79 bool is_sink_available_ = false; 75 bool remote_rendering_started_ = false;
80 76
81 // Indicates if remoting is started. 77 // Indicates whether remoting session can be started.
82 bool is_remoting_ = false; 78 bool session_can_remote_ = false;
83 79
84 // Indicates whether audio or video is encrypted. 80 // Indicates whether audio or video is encrypted.
85 bool is_encrypted_ = false; 81 bool is_encrypted_ = false;
86 82
87 // Current audio/video config. 83 // Current audio/video config.
88 VideoDecoderConfig video_decoder_config_; 84 VideoDecoderConfig video_decoder_config_;
89 AudioDecoderConfig audio_decoder_config_; 85 AudioDecoderConfig audio_decoder_config_;
90 bool has_audio_ = false; 86 bool has_audio_ = false;
91 bool has_video_ = false; 87 bool has_video_ = false;
92 88
93 // The callback to switch the media renderer. 89 // The callback to switch the media renderer.
94 SwitchRendererCallback switch_renderer_cb_; 90 base::Closure switch_renderer_cb_;
95 91
96 mojo::Binding<mojom::RemotingSource> binding_; 92 // This is initially the RemotingSourceImpl passed to the ctor, and might be
97 mojom::RemoterPtr remoter_; 93 // replaced with a different instance later if OnSetCdm() is called.
94 scoped_refptr<RemotingSourceImpl> remoting_source_;
98 95
99 // TODO(xjz): Add a media thread task runner for the received RPC messages for 96 // This is used to check all the methods are called on the current thread in
100 // remoting media renderer in the up-coming change. 97 // debug builds.
101 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 98 base::ThreadChecker thread_checker_;
102 99
103 base::WeakPtrFactory<RemotingController> weak_factory_; 100 base::WeakPtrFactory<RemotingRendererController> weak_factory_;
104 101
105 DISALLOW_COPY_AND_ASSIGN(RemotingController); 102 DISALLOW_COPY_AND_ASSIGN(RemotingRendererController);
106 }; 103 };
107 104
108 } // namespace media 105 } // namespace media
109 106
110 #endif // MEDIA_REMOTING_REMOTING_CONTROLLER_H_ 107 #endif // MEDIA_REMOTING_REMOTING_RENDERER_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698