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

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

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