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

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

Issue 1721273002: MediaStream audio object graph untangling and clean-ups. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: REBASE Created 4 years, 9 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "content/renderer/media/speech_recognition_audio_sink.h" 5 #include "content/renderer/media/speech_recognition_audio_sink.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <string.h> 9 #include <string.h>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "content/renderer/media/media_stream_audio_source.h" 15 #include "content/renderer/media/media_stream_audio_source.h"
16 #include "content/renderer/media/mock_media_constraint_factory.h"
17 #include "content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h" 16 #include "content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h"
18 #include "content/renderer/media/webrtc_local_audio_track.h" 17 #include "content/renderer/media/webrtc_local_audio_track.h"
19 #include "media/audio/audio_parameters.h" 18 #include "media/audio/audio_parameters.h"
20 #include "media/base/audio_bus.h" 19 #include "media/base/audio_bus.h"
21 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
22 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
23 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" 22 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h"
24 #include "third_party/WebKit/public/web/WebHeap.h" 23 #include "third_party/WebKit/public/web/WebHeap.h"
25 24
26 namespace { 25 namespace {
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 267
269 // Mock callback expected to be called when the track is stopped. 268 // Mock callback expected to be called when the track is stopped.
270 MOCK_METHOD0(StoppedCallback, void()); 269 MOCK_METHOD0(StoppedCallback, void());
271 270
272 protected: 271 protected:
273 // Prepares a blink track of a given MediaStreamType and attaches the native 272 // Prepares a blink track of a given MediaStreamType and attaches the native
274 // track which can be used to capture audio data and pass it to the producer. 273 // track which can be used to capture audio data and pass it to the producer.
275 static void PrepareBlinkTrackOfType( 274 static void PrepareBlinkTrackOfType(
276 const MediaStreamType device_type, 275 const MediaStreamType device_type,
277 blink::WebMediaStreamTrack* blink_track) { 276 blink::WebMediaStreamTrack* blink_track) {
278 StreamDeviceInfo device_info(device_type, "Mock device",
279 "mock_device_id");
280 MockMediaConstraintFactory constraint_factory;
281 const blink::WebMediaConstraints constraints =
282 constraint_factory.CreateWebMediaConstraints();
283 scoped_refptr<WebRtcAudioCapturer> capturer(
284 WebRtcAudioCapturer::CreateCapturer(-1, device_info, constraints, NULL,
285 NULL));
286 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( 277 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter(
287 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); 278 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL));
288 scoped_ptr<WebRtcLocalAudioTrack> native_track( 279 scoped_ptr<WebRtcLocalAudioTrack> native_track(
289 new WebRtcLocalAudioTrack(adapter.get(), capturer, NULL)); 280 new WebRtcLocalAudioTrack(adapter.get()));
290 blink::WebMediaStreamSource blink_audio_source; 281 blink::WebMediaStreamSource blink_audio_source;
291 blink_audio_source.initialize(base::UTF8ToUTF16("dummy_source_id"), 282 blink_audio_source.initialize(base::UTF8ToUTF16("dummy_source_id"),
292 blink::WebMediaStreamSource::TypeAudio, 283 blink::WebMediaStreamSource::TypeAudio,
293 base::UTF8ToUTF16("dummy_source_name"), 284 base::UTF8ToUTF16("dummy_source_name"),
294 false /* remote */, true /* readonly */); 285 false /* remote */, true /* readonly */);
295 MediaStreamSource::SourceStoppedCallback cb; 286 MediaStreamSource::SourceStoppedCallback cb;
296 blink_audio_source.setExtraData( 287 blink_audio_source.setExtraData(new MediaStreamAudioSource(
297 new MediaStreamAudioSource(-1, device_info, cb, NULL)); 288 -1, StreamDeviceInfo(device_type, "Mock device", "mock_device_id"), cb,
289 nullptr));
298 blink_track->initialize(blink::WebString::fromUTF8("dummy_track"), 290 blink_track->initialize(blink::WebString::fromUTF8("dummy_track"),
299 blink_audio_source); 291 blink_audio_source);
300 blink_track->setExtraData(native_track.release()); 292 blink_track->setExtraData(native_track.release());
301 } 293 }
302 294
303 // Emulates an audio capture device capturing data from the source. 295 // Emulates an audio capture device capturing data from the source.
304 inline void CaptureAudio(const uint32_t buffers) { 296 inline void CaptureAudio(const uint32_t buffers) {
305 for (uint32_t i = 0; i < buffers; ++i) { 297 for (uint32_t i = 0; i < buffers; ++i) {
306 const base::TimeTicks estimated_capture_time = first_frame_capture_time_ + 298 const base::TimeTicks estimated_capture_time = first_frame_capture_time_ +
307 (sample_frames_captured_ * base::TimeDelta::FromSeconds(1) / 299 (sample_frames_captured_ * base::TimeDelta::FromSeconds(1) /
308 source_params_.sample_rate()); 300 source_params_.sample_rate());
309 native_track()->Capture(*source_bus_, estimated_capture_time, false); 301 native_track()->Capture(*source_bus_, estimated_capture_time);
310 sample_frames_captured_ += source_bus_->frames(); 302 sample_frames_captured_ += source_bus_->frames();
311 } 303 }
312 } 304 }
313 305
314 // Used to simulate a problem with sockets. 306 // Used to simulate a problem with sockets.
315 void SetFailureModeOnForeignSocket(bool in_failure_mode) { 307 void SetFailureModeOnForeignSocket(bool in_failure_mode) {
316 recognizer()->sending_socket()->SetFailureMode(in_failure_mode); 308 recognizer()->sending_socket()->SetFailureMode(in_failure_mode);
317 } 309 }
318 310
319 // Helper method for verifying captured audio data has been consumed. 311 // Helper method for verifying captured audio data has been consumed.
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 const uint32_t buffers_per_notification = Initialize(44100, 441, 16000, 1600); 520 const uint32_t buffers_per_notification = Initialize(44100, 441, 16000, 1600);
529 AssertConsumedBuffers(0U); 521 AssertConsumedBuffers(0U);
530 CaptureAudioAndAssertConsumedBuffers(buffers_per_notification, 1U); 522 CaptureAudioAndAssertConsumedBuffers(buffers_per_notification, 1U);
531 EXPECT_CALL(*this, StoppedCallback()).Times(1); 523 EXPECT_CALL(*this, StoppedCallback()).Times(1);
532 524
533 native_track()->Stop(); 525 native_track()->Stop();
534 CaptureAudioAndAssertConsumedBuffers(buffers_per_notification, 1U); 526 CaptureAudioAndAssertConsumedBuffers(buffers_per_notification, 1U);
535 } 527 }
536 528
537 } // namespace content 529 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/speech_recognition_audio_sink.cc ('k') | content/renderer/media/track_audio_renderer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698