Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(366)

Side by Side Diff: media/remoting/rpc/proto_utils_unittest.cc

Issue 2643253003: Media Remoting Clean-up: Less-redundant naming, style consistency, etc. (Closed)
Patch Set: REBASE Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/remoting/rpc/proto_utils.cc ('k') | media/remoting/rpc/rpc_broker.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 #include "media/remoting/rpc/proto_utils.h"
6
7 #include <memory>
8 #include <string>
9 #include <utility>
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/content_decryption_module.h"
18 #include "media/base/decoder_buffer.h"
19 #include "media/base/demuxer_stream.h"
20 #include "media/base/eme_constants.h"
21 #include "media/base/video_decoder_config.h"
22 #include "media/remoting/remoting_rpc_message.pb.h"
23 #include "testing/gmock/include/gmock/gmock.h"
24 #include "testing/gtest/include/gtest/gtest.h"
25
26 using testing::_;
27 using testing::Invoke;
28 using testing::Return;
29
30 namespace media {
31 namespace remoting {
32
33 class ProtoUtilsTest : public testing::Test {
34 protected:
35 void SetUp() override {}
36 };
37
38 TEST_F(ProtoUtilsTest, PassEOSDecoderBuffer) {
39 // 1. To DecoderBuffer
40 scoped_refptr<::media::DecoderBuffer> input_buffer =
41 ::media::DecoderBuffer::CreateEOSBuffer();
42
43 // 2. To Byte Array
44 std::vector<uint8_t> data = DecoderBufferToByteArray(input_buffer);
45
46 // 3. To DecoderBuffer
47 scoped_refptr<::media::DecoderBuffer> output_buffer =
48 ByteArrayToDecoderBuffer(data.data(), data.size());
49 DCHECK(output_buffer);
50
51 ASSERT_TRUE(output_buffer->end_of_stream());
52 }
53
54 TEST_F(ProtoUtilsTest, PassValidDecoderBuffer) {
55 const uint8_t buffer[] = {
56 0, 0, 0, 1, 9, 224, 0, 0, 0, 1, 103, 77, 64, 21, 217,
57 1, 177, 254, 78, 16, 0, 0, 62, 144, 0, 11, 184, 0, 241, 98,
58 228, 128, 0, 0, 0, 1, 104, 235, 143, 32, 0, 0, 0, 1, 103,
59 77, 64, 21, 217, 1, 177, 254, 78, 16, 0, 0, 62, 144, 0, 11,
60 184, 0, 241, 98, 228, 128, 0, 0, 0, 1, 104, 235, 143, 32, 0,
61 0, 0, 1, 101, 136, 132, 25, 255, 0, 191, 98, 0, 6, 29, 63,
62 252, 65, 246, 207, 255, 235, 63, 172, 35, 112, 198, 115, 222, 243, 159,
63 232, 208, 32, 0, 0, 3, 0, 0, 203, 255, 149, 20, 71, 203, 213,
64 40, 0, 0, 139, 0, 24, 117, 166, 249, 227, 68, 230, 177, 134, 161,
65 162, 1, 22, 105, 78, 66, 183, 130, 158, 108, 252, 112, 113, 58, 159,
66 72, 116, 78, 141, 133, 76, 225, 209, 13, 221, 49, 187, 83, 123, 193,
67 112, 123, 112, 74, 121, 133};
68 size_t buffer_size = sizeof(buffer) / sizeof(uint8_t);
69 const uint8_t side_buffer[] = "XX";
70 size_t side_buffer_size = sizeof(side_buffer) / sizeof(uint8_t);
71 base::TimeDelta pts = base::TimeDelta::FromMilliseconds(5);
72
73 // 1. To DecoderBuffer
74 scoped_refptr<::media::DecoderBuffer> input_buffer =
75 ::media::DecoderBuffer::CopyFrom(buffer, buffer_size, side_buffer,
76 side_buffer_size);
77 input_buffer->set_timestamp(pts);
78 input_buffer->set_is_key_frame(true);
79
80 // 2. To Byte Array
81 std::vector<uint8_t> data = DecoderBufferToByteArray(input_buffer);
82
83 // 3. To DecoderBuffer
84 scoped_refptr<::media::DecoderBuffer> output_buffer =
85 ByteArrayToDecoderBuffer(data.data(), data.size());
86 DCHECK(output_buffer);
87
88 ASSERT_FALSE(output_buffer->end_of_stream());
89 ASSERT_TRUE(output_buffer->is_key_frame());
90 ASSERT_EQ(output_buffer->timestamp(), pts);
91 ASSERT_EQ(output_buffer->data_size(), buffer_size);
92 const uint8_t* output_data = output_buffer->data();
93 for (size_t i = 0; i < buffer_size; i++) {
94 ASSERT_EQ(output_data[i], buffer[i]);
95 }
96 ASSERT_EQ(output_buffer->side_data_size(), side_buffer_size);
97 const uint8_t* output_side_data = output_buffer->side_data();
98 for (size_t i = 0; i < side_buffer_size; i++) {
99 ASSERT_EQ(output_side_data[i], side_buffer[i]);
100 }
101 }
102
103 TEST_F(ProtoUtilsTest, AudioDecoderConfigConversionTest) {
104 const std::string extra_data = "ACEG";
105 const EncryptionScheme encryption_scheme(
106 EncryptionScheme::CIPHER_MODE_AES_CTR, EncryptionScheme::Pattern(20, 40));
107 AudioDecoderConfig audio_config(
108 kCodecAAC, kSampleFormatF32, CHANNEL_LAYOUT_MONO, 48000,
109 std::vector<uint8_t>(extra_data.begin(), extra_data.end()),
110 encryption_scheme);
111 ASSERT_TRUE(audio_config.IsValidConfig());
112
113 pb::AudioDecoderConfig audio_message;
114 ConvertAudioDecoderConfigToProto(audio_config, &audio_message);
115
116 AudioDecoderConfig audio_output_config;
117 ASSERT_TRUE(
118 ConvertProtoToAudioDecoderConfig(audio_message, &audio_output_config));
119
120 ASSERT_TRUE(audio_config.Matches(audio_output_config));
121 }
122
123 TEST_F(ProtoUtilsTest, CdmPromiseResultConversion) {
124 CdmPromiseResult success_result = CdmPromiseResult::SuccessResult();
125
126 pb::CdmPromise promise_message;
127 ConvertCdmPromiseToProto(success_result, &promise_message);
128
129 CdmPromiseResult output_result;
130 ASSERT_TRUE(ConvertProtoToCdmPromise(promise_message, &output_result));
131
132 ASSERT_EQ(success_result.success(), output_result.success());
133 ASSERT_EQ(success_result.exception(), output_result.exception());
134 ASSERT_EQ(success_result.system_code(), output_result.system_code());
135 ASSERT_EQ(success_result.error_message(), output_result.error_message());
136 }
137
138 TEST_F(ProtoUtilsTest, CdmKeyInformationConversion) {
139 std::unique_ptr<CdmKeyInformation> cdm_key_info_1(new CdmKeyInformation(
140 "key_1", CdmKeyInformation::OUTPUT_RESTRICTED, 100));
141 std::unique_ptr<CdmKeyInformation> cdm_key_info_2(
142 new CdmKeyInformation("key_2", CdmKeyInformation::EXPIRED, 11));
143 std::unique_ptr<CdmKeyInformation> cdm_key_info_3(
144 new CdmKeyInformation("key_3", CdmKeyInformation::RELEASED, 22));
145 CdmKeysInfo keys_information;
146 keys_information.push_back(std::move(cdm_key_info_1));
147 keys_information.push_back(std::move(cdm_key_info_2));
148 keys_information.push_back(std::move(cdm_key_info_3));
149
150 pb::CdmClientOnSessionKeysChange key_message;
151 ConvertCdmKeyInfoToProto(keys_information, &key_message);
152
153 CdmKeysInfo key_output_information;
154 ConvertProtoToCdmKeyInfo(key_message, &key_output_information);
155
156 ASSERT_EQ(keys_information.size(), key_output_information.size());
157 for (uint32_t i = 0; i < 3; i++) {
158 ASSERT_EQ(keys_information[i]->key_id, key_output_information[i]->key_id);
159 ASSERT_EQ(keys_information[i]->status, key_output_information[i]->status);
160 ASSERT_EQ(keys_information[i]->system_code,
161 key_output_information[i]->system_code);
162 }
163 }
164
165 } // namespace remoting
166 } // namespace media
OLDNEW
« no previous file with comments | « media/remoting/rpc/proto_utils.cc ('k') | media/remoting/rpc/rpc_broker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698