[BackgroundSync] Clean up some tests
[chromium-blink-merge.git] / media / base / android / media_player_android.h
blob8928222156bc3078098507ac81452009c0d44185
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
3 // found in the LICENSE file.
5 #ifndef MEDIA_BASE_ANDROID_MEDIA_PLAYER_ANDROID_H_
6 #define MEDIA_BASE_ANDROID_MEDIA_PLAYER_ANDROID_H_
8 #include <jni.h>
9 #include <string>
11 #include "base/callback.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/time/time.h"
14 #include "media/base/android/media_player_listener.h"
15 #include "media/base/media_export.h"
16 #include "ui/gl/android/scoped_java_surface.h"
17 #include "url/gurl.h"
19 namespace media {
21 class BrowserCdm;
22 class MediaPlayerManager;
24 // This class serves as the base class for different media player
25 // implementations on Android. Subclasses need to provide their own
26 // MediaPlayerAndroid::Create() implementation.
27 class MEDIA_EXPORT MediaPlayerAndroid {
28 public:
29 virtual ~MediaPlayerAndroid();
31 // Error types for MediaErrorCB.
32 enum MediaErrorType {
33 MEDIA_ERROR_FORMAT,
34 MEDIA_ERROR_DECODE,
35 MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK,
36 MEDIA_ERROR_INVALID_CODE,
39 // Callback when the player needs decoding resources.
40 typedef base::Callback<void(int player_id)> RequestMediaResourcesCB;
42 // Virtual destructor.
43 // For most subclasses we can delete on the caller thread.
44 virtual void DeleteOnCorrectThread();
46 // Passing an external java surface object to the player.
47 virtual void SetVideoSurface(gfx::ScopedJavaSurface surface) = 0;
49 // Start playing the media.
50 virtual void Start() = 0;
52 // Pause the media.
53 virtual void Pause(bool is_media_related_action) = 0;
55 // Seek to a particular position, based on renderer signaling actual seek
56 // with MediaPlayerHostMsg_Seek. If eventual success, OnSeekComplete() will be
57 // called.
58 virtual void SeekTo(base::TimeDelta timestamp) = 0;
60 // Release the player resources.
61 virtual void Release() = 0;
63 // Set the player volume.
64 virtual void SetVolume(double volume) = 0;
66 // Get the media information from the player.
67 virtual int GetVideoWidth() = 0;
68 virtual int GetVideoHeight() = 0;
69 virtual base::TimeDelta GetDuration() = 0;
70 virtual base::TimeDelta GetCurrentTime() = 0;
71 virtual bool IsPlaying() = 0;
72 virtual bool IsPlayerReady() = 0;
73 virtual bool CanPause() = 0;
74 virtual bool CanSeekForward() = 0;
75 virtual bool CanSeekBackward() = 0;
76 virtual GURL GetUrl();
77 virtual GURL GetFirstPartyForCookies();
79 // Associates the |cdm| with this player.
80 virtual void SetCdm(BrowserCdm* cdm);
82 int player_id() { return player_id_; }
84 GURL frame_url() { return frame_url_; }
86 protected:
87 MediaPlayerAndroid(int player_id,
88 MediaPlayerManager* manager,
89 const RequestMediaResourcesCB& request_media_resources_cb,
90 const GURL& frame_url);
92 // TODO(qinmin): Simplify the MediaPlayerListener class to only listen to
93 // media interrupt events. And have a separate child class to listen to all
94 // the events needed by MediaPlayerBridge. http://crbug.com/422597.
95 // MediaPlayerListener callbacks.
96 virtual void OnVideoSizeChanged(int width, int height);
97 virtual void OnMediaError(int error_type);
98 virtual void OnBufferingUpdate(int percent);
99 virtual void OnPlaybackComplete();
100 virtual void OnMediaInterrupted();
101 virtual void OnSeekComplete();
102 virtual void OnMediaPrepared();
104 // Attach/Detaches |listener_| for listening to all the media events. If
105 // |j_media_player| is NULL, |listener_| only listens to the system media
106 // events. Otherwise, it also listens to the events from |j_media_player|.
107 void AttachListener(jobject j_media_player);
108 void DetachListener();
110 // When destroying a subclassed object on a non-UI thread
111 // it is still required to destroy the |listener_| related stuff
112 // on the UI thread.
113 void DestroyListenerOnUIThread();
114 void SetAudible(bool is_audible);
116 MediaPlayerManager* manager() { return manager_; }
118 RequestMediaResourcesCB request_media_resources_cb_;
120 private:
121 friend class MediaPlayerListener;
123 // Player ID assigned to this player.
124 int player_id_;
126 // Resource manager for all the media players.
127 MediaPlayerManager* manager_;
129 // Url for the frame that contains this player.
130 GURL frame_url_;
132 // Listener object that listens to all the media player events.
133 scoped_ptr<MediaPlayerListener> listener_;
135 // Maintains the audible state of the player, true if it is playing sound.
136 bool is_audible_;
138 // Weak pointer passed to |listener_| for callbacks.
139 // NOTE: Weak pointers must be invalidated before all other member variables.
140 base::WeakPtrFactory<MediaPlayerAndroid> weak_factory_;
142 DISALLOW_COPY_AND_ASSIGN(MediaPlayerAndroid);
145 } // namespace media
147 #endif // MEDIA_BASE_ANDROID_MEDIA_PLAYER_ANDROID_H_