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. Players may | |
38 // return |false| to indicate they did not handle the event, in which case | |
39 // OnIdleTimeout() will be called again in the future. | |
40 // | |
41 // Players should typically respond by releasing resources, for example by | |
42 // discarding their decoders. | |
43 // | |
44 // Players MUST NOT call SetIdle(false) from OnIdleTimeout(). | |
45 virtual bool OnIdleTimeout() = 0; | |
46 | |
47 // Called when external controls are activated. | |
39 virtual void OnPlay() = 0; | 48 virtual void OnPlay() = 0; |
40 virtual void OnPause() = 0; | 49 virtual void OnPause() = 0; |
41 | 50 |
42 // Playout volume should be set to current_volume * multiplier. The range is | 51 // Called to control audio ducking. Output volume should be set to |
43 // [0, 1] and is typically 1. | 52 // |player_volume| * |multiplier|. The range of |multiplier| is [0, 1], |
53 // where 1 indicates normal (non-ducked) playback. | |
44 virtual void OnVolumeMultiplierUpdate(double multiplier) = 0; | 54 virtual void OnVolumeMultiplierUpdate(double multiplier) = 0; |
45 }; | 55 }; |
46 | 56 |
47 WebMediaPlayerDelegate() {} | 57 // These return the visibility state of the host frame. |
58 // TODO(sandersd): Experiment to determine exactly what gets called when | |
59 // restoring a closed tab. | |
60 virtual bool IsFrameHidden() = 0; | |
61 virtual bool IsFrameClosed() = 0; | |
48 | 62 |
49 // Subscribe or unsubscribe from observer callbacks respectively. A client | 63 // Returns |true| if background video playback has been enabled, for example |
50 // must use the delegate id returned by AddObserver() for all other calls. | 64 // by a media session 'play' command. |
65 virtual bool IsBackgroundVideoPlaybackAllowed() = 0; | |
66 | |
67 // Subscribe to observer callbacks. A player must use the returned |player_id| | |
68 // for the rest of the calls below. | |
51 virtual int AddObserver(Observer* observer) = 0; | 69 virtual int AddObserver(Observer* observer) = 0; |
52 virtual void RemoveObserver(int delegate_id) = 0; | |
53 | 70 |
54 // The specified player started playing media. | 71 // Unsubscribe from observer callbacks. |
55 virtual void DidPlay(int delegate_id, | 72 virtual void RemoveObserver(int player_id) = 0; |
73 | |
74 // Notify playback started. This will request appropriate wake locks and, if | |
75 // applicable, show a pause button in external controls. | |
76 // | |
77 // DidPlay() should not be called for remote playback. | |
78 virtual void DidPlay(int player_id, | |
79 bool has_audio, | |
56 bool has_video, | 80 bool has_video, |
57 bool has_audio, | |
58 bool is_remote, | |
59 media::MediaContentType media_content_type) = 0; | 81 media::MediaContentType media_content_type) = 0; |
60 | 82 |
61 // The specified player stopped playing media. This may be called at any time | 83 // Notify that playback is paused. This will drop wake locks and, if |
62 // with or without a DidPlay() having previously occurred. Calling this will | 84 // applicable, show a play button in external controls. |
63 // cause the delegate to be registered for idle suspension. I.e., after some | 85 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 | 86 |
67 // The specified player was destroyed or suspended and will no longer accept | 87 // Notify that playback is stopped. This will drop wake locks and remove any |
68 // Observer::OnPlay() or Observer::OnPause() calls. This may be called | 88 // external controls. |
69 // multiple times in row. Note: Clients must still call RemoveObserver() to | 89 // |
70 // unsubscribe from callbacks. | 90 // Clients must still call RemoveObserver() to unsubscribe from observer |
71 virtual void PlayerGone(int delegate_id) = 0; | 91 // callbacks. |
92 virtual void PlayerGone(int player_id) = 0; | |
72 | 93 |
73 // Returns whether the render frame is currently hidden. | 94 // Set the player's idle state. While idle, a player may recieve an |
DaleCurtis
2016/12/20 22:34:04
Seems this is always called after one of the above
sandersd (OOO until July 31)
2017/01/05 23:12:21
There is one counterexample, webmediaplayer_ms cal
DaleCurtis
2017/01/05 23:20:36
Does that make sense? Isn't IsIdle() always true w
| |
74 virtual bool IsHidden() = 0; | 95 // OnIdleTimeout() callback. |
96 virtual void SetIdle(int player_id, bool is_idle) = 0; | |
75 | 97 |
76 // Returns whether there's a video playing in background within the render | 98 // Get the player's idle state. A player is idle after SetIdle(true), even if |
DaleCurtis
2016/12/20 22:34:05
Unused?
sandersd (OOO until July 31)
2017/01/05 23:12:21
WMPI uses this in one case to basically result in
| |
77 // frame. | 99 // it has gone stale. |
78 virtual bool IsPlayingBackgroundVideo() = 0; | 100 virtual bool IsIdle(int player_id) = 0; |
101 | |
102 // Returns a stale player to an idle state, and resumes OnIdleTimeout() calls | |
DaleCurtis
2016/12/20 22:34:04
Hmm, don't really love exposing the stale concept
sandersd (OOO until July 31)
2017/01/05 23:12:21
(See above.)
| |
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(), which may allow us to eliminate the return value from | |
107 // OnIdleTimeout() as well. | |
108 virtual void ClearStaleFlag(int player_id) = 0; | |
109 | |
110 // Returns |true| if the player is stale; that is that OnIdleTimeout() was | |
111 // called and returned |true|. | |
112 virtual bool IsStale(int player_id) = 0; | |
79 | 113 |
80 protected: | 114 protected: |
81 virtual ~WebMediaPlayerDelegate() {} | 115 WebMediaPlayerDelegate() = default; |
116 virtual ~WebMediaPlayerDelegate() = default; | |
82 }; | 117 }; |
83 | 118 |
84 } // namespace media | 119 } // namespace media |
85 | 120 |
86 #endif // MEDIA_BLINK_WEBMEDIAPLAYER_DELEGATE_H_ | 121 #endif // MEDIA_BLINK_WEBMEDIAPLAYER_DELEGATE_H_ |
OLD | NEW |