Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "base/logging.h" | 5 #include "base/logging.h" |
| 6 #include "base/strings/utf_string_conversions.h" | |
| 7 #include "content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h" | |
| 8 #include "content/renderer/media/webrtc_audio_capturer.h" | |
| 6 #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" | |
| 7 #include "media/audio/audio_parameters.h" | 11 #include "media/audio/audio_parameters.h" |
| 8 #include "media/base/audio_bus.h" | 12 #include "media/base/audio_bus.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" | |
| 15 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" | |
| 10 | 16 |
| 11 namespace content { | 17 namespace content { |
| 12 | 18 |
| 13 class WebRtcLocalAudioSourceProviderTest : public testing::Test { | 19 class WebRtcLocalAudioSourceProviderTest : public testing::Test { |
| 14 protected: | 20 protected: |
| 15 virtual void SetUp() OVERRIDE { | 21 virtual void SetUp() OVERRIDE { |
| 16 source_params_.Reset(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, | 22 source_params_.Reset(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, |
| 17 media::CHANNEL_LAYOUT_MONO, 1, 0, 48000, 16, 480); | 23 media::CHANNEL_LAYOUT_MONO, 1, 0, 48000, 16, 480); |
| 18 sink_params_.Reset( | 24 sink_params_.Reset( |
| 19 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, | 25 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, |
| 20 media::CHANNEL_LAYOUT_STEREO, 2, 0, 44100, 16, | 26 media::CHANNEL_LAYOUT_STEREO, 2, 0, 44100, 16, |
| 21 WebRtcLocalAudioSourceProvider::kWebAudioRenderBufferSize); | 27 WebRtcLocalAudioSourceProvider::kWebAudioRenderBufferSize); |
| 22 const int length = | 28 const int length = |
| 23 source_params_.frames_per_buffer() * source_params_.channels(); | 29 source_params_.frames_per_buffer() * source_params_.channels(); |
| 24 source_data_.reset(new int16[length]); | 30 source_data_.reset(new int16[length]); |
| 25 sink_bus_ = media::AudioBus::Create(sink_params_); | 31 sink_bus_ = media::AudioBus::Create(sink_params_); |
| 26 source_provider_.reset(new WebRtcLocalAudioSourceProvider()); | 32 blink::WebMediaConstraints constraints; |
| 33 scoped_refptr<WebRtcAudioCapturer> capturer( | |
| 34 WebRtcAudioCapturer::CreateCapturer(-1, StreamDeviceInfo(), | |
| 35 constraints, NULL)); | |
| 36 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( | |
| 37 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | |
| 38 scoped_ptr<WebRtcLocalAudioTrack> native_track( | |
| 39 new WebRtcLocalAudioTrack(adapter, capturer, NULL)); | |
| 40 blink::WebMediaStreamSource audio_source; | |
| 41 audio_source.initialize(base::UTF8ToUTF16("dummy_source_id"), | |
| 42 blink::WebMediaStreamSource::TypeAudio, | |
| 43 base::UTF8ToUTF16("dummy_source_name")); | |
| 44 blink_track_.initialize(blink::WebString::fromUTF8("audio_track"), | |
| 45 audio_source); | |
| 46 blink_track_.setExtraData(native_track.release()); | |
| 47 source_provider_.reset(new WebRtcLocalAudioSourceProvider(blink_track_)); | |
| 27 source_provider_->SetSinkParamsForTesting(sink_params_); | 48 source_provider_->SetSinkParamsForTesting(sink_params_); |
| 28 source_provider_->OnSetFormat(source_params_); | 49 source_provider_->OnSetFormat(source_params_); |
| 29 } | 50 } |
| 30 | 51 |
| 31 media::AudioParameters source_params_; | 52 media::AudioParameters source_params_; |
| 32 scoped_ptr<int16[]> source_data_; | 53 scoped_ptr<int16[]> source_data_; |
| 33 media::AudioParameters sink_params_; | 54 media::AudioParameters sink_params_; |
| 34 scoped_ptr<media::AudioBus> sink_bus_; | 55 scoped_ptr<media::AudioBus> sink_bus_; |
| 56 blink::WebMediaStreamTrack blink_track_; | |
| 35 scoped_ptr<WebRtcLocalAudioSourceProvider> source_provider_; | 57 scoped_ptr<WebRtcLocalAudioSourceProvider> source_provider_; |
| 36 }; | 58 }; |
| 37 | 59 |
| 38 TEST_F(WebRtcLocalAudioSourceProviderTest, VerifyDataFlow) { | 60 TEST_F(WebRtcLocalAudioSourceProviderTest, VerifyDataFlow) { |
| 39 // Point the WebVector into memory owned by |sink_bus_|. | 61 // Point the WebVector into memory owned by |sink_bus_|. |
| 40 blink::WebVector<float*> audio_data( | 62 blink::WebVector<float*> audio_data( |
| 41 static_cast<size_t>(sink_bus_->channels())); | 63 static_cast<size_t>(sink_bus_->channels())); |
| 42 for (size_t i = 0; i < audio_data.size(); ++i) | 64 for (size_t i = 0; i < audio_data.size(); ++i) |
| 43 audio_data[i] = sink_bus_->channel(i); | 65 audio_data[i] = sink_bus_->channel(i); |
| 44 | 66 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 i += sink_params_.frames_per_buffer()) { | 106 i += sink_params_.frames_per_buffer()) { |
| 85 sink_bus_->Zero(); | 107 sink_bus_->Zero(); |
| 86 source_provider_->provideInput(audio_data, | 108 source_provider_->provideInput(audio_data, |
| 87 sink_params_.frames_per_buffer()); | 109 sink_params_.frames_per_buffer()); |
| 88 EXPECT_GT(sink_bus_->channel(0)[0], 0); | 110 EXPECT_GT(sink_bus_->channel(0)[0], 0); |
| 89 EXPECT_GT(sink_bus_->channel(1)[0], 0); | 111 EXPECT_GT(sink_bus_->channel(1)[0], 0); |
| 90 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]); |
| 91 } | 113 } |
| 92 } | 114 } |
| 93 | 115 |
| 116 TEST_F(WebRtcLocalAudioSourceProviderTest, | |
| 117 DeleteSourceProviderBeforeStoppingTrack) { | |
| 118 source_provider_.reset(); | |
| 119 | |
| 120 // Stop the audio track. | |
| 121 WebRtcLocalAudioTrack* native_track = static_cast<WebRtcLocalAudioTrack*>( | |
|
perkj_chrome
2014/04/03 07:45:43
Can you make sure this is always the case?
no longer working on chromium
2014/04/03 09:18:57
Yes, we set this up in SetUp() method, otherwise i
perkj_chrome
2014/04/03 09:42:06
I think what I meant was, The sourceProvider shoul
no longer working on chromium
2014/04/03 09:48:20
Yes, it has been the case that track will always o
| |
| 122 MediaStreamTrack::GetTrack(blink_track_)); | |
| 123 native_track->Stop(); | |
| 124 } | |
| 125 | |
| 126 TEST_F(WebRtcLocalAudioSourceProviderTest, | |
| 127 StopTrackBeforeDeletingSourceProvider) { | |
| 128 // Stop the audio track. | |
| 129 WebRtcLocalAudioTrack* native_track = static_cast<WebRtcLocalAudioTrack*>( | |
| 130 MediaStreamTrack::GetTrack(blink_track_)); | |
| 131 native_track->Stop(); | |
| 132 | |
| 133 // Delete the source provider. | |
| 134 source_provider_.reset(); | |
| 135 } | |
| 136 | |
| 94 } // namespace content | 137 } // namespace content |
| OLD | NEW |