Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / media / base / android / media_player_android.h
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.
4
5 #ifndef MEDIA_BASE_ANDROID_MEDIA_PLAYER_ANDROID_H_
6 #define MEDIA_BASE_ANDROID_MEDIA_PLAYER_ANDROID_H_
7
8 #include <jni.h>
9 #include <string>
10
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"
16
17 namespace media {
18
19 class BrowserCdm;
20 class MediaPlayerManager;
21
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();
28
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,
35   };
36
37   // Callback when the player needs decoding resources.
38   typedef base::Callback<void(int player_id)> RequestMediaResourcesCB;
39
40   // Passing an external java surface object to the player.
41   virtual void SetVideoSurface(gfx::ScopedJavaSurface surface) = 0;
42
43   // Start playing the media.
44   virtual void Start() = 0;
45
46   // Pause the media.
47   virtual void Pause(bool is_media_related_action) = 0;
48
49   // Seek to a particular position, based on renderer signaling actual seek
50   // with MediaPlayerHostMsg_Seek. If eventual success, OnSeekComplete() will be
51   // called.
52   virtual void SeekTo(base::TimeDelta timestamp) = 0;
53
54   // Release the player resources.
55   virtual void Release() = 0;
56
57   // Set the player volume.
58   virtual void SetVolume(double volume) = 0;
59
60   // Get the media information from the player.
61   virtual int GetVideoWidth() = 0;
62   virtual int GetVideoHeight() = 0;
63   virtual base::TimeDelta GetDuration() = 0;
64   virtual base::TimeDelta GetCurrentTime() = 0;
65   virtual bool IsPlaying() = 0;
66   virtual bool IsPlayerReady() = 0;
67   virtual bool CanPause() = 0;
68   virtual bool CanSeekForward() = 0;
69   virtual bool CanSeekBackward() = 0;
70   virtual GURL GetUrl();
71   virtual GURL GetFirstPartyForCookies();
72
73   // Associates the |cdm| with this player.
74   virtual void SetCdm(BrowserCdm* cdm);
75
76   // Check whether the player still uses the current surface.
77   virtual bool IsSurfaceInUse() const = 0;
78
79   int player_id() { return player_id_; }
80
81   GURL frame_url() { return frame_url_; }
82
83  protected:
84   MediaPlayerAndroid(int player_id,
85                      MediaPlayerManager* manager,
86                      const RequestMediaResourcesCB& request_media_resources_cb,
87                      const GURL& frame_url);
88
89   MediaPlayerManager* manager() { return manager_; }
90
91   RequestMediaResourcesCB request_media_resources_cb_;
92
93  private:
94   // Player ID assigned to this player.
95   int player_id_;
96
97   // Resource manager for all the media players.
98   MediaPlayerManager* manager_;
99
100   // Url for the frame that contains this player.
101   GURL frame_url_;
102
103   DISALLOW_COPY_AND_ASSIGN(MediaPlayerAndroid);
104 };
105
106 }  // namespace media
107
108 #endif  // MEDIA_BASE_ANDROID_MEDIA_PLAYER_ANDROID_H_