OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/location.h" | 6 #include "base/location.h" |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "media/audio/audio_parameters.h" | |
11 #include "media/base/channel_layout.h" | |
10 #include "media/base/video_frame.h" | 12 #include "media/base/video_frame.h" |
11 #include "media/capture/webm_muxer.h" | 13 #include "media/capture/webm_muxer.h" |
12 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
14 | 16 |
15 using ::testing::_; | 17 using ::testing::_; |
16 using ::testing::AtLeast; | 18 using ::testing::AtLeast; |
17 using ::testing::Mock; | 19 using ::testing::Mock; |
18 using ::testing::TestWithParam; | 20 using ::testing::TestWithParam; |
19 using ::testing::Values; | 21 using ::testing::ValuesIn; |
20 using ::testing::WithArgs; | 22 using ::testing::WithArgs; |
21 | 23 |
22 namespace media { | 24 namespace media { |
23 | 25 |
24 class WebmMuxerTest : public TestWithParam<VideoCodec> { | 26 struct kTestParams { |
27 VideoCodec codec; | |
28 size_t num_video_tracks; | |
29 size_t num_audio_tracks; | |
30 }; | |
31 | |
32 class WebmMuxerTest : public TestWithParam<kTestParams> { | |
25 public: | 33 public: |
26 WebmMuxerTest() | 34 WebmMuxerTest() |
27 : webm_muxer_( | 35 : webm_muxer_(GetParam().codec, |
28 GetParam() /* codec */, | 36 GetParam().num_video_tracks, |
29 base::Bind(&WebmMuxerTest::WriteCallback, base::Unretained(this))), | 37 GetParam().num_audio_tracks, |
38 base::Bind(&WebmMuxerTest::WriteCallback, | |
39 base::Unretained(this))), | |
30 last_encoded_length_(0), | 40 last_encoded_length_(0), |
31 accumulated_position_(0) { | 41 accumulated_position_(0) { |
32 EXPECT_EQ(webm_muxer_.Position(), 0); | 42 EXPECT_EQ(webm_muxer_.Position(), 0); |
33 const mkvmuxer::int64 kRandomNewPosition = 333; | 43 const mkvmuxer::int64 kRandomNewPosition = 333; |
34 EXPECT_EQ(webm_muxer_.Position(kRandomNewPosition), -1); | 44 EXPECT_EQ(webm_muxer_.Position(kRandomNewPosition), -1); |
35 EXPECT_FALSE(webm_muxer_.Seekable()); | 45 EXPECT_FALSE(webm_muxer_.Seekable()); |
36 } | 46 } |
37 | 47 |
38 MOCK_METHOD1(WriteCallback, void(base::StringPiece)); | 48 MOCK_METHOD1(WriteCallback, void(base::StringPiece)); |
39 | 49 |
(...skipping 30 matching lines...) Expand all Loading... | |
70 | 80 |
71 EXPECT_CALL(*this, WriteCallback(encoded_data)); | 81 EXPECT_CALL(*this, WriteCallback(encoded_data)); |
72 WebmMuxerWrite(encoded_data.data(), encoded_data.size()); | 82 WebmMuxerWrite(encoded_data.data(), encoded_data.size()); |
73 | 83 |
74 EXPECT_EQ(GetWebmMuxerPosition(), static_cast<int64_t>(encoded_data.size())); | 84 EXPECT_EQ(GetWebmMuxerPosition(), static_cast<int64_t>(encoded_data.size())); |
75 } | 85 } |
76 | 86 |
77 // This test sends two frames and checks that the WriteCallback is called with | 87 // This test sends two frames and checks that the WriteCallback is called with |
78 // appropriate params in both cases. | 88 // appropriate params in both cases. |
79 TEST_P(WebmMuxerTest, OnEncodedVideoTwoFrames) { | 89 TEST_P(WebmMuxerTest, OnEncodedVideoTwoFrames) { |
90 if (GetParam().num_video_tracks == 0) | |
91 return; | |
92 | |
80 const gfx::Size frame_size(160, 80); | 93 const gfx::Size frame_size(160, 80); |
81 const scoped_refptr<VideoFrame> video_frame = | 94 const scoped_refptr<VideoFrame> video_frame = |
82 VideoFrame::CreateBlackFrame(frame_size); | 95 VideoFrame::CreateBlackFrame(frame_size); |
83 const std::string encoded_data("abcdefghijklmnopqrstuvwxyz"); | 96 const std::string encoded_data("abcdefghijklmnopqrstuvwxyz"); |
84 | 97 |
85 EXPECT_CALL(*this, WriteCallback(_)) | 98 EXPECT_CALL(*this, WriteCallback(_)) |
86 .Times(AtLeast(1)) | 99 .Times(AtLeast(1)) |
87 .WillRepeatedly(WithArgs<0>( | 100 .WillRepeatedly(WithArgs<0>( |
88 Invoke(this, &WebmMuxerTest::SaveEncodedDataLen))); | 101 Invoke(this, &WebmMuxerTest::SaveEncodedDataLen))); |
89 webm_muxer_.OnEncodedVideo(video_frame, | 102 webm_muxer_.OnEncodedVideo(video_frame, |
(...skipping 21 matching lines...) Expand all Loading... | |
111 // The second time around the callbacks should include a SimpleBlock header, | 124 // The second time around the callbacks should include a SimpleBlock header, |
112 // namely the track index, a timestamp and a flags byte, for a total of 6B. | 125 // namely the track index, a timestamp and a flags byte, for a total of 6B. |
113 EXPECT_EQ(last_encoded_length_, encoded_data.size()); | 126 EXPECT_EQ(last_encoded_length_, encoded_data.size()); |
114 EXPECT_EQ(GetWebmMuxerPosition(), accumulated_position_); | 127 EXPECT_EQ(GetWebmMuxerPosition(), accumulated_position_); |
115 const uint32_t kSimpleBlockSize = 6u; | 128 const uint32_t kSimpleBlockSize = 6u; |
116 EXPECT_EQ(static_cast<int64_t>(begin_of_second_block + kSimpleBlockSize + | 129 EXPECT_EQ(static_cast<int64_t>(begin_of_second_block + kSimpleBlockSize + |
117 encoded_data.size()), | 130 encoded_data.size()), |
118 accumulated_position_); | 131 accumulated_position_); |
119 } | 132 } |
120 | 133 |
121 INSTANTIATE_TEST_CASE_P(, WebmMuxerTest, Values(kCodecVP8, kCodecVP9)); | 134 TEST_P(WebmMuxerTest, OnEncodedAudioTwoFrames) { |
135 if (GetParam().num_audio_tracks == 0) | |
136 return; | |
137 | |
138 int sample_rate = 48000; | |
139 int bits_per_sample = 16; | |
140 int frames_per_buffer = 480; | |
141 media::AudioParameters audio_params( | |
142 media::AudioParameters::Format::AUDIO_PCM_LOW_LATENCY, | |
143 media::CHANNEL_LAYOUT_MONO, sample_rate, bits_per_sample, | |
144 frames_per_buffer); | |
145 | |
146 const std::string encoded_data("abcdefghijklmnopqrstuvwxyz"); | |
147 | |
148 EXPECT_CALL(*this, WriteCallback(_)) | |
149 .Times(AtLeast(1)) | |
150 .WillRepeatedly( | |
151 WithArgs<0>(Invoke(this, &WebmMuxerTest::SaveEncodedDataLen))); | |
152 webm_muxer_.OnEncodedAudio(audio_params, | |
153 make_scoped_ptr(new std::string(encoded_data)), | |
154 base::TimeTicks::Now()); | |
155 | |
156 // First time around WriteCallback() is pinged a number of times to write the | |
157 // Matroska header, but at the end it dumps |encoded_data|. | |
158 EXPECT_EQ(last_encoded_length_, encoded_data.size()); | |
159 EXPECT_EQ(GetWebmMuxerPosition(), accumulated_position_); | |
160 EXPECT_GE(GetWebmMuxerPosition(), static_cast<int64_t>(last_encoded_length_)); | |
161 EXPECT_EQ(GetWebmSegmentMode(), mkvmuxer::Segment::kLive); | |
162 | |
163 const int64_t begin_of_second_block = accumulated_position_; | |
164 EXPECT_CALL(*this, WriteCallback(_)) | |
165 .Times(AtLeast(1)) | |
166 .WillRepeatedly( | |
167 WithArgs<0>(Invoke(this, &WebmMuxerTest::SaveEncodedDataLen))); | |
168 webm_muxer_.OnEncodedAudio(audio_params, | |
169 make_scoped_ptr(new std::string(encoded_data)), | |
170 base::TimeTicks::Now()); | |
171 | |
172 // The second time around the callbacks should include a SimpleBlock header, | |
173 // namely the track index, a timestamp and a flags byte, for a total of 6B. | |
174 EXPECT_EQ(last_encoded_length_, encoded_data.size()); | |
175 EXPECT_EQ(GetWebmMuxerPosition(), accumulated_position_); | |
176 const uint32_t kSimpleBlockSize = 6u; | |
177 EXPECT_EQ(static_cast<int64_t>(begin_of_second_block + kSimpleBlockSize + | |
178 encoded_data.size()), | |
179 accumulated_position_); | |
180 } | |
181 | |
182 const kTestParams kTestCases[] = { | |
183 // TODO: consider not enumerating every combination by hand. | |
184 {kCodecVP8, 1 /* num_video_tracks */, 0 /*num_audio_tracks*/}, | |
185 {kCodecVP9, 1, 0}, | |
186 {kCodecVP8, 0, 1}, | |
187 }; | |
188 | |
189 INSTANTIATE_TEST_CASE_P(, WebmMuxerTest, ::testing::ValuesIn(kTestCases)); | |
mcasas
2015/11/02 18:29:54
Yes, here you can s/::testing::ValuesIn/ValuesIn/
ajose
2015/11/02 22:39:51
Done.
| |
122 | 190 |
123 } // namespace media | 191 } // namespace media |
OLD | NEW |