Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_BLINK_WEBMEDIAPLAYER_IMPL_H_ | 5 #ifndef MEDIA_BLINK_WEBMEDIAPLAYER_IMPL_H_ |
| 6 #define MEDIA_BLINK_WEBMEDIAPLAYER_IMPL_H_ | 6 #define MEDIA_BLINK_WEBMEDIAPLAYER_IMPL_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/cancelable_callback.h" | 14 #include "base/cancelable_callback.h" |
| 15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/memory/linked_ptr.h" | 17 #include "base/memory/linked_ptr.h" |
| 18 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
| 19 #include "base/memory/weak_ptr.h" | 19 #include "base/memory/weak_ptr.h" |
| 20 #include "base/threading/thread.h" | 20 #include "base/threading/thread.h" |
| 21 #include "base/timer/elapsed_timer.h" | 21 #include "base/timer/elapsed_timer.h" |
| 22 #include "base/timer/timer.h" | 22 #include "base/timer/timer.h" |
| 23 #include "build/build_config.h" | 23 #include "build/build_config.h" |
| 24 #include "media/base/media_tracks.h" | 24 #include "media/base/media_tracks.h" |
| 25 #include "media/base/mediaplayer_observer.h" | |
| 25 #include "media/base/pipeline_impl.h" | 26 #include "media/base/pipeline_impl.h" |
| 26 #include "media/base/renderer_factory.h" | 27 #include "media/base/renderer_factory.h" |
| 27 #include "media/base/surface_manager.h" | 28 #include "media/base/surface_manager.h" |
| 28 #include "media/base/text_track.h" | 29 #include "media/base/text_track.h" |
| 29 #include "media/blink/buffered_data_source_host_impl.h" | 30 #include "media/blink/buffered_data_source_host_impl.h" |
| 30 #include "media/blink/media_blink_export.h" | 31 #include "media/blink/media_blink_export.h" |
| 31 #include "media/blink/multibuffer_data_source.h" | 32 #include "media/blink/multibuffer_data_source.h" |
| 32 #include "media/blink/video_frame_compositor.h" | 33 #include "media/blink/video_frame_compositor.h" |
| 33 #include "media/blink/webmediaplayer_delegate.h" | 34 #include "media/blink/webmediaplayer_delegate.h" |
| 34 #include "media/blink/webmediaplayer_params.h" | 35 #include "media/blink/webmediaplayer_params.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 81 // Pipeline. Handles normal resource loading, Media Source, and | 82 // Pipeline. Handles normal resource loading, Media Source, and |
| 82 // Encrypted Media. | 83 // Encrypted Media. |
| 83 class MEDIA_BLINK_EXPORT WebMediaPlayerImpl | 84 class MEDIA_BLINK_EXPORT WebMediaPlayerImpl |
| 84 : public NON_EXPORTED_BASE(blink::WebMediaPlayer), | 85 : public NON_EXPORTED_BASE(blink::WebMediaPlayer), |
| 85 public NON_EXPORTED_BASE(WebMediaPlayerDelegate::Observer), | 86 public NON_EXPORTED_BASE(WebMediaPlayerDelegate::Observer), |
| 86 public NON_EXPORTED_BASE(Pipeline::Client), | 87 public NON_EXPORTED_BASE(Pipeline::Client), |
| 87 public base::SupportsWeakPtr<WebMediaPlayerImpl> { | 88 public base::SupportsWeakPtr<WebMediaPlayerImpl> { |
| 88 public: | 89 public: |
| 89 // Constructs a WebMediaPlayer implementation using Chromium's media stack. | 90 // Constructs a WebMediaPlayer implementation using Chromium's media stack. |
| 90 // |delegate| may be null. |renderer_factory| must not be null. | 91 // |delegate| may be null. |renderer_factory| must not be null. |
| 92 // |observer| outlives this class, and could be null. | |
|
xhwang
2016/10/01 07:12:15
In your case, the |observer| is the same object as
xjz
2016/10/03 22:31:08
Done.
| |
| 91 WebMediaPlayerImpl( | 93 WebMediaPlayerImpl( |
| 92 blink::WebLocalFrame* frame, | 94 blink::WebLocalFrame* frame, |
| 93 blink::WebMediaPlayerClient* client, | 95 blink::WebMediaPlayerClient* client, |
| 94 blink::WebMediaPlayerEncryptedMediaClient* encrypted_client, | 96 blink::WebMediaPlayerEncryptedMediaClient* encrypted_client, |
| 95 base::WeakPtr<WebMediaPlayerDelegate> delegate, | 97 base::WeakPtr<WebMediaPlayerDelegate> delegate, |
| 96 std::unique_ptr<RendererFactory> renderer_factory, | 98 std::unique_ptr<RendererFactory> renderer_factory, |
| 97 linked_ptr<UrlIndex> url_index, | 99 linked_ptr<UrlIndex> url_index, |
| 100 MediaPlayerObserver* observer, | |
| 98 const WebMediaPlayerParams& params); | 101 const WebMediaPlayerParams& params); |
| 99 ~WebMediaPlayerImpl() override; | 102 ~WebMediaPlayerImpl() override; |
| 100 | 103 |
| 101 void load(LoadType load_type, | 104 void load(LoadType load_type, |
| 102 const blink::WebMediaPlayerSource& source, | 105 const blink::WebMediaPlayerSource& source, |
| 103 CORSMode cors_mode) override; | 106 CORSMode cors_mode) override; |
| 104 | 107 |
| 105 // Playback controls. | 108 // Playback controls. |
| 106 void play() override; | 109 void play() override; |
| 107 void pause() override; | 110 void pause() override; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 174 blink::WebAudioSourceProvider* getAudioSourceProvider() override; | 177 blink::WebAudioSourceProvider* getAudioSourceProvider() override; |
| 175 | 178 |
| 176 void setContentDecryptionModule( | 179 void setContentDecryptionModule( |
| 177 blink::WebContentDecryptionModule* cdm, | 180 blink::WebContentDecryptionModule* cdm, |
| 178 blink::WebContentDecryptionModuleResult result) override; | 181 blink::WebContentDecryptionModuleResult result) override; |
| 179 | 182 |
| 180 bool supportsOverlayFullscreenVideo() override; | 183 bool supportsOverlayFullscreenVideo() override; |
| 181 void enteredFullscreen() override; | 184 void enteredFullscreen() override; |
| 182 void exitedFullscreen() override; | 185 void exitedFullscreen() override; |
| 183 | 186 |
| 187 // These are called when any ancestor enters/exits full screen. | |
| 188 void ancestorEnteredFullscreen() override; | |
| 189 void ancestorExitedFullscreen() override; | |
| 190 | |
| 184 // WebMediaPlayerDelegate::Observer implementation. | 191 // WebMediaPlayerDelegate::Observer implementation. |
| 185 void OnHidden() override; | 192 void OnHidden() override; |
| 186 void OnShown() override; | 193 void OnShown() override; |
| 187 void OnSuspendRequested(bool must_suspend) override; | 194 void OnSuspendRequested(bool must_suspend) override; |
| 188 void OnPlay() override; | 195 void OnPlay() override; |
| 189 void OnPause() override; | 196 void OnPause() override; |
| 190 void OnVolumeMultiplierUpdate(double multiplier) override; | 197 void OnVolumeMultiplierUpdate(double multiplier) override; |
| 191 | 198 |
| 192 #if defined(OS_ANDROID) // WMPI_CAST | 199 #if defined(OS_ANDROID) // WMPI_CAST |
| 193 bool isRemote() const override; | 200 bool isRemote() const override; |
| 194 void requestRemotePlayback() override; | 201 void requestRemotePlayback() override; |
| 195 void requestRemotePlaybackControl() override; | 202 void requestRemotePlaybackControl() override; |
| 196 | 203 |
| 197 void SetMediaPlayerManager( | 204 void SetMediaPlayerManager( |
| 198 RendererMediaPlayerManagerInterface* media_player_manager); | 205 RendererMediaPlayerManagerInterface* media_player_manager); |
| 199 void OnRemotePlaybackEnded(); | 206 void OnRemotePlaybackEnded(); |
| 200 void OnDisconnectedFromRemoteDevice(double t); | 207 void OnDisconnectedFromRemoteDevice(double t); |
| 201 void SuspendForRemote(); | 208 void SuspendForRemote(); |
| 202 void DisplayCastFrameAfterSuspend(const scoped_refptr<VideoFrame>& new_frame, | 209 void DisplayCastFrameAfterSuspend(const scoped_refptr<VideoFrame>& new_frame, |
| 203 PipelineStatus status); | 210 PipelineStatus status); |
| 204 gfx::Size GetCanvasSize() const; | 211 gfx::Size GetCanvasSize() const; |
| 205 void SetDeviceScaleFactor(float scale_factor); | 212 void SetDeviceScaleFactor(float scale_factor); |
| 206 void setPoster(const blink::WebURL& poster) override; | 213 void setPoster(const blink::WebURL& poster) override; |
| 207 #endif | 214 #endif |
| 208 | 215 |
| 209 // Called from WebMediaPlayerCast. | 216 // Called from WebMediaPlayerCast. |
| 210 // TODO(hubbe): WMPI_CAST make private. | 217 // TODO(hubbe): WMPI_CAST make private. |
| 211 void OnPipelineSeeked(bool time_updated); | 218 void OnPipelineSeeked(bool time_updated); |
| 212 | 219 |
| 220 // Restart the player/pipeline as soon as possible. This will destroy the | |
| 221 // current renderer, if any, and create a new one via the RendererFactory; and | |
| 222 // then seek to resume playback at the current position. | |
| 223 void ScheduleRestart(); | |
| 224 | |
| 213 // Distinct states that |delegate_| can be in. | 225 // Distinct states that |delegate_| can be in. |
| 214 // TODO(sandersd): This should move into WebMediaPlayerDelegate. | 226 // TODO(sandersd): This should move into WebMediaPlayerDelegate. |
| 215 // (Public for testing.) | 227 // (Public for testing.) |
| 216 enum class DelegateState { | 228 enum class DelegateState { |
| 217 GONE, | 229 GONE, |
| 218 PLAYING, | 230 PLAYING, |
| 219 PAUSED, | 231 PAUSED, |
| 220 ENDED, | 232 ENDED, |
| 221 }; | 233 }; |
| 222 | 234 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 246 void OnAddTextTrack(const TextTrackConfig& config, | 258 void OnAddTextTrack(const TextTrackConfig& config, |
| 247 const AddTextTrackDoneCB& done_cb) override; | 259 const AddTextTrackDoneCB& done_cb) override; |
| 248 void OnWaitingForDecryptionKey() override; | 260 void OnWaitingForDecryptionKey() override; |
| 249 void OnVideoNaturalSizeChange(const gfx::Size& size) override; | 261 void OnVideoNaturalSizeChange(const gfx::Size& size) override; |
| 250 void OnVideoOpacityChange(bool opaque) override; | 262 void OnVideoOpacityChange(bool opaque) override; |
| 251 | 263 |
| 252 // Actually seek. Avoids causing |should_notify_time_changed_| to be set when | 264 // Actually seek. Avoids causing |should_notify_time_changed_| to be set when |
| 253 // |time_updated| is false. | 265 // |time_updated| is false. |
| 254 void DoSeek(base::TimeDelta time, bool time_updated); | 266 void DoSeek(base::TimeDelta time, bool time_updated); |
| 255 | 267 |
| 256 // Ask for the renderer to be restarted (destructed and recreated). | |
| 257 void ScheduleRestart(); | |
| 258 | |
| 259 // Called after |defer_load_cb_| has decided to allow the load. If | 268 // Called after |defer_load_cb_| has decided to allow the load. If |
| 260 // |defer_load_cb_| is null this is called immediately. | 269 // |defer_load_cb_| is null this is called immediately. |
| 261 void DoLoad(LoadType load_type, | 270 void DoLoad(LoadType load_type, |
| 262 const blink::WebURL& url, | 271 const blink::WebURL& url, |
| 263 CORSMode cors_mode); | 272 CORSMode cors_mode); |
| 264 | 273 |
| 265 // Called after asynchronous initialization of a data source completed. | 274 // Called after asynchronous initialization of a data source completed. |
| 266 void DataSourceInitialized(bool success); | 275 void DataSourceInitialized(bool success); |
| 267 | 276 |
| 268 // Called when the data source is downloading or paused. | 277 // Called when the data source is downloading or paused. |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 541 base::OneShotTimer background_pause_timer_; | 550 base::OneShotTimer background_pause_timer_; |
| 542 | 551 |
| 543 // Monitors the watch time of the played content. | 552 // Monitors the watch time of the played content. |
| 544 std::unique_ptr<WatchTimeReporter> watch_time_reporter_; | 553 std::unique_ptr<WatchTimeReporter> watch_time_reporter_; |
| 545 bool is_encrypted_; | 554 bool is_encrypted_; |
| 546 | 555 |
| 547 // Number of times we've reached BUFFERING_HAVE_NOTHING during playback. | 556 // Number of times we've reached BUFFERING_HAVE_NOTHING during playback. |
| 548 int underflow_count_; | 557 int underflow_count_; |
| 549 std::unique_ptr<base::ElapsedTimer> underflow_timer_; | 558 std::unique_ptr<base::ElapsedTimer> underflow_timer_; |
| 550 | 559 |
| 560 // Monitors the player events. | |
| 561 MediaPlayerObserver* const observer_; | |
| 562 | |
| 551 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerImpl); | 563 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerImpl); |
| 552 }; | 564 }; |
| 553 | 565 |
| 554 } // namespace media | 566 } // namespace media |
| 555 | 567 |
| 556 #endif // MEDIA_BLINK_WEBMEDIAPLAYER_IMPL_H_ | 568 #endif // MEDIA_BLINK_WEBMEDIAPLAYER_IMPL_H_ |
| OLD | NEW |