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 // Note: WebMediaPlayerDelegate implementations should not call an Observer | |
20 // method on a stack that includes a call from the player. | |
21 // Note: It is likely that players will call WebMediaPlayerDelegate methods | |
22 // from within Observer callbacks. | |
19 class Observer { | 23 class Observer { |
20 public: | 24 public: |
21 // Called when the WebMediaPlayer enters the background or foreground | 25 // Called when the host frame is hidden (usually by tab switching). |
22 // respectively. Note: Some implementations will stop playback when hidden, | 26 virtual void OnFrameHidden() = 0; |
23 // and thus subsequently call WebMediaPlayerDelegate::PlayerGone(). | |
24 virtual void OnHidden() = 0; | |
25 virtual void OnShown() = 0; | |
26 | 27 |
27 // Requests a WebMediaPlayer instance to release all idle resources. If | 28 // Called when the host frame is closed. Note that it is sometimes possible |
28 // |must_suspend| is true, the player must stop playback, release all idle | 29 // for a closed frame to be shown again. (Android only; other platforms tear |
29 // resources, and finally call WebMediaPlayerDelegate::PlayerGone(). If | 30 // down players when the host frame is closed.) |
30 // |must_suspend| is false, the player may ignore the request. Optionally, | 31 virtual void OnFrameClosed() = 0; |
31 // it may do some or all of the same actions as when |must_suspend| is true. | |
32 // To be clear, the player is not required to call PlayerGone() when | |
33 // |must_suspend| is false. | |
34 // Return false to reject the request and indicate that further calls to | |
35 // OnSuspendRequested() are required. Otherwise the Observer is removed | |
36 // from the idle list. | |
37 virtual bool OnSuspendRequested(bool must_suspend) = 0; | |
38 | 32 |
33 // Called when the host frame is shown (usually by tab switching). | |
34 virtual void OnFrameShown() = 0; | |
35 | |
36 // Called when an idle player has become stale, usually interpreted to mean | |
37 // that it is unlikely to be interacted with in the near future. | |
38 // | |
39 // Players should typically respond by releasing resources, for example by | |
40 // discarding their decoders. | |
41 virtual void OnIdleTimeout() = 0; | |
42 | |
43 // Called when external controls are activated. | |
39 virtual void OnPlay() = 0; | 44 virtual void OnPlay() = 0; |
40 virtual void OnPause() = 0; | 45 virtual void OnPause() = 0; |
41 | 46 |
42 // Playout volume should be set to current_volume * multiplier. The range is | 47 // Called to control audio ducking. Output volume should be set to |
43 // [0, 1] and is typically 1. | 48 // |player_volume| * |multiplier|. The range of |multiplier| is [0, 1], |
49 // where 1 indicates normal (non-ducked) playback. | |
44 virtual void OnVolumeMultiplierUpdate(double multiplier) = 0; | 50 virtual void OnVolumeMultiplierUpdate(double multiplier) = 0; |
45 }; | 51 }; |
46 | 52 |
47 WebMediaPlayerDelegate() {} | 53 // These return the visibility state of the host frame. |
54 // TODO(sandersd): Experiment to determine exactly what gets called when | |
55 // restoring a closed tab. | |
56 virtual bool IsFrameHidden() = 0; | |
whywhat
2017/01/06 17:18:51
nit: say that IsFrameHidden also considers closed
sandersd (OOO until July 31)
2017/01/06 23:08:35
Done.
| |
57 virtual bool IsFrameClosed() = 0; | |
48 | 58 |
49 // Subscribe or unsubscribe from observer callbacks respectively. A client | 59 // Returns |true| if background video playback has been enabled, for example |
50 // must use the delegate id returned by AddObserver() for all other calls. | 60 // by a media session 'play' command. |
61 virtual bool IsBackgroundVideoPlaybackAllowed() = 0; | |
62 | |
63 // Subscribe to observer callbacks. A player must use the returned |player_id| | |
64 // for the rest of the calls below. | |
51 virtual int AddObserver(Observer* observer) = 0; | 65 virtual int AddObserver(Observer* observer) = 0; |
52 virtual void RemoveObserver(int delegate_id) = 0; | |
53 | 66 |
54 // The specified player started playing media. | 67 // Unsubscribe from observer callbacks. |
55 virtual void DidPlay(int delegate_id, | 68 virtual void RemoveObserver(int player_id) = 0; |
69 | |
70 // Notify playback started. This will request appropriate wake locks and, if | |
71 // applicable, show a pause button in external controls. | |
72 // | |
73 // DidPlay() should not be called for remote playback. | |
74 virtual void DidPlay(int player_id, | |
75 bool has_audio, | |
56 bool has_video, | 76 bool has_video, |
57 bool has_audio, | |
58 bool is_remote, | |
59 media::MediaContentType media_content_type) = 0; | 77 media::MediaContentType media_content_type) = 0; |
60 | 78 |
61 // The specified player stopped playing media. This may be called at any time | 79 // Notify that playback is paused. This will drop wake locks and, if |
62 // with or without a DidPlay() having previously occurred. Calling this will | 80 // applicable, show a play button in external controls. |
63 // cause the delegate to be registered for idle suspension. I.e., after some | 81 // TODO(sandersd): It may be helpful to get |has_audio| and |has_video| here, |
64 // time elapses without a DidPlay(), OnSuspendRequested() will be issued. | 82 // so that we can do the right thing with media that starts paused. |
65 virtual void DidPause(int delegate_id, bool reached_end_of_stream) = 0; | 83 virtual void DidPause(int player_id) = 0; |
66 | 84 |
67 // The specified player was destroyed or suspended and will no longer accept | 85 // Notify that playback is stopped. This will drop wake locks and remove any |
68 // Observer::OnPlay() or Observer::OnPause() calls. This may be called | 86 // external controls. |
69 // multiple times in row. Note: Clients must still call RemoveObserver() to | 87 // |
70 // unsubscribe from callbacks. | 88 // Clients must still call RemoveObserver() to unsubscribe from observer |
71 virtual void PlayerGone(int delegate_id) = 0; | 89 // callbacks. |
90 virtual void PlayerGone(int player_id) = 0; | |
72 | 91 |
73 // Returns whether the render frame is currently hidden. | 92 // Set the player's idle state. While idle, a player may recieve an |
74 virtual bool IsHidden() = 0; | 93 // OnIdleTimeout() callback. |
94 // TODO(sandersd): Merge this into DidPlay()/DidPause()/PlayerGone(). | |
95 virtual void SetIdle(int player_id, bool is_idle) = 0; | |
75 | 96 |
76 // Returns whether there's a video playing in background within the render | 97 // Get the player's idle state. A stale player is considered idle. |
77 // frame. | 98 // TODO(sandersd): Remove this. It is only used in tests and in one special |
78 virtual bool IsPlayingBackgroundVideo() = 0; | 99 // case in WMPI. |
100 virtual bool IsIdle(int player_id) = 0; | |
101 | |
102 // Returns a stale player to an idle state, and resumes OnIdleTimeout() calls | |
103 // without an additional idle timeout. | |
104 // TODO(sandersd): This exists only to support WMPI's didLoadingProgress() | |
105 // workaround. A better option may be to take a 'minimum idle' duration in | |
106 // SetIdle(). | |
107 virtual void ClearStaleFlag(int player_id) = 0; | |
108 | |
109 // Returns |true| if the player is stale; that is that OnIdleTimeout() was | |
110 // called and returned |true|. | |
111 virtual bool IsStale(int player_id) = 0; | |
79 | 112 |
80 protected: | 113 protected: |
81 virtual ~WebMediaPlayerDelegate() {} | 114 WebMediaPlayerDelegate() = default; |
115 virtual ~WebMediaPlayerDelegate() = default; | |
82 }; | 116 }; |
83 | 117 |
84 } // namespace media | 118 } // namespace media |
85 | 119 |
86 #endif // MEDIA_BLINK_WEBMEDIAPLAYER_DELEGATE_H_ | 120 #endif // MEDIA_BLINK_WEBMEDIAPLAYER_DELEGATE_H_ |
OLD | NEW |