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