| 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)> OnDecoderResourcesReleasedCB; |
| 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 // Requests playback permission from MediaPlayerManager. | 83 // Requests playback permission from MediaPlayerManager. |
| 84 // Overridden in MediaCodecPlayer to pass data between threads. | 84 // Overridden in MediaCodecPlayer to pass data between threads. |
| 85 virtual void RequestPermissionAndPostResult(base::TimeDelta duration) {} | 85 virtual void RequestPermissionAndPostResult(base::TimeDelta duration) {} |
| 86 | 86 |
| 87 // Overridden in MediaCodecPlayer to pass data between threads. | 87 // Overridden in MediaCodecPlayer to pass data between threads. |
| 88 virtual void OnMediaMetadataChanged(base::TimeDelta duration, | 88 virtual void OnMediaMetadataChanged(base::TimeDelta duration, |
| 89 const gfx::Size& video_size) {} | 89 const gfx::Size& video_size) {} |
| 90 | 90 |
| 91 // Overridden in MediaCodecPlayer to pass data between threads. | 91 // Overridden in MediaCodecPlayer to pass data between threads. |
| 92 virtual void OnTimeUpdate(base::TimeDelta current_timestamp, | 92 virtual void OnTimeUpdate(base::TimeDelta current_timestamp, |
| 93 base::TimeTicks current_time_ticks) {} | 93 base::TimeTicks current_time_ticks) {} |
| 94 | 94 |
| 95 int player_id() { return player_id_; } | 95 int player_id() { return player_id_; } |
| 96 | 96 |
| 97 GURL frame_url() { return frame_url_; } | 97 GURL frame_url() { return frame_url_; } |
| 98 | 98 |
| 99 // Attach/Detaches |listener_| for listening to all the media events. If | 99 // Attach/Detaches |listener_| for listening to all the media events. If |
| 100 // |j_media_player| is NULL, |listener_| only listens to the system media | 100 // |j_media_player| is NULL, |listener_| only listens to the system media |
| 101 // events. Otherwise, it also listens to the events from |j_media_player|. | 101 // events. Otherwise, it also listens to the events from |j_media_player|. |
| 102 void AttachListener(jobject j_media_player); | 102 void AttachListener(jobject j_media_player); |
| 103 void DetachListener(); | 103 void DetachListener(); |
| 104 | 104 |
| 105 protected: | 105 protected: |
| 106 MediaPlayerAndroid(int player_id, | 106 MediaPlayerAndroid( |
| 107 MediaPlayerManager* manager, | 107 int player_id, |
| 108 const RequestMediaResourcesCB& request_media_resources_cb, | 108 MediaPlayerManager* manager, |
| 109 const GURL& frame_url); | 109 const OnDecoderResourcesReleasedCB& on_decoder_resources_released_cb, |
| 110 const GURL& frame_url); |
| 110 | 111 |
| 111 // TODO(qinmin): Simplify the MediaPlayerListener class to only listen to | 112 // TODO(qinmin): Simplify the MediaPlayerListener class to only listen to |
| 112 // media interrupt events. And have a separate child class to listen to all | 113 // media interrupt events. And have a separate child class to listen to all |
| 113 // the events needed by MediaPlayerBridge. http://crbug.com/422597. | 114 // the events needed by MediaPlayerBridge. http://crbug.com/422597. |
| 114 // MediaPlayerListener callbacks. | 115 // MediaPlayerListener callbacks. |
| 115 virtual void OnVideoSizeChanged(int width, int height); | 116 virtual void OnVideoSizeChanged(int width, int height); |
| 116 virtual void OnMediaError(int error_type); | 117 virtual void OnMediaError(int error_type); |
| 117 virtual void OnBufferingUpdate(int percent); | 118 virtual void OnBufferingUpdate(int percent); |
| 118 virtual void OnPlaybackComplete(); | 119 virtual void OnPlaybackComplete(); |
| 119 virtual void OnMediaInterrupted(); | 120 virtual void OnMediaInterrupted(); |
| 120 virtual void OnSeekComplete(); | 121 virtual void OnSeekComplete(); |
| 121 virtual void OnMediaPrepared(); | 122 virtual void OnMediaPrepared(); |
| 122 | 123 |
| 123 // When destroying a subclassed object on a non-UI thread | 124 // When destroying a subclassed object on a non-UI thread |
| 124 // it is still required to destroy the |listener_| related stuff | 125 // it is still required to destroy the |listener_| related stuff |
| 125 // on the UI thread. | 126 // on the UI thread. |
| 126 void DestroyListenerOnUIThread(); | 127 void DestroyListenerOnUIThread(); |
| 127 | 128 |
| 128 MediaPlayerManager* manager() { return manager_; } | 129 MediaPlayerManager* manager() { return manager_; } |
| 129 | 130 |
| 130 base::WeakPtr<MediaPlayerAndroid> WeakPtrForUIThread(); | 131 base::WeakPtr<MediaPlayerAndroid> WeakPtrForUIThread(); |
| 131 | 132 |
| 132 RequestMediaResourcesCB request_media_resources_cb_; | 133 OnDecoderResourcesReleasedCB on_decoder_resources_released_cb_; |
| 133 | 134 |
| 134 private: | 135 private: |
| 135 friend class MediaPlayerListener; | 136 friend class MediaPlayerListener; |
| 136 | 137 |
| 137 // Player ID assigned to this player. | 138 // Player ID assigned to this player. |
| 138 int player_id_; | 139 int player_id_; |
| 139 | 140 |
| 140 // Resource manager for all the media players. | 141 // Resource manager for all the media players. |
| 141 MediaPlayerManager* manager_; | 142 MediaPlayerManager* manager_; |
| 142 | 143 |
| 143 // Url for the frame that contains this player. | 144 // Url for the frame that contains this player. |
| 144 GURL frame_url_; | 145 GURL frame_url_; |
| 145 | 146 |
| 146 // Listener object that listens to all the media player events. | 147 // Listener object that listens to all the media player events. |
| 147 scoped_ptr<MediaPlayerListener> listener_; | 148 scoped_ptr<MediaPlayerListener> listener_; |
| 148 | 149 |
| 149 // Weak pointer passed to |listener_| for callbacks. | 150 // Weak pointer passed to |listener_| for callbacks. |
| 150 // NOTE: Weak pointers must be invalidated before all other member variables. | 151 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 151 base::WeakPtrFactory<MediaPlayerAndroid> weak_factory_; | 152 base::WeakPtrFactory<MediaPlayerAndroid> weak_factory_; |
| 152 | 153 |
| 153 DISALLOW_COPY_AND_ASSIGN(MediaPlayerAndroid); | 154 DISALLOW_COPY_AND_ASSIGN(MediaPlayerAndroid); |
| 154 }; | 155 }; |
| 155 | 156 |
| 156 } // namespace media | 157 } // namespace media |
| 157 | 158 |
| 158 #endif // MEDIA_BASE_ANDROID_MEDIA_PLAYER_ANDROID_H_ | 159 #endif // MEDIA_BASE_ANDROID_MEDIA_PLAYER_ANDROID_H_ |
| OLD | NEW |