| erickung | 1fc58a4 | 2016-09-24 03:00:07 | [diff] [blame] | 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 | |
| miu | 9f7788e | 2017-01-25 00:46:09 | [diff] [blame] | 5 | #ifndef MEDIA_REMOTING_PROTO_UTILS_H_ |
| 6 | #define MEDIA_REMOTING_PROTO_UTILS_H_ |
| erickung | 1fc58a4 | 2016-09-24 03:00:07 | [diff] [blame] | 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" |
| corona10 | 1f1c7d3 | 2016-10-27 17:08:10 | [diff] [blame] | 17 | #include "media/base/cdm_promise.h" |
| jrummell | 6e462aa | 2017-07-13 20:49:47 | [diff] [blame] | 18 | #include "media/base/content_decryption_module.h" |
| erickung | 1fc58a4 | 2016-09-24 03:00:07 | [diff] [blame] | 19 | #include "media/base/decoder_buffer.h" |
| 20 | #include "media/base/demuxer_stream.h" |
| 21 | #include "media/base/eme_constants.h" |
| erickung | 1fc58a4 | 2016-09-24 03:00:07 | [diff] [blame] | 22 | #include "media/base/pipeline_status.h" |
| 23 | #include "media/base/video_decoder_config.h" |
| miu | 9f7788e | 2017-01-25 00:46:09 | [diff] [blame] | 24 | #include "media/remoting/rpc.pb.h" |
| erickung | 1fc58a4 | 2016-09-24 03:00:07 | [diff] [blame] | 25 | |
| 26 | namespace media { |
| 27 | namespace remoting { |
| 28 | |
| 29 | class CdmPromiseResult; |
| 30 | |
| miu | 9f7788e | 2017-01-25 00:46:09 | [diff] [blame] | 31 | // Utility class to convert data between media::DecoderBuffer and byte array. |
| 32 | // It is to serialize media::DecoderBuffer structure except for actual data |
| erickung | 1fc58a4 | 2016-09-24 03:00:07 | [diff] [blame] | 33 | // into pb::DecoderBuffer followed by byte array of decoder buffer. The reason |
| 34 | // data is not part of proto buffer because it would cost unnecessary time to |
| 35 | // wait for whole proto received before conversion given the fact that decoder |
| 36 | // buffer data can vary from hundred bytes to 3~5MB. Also, it would costs extra |
| 37 | // CPU to sirealize/de-serialize decoder buffer which is encoded and encrypted |
| 38 | // as wire format for data transmission. |
| 39 | // |
| 40 | // DecoderBufferSegment { |
| 41 | // // Payload version. Default value is 0. |
| 42 | // u8 payload_version; |
| 43 | // |
| miu | 9f7788e | 2017-01-25 00:46:09 | [diff] [blame] | 44 | // // Length of pb::DecoderBuffer (protobuf-encoded of media::DecoderBuffer |
| erickung | 1fc58a4 | 2016-09-24 03:00:07 | [diff] [blame] | 45 | // except for data). |
| 46 | // u16 buffer_segment_size; |
| 47 | // // pb::DecoderBuffer. |
| 48 | // u8[buffer_segment_size] buffer_segment; |
| 49 | // |
| 50 | // // Length of data in media::DecoderBuffer. |
| 51 | // u32 data_buffer_size; |
| 52 | // // media::DecoderBuffer data. |
| 53 | // u8[data_buffer_size] data_buffer; |
| 54 | //}; |
| 55 | |
| 56 | // Converts DecoderBufferSegment into byte array. |
| 57 | std::vector<uint8_t> DecoderBufferToByteArray( |
| miu | 9f7788e | 2017-01-25 00:46:09 | [diff] [blame] | 58 | const DecoderBuffer& decoder_buffer); |
| erickung | 1fc58a4 | 2016-09-24 03:00:07 | [diff] [blame] | 59 | |
| 60 | // Converts byte array into DecoderBufferSegment. |
| miu | 9f7788e | 2017-01-25 00:46:09 | [diff] [blame] | 61 | scoped_refptr<DecoderBuffer> ByteArrayToDecoderBuffer(const uint8_t* data, |
| 62 | uint32_t size); |
| erickung | 1fc58a4 | 2016-09-24 03:00:07 | [diff] [blame] | 63 | |
| miu | 9f7788e | 2017-01-25 00:46:09 | [diff] [blame] | 64 | // Data type conversion between media::AudioDecoderConfig and proto buffer. |
| 65 | void ConvertAudioDecoderConfigToProto(const AudioDecoderConfig& audio_config, |
| 66 | pb::AudioDecoderConfig* audio_message); |
| erickung | 1fc58a4 | 2016-09-24 03:00:07 | [diff] [blame] | 67 | bool ConvertProtoToAudioDecoderConfig( |
| 68 | const pb::AudioDecoderConfig& audio_message, |
| miu | 9f7788e | 2017-01-25 00:46:09 | [diff] [blame] | 69 | AudioDecoderConfig* audio_config); |
| erickung | 1fc58a4 | 2016-09-24 03:00:07 | [diff] [blame] | 70 | |
| miu | 9f7788e | 2017-01-25 00:46:09 | [diff] [blame] | 71 | // Data type conversion between media::VideoDecoderConfig and proto buffer. |
| 72 | void ConvertVideoDecoderConfigToProto(const VideoDecoderConfig& video_config, |
| 73 | pb::VideoDecoderConfig* video_message); |
| erickung | 1fc58a4 | 2016-09-24 03:00:07 | [diff] [blame] | 74 | bool ConvertProtoToVideoDecoderConfig( |
| 75 | const pb::VideoDecoderConfig& video_message, |
| miu | 9f7788e | 2017-01-25 00:46:09 | [diff] [blame] | 76 | VideoDecoderConfig* video_config); |
| erickung | 1fc58a4 | 2016-09-24 03:00:07 | [diff] [blame] | 77 | |
| miu | 9f7788e | 2017-01-25 00:46:09 | [diff] [blame] | 78 | // Data type conversion between media::VideoDecoderConfig and proto buffer. |
| 79 | void ConvertProtoToPipelineStatistics( |
| 80 | const pb::PipelineStatistics& stats_message, |
| 81 | PipelineStatistics* stats); |
| 82 | |
| 83 | // Data type conversion between media::CdmKeysInfo and proto buffer. |
| erickung | 1fc58a4 | 2016-09-24 03:00:07 | [diff] [blame] | 84 | void ConvertCdmKeyInfoToProto( |
| miu | 9f7788e | 2017-01-25 00:46:09 | [diff] [blame] | 85 | const CdmKeysInfo& keys_information, |
| erickung | 1fc58a4 | 2016-09-24 03:00:07 | [diff] [blame] | 86 | pb::CdmClientOnSessionKeysChange* key_change_message); |
| 87 | void ConvertProtoToCdmKeyInfo( |
| 88 | const pb::CdmClientOnSessionKeysChange keychange_message, |
| 89 | CdmKeysInfo* key_information); |
| 90 | |
| 91 | // Data type conversion between CdmPromiseResult and proto buffer. |
| 92 | void ConvertCdmPromiseToProto(const CdmPromiseResult& result, |
| 93 | pb::CdmPromise* promise_message); |
| 94 | void ConvertCdmPromiseWithSessionIdToProto(const CdmPromiseResult& result, |
| 95 | const std::string& session_id, |
| 96 | pb::CdmPromise* promise_message); |
| 97 | void ConvertCdmPromiseWithCdmIdToProto(const CdmPromiseResult& result, |
| 98 | int cdm_id, |
| 99 | pb::CdmPromise* promise_message); |
| 100 | bool ConvertProtoToCdmPromise(const pb::CdmPromise& promise_message, |
| 101 | CdmPromiseResult* result); |
| 102 | bool ConvertProtoToCdmPromiseWithCdmIdSessionId(const pb::RpcMessage& message, |
| 103 | CdmPromiseResult* result, |
| 104 | int* cdm_id, |
| 105 | std::string* session_id); |
| 106 | |
| 107 | //================================================================== |
| 108 | class CdmPromiseResult { |
| 109 | public: |
| 110 | CdmPromiseResult(); |
| miu | 9f7788e | 2017-01-25 00:46:09 | [diff] [blame] | 111 | CdmPromiseResult(CdmPromise::Exception exception, |
| erickung | 1fc58a4 | 2016-09-24 03:00:07 | [diff] [blame] | 112 | uint32_t system_code, |
| 113 | std::string error_message); |
| 114 | CdmPromiseResult(const CdmPromiseResult& other); |
| 115 | ~CdmPromiseResult(); |
| 116 | |
| 117 | static CdmPromiseResult SuccessResult(); |
| 118 | |
| 119 | bool success() const { return success_; } |
| miu | 9f7788e | 2017-01-25 00:46:09 | [diff] [blame] | 120 | CdmPromise::Exception exception() const { return exception_; } |
| erickung | 1fc58a4 | 2016-09-24 03:00:07 | [diff] [blame] | 121 | uint32_t system_code() const { return system_code_; } |
| 122 | const std::string& error_message() const { return error_message_; } |
| 123 | |
| 124 | private: |
| 125 | bool success_; |
| miu | 9f7788e | 2017-01-25 00:46:09 | [diff] [blame] | 126 | CdmPromise::Exception exception_; |
| erickung | 1fc58a4 | 2016-09-24 03:00:07 | [diff] [blame] | 127 | uint32_t system_code_; |
| 128 | std::string error_message_; |
| 129 | }; |
| 130 | |
| 131 | } // namespace remoting |
| 132 | } // namespace media |
| 133 | |
| miu | 9f7788e | 2017-01-25 00:46:09 | [diff] [blame] | 134 | #endif // MEDIA_REMOTING_PROTO_UTILS_H_ |