Chromium Code Reviews| Index: media/remoting/rpc/rpc.h |
| diff --git a/media/remoting/rpc/rpc.h b/media/remoting/rpc/rpc.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..15a9bd14ed9b74167569500772a2d04bcbee815a |
| --- /dev/null |
| +++ b/media/remoting/rpc/rpc.h |
| @@ -0,0 +1,873 @@ |
| +// Copyright 2016 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 MEDIA_REMOTING_RPC_RPC_H_ |
| +#define MEDIA_REMOTING_RPC_RPC_H_ |
| + |
| +#include <cstdint> |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "base/macros.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "media/base/audio_decoder_config.h" |
| +#include "media/base/cdm_config.h" |
| +#include "media/base/cdm_key_information.h" |
| +#include "media/base/demuxer_stream.h" |
| +#include "media/base/eme_constants.h" |
| +#include "media/base/media_keys.h" |
| +#include "media/base/pipeline_status.h" |
| +#include "media/base/video_decoder_config.h" |
| +#include "media/remoting/remoting_rpc_message.pb.h" |
| + |
| +namespace media { |
| +namespace remoting { |
| + |
| +class CdmPromiseResult; |
| + |
| +namespace internal { |
| + |
| +template <class T> |
| +inline bool ProtoMessageGet(const pb::RpcMessage& message, T* value); |
| + |
| +template <class T> |
| +inline void ProtoMessageSet(pb::RpcMessage* message, const T& value); |
| + |
| +template <> |
| +inline bool ProtoMessageGet<bool>(const pb::RpcMessage& message, bool* value) { |
| + if (!message.has_boolean_value()) |
| + return false; |
| + *value = message.boolean_value(); |
| + return true; |
| +} |
| + |
| +template <> |
| +inline bool ProtoMessageGet<int>(const pb::RpcMessage& message, int* value) { |
| + if (!message.has_integer_value()) |
| + return false; |
| + *value = message.integer_value(); |
| + return true; |
| +} |
| + |
| +template <> |
| +inline bool ProtoMessageGet<int64_t>(const pb::RpcMessage& message, |
| + int64_t* value) { |
| + if (!message.has_integer64_value()) |
| + return false; |
| + *value = message.integer64_value(); |
| + return true; |
| +} |
| + |
| +template <> |
| +inline bool ProtoMessageGet<double>(const pb::RpcMessage& message, |
| + double* value) { |
| + if (!message.has_double_value()) |
| + return false; |
| + *value = message.double_value(); |
| + return true; |
| +} |
| + |
| +template <> |
| +inline bool ProtoMessageGet<std::string>(const pb::RpcMessage& message, |
| + std::string* value) { |
| + if (!message.has_string_value()) |
| + return false; |
| + *value = message.string_value(); |
| + return true; |
| +} |
| + |
| +template <> |
| +inline void ProtoMessageSet<bool>(pb::RpcMessage* message, const bool& value) { |
| + message->set_boolean_value(value); |
| +} |
| + |
| +template <> |
| +inline void ProtoMessageSet<int>(pb::RpcMessage* message, const int& value) { |
| + message->set_integer_value(value); |
| +} |
| + |
| +template <> |
| +inline void ProtoMessageSet<int64_t>(pb::RpcMessage* message, |
| + const int64_t& value) { |
| + message->set_integer64_value(value); |
| +} |
| + |
| +template <> |
| +inline void ProtoMessageSet<double>(pb::RpcMessage* message, |
| + const double& value) { |
| + message->set_double_value(value); |
| +} |
| + |
| +template <> |
| +inline void ProtoMessageSet<std::string>(pb::RpcMessage* message, |
| + const std::string& value) { |
| + message->set_string_value(value); |
| +} |
| + |
| +bool CdmPromiseFromMessage(const pb::CdmPromise& promise_message, |
| + CdmPromiseResult* result, |
| + std::string* session_id); |
| + |
| +void CdmPromiseToMessage(pb::CdmPromise* promise_message, |
| + const CdmPromiseResult& result, |
| + const std::string& session_id); |
| + |
| +} // namespace internal |
| + |
| +class Rpc : public base::RefCountedThreadSafe<Rpc> { |
|
miu
2016/09/08 01:07:35
Is there a special reason to ref-count this object
|
| + public: |
| + static const int kInvalidHandle = -1; |
| + static const int kReceiverHandle = 0; |
| + |
| + 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
|
| + |
| + int handle() const { return handle_; } |
| + |
| + std::string ToMessage() const; |
|
miu
2016/09/08 01:07:35
ditto: If these are to be sent via the Mojo interf
|
| + |
| + virtual pb::RpcProc GetProc() const = 0; |
| + |
| + protected: |
| + friend class base::RefCountedThreadSafe<Rpc>; |
| + explicit Rpc(int handle); |
| + virtual ~Rpc(); |
| + |
| + virtual void ToMessageInternal(pb::RpcMessage* rpc) const = 0; |
| + |
| + private: |
| + int handle_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(Rpc); |
| +}; |
| + |
| +template <typename T, pb::RpcProc Proc> |
| +class SimpleRpc : public Rpc { |
| + public: |
| + SimpleRpc(int handle, T value) : Rpc(handle), value_(value) {} |
| + |
| + static scoped_refptr<SimpleRpc> FromRpcMessage(const pb::RpcMessage* rpc) { |
| + T value; |
| + if (!internal::ProtoMessageGet(*rpc, &value)) { |
| + LOG(ERROR) << "Not valid proto buffer message"; |
| + return nullptr; |
| + } |
| + |
| + return new SimpleRpc(rpc->handle(), value); |
| + } |
| + |
| + const T& value() const { return value_; } |
| + |
| + pb::RpcProc GetProc() const override { return Proc; } |
| + |
| + protected: |
| + void ToMessageInternal(pb::RpcMessage* rpc) const override { |
| + internal::ProtoMessageSet(rpc, value_); |
| + } |
| + |
| + private: |
| + ~SimpleRpc() override = default; |
| + T value_; |
| +}; |
| + |
| +template <pb::RpcProc Proc> |
| +class NullRpc : public Rpc { |
| + public: |
| + explicit NullRpc(int handle) : Rpc(handle) {} |
| + |
| + static scoped_refptr<NullRpc> FromRpcMessage(const pb::RpcMessage* rpc) { |
| + return new NullRpc(rpc->handle()); |
| + } |
| + |
| + pb::RpcProc GetProc() const override { return Proc; } |
| + |
| + protected: |
| + void ToMessageInternal(pb::RpcMessage* rpc) const override {} |
| + |
| + private: |
| + ~NullRpc() override = default; |
| +}; |
| + |
| +//============================================================================== |
| +using AcquireRendererRpc = SimpleRpc<int, pb::RPC_ACQUIRE_RENDERER>; |
| +using AcquireRendererDoneRpc = SimpleRpc<int, pb::RPC_ACQUIRE_RENDERER_DONE>; |
| +using AcquireCdmRpc = SimpleRpc<int, pb::RPC_ACQUIRE_CDM>; |
| +using AcquireCdmDoneRpc = SimpleRpc<int, pb::RPC_ACQUIRE_CDM_DONE>; |
| + |
| +//============================================================================== |
| +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
|
| + public: |
| + RendererInitializeRpc(int handle, |
| + int client_handle, |
| + int audio_demuxer_handle, |
| + int video_demuxer_handle, |
| + int callback_handle); |
| + |
| + static scoped_refptr<RendererInitializeRpc> FromRpcMessage( |
| + const pb::RpcMessage* rpc); |
| + |
| + int client_handle() const { return client_handle_; } |
| + int audio_demuxer_handle() const { return audio_demuxer_handle_; } |
| + int video_demuxer_handle() const { return video_demuxer_handle_; } |
| + int callback_handle() const { return callback_handle_; } |
| + |
| + pb::RpcProc GetProc() const override; |
| + |
| + protected: |
| + void ToMessageInternal(pb::RpcMessage* rpc) const override; |
| + |
| + private: |
| + ~RendererInitializeRpc() override; |
| + int client_handle_; |
| + int audio_demuxer_handle_; |
| + int video_demuxer_handle_; |
| + int callback_handle_; |
| +}; |
| + |
| +//============================================================================== |
| +class RendererFlushUntilRpc : public Rpc { |
| + public: |
| + RendererFlushUntilRpc(int handle, |
| + uint32_t audio_frame_id, |
| + uint32_t video_frame_id, |
| + int callback_handle); |
| + |
| + static scoped_refptr<RendererFlushUntilRpc> FromRpcMessage( |
| + const pb::RpcMessage* rpc); |
| + |
| + uint32_t audio_frame_id() const { return audio_frame_id_; } |
| + uint32_t video_frame_id() const { return video_frame_id_; } |
| + int callback_handle() const { return callback_handle_; } |
| + |
| + pb::RpcProc GetProc() const override; |
| + |
| + protected: |
| + void ToMessageInternal(pb::RpcMessage* rpc) const override; |
| + |
| + private: |
| + ~RendererFlushUntilRpc() override; |
| + uint32_t audio_frame_id_; |
| + uint32_t video_frame_id_; |
| + int callback_handle_; |
| +}; |
| + |
| +//============================================================================== |
| +using RendererStartPlayingFromRpc = |
| + SimpleRpc<int64_t, pb::RPC_R_STARTPLAYINGFROM>; |
| +using RendererSetPlaybackRateRpc = SimpleRpc<double, pb::RPC_R_SETPLAYBACKRATE>; |
| +using RendererSetVolumeRpc = SimpleRpc<double, pb::RPC_R_SETVOLUME>; |
| + |
| +//============================================================================== |
| +class RendererSetCdmRpc : public Rpc { |
| + public: |
| + RendererSetCdmRpc(int handle, int cdm_id, int callback_handle); |
| + |
| + static scoped_refptr<RendererSetCdmRpc> FromRpcMessage( |
| + const pb::RpcMessage* rpc); |
| + |
| + int cdm_id() const { return cdm_id_; } |
| + int callback_handle() const { return callback_handle_; } |
| + |
| + pb::RpcProc GetProc() const override; |
| + |
| + protected: |
| + void ToMessageInternal(pb::RpcMessage* rpc) const override; |
| + |
| + private: |
| + ~RendererSetCdmRpc() override; |
| + int cdm_id_; |
| + int callback_handle_; |
| +}; |
| + |
| +//============================================================================== |
| +using RendererInitializeCallbackRpc = |
| + SimpleRpc<bool, pb::RPC_R_INITIALIZE_CALLBACK>; |
| +using RendererFlushUntilCallbackRpc = NullRpc<pb::RPC_R_FLUSHUNTIL_CALLBACK>; |
| +using RendererSetCdmCallbackRpc = SimpleRpc<bool, pb::RPC_R_SETCDM_CALLBACK>; |
| + |
| +//============================================================================== |
| +class RendererClientOnTimeUpdateRpc : public Rpc { |
| + public: |
| + RendererClientOnTimeUpdateRpc(int handle, |
| + int64_t time_usec, |
| + int64_t max_time_usec); |
| + |
| + static scoped_refptr<RendererClientOnTimeUpdateRpc> FromRpcMessage( |
| + const pb::RpcMessage* rpc); |
| + |
| + int64_t time_usec() const { return time_usec_; } |
| + int64_t max_time_usec() const { return max_time_usec_; } |
| + |
| + pb::RpcProc GetProc() const override; |
| + |
| + protected: |
| + void ToMessageInternal(pb::RpcMessage* rpc) const override; |
| + |
| + private: |
| + ~RendererClientOnTimeUpdateRpc() override; |
| + int64_t time_usec_; |
| + int64_t max_time_usec_; |
| +}; |
| + |
| +//============================================================================== |
| +using RendererClientOnBufferingStateChangeRpc = |
| + SimpleRpc<int, pb::RPC_RC_ONBUFFERINGSTATECHANGE>; |
| +using RendererClientOnEndedRpc = NullRpc<pb::RPC_RC_ONENDED>; |
| +using RendererClientOnErrorRpc = NullRpc<pb::RPC_RC_ONERROR>; |
| + |
| +//============================================================================== |
| +class RendererClientOnVideoNaturalSizeChangeRpc : public Rpc { |
| + public: |
| + RendererClientOnVideoNaturalSizeChangeRpc(int handle, const gfx::Size& size); |
| + |
| + static scoped_refptr<RendererClientOnVideoNaturalSizeChangeRpc> |
| + FromRpcMessage(const pb::RpcMessage* rpc); |
| + |
| + const gfx::Size& size() const { return size_; } |
| + |
| + pb::RpcProc GetProc() const override; |
| + |
| + protected: |
| + void ToMessageInternal(pb::RpcMessage* rpc) const override; |
| + |
| + private: |
| + ~RendererClientOnVideoNaturalSizeChangeRpc() override; |
| + gfx::Size size_; |
| +}; |
| + |
| +//============================================================================== |
| +using RendererClientOnVideoOpacityChangeRpc = |
| + SimpleRpc<bool, pb::RPC_RC_ONVIDEOOPACITYCHANGE>; |
| + |
| +//============================================================================== |
| +class RendererClientOnStatisticsUpdateRpc : public Rpc { |
| + public: |
| + RendererClientOnStatisticsUpdateRpc(int handle, |
| + const ::media::PipelineStatistics& stats); |
| + |
| + static scoped_refptr<RendererClientOnStatisticsUpdateRpc> FromRpcMessage( |
| + const pb::RpcMessage* rpc); |
| + |
| + const ::media::PipelineStatistics& stats() const { return stats_; } |
| + |
| + pb::RpcProc GetProc() const override; |
| + |
| + protected: |
| + void ToMessageInternal(pb::RpcMessage* rpc) const override; |
| + |
| + private: |
| + ~RendererClientOnStatisticsUpdateRpc() override; |
| + ::media::PipelineStatistics stats_; |
| +}; |
| + |
| +//============================================================================== |
| +using RendererClientOnWaitingForDecryptionKeyRpc = |
| + NullRpc<pb::RPC_RC_ONWAITINGFORDECRYPTIONKEY>; |
| +using RendererClientOnDurationChangeRpc = |
| + SimpleRpc<int64_t, pb::RPC_RC_ONDURATIONCHANGE>; |
| +using DemuxerStreamInitializeRpc = SimpleRpc<int, pb::RPC_DS_INITIALIZE>; |
| +using DemuxerStreamEnableBitstreamConverterRpc = |
| + NullRpc<pb::RPC_DS_ENABLEBITSTREAMCONVERTER>; |
| + |
| +//============================================================================== |
| +class DemuxerStreamReadUntilRpc : public Rpc { |
| + public: |
| + DemuxerStreamReadUntilRpc(int handle, uint32_t frame_id, int callback_handle); |
| + |
| + static scoped_refptr<DemuxerStreamReadUntilRpc> FromRpcMessage( |
| + const pb::RpcMessage* rpc); |
| + |
| + uint32_t frame_id() const { return frame_id_; } |
| + int callback_handle() const { return callback_handle_; } |
| + |
| + pb::RpcProc GetProc() const override; |
| + |
| + protected: |
| + void ToMessageInternal(pb::RpcMessage* rpc) const override; |
| + |
| + private: |
| + ~DemuxerStreamReadUntilRpc() override; |
| + uint32_t frame_id_; |
| + int callback_handle_; |
| +}; |
| + |
| +class DemuxerStreamInitializeCallbackRpc : public Rpc { |
| + public: |
| + DemuxerStreamInitializeCallbackRpc( |
| + int handle, |
| + ::media::DemuxerStream::Type type, |
| + const ::media::AudioDecoderConfig& audio_config, |
| + const ::media::VideoDecoderConfig& video_config); |
| + |
| + static scoped_refptr<DemuxerStreamInitializeCallbackRpc> FromRpcMessage( |
| + const pb::RpcMessage* rpc); |
| + |
| + ::media::DemuxerStream::Type type() const { return type_; } |
| + const ::media::AudioDecoderConfig& audio_config() const { |
| + return audio_config_; |
| + } |
| + const ::media::VideoDecoderConfig& video_config() const { |
| + return video_config_; |
| + } |
| + |
| + pb::RpcProc GetProc() const override; |
| + |
| + protected: |
| + void ToMessageInternal(pb::RpcMessage* rpc) const override; |
| + |
| + private: |
| + ~DemuxerStreamInitializeCallbackRpc() override; |
| + ::media::DemuxerStream::Type type_; |
| + ::media::AudioDecoderConfig audio_config_; |
| + ::media::VideoDecoderConfig video_config_; |
| +}; |
| + |
| +class DemuxerStreamReadUntilCallbackRpc : public Rpc { |
| + public: |
| + DemuxerStreamReadUntilCallbackRpc( |
| + int handle, |
| + uint32_t frame_id, |
| + ::media::DemuxerStream::Status status, |
| + const ::media::AudioDecoderConfig& audio_config, |
| + const ::media::VideoDecoderConfig& video_config); |
| + |
| + static scoped_refptr<DemuxerStreamReadUntilCallbackRpc> FromRpcMessage( |
| + const pb::RpcMessage* rpc); |
| + |
| + uint32_t frame_id() const { return frame_id_; } |
| + ::media::DemuxerStream::Status status() const { return status_; } |
| + |
| + const ::media::AudioDecoderConfig& audio_config() const { |
| + return audio_config_; |
| + } |
| + const ::media::VideoDecoderConfig& video_config() const { |
| + return video_config_; |
| + } |
| + |
| + pb::RpcProc GetProc() const override; |
| + |
| + protected: |
| + void ToMessageInternal(pb::RpcMessage* rpc) const override; |
| + |
| + private: |
| + ~DemuxerStreamReadUntilCallbackRpc() override; |
| + uint32_t frame_id_; |
| + ::media::DemuxerStream::Status status_; |
| + ::media::AudioDecoderConfig audio_config_; |
| + ::media::VideoDecoderConfig video_config_; |
| +}; |
| + |
| +typedef SimpleRpc<int, pb::RPC_CDM_SETCLIENT> CdmSetClientRpc; |
| + |
| +class CdmInitializeRpc : public Rpc { |
| + public: |
| + CdmInitializeRpc(int handle, |
| + const std::string& key_system, |
| + const std::string& security_origin, |
| + const ::media::CdmConfig& cdm_config, |
| + int callback_handle); |
| + |
| + static scoped_refptr<CdmInitializeRpc> FromRpcMessage( |
| + const pb::RpcMessage* rpc); |
| + |
| + const std::string& key_system() const { return key_system_; } |
| + const std::string& security_origin() const { return security_origin_; } |
| + const ::media::CdmConfig& cdm_config() const { return cdm_config_; } |
| + int callback_handle() const { return callback_handle_; } |
| + |
| + pb::RpcProc GetProc() const override; |
| + |
| + protected: |
| + void ToMessageInternal(pb::RpcMessage* rpc) const override; |
| + |
| + private: |
| + ~CdmInitializeRpc() override; |
| + std::string key_system_; |
| + std::string security_origin_; |
| + ::media::CdmConfig cdm_config_; |
| + int callback_handle_; |
| +}; |
| + |
| +class CdmSetServerCertificateRpc : public Rpc { |
| + public: |
| + CdmSetServerCertificateRpc(int handle, |
| + const uint8_t* certificate_data, |
| + size_t certificate_data_size, |
| + int callback_handle); |
| + |
| + static scoped_refptr<CdmSetServerCertificateRpc> FromRpcMessage( |
| + const pb::RpcMessage* rpc); |
| + |
| + const uint8_t* certificate_data() const { |
| + return certificate_data_.empty() ? nullptr : certificate_data_.data(); |
| + } |
| + size_t certificate_data_size() const { return certificate_data_.size(); } |
| + int callback_handle() const { return callback_handle_; } |
| + |
| + pb::RpcProc GetProc() const override; |
| + |
| + protected: |
| + void ToMessageInternal(pb::RpcMessage* rpc) const override; |
| + |
| + private: |
| + ~CdmSetServerCertificateRpc() override; |
| + std::vector<uint8_t> certificate_data_; |
| + int callback_handle_; |
| +}; |
| + |
| +class CdmCreateSessionAndGenerateRequestRpc : public Rpc { |
| + public: |
| + CdmCreateSessionAndGenerateRequestRpc( |
| + int handle, |
| + ::media::MediaKeys::SessionType session_type, |
| + ::media::EmeInitDataType init_data_type, |
| + const uint8_t* init_data, |
| + size_t init_data_size, |
| + int callback_handle); |
| + |
| + static scoped_refptr<CdmCreateSessionAndGenerateRequestRpc> FromRpcMessage( |
| + const pb::RpcMessage* rpc); |
| + |
| + ::media::MediaKeys::SessionType session_type() const { return session_type_; } |
| + ::media::EmeInitDataType init_data_type() const { return init_data_type_; } |
| + const uint8_t* init_data() const { |
| + return init_data_.empty() ? nullptr : init_data_.data(); |
| + } |
| + size_t init_data_size() const { return init_data_.size(); } |
| + int callback_handle() const { return callback_handle_; } |
| + |
| + pb::RpcProc GetProc() const override; |
| + |
| + protected: |
| + void ToMessageInternal(pb::RpcMessage* rpc) const override; |
| + |
| + private: |
| + ~CdmCreateSessionAndGenerateRequestRpc() override; |
| + ::media::MediaKeys::SessionType session_type_; |
| + ::media::EmeInitDataType init_data_type_; |
| + std::vector<uint8_t> init_data_; |
| + int callback_handle_; |
| +}; |
| + |
| +class CdmLoadSessionRpc : public Rpc { |
| + public: |
| + CdmLoadSessionRpc(int handle, |
| + ::media::MediaKeys::SessionType session_type, |
| + const std::string& session_id, |
| + int callback_handle); |
| + |
| + static scoped_refptr<CdmLoadSessionRpc> FromRpcMessage( |
| + const pb::RpcMessage* rpc); |
| + |
| + ::media::MediaKeys::SessionType session_type() const { return session_type_; } |
| + const std::string& session_id() const { return session_id_; } |
| + int callback_handle() const { return callback_handle_; } |
| + |
| + pb::RpcProc GetProc() const override; |
| + |
| + protected: |
| + void ToMessageInternal(pb::RpcMessage* rpc) const override; |
| + |
| + private: |
| + ~CdmLoadSessionRpc() override; |
| + ::media::MediaKeys::SessionType session_type_; |
| + std::string session_id_; |
| + int callback_handle_; |
| +}; |
| + |
| +class CdmUpdateSessionRpc : public Rpc { |
| + public: |
| + CdmUpdateSessionRpc(int handle, |
| + const std::string& session_id, |
| + const uint8_t* response, |
| + size_t response_size, |
| + int callback_handle); |
| + |
| + static scoped_refptr<CdmUpdateSessionRpc> FromRpcMessage( |
| + const pb::RpcMessage* rpc); |
| + |
| + const std::string& session_id() const { return session_id_; } |
| + const uint8_t* response() const { |
| + return response_.empty() ? nullptr : response_.data(); |
| + } |
| + size_t response_size() const { return response_.size(); } |
| + int callback_handle() const { return callback_handle_; } |
| + |
| + pb::RpcProc GetProc() const override; |
| + |
| + protected: |
| + void ToMessageInternal(pb::RpcMessage* rpc) const override; |
| + |
| + private: |
| + ~CdmUpdateSessionRpc() override; |
| + std::string session_id_; |
| + std::vector<uint8_t> response_; |
| + int callback_handle_; |
| +}; |
| + |
| +class CdmCloseSessionRpc : public Rpc { |
| + public: |
| + CdmCloseSessionRpc(int handle, |
| + const std::string& session_id, |
| + int callback_handle); |
| + |
| + static scoped_refptr<CdmCloseSessionRpc> FromRpcMessage( |
| + const pb::RpcMessage* rpc); |
| + |
| + const std::string& session_id() const { return session_id_; } |
| + int callback_handle() const { return callback_handle_; } |
| + |
| + pb::RpcProc GetProc() const override; |
| + |
| + protected: |
| + void ToMessageInternal(pb::RpcMessage* rpc) const override; |
| + |
| + private: |
| + ~CdmCloseSessionRpc() override; |
| + std::string session_id_; |
| + int callback_handle_; |
| +}; |
| + |
| +class CdmRemoveSessionRpc : public Rpc { |
| + public: |
| + CdmRemoveSessionRpc(int handle, |
| + const std::string& session_id, |
| + int callback_handle); |
| + |
| + static scoped_refptr<CdmRemoveSessionRpc> FromRpcMessage( |
| + const pb::RpcMessage* rpc); |
| + |
| + const std::string& session_id() const { return session_id_; } |
| + int callback_handle() const { return callback_handle_; } |
| + |
| + pb::RpcProc GetProc() const override; |
| + |
| + protected: |
| + void ToMessageInternal(pb::RpcMessage* rpc) const override; |
| + |
| + private: |
| + ~CdmRemoveSessionRpc() override; |
| + std::string session_id_; |
| + int callback_handle_; |
| +}; |
| + |
| +class CdmPromiseResult { |
| + public: |
| + CdmPromiseResult(); |
| + CdmPromiseResult(::media::MediaKeys::Exception exception, |
| + uint32_t system_code, |
| + std::string error_message); |
| + CdmPromiseResult(const CdmPromiseResult& other); |
| + ~CdmPromiseResult(); |
| + |
| + static CdmPromiseResult SuccessResult(); |
| + |
| + bool success() const { return success_; } |
| + ::media::MediaKeys::Exception exception() const { return exception_; } |
| + uint32_t system_code() const { return system_code_; } |
| + const std::string& error_message() const { return error_message_; } |
| + |
| + private: |
| + bool success_; |
| + ::media::MediaKeys::Exception exception_; |
| + uint32_t system_code_; |
| + std::string error_message_; |
| +}; |
| + |
| +template <pb::RpcProc Proc> |
| +class CdmPromiseCallbackRpc : public Rpc { |
| + public: |
| + CdmPromiseCallbackRpc(int handle, const CdmPromiseResult& result) |
| + : Rpc(handle), result_(result) {} |
| + |
| + static scoped_refptr<CdmPromiseCallbackRpc> FromRpcMessage( |
| + const pb::RpcMessage* rpc) { |
| + CdmPromiseResult result; |
| + DCHECK(rpc->has_cdm_promise_rpc()); |
| + const pb::CdmPromise promise_message = rpc->cdm_promise_rpc(); |
| + if (!internal::CdmPromiseFromMessage(promise_message, &result, nullptr)) |
| + return nullptr; |
| + return new CdmPromiseCallbackRpc(rpc->handle(), result); |
| + } |
| + |
| + const CdmPromiseResult& result() const { return result_; } |
| + |
| + pb::RpcProc GetProc() const override { return Proc; } |
| + |
| + protected: |
| + ~CdmPromiseCallbackRpc() = default; |
| + void ToMessageInternal(pb::RpcMessage* rpc) const override { |
| + pb::CdmPromise* promise_message = rpc->mutable_cdm_promise_rpc(); |
| + internal::CdmPromiseToMessage(promise_message, result_, ""); |
| + } |
| + |
| + private: |
| + CdmPromiseResult result_; |
| +}; |
| + |
| +template <pb::RpcProc Proc> |
| +class CdmPromiseWithSessionIdCallbackRpc : public CdmPromiseCallbackRpc<Proc> { |
| + public: |
| + CdmPromiseWithSessionIdCallbackRpc(int handle, |
| + const CdmPromiseResult& result, |
| + const std::string& session_id) |
| + : CdmPromiseCallbackRpc<Proc>(handle, result), session_id_(session_id) {} |
| + |
| + static scoped_refptr<CdmPromiseWithSessionIdCallbackRpc> FromRpcMessage( |
| + const pb::RpcMessage* rpc) { |
| + CdmPromiseResult result; |
| + std::string session_id; |
| + DCHECK(rpc->has_cdm_promise_rpc()); |
| + const pb::CdmPromise promise_message = rpc->cdm_promise_rpc(); |
| + if (!internal::CdmPromiseFromMessage(promise_message, &result, &session_id)) |
| + return nullptr; |
| + return new CdmPromiseWithSessionIdCallbackRpc(rpc->handle(), result, |
| + session_id); |
| + } |
| + |
| + const std::string& session_id() const { return session_id_; } |
| + |
| + protected: |
| + void ToMessageInternal(pb::RpcMessage* rpc) const override { |
| + pb::CdmPromise* promise_message = rpc->mutable_cdm_promise_rpc(); |
| + internal::CdmPromiseToMessage( |
| + promise_message, CdmPromiseCallbackRpc<Proc>::result(), session_id_); |
| + } |
| + |
| + private: |
| + ~CdmPromiseWithSessionIdCallbackRpc() = default; |
| + std::string session_id_; |
| +}; |
| + |
| +//============================================================================== |
| +using CdmSetServerCertificateCallbackRpc = |
| + CdmPromiseCallbackRpc<pb::RPC_CDM_SETSERVERCERTIFICATE_CALLBACK>; |
| +using CdmCreateSessionAndGenerateRequestCallbackRpc = |
| + CdmPromiseWithSessionIdCallbackRpc< |
| + pb::RPC_CDM_CREATESESSIONANDGENERATEREQUEST_CALLBACK>; |
| +using CdmLoadSessionCallbackRpc = |
| + CdmPromiseWithSessionIdCallbackRpc<pb::RPC_CDM_LOADSESSION_CALLBACK>; |
| +using CdmUpdateSessionCallbackRpc = |
| + CdmPromiseCallbackRpc<pb::RPC_CDM_UPDATESESSION_CALLBACK>; |
| +using CdmCloseSessionCallbackRpc = |
| + CdmPromiseCallbackRpc<pb::RPC_CDM_CLOSESESSION_CALLBACK>; |
| +using CdmRemoveSessionCallbackRpc = |
| + CdmPromiseCallbackRpc<pb::RPC_CDM_REMOVESESSION_CALLBACK>; |
| + |
| +//============================================================================== |
| +class CdmInitializeCallbackRpc |
| + : public CdmPromiseCallbackRpc<pb::RPC_CDM_INITIALIZE_CALLBACK> { |
| + public: |
| + CdmInitializeCallbackRpc(int handle, |
| + const CdmPromiseResult& result, |
| + int cdm_id, |
| + int decryptor_handle); |
| + |
| + static scoped_refptr<CdmInitializeCallbackRpc> FromRpcMessage( |
| + const pb::RpcMessage* rpc); |
| + |
| + int cdm_id() const { return cdm_id_; } |
| + int decryptor_handle() const { return decryptor_handle_; } |
| + |
| + protected: |
| + void ToMessageInternal(pb::RpcMessage* rpc) const override; |
| + |
| + private: |
| + ~CdmInitializeCallbackRpc() override; |
| + int cdm_id_; |
| + int decryptor_handle_; |
| +}; |
| + |
| +class CdmClientOnSessionMessageRpc : public Rpc { |
| + public: |
| + CdmClientOnSessionMessageRpc(int handle, |
| + const std::string& session_id, |
| + ::media::MediaKeys::MessageType message_type, |
| + const uint8_t* message, |
| + size_t message_size); |
| + |
| + static scoped_refptr<CdmClientOnSessionMessageRpc> FromRpcMessage( |
| + const pb::RpcMessage* rpc); |
| + |
| + const std::string& session_id() const { return session_id_; } |
| + ::media::MediaKeys::MessageType message_type() const { return message_type_; } |
| + const uint8_t* message() const { |
| + return message_.empty() ? nullptr : message_.data(); |
| + } |
| + size_t message_size() const { return message_.size(); } |
| + |
| + pb::RpcProc GetProc() const override; |
| + |
| + protected: |
| + void ToMessageInternal(pb::RpcMessage* rpc) const override; |
| + |
| + private: |
| + ~CdmClientOnSessionMessageRpc() override; |
| + std::string session_id_; |
| + ::media::MediaKeys::MessageType message_type_; |
| + std::vector<uint8_t> message_; |
| +}; |
| + |
| +//============================================================================== |
| +using CdmClientOnSessionClosedRpc = |
| + SimpleRpc<std::string, pb::RPC_CDMC_ONSESSIONCLOSED>; |
| + |
| +//============================================================================== |
| +class CdmClientOnSessionKeysChangeRpc : public Rpc { |
| + public: |
| + CdmClientOnSessionKeysChangeRpc( |
| + int handle, |
| + const std::string& session_id, |
| + bool has_additional_usable_key, |
| + const ::media::CdmKeyInformation* key_information, |
| + size_t key_information_size); |
| + |
| + static scoped_refptr<CdmClientOnSessionKeysChangeRpc> FromRpcMessage( |
| + const pb::RpcMessage* rpc); |
| + |
| + const std::string& session_id() const { return session_id_; } |
| + bool has_additional_usable_key() const { return has_additional_usable_key_; } |
| + const ::media::CdmKeyInformation* key_information() const { |
| + return key_information_.empty() ? nullptr : key_information_.data(); |
| + } |
| + size_t key_information_size() const { return key_information_.size(); } |
| + |
| + pb::RpcProc GetProc() const override; |
| + |
| + protected: |
| + void ToMessageInternal(pb::RpcMessage* rpc) const override; |
| + |
| + private: |
| + ~CdmClientOnSessionKeysChangeRpc() override; |
| + std::string session_id_; |
| + bool has_additional_usable_key_; |
| + std::vector<::media::CdmKeyInformation> key_information_; |
| +}; |
| + |
| +class CdmClientOnSessionExpirationUpdateRpc : public Rpc { |
| + public: |
| + CdmClientOnSessionExpirationUpdateRpc(int handle, |
| + const std::string& session_id, |
| + double new_expiry_time_sec); |
| + |
| + static scoped_refptr<CdmClientOnSessionExpirationUpdateRpc> FromRpcMessage( |
| + const pb::RpcMessage* rpc); |
| + |
| + const std::string& session_id() const { return session_id_; } |
| + double new_expiry_time_sec() const { return new_expiry_time_sec_; } |
| + |
| + pb::RpcProc GetProc() const override; |
| + |
| + protected: |
| + void ToMessageInternal(pb::RpcMessage* rpc) const override; |
| + |
| + private: |
| + ~CdmClientOnSessionExpirationUpdateRpc() override; |
| + std::string session_id_; |
| + double new_expiry_time_sec_; |
| +}; |
| + |
| +} // namespace remoting |
| +} // namespace media |
| + |
| +#endif // MEDIA_REMOTING_RPC_RPC_H_ |