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/mediaplayer_observer.h" |
| 11 #include "media/mojo/interfaces/remoting.mojom.h" |
| 12 #include "mojo/public/cpp/bindings/binding.h" |
| 13 |
| 14 // This class does the following: |
| 15 // 1) Sends/Receives messages from/to Remoter; |
| 16 // 2) Monitors player events as a MediaPlayerObserver; |
| 17 // 3) May trigger the switch of the media renderer between local playback |
| 18 // and remoting. |
| 19 // |
| 20 namespace media { |
| 21 |
| 22 class MEDIA_EXPORT RemotingController final : public MediaPlayerObserver, |
| 23 public mojom::RemotingSource { |
| 24 public: |
| 25 // |remoter_factory| is just being used to create a Remoter and need not |
| 26 // remain valid after the constructor returns. |
| 27 explicit RemotingController(mojom::RemoterFactory* remoter_factory); |
| 28 ~RemotingController() override; |
| 29 |
| 30 // RemotingSource implementations. |
| 31 void OnSinkAvailable() override; |
| 32 void OnSinkGone() override; |
| 33 void OnStarted() override; |
| 34 void OnStartFailed(mojom::RemotingStartFailReason reason) override; |
| 35 void OnMessageFromSink(const std::vector<uint8_t>& message) override; |
| 36 void OnStopped(mojom::RemotingStopReason reson) override; |
| 37 |
| 38 // MediaPlayerObserver implementation. |
| 39 void OnEnteredFullscreen() override; |
| 40 void OnExitedFullscreen() override; |
| 41 void OnSetCdm(CdmContext* cdm_context) override; |
| 42 void OnDecoderConfigChanged(const AudioDecoderConfig& audio_config, |
| 43 const VideoDecoderConfig& video_config) override; |
| 44 using SwitchRendererCallback = base::Callback<void()>; |
| 45 void SetSwitchRenderCallback(const SwitchRendererCallback& cb); |
| 46 |
| 47 // Tells which renderer should be used. |
| 48 bool is_remoting() const { |
| 49 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 50 return is_remoting_; |
| 51 } |
| 52 |
| 53 private: |
| 54 bool isVideoConfigSupported(); |
| 55 bool isAudioConfigSupported(); |
| 56 |
| 57 // Determines whether to enter or leave Remoting mode and switches if |
| 58 // necessary. |
| 59 void Update(); |
| 60 |
| 61 // Indicates if this media element or its ancestor enters full screen. |
| 62 bool is_fullscreen_; |
| 63 |
| 64 // Indicates the remoting sink availablity. |
| 65 bool is_sink_available_; |
| 66 |
| 67 // Indicates if remoting is started. |
| 68 bool is_remoting_; |
| 69 |
| 70 // Current audio/video config. |
| 71 VideoDecoderConfig video_decoder_config_; |
| 72 AudioDecoderConfig audio_decoder_config_; |
| 73 |
| 74 // The callback to switch the media renderer. |
| 75 SwitchRendererCallback switch_renderer_cb_; |
| 76 |
| 77 mojo::Binding<mojom::RemotingSource> binding_; |
| 78 mojom::RemoterPtr remoter_; |
| 79 |
| 80 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 81 |
| 82 DISALLOW_COPY_AND_ASSIGN(RemotingController); |
| 83 }; |
| 84 |
| 85 } // namespace media |
| 86 |
| 87 #endif // MEDIA_REMOTING_REMOTING_CONTROLLER_H_ |
OLD | NEW |