Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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_REMOTING_RPC_RPC_H_ | |
| 6 #define MEDIA_REMOTING_RPC_RPC_H_ | |
| 7 | |
| 8 #include <cstdint> | |
| 9 #include <string> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/macros.h" | |
| 13 #include "base/memory/ref_counted.h" | |
| 14 #include "media/base/audio_decoder_config.h" | |
| 15 #include "media/base/cdm_config.h" | |
| 16 #include "media/base/cdm_key_information.h" | |
| 17 #include "media/base/demuxer_stream.h" | |
| 18 #include "media/base/eme_constants.h" | |
| 19 #include "media/base/media_keys.h" | |
| 20 #include "media/base/pipeline_status.h" | |
| 21 #include "media/base/video_decoder_config.h" | |
| 22 #include "media/remoting/remoting_rpc_message.pb.h" | |
| 23 | |
| 24 namespace media { | |
| 25 namespace remoting { | |
| 26 | |
| 27 class CdmPromiseResult; | |
| 28 | |
| 29 namespace internal { | |
| 30 | |
| 31 template <class T> | |
| 32 inline bool ProtoMessageGet(const pb::RpcMessage& message, T* value); | |
| 33 | |
| 34 template <class T> | |
| 35 inline void ProtoMessageSet(pb::RpcMessage* message, const T& value); | |
| 36 | |
| 37 template <> | |
| 38 inline bool ProtoMessageGet<bool>(const pb::RpcMessage& message, bool* value) { | |
| 39 if (!message.has_boolean_value()) | |
| 40 return false; | |
| 41 *value = message.boolean_value(); | |
| 42 return true; | |
| 43 } | |
| 44 | |
| 45 template <> | |
| 46 inline bool ProtoMessageGet<int>(const pb::RpcMessage& message, int* value) { | |
| 47 if (!message.has_integer_value()) | |
| 48 return false; | |
| 49 *value = message.integer_value(); | |
| 50 return true; | |
| 51 } | |
| 52 | |
| 53 template <> | |
| 54 inline bool ProtoMessageGet<int64_t>(const pb::RpcMessage& message, | |
| 55 int64_t* value) { | |
| 56 if (!message.has_integer64_value()) | |
| 57 return false; | |
| 58 *value = message.integer64_value(); | |
| 59 return true; | |
| 60 } | |
| 61 | |
| 62 template <> | |
| 63 inline bool ProtoMessageGet<double>(const pb::RpcMessage& message, | |
| 64 double* value) { | |
| 65 if (!message.has_double_value()) | |
| 66 return false; | |
| 67 *value = message.double_value(); | |
| 68 return true; | |
| 69 } | |
| 70 | |
| 71 template <> | |
| 72 inline bool ProtoMessageGet<std::string>(const pb::RpcMessage& message, | |
| 73 std::string* value) { | |
| 74 if (!message.has_string_value()) | |
| 75 return false; | |
| 76 *value = message.string_value(); | |
| 77 return true; | |
| 78 } | |
| 79 | |
| 80 template <> | |
| 81 inline void ProtoMessageSet<bool>(pb::RpcMessage* message, const bool& value) { | |
| 82 message->set_boolean_value(value); | |
| 83 } | |
| 84 | |
| 85 template <> | |
| 86 inline void ProtoMessageSet<int>(pb::RpcMessage* message, const int& value) { | |
| 87 message->set_integer_value(value); | |
| 88 } | |
| 89 | |
| 90 template <> | |
| 91 inline void ProtoMessageSet<int64_t>(pb::RpcMessage* message, | |
| 92 const int64_t& value) { | |
| 93 message->set_integer64_value(value); | |
| 94 } | |
| 95 | |
| 96 template <> | |
| 97 inline void ProtoMessageSet<double>(pb::RpcMessage* message, | |
| 98 const double& value) { | |
| 99 message->set_double_value(value); | |
| 100 } | |
| 101 | |
| 102 template <> | |
| 103 inline void ProtoMessageSet<std::string>(pb::RpcMessage* message, | |
| 104 const std::string& value) { | |
| 105 message->set_string_value(value); | |
| 106 } | |
| 107 | |
| 108 bool CdmPromiseFromMessage(const pb::CdmPromise& promise_message, | |
| 109 CdmPromiseResult* result, | |
| 110 std::string* session_id); | |
| 111 | |
| 112 void CdmPromiseToMessage(pb::CdmPromise* promise_message, | |
| 113 const CdmPromiseResult& result, | |
| 114 const std::string& session_id); | |
| 115 | |
| 116 } // namespace internal | |
| 117 | |
| 118 class Rpc : public base::RefCountedThreadSafe<Rpc> { | |
|
miu
2016/09/08 01:07:35
Is there a special reason to ref-count this object
| |
| 119 public: | |
| 120 static const int kInvalidHandle = -1; | |
| 121 static const int kReceiverHandle = 0; | |
| 122 | |
| 123 static scoped_refptr<Rpc> FromMessage(const std::string& proto); | |
|
miu
2016/09/08 01:07:35
Note: Since these will come from the Mojo interfac
| |
| 124 | |
| 125 int handle() const { return handle_; } | |
| 126 | |
| 127 std::string ToMessage() const; | |
|
miu
2016/09/08 01:07:35
ditto: If these are to be sent via the Mojo interf
| |
| 128 | |
| 129 virtual pb::RpcProc GetProc() const = 0; | |
| 130 | |
| 131 protected: | |
| 132 friend class base::RefCountedThreadSafe<Rpc>; | |
| 133 explicit Rpc(int handle); | |
| 134 virtual ~Rpc(); | |
| 135 | |
| 136 virtual void ToMessageInternal(pb::RpcMessage* rpc) const = 0; | |
| 137 | |
| 138 private: | |
| 139 int handle_; | |
| 140 | |
| 141 DISALLOW_COPY_AND_ASSIGN(Rpc); | |
| 142 }; | |
| 143 | |
| 144 template <typename T, pb::RpcProc Proc> | |
| 145 class SimpleRpc : public Rpc { | |
| 146 public: | |
| 147 SimpleRpc(int handle, T value) : Rpc(handle), value_(value) {} | |
| 148 | |
| 149 static scoped_refptr<SimpleRpc> FromRpcMessage(const pb::RpcMessage* rpc) { | |
| 150 T value; | |
| 151 if (!internal::ProtoMessageGet(*rpc, &value)) { | |
| 152 LOG(ERROR) << "Not valid proto buffer message"; | |
| 153 return nullptr; | |
| 154 } | |
| 155 | |
| 156 return new SimpleRpc(rpc->handle(), value); | |
| 157 } | |
| 158 | |
| 159 const T& value() const { return value_; } | |
| 160 | |
| 161 pb::RpcProc GetProc() const override { return Proc; } | |
| 162 | |
| 163 protected: | |
| 164 void ToMessageInternal(pb::RpcMessage* rpc) const override { | |
| 165 internal::ProtoMessageSet(rpc, value_); | |
| 166 } | |
| 167 | |
| 168 private: | |
| 169 ~SimpleRpc() override = default; | |
| 170 T value_; | |
| 171 }; | |
| 172 | |
| 173 template <pb::RpcProc Proc> | |
| 174 class NullRpc : public Rpc { | |
| 175 public: | |
| 176 explicit NullRpc(int handle) : Rpc(handle) {} | |
| 177 | |
| 178 static scoped_refptr<NullRpc> FromRpcMessage(const pb::RpcMessage* rpc) { | |
| 179 return new NullRpc(rpc->handle()); | |
| 180 } | |
| 181 | |
| 182 pb::RpcProc GetProc() const override { return Proc; } | |
| 183 | |
| 184 protected: | |
| 185 void ToMessageInternal(pb::RpcMessage* rpc) const override {} | |
| 186 | |
| 187 private: | |
| 188 ~NullRpc() override = default; | |
| 189 }; | |
| 190 | |
| 191 //============================================================================== | |
| 192 using AcquireRendererRpc = SimpleRpc<int, pb::RPC_ACQUIRE_RENDERER>; | |
| 193 using AcquireRendererDoneRpc = SimpleRpc<int, pb::RPC_ACQUIRE_RENDERER_DONE>; | |
| 194 using AcquireCdmRpc = SimpleRpc<int, pb::RPC_ACQUIRE_CDM>; | |
| 195 using AcquireCdmDoneRpc = SimpleRpc<int, pb::RPC_ACQUIRE_CDM_DONE>; | |
| 196 | |
| 197 //============================================================================== | |
| 198 class RendererInitializeRpc : public Rpc { | |
|
miu
2016/09/08 01:07:35
General comments for rest of file: Do we really ne
erickung1
2016/09/08 18:18:45
We had similar discussion before sending out this
miu
2016/09/08 20:33:37
I should also admit: I myself am often tempted to
| |
| 199 public: | |
| 200 RendererInitializeRpc(int handle, | |
| 201 int client_handle, | |
| 202 int audio_demuxer_handle, | |
| 203 int video_demuxer_handle, | |
| 204 int callback_handle); | |
| 205 | |
| 206 static scoped_refptr<RendererInitializeRpc> FromRpcMessage( | |
| 207 const pb::RpcMessage* rpc); | |
| 208 | |
| 209 int client_handle() const { return client_handle_; } | |
| 210 int audio_demuxer_handle() const { return audio_demuxer_handle_; } | |
| 211 int video_demuxer_handle() const { return video_demuxer_handle_; } | |
| 212 int callback_handle() const { return callback_handle_; } | |
| 213 | |
| 214 pb::RpcProc GetProc() const override; | |
| 215 | |
| 216 protected: | |
| 217 void ToMessageInternal(pb::RpcMessage* rpc) const override; | |
| 218 | |
| 219 private: | |
| 220 ~RendererInitializeRpc() override; | |
| 221 int client_handle_; | |
| 222 int audio_demuxer_handle_; | |
| 223 int video_demuxer_handle_; | |
| 224 int callback_handle_; | |
| 225 }; | |
| 226 | |
| 227 //============================================================================== | |
| 228 class RendererFlushUntilRpc : public Rpc { | |
| 229 public: | |
| 230 RendererFlushUntilRpc(int handle, | |
| 231 uint32_t audio_frame_id, | |
| 232 uint32_t video_frame_id, | |
| 233 int callback_handle); | |
| 234 | |
| 235 static scoped_refptr<RendererFlushUntilRpc> FromRpcMessage( | |
| 236 const pb::RpcMessage* rpc); | |
| 237 | |
| 238 uint32_t audio_frame_id() const { return audio_frame_id_; } | |
| 239 uint32_t video_frame_id() const { return video_frame_id_; } | |
| 240 int callback_handle() const { return callback_handle_; } | |
| 241 | |
| 242 pb::RpcProc GetProc() const override; | |
| 243 | |
| 244 protected: | |
| 245 void ToMessageInternal(pb::RpcMessage* rpc) const override; | |
| 246 | |
| 247 private: | |
| 248 ~RendererFlushUntilRpc() override; | |
| 249 uint32_t audio_frame_id_; | |
| 250 uint32_t video_frame_id_; | |
| 251 int callback_handle_; | |
| 252 }; | |
| 253 | |
| 254 //============================================================================== | |
| 255 using RendererStartPlayingFromRpc = | |
| 256 SimpleRpc<int64_t, pb::RPC_R_STARTPLAYINGFROM>; | |
| 257 using RendererSetPlaybackRateRpc = SimpleRpc<double, pb::RPC_R_SETPLAYBACKRATE>; | |
| 258 using RendererSetVolumeRpc = SimpleRpc<double, pb::RPC_R_SETVOLUME>; | |
| 259 | |
| 260 //============================================================================== | |
| 261 class RendererSetCdmRpc : public Rpc { | |
| 262 public: | |
| 263 RendererSetCdmRpc(int handle, int cdm_id, int callback_handle); | |
| 264 | |
| 265 static scoped_refptr<RendererSetCdmRpc> FromRpcMessage( | |
| 266 const pb::RpcMessage* rpc); | |
| 267 | |
| 268 int cdm_id() const { return cdm_id_; } | |
| 269 int callback_handle() const { return callback_handle_; } | |
| 270 | |
| 271 pb::RpcProc GetProc() const override; | |
| 272 | |
| 273 protected: | |
| 274 void ToMessageInternal(pb::RpcMessage* rpc) const override; | |
| 275 | |
| 276 private: | |
| 277 ~RendererSetCdmRpc() override; | |
| 278 int cdm_id_; | |
| 279 int callback_handle_; | |
| 280 }; | |
| 281 | |
| 282 //============================================================================== | |
| 283 using RendererInitializeCallbackRpc = | |
| 284 SimpleRpc<bool, pb::RPC_R_INITIALIZE_CALLBACK>; | |
| 285 using RendererFlushUntilCallbackRpc = NullRpc<pb::RPC_R_FLUSHUNTIL_CALLBACK>; | |
| 286 using RendererSetCdmCallbackRpc = SimpleRpc<bool, pb::RPC_R_SETCDM_CALLBACK>; | |
| 287 | |
| 288 //============================================================================== | |
| 289 class RendererClientOnTimeUpdateRpc : public Rpc { | |
| 290 public: | |
| 291 RendererClientOnTimeUpdateRpc(int handle, | |
| 292 int64_t time_usec, | |
| 293 int64_t max_time_usec); | |
| 294 | |
| 295 static scoped_refptr<RendererClientOnTimeUpdateRpc> FromRpcMessage( | |
| 296 const pb::RpcMessage* rpc); | |
| 297 | |
| 298 int64_t time_usec() const { return time_usec_; } | |
| 299 int64_t max_time_usec() const { return max_time_usec_; } | |
| 300 | |
| 301 pb::RpcProc GetProc() const override; | |
| 302 | |
| 303 protected: | |
| 304 void ToMessageInternal(pb::RpcMessage* rpc) const override; | |
| 305 | |
| 306 private: | |
| 307 ~RendererClientOnTimeUpdateRpc() override; | |
| 308 int64_t time_usec_; | |
| 309 int64_t max_time_usec_; | |
| 310 }; | |
| 311 | |
| 312 //============================================================================== | |
| 313 using RendererClientOnBufferingStateChangeRpc = | |
| 314 SimpleRpc<int, pb::RPC_RC_ONBUFFERINGSTATECHANGE>; | |
| 315 using RendererClientOnEndedRpc = NullRpc<pb::RPC_RC_ONENDED>; | |
| 316 using RendererClientOnErrorRpc = NullRpc<pb::RPC_RC_ONERROR>; | |
| 317 | |
| 318 //============================================================================== | |
| 319 class RendererClientOnVideoNaturalSizeChangeRpc : public Rpc { | |
| 320 public: | |
| 321 RendererClientOnVideoNaturalSizeChangeRpc(int handle, const gfx::Size& size); | |
| 322 | |
| 323 static scoped_refptr<RendererClientOnVideoNaturalSizeChangeRpc> | |
| 324 FromRpcMessage(const pb::RpcMessage* rpc); | |
| 325 | |
| 326 const gfx::Size& size() const { return size_; } | |
| 327 | |
| 328 pb::RpcProc GetProc() const override; | |
| 329 | |
| 330 protected: | |
| 331 void ToMessageInternal(pb::RpcMessage* rpc) const override; | |
| 332 | |
| 333 private: | |
| 334 ~RendererClientOnVideoNaturalSizeChangeRpc() override; | |
| 335 gfx::Size size_; | |
| 336 }; | |
| 337 | |
| 338 //============================================================================== | |
| 339 using RendererClientOnVideoOpacityChangeRpc = | |
| 340 SimpleRpc<bool, pb::RPC_RC_ONVIDEOOPACITYCHANGE>; | |
| 341 | |
| 342 //============================================================================== | |
| 343 class RendererClientOnStatisticsUpdateRpc : public Rpc { | |
| 344 public: | |
| 345 RendererClientOnStatisticsUpdateRpc(int handle, | |
| 346 const ::media::PipelineStatistics& stats); | |
| 347 | |
| 348 static scoped_refptr<RendererClientOnStatisticsUpdateRpc> FromRpcMessage( | |
| 349 const pb::RpcMessage* rpc); | |
| 350 | |
| 351 const ::media::PipelineStatistics& stats() const { return stats_; } | |
| 352 | |
| 353 pb::RpcProc GetProc() const override; | |
| 354 | |
| 355 protected: | |
| 356 void ToMessageInternal(pb::RpcMessage* rpc) const override; | |
| 357 | |
| 358 private: | |
| 359 ~RendererClientOnStatisticsUpdateRpc() override; | |
| 360 ::media::PipelineStatistics stats_; | |
| 361 }; | |
| 362 | |
| 363 //============================================================================== | |
| 364 using RendererClientOnWaitingForDecryptionKeyRpc = | |
| 365 NullRpc<pb::RPC_RC_ONWAITINGFORDECRYPTIONKEY>; | |
| 366 using RendererClientOnDurationChangeRpc = | |
| 367 SimpleRpc<int64_t, pb::RPC_RC_ONDURATIONCHANGE>; | |
| 368 using DemuxerStreamInitializeRpc = SimpleRpc<int, pb::RPC_DS_INITIALIZE>; | |
| 369 using DemuxerStreamEnableBitstreamConverterRpc = | |
| 370 NullRpc<pb::RPC_DS_ENABLEBITSTREAMCONVERTER>; | |
| 371 | |
| 372 //============================================================================== | |
| 373 class DemuxerStreamReadUntilRpc : public Rpc { | |
| 374 public: | |
| 375 DemuxerStreamReadUntilRpc(int handle, uint32_t frame_id, int callback_handle); | |
| 376 | |
| 377 static scoped_refptr<DemuxerStreamReadUntilRpc> FromRpcMessage( | |
| 378 const pb::RpcMessage* rpc); | |
| 379 | |
| 380 uint32_t frame_id() const { return frame_id_; } | |
| 381 int callback_handle() const { return callback_handle_; } | |
| 382 | |
| 383 pb::RpcProc GetProc() const override; | |
| 384 | |
| 385 protected: | |
| 386 void ToMessageInternal(pb::RpcMessage* rpc) const override; | |
| 387 | |
| 388 private: | |
| 389 ~DemuxerStreamReadUntilRpc() override; | |
| 390 uint32_t frame_id_; | |
| 391 int callback_handle_; | |
| 392 }; | |
| 393 | |
| 394 class DemuxerStreamInitializeCallbackRpc : public Rpc { | |
| 395 public: | |
| 396 DemuxerStreamInitializeCallbackRpc( | |
| 397 int handle, | |
| 398 ::media::DemuxerStream::Type type, | |
| 399 const ::media::AudioDecoderConfig& audio_config, | |
| 400 const ::media::VideoDecoderConfig& video_config); | |
| 401 | |
| 402 static scoped_refptr<DemuxerStreamInitializeCallbackRpc> FromRpcMessage( | |
| 403 const pb::RpcMessage* rpc); | |
| 404 | |
| 405 ::media::DemuxerStream::Type type() const { return type_; } | |
| 406 const ::media::AudioDecoderConfig& audio_config() const { | |
| 407 return audio_config_; | |
| 408 } | |
| 409 const ::media::VideoDecoderConfig& video_config() const { | |
| 410 return video_config_; | |
| 411 } | |
| 412 | |
| 413 pb::RpcProc GetProc() const override; | |
| 414 | |
| 415 protected: | |
| 416 void ToMessageInternal(pb::RpcMessage* rpc) const override; | |
| 417 | |
| 418 private: | |
| 419 ~DemuxerStreamInitializeCallbackRpc() override; | |
| 420 ::media::DemuxerStream::Type type_; | |
| 421 ::media::AudioDecoderConfig audio_config_; | |
| 422 ::media::VideoDecoderConfig video_config_; | |
| 423 }; | |
| 424 | |
| 425 class DemuxerStreamReadUntilCallbackRpc : public Rpc { | |
| 426 public: | |
| 427 DemuxerStreamReadUntilCallbackRpc( | |
| 428 int handle, | |
| 429 uint32_t frame_id, | |
| 430 ::media::DemuxerStream::Status status, | |
| 431 const ::media::AudioDecoderConfig& audio_config, | |
| 432 const ::media::VideoDecoderConfig& video_config); | |
| 433 | |
| 434 static scoped_refptr<DemuxerStreamReadUntilCallbackRpc> FromRpcMessage( | |
| 435 const pb::RpcMessage* rpc); | |
| 436 | |
| 437 uint32_t frame_id() const { return frame_id_; } | |
| 438 ::media::DemuxerStream::Status status() const { return status_; } | |
| 439 | |
| 440 const ::media::AudioDecoderConfig& audio_config() const { | |
| 441 return audio_config_; | |
| 442 } | |
| 443 const ::media::VideoDecoderConfig& video_config() const { | |
| 444 return video_config_; | |
| 445 } | |
| 446 | |
| 447 pb::RpcProc GetProc() const override; | |
| 448 | |
| 449 protected: | |
| 450 void ToMessageInternal(pb::RpcMessage* rpc) const override; | |
| 451 | |
| 452 private: | |
| 453 ~DemuxerStreamReadUntilCallbackRpc() override; | |
| 454 uint32_t frame_id_; | |
| 455 ::media::DemuxerStream::Status status_; | |
| 456 ::media::AudioDecoderConfig audio_config_; | |
| 457 ::media::VideoDecoderConfig video_config_; | |
| 458 }; | |
| 459 | |
| 460 typedef SimpleRpc<int, pb::RPC_CDM_SETCLIENT> CdmSetClientRpc; | |
| 461 | |
| 462 class CdmInitializeRpc : public Rpc { | |
| 463 public: | |
| 464 CdmInitializeRpc(int handle, | |
| 465 const std::string& key_system, | |
| 466 const std::string& security_origin, | |
| 467 const ::media::CdmConfig& cdm_config, | |
| 468 int callback_handle); | |
| 469 | |
| 470 static scoped_refptr<CdmInitializeRpc> FromRpcMessage( | |
| 471 const pb::RpcMessage* rpc); | |
| 472 | |
| 473 const std::string& key_system() const { return key_system_; } | |
| 474 const std::string& security_origin() const { return security_origin_; } | |
| 475 const ::media::CdmConfig& cdm_config() const { return cdm_config_; } | |
| 476 int callback_handle() const { return callback_handle_; } | |
| 477 | |
| 478 pb::RpcProc GetProc() const override; | |
| 479 | |
| 480 protected: | |
| 481 void ToMessageInternal(pb::RpcMessage* rpc) const override; | |
| 482 | |
| 483 private: | |
| 484 ~CdmInitializeRpc() override; | |
| 485 std::string key_system_; | |
| 486 std::string security_origin_; | |
| 487 ::media::CdmConfig cdm_config_; | |
| 488 int callback_handle_; | |
| 489 }; | |
| 490 | |
| 491 class CdmSetServerCertificateRpc : public Rpc { | |
| 492 public: | |
| 493 CdmSetServerCertificateRpc(int handle, | |
| 494 const uint8_t* certificate_data, | |
| 495 size_t certificate_data_size, | |
| 496 int callback_handle); | |
| 497 | |
| 498 static scoped_refptr<CdmSetServerCertificateRpc> FromRpcMessage( | |
| 499 const pb::RpcMessage* rpc); | |
| 500 | |
| 501 const uint8_t* certificate_data() const { | |
| 502 return certificate_data_.empty() ? nullptr : certificate_data_.data(); | |
| 503 } | |
| 504 size_t certificate_data_size() const { return certificate_data_.size(); } | |
| 505 int callback_handle() const { return callback_handle_; } | |
| 506 | |
| 507 pb::RpcProc GetProc() const override; | |
| 508 | |
| 509 protected: | |
| 510 void ToMessageInternal(pb::RpcMessage* rpc) const override; | |
| 511 | |
| 512 private: | |
| 513 ~CdmSetServerCertificateRpc() override; | |
| 514 std::vector<uint8_t> certificate_data_; | |
| 515 int callback_handle_; | |
| 516 }; | |
| 517 | |
| 518 class CdmCreateSessionAndGenerateRequestRpc : public Rpc { | |
| 519 public: | |
| 520 CdmCreateSessionAndGenerateRequestRpc( | |
| 521 int handle, | |
| 522 ::media::MediaKeys::SessionType session_type, | |
| 523 ::media::EmeInitDataType init_data_type, | |
| 524 const uint8_t* init_data, | |
| 525 size_t init_data_size, | |
| 526 int callback_handle); | |
| 527 | |
| 528 static scoped_refptr<CdmCreateSessionAndGenerateRequestRpc> FromRpcMessage( | |
| 529 const pb::RpcMessage* rpc); | |
| 530 | |
| 531 ::media::MediaKeys::SessionType session_type() const { return session_type_; } | |
| 532 ::media::EmeInitDataType init_data_type() const { return init_data_type_; } | |
| 533 const uint8_t* init_data() const { | |
| 534 return init_data_.empty() ? nullptr : init_data_.data(); | |
| 535 } | |
| 536 size_t init_data_size() const { return init_data_.size(); } | |
| 537 int callback_handle() const { return callback_handle_; } | |
| 538 | |
| 539 pb::RpcProc GetProc() const override; | |
| 540 | |
| 541 protected: | |
| 542 void ToMessageInternal(pb::RpcMessage* rpc) const override; | |
| 543 | |
| 544 private: | |
| 545 ~CdmCreateSessionAndGenerateRequestRpc() override; | |
| 546 ::media::MediaKeys::SessionType session_type_; | |
| 547 ::media::EmeInitDataType init_data_type_; | |
| 548 std::vector<uint8_t> init_data_; | |
| 549 int callback_handle_; | |
| 550 }; | |
| 551 | |
| 552 class CdmLoadSessionRpc : public Rpc { | |
| 553 public: | |
| 554 CdmLoadSessionRpc(int handle, | |
| 555 ::media::MediaKeys::SessionType session_type, | |
| 556 const std::string& session_id, | |
| 557 int callback_handle); | |
| 558 | |
| 559 static scoped_refptr<CdmLoadSessionRpc> FromRpcMessage( | |
| 560 const pb::RpcMessage* rpc); | |
| 561 | |
| 562 ::media::MediaKeys::SessionType session_type() const { return session_type_; } | |
| 563 const std::string& session_id() const { return session_id_; } | |
| 564 int callback_handle() const { return callback_handle_; } | |
| 565 | |
| 566 pb::RpcProc GetProc() const override; | |
| 567 | |
| 568 protected: | |
| 569 void ToMessageInternal(pb::RpcMessage* rpc) const override; | |
| 570 | |
| 571 private: | |
| 572 ~CdmLoadSessionRpc() override; | |
| 573 ::media::MediaKeys::SessionType session_type_; | |
| 574 std::string session_id_; | |
| 575 int callback_handle_; | |
| 576 }; | |
| 577 | |
| 578 class CdmUpdateSessionRpc : public Rpc { | |
| 579 public: | |
| 580 CdmUpdateSessionRpc(int handle, | |
| 581 const std::string& session_id, | |
| 582 const uint8_t* response, | |
| 583 size_t response_size, | |
| 584 int callback_handle); | |
| 585 | |
| 586 static scoped_refptr<CdmUpdateSessionRpc> FromRpcMessage( | |
| 587 const pb::RpcMessage* rpc); | |
| 588 | |
| 589 const std::string& session_id() const { return session_id_; } | |
| 590 const uint8_t* response() const { | |
| 591 return response_.empty() ? nullptr : response_.data(); | |
| 592 } | |
| 593 size_t response_size() const { return response_.size(); } | |
| 594 int callback_handle() const { return callback_handle_; } | |
| 595 | |
| 596 pb::RpcProc GetProc() const override; | |
| 597 | |
| 598 protected: | |
| 599 void ToMessageInternal(pb::RpcMessage* rpc) const override; | |
| 600 | |
| 601 private: | |
| 602 ~CdmUpdateSessionRpc() override; | |
| 603 std::string session_id_; | |
| 604 std::vector<uint8_t> response_; | |
| 605 int callback_handle_; | |
| 606 }; | |
| 607 | |
| 608 class CdmCloseSessionRpc : public Rpc { | |
| 609 public: | |
| 610 CdmCloseSessionRpc(int handle, | |
| 611 const std::string& session_id, | |
| 612 int callback_handle); | |
| 613 | |
| 614 static scoped_refptr<CdmCloseSessionRpc> FromRpcMessage( | |
| 615 const pb::RpcMessage* rpc); | |
| 616 | |
| 617 const std::string& session_id() const { return session_id_; } | |
| 618 int callback_handle() const { return callback_handle_; } | |
| 619 | |
| 620 pb::RpcProc GetProc() const override; | |
| 621 | |
| 622 protected: | |
| 623 void ToMessageInternal(pb::RpcMessage* rpc) const override; | |
| 624 | |
| 625 private: | |
| 626 ~CdmCloseSessionRpc() override; | |
| 627 std::string session_id_; | |
| 628 int callback_handle_; | |
| 629 }; | |
| 630 | |
| 631 class CdmRemoveSessionRpc : public Rpc { | |
| 632 public: | |
| 633 CdmRemoveSessionRpc(int handle, | |
| 634 const std::string& session_id, | |
| 635 int callback_handle); | |
| 636 | |
| 637 static scoped_refptr<CdmRemoveSessionRpc> FromRpcMessage( | |
| 638 const pb::RpcMessage* rpc); | |
| 639 | |
| 640 const std::string& session_id() const { return session_id_; } | |
| 641 int callback_handle() const { return callback_handle_; } | |
| 642 | |
| 643 pb::RpcProc GetProc() const override; | |
| 644 | |
| 645 protected: | |
| 646 void ToMessageInternal(pb::RpcMessage* rpc) const override; | |
| 647 | |
| 648 private: | |
| 649 ~CdmRemoveSessionRpc() override; | |
| 650 std::string session_id_; | |
| 651 int callback_handle_; | |
| 652 }; | |
| 653 | |
| 654 class CdmPromiseResult { | |
| 655 public: | |
| 656 CdmPromiseResult(); | |
| 657 CdmPromiseResult(::media::MediaKeys::Exception exception, | |
| 658 uint32_t system_code, | |
| 659 std::string error_message); | |
| 660 CdmPromiseResult(const CdmPromiseResult& other); | |
| 661 ~CdmPromiseResult(); | |
| 662 | |
| 663 static CdmPromiseResult SuccessResult(); | |
| 664 | |
| 665 bool success() const { return success_; } | |
| 666 ::media::MediaKeys::Exception exception() const { return exception_; } | |
| 667 uint32_t system_code() const { return system_code_; } | |
| 668 const std::string& error_message() const { return error_message_; } | |
| 669 | |
| 670 private: | |
| 671 bool success_; | |
| 672 ::media::MediaKeys::Exception exception_; | |
| 673 uint32_t system_code_; | |
| 674 std::string error_message_; | |
| 675 }; | |
| 676 | |
| 677 template <pb::RpcProc Proc> | |
| 678 class CdmPromiseCallbackRpc : public Rpc { | |
| 679 public: | |
| 680 CdmPromiseCallbackRpc(int handle, const CdmPromiseResult& result) | |
| 681 : Rpc(handle), result_(result) {} | |
| 682 | |
| 683 static scoped_refptr<CdmPromiseCallbackRpc> FromRpcMessage( | |
| 684 const pb::RpcMessage* rpc) { | |
| 685 CdmPromiseResult result; | |
| 686 DCHECK(rpc->has_cdm_promise_rpc()); | |
| 687 const pb::CdmPromise promise_message = rpc->cdm_promise_rpc(); | |
| 688 if (!internal::CdmPromiseFromMessage(promise_message, &result, nullptr)) | |
| 689 return nullptr; | |
| 690 return new CdmPromiseCallbackRpc(rpc->handle(), result); | |
| 691 } | |
| 692 | |
| 693 const CdmPromiseResult& result() const { return result_; } | |
| 694 | |
| 695 pb::RpcProc GetProc() const override { return Proc; } | |
| 696 | |
| 697 protected: | |
| 698 ~CdmPromiseCallbackRpc() = default; | |
| 699 void ToMessageInternal(pb::RpcMessage* rpc) const override { | |
| 700 pb::CdmPromise* promise_message = rpc->mutable_cdm_promise_rpc(); | |
| 701 internal::CdmPromiseToMessage(promise_message, result_, ""); | |
| 702 } | |
| 703 | |
| 704 private: | |
| 705 CdmPromiseResult result_; | |
| 706 }; | |
| 707 | |
| 708 template <pb::RpcProc Proc> | |
| 709 class CdmPromiseWithSessionIdCallbackRpc : public CdmPromiseCallbackRpc<Proc> { | |
| 710 public: | |
| 711 CdmPromiseWithSessionIdCallbackRpc(int handle, | |
| 712 const CdmPromiseResult& result, | |
| 713 const std::string& session_id) | |
| 714 : CdmPromiseCallbackRpc<Proc>(handle, result), session_id_(session_id) {} | |
| 715 | |
| 716 static scoped_refptr<CdmPromiseWithSessionIdCallbackRpc> FromRpcMessage( | |
| 717 const pb::RpcMessage* rpc) { | |
| 718 CdmPromiseResult result; | |
| 719 std::string session_id; | |
| 720 DCHECK(rpc->has_cdm_promise_rpc()); | |
| 721 const pb::CdmPromise promise_message = rpc->cdm_promise_rpc(); | |
| 722 if (!internal::CdmPromiseFromMessage(promise_message, &result, &session_id)) | |
| 723 return nullptr; | |
| 724 return new CdmPromiseWithSessionIdCallbackRpc(rpc->handle(), result, | |
| 725 session_id); | |
| 726 } | |
| 727 | |
| 728 const std::string& session_id() const { return session_id_; } | |
| 729 | |
| 730 protected: | |
| 731 void ToMessageInternal(pb::RpcMessage* rpc) const override { | |
| 732 pb::CdmPromise* promise_message = rpc->mutable_cdm_promise_rpc(); | |
| 733 internal::CdmPromiseToMessage( | |
| 734 promise_message, CdmPromiseCallbackRpc<Proc>::result(), session_id_); | |
| 735 } | |
| 736 | |
| 737 private: | |
| 738 ~CdmPromiseWithSessionIdCallbackRpc() = default; | |
| 739 std::string session_id_; | |
| 740 }; | |
| 741 | |
| 742 //============================================================================== | |
| 743 using CdmSetServerCertificateCallbackRpc = | |
| 744 CdmPromiseCallbackRpc<pb::RPC_CDM_SETSERVERCERTIFICATE_CALLBACK>; | |
| 745 using CdmCreateSessionAndGenerateRequestCallbackRpc = | |
| 746 CdmPromiseWithSessionIdCallbackRpc< | |
| 747 pb::RPC_CDM_CREATESESSIONANDGENERATEREQUEST_CALLBACK>; | |
| 748 using CdmLoadSessionCallbackRpc = | |
| 749 CdmPromiseWithSessionIdCallbackRpc<pb::RPC_CDM_LOADSESSION_CALLBACK>; | |
| 750 using CdmUpdateSessionCallbackRpc = | |
| 751 CdmPromiseCallbackRpc<pb::RPC_CDM_UPDATESESSION_CALLBACK>; | |
| 752 using CdmCloseSessionCallbackRpc = | |
| 753 CdmPromiseCallbackRpc<pb::RPC_CDM_CLOSESESSION_CALLBACK>; | |
| 754 using CdmRemoveSessionCallbackRpc = | |
| 755 CdmPromiseCallbackRpc<pb::RPC_CDM_REMOVESESSION_CALLBACK>; | |
| 756 | |
| 757 //============================================================================== | |
| 758 class CdmInitializeCallbackRpc | |
| 759 : public CdmPromiseCallbackRpc<pb::RPC_CDM_INITIALIZE_CALLBACK> { | |
| 760 public: | |
| 761 CdmInitializeCallbackRpc(int handle, | |
| 762 const CdmPromiseResult& result, | |
| 763 int cdm_id, | |
| 764 int decryptor_handle); | |
| 765 | |
| 766 static scoped_refptr<CdmInitializeCallbackRpc> FromRpcMessage( | |
| 767 const pb::RpcMessage* rpc); | |
| 768 | |
| 769 int cdm_id() const { return cdm_id_; } | |
| 770 int decryptor_handle() const { return decryptor_handle_; } | |
| 771 | |
| 772 protected: | |
| 773 void ToMessageInternal(pb::RpcMessage* rpc) const override; | |
| 774 | |
| 775 private: | |
| 776 ~CdmInitializeCallbackRpc() override; | |
| 777 int cdm_id_; | |
| 778 int decryptor_handle_; | |
| 779 }; | |
| 780 | |
| 781 class CdmClientOnSessionMessageRpc : public Rpc { | |
| 782 public: | |
| 783 CdmClientOnSessionMessageRpc(int handle, | |
| 784 const std::string& session_id, | |
| 785 ::media::MediaKeys::MessageType message_type, | |
| 786 const uint8_t* message, | |
| 787 size_t message_size); | |
| 788 | |
| 789 static scoped_refptr<CdmClientOnSessionMessageRpc> FromRpcMessage( | |
| 790 const pb::RpcMessage* rpc); | |
| 791 | |
| 792 const std::string& session_id() const { return session_id_; } | |
| 793 ::media::MediaKeys::MessageType message_type() const { return message_type_; } | |
| 794 const uint8_t* message() const { | |
| 795 return message_.empty() ? nullptr : message_.data(); | |
| 796 } | |
| 797 size_t message_size() const { return message_.size(); } | |
| 798 | |
| 799 pb::RpcProc GetProc() const override; | |
| 800 | |
| 801 protected: | |
| 802 void ToMessageInternal(pb::RpcMessage* rpc) const override; | |
| 803 | |
| 804 private: | |
| 805 ~CdmClientOnSessionMessageRpc() override; | |
| 806 std::string session_id_; | |
| 807 ::media::MediaKeys::MessageType message_type_; | |
| 808 std::vector<uint8_t> message_; | |
| 809 }; | |
| 810 | |
| 811 //============================================================================== | |
| 812 using CdmClientOnSessionClosedRpc = | |
| 813 SimpleRpc<std::string, pb::RPC_CDMC_ONSESSIONCLOSED>; | |
| 814 | |
| 815 //============================================================================== | |
| 816 class CdmClientOnSessionKeysChangeRpc : public Rpc { | |
| 817 public: | |
| 818 CdmClientOnSessionKeysChangeRpc( | |
| 819 int handle, | |
| 820 const std::string& session_id, | |
| 821 bool has_additional_usable_key, | |
| 822 const ::media::CdmKeyInformation* key_information, | |
| 823 size_t key_information_size); | |
| 824 | |
| 825 static scoped_refptr<CdmClientOnSessionKeysChangeRpc> FromRpcMessage( | |
| 826 const pb::RpcMessage* rpc); | |
| 827 | |
| 828 const std::string& session_id() const { return session_id_; } | |
| 829 bool has_additional_usable_key() const { return has_additional_usable_key_; } | |
| 830 const ::media::CdmKeyInformation* key_information() const { | |
| 831 return key_information_.empty() ? nullptr : key_information_.data(); | |
| 832 } | |
| 833 size_t key_information_size() const { return key_information_.size(); } | |
| 834 | |
| 835 pb::RpcProc GetProc() const override; | |
| 836 | |
| 837 protected: | |
| 838 void ToMessageInternal(pb::RpcMessage* rpc) const override; | |
| 839 | |
| 840 private: | |
| 841 ~CdmClientOnSessionKeysChangeRpc() override; | |
| 842 std::string session_id_; | |
| 843 bool has_additional_usable_key_; | |
| 844 std::vector<::media::CdmKeyInformation> key_information_; | |
| 845 }; | |
| 846 | |
| 847 class CdmClientOnSessionExpirationUpdateRpc : public Rpc { | |
| 848 public: | |
| 849 CdmClientOnSessionExpirationUpdateRpc(int handle, | |
| 850 const std::string& session_id, | |
| 851 double new_expiry_time_sec); | |
| 852 | |
| 853 static scoped_refptr<CdmClientOnSessionExpirationUpdateRpc> FromRpcMessage( | |
| 854 const pb::RpcMessage* rpc); | |
| 855 | |
| 856 const std::string& session_id() const { return session_id_; } | |
| 857 double new_expiry_time_sec() const { return new_expiry_time_sec_; } | |
| 858 | |
| 859 pb::RpcProc GetProc() const override; | |
| 860 | |
| 861 protected: | |
| 862 void ToMessageInternal(pb::RpcMessage* rpc) const override; | |
| 863 | |
| 864 private: | |
| 865 ~CdmClientOnSessionExpirationUpdateRpc() override; | |
| 866 std::string session_id_; | |
| 867 double new_expiry_time_sec_; | |
| 868 }; | |
| 869 | |
| 870 } // namespace remoting | |
| 871 } // namespace media | |
| 872 | |
| 873 #endif // MEDIA_REMOTING_RPC_RPC_H_ | |
| OLD | NEW |