Home | History | Annotate | Download | only in media
      1 // Copyright (c) 2012 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 // IPC messages for android media player.
      6 // Multiply-included message file, hence no include guard.
      7 
      8 #include <string>
      9 #include <vector>
     10 
     11 #include "base/basictypes.h"
     12 #include "base/time/time.h"
     13 #include "content/common/content_export.h"
     14 #include "content/common/media/media_player_messages_enums_android.h"
     15 #include "ipc/ipc_message_macros.h"
     16 #include "media/base/android/media_player_android.h"
     17 #include "media/base/android/demuxer_stream_player_params.h"
     18 #include "media/base/media_keys.h"
     19 #include "ui/gfx/rect_f.h"
     20 #include "url/gurl.h"
     21 
     22 #undef IPC_MESSAGE_EXPORT
     23 #define IPC_MESSAGE_EXPORT CONTENT_EXPORT
     24 #define IPC_MESSAGE_START MediaPlayerMsgStart
     25 
     26 IPC_ENUM_TRAITS(media::AudioCodec)
     27 IPC_ENUM_TRAITS(media::DemuxerStream::Status)
     28 IPC_ENUM_TRAITS(media::DemuxerStream::Type)
     29 IPC_ENUM_TRAITS(media::MediaKeys::KeyError)
     30 IPC_ENUM_TRAITS(media::VideoCodec)
     31 
     32 IPC_STRUCT_TRAITS_BEGIN(media::DemuxerConfigs)
     33   IPC_STRUCT_TRAITS_MEMBER(audio_codec)
     34   IPC_STRUCT_TRAITS_MEMBER(audio_channels)
     35   IPC_STRUCT_TRAITS_MEMBER(audio_sampling_rate)
     36   IPC_STRUCT_TRAITS_MEMBER(is_audio_encrypted)
     37   IPC_STRUCT_TRAITS_MEMBER(audio_extra_data)
     38 
     39   IPC_STRUCT_TRAITS_MEMBER(video_codec)
     40   IPC_STRUCT_TRAITS_MEMBER(video_size)
     41   IPC_STRUCT_TRAITS_MEMBER(is_video_encrypted)
     42   IPC_STRUCT_TRAITS_MEMBER(video_extra_data)
     43 
     44   IPC_STRUCT_TRAITS_MEMBER(duration_ms)
     45 #if defined(GOOGLE_TV)
     46   IPC_STRUCT_TRAITS_MEMBER(key_system)
     47 #endif  // defined(GOOGLE_TV)
     48 IPC_STRUCT_TRAITS_END()
     49 
     50 IPC_STRUCT_TRAITS_BEGIN(media::DemuxerData)
     51   IPC_STRUCT_TRAITS_MEMBER(type)
     52   IPC_STRUCT_TRAITS_MEMBER(access_units)
     53 IPC_STRUCT_TRAITS_END()
     54 
     55 IPC_STRUCT_TRAITS_BEGIN(media::AccessUnit)
     56   IPC_STRUCT_TRAITS_MEMBER(status)
     57   IPC_STRUCT_TRAITS_MEMBER(end_of_stream)
     58   IPC_STRUCT_TRAITS_MEMBER(data)
     59   IPC_STRUCT_TRAITS_MEMBER(timestamp)
     60   IPC_STRUCT_TRAITS_MEMBER(key_id)
     61   IPC_STRUCT_TRAITS_MEMBER(iv)
     62   IPC_STRUCT_TRAITS_MEMBER(subsamples)
     63 IPC_STRUCT_TRAITS_END()
     64 
     65 IPC_STRUCT_TRAITS_BEGIN(media::SubsampleEntry)
     66   IPC_STRUCT_TRAITS_MEMBER(clear_bytes)
     67   IPC_STRUCT_TRAITS_MEMBER(cypher_bytes)
     68 IPC_STRUCT_TRAITS_END()
     69 
     70 IPC_ENUM_TRAITS(MediaPlayerHostMsg_Initialize_Type)
     71 
     72 // Chrome for Android seek message sequence is:
     73 // 1. Renderer->Browser MediaPlayerHostMsg_Seek
     74 //    This is the beginning of actual seek flow in response to web app requests
     75 //    for seeks and browser MediaPlayerMsg_SeekRequests. With this message,
     76 //    the renderer asks browser to perform actual seek. At most one of these
     77 //    actual seeks will be in process between this message and renderer's later
     78 //    receipt of MediaPlayerMsg_SeekCompleted from the browser.
     79 // 2. Browser->Renderer MediaPlayerMsg_SeekCompleted
     80 //    Once the browser determines the seek is complete, it sends this message to
     81 //    notify the renderer of seek completion.
     82 //
     83 // Other seek-related IPC messages:
     84 // Browser->Renderer MediaPlayerMsg_SeekRequest
     85 //    Browser requests to begin a seek. All browser-initiated seeks must begin
     86 //    with this request. Renderer controls actual seek initiation via the normal
     87 //    seek flow, above, keeping web apps aware of seeks. These requests are
     88 //    also allowed while another actual seek is in progress.
     89 //
     90 // If the demuxer is located in the renderer, as in media source players, the
     91 // browser must ensure the renderer demuxer is appropriately seeked between
     92 // receipt of MediaPlayerHostMsg_Seek and transmission of
     93 // MediaPlayerMsg_SeekCompleted. The following two renderer-demuxer control
     94 // messages book-end the renderer-demuxer seek:
     95 // 1.1 Browser->Renderer MediaPlayerMsg_DemuxerSeekRequest
     96 // 1.2 Renderer->Browser MediaPlayerHostMsg_DemuxerSeekDone
     97 
     98 // Only in short-term hack to seek to reach I-Frame to feed a newly constructed
     99 // video decoder may the above IPC sequence be modified to exclude SeekRequest,
    100 // Seek and SeekCompleted, with condition that DemuxerSeekRequest's
    101 // |is_browser_seek| parameter be true. Regular seek messages must still be
    102 // handled even when a hack browser seek is in progress. In this case, the
    103 // browser seek request's |time_to_seek| may no longer be buffered and the
    104 // demuxer may instead seek to a future buffered time. The resulting
    105 // DemuxerSeekDone message's |actual_browser_seek_time| is the time actually
    106 // seeked-to, and is only meaningful for these hack browser seeks.
    107 // TODO(wolenetz): Instead of doing browser seek, replay cached data since last
    108 // keyframe. See http://crbug.com/304234.
    109 
    110 // Messages for notifying the render process of media playback status -------
    111 
    112 // Media buffering has updated.
    113 IPC_MESSAGE_ROUTED2(MediaPlayerMsg_MediaBufferingUpdate,
    114                     int /* player_id */,
    115                     int /* percent */)
    116 
    117 // A media playback error has occurred.
    118 IPC_MESSAGE_ROUTED2(MediaPlayerMsg_MediaError,
    119                     int /* player_id */,
    120                     int /* error */)
    121 
    122 // Playback is completed.
    123 IPC_MESSAGE_ROUTED1(MediaPlayerMsg_MediaPlaybackCompleted,
    124                     int /* player_id */)
    125 
    126 // Media metadata has changed.
    127 IPC_MESSAGE_ROUTED5(MediaPlayerMsg_MediaMetadataChanged,
    128                     int /* player_id */,
    129                     base::TimeDelta /* duration */,
    130                     int /* width */,
    131                     int /* height */,
    132                     bool /* success */)
    133 
    134 // Requests renderer player to ask its client (blink HTMLMediaElement) to seek.
    135 IPC_MESSAGE_ROUTED2(MediaPlayerMsg_SeekRequest,
    136                     int /* player_id */,
    137                     base::TimeDelta /* time_to_seek_to */)
    138 
    139 // Media seek is completed.
    140 IPC_MESSAGE_ROUTED2(MediaPlayerMsg_SeekCompleted,
    141                     int /* player_id */,
    142                     base::TimeDelta /* current_time */)
    143 
    144 // Video size has changed.
    145 IPC_MESSAGE_ROUTED3(MediaPlayerMsg_MediaVideoSizeChanged,
    146                     int /* player_id */,
    147                     int /* width */,
    148                     int /* height */)
    149 
    150 // The current play time has updated.
    151 IPC_MESSAGE_ROUTED2(MediaPlayerMsg_MediaTimeUpdate,
    152                     int /* player_id */,
    153                     base::TimeDelta /* current_time */)
    154 
    155 // The player has been released.
    156 IPC_MESSAGE_ROUTED1(MediaPlayerMsg_MediaPlayerReleased,
    157                     int /* player_id */)
    158 
    159 // The player has entered fullscreen mode.
    160 IPC_MESSAGE_ROUTED1(MediaPlayerMsg_DidEnterFullscreen,
    161                     int /* player_id */)
    162 
    163 // The player exited fullscreen.
    164 IPC_MESSAGE_ROUTED1(MediaPlayerMsg_DidExitFullscreen,
    165                     int /* player_id */)
    166 
    167 // The player started playing.
    168 IPC_MESSAGE_ROUTED1(MediaPlayerMsg_DidMediaPlayerPlay,
    169                     int /* player_id */)
    170 
    171 // The player was paused.
    172 IPC_MESSAGE_ROUTED1(MediaPlayerMsg_DidMediaPlayerPause,
    173                     int /* player_id */)
    174 
    175 // Requests renderer demuxer seek.
    176 IPC_MESSAGE_CONTROL3(MediaPlayerMsg_DemuxerSeekRequest,
    177                      int /* demuxer_client_id */,
    178                      base::TimeDelta /* time_to_seek */,
    179                      bool /* is_browser_seek */)
    180 
    181 // The media source player reads data from demuxer
    182 IPC_MESSAGE_CONTROL2(MediaPlayerMsg_ReadFromDemuxer,
    183                      int /* demuxer_client_id */,
    184                      media::DemuxerStream::Type /* type */)
    185 
    186 // The player needs new config data
    187 IPC_MESSAGE_CONTROL1(MediaPlayerMsg_MediaConfigRequest,
    188                      int /* demuxer_client_id */)
    189 
    190 IPC_MESSAGE_ROUTED1(MediaPlayerMsg_ConnectedToRemoteDevice,
    191                     int /* player_id */)
    192 
    193 IPC_MESSAGE_ROUTED1(MediaPlayerMsg_DisconnectedFromRemoteDevice,
    194                     int /* player_id */)
    195 
    196 // Instructs the video element to enter fullscreen.
    197 IPC_MESSAGE_ROUTED1(MediaPlayerMsg_RequestFullscreen,
    198                     int /*player_id */)
    199 
    200 // Messages for controlling the media playback in browser process ----------
    201 
    202 // Destroy the media player object.
    203 IPC_MESSAGE_ROUTED1(MediaPlayerHostMsg_DestroyMediaPlayer,
    204                     int /* player_id */)
    205 
    206 // Destroy all the players.
    207 IPC_MESSAGE_ROUTED0(MediaPlayerHostMsg_DestroyAllMediaPlayers)
    208 
    209 // Initialize a media player object with the given type and player_id. The other
    210 // parameters are used depending on the type of player.
    211 //
    212 // url: the URL to load when initializing a URL player.
    213 //
    214 // first_party_for_cookies: the cookie store to use when loading a URL.
    215 //
    216 // demuxer_client_id: the demuxer associated with this player when initializing
    217 // a media source player.
    218 IPC_MESSAGE_ROUTED5(
    219     MediaPlayerHostMsg_Initialize,
    220     MediaPlayerHostMsg_Initialize_Type /* type */,
    221     int /* player_id */,
    222     GURL /* url */,
    223     GURL /* first_party_for_cookies */,
    224     int /* demuxer_client_id */)
    225 
    226 // Pause the player.
    227 IPC_MESSAGE_ROUTED2(MediaPlayerHostMsg_Pause,
    228                     int /* player_id */,
    229                     bool /* is_media_related_action */)
    230 
    231 // Release player resources, but keep the object for future usage.
    232 IPC_MESSAGE_ROUTED1(MediaPlayerHostMsg_Release, int /* player_id */)
    233 
    234 // Perform a seek.
    235 IPC_MESSAGE_ROUTED2(MediaPlayerHostMsg_Seek,
    236                     int /* player_id */,
    237                     base::TimeDelta /* time */)
    238 
    239 // Start the player for playback.
    240 IPC_MESSAGE_ROUTED1(MediaPlayerHostMsg_Start, int /* player_id */)
    241 
    242 // Start the player for playback.
    243 IPC_MESSAGE_ROUTED2(MediaPlayerHostMsg_SetVolume,
    244                     int /* player_id */,
    245                     double /* volume */)
    246 
    247 // Requests the player to enter fullscreen.
    248 IPC_MESSAGE_ROUTED1(MediaPlayerHostMsg_EnterFullscreen, int /* player_id */)
    249 
    250 // Requests the player to exit fullscreen.
    251 IPC_MESSAGE_ROUTED1(MediaPlayerHostMsg_ExitFullscreen, int /* player_id */)
    252 
    253 // Sent after the renderer demuxer has seeked.
    254 IPC_MESSAGE_CONTROL2(MediaPlayerHostMsg_DemuxerSeekDone,
    255                      int /* demuxer_client_id */,
    256                      base::TimeDelta /* actual_browser_seek_time */)
    257 
    258 // Inform the media source player that the demuxer is ready.
    259 IPC_MESSAGE_CONTROL2(MediaPlayerHostMsg_DemuxerReady,
    260                      int /* demuxer_client_id */,
    261                      media::DemuxerConfigs)
    262 
    263 // Sent when the data was read from the ChunkDemuxer.
    264 IPC_MESSAGE_CONTROL2(MediaPlayerHostMsg_ReadFromDemuxerAck,
    265                      int /* demuxer_client_id */,
    266                      media::DemuxerData)
    267 
    268 // Inform the media source player of changed media duration from demuxer.
    269 IPC_MESSAGE_CONTROL2(MediaPlayerHostMsg_DurationChanged,
    270                      int /* demuxer_client_id */,
    271                      base::TimeDelta /* duration */)
    272 
    273 #if defined(VIDEO_HOLE)
    274 // Notify the player about the external surface, requesting it if necessary.
    275 IPC_MESSAGE_ROUTED3(MediaPlayerHostMsg_NotifyExternalSurface,
    276                     int /* player_id */,
    277                     bool /* is_request */,
    278                     gfx::RectF /* rect */)
    279 #endif  // defined(VIDEO_HOLE)
    280 
    281 // Messages for encrypted media extensions API ------------------------------
    282 // TODO(xhwang): Move the following messages to a separate file.
    283 
    284 IPC_MESSAGE_ROUTED3(MediaKeysHostMsg_InitializeCDM,
    285                     int /* media_keys_id */,
    286                     std::vector<uint8> /* uuid */,
    287                     GURL /* frame url */)
    288 
    289 IPC_MESSAGE_ROUTED4(MediaKeysHostMsg_CreateSession,
    290                     int /* media_keys_id */,
    291                     uint32_t /* session_id */,
    292                     std::string /* type */,
    293                     std::vector<uint8> /* init_data */)
    294 // TODO(jrummell): Use enum for type (http://crbug.com/327449)
    295 
    296 IPC_MESSAGE_ROUTED3(MediaKeysHostMsg_UpdateSession,
    297                     int /* media_keys_id */,
    298                     uint32_t /* session_id */,
    299                     std::vector<uint8> /* response */)
    300 
    301 IPC_MESSAGE_ROUTED2(MediaKeysHostMsg_ReleaseSession,
    302                     int /* media_keys_id */,
    303                     uint32_t /* session_id */)
    304 
    305 IPC_MESSAGE_ROUTED3(MediaKeysMsg_SessionCreated,
    306                     int /* media_keys_id */,
    307                     uint32_t /* session_id */,
    308                     std::string /* web_session_id */)
    309 
    310 IPC_MESSAGE_ROUTED4(MediaKeysMsg_SessionMessage,
    311                     int /* media_keys_id */,
    312                     uint32_t /* session_id */,
    313                     std::vector<uint8> /* message */,
    314                     std::string /* destination_url */)
    315 // TODO(jrummell): Use GURL for destination_url (http://crbug.com/326663)
    316 
    317 IPC_MESSAGE_ROUTED2(MediaKeysMsg_SessionReady,
    318                     int /* media_keys_id */,
    319                     uint32_t /* session_id */)
    320 
    321 IPC_MESSAGE_ROUTED2(MediaKeysMsg_SessionClosed,
    322                     int /* media_keys_id */,
    323                     uint32_t /* session_id */)
    324 
    325 IPC_MESSAGE_ROUTED4(MediaKeysMsg_SessionError,
    326                     int /* media_keys_id */,
    327                     uint32_t /* session_id */,
    328                     media::MediaKeys::KeyError /* error_code */,
    329                     int /* system_code */)
    330