OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "media/remoting/rpc/proto_utils.h" | 5 #include "media/remoting/proto_utils.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "media/base/audio_decoder_config.h" | 14 #include "media/base/audio_decoder_config.h" |
15 #include "media/base/cdm_config.h" | 15 #include "media/base/cdm_config.h" |
16 #include "media/base/cdm_key_information.h" | 16 #include "media/base/cdm_key_information.h" |
17 #include "media/base/content_decryption_module.h" | 17 #include "media/base/content_decryption_module.h" |
18 #include "media/base/decoder_buffer.h" | 18 #include "media/base/decoder_buffer.h" |
19 #include "media/base/demuxer_stream.h" | 19 #include "media/base/demuxer_stream.h" |
20 #include "media/base/eme_constants.h" | 20 #include "media/base/eme_constants.h" |
21 #include "media/base/video_decoder_config.h" | 21 #include "media/base/video_decoder_config.h" |
22 #include "media/remoting/remoting_rpc_message.pb.h" | 22 #include "media/remoting/rpc.pb.h" |
23 #include "testing/gmock/include/gmock/gmock.h" | 23 #include "testing/gmock/include/gmock/gmock.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
25 | 25 |
26 using testing::_; | 26 using testing::_; |
27 using testing::Invoke; | 27 using testing::Invoke; |
28 using testing::Return; | 28 using testing::Return; |
29 | 29 |
30 namespace media { | 30 namespace media { |
31 namespace remoting { | 31 namespace remoting { |
32 | 32 |
33 class ProtoUtilsTest : public testing::Test { | 33 class ProtoUtilsTest : public testing::Test { |
34 protected: | 34 protected: |
35 void SetUp() override {} | 35 void SetUp() override {} |
36 }; | 36 }; |
37 | 37 |
38 TEST_F(ProtoUtilsTest, PassEOSDecoderBuffer) { | 38 TEST_F(ProtoUtilsTest, PassEOSDecoderBuffer) { |
39 // 1. To DecoderBuffer | 39 // 1. To DecoderBuffer |
40 scoped_refptr<::media::DecoderBuffer> input_buffer = | 40 scoped_refptr<DecoderBuffer> input_buffer = DecoderBuffer::CreateEOSBuffer(); |
41 ::media::DecoderBuffer::CreateEOSBuffer(); | |
42 | 41 |
43 // 2. To Byte Array | 42 // 2. To Byte Array |
44 std::vector<uint8_t> data = DecoderBufferToByteArray(input_buffer); | 43 std::vector<uint8_t> data = DecoderBufferToByteArray(*input_buffer); |
45 | 44 |
46 // 3. To DecoderBuffer | 45 // 3. To DecoderBuffer |
47 scoped_refptr<::media::DecoderBuffer> output_buffer = | 46 scoped_refptr<DecoderBuffer> output_buffer = |
48 ByteArrayToDecoderBuffer(data.data(), data.size()); | 47 ByteArrayToDecoderBuffer(data.data(), data.size()); |
49 DCHECK(output_buffer); | 48 DCHECK(output_buffer); |
50 | 49 |
51 ASSERT_TRUE(output_buffer->end_of_stream()); | 50 ASSERT_TRUE(output_buffer->end_of_stream()); |
52 } | 51 } |
53 | 52 |
54 TEST_F(ProtoUtilsTest, PassValidDecoderBuffer) { | 53 TEST_F(ProtoUtilsTest, PassValidDecoderBuffer) { |
55 const uint8_t buffer[] = { | 54 const uint8_t buffer[] = { |
56 0, 0, 0, 1, 9, 224, 0, 0, 0, 1, 103, 77, 64, 21, 217, | 55 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, | 56 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, | 57 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, | 58 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, | 59 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, | 60 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, | 61 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, | 62 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, | 63 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, | 64 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, | 65 72, 116, 78, 141, 133, 76, 225, 209, 13, 221, 49, 187, 83, 123, 193, |
67 112, 123, 112, 74, 121, 133}; | 66 112, 123, 112, 74, 121, 133}; |
68 size_t buffer_size = sizeof(buffer) / sizeof(uint8_t); | 67 size_t buffer_size = sizeof(buffer) / sizeof(uint8_t); |
69 const uint8_t side_buffer[] = "XX"; | 68 const uint8_t side_buffer[] = "XX"; |
70 size_t side_buffer_size = sizeof(side_buffer) / sizeof(uint8_t); | 69 size_t side_buffer_size = sizeof(side_buffer) / sizeof(uint8_t); |
71 base::TimeDelta pts = base::TimeDelta::FromMilliseconds(5); | 70 base::TimeDelta pts = base::TimeDelta::FromMilliseconds(5); |
72 | 71 |
73 // 1. To DecoderBuffer | 72 // 1. To DecoderBuffer |
74 scoped_refptr<::media::DecoderBuffer> input_buffer = | 73 scoped_refptr<DecoderBuffer> input_buffer = DecoderBuffer::CopyFrom( |
75 ::media::DecoderBuffer::CopyFrom(buffer, buffer_size, side_buffer, | 74 buffer, buffer_size, side_buffer, side_buffer_size); |
76 side_buffer_size); | |
77 input_buffer->set_timestamp(pts); | 75 input_buffer->set_timestamp(pts); |
78 input_buffer->set_is_key_frame(true); | 76 input_buffer->set_is_key_frame(true); |
79 | 77 |
80 // 2. To Byte Array | 78 // 2. To Byte Array |
81 std::vector<uint8_t> data = DecoderBufferToByteArray(input_buffer); | 79 std::vector<uint8_t> data = DecoderBufferToByteArray(*input_buffer); |
82 | 80 |
83 // 3. To DecoderBuffer | 81 // 3. To DecoderBuffer |
84 scoped_refptr<::media::DecoderBuffer> output_buffer = | 82 scoped_refptr<DecoderBuffer> output_buffer = |
85 ByteArrayToDecoderBuffer(data.data(), data.size()); | 83 ByteArrayToDecoderBuffer(data.data(), data.size()); |
86 DCHECK(output_buffer); | 84 DCHECK(output_buffer); |
87 | 85 |
88 ASSERT_FALSE(output_buffer->end_of_stream()); | 86 ASSERT_FALSE(output_buffer->end_of_stream()); |
89 ASSERT_TRUE(output_buffer->is_key_frame()); | 87 ASSERT_TRUE(output_buffer->is_key_frame()); |
90 ASSERT_EQ(output_buffer->timestamp(), pts); | 88 ASSERT_EQ(output_buffer->timestamp(), pts); |
91 ASSERT_EQ(output_buffer->data_size(), buffer_size); | 89 ASSERT_EQ(output_buffer->data_size(), buffer_size); |
92 const uint8_t* output_data = output_buffer->data(); | 90 const uint8_t* output_data = output_buffer->data(); |
93 for (size_t i = 0; i < buffer_size; i++) { | 91 for (size_t i = 0; i < buffer_size; i++) { |
94 ASSERT_EQ(output_data[i], buffer[i]); | 92 ASSERT_EQ(output_data[i], buffer[i]); |
(...skipping 18 matching lines...) Expand all Loading... |
113 pb::AudioDecoderConfig audio_message; | 111 pb::AudioDecoderConfig audio_message; |
114 ConvertAudioDecoderConfigToProto(audio_config, &audio_message); | 112 ConvertAudioDecoderConfigToProto(audio_config, &audio_message); |
115 | 113 |
116 AudioDecoderConfig audio_output_config; | 114 AudioDecoderConfig audio_output_config; |
117 ASSERT_TRUE( | 115 ASSERT_TRUE( |
118 ConvertProtoToAudioDecoderConfig(audio_message, &audio_output_config)); | 116 ConvertProtoToAudioDecoderConfig(audio_message, &audio_output_config)); |
119 | 117 |
120 ASSERT_TRUE(audio_config.Matches(audio_output_config)); | 118 ASSERT_TRUE(audio_config.Matches(audio_output_config)); |
121 } | 119 } |
122 | 120 |
| 121 TEST_F(ProtoUtilsTest, PipelineStatisticsConversion) { |
| 122 PipelineStatistics original; |
| 123 // Note: Fill the structure with non-zero bytes to ensure this test is |
| 124 // initializing *all* fields. |
| 125 memset(&original, 0xcd, sizeof(original)); |
| 126 original.audio_bytes_decoded = 123; |
| 127 original.video_bytes_decoded = 456; |
| 128 original.video_frames_decoded = 789; |
| 129 original.video_frames_dropped = 21; |
| 130 original.audio_memory_usage = 32; |
| 131 original.video_memory_usage = 43; |
| 132 original.video_keyframe_distance_average = base::TimeDelta::Max(); |
| 133 |
| 134 // There is no convert-to-proto function, so just do that here. |
| 135 pb::PipelineStatistics pb_stats; |
| 136 pb_stats.set_audio_bytes_decoded(original.audio_bytes_decoded); |
| 137 pb_stats.set_video_bytes_decoded(original.video_bytes_decoded); |
| 138 pb_stats.set_video_frames_decoded(original.video_frames_decoded); |
| 139 pb_stats.set_video_frames_dropped(original.video_frames_dropped); |
| 140 pb_stats.set_audio_memory_usage(original.audio_memory_usage); |
| 141 pb_stats.set_video_memory_usage(original.video_memory_usage); |
| 142 |
| 143 PipelineStatistics converted; |
| 144 memset(&converted, ~0xcd, sizeof(converted)); // See note above. |
| 145 ConvertProtoToPipelineStatistics(pb_stats, &converted); |
| 146 |
| 147 // If this fails, did media::PipelineStatistics add/change fields that are not |
| 148 // being set by media::remoting::ConvertProtoToPipelineStatistics()? |
| 149 EXPECT_EQ(0, memcmp(&original, &converted, sizeof(converted))); |
| 150 } |
| 151 |
| 152 // TODO(miu): Tests for all other conversion functions. |
| 153 |
123 TEST_F(ProtoUtilsTest, CdmPromiseResultConversion) { | 154 TEST_F(ProtoUtilsTest, CdmPromiseResultConversion) { |
124 CdmPromiseResult success_result = CdmPromiseResult::SuccessResult(); | 155 CdmPromiseResult success_result = CdmPromiseResult::SuccessResult(); |
125 | 156 |
126 pb::CdmPromise promise_message; | 157 pb::CdmPromise promise_message; |
127 ConvertCdmPromiseToProto(success_result, &promise_message); | 158 ConvertCdmPromiseToProto(success_result, &promise_message); |
128 | 159 |
129 CdmPromiseResult output_result; | 160 CdmPromiseResult output_result; |
130 ASSERT_TRUE(ConvertProtoToCdmPromise(promise_message, &output_result)); | 161 ASSERT_TRUE(ConvertProtoToCdmPromise(promise_message, &output_result)); |
131 | 162 |
132 ASSERT_EQ(success_result.success(), output_result.success()); | 163 ASSERT_EQ(success_result.success(), output_result.success()); |
(...skipping 24 matching lines...) Expand all Loading... |
157 for (uint32_t i = 0; i < 3; i++) { | 188 for (uint32_t i = 0; i < 3; i++) { |
158 ASSERT_EQ(keys_information[i]->key_id, key_output_information[i]->key_id); | 189 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); | 190 ASSERT_EQ(keys_information[i]->status, key_output_information[i]->status); |
160 ASSERT_EQ(keys_information[i]->system_code, | 191 ASSERT_EQ(keys_information[i]->system_code, |
161 key_output_information[i]->system_code); | 192 key_output_information[i]->system_code); |
162 } | 193 } |
163 } | 194 } |
164 | 195 |
165 } // namespace remoting | 196 } // namespace remoting |
166 } // namespace media | 197 } // namespace media |
OLD | NEW |