OLD | NEW |
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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include "content/renderer/media/media_stream_audio_level_calculator.h" | 7 #include "content/renderer/media/mock_media_constraint_factory.h" |
8 #include "content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h" | 8 #include "content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h" |
9 #include "content/renderer/media/webrtc_audio_capturer.h" | 9 #include "content/renderer/media/webrtc_audio_capturer.h" |
10 #include "content/renderer/media/webrtc_local_audio_track.h" | 10 #include "content/renderer/media/webrtc_local_audio_track.h" |
11 #include "testing/gmock/include/gmock/gmock.h" | 11 #include "testing/gmock/include/gmock/gmock.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "third_party/webrtc/api/mediastreaminterface.h" | 13 #include "third_party/webrtc/api/mediastreaminterface.h" |
14 | 14 |
15 using ::testing::_; | 15 using ::testing::_; |
16 using ::testing::AnyNumber; | 16 using ::testing::AnyNumber; |
17 | 17 |
(...skipping 13 matching lines...) Expand all Loading... |
31 }; | 31 }; |
32 | 32 |
33 } // namespace | 33 } // namespace |
34 | 34 |
35 class WebRtcLocalAudioTrackAdapterTest : public ::testing::Test { | 35 class WebRtcLocalAudioTrackAdapterTest : public ::testing::Test { |
36 public: | 36 public: |
37 WebRtcLocalAudioTrackAdapterTest() | 37 WebRtcLocalAudioTrackAdapterTest() |
38 : params_(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, | 38 : params_(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, |
39 media::CHANNEL_LAYOUT_STEREO, 48000, 16, 480), | 39 media::CHANNEL_LAYOUT_STEREO, 48000, 16, 480), |
40 adapter_(WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)) { | 40 adapter_(WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)) { |
41 track_.reset(new WebRtcLocalAudioTrack(adapter_.get())); | 41 MockMediaConstraintFactory constraint_factory; |
| 42 capturer_ = WebRtcAudioCapturer::CreateCapturer( |
| 43 -1, StreamDeviceInfo(MEDIA_DEVICE_AUDIO_CAPTURE, "", ""), |
| 44 constraint_factory.CreateWebMediaConstraints(), NULL, NULL); |
| 45 track_.reset(new WebRtcLocalAudioTrack(adapter_.get(), capturer_, NULL)); |
42 } | 46 } |
43 | 47 |
44 protected: | 48 protected: |
45 void SetUp() override { | 49 void SetUp() override { |
46 track_->OnSetFormat(params_); | 50 track_->OnSetFormat(params_); |
47 EXPECT_TRUE(track_->GetAudioAdapter()->enabled()); | 51 EXPECT_TRUE(track_->GetAudioAdapter()->enabled()); |
48 } | 52 } |
49 | 53 |
50 media::AudioParameters params_; | 54 media::AudioParameters params_; |
51 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_; | 55 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_; |
| 56 scoped_refptr<WebRtcAudioCapturer> capturer_; |
52 scoped_ptr<WebRtcLocalAudioTrack> track_; | 57 scoped_ptr<WebRtcLocalAudioTrack> track_; |
53 }; | 58 }; |
54 | 59 |
55 // Adds and Removes a WebRtcAudioSink to a local audio track. | 60 // Adds and Removes a WebRtcAudioSink to a local audio track. |
56 TEST_F(WebRtcLocalAudioTrackAdapterTest, AddAndRemoveSink) { | 61 TEST_F(WebRtcLocalAudioTrackAdapterTest, AddAndRemoveSink) { |
57 // Add a sink to the webrtc track. | 62 // Add a sink to the webrtc track. |
58 scoped_ptr<MockWebRtcAudioSink> sink(new MockWebRtcAudioSink()); | 63 scoped_ptr<MockWebRtcAudioSink> sink(new MockWebRtcAudioSink()); |
59 webrtc::AudioTrackInterface* webrtc_track = | 64 webrtc::AudioTrackInterface* webrtc_track = |
60 static_cast<webrtc::AudioTrackInterface*>(adapter_.get()); | 65 static_cast<webrtc::AudioTrackInterface*>(adapter_.get()); |
61 webrtc_track->AddSink(sink.get()); | 66 webrtc_track->AddSink(sink.get()); |
62 | 67 |
63 // Send a packet via |track_| and the data should reach the sink of the | 68 // Send a packet via |track_| and the data should reach the sink of the |
64 // |adapter_|. | 69 // |adapter_|. |
65 const scoped_ptr<media::AudioBus> audio_bus = | 70 const scoped_ptr<media::AudioBus> audio_bus = |
66 media::AudioBus::Create(params_); | 71 media::AudioBus::Create(params_); |
67 // While this test is not checking the signal data being passed around, the | 72 // While this test is not checking the signal data being passed around, the |
68 // implementation in WebRtcLocalAudioTrack reads the data for its signal level | 73 // implementation in WebRtcLocalAudioTrack reads the data for its signal level |
69 // computation. Initialize all samples to zero to make the memory sanitizer | 74 // computation. Initialize all samples to zero to make the memory sanitizer |
70 // happy. | 75 // happy. |
71 audio_bus->Zero(); | 76 audio_bus->Zero(); |
72 | 77 |
73 base::TimeTicks estimated_capture_time = base::TimeTicks::Now(); | 78 base::TimeTicks estimated_capture_time = base::TimeTicks::Now(); |
74 EXPECT_CALL(*sink, | 79 EXPECT_CALL(*sink, |
75 OnData(_, 16, params_.sample_rate(), params_.channels(), | 80 OnData(_, 16, params_.sample_rate(), params_.channels(), |
76 params_.frames_per_buffer())); | 81 params_.frames_per_buffer())); |
77 track_->Capture(*audio_bus, estimated_capture_time); | 82 track_->Capture(*audio_bus, estimated_capture_time, false); |
78 | 83 |
79 // Remove the sink from the webrtc track. | 84 // Remove the sink from the webrtc track. |
80 webrtc_track->RemoveSink(sink.get()); | 85 webrtc_track->RemoveSink(sink.get()); |
81 sink.reset(); | 86 sink.reset(); |
82 | 87 |
83 // Verify that no more callback gets into the sink. | 88 // Verify that no more callback gets into the sink. |
84 estimated_capture_time += | 89 estimated_capture_time += |
85 params_.frames_per_buffer() * base::TimeDelta::FromSeconds(1) / | 90 params_.frames_per_buffer() * base::TimeDelta::FromSeconds(1) / |
86 params_.sample_rate(); | 91 params_.sample_rate(); |
87 track_->Capture(*audio_bus, estimated_capture_time); | 92 track_->Capture(*audio_bus, estimated_capture_time, false); |
88 } | 93 } |
89 | 94 |
90 TEST_F(WebRtcLocalAudioTrackAdapterTest, GetSignalLevel) { | 95 TEST_F(WebRtcLocalAudioTrackAdapterTest, GetSignalLevel) { |
91 webrtc::AudioTrackInterface* webrtc_track = | 96 webrtc::AudioTrackInterface* webrtc_track = |
92 static_cast<webrtc::AudioTrackInterface*>(adapter_.get()); | 97 static_cast<webrtc::AudioTrackInterface*>(adapter_.get()); |
93 int signal_level = -1; | 98 int signal_level = 0; |
94 EXPECT_FALSE(webrtc_track->GetSignalLevel(&signal_level)); | |
95 MediaStreamAudioLevelCalculator calculator; | |
96 adapter_->SetLevel(calculator.level()); | |
97 signal_level = -1; | |
98 EXPECT_TRUE(webrtc_track->GetSignalLevel(&signal_level)); | 99 EXPECT_TRUE(webrtc_track->GetSignalLevel(&signal_level)); |
99 EXPECT_EQ(0, signal_level); | |
100 } | 100 } |
101 | 101 |
102 } // namespace content | 102 } // namespace content |
OLD | NEW |