summaryrefslogtreecommitdiffstats
path: root/content/browser/android/media_player_manager_impl.h
blob: 61c1557f416b0143e5e48d6adf961dddcf2ebb39 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_BROWSER_ANDROID_MEDIA_PLAYER_MANAGER_IMPL_H_
#define CONTENT_BROWSER_ANDROID_MEDIA_PLAYER_MANAGER_IMPL_H_

#include <map>

#include "base/callback.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h"
#include "base/time.h"
#include "content/browser/android/content_video_view.h"
#include "content/public/browser/render_view_host_observer.h"
#include "googleurl/src/gurl.h"
#include "media/base/android/demuxer_stream_player_params.h"
#include "media/base/android/media_player_android.h"
#include "media/base/android/media_player_manager.h"
#include "ui/gfx/rect_f.h"

namespace content {

class WebContents;

// This class manages all the MediaPlayerAndroid objects. It receives
// control operations from the the render process, and forwards
// them to corresponding MediaPlayerAndroid object. Callbacks from
// MediaPlayerAndroid objects are converted to IPCs and then sent to the
// render process.
class MediaPlayerManagerImpl
    : public RenderViewHostObserver,
      public media::MediaPlayerManager {
 public:
  virtual ~MediaPlayerManagerImpl();

  // RenderViewHostObserver overrides.
  virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;

  // Fullscreen video playback controls.
  void FullscreenPlayerPlay();
  void FullscreenPlayerPause();
  void FullscreenPlayerSeek(int msec);
  void ExitFullscreen(bool release_media_player);
  void SetVideoSurface(jobject surface);

  // media::MediaPlayerManager overrides.
  virtual void OnTimeUpdate(
      int player_id, base::TimeDelta current_time) OVERRIDE;
  virtual void OnMediaMetadataChanged(
      int player_id,
      base::TimeDelta duration,
      int width,
      int height,
      bool success) OVERRIDE;
  virtual void OnPlaybackComplete(int player_id) OVERRIDE;
  virtual void OnMediaInterrupted(int player_id) OVERRIDE;
  virtual void OnBufferingUpdate(int player_id, int percentage) OVERRIDE;
  virtual void OnSeekComplete(
      int player_id, base::TimeDelta current_time) OVERRIDE;
  virtual void OnError(int player_id, int error) OVERRIDE;
  virtual void OnVideoSizeChanged(
      int player_id, int width, int height) OVERRIDE;
  virtual void OnReadFromDemuxer(
      int player_id,
      media::DemuxerStream::Type type,
      bool seek_done) OVERRIDE;
  virtual void RequestMediaResources(
      media::MediaPlayerAndroid* player) OVERRIDE;
  virtual void ReleaseMediaResources(
      media::MediaPlayerAndroid* player) OVERRIDE;
  virtual media::MediaResourceGetter* GetMediaResourceGetter() OVERRIDE;
  virtual media::MediaPlayerAndroid* GetFullscreenPlayer() OVERRIDE;
  virtual media::MediaPlayerAndroid* GetPlayer(int player_id) OVERRIDE;
  virtual void DestroyAllMediaPlayers() OVERRIDE;

#if defined(GOOGLE_TV)
  void AttachExternalVideoSurface(int player_id, jobject surface);
  void DetachExternalVideoSurface(int player_id);
#endif

 protected:
  friend MediaPlayerManager* MediaPlayerManager::Create(
      content::RenderViewHost*);

  // The instance of this class is supposed to be created by either Create()
  // method of MediaPlayerManager or the derived classes constructors.
  explicit MediaPlayerManagerImpl(RenderViewHost* render_view_host);

 private:
  // Message handlers.
  void OnEnterFullscreen(int player_id);
  void OnExitFullscreen(int player_id);
  void OnInitialize(int player_id, const GURL& url,
                    bool is_media_source,
                    const GURL& first_party_for_cookies);
  void OnStart(int player_id);
  void OnSeek(int player_id, base::TimeDelta time);
  void OnPause(int player_id);
  void OnReleaseResources(int player_id);
  void OnDestroyPlayer(int player_id);
  void OnDemuxerReady(
      int player_id,
      const media::MediaPlayerHostMsg_DemuxerReady_Params& params);
  void OnReadFromDemuxerAck(
      int player_id,
      const media::MediaPlayerHostMsg_ReadFromDemuxerAck_Params& params);

#if defined(GOOGLE_TV)
  void OnNotifyExternalSurface(
      int player_id, bool is_request, const gfx::RectF& rect);
#endif

  // An array of managed players.
  ScopedVector<media::MediaPlayerAndroid> players_;

  // The fullscreen video view object.
  ContentVideoView video_view_;

  // Player ID of the fullscreen media player.
  int fullscreen_player_id_;

  WebContents* web_contents_;

  // Object for retrieving resources media players.
  scoped_ptr<media::MediaResourceGetter> media_resource_getter_;

  DISALLOW_COPY_AND_ASSIGN(MediaPlayerManagerImpl);
};

}  // namespace content

#endif  // CONTENT_BROWSER_ANDROID_MEDIA_PLAYER_MANAGER_IMPL_H_