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_DELEGATE_H_ | 5 #ifndef MEDIA_BLINK_WEBMEDIAPLAYER_DELEGATE_H_ |
| 6 #define MEDIA_BLINK_WEBMEDIAPLAYER_DELEGATE_H_ | 6 #define MEDIA_BLINK_WEBMEDIAPLAYER_DELEGATE_H_ |
| 7 | 7 |
| 8 namespace blink { | 8 namespace blink { |
| 9 class WebMediaPlayer; | 9 class WebMediaPlayer; |
| 10 } | 10 } |
| 11 namespace media { | 11 namespace media { |
| 12 | 12 |
| 13 enum class MediaContentType; | 13 enum class MediaContentType; |
| 14 | 14 |
| 15 // An interface to allow a WebMediaPlayer to communicate changes of state to | 15 // An interface to collect WebMediaPlayer state changes and to fan out commands |
| 16 // objects that need to know. | 16 // from the browser. |
| 17 class WebMediaPlayerDelegate { | 17 class WebMediaPlayerDelegate { |
| 18 public: | 18 public: |
| 19 class Observer { | 19 class Observer { |
| 20 public: | 20 public: |
| 21 // Called when the WebMediaPlayer enters the background or foreground | 21 // Called when the host frame is hidden (usually by tab switching). |
| 22 // respectively. Note: Some implementations will stop playback when hidden, | |
| 23 // and thus subsequently call WebMediaPlayerDelegate::PlayerGone(). | |
| 24 virtual void OnHidden() = 0; | 22 virtual void OnHidden() = 0; |
| 23 | |
| 24 // Called when the host frame is closed. Note that it is sometimes possible | |
| 25 // for a closed frame to be shown again. (Android only; other platforms tear | |
| 26 // down players when the host frame is closed.) | |
| 27 virtual void OnClosed() = 0; | |
| 28 | |
| 29 // Called when the host frame is shown (usually by tab switching). | |
| 25 virtual void OnShown() = 0; | 30 virtual void OnShown() = 0; |
| 26 | 31 |
| 27 // Requests a WebMediaPlayer instance to release all idle resources. If | 32 // Called when an idle player has become stale, usually interpreted to mean |
| 28 // |must_suspend| is true, the player must stop playback, release all idle | 33 // that it is unlikely to be interacted with in the near future. Players may |
| 29 // resources, and finally call WebMediaPlayerDelegate::PlayerGone(). If | 34 // return |false| to indicate they did not handle the event, in which case |
| 30 // |must_suspend| is false, the player may ignore the request. Optionally, | 35 // OnIdleTimeout() will be called again in the future. |
| 31 // it may do some or all of the same actions as when |must_suspend| is true. | 36 // |
| 32 // To be clear, the player is not required to call PlayerGone() when | 37 // Players should typically respond by releasing resources, for example by |
| 33 // |must_suspend| is false. | 38 // discarding their decoders. |
| 34 // Return false to reject the request and indicate that further calls to | 39 virtual bool OnIdleTimeout() = 0; |
| 35 // OnSuspendRequested() are required. Otherwise the Observer is removed | |
| 36 // from the idle list. | |
| 37 virtual bool OnSuspendRequested(bool must_suspend) = 0; | |
| 38 | 40 |
| 41 // Called when external controls are activated. | |
| 39 virtual void OnPlay() = 0; | 42 virtual void OnPlay() = 0; |
| 40 virtual void OnPause() = 0; | 43 virtual void OnPause() = 0; |
| 41 | 44 |
| 42 // Playout volume should be set to current_volume * multiplier. The range is | 45 // Called to control audio ducking. Output volume should be set to |
| 43 // [0, 1] and is typically 1. | 46 // |player_volume| * |multiplier|. The range of |multiplier| is [0, 1], |
| 47 // where 1 indicates normal (non-ducked) playback. | |
| 44 virtual void OnVolumeMultiplierUpdate(double multiplier) = 0; | 48 virtual void OnVolumeMultiplierUpdate(double multiplier) = 0; |
| 45 }; | 49 }; |
| 46 | 50 |
| 47 WebMediaPlayerDelegate() {} | 51 // These return the visibility state of the host frame. |
| 52 virtual bool IsHidden() = 0; | |
| 53 virtual bool IsClosed() = 0; | |
|
watk
2016/11/08 23:34:47
I wonder if all the {on,is}{hidden,shown} should h
sandersd (OOO until July 31)
2016/11/08 23:44:44
Done.
| |
| 48 | 54 |
| 49 // Subscribe or unsubscribe from observer callbacks respectively. A client | 55 // Returns |true| if there is any player with playing video in the host frame. |
| 50 // must use the delegate id returned by AddObserver() for all other calls. | 56 virtual bool IsPlayingVideo() = 0; |
| 57 | |
| 58 // Subscribe to observer callbacks. A player must use the returned |player_id| | |
| 59 // for the rest of the calls below. | |
| 51 virtual int AddObserver(Observer* observer) = 0; | 60 virtual int AddObserver(Observer* observer) = 0; |
| 52 virtual void RemoveObserver(int delegate_id) = 0; | |
| 53 | 61 |
| 54 // The specified player started playing media. | 62 // Unsubscribe from observer callbacks. |
| 55 virtual void DidPlay(int delegate_id, | 63 virtual void RemoveObserver(int player_id) = 0; |
| 64 | |
| 65 // Notify playback started. This will request appropriate wake locks and, if | |
| 66 // applicable, show a pause button in external controls. | |
| 67 // | |
| 68 // DidPlay() should not be called for remote playback. | |
| 69 virtual void DidPlay(int player_id, | |
|
watk
2016/11/08 23:34:47
I like player_id a lot
| |
| 70 bool has_audio, | |
| 56 bool has_video, | 71 bool has_video, |
| 57 bool has_audio, | |
| 58 bool is_remote, | |
| 59 media::MediaContentType media_content_type) = 0; | 72 media::MediaContentType media_content_type) = 0; |
| 60 | 73 |
| 61 // The specified player stopped playing media. This may be called at any time | 74 // Notify that playback is paused. This will drop wake locks and, if |
| 62 // with or without a DidPlay() having previously occurred. Calling this will | 75 // applicable, show a play button in external controls. |
| 63 // cause the delegate to be registered for idle suspension. I.e., after some | 76 virtual void DidPause(int player_id) = 0; |
| 64 // time elapses without a DidPlay(), OnSuspendRequested() will be issued. | |
| 65 virtual void DidPause(int delegate_id, bool reached_end_of_stream) = 0; | |
| 66 | 77 |
| 67 // The specified player was destroyed or suspended and will no longer accept | 78 // Notify that playback is stopped. This will drop wake locks and remove any |
| 68 // Observer::OnPlay() or Observer::OnPause() calls. This may be called | 79 // external controls. |
| 69 // multiple times in row. Note: Clients must still call RemoveObserver() to | 80 // |
| 70 // unsubscribe from callbacks. | 81 // Clients must still call RemoveObserver() to unsubscribe from observer |
| 71 virtual void PlayerGone(int delegate_id) = 0; | 82 // callbacks. |
| 83 virtual void PlayerGone(int player_id) = 0; | |
| 72 | 84 |
| 73 // Returns whether the render frame is currently hidden. | 85 // Set the player's idle state. While idle, a player may recieve an |
| 74 virtual bool IsHidden() = 0; | 86 // OnIdleTimeout() callback. |
| 75 | 87 virtual void SetIdle(int player_id, bool is_idle) = 0; |
| 76 // Returns whether there's a video playing in background within the render | |
| 77 // frame. | |
| 78 virtual bool IsPlayingBackgroundVideo() = 0; | |
| 79 | 88 |
| 80 protected: | 89 protected: |
| 81 virtual ~WebMediaPlayerDelegate() {} | 90 WebMediaPlayerDelegate() = default; |
| 91 virtual ~WebMediaPlayerDelegate() = default; | |
| 82 }; | 92 }; |
| 83 | 93 |
| 84 } // namespace media | 94 } // namespace media |
| 85 | 95 |
| 86 #endif // MEDIA_BLINK_WEBMEDIAPLAYER_DELEGATE_H_ | 96 #endif // MEDIA_BLINK_WEBMEDIAPLAYER_DELEGATE_H_ |
| OLD | NEW |