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

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

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