Commit 1d008ed4 authored by Antonio Gomes's avatar Antonio Gomes Committed by Commit Bot

Onion soup content/renderer/media/webrtc/webrtc_audio_sink.cc|h

This is part of phase 1.9 on the design document [1].

[1] https://docs.google.com/document/d/1AJKVA5U4nDkyDB9p4ROrggWXadCxyy-grKaE9KS5vOU/

Since there are clients in //content directly referencing to this class,
it was temporarily placed in blink/public/platform.

Also, once its clients get moved to Blink, and so this API, it can
switch over from STL types (std::string and vector) to its WTF
counterparts. TODO is left.

BUG=787254
R=guidou@chromium.org, haraken@chromium.org

Change-Id: I3519318d5ae6f5b3641442f78d5e6116801dbbe9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1778005
Commit-Queue: Antonio Gomes <tonikitoo@igalia.com>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#692180}
parent 0358e021
......@@ -230,8 +230,6 @@ target(link_target_type, "renderer") {
"media/webrtc/transmission_encoding_info_handler.h",
"media/webrtc/video_codec_factory.cc",
"media/webrtc/video_codec_factory.h",
"media/webrtc/webrtc_audio_sink.cc",
"media/webrtc/webrtc_audio_sink.h",
"media/webrtc/webrtc_media_stream_track_adapter.cc",
"media/webrtc/webrtc_media_stream_track_adapter.h",
"media/webrtc/webrtc_media_stream_track_adapter_map.cc",
......@@ -510,7 +508,6 @@ target(link_target_type, "renderer") {
"//third_party/webrtc/p2p:libstunprober",
"//third_party/webrtc/p2p:rtc_p2p",
"//third_party/webrtc/pc:libjingle_peerconnection",
"//third_party/webrtc/pc:peerconnection",
"//third_party/webrtc/pc:rtc_pc",
"//third_party/webrtc/pc:rtc_pc_base",
"//third_party/webrtc/rtc_base:async_resolver_interface",
......
......@@ -164,9 +164,9 @@ void WebRtcMediaStreamTrackAdapter::InitializeLocalAudioTrack(
// the webrtc::AudioSourceInterface, and also do not need references to the
// audio level calculator or audio processor passed to the sink.
webrtc::AudioSourceInterface* source_interface = nullptr;
local_track_audio_sink_.reset(
new WebRtcAudioSink(web_track_.Id().Utf8(), source_interface,
factory_->GetWebRtcSignalingThread(), main_thread_));
local_track_audio_sink_.reset(new blink::WebRtcAudioSink(
web_track_.Id().Utf8(), source_interface,
factory_->GetWebRtcSignalingThread(), main_thread_));
if (auto* media_stream_source = blink::ProcessedLocalAudioSource::From(
blink::MediaStreamAudioSource::From(web_track_.Source()))) {
......
......@@ -11,8 +11,8 @@
#include "base/synchronization/waitable_event.h"
#include "content/common/content_export.h"
#include "content/renderer/media/webrtc/media_stream_video_webrtc_sink.h"
#include "content/renderer/media/webrtc/webrtc_audio_sink.h"
#include "content/renderer/media/webrtc/webrtc_media_stream_track_adapter.h"
#include "third_party/blink/public/platform/modules/peerconnection/webrtc_audio_sink.h"
#include "third_party/blink/public/platform/web_media_stream.h"
#include "third_party/blink/public/platform/web_media_stream_track.h"
#include "third_party/blink/public/web/modules/mediastream/remote_media_stream_track_adapter.h"
......@@ -64,7 +64,7 @@ class CONTENT_EXPORT WebRtcMediaStreamTrackAdapter
bool IsEqual(const blink::WebMediaStreamTrack& web_track);
// For testing.
WebRtcAudioSink* GetLocalTrackAudioSinkForTesting() {
blink::WebRtcAudioSink* GetLocalTrackAudioSinkForTesting() {
return local_track_audio_sink_.get();
}
MediaStreamVideoWebRtcSink* GetLocalTrackVideoSinkForTesting() {
......@@ -126,7 +126,7 @@ class CONTENT_EXPORT WebRtcMediaStreamTrackAdapter
scoped_refptr<webrtc::MediaStreamTrackInterface> webrtc_track_;
// If the track is local, a sink is added to the local webrtc track that is
// owned by us.
std::unique_ptr<WebRtcAudioSink> local_track_audio_sink_;
std::unique_ptr<blink::WebRtcAudioSink> local_track_audio_sink_;
std::unique_ptr<MediaStreamVideoWebRtcSink> local_track_video_sink_;
// If the track is remote, an adapter is used that listens to notifications on
// the remote webrtc track and notifies Blink.
......
......@@ -161,6 +161,7 @@ source_set("blink_headers") {
"platform/modules/peerconnection/two_keys_adapter_map.h",
"platform/modules/peerconnection/web_rtc_video_encoder_factory.h",
"platform/modules/peerconnection/web_rtc_video_frame_adapter_factory.h",
"platform/modules/peerconnection/webrtc_audio_sink.h",
"platform/modules/peerconnection/webrtc_util.h",
"platform/modules/remoteplayback/web_remote_playback_client.h",
"platform/modules/service_worker/web_service_worker_error.h",
......@@ -561,6 +562,7 @@ source_set("blink_headers") {
"//third_party/webrtc/media:rtc_media_base",
"//third_party/webrtc/modules/audio_device:audio_device_api",
"//third_party/webrtc/modules/audio_processing:api",
"//third_party/webrtc/pc:peerconnection",
"//third_party/webrtc/rtc_base:rtc_base",
"//third_party/webrtc/rtc_base:rtc_task_queue",
"//third_party/webrtc_overrides:init_webrtc",
......
include_rules = [
"+media/base/video_codecs.h",
"+media/base/audio_parameters.h",
"+media/base/audio_push_fifo.h",
]
......@@ -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 CONTENT_RENDERER_MEDIA_WEBRTC_WEBRTC_AUDIO_SINK_H_
#define CONTENT_RENDERER_MEDIA_WEBRTC_WEBRTC_AUDIO_SINK_H_
#ifndef THIRD_PARTY_BLINK_PUBLIC_PLATFORM_MODULES_PEERCONNECTION_WEBRTC_AUDIO_SINK_H_
#define THIRD_PARTY_BLINK_PUBLIC_PLATFORM_MODULES_PEERCONNECTION_WEBRTC_AUDIO_SINK_H_
#include <stdint.h>
......@@ -17,17 +17,17 @@
#include "base/single_thread_task_runner.h"
#include "base/synchronization/lock.h"
#include "base/threading/thread_checker.h"
#include "content/common/content_export.h"
#include "media/base/audio_parameters.h"
#include "media/base/audio_push_fifo.h"
#include "third_party/blink/public/platform/modules/mediastream/media_stream_audio_level_calculator.h"
#include "third_party/blink/public/platform/modules/mediastream/web_media_stream_audio_sink.h"
#include "third_party/blink/public/platform/web_common.h"
#include "third_party/webrtc/api/media_stream_interface.h"
#include "third_party/webrtc/pc/media_stream_track.h"
namespace content {
namespace blink {
// Provides an implementation of the blink::WebMediaStreamAudioSink which
// Provides an implementation of the WebMediaStreamAudioSink which
// re-chunks audio data into the 10ms chunks required by WebRTC and then
// delivers the audio to one or more objects implementing the
// webrtc::AudioTrackSinkInterface.
......@@ -36,7 +36,11 @@ namespace content {
// manages one or more "WebRTC sinks" (i.e., instances of
// webrtc::AudioTrackSinkInterface) which are added/removed on the WebRTC
// signaling thread.
class CONTENT_EXPORT WebRtcAudioSink : public blink::WebMediaStreamAudioSink {
//
// TODO(crbug.com/787254): Move this class out of the Blink exposed API when its
// clients get Onion soup'ed. Also, switch away from using std::string and
// std::vector.
class BLINK_PLATFORM_EXPORT WebRtcAudioSink : public WebMediaStreamAudioSink {
public:
WebRtcAudioSink(
const std::string& label,
......@@ -54,8 +58,7 @@ class CONTENT_EXPORT WebRtcAudioSink : public blink::WebMediaStreamAudioSink {
// level. This is passed via the Adapter to libjingle. This method may only
// be called once, before the audio data flow starts, and before any calls to
// Adapter::GetSignalLevel() might be made.
void SetLevel(
scoped_refptr<blink::MediaStreamAudioLevelCalculator::Level> level);
void SetLevel(scoped_refptr<MediaStreamAudioLevelCalculator::Level> level);
// Set the processor that applies signal processing on the data from the
// source. This is passed via the Adapter to libjingle. This method may only
......@@ -89,7 +92,7 @@ class CONTENT_EXPORT WebRtcAudioSink : public blink::WebMediaStreamAudioSink {
audio_processor_ = std::move(processor);
}
void set_level(
scoped_refptr<blink::MediaStreamAudioLevelCalculator::Level> level) {
scoped_refptr<MediaStreamAudioLevelCalculator::Level> level) {
level_ = std::move(level);
}
......@@ -136,7 +139,7 @@ class CONTENT_EXPORT WebRtcAudioSink : public blink::WebMediaStreamAudioSink {
// Thread-safe accessor to current audio signal level. This may be null, if
// not applicable to the current use case. This must be set before calls to
// GetSignalLevel() are made.
scoped_refptr<blink::MediaStreamAudioLevelCalculator::Level> level_;
scoped_refptr<MediaStreamAudioLevelCalculator::Level> level_;
// Lock that protects concurrent access to the |sinks_| list.
base::Lock lock_;
......@@ -148,7 +151,7 @@ class CONTENT_EXPORT WebRtcAudioSink : public blink::WebMediaStreamAudioSink {
DISALLOW_COPY_AND_ASSIGN(Adapter);
};
// blink::WebMediaStreamAudioSink implementation.
// WebMediaStreamAudioSink implementation.
void OnData(const media::AudioBus& audio_bus,
base::TimeTicks estimated_capture_time) override;
void OnSetFormat(const media::AudioParameters& params) override;
......@@ -180,6 +183,6 @@ class CONTENT_EXPORT WebRtcAudioSink : public blink::WebMediaStreamAudioSink {
DISALLOW_COPY_AND_ASSIGN(WebRtcAudioSink);
};
} // namespace content
} // namespace blink
#endif // CONTENT_RENDERER_MEDIA_WEBRTC_WEBRTC_AUDIO_SINK_H_
#endif // THIRD_PARTY_BLINK_PUBLIC_PLATFORM_MODULES_PEERCONNECTION_WEBRTC_AUDIO_SINK_H_
......@@ -1243,6 +1243,7 @@ jumbo_component("platform") {
"peerconnection/rtc_video_encoder.cc",
"peerconnection/rtc_video_encoder.h",
"peerconnection/rtc_void_request.h",
"peerconnection/webrtc_audio_sink.cc",
"prerender.cc",
"prerender.h",
"prerender_client.h",
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/renderer/media/webrtc/webrtc_audio_sink.h"
#include "third_party/blink/public/platform/modules/peerconnection/webrtc_audio_sink.h"
#include <algorithm>
#include <limits>
......@@ -12,10 +12,9 @@
#include "base/location.h"
#include "base/logging.h"
#include "base/stl_util.h"
#include "base/threading/thread_task_runner_handle.h"
#include "third_party/webrtc/rtc_base/ref_counted_object.h"
namespace content {
namespace blink {
WebRtcAudioSink::WebRtcAudioSink(
const std::string& label,
......@@ -45,7 +44,7 @@ void WebRtcAudioSink::SetAudioProcessor(
}
void WebRtcAudioSink::SetLevel(
scoped_refptr<blink::MediaStreamAudioLevelCalculator::Level> level) {
scoped_refptr<MediaStreamAudioLevelCalculator::Level> level) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DCHECK(level.get());
adapter_->set_level(std::move(level));
......@@ -93,8 +92,7 @@ void WebRtcAudioSink::DeliverRebufferedAudio(const media::AudioBus& audio_bus,
audio_bus.ToInterleaved<media::SignedInt16SampleTypeTraits>(
audio_bus.frames(), interleaved_data_.get());
adapter_->DeliverPCMToWebRtcSinks(interleaved_data_.get(),
params_.sample_rate(),
audio_bus.channels(),
params_.sample_rate(), audio_bus.channels(),
audio_bus.frames());
}
......@@ -144,8 +142,8 @@ std::string WebRtcAudioSink::Adapter::kind() const {
bool WebRtcAudioSink::Adapter::set_enabled(bool enable) {
DCHECK(!signaling_task_runner_ ||
signaling_task_runner_->RunsTasksInCurrentSequence());
return webrtc::MediaStreamTrack<webrtc::AudioTrackInterface>::
set_enabled(enable);
return webrtc::MediaStreamTrack<webrtc::AudioTrackInterface>::set_enabled(
enable);
}
void WebRtcAudioSink::Adapter::AddSink(webrtc::AudioTrackSinkInterface* sink) {
......@@ -197,4 +195,4 @@ webrtc::AudioSourceInterface* WebRtcAudioSink::Adapter::GetSource() const {
return source_.get();
}
} // namespace content
} // 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