Commit 3a858b52 authored by Antonio Gomes's avatar Antonio Gomes Committed by Commit Bot

Onion soup media/blink/webaudiosourceprovider_impl.cc

.. as well as its header and unit test.

This is a prepration CL to Onion Soup the remaining bits
in //content/renderer/media_capture_from_element/ (namely
class HtmlAudioElementCapturerSource).

Note that this opens room for some possible follow ups, including

- the rename of the files itself, using the convension in Blink,
  eg web_audio_source_provider_impl.cc|h|test.cc

- considering unifying webaudiosourceprovider_impl.cc|h and
  web_audio_source_provider.h now that they are sibling headers,
  or alternatively rename it to something that indicates it also
  implements media::SwitchableAudioRendererSink.

BUG=787261
R=dalecurtis@chromium.org, guidou@chromium.org, haraken@chromium.org

Change-Id: Ifd1da4e7001f39c1740e2df94d723cbca26f160d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1629948Reviewed-by: default avatarDale Curtis <dalecurtis@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarGuido Urdaneta <guidou@chromium.org>
Commit-Queue: Antonio Gomes <tonikitoo@igalia.com>
Cr-Commit-Position: refs/heads/master@{#665033}
parent 6919166f
......@@ -10,8 +10,8 @@
#include "base/threading/thread_task_runner_handle.h"
#include "media/base/audio_parameters.h"
#include "media/base/audio_renderer_sink.h"
#include "media/blink/webaudiosourceprovider_impl.h"
#include "third_party/blink/public/platform/web_media_player.h"
#include "third_party/blink/public/platform/webaudiosourceprovider_impl.h"
namespace content {
......@@ -22,13 +22,13 @@ HtmlAudioElementCapturerSource::CreateFromWebMediaPlayerImpl(
scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
DCHECK(player);
return new HtmlAudioElementCapturerSource(
static_cast<media::WebAudioSourceProviderImpl*>(
static_cast<blink::WebAudioSourceProviderImpl*>(
player->GetAudioSourceProvider()),
std::move(task_runner));
}
HtmlAudioElementCapturerSource::HtmlAudioElementCapturerSource(
media::WebAudioSourceProviderImpl* audio_source,
blink::WebAudioSourceProviderImpl* audio_source,
scoped_refptr<base::SingleThreadTaskRunner> task_runner)
: blink::MediaStreamAudioSource(std::move(task_runner),
true /* is_local_source */),
......
......@@ -13,11 +13,11 @@
namespace blink {
class WebMediaPlayer;
class WebAudioSourceProviderImpl;
} // namespace blink
namespace media {
class AudioBus;
class WebAudioSourceProviderImpl;
} // namespace media
namespace content {
......@@ -34,7 +34,7 @@ class CONTENT_EXPORT HtmlAudioElementCapturerSource final
scoped_refptr<base::SingleThreadTaskRunner> task_runner);
HtmlAudioElementCapturerSource(
media::WebAudioSourceProviderImpl* audio_source,
blink::WebAudioSourceProviderImpl* audio_source,
scoped_refptr<base::SingleThreadTaskRunner> task_runner);
~HtmlAudioElementCapturerSource() override;
......@@ -49,7 +49,7 @@ class CONTENT_EXPORT HtmlAudioElementCapturerSource final
uint32_t frames_delayed,
int sample_rate);
scoped_refptr<media::WebAudioSourceProviderImpl> audio_source_;
scoped_refptr<blink::WebAudioSourceProviderImpl> audio_source_;
bool is_started_;
int last_sample_rate_;
......
......@@ -11,13 +11,13 @@
#include "media/base/audio_parameters.h"
#include "media/base/fake_audio_render_callback.h"
#include "media/base/media_util.h"
#include "media/blink/webaudiosourceprovider_impl.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/platform/modules/mediastream/media_stream_audio_track.h"
#include "third_party/blink/public/platform/modules/mediastream/web_media_stream_audio_sink.h"
#include "third_party/blink/public/platform/scheduler/test/renderer_scheduler_test_support.h"
#include "third_party/blink/public/platform/web_string.h"
#include "third_party/blink/public/platform/webaudiosourceprovider_impl.h"
#include "third_party/blink/public/web/web_heap.h"
using ::testing::_;
......@@ -63,7 +63,7 @@ class HTMLAudioElementCapturerSourceTest : public testing::Test {
public:
HTMLAudioElementCapturerSourceTest()
: fake_callback_(0.1, kAudioTrackSampleRate),
audio_source_(new media::WebAudioSourceProviderImpl(
audio_source_(new blink::WebAudioSourceProviderImpl(
new media::NullAudioSink(
blink::scheduler::GetSingleThreadTaskRunnerForTesting()),
&media_log_)) {}
......@@ -123,7 +123,7 @@ class HTMLAudioElementCapturerSourceTest : public testing::Test {
media::NullMediaLog media_log_;
media::FakeAudioRenderCallback fake_callback_;
scoped_refptr<media::WebAudioSourceProviderImpl> audio_source_;
scoped_refptr<blink::WebAudioSourceProviderImpl> audio_source_;
};
// Constructs and destructs all objects. This is a non trivial sequence.
......
......@@ -49,8 +49,6 @@ component("blink") {
"watch_time_component.h",
"watch_time_reporter.cc",
"watch_time_reporter.h",
"webaudiosourceprovider_impl.cc",
"webaudiosourceprovider_impl.h",
"webcontentdecryptionmodule_impl.cc",
"webcontentdecryptionmodule_impl.h",
"webcontentdecryptionmoduleaccess_impl.cc",
......@@ -153,7 +151,6 @@ test("media_blink_unittests") {
"video_frame_compositor_unittest.cc",
"watch_time_component_unittest.cc",
"watch_time_reporter_unittest.cc",
"webaudiosourceprovider_impl_unittest.cc",
"webmediaplayer_impl_unittest.cc",
"webmediaplayer_util_unittest.cc",
]
......
......@@ -46,7 +46,6 @@
#include "media/blink/url_index.h"
#include "media/blink/video_decode_stats_reporter.h"
#include "media/blink/watch_time_reporter.h"
#include "media/blink/webaudiosourceprovider_impl.h"
#include "media/blink/webcontentdecryptionmodule_impl.h"
#include "media/blink/webinbandtexttrack_impl.h"
#include "media/blink/webmediaplayer_delegate.h"
......@@ -70,6 +69,7 @@
#include "third_party/blink/public/platform/web_string.h"
#include "third_party/blink/public/platform/web_surface_layer_bridge.h"
#include "third_party/blink/public/platform/web_url.h"
#include "third_party/blink/public/platform/webaudiosourceprovider_impl.h"
#include "third_party/blink/public/web/web_document.h"
#include "third_party/blink/public/web/web_frame.h"
#include "third_party/blink/public/web/web_local_frame.h"
......@@ -94,9 +94,10 @@ namespace media {
namespace {
void SetSinkIdOnMediaThread(scoped_refptr<WebAudioSourceProviderImpl> sink,
const std::string& device_id,
OutputDeviceStatusCB callback) {
void SetSinkIdOnMediaThread(
scoped_refptr<blink::WebAudioSourceProviderImpl> sink,
const std::string& device_id,
OutputDeviceStatusCB callback) {
sink->SwitchOutputDevice(device_id, std::move(callback));
}
......@@ -388,7 +389,7 @@ WebMediaPlayerImpl::WebMediaPlayerImpl(
// TODO(xhwang): When we use an external Renderer, many methods won't work,
// e.g. GetCurrentFrameFromCompositor(). See http://crbug.com/434861
audio_source_provider_ = new WebAudioSourceProviderImpl(
audio_source_provider_ = new blink::WebAudioSourceProviderImpl(
params->audio_renderer_sink(), media_log_.get());
if (observer_)
......
......@@ -52,6 +52,7 @@ namespace blink {
class WebLocalFrame;
class WebMediaPlayerClient;
class WebMediaPlayerEncryptedMediaClient;
class WebAudioSourceProviderImpl;
}
namespace base {
......@@ -78,7 +79,6 @@ class MediaLog;
class UrlIndex;
class VideoFrameCompositor;
class WatchTimeReporter;
class WebAudioSourceProviderImpl;
class WebMediaPlayerDelegate;
// The canonical implementation of blink::WebMediaPlayer that's backed by
......@@ -700,7 +700,7 @@ class MEDIA_BLINK_EXPORT WebMediaPlayerImpl
int64_t last_reported_memory_usage_ = 0;
// Routes audio playback to either AudioRendererSink or WebAudio.
scoped_refptr<WebAudioSourceProviderImpl> audio_source_provider_;
scoped_refptr<blink::WebAudioSourceProviderImpl> audio_source_provider_;
// These two are mutually exclusive:
// |data_source_| is used for regular resource loads.
......
......@@ -355,6 +355,7 @@ source_set("blink_headers") {
"platform/web_video_frame_submitter.h",
"platform/web_viewport_style.h",
"platform/web_worker_fetch_context.h",
"platform/webaudiosourceprovider_impl.h",
"platform/websocket_handshake_throttle.h",
"web/blink.h",
"web/mac/web_substring_util.h",
......
......@@ -23,6 +23,7 @@ include_rules = [
"+build/build_config.h",
"+cc",
"+components/viz/common",
"+media/base/audio_renderer_sink.h",
"+media/base/video_transformation.h",
"+mojo/public",
"+net/cert",
......
......@@ -14,6 +14,7 @@ per-file web_media_player*=mlamouri@chromium.org
# Video SurfaceLayer functionality.
per-file web_video_frame*=file://media/OWNERS
per-file webaudiosourceprovider_impl.h=file://media/OWNERS
per-file web_video_frame*=mlamouri@chromium.org
per-file web_video_frame*=lethalantidote@chromium.org
per-file web_surface_layer_bridge*=file://media/OWNERS
......
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef MEDIA_BLINK_WEBAUDIOSOURCEPROVIDER_IMPL_H_
#define MEDIA_BLINK_WEBAUDIOSOURCEPROVIDER_IMPL_H_
#ifndef THIRD_PARTY_BLINK_PUBLIC_PLATFORM_WEBAUDIOSOURCEPROVIDER_IMPL_H_
#define THIRD_PARTY_BLINK_PUBLIC_PLATFORM_WEBAUDIOSOURCEPROVIDER_IMPL_H_
#include <stddef.h>
......@@ -14,25 +14,25 @@
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/synchronization/lock.h"
#include "base/thread_annotations.h"
#include "media/base/audio_renderer_sink.h"
#include "media/blink/media_blink_export.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/platform/web_audio_source_provider.h"
#include "third_party/blink/public/platform/web_vector.h"
namespace blink {
class WebAudioSourceProviderClient;
}
namespace media {
class MediaLog;
}
namespace blink {
class WebAudioSourceProviderClient;
// WebAudioSourceProviderImpl is either one of two things (but not both):
// - a connection between a RestartableAudioRendererSink (the |sink_|) passed in
// constructor and an AudioRendererSink::RenderCallback passed on Initialize()
// by means of an internal AudioRendererSink::RenderCallback.
// - a connection between the said AudioRendererSink::RenderCallback and a
// blink::WebAudioSourceProviderClient passed via setClient() (the |client_|),
// WebAudioSourceProviderClient passed via setClient() (the |client_|),
// again using the internal AudioRendererSink::RenderCallback. Blink calls
// provideInput() periodically to fetch the appropriate data.
//
......@@ -42,24 +42,26 @@ class MediaLog;
// Pause() etc).
//
// All calls are protected by a lock.
class MEDIA_BLINK_EXPORT WebAudioSourceProviderImpl
: public blink::WebAudioSourceProvider,
public SwitchableAudioRendererSink {
class BLINK_PLATFORM_EXPORT WebAudioSourceProviderImpl
: public WebAudioSourceProvider,
public media::SwitchableAudioRendererSink {
public:
using CopyAudioCB = base::RepeatingCallback<void(std::unique_ptr<AudioBus>,
uint32_t frames_delayed,
int sample_rate)>;
WebAudioSourceProviderImpl(scoped_refptr<SwitchableAudioRendererSink> sink,
MediaLog* media_log);
// blink::WebAudioSourceProvider implementation.
void SetClient(blink::WebAudioSourceProviderClient* client) override;
void ProvideInput(const blink::WebVector<float*>& audio_data,
using CopyAudioCB =
base::RepeatingCallback<void(std::unique_ptr<media::AudioBus>,
uint32_t frames_delayed,
int sample_rate)>;
WebAudioSourceProviderImpl(
scoped_refptr<media::SwitchableAudioRendererSink> sink,
media::MediaLog* media_log);
// WebAudioSourceProvider implementation.
void SetClient(WebAudioSourceProviderClient* client) override;
void ProvideInput(const WebVector<float*>& audio_data,
size_t number_of_frames) override;
// RestartableAudioRendererSink implementation.
void Initialize(const AudioParameters& params,
void Initialize(const media::AudioParameters& params,
RenderCallback* renderer) override;
void Start() override;
void Stop() override;
......@@ -67,18 +69,18 @@ class MEDIA_BLINK_EXPORT WebAudioSourceProviderImpl
void Pause() override;
void Flush() override;
bool SetVolume(double volume) override;
OutputDeviceInfo GetOutputDeviceInfo() override;
media::OutputDeviceInfo GetOutputDeviceInfo() override;
void GetOutputDeviceInfoAsync(OutputDeviceInfoCB info_cb) override;
bool IsOptimizedForHardwareParameters() override;
bool CurrentThreadIsRenderingThread() override;
void SwitchOutputDevice(const std::string& device_id,
OutputDeviceStatusCB callback) override;
media::OutputDeviceStatusCB callback) override;
// These methods allow a client to get a copy of the rendered audio.
void SetCopyAudioCallback(CopyAudioCB callback);
void ClearCopyAudioCallback();
int RenderForTesting(AudioBus* audio_bus);
int RenderForTesting(media::AudioBus* audio_bus);
protected:
~WebAudioSourceProviderImpl() override;
......@@ -99,18 +101,19 @@ class MEDIA_BLINK_EXPORT WebAudioSourceProviderImpl
// Closure that calls OnSetFormat() on |client_| on the renderer thread.
base::Closure set_format_cb_;
// When set via setClient() it overrides |sink_| for consuming audio.
blink::WebAudioSourceProviderClient* client_;
WebAudioSourceProviderClient* client_;
// Where audio ends up unless overridden by |client_|.
base::Lock sink_lock_;
scoped_refptr<SwitchableAudioRendererSink> sink_ GUARDED_BY(sink_lock_);
std::unique_ptr<AudioBus> bus_wrapper_;
scoped_refptr<media::SwitchableAudioRendererSink> sink_
GUARDED_BY(sink_lock_);
std::unique_ptr<media::AudioBus> bus_wrapper_;
// An inner class acting as a T filter where actual data can be tapped.
class TeeFilter;
const std::unique_ptr<TeeFilter> tee_filter_;
MediaLog* const media_log_;
media::MediaLog* const media_log_;
// NOTE: Weak pointers must be invalidated before all other member variables.
base::WeakPtrFactory<WebAudioSourceProviderImpl> weak_factory_;
......@@ -118,6 +121,6 @@ class MEDIA_BLINK_EXPORT WebAudioSourceProviderImpl
DISALLOW_IMPLICIT_CONSTRUCTORS(WebAudioSourceProviderImpl);
};
} // namespace media
} // namespace blink
#endif // MEDIA_BLINK_WEBAUDIOSOURCEPROVIDER_IMPL_H_
#endif // THIRD_PARTY_BLINK_PUBLIC_PLATFORM_WEBAUDIOSOURCEPROVIDER_IMPL_H_
......@@ -1182,6 +1182,7 @@ jumbo_component("platform") {
"mac/local_current_graphics_context.mm",
"mac/web_core_ns_cell_extras.h",
"mac/web_core_ns_cell_extras.mm",
"media/webaudiosourceprovider_impl.cc",
"mediastream/media_stream_center.cc",
"mediastream/media_stream_center.h",
"mediastream/media_stream_component.cc",
......@@ -1747,6 +1748,7 @@ jumbo_source_set("blink_platform_unittests_sources") {
"loader/allowed_by_nosniff_test.cc",
"loader/cors/cors_test.cc",
"mac/graphics_context_canvas_test.mm",
"media/webaudiosourceprovider_impl_test.cc",
"mhtml/mhtml_parser_test.cc",
"mojo/big_string_mojom_traits_test.cc",
"mojo/geometry_struct_traits_test.cc",
......@@ -1810,6 +1812,7 @@ jumbo_source_set("blink_platform_unittests_sources") {
"//base/test:test_support",
"//cc",
"//cc:test_support",
"//media:test_support",
"//mojo/core/embedder",
"//mojo/public/cpp/bindings/tests:for_blink_tests",
"//mojo/public/cpp/test_support:test_utils",
......
include_rules = [
"+media/base/audio_timestamp_helper.h",
"+media/base/bind_to_current_loop.h",
"+media/base/media_log.h",
]
specific_include_rules = {
"webaudiosourceprovider_impl_test.cc": [
"+media/base/audio_parameters.h",
"+media/base/fake_audio_render_callback.h",
"+media/base/media_util.h",
"+media/base/mock_audio_renderer_sink.h",
],
}
......@@ -2,30 +2,25 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "media/blink/webaudiosourceprovider_impl.h"
#include "third_party/blink/public/platform/webaudiosourceprovider_impl.h"
#include <atomic>
#include <utility>
#include <vector>
#include "base/bind.h"
#include "base/callback_helpers.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_macros.h"
#include "base/single_thread_task_runner.h"
#include "base/thread_annotations.h"
#include "base/threading/sequenced_task_runner_handle.h"
#include "base/threading/thread_task_runner_handle.h"
#include "media/base/audio_timestamp_helper.h"
#include "media/base/bind_to_current_loop.h"
#include "media/base/media_log.h"
#include "third_party/blink/public/platform/web_audio_source_provider_client.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
using blink::WebVector;
namespace media {
namespace blink {
namespace {
......@@ -80,7 +75,7 @@ class WebAudioSourceProviderImpl::TeeFilter
int Render(base::TimeDelta delay,
base::TimeTicks delay_timestamp,
int prior_frames_skipped,
AudioBus* dest) override;
media::AudioBus* dest) override;
void OnRenderError() override;
bool initialized() const { return !!renderer_; }
......@@ -108,8 +103,8 @@ class WebAudioSourceProviderImpl::TeeFilter
};
WebAudioSourceProviderImpl::WebAudioSourceProviderImpl(
scoped_refptr<SwitchableAudioRendererSink> sink,
MediaLog* media_log)
scoped_refptr<media::SwitchableAudioRendererSink> sink,
media::MediaLog* media_log)
: volume_(1.0),
state_(kStopped),
client_(nullptr),
......@@ -121,7 +116,7 @@ WebAudioSourceProviderImpl::WebAudioSourceProviderImpl(
WebAudioSourceProviderImpl::~WebAudioSourceProviderImpl() = default;
void WebAudioSourceProviderImpl::SetClient(
blink::WebAudioSourceProviderClient* client) {
WebAudioSourceProviderClient* client) {
// Skip taking the lock if unnecessary. This function is the only setter for
// |client_| so it's safe to check |client_| outside of the lock.
if (client_ == client)
......@@ -141,7 +136,7 @@ void WebAudioSourceProviderImpl::SetClient(
// The client will now take control by calling provideInput() periodically.
client_ = client;
set_format_cb_ = BindToCurrentLoop(base::Bind(
set_format_cb_ = media::BindToCurrentLoop(WTF::BindRepeating(
&WebAudioSourceProviderImpl::OnSetFormat, weak_factory_.GetWeakPtr()));
// If |tee_filter_| is Initialize()d - then run |set_format_cb_| to send
......@@ -163,7 +158,8 @@ void WebAudioSourceProviderImpl::ProvideInput(
size_t number_of_frames) {
if (!bus_wrapper_ ||
static_cast<size_t>(bus_wrapper_->channels()) != audio_data.size()) {
bus_wrapper_ = AudioBus::CreateWrapper(static_cast<int>(audio_data.size()));
bus_wrapper_ =
media::AudioBus::CreateWrapper(static_cast<int>(audio_data.size()));
}
const int incoming_number_of_frames = static_cast<int>(number_of_frames);
......@@ -190,8 +186,9 @@ void WebAudioSourceProviderImpl::ProvideInput(
bus_wrapper_->Scale(volume_);
}
void WebAudioSourceProviderImpl::Initialize(const AudioParameters& params,
RenderCallback* renderer) {
void WebAudioSourceProviderImpl::Initialize(
const media::AudioParameters& params,
RenderCallback* renderer) {
base::AutoLock auto_lock(sink_lock_);
DCHECK_EQ(state_, kStopped);
......@@ -250,9 +247,9 @@ bool WebAudioSourceProviderImpl::SetVolume(double volume) {
return true;
}
OutputDeviceInfo WebAudioSourceProviderImpl::GetOutputDeviceInfo() {
media::OutputDeviceInfo WebAudioSourceProviderImpl::GetOutputDeviceInfo() {
NOTREACHED(); // The blocking API is intentionally not supported.
return OutputDeviceInfo();
return media::OutputDeviceInfo();
}
void WebAudioSourceProviderImpl::GetOutputDeviceInfoAsync(
......@@ -266,9 +263,10 @@ void WebAudioSourceProviderImpl::GetOutputDeviceInfoAsync(
// Just return empty hardware parameters. When a |client_| is attached, the
// underlying audio renderer will prefer the media parameters. See
// IsOptimizedForHardwareParameters() for more details.
base::SequencedTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(std::move(info_cb),
OutputDeviceInfo(OUTPUT_DEVICE_STATUS_OK)));
media::BindToCurrentLoop(
WTF::Bind(std::move(info_cb),
media::OutputDeviceInfo(media::OUTPUT_DEVICE_STATUS_OK)))
.Run();
}
bool WebAudioSourceProviderImpl::IsOptimizedForHardwareParameters() {
......@@ -283,10 +281,10 @@ bool WebAudioSourceProviderImpl::CurrentThreadIsRenderingThread() {
void WebAudioSourceProviderImpl::SwitchOutputDevice(
const std::string& device_id,
OutputDeviceStatusCB callback) {
media::OutputDeviceStatusCB callback) {
base::AutoLock auto_lock(sink_lock_);
if (client_ || !sink_)
std::move(callback).Run(OUTPUT_DEVICE_STATUS_ERROR_INTERNAL);
std::move(callback).Run(media::OUTPUT_DEVICE_STATUS_ERROR_INTERNAL);
else
sink_->SwitchOutputDevice(device_id, std::move(callback));
}
......@@ -300,7 +298,7 @@ void WebAudioSourceProviderImpl::ClearCopyAudioCallback() {
tee_filter_->SetCopyAudioCallback(CopyAudioCB());
}
int WebAudioSourceProviderImpl::RenderForTesting(AudioBus* audio_bus) {
int WebAudioSourceProviderImpl::RenderForTesting(media::AudioBus* audio_bus) {
return tee_filter_->Render(base::TimeDelta(), base::TimeTicks::Now(), 0,
audio_bus);
}
......@@ -318,7 +316,7 @@ int WebAudioSourceProviderImpl::TeeFilter::Render(
base::TimeDelta delay,
base::TimeTicks delay_timestamp,
int prior_frames_skipped,
AudioBus* audio_bus) {
media::AudioBus* audio_bus) {
DCHECK(initialized());
const int num_rendered_frames = renderer_->Render(
......@@ -329,11 +327,12 @@ int WebAudioSourceProviderImpl::TeeFilter::Render(
base::AutoLock auto_lock(copy_lock_);
if (!copy_audio_bus_callback_.is_null()) {
const int64_t frames_delayed =
AudioTimestampHelper::TimeToFrames(delay, sample_rate_);
std::unique_ptr<AudioBus> bus_copy =
AudioBus::Create(audio_bus->channels(), audio_bus->frames());
media::AudioTimestampHelper::TimeToFrames(delay, sample_rate_);
std::unique_ptr<media::AudioBus> bus_copy =
media::AudioBus::Create(audio_bus->channels(), audio_bus->frames());
audio_bus->CopyTo(bus_copy.get());
copy_audio_bus_callback_.Run(std::move(bus_copy), frames_delayed,
copy_audio_bus_callback_.Run(std::move(bus_copy),
static_cast<uint32_t>(frames_delayed),
sample_rate_);
}
}
......@@ -346,4 +345,4 @@ void WebAudioSourceProviderImpl::TeeFilter::OnRenderError() {
renderer_->OnRenderError();
}
} // namespace media
} // namespace blink
......@@ -7,35 +7,35 @@
#include "base/bind.h"
#include "base/macros.h"
#include "base/run_loop.h"
#include "base/test/scoped_task_environment.h"
#include "media/base/audio_parameters.h"
#include "media/base/fake_audio_render_callback.h"
#include "media/base/media_util.h"
#include "media/base/mock_audio_renderer_sink.h"
#include "media/blink/webaudiosourceprovider_impl.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/platform/web_audio_source_provider_client.h"
#include "third_party/blink/public/platform/webaudiosourceprovider_impl.h"
using ::testing::_;
namespace media {
namespace blink {
namespace {
const float kTestVolume = 0.25;
const int kSampleRate = 48000;
} // namespace
class WebAudioSourceProviderImplTest
: public testing::Test,
public blink::WebAudioSourceProviderClient {
class WebAudioSourceProviderImplTest : public testing::Test,
public WebAudioSourceProviderClient {
public:
WebAudioSourceProviderImplTest()
: params_(AudioParameters::AUDIO_PCM_LINEAR,
CHANNEL_LAYOUT_STEREO,
: params_(media::AudioParameters::AUDIO_PCM_LINEAR,
media::CHANNEL_LAYOUT_STEREO,
kSampleRate,
64),
fake_callback_(0.1, kSampleRate),
mock_sink_(new MockAudioRendererSink()),
mock_sink_(new media::MockAudioRendererSink()),
wasp_impl_(new WebAudioSourceProviderImpl(mock_sink_, &media_log_)) {}
virtual ~WebAudioSourceProviderImplTest() = default;
......@@ -61,7 +61,7 @@ class WebAudioSourceProviderImplTest
testing::Mock::VerifyAndClear(mock_sink_.get());
}
void SetClient(blink::WebAudioSourceProviderClient* client) {
void SetClient(WebAudioSourceProviderClient* client) {
testing::InSequence s;
if (client) {
......@@ -75,7 +75,7 @@ class WebAudioSourceProviderImplTest
testing::Mock::VerifyAndClear(this);
}
bool CompareBusses(const AudioBus* bus1, const AudioBus* bus2) {
bool CompareBusses(const media::AudioBus* bus1, const media::AudioBus* bus2) {
EXPECT_EQ(bus1->channels(), bus2->channels());
EXPECT_EQ(bus1->frames(), bus2->frames());
for (int ch = 0; ch < bus1->channels(); ++ch) {
......@@ -87,27 +87,31 @@ class WebAudioSourceProviderImplTest
return true;
}
// blink::WebAudioSourceProviderClient implementation.
// WebAudioSourceProviderClient implementation.
MOCK_METHOD2(SetFormat, void(uint32_t numberOfChannels, float sampleRate));
// CopyAudioCB. Added forwarder method due to GMock troubles with scoped_ptr.
MOCK_METHOD3(DoCopyAudioCB,
void(AudioBus*, uint32_t frames_delayed, int sample_rate));
void OnAudioBus(std::unique_ptr<AudioBus> bus,
void(media::AudioBus*,
uint32_t frames_delayed,
int sample_rate));
void OnAudioBus(std::unique_ptr<media::AudioBus> bus,
uint32_t frames_delayed,
int sample_rate) {
DoCopyAudioCB(bus.get(), frames_delayed, sample_rate);
}
int Render(AudioBus* audio_bus) {
int Render(media::AudioBus* audio_bus) {
return wasp_impl_->RenderForTesting(audio_bus);
}
protected:
AudioParameters params_;
FakeAudioRenderCallback fake_callback_;
NullMediaLog media_log_;
scoped_refptr<MockAudioRendererSink> mock_sink_;
base::test::ScopedTaskEnvironment scoped_task_environment_;
media::AudioParameters params_;
media::FakeAudioRenderCallback fake_callback_;
media::NullMediaLog media_log_;
scoped_refptr<media::MockAudioRendererSink> mock_sink_;
scoped_refptr<WebAudioSourceProviderImpl> wasp_impl_;
DISALLOW_COPY_AND_ASSIGN(WebAudioSourceProviderImplTest);
......@@ -161,11 +165,11 @@ TEST_F(WebAudioSourceProviderImplTest, SinkMethods) {
// Test the AudioRendererSink state machine and its effects on provideInput().
TEST_F(WebAudioSourceProviderImplTest, ProvideInput) {
std::unique_ptr<AudioBus> bus1 = AudioBus::Create(params_);
std::unique_ptr<AudioBus> bus2 = AudioBus::Create(params_);
auto bus1 = media::AudioBus::Create(params_);
auto bus2 = media::AudioBus::Create(params_);
// Point the WebVector into memory owned by |bus1|.
blink::WebVector<float*> audio_data(static_cast<size_t>(bus1->channels()));
WebVector<float*> audio_data(static_cast<size_t>(bus1->channels()));
for (size_t i = 0; i < audio_data.size(); ++i)
audio_data[i] = bus1->channel(static_cast<int>(i));
......@@ -252,7 +256,7 @@ TEST_F(WebAudioSourceProviderImplTest, CopyAudioCB) {
wasp_impl_->SetCopyAudioCallback(base::Bind(
&WebAudioSourceProviderImplTest::OnAudioBus, base::Unretained(this)));
const std::unique_ptr<AudioBus> bus1 = AudioBus::Create(params_);
const auto bus1 = media::AudioBus::Create(params_);
EXPECT_CALL(*this, DoCopyAudioCB(_, 0, params_.sample_rate())).Times(1);
Render(bus1.get());
......@@ -263,4 +267,4 @@ TEST_F(WebAudioSourceProviderImplTest, CopyAudioCB) {
testing::Mock::VerifyAndClear(mock_sink_.get());
}
} // namespace media
} // namespace blink
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment