Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / media / base / android / media_player_android.h
blob0fd481517c18827bbbb0d8a72a56933af81c7f35
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/time/time.h"
13 #include "media/base/media_export.h"
14 #include "ui/gl/android/scoped_java_surface.h"
15 #include "url/gurl.h"
17 namespace media {
19 class MediaDrmBridge;
20 class MediaPlayerManager;
22 // This class serves as the base class for different media player
23 // implementations on Android. Subclasses need to provide their own
24 // MediaPlayerAndroid::Create() implementation.
25 class MEDIA_EXPORT MediaPlayerAndroid {
26 public:
27 virtual ~MediaPlayerAndroid();
29 // Error types for MediaErrorCB.
30 enum MediaErrorType {
31 MEDIA_ERROR_FORMAT,
32 MEDIA_ERROR_DECODE,
33 MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK,
34 MEDIA_ERROR_INVALID_CODE,
37 // Callback when the player needs decoding resources.
38 typedef base::Callback<void(int player_id)> RequestMediaResourcesCB;
40 // Callback when the player releases decoding resources.
41 typedef base::Callback<void(int player_id)> ReleaseMediaResourcesCB;
43 // Passing an external java surface object to the player.
44 virtual void SetVideoSurface(gfx::ScopedJavaSurface surface) = 0;
46 // Start playing the media.
47 virtual void Start() = 0;
49 // Pause the media.
50 virtual void Pause(bool is_media_related_action) = 0;
52 // Seek to a particular position, based on renderer signaling actual seek
53 // with MediaPlayerHostMsg_Seek. If eventual success, OnSeekComplete() will be
54 // called.
55 virtual void SeekTo(base::TimeDelta timestamp) = 0;
57 // Release the player resources.
58 virtual void Release() = 0;
60 // Set the player volume.
61 virtual void SetVolume(double volume) = 0;
63 // Get the media information from the player.
64 virtual int GetVideoWidth() = 0;
65 virtual int GetVideoHeight() = 0;
66 virtual base::TimeDelta GetDuration() = 0;
67 virtual base::TimeDelta GetCurrentTime() = 0;
68 virtual bool IsPlaying() = 0;
69 virtual bool IsPlayerReady() = 0;
70 virtual bool CanPause() = 0;
71 virtual bool CanSeekForward() = 0;
72 virtual bool CanSeekBackward() = 0;
73 virtual GURL GetUrl();
74 virtual GURL GetFirstPartyForCookies();
76 // Pass a drm bridge to a player.
77 virtual void SetDrmBridge(MediaDrmBridge* drm_bridge);
79 // Notifies the player that a decryption key has been added. The player
80 // may want to start/resume playback if it is waiting for a key.
81 virtual void OnKeyAdded();
83 // Check whether the player still uses the current surface.
84 virtual bool IsSurfaceInUse() const = 0;
86 int player_id() { return player_id_; }
88 protected:
89 MediaPlayerAndroid(int player_id,
90 MediaPlayerManager* manager,
91 const RequestMediaResourcesCB& request_media_resources_cb,
92 const ReleaseMediaResourcesCB& release_media_resources_cb);
94 MediaPlayerManager* manager() { return manager_; }
96 RequestMediaResourcesCB request_media_resources_cb_;
98 ReleaseMediaResourcesCB release_media_resources_cb_;
100 private:
101 // Player ID assigned to this player.
102 int player_id_;
104 // Resource manager for all the media players.
105 MediaPlayerManager* manager_;
107 DISALLOW_COPY_AND_ASSIGN(MediaPlayerAndroid);
110 } // namespace media
112 #endif // MEDIA_BASE_ANDROID_MEDIA_PLAYER_ANDROID_H_