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

Side by Side Diff: content/renderer/media/webrtc/webrtc_local_audio_track_adapter_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: Addressed mcasas's 1st round comments, plus 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include "content/renderer/media/mock_media_constraint_factory.h" 7 #include "content/renderer/media/media_stream_audio_level_calculator.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
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 MockMediaConstraintFactory constraint_factory; 41 track_.reset(new WebRtcLocalAudioTrack(adapter_.get()));
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));
46 } 42 }
47 43
48 protected: 44 protected:
49 void SetUp() override { 45 void SetUp() override {
50 track_->OnSetFormat(params_); 46 track_->OnSetFormat(params_);
51 EXPECT_TRUE(track_->GetAudioAdapter()->enabled()); 47 EXPECT_TRUE(track_->GetAudioAdapter()->enabled());
52 } 48 }
53 49
54 media::AudioParameters params_; 50 media::AudioParameters params_;
55 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_; 51 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_;
56 scoped_refptr<WebRtcAudioCapturer> capturer_;
57 scoped_ptr<WebRtcLocalAudioTrack> track_; 52 scoped_ptr<WebRtcLocalAudioTrack> track_;
58 }; 53 };
59 54
60 // Adds and Removes a WebRtcAudioSink to a local audio track. 55 // Adds and Removes a WebRtcAudioSink to a local audio track.
61 TEST_F(WebRtcLocalAudioTrackAdapterTest, AddAndRemoveSink) { 56 TEST_F(WebRtcLocalAudioTrackAdapterTest, AddAndRemoveSink) {
62 // Add a sink to the webrtc track. 57 // Add a sink to the webrtc track.
63 scoped_ptr<MockWebRtcAudioSink> sink(new MockWebRtcAudioSink()); 58 scoped_ptr<MockWebRtcAudioSink> sink(new MockWebRtcAudioSink());
64 webrtc::AudioTrackInterface* webrtc_track = 59 webrtc::AudioTrackInterface* webrtc_track =
65 static_cast<webrtc::AudioTrackInterface*>(adapter_.get()); 60 static_cast<webrtc::AudioTrackInterface*>(adapter_.get());
66 webrtc_track->AddSink(sink.get()); 61 webrtc_track->AddSink(sink.get());
67 62
68 // Send a packet via |track_| and the data should reach the sink of the 63 // Send a packet via |track_| and the data should reach the sink of the
69 // |adapter_|. 64 // |adapter_|.
70 const scoped_ptr<media::AudioBus> audio_bus = 65 const scoped_ptr<media::AudioBus> audio_bus =
71 media::AudioBus::Create(params_); 66 media::AudioBus::Create(params_);
72 // While this test is not checking the signal data being passed around, the 67 // While this test is not checking the signal data being passed around, the
73 // implementation in WebRtcLocalAudioTrack reads the data for its signal level 68 // implementation in WebRtcLocalAudioTrack reads the data for its signal level
74 // computation. Initialize all samples to zero to make the memory sanitizer 69 // computation. Initialize all samples to zero to make the memory sanitizer
75 // happy. 70 // happy.
76 audio_bus->Zero(); 71 audio_bus->Zero();
77 72
78 base::TimeTicks estimated_capture_time = base::TimeTicks::Now(); 73 base::TimeTicks estimated_capture_time = base::TimeTicks::Now();
79 EXPECT_CALL(*sink, 74 EXPECT_CALL(*sink,
80 OnData(_, 16, params_.sample_rate(), params_.channels(), 75 OnData(_, 16, params_.sample_rate(), params_.channels(),
81 params_.frames_per_buffer())); 76 params_.frames_per_buffer()));
82 track_->Capture(*audio_bus, estimated_capture_time, false); 77 track_->Capture(*audio_bus, estimated_capture_time);
83 78
84 // Remove the sink from the webrtc track. 79 // Remove the sink from the webrtc track.
85 webrtc_track->RemoveSink(sink.get()); 80 webrtc_track->RemoveSink(sink.get());
86 sink.reset(); 81 sink.reset();
87 82
88 // Verify that no more callback gets into the sink. 83 // Verify that no more callback gets into the sink.
89 estimated_capture_time += 84 estimated_capture_time +=
90 params_.frames_per_buffer() * base::TimeDelta::FromSeconds(1) / 85 params_.frames_per_buffer() * base::TimeDelta::FromSeconds(1) /
91 params_.sample_rate(); 86 params_.sample_rate();
92 track_->Capture(*audio_bus, estimated_capture_time, false); 87 track_->Capture(*audio_bus, estimated_capture_time);
93 } 88 }
94 89
95 TEST_F(WebRtcLocalAudioTrackAdapterTest, GetSignalLevel) { 90 TEST_F(WebRtcLocalAudioTrackAdapterTest, GetSignalLevel) {
96 webrtc::AudioTrackInterface* webrtc_track = 91 webrtc::AudioTrackInterface* webrtc_track =
97 static_cast<webrtc::AudioTrackInterface*>(adapter_.get()); 92 static_cast<webrtc::AudioTrackInterface*>(adapter_.get());
98 int signal_level = 0; 93 int signal_level = -1;
94 EXPECT_FALSE(webrtc_track->GetSignalLevel(&signal_level));
95 MediaStreamAudioLevelCalculator calculator;
96 adapter_->SetLevel(calculator.level());
97 signal_level = -1;
99 EXPECT_TRUE(webrtc_track->GetSignalLevel(&signal_level)); 98 EXPECT_TRUE(webrtc_track->GetSignalLevel(&signal_level));
99 EXPECT_EQ(0, signal_level);
100 } 100 }
101 101
102 } // namespace content 102 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698