OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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_BASE_ANDROID_MEDIA_PLAYER_ANDROID_H_ | 5 #ifndef MEDIA_BASE_ANDROID_MEDIA_PLAYER_ANDROID_H_ |
6 #define MEDIA_BASE_ANDROID_MEDIA_PLAYER_ANDROID_H_ | 6 #define MEDIA_BASE_ANDROID_MEDIA_PLAYER_ANDROID_H_ |
7 | 7 |
8 #include <jni.h> | 8 #include <jni.h> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 19 matching lines...) Expand all Loading... |
30 virtual ~MediaPlayerAndroid(); | 30 virtual ~MediaPlayerAndroid(); |
31 | 31 |
32 // Error types for MediaErrorCB. | 32 // Error types for MediaErrorCB. |
33 enum MediaErrorType { | 33 enum MediaErrorType { |
34 MEDIA_ERROR_FORMAT, | 34 MEDIA_ERROR_FORMAT, |
35 MEDIA_ERROR_DECODE, | 35 MEDIA_ERROR_DECODE, |
36 MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK, | 36 MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK, |
37 MEDIA_ERROR_INVALID_CODE, | 37 MEDIA_ERROR_INVALID_CODE, |
38 }; | 38 }; |
39 | 39 |
40 // Callback when the player needs decoding resources. | 40 // Callback when the player releases decoding resources. |
41 typedef base::Callback<void(int player_id)> RequestMediaResourcesCB; | 41 typedef base::Callback<void(int player_id)> OnPlayerReleasedCB; |
42 | 42 |
43 // Virtual destructor. | 43 // Virtual destructor. |
44 // For most subclasses we can delete on the caller thread. | 44 // For most subclasses we can delete on the caller thread. |
45 virtual void DeleteOnCorrectThread(); | 45 virtual void DeleteOnCorrectThread(); |
46 | 46 |
47 // Passing an external java surface object to the player. | 47 // Passing an external java surface object to the player. |
48 virtual void SetVideoSurface(gfx::ScopedJavaSurface surface) = 0; | 48 virtual void SetVideoSurface(gfx::ScopedJavaSurface surface) = 0; |
49 | 49 |
50 // Start playing the media. | 50 // Start playing the media. |
51 virtual void Start() = 0; | 51 virtual void Start() = 0; |
(...skipping 11 matching lines...) Expand all Loading... |
63 | 63 |
64 // Set the player volume. | 64 // Set the player volume. |
65 virtual void SetVolume(double volume) = 0; | 65 virtual void SetVolume(double volume) = 0; |
66 | 66 |
67 // Get the media information from the player. | 67 // Get the media information from the player. |
68 virtual int GetVideoWidth() = 0; | 68 virtual int GetVideoWidth() = 0; |
69 virtual int GetVideoHeight() = 0; | 69 virtual int GetVideoHeight() = 0; |
70 virtual base::TimeDelta GetDuration() = 0; | 70 virtual base::TimeDelta GetDuration() = 0; |
71 virtual base::TimeDelta GetCurrentTime() = 0; | 71 virtual base::TimeDelta GetCurrentTime() = 0; |
72 virtual bool IsPlaying() = 0; | 72 virtual bool IsPlaying() = 0; |
73 virtual bool IsPlayerReady() = 0; | |
74 virtual bool CanPause() = 0; | 73 virtual bool CanPause() = 0; |
75 virtual bool CanSeekForward() = 0; | 74 virtual bool CanSeekForward() = 0; |
76 virtual bool CanSeekBackward() = 0; | 75 virtual bool CanSeekBackward() = 0; |
| 76 virtual bool IsPlayerReady() = 0; |
77 virtual GURL GetUrl(); | 77 virtual GURL GetUrl(); |
78 virtual GURL GetFirstPartyForCookies(); | 78 virtual GURL GetFirstPartyForCookies(); |
79 | 79 |
80 // Associates the |cdm| with this player. | 80 // Associates the |cdm| with this player. |
81 virtual void SetCdm(BrowserCdm* cdm); | 81 virtual void SetCdm(BrowserCdm* cdm); |
82 | 82 |
83 // Overridden in MediaCodecPlayer to pass data between threads. | 83 // Overridden in MediaCodecPlayer to pass data between threads. |
84 virtual void OnMediaMetadataChanged(base::TimeDelta duration, | 84 virtual void OnMediaMetadataChanged(base::TimeDelta duration, |
85 const gfx::Size& video_size) {} | 85 const gfx::Size& video_size) {} |
86 | 86 |
87 // Overridden in MediaCodecPlayer to pass data between threads. | 87 // Overridden in MediaCodecPlayer to pass data between threads. |
88 virtual void OnTimeUpdate(base::TimeDelta current_timestamp, | 88 virtual void OnTimeUpdate(base::TimeDelta current_timestamp, |
89 base::TimeTicks current_time_ticks) {} | 89 base::TimeTicks current_time_ticks) {} |
90 | 90 |
91 int player_id() { return player_id_; } | 91 int player_id() { return player_id_; } |
92 | 92 |
93 GURL frame_url() { return frame_url_; } | 93 GURL frame_url() { return frame_url_; } |
94 | 94 |
95 // Attach/Detaches |listener_| for listening to all the media events. If | 95 // Attach/Detaches |listener_| for listening to all the media events. If |
96 // |j_media_player| is NULL, |listener_| only listens to the system media | 96 // |j_media_player| is NULL, |listener_| only listens to the system media |
97 // events. Otherwise, it also listens to the events from |j_media_player|. | 97 // events. Otherwise, it also listens to the events from |j_media_player|. |
98 void AttachListener(jobject j_media_player); | 98 void AttachListener(jobject j_media_player); |
99 void DetachListener(); | 99 void DetachListener(); |
100 | 100 |
101 protected: | 101 protected: |
102 MediaPlayerAndroid(int player_id, | 102 MediaPlayerAndroid( |
103 MediaPlayerManager* manager, | 103 int player_id, |
104 const RequestMediaResourcesCB& request_media_resources_cb, | 104 MediaPlayerManager* manager, |
105 const GURL& frame_url); | 105 const OnPlayerReleasedCB& on_player_released_cb, |
| 106 const GURL& frame_url); |
106 | 107 |
107 // TODO(qinmin): Simplify the MediaPlayerListener class to only listen to | 108 // TODO(qinmin): Simplify the MediaPlayerListener class to only listen to |
108 // media interrupt events. And have a separate child class to listen to all | 109 // media interrupt events. And have a separate child class to listen to all |
109 // the events needed by MediaPlayerBridge. http://crbug.com/422597. | 110 // the events needed by MediaPlayerBridge. http://crbug.com/422597. |
110 // MediaPlayerListener callbacks. | 111 // MediaPlayerListener callbacks. |
111 virtual void OnVideoSizeChanged(int width, int height); | 112 virtual void OnVideoSizeChanged(int width, int height); |
112 virtual void OnMediaError(int error_type); | 113 virtual void OnMediaError(int error_type); |
113 virtual void OnBufferingUpdate(int percent); | 114 virtual void OnBufferingUpdate(int percent); |
114 virtual void OnPlaybackComplete(); | 115 virtual void OnPlaybackComplete(); |
115 virtual void OnMediaInterrupted(); | 116 virtual void OnMediaInterrupted(); |
116 virtual void OnSeekComplete(); | 117 virtual void OnSeekComplete(); |
117 virtual void OnMediaPrepared(); | 118 virtual void OnMediaPrepared(); |
118 | 119 |
119 // When destroying a subclassed object on a non-UI thread | 120 // When destroying a subclassed object on a non-UI thread |
120 // it is still required to destroy the |listener_| related stuff | 121 // it is still required to destroy the |listener_| related stuff |
121 // on the UI thread. | 122 // on the UI thread. |
122 void DestroyListenerOnUIThread(); | 123 void DestroyListenerOnUIThread(); |
123 | 124 |
124 MediaPlayerManager* manager() { return manager_; } | 125 MediaPlayerManager* manager() { return manager_; } |
125 | 126 |
126 base::WeakPtr<MediaPlayerAndroid> WeakPtrForUIThread(); | 127 base::WeakPtr<MediaPlayerAndroid> WeakPtrForUIThread(); |
127 | 128 |
128 RequestMediaResourcesCB request_media_resources_cb_; | 129 OnPlayerReleasedCB on_player_released_cb_; |
129 | 130 |
130 private: | 131 private: |
131 friend class MediaPlayerListener; | 132 friend class MediaPlayerListener; |
132 | 133 |
133 // Player ID assigned to this player. | 134 // Player ID assigned to this player. |
134 int player_id_; | 135 int player_id_; |
135 | 136 |
136 // Resource manager for all the media players. | 137 // Resource manager for all the media players. |
137 MediaPlayerManager* manager_; | 138 MediaPlayerManager* manager_; |
138 | 139 |
139 // Url for the frame that contains this player. | 140 // Url for the frame that contains this player. |
140 GURL frame_url_; | 141 GURL frame_url_; |
141 | 142 |
142 // Listener object that listens to all the media player events. | 143 // Listener object that listens to all the media player events. |
143 scoped_ptr<MediaPlayerListener> listener_; | 144 scoped_ptr<MediaPlayerListener> listener_; |
144 | 145 |
145 // Weak pointer passed to |listener_| for callbacks. | 146 // Weak pointer passed to |listener_| for callbacks. |
146 // NOTE: Weak pointers must be invalidated before all other member variables. | 147 // NOTE: Weak pointers must be invalidated before all other member variables. |
147 base::WeakPtrFactory<MediaPlayerAndroid> weak_factory_; | 148 base::WeakPtrFactory<MediaPlayerAndroid> weak_factory_; |
148 | 149 |
149 DISALLOW_COPY_AND_ASSIGN(MediaPlayerAndroid); | 150 DISALLOW_COPY_AND_ASSIGN(MediaPlayerAndroid); |
150 }; | 151 }; |
151 | 152 |
152 } // namespace media | 153 } // namespace media |
153 | 154 |
154 #endif // MEDIA_BASE_ANDROID_MEDIA_PLAYER_ANDROID_H_ | 155 #endif // MEDIA_BASE_ANDROID_MEDIA_PLAYER_ANDROID_H_ |
OLD | NEW |