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

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

Issue 1834323002: MediaStream audio: Refactor 3 separate "glue" implementations into one. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: REBASE + Workaround to ensure MediaStreamAudioProcessor is destroyed on the main thread. Created 4 years, 7 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "base/logging.h" 7 #include "base/logging.h"
8 #include "content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h" 8 #include "content/renderer/media/media_stream_audio_track.h"
9 #include "content/renderer/media/webrtc_local_audio_source_provider.h" 9 #include "content/renderer/media/webrtc_local_audio_source_provider.h"
10 #include "content/renderer/media/webrtc_local_audio_track.h"
11 #include "media/base/audio_bus.h" 10 #include "media/base/audio_bus.h"
12 #include "media/base/audio_parameters.h" 11 #include "media/base/audio_parameters.h"
13 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
14 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" 13 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h"
15 #include "third_party/WebKit/public/platform/WebString.h" 14 #include "third_party/WebKit/public/platform/WebString.h"
16 #include "third_party/WebKit/public/web/WebHeap.h" 15 #include "third_party/WebKit/public/web/WebHeap.h"
17 16
18 namespace content { 17 namespace content {
19 18
20 class WebRtcLocalAudioSourceProviderTest : public testing::Test { 19 class WebRtcLocalAudioSourceProviderTest : public testing::Test {
21 protected: 20 protected:
22 void SetUp() override { 21 void SetUp() override {
23 source_params_.Reset(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, 22 source_params_.Reset(media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
24 media::CHANNEL_LAYOUT_MONO, 48000, 16, 480); 23 media::CHANNEL_LAYOUT_MONO, 48000, 16, 480);
25 sink_params_.Reset( 24 sink_params_.Reset(
26 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, 25 media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
27 media::CHANNEL_LAYOUT_STEREO, 44100, 16, 26 media::CHANNEL_LAYOUT_STEREO, 44100, 16,
28 WebRtcLocalAudioSourceProvider::kWebAudioRenderBufferSize); 27 WebRtcLocalAudioSourceProvider::kWebAudioRenderBufferSize);
29 sink_bus_ = media::AudioBus::Create(sink_params_); 28 sink_bus_ = media::AudioBus::Create(sink_params_);
30 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter(
31 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL));
32 std::unique_ptr<WebRtcLocalAudioTrack> native_track(
33 new WebRtcLocalAudioTrack(adapter.get()));
34 blink::WebMediaStreamSource audio_source; 29 blink::WebMediaStreamSource audio_source;
35 audio_source.initialize(blink::WebString::fromUTF8("dummy_source_id"), 30 audio_source.initialize(blink::WebString::fromUTF8("dummy_source_id"),
36 blink::WebMediaStreamSource::TypeAudio, 31 blink::WebMediaStreamSource::TypeAudio,
37 blink::WebString::fromUTF8("dummy_source_name"), 32 blink::WebString::fromUTF8("dummy_source_name"),
38 false /* remote */); 33 false /* remote */);
39 blink_track_.initialize(blink::WebString::fromUTF8("audio_track"), 34 blink_track_.initialize(blink::WebString::fromUTF8("audio_track"),
40 audio_source); 35 audio_source);
41 blink_track_.setExtraData(native_track.release()); 36 blink_track_.setExtraData(new MediaStreamAudioTrack(true));
42 source_provider_.reset(new WebRtcLocalAudioSourceProvider(blink_track_)); 37 source_provider_.reset(new WebRtcLocalAudioSourceProvider(blink_track_));
43 source_provider_->SetSinkParamsForTesting(sink_params_); 38 source_provider_->SetSinkParamsForTesting(sink_params_);
44 source_provider_->OnSetFormat(source_params_); 39 source_provider_->OnSetFormat(source_params_);
45 } 40 }
46 41
47 void TearDown() override { 42 void TearDown() override {
48 source_provider_.reset(); 43 source_provider_.reset();
49 blink_track_.reset(); 44 blink_track_.reset();
50 blink::WebHeap::collectAllGarbageForTesting(); 45 blink::WebHeap::collectAllGarbageForTesting();
51 } 46 }
52 47
53 media::AudioParameters source_params_; 48 media::AudioParameters source_params_;
54 media::AudioParameters sink_params_; 49 media::AudioParameters sink_params_;
55 std::unique_ptr<media::AudioBus> sink_bus_; 50 std::unique_ptr<media::AudioBus> sink_bus_;
56 blink::WebMediaStreamTrack blink_track_; 51 blink::WebMediaStreamTrack blink_track_;
57 std::unique_ptr<WebRtcLocalAudioSourceProvider> source_provider_; 52 std::unique_ptr<WebRtcLocalAudioSourceProvider> source_provider_;
58 }; 53 };
59 54
60 TEST_F(WebRtcLocalAudioSourceProviderTest, VerifyDataFlow) { 55 TEST_F(WebRtcLocalAudioSourceProviderTest, VerifyDataFlow) {
56 // TODO(miu): This test should be re-worked so that the audio data and format
57 // is feed into a MediaStreamAudioSource and, through the
58 // MediaStreamAudioTrack, ultimately delivered to the |source_provider_|.
59
61 // Point the WebVector into memory owned by |sink_bus_|. 60 // Point the WebVector into memory owned by |sink_bus_|.
62 blink::WebVector<float*> audio_data( 61 blink::WebVector<float*> audio_data(
63 static_cast<size_t>(sink_bus_->channels())); 62 static_cast<size_t>(sink_bus_->channels()));
64 for (size_t i = 0; i < audio_data.size(); ++i) 63 for (size_t i = 0; i < audio_data.size(); ++i)
65 audio_data[i] = sink_bus_->channel(i); 64 audio_data[i] = sink_bus_->channel(i);
66 65
67 // Enable the |source_provider_| by asking for data. This will inject 66 // Enable the |source_provider_| by asking for data. This will inject
68 // source_params_.frames_per_buffer() of zero into the resampler since there 67 // source_params_.frames_per_buffer() of zero into the resampler since there
69 // no available data in the FIFO. 68 // no available data in the FIFO.
70 source_provider_->provideInput(audio_data, sink_params_.frames_per_buffer()); 69 source_provider_->provideInput(audio_data, sink_params_.frames_per_buffer());
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 EXPECT_NEAR(0.5f, sink_bus_->channel(1)[0], 0.001f); 111 EXPECT_NEAR(0.5f, sink_bus_->channel(1)[0], 0.001f);
113 EXPECT_DOUBLE_EQ(sink_bus_->channel(0)[0], sink_bus_->channel(1)[0]); 112 EXPECT_DOUBLE_EQ(sink_bus_->channel(0)[0], sink_bus_->channel(1)[0]);
114 } 113 }
115 } 114 }
116 115
117 TEST_F(WebRtcLocalAudioSourceProviderTest, 116 TEST_F(WebRtcLocalAudioSourceProviderTest,
118 DeleteSourceProviderBeforeStoppingTrack) { 117 DeleteSourceProviderBeforeStoppingTrack) {
119 source_provider_.reset(); 118 source_provider_.reset();
120 119
121 // Stop the audio track. 120 // Stop the audio track.
122 WebRtcLocalAudioTrack* native_track = static_cast<WebRtcLocalAudioTrack*>( 121 MediaStreamAudioTrack::From(blink_track_)->Stop();
123 MediaStreamTrack::GetTrack(blink_track_));
124 native_track->Stop();
125 } 122 }
126 123
127 TEST_F(WebRtcLocalAudioSourceProviderTest, 124 TEST_F(WebRtcLocalAudioSourceProviderTest,
128 StopTrackBeforeDeletingSourceProvider) { 125 StopTrackBeforeDeletingSourceProvider) {
129 // Stop the audio track. 126 // Stop the audio track.
130 WebRtcLocalAudioTrack* native_track = static_cast<WebRtcLocalAudioTrack*>( 127 MediaStreamAudioTrack::From(blink_track_)->Stop();
131 MediaStreamTrack::GetTrack(blink_track_));
132 native_track->Stop();
133 128
134 // Delete the source provider. 129 // Delete the source provider.
135 source_provider_.reset(); 130 source_provider_.reset();
136 } 131 }
137 132
138 } // namespace content 133 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/webrtc_local_audio_source_provider.h ('k') | content/renderer/media/webrtc_local_audio_track.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698