Home | History | Annotate | Download | only in android
      1 // Copyright 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 CONTENT_RENDERER_MEDIA_ANDROID_WEBMEDIAPLAYER_PROXY_ANDROID_H_
      6 #define CONTENT_RENDERER_MEDIA_ANDROID_WEBMEDIAPLAYER_PROXY_ANDROID_H_
      7 
      8 #include <string>
      9 #include <vector>
     10 
     11 #include "base/basictypes.h"
     12 #include "base/time/time.h"
     13 #include "content/public/renderer/render_view_observer.h"
     14 #include "media/base/android/demuxer_stream_player_params.h"
     15 #include "media/base/android/media_player_android.h"
     16 #include "media/base/media_keys.h"
     17 #include "url/gurl.h"
     18 
     19 namespace content {
     20 class WebMediaPlayerAndroid;
     21 class RendererMediaPlayerManager;
     22 
     23 // This class manages IPC communication between WebMediaPlayerAndroid and the
     24 // MediaPlayerManagerAndroid in the browser process.
     25 class WebMediaPlayerProxyAndroid : public RenderViewObserver {
     26  public:
     27   // Construct a WebMediaPlayerProxyAndroid object for the |render_view|.
     28   // |manager| is passed to this class so that it can find the right
     29   // WebMediaPlayerAndroid using player IDs.
     30   WebMediaPlayerProxyAndroid(
     31       RenderView* render_view,
     32       RendererMediaPlayerManager* manager);
     33   virtual ~WebMediaPlayerProxyAndroid();
     34 
     35   // RenderViewObserver overrides.
     36   virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
     37 
     38   // Initializes a MediaPlayerAndroid object in browser process.
     39   void Initialize(int player_id,
     40                   const GURL& url,
     41                   media::MediaPlayerAndroid::SourceType source_type,
     42                   const GURL& first_party_for_cookies);
     43 
     44   // Starts the player.
     45   void Start(int player_id);
     46 
     47   // Pausees the player.
     48   void Pause(int player_id);
     49 
     50   // Performs seek on the player.
     51   void Seek(int player_id, base::TimeDelta time);
     52 
     53   // Set the player volume.
     54   void SetVolume(int player_id, double volume);
     55 
     56   // Release resources for the player.
     57   void ReleaseResources(int player_id);
     58 
     59   // Destroy the player in the browser process
     60   void DestroyPlayer(int player_id);
     61 
     62   // Request the player to enter fullscreen.
     63   void EnterFullscreen(int player_id);
     64 
     65   // Request the player to exit fullscreen.
     66   void ExitFullscreen(int player_id);
     67 
     68 #if defined(GOOGLE_TV)
     69   // Request an external surface for out-of-band compositing.
     70   void RequestExternalSurface(int player_id, const gfx::RectF& geometry);
     71 
     72   // RenderViewObserver overrides.
     73   virtual void DidCommitCompositorFrame() OVERRIDE;
     74 #endif
     75 
     76   // Media source related methods.
     77   void DemuxerReady(int player_id,
     78                     const media::MediaPlayerHostMsg_DemuxerReady_Params&);
     79   void ReadFromDemuxerAck(
     80       int player_id,
     81       const media::MediaPlayerHostMsg_ReadFromDemuxerAck_Params& params);
     82   void SeekRequestAck(int player_id, unsigned seek_request_id);
     83   void DurationChanged(int player_id, const base::TimeDelta& duration);
     84 
     85   // Encrypted media related methods.
     86   void InitializeCDM(int media_keys_id, const std::vector<uint8>& uuid);
     87   void GenerateKeyRequest(int media_keys_id,
     88                           const std::string& type,
     89                           const std::vector<uint8>& init_data);
     90   void AddKey(int media_keys_id,
     91               const std::vector<uint8>& key,
     92               const std::vector<uint8>& init_data,
     93               const std::string& session_id);
     94   void CancelKeyRequest(int media_keys_id, const std::string& session_id);
     95 
     96  private:
     97   WebMediaPlayerAndroid* GetWebMediaPlayer(int player_id);
     98 
     99   // Message handlers.
    100   void OnMediaMetadataChanged(int player_id,
    101                               base::TimeDelta duration,
    102                               int width,
    103                               int height,
    104                               bool success);
    105   void OnMediaPlaybackCompleted(int player_id);
    106   void OnMediaBufferingUpdate(int player_id, int percent);
    107   void OnMediaSeekCompleted(int player_id, base::TimeDelta current_time);
    108   void OnMediaError(int player_id, int error);
    109   void OnVideoSizeChanged(int player_id, int width, int height);
    110   void OnTimeUpdate(int player_id, base::TimeDelta current_time);
    111   void OnMediaPlayerReleased(int player_id);
    112   void OnDidExitFullscreen(int player_id);
    113   void OnDidEnterFullscreen(int player_id);
    114   void OnPlayerPlay(int player_id);
    115   void OnPlayerPause(int player_id);
    116   void OnReadFromDemuxer(int player_id,
    117                          media::DemuxerStream::Type type);
    118   void OnMediaSeekRequest(int player_id,
    119                           base::TimeDelta time_to_seek,
    120                           unsigned seek_request_id);
    121   void OnMediaConfigRequest(int player_id);
    122   void OnKeyAdded(int media_keys_id, const std::string& session_id);
    123   void OnKeyError(int media_keys_id,
    124                   const std::string& session_id,
    125                   media::MediaKeys::KeyError error_code,
    126                   int system_code);
    127   void OnKeyMessage(int media_keys_id,
    128                     const std::string& session_id,
    129                     const std::vector<uint8>& message,
    130                     const std::string& destination_url);
    131 
    132   RendererMediaPlayerManager* manager_;
    133 
    134   DISALLOW_IMPLICIT_CONSTRUCTORS(WebMediaPlayerProxyAndroid);
    135 };
    136 
    137 }  // namespace content
    138 
    139 #endif  // CONTENT_RENDERER_MEDIA_ANDROID_WEBMEDIAPLAYER_PROXY_ANDROID_H_
    140