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

Side by Side Diff: content/renderer/media/media_recorder_handler_unittest.cc

Issue 1534553003: MediaRecorder: correct MIME type parsing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updated content_unittests, updated vp9 handling Created 5 years 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
OLDNEW
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/run_loop.h" 5 #include "base/run_loop.h"
6 #include "base/strings/utf_string_conversions.h" 6 #include "base/strings/utf_string_conversions.h"
7 #include "content/child/child_process.h" 7 #include "content/child/child_process.h"
8 #include "content/renderer/media/media_recorder_handler.h" 8 #include "content/renderer/media/media_recorder_handler.h"
9 #include "content/renderer/media/mock_media_stream_registry.h" 9 #include "content/renderer/media/mock_media_stream_registry.h"
10 #include "media/audio/simple_sources.h" 10 #include "media/audio/simple_sources.h"
(...skipping 26 matching lines...) Expand all
37 static const std::string kTestAudioTrackId = "audio_track_id"; 37 static const std::string kTestAudioTrackId = "audio_track_id";
38 static const int kTestAudioChannels = 2; 38 static const int kTestAudioChannels = 2;
39 static const int kTestAudioBitsPerSample = 16; 39 static const int kTestAudioBitsPerSample = 16;
40 static const int kTestAudioSampleRate = 48000; 40 static const int kTestAudioSampleRate = 48000;
41 static const int kTestAudioBufferDurationMS = 60; 41 static const int kTestAudioBufferDurationMS = 60;
42 42
43 struct MediaRecorderTestParams { 43 struct MediaRecorderTestParams {
44 const bool has_video; 44 const bool has_video;
45 const bool has_audio; 45 const bool has_audio;
46 const char* const mime_type; 46 const char* const mime_type;
47 const char* const codecs;
47 const size_t first_encoded_video_frame_size; 48 const size_t first_encoded_video_frame_size;
48 const size_t second_encoded_video_frame_size; 49 const size_t second_encoded_video_frame_size;
49 const size_t first_encoded_audio_frame_size; 50 const size_t first_encoded_audio_frame_size;
50 const size_t second_encoded_audio_frame_size; 51 const size_t second_encoded_audio_frame_size;
51 }; 52 };
52 53
53 static const MediaRecorderTestParams kMediaRecorderTestParams[] = { 54 static const MediaRecorderTestParams kMediaRecorderTestParams[] = {
tommi (sloooow) - chröme 2015/12/18 10:06:30 Can you document what this array contains? Does it
mcasas 2015/12/18 21:27:45 Done.
54 {true, false, "video/vp8", 52, 32, 0, 0}, 55 {true, false, "video/webm", "vp8", 52, 32, 0, 0},
55 {true, false, "video/vp9", 33, 18, 0, 0}, 56 {true, false, "video/webm", "vp9", 33, 18, 0, 0},
56 {false, true, "video/vp8", 0, 0, 990, 706}}; 57 {false, true, "video/webm", "vp8", 0, 0, 990, 706}};
57 58
58 class MediaRecorderHandlerTest : public TestWithParam<MediaRecorderTestParams>, 59 class MediaRecorderHandlerTest : public TestWithParam<MediaRecorderTestParams>,
59 public blink::WebMediaRecorderHandlerClient { 60 public blink::WebMediaRecorderHandlerClient {
60 public: 61 public:
61 MediaRecorderHandlerTest() 62 MediaRecorderHandlerTest()
62 : media_recorder_handler_(new MediaRecorderHandler()), 63 : media_recorder_handler_(new MediaRecorderHandler()),
63 audio_source_(kTestAudioChannels, 64 audio_source_(kTestAudioChannels,
64 440 /* freq */, 65 440 /* freq */,
65 kTestAudioSampleRate) { 66 kTestAudioSampleRate) {
66 EXPECT_FALSE(media_recorder_handler_->recording_); 67 EXPECT_FALSE(media_recorder_handler_->recording_);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 scoped_ptr<MediaRecorderHandler> media_recorder_handler_; 125 scoped_ptr<MediaRecorderHandler> media_recorder_handler_;
125 126
126 // For generating test AudioBuses 127 // For generating test AudioBuses
127 media::SineWaveAudioSource audio_source_; 128 media::SineWaveAudioSource audio_source_;
128 129
129 private: 130 private:
130 DISALLOW_COPY_AND_ASSIGN(MediaRecorderHandlerTest); 131 DISALLOW_COPY_AND_ASSIGN(MediaRecorderHandlerTest);
131 }; 132 };
132 133
133 // Checks that canSupportMimeType() works as expected. 134 // Checks that canSupportMimeType() works as expected.
134 // TODO(mcasas): revisit this when canSupportMimeType() is fully implemented.
135 TEST_F(MediaRecorderHandlerTest, CanSupportMimeType) { 135 TEST_F(MediaRecorderHandlerTest, CanSupportMimeType) {
136 const WebString good_mime_type_vp8(base::UTF8ToUTF16("video/vp8")); 136 const WebString bad_mime_type(base::UTF8ToUTF16("video/mpeg"));
137 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType(good_mime_type_vp8)); 137 EXPECT_FALSE(media_recorder_handler_->canSupportMimeType(
138 bad_mime_type, WebString()));
138 139
139 const WebString good_mime_type_vp9(base::UTF8ToUTF16("video/vp9")); 140 const WebString mime_type_video(base::UTF8ToUTF16("video/webm"));
tommi (sloooow) - chröme 2015/12/18 10:06:30 suggest tests for mixed case mime types as well as
mcasas 2015/12/18 21:27:45 Done. (Note that there were a few negative cases
140 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType(good_mime_type_vp9)); 141 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType(
142 mime_type_video, WebString()));
143 const WebString example_good_codecs_1(base::UTF8ToUTF16("vp8"));
144 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType(
145 mime_type_video, example_good_codecs_1));
146 const WebString example_good_codecs_2(base::UTF8ToUTF16("vp9,opus"));
147 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType(
148 mime_type_video, example_good_codecs_2));
149 const WebString example_bad_codecs_1(base::UTF8ToUTF16("daala"));
150 EXPECT_FALSE(media_recorder_handler_->canSupportMimeType(
151 mime_type_video, example_bad_codecs_1));
141 152
142 const WebString audio_mime_type(base::UTF8ToUTF16("audio/opus")); 153 const WebString mime_type_audio(base::UTF8ToUTF16("audio/webm"));
143 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType(audio_mime_type)); 154 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType(
144 155 mime_type_audio, WebString()));
145 const WebString combo_mime_type(base::UTF8ToUTF16("video/vp8, audio/opus")); 156 const WebString example_good_codecs_3(base::UTF8ToUTF16("opus"));
146 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType(combo_mime_type)); 157 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType(
147 158 mime_type_audio, example_good_codecs_3));
148 const WebString bad_combo(base::UTF8ToUTF16("video/vp8, audio/unsupported")); 159 const WebString example_bad_codecs_2(base::UTF8ToUTF16("vorbis"));
149 EXPECT_FALSE(media_recorder_handler_->canSupportMimeType(bad_combo)); 160 EXPECT_FALSE(media_recorder_handler_->canSupportMimeType(
150 161 mime_type_audio, example_bad_codecs_2));
151 const WebString bad_mime_type(base::UTF8ToUTF16("video/unsupportedcodec"));
152 EXPECT_FALSE(media_recorder_handler_->canSupportMimeType(bad_mime_type));
153
154 const WebString empty_mime_type(base::UTF8ToUTF16(""));
155 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType(empty_mime_type));
156 } 162 }
157 163
158 // Checks that the initialization-destruction sequence works fine. 164 // Checks that the initialization-destruction sequence works fine.
159 TEST_P(MediaRecorderHandlerTest, InitializeStartStop) { 165 TEST_P(MediaRecorderHandlerTest, InitializeStartStop) {
160 AddTracks(); 166 AddTracks();
161 const WebString mime_type(base::UTF8ToUTF16(GetParam().mime_type)); 167 const WebString mime_type(base::UTF8ToUTF16(GetParam().mime_type));
168 const WebString codecs(base::UTF8ToUTF16(GetParam().codecs));
162 EXPECT_TRUE(media_recorder_handler_->initialize(this, 169 EXPECT_TRUE(media_recorder_handler_->initialize(this,
163 registry_.test_stream(), 170 registry_.test_stream(),
164 mime_type)); 171 mime_type,
172 codecs));
165 EXPECT_FALSE(recording()); 173 EXPECT_FALSE(recording());
166 EXPECT_FALSE(hasVideoRecorders()); 174 EXPECT_FALSE(hasVideoRecorders());
167 EXPECT_FALSE(hasAudioRecorders()); 175 EXPECT_FALSE(hasAudioRecorders());
168 176
169 EXPECT_TRUE(media_recorder_handler_->start()); 177 EXPECT_TRUE(media_recorder_handler_->start());
170 EXPECT_TRUE(recording()); 178 EXPECT_TRUE(recording());
171 179
172 EXPECT_TRUE(hasVideoRecorders() || !GetParam().has_video); 180 EXPECT_TRUE(hasVideoRecorders() || !GetParam().has_video);
173 EXPECT_TRUE(hasAudioRecorders() || !GetParam().has_audio); 181 EXPECT_TRUE(hasAudioRecorders() || !GetParam().has_audio);
174 182
175 media_recorder_handler_->stop(); 183 media_recorder_handler_->stop();
176 EXPECT_FALSE(recording()); 184 EXPECT_FALSE(recording());
177 EXPECT_FALSE(hasVideoRecorders()); 185 EXPECT_FALSE(hasVideoRecorders());
178 EXPECT_FALSE(hasAudioRecorders()); 186 EXPECT_FALSE(hasAudioRecorders());
179 187
180 // Expect a last call on destruction. 188 // Expect a last call on destruction.
181 EXPECT_CALL(*this, writeData(_, _, true)).Times(1); 189 EXPECT_CALL(*this, writeData(_, _, true)).Times(1);
182 media_recorder_handler_.reset(); 190 media_recorder_handler_.reset();
183 } 191 }
184 192
185 // Sends 2 frames and expect them as WebM contained encoded data in writeData(). 193 // Sends 2 frames and expect them as WebM contained encoded data in writeData().
186 TEST_P(MediaRecorderHandlerTest, EncodeVideoFrames) { 194 TEST_P(MediaRecorderHandlerTest, EncodeVideoFrames) {
187 // Video-only test. 195 // Video-only test.
188 if (GetParam().has_audio) 196 if (GetParam().has_audio)
189 return; 197 return;
190 198
191 AddTracks(); 199 AddTracks();
192 200
193 const WebString mime_type(base::UTF8ToUTF16(GetParam().mime_type)); 201 const WebString mime_type(base::UTF8ToUTF16(GetParam().mime_type));
202 const WebString codecs(base::UTF8ToUTF16(GetParam().codecs));
194 EXPECT_TRUE(media_recorder_handler_->initialize(this, registry_.test_stream(), 203 EXPECT_TRUE(media_recorder_handler_->initialize(this, registry_.test_stream(),
195 mime_type)); 204 mime_type, codecs));
196 EXPECT_TRUE(media_recorder_handler_->start()); 205 EXPECT_TRUE(media_recorder_handler_->start());
197 206
198 InSequence s; 207 InSequence s;
199 const scoped_refptr<media::VideoFrame> video_frame = 208 const scoped_refptr<media::VideoFrame> video_frame =
200 media::VideoFrame::CreateBlackFrame(gfx::Size(160, 80)); 209 media::VideoFrame::CreateBlackFrame(gfx::Size(160, 80));
201 210
202 { 211 {
203 base::RunLoop run_loop; 212 base::RunLoop run_loop;
204 base::Closure quit_closure = run_loop.QuitClosure(); 213 base::Closure quit_closure = run_loop.QuitClosure();
205 // writeData() is pinged a number of times as the WebM header is written; 214 // writeData() is pinged a number of times as the WebM header is written;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 ValuesIn(kMediaRecorderTestParams)); 252 ValuesIn(kMediaRecorderTestParams));
244 253
245 // Sends 2 frames and expect them as WebM contained encoded data in writeData(). 254 // Sends 2 frames and expect them as WebM contained encoded data in writeData().
246 TEST_P(MediaRecorderHandlerTest, EncodeAudioFrames) { 255 TEST_P(MediaRecorderHandlerTest, EncodeAudioFrames) {
247 // Audio-only test. 256 // Audio-only test.
248 if (GetParam().has_video) 257 if (GetParam().has_video)
249 return; 258 return;
250 259
251 AddTracks(); 260 AddTracks();
252 261
253 const WebString mime_type(base::UTF8ToUTF16("audio/opus")); 262 const WebString mime_type(base::UTF8ToUTF16("audio/webm"));
254 EXPECT_TRUE(media_recorder_handler_->initialize(this, registry_.test_stream(), 263 EXPECT_TRUE(media_recorder_handler_->initialize(this, registry_.test_stream(),
255 mime_type)); 264 mime_type, WebString()));
256 EXPECT_TRUE(media_recorder_handler_->start()); 265 EXPECT_TRUE(media_recorder_handler_->start());
257 266
258 InSequence s; 267 InSequence s;
259 const scoped_ptr<media::AudioBus> audio_bus1 = NextAudioBus(); 268 const scoped_ptr<media::AudioBus> audio_bus1 = NextAudioBus();
260 const scoped_ptr<media::AudioBus> audio_bus2 = NextAudioBus(); 269 const scoped_ptr<media::AudioBus> audio_bus2 = NextAudioBus();
261 270
262 media::AudioParameters params( 271 media::AudioParameters params(
263 media::AudioParameters::AUDIO_PCM_LINEAR, media::CHANNEL_LAYOUT_STEREO, 272 media::AudioParameters::AUDIO_PCM_LINEAR, media::CHANNEL_LAYOUT_STEREO,
264 kTestAudioSampleRate, kTestAudioBitsPerSample, 273 kTestAudioSampleRate, kTestAudioBitsPerSample,
265 kTestAudioSampleRate * kTestAudioBufferDurationMS / 1000); 274 kTestAudioSampleRate * kTestAudioBufferDurationMS / 1000);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 } 307 }
299 308
300 media_recorder_handler_->stop(); 309 media_recorder_handler_->stop();
301 310
302 // Expect a last call on destruction, with size 0 and |lastInSlice| true. 311 // Expect a last call on destruction, with size 0 and |lastInSlice| true.
303 EXPECT_CALL(*this, writeData(nullptr, 0, true)).Times(1); 312 EXPECT_CALL(*this, writeData(nullptr, 0, true)).Times(1);
304 media_recorder_handler_.reset(); 313 media_recorder_handler_.reset();
305 } 314 }
306 315
307 } // namespace content 316 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698