Commit 12fa8b73 authored by Henrik Boström's avatar Henrik Boström Committed by Commit Bot

Preparation CL for getStats() with selector argument.

Mostly moving things around, refactoring...

1. Move GetRTCStatsCallback from rtc_peer_connection_handler.cc to
   rtc_stats.[h/cc] where other blink/webrtc stats-related content-glue
   is placed, and rename it RTCStatsCollectorCallbackImpl.

   This allows it to be used by content's RTCRtpSender and
   RTCRtpReceiver in follow-up CLs.

2. Remove unused content::RTCRtpSender-constructor.

3. Move WebRTCStatsReportCallbackResolver from RTCPeerConnection.cpp
   to its own file.

   This allows it to be used by blink's RTCRtpSender and RTCRtpReceiver
   in follow-up CLs.

4. Implement new PeerConnectionInterface::GetStats() functions in
   MockPeerConnectionImpl (need to wait for
   https://webrtc-review.googlesource.com/c/src/+/62900 to land and roll
   into chromium).

Bug: 680172
Change-Id: Ief18b2fb96ebc292149af606bd0edd87bac9e961
Reviewed-on: https://chromium-review.googlesource.com/973368
Commit-Queue: Henrik Boström <hbos@chromium.org>
Reviewed-by: default avatarGuido Urdaneta <guidou@chromium.org>
Cr-Commit-Position: refs/heads/master@{#546101}
parent 7a7ae0b2
...@@ -398,6 +398,18 @@ void MockPeerConnectionImpl::GetStats( ...@@ -398,6 +398,18 @@ void MockPeerConnectionImpl::GetStats(
callback->OnStatsDelivered(stats_report_); callback->OnStatsDelivered(stats_report_);
} }
void MockPeerConnectionImpl::GetStats(
rtc::scoped_refptr<webrtc::RtpSenderInterface> selector,
rtc::scoped_refptr<webrtc::RTCStatsCollectorCallback> callback) {
callback->OnStatsDelivered(stats_report_);
}
void MockPeerConnectionImpl::GetStats(
rtc::scoped_refptr<webrtc::RtpReceiverInterface> selector,
rtc::scoped_refptr<webrtc::RTCStatsCollectorCallback> callback) {
callback->OnStatsDelivered(stats_report_);
}
void MockPeerConnectionImpl::SetGetStatsReport(webrtc::RTCStatsReport* report) { void MockPeerConnectionImpl::SetGetStatsReport(webrtc::RTCStatsReport* report) {
stats_report_ = report; stats_report_ = report;
} }
......
...@@ -103,6 +103,12 @@ class MockPeerConnectionImpl : public webrtc::PeerConnectionInterface { ...@@ -103,6 +103,12 @@ class MockPeerConnectionImpl : public webrtc::PeerConnectionInterface {
webrtc::MediaStreamTrackInterface* track, webrtc::MediaStreamTrackInterface* track,
StatsOutputLevel level) override; StatsOutputLevel level) override;
void GetStats(webrtc::RTCStatsCollectorCallback* callback) override; void GetStats(webrtc::RTCStatsCollectorCallback* callback) override;
void GetStats(
rtc::scoped_refptr<webrtc::RtpSenderInterface> selector,
rtc::scoped_refptr<webrtc::RTCStatsCollectorCallback> callback) override;
void GetStats(
rtc::scoped_refptr<webrtc::RtpReceiverInterface> selector,
rtc::scoped_refptr<webrtc::RTCStatsCollectorCallback> callback) override;
// Call this function to make sure next call to legacy GetStats fail. // Call this function to make sure next call to legacy GetStats fail.
void SetGetStatsResult(bool result) { getstats_result_ = result; } void SetGetStatsResult(bool result) { getstats_result_ = result; }
......
...@@ -698,52 +698,6 @@ void GetStatsOnSignalingThread( ...@@ -698,52 +698,6 @@ void GetStatsOnSignalingThread(
} }
} }
// A stats collector callback.
// It is invoked on the WebRTC signaling thread and will post a task to invoke
// |callback| on the thread given in the |main_thread| argument.
// The argument to the callback will be a |blink::WebRTCStatsReport|.
class GetRTCStatsCallback : public webrtc::RTCStatsCollectorCallback {
public:
static rtc::scoped_refptr<GetRTCStatsCallback> Create(
const scoped_refptr<base::SingleThreadTaskRunner>& main_thread,
std::unique_ptr<blink::WebRTCStatsReportCallback> callback) {
return rtc::scoped_refptr<GetRTCStatsCallback>(
new rtc::RefCountedObject<GetRTCStatsCallback>(
main_thread, callback.release()));
}
void OnStatsDelivered(
const rtc::scoped_refptr<const webrtc::RTCStatsReport>& report) override {
main_thread_->PostTask(
FROM_HERE,
base::BindOnce(&GetRTCStatsCallback::OnStatsDeliveredOnMainThread, this,
report));
}
protected:
GetRTCStatsCallback(
const scoped_refptr<base::SingleThreadTaskRunner>& main_thread,
blink::WebRTCStatsReportCallback* callback)
: main_thread_(main_thread),
callback_(callback) {
}
~GetRTCStatsCallback() override { DCHECK(!callback_); }
void OnStatsDeliveredOnMainThread(
const rtc::scoped_refptr<const webrtc::RTCStatsReport>& report) {
DCHECK(main_thread_->BelongsToCurrentThread());
DCHECK(report);
DCHECK(callback_);
callback_->OnStatsDelivered(std::unique_ptr<blink::WebRTCStatsReport>(
new RTCStatsReport(base::WrapRefCounted(report.get()))));
// Make sure the callback is destroyed in the main thread as well.
callback_.reset();
}
const scoped_refptr<base::SingleThreadTaskRunner> main_thread_;
std::unique_ptr<blink::WebRTCStatsReportCallback> callback_;
};
void GetRTCStatsOnSignalingThread( void GetRTCStatsOnSignalingThread(
const scoped_refptr<base::SingleThreadTaskRunner>& main_thread, const scoped_refptr<base::SingleThreadTaskRunner>& main_thread,
scoped_refptr<webrtc::PeerConnectionInterface> native_peer_connection, scoped_refptr<webrtc::PeerConnectionInterface> native_peer_connection,
...@@ -751,7 +705,7 @@ void GetRTCStatsOnSignalingThread( ...@@ -751,7 +705,7 @@ void GetRTCStatsOnSignalingThread(
TRACE_EVENT0("webrtc", "GetRTCStatsOnSignalingThread"); TRACE_EVENT0("webrtc", "GetRTCStatsOnSignalingThread");
native_peer_connection->GetStats( native_peer_connection->GetStats(
GetRTCStatsCallback::Create(main_thread, std::move(callback))); RTCStatsCollectorCallbackImpl::Create(main_thread, std::move(callback)));
} }
class PeerConnectionUMAObserver : public webrtc::UMAObserver { class PeerConnectionUMAObserver : public webrtc::UMAObserver {
......
...@@ -201,21 +201,6 @@ RTCRtpSender::RTCRtpSender( ...@@ -201,21 +201,6 @@ RTCRtpSender::RTCRtpSender(
std::move(web_track), std::move(web_track),
std::move(web_streams))) {} std::move(web_streams))) {}
RTCRtpSender::RTCRtpSender(
scoped_refptr<base::SingleThreadTaskRunner> main_thread,
scoped_refptr<base::SingleThreadTaskRunner> signaling_thread,
scoped_refptr<WebRtcMediaStreamAdapterMap> stream_map,
rtc::scoped_refptr<webrtc::RtpSenderInterface> webrtc_sender,
std::unique_ptr<WebRtcMediaStreamTrackAdapterMap::AdapterRef> track_ref)
: RTCRtpSender(
std::move(main_thread),
std::move(signaling_thread),
std::move(stream_map),
std::move(webrtc_sender),
std::move(track_ref),
std::vector<
std::unique_ptr<WebRtcMediaStreamAdapterMap::AdapterRef>>()) {}
RTCRtpSender::RTCRtpSender( RTCRtpSender::RTCRtpSender(
scoped_refptr<base::SingleThreadTaskRunner> main_thread, scoped_refptr<base::SingleThreadTaskRunner> main_thread,
scoped_refptr<base::SingleThreadTaskRunner> signaling_thread, scoped_refptr<base::SingleThreadTaskRunner> signaling_thread,
......
...@@ -33,15 +33,6 @@ class CONTENT_EXPORT RTCRtpSender : public blink::WebRTCRtpSender { ...@@ -33,15 +33,6 @@ class CONTENT_EXPORT RTCRtpSender : public blink::WebRTCRtpSender {
rtc::scoped_refptr<webrtc::RtpSenderInterface> webrtc_sender, rtc::scoped_refptr<webrtc::RtpSenderInterface> webrtc_sender,
blink::WebMediaStreamTrack web_track, blink::WebMediaStreamTrack web_track,
std::vector<blink::WebMediaStream> web_streams); std::vector<blink::WebMediaStream> web_streams);
// TODO(hbos): Remove these in favor of the above constructor that creates the
// corresponding adapter refs. They won't be needed after
// https://crbug.com/738929.
RTCRtpSender(
scoped_refptr<base::SingleThreadTaskRunner> main_thread,
scoped_refptr<base::SingleThreadTaskRunner> signaling_thread,
scoped_refptr<WebRtcMediaStreamAdapterMap> stream_map,
rtc::scoped_refptr<webrtc::RtpSenderInterface> webrtc_sender,
std::unique_ptr<WebRtcMediaStreamTrackAdapterMap::AdapterRef> track_ref);
RTCRtpSender( RTCRtpSender(
scoped_refptr<base::SingleThreadTaskRunner> main_thread, scoped_refptr<base::SingleThreadTaskRunner> main_thread,
scoped_refptr<base::SingleThreadTaskRunner> signaling_thread, scoped_refptr<base::SingleThreadTaskRunner> signaling_thread,
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <set> #include <set>
#include <string> #include <string>
#include "base/bind.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "third_party/webrtc/api/stats/rtcstats_objects.h" #include "third_party/webrtc/api/stats/rtcstats_objects.h"
...@@ -280,6 +281,45 @@ blink::WebVector<blink::WebString> RTCStatsMember::ValueSequenceString() const { ...@@ -280,6 +281,45 @@ blink::WebVector<blink::WebString> RTCStatsMember::ValueSequenceString() const {
return web_sequence; return web_sequence;
} }
// static
rtc::scoped_refptr<RTCStatsCollectorCallbackImpl>
RTCStatsCollectorCallbackImpl::Create(
scoped_refptr<base::SingleThreadTaskRunner> main_thread,
std::unique_ptr<blink::WebRTCStatsReportCallback> callback) {
return rtc::scoped_refptr<RTCStatsCollectorCallbackImpl>(
new rtc::RefCountedObject<RTCStatsCollectorCallbackImpl>(
std::move(main_thread), callback.release()));
}
RTCStatsCollectorCallbackImpl::RTCStatsCollectorCallbackImpl(
scoped_refptr<base::SingleThreadTaskRunner> main_thread,
blink::WebRTCStatsReportCallback* callback)
: main_thread_(std::move(main_thread)), callback_(callback) {}
RTCStatsCollectorCallbackImpl::~RTCStatsCollectorCallbackImpl() {
DCHECK(!callback_);
}
void RTCStatsCollectorCallbackImpl::OnStatsDelivered(
const rtc::scoped_refptr<const webrtc::RTCStatsReport>& report) {
main_thread_->PostTask(
FROM_HERE,
base::BindOnce(
&RTCStatsCollectorCallbackImpl::OnStatsDeliveredOnMainThread, this,
report));
}
void RTCStatsCollectorCallbackImpl::OnStatsDeliveredOnMainThread(
rtc::scoped_refptr<const webrtc::RTCStatsReport> report) {
DCHECK(main_thread_->BelongsToCurrentThread());
DCHECK(report);
DCHECK(callback_);
callback_->OnStatsDelivered(std::unique_ptr<blink::WebRTCStatsReport>(
new RTCStatsReport(base::WrapRefCounted(report.get()))));
// Make sure the callback is destroyed in the main thread as well.
callback_.reset();
}
void WhitelistStatsForTesting(const char* type) { void WhitelistStatsForTesting(const char* type) {
GetStatsWhitelist()->WhitelistStatsForTesting(type); GetStatsWhitelist()->WhitelistStatsForTesting(type);
} }
......
...@@ -6,9 +6,11 @@ ...@@ -6,9 +6,11 @@
#define CONTENT_RENDERER_MEDIA_WEBRTC_RTC_STATS_H_ #define CONTENT_RENDERER_MEDIA_WEBRTC_RTC_STATS_H_
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/single_thread_task_runner.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "third_party/WebKit/public/platform/WebRTCStats.h" #include "third_party/WebKit/public/platform/WebRTCStats.h"
#include "third_party/webrtc/api/stats/rtcstats.h" #include "third_party/webrtc/api/stats/rtcstats.h"
#include "third_party/webrtc/api/stats/rtcstatscollectorcallback.h"
#include "third_party/webrtc/api/stats/rtcstatsreport.h" #include "third_party/webrtc/api/stats/rtcstatsreport.h"
namespace content { namespace content {
...@@ -85,6 +87,32 @@ class CONTENT_EXPORT RTCStatsMember : public blink::WebRTCStatsMember { ...@@ -85,6 +87,32 @@ class CONTENT_EXPORT RTCStatsMember : public blink::WebRTCStatsMember {
const webrtc::RTCStatsMemberInterface* const member_; const webrtc::RTCStatsMemberInterface* const member_;
}; };
// A stats collector callback.
// It is invoked on the WebRTC signaling thread and will post a task to invoke
// |callback| on the thread given in the |main_thread| argument.
// The argument to the callback will be a |blink::WebRTCStatsReport|.
class RTCStatsCollectorCallbackImpl : public webrtc::RTCStatsCollectorCallback {
public:
static rtc::scoped_refptr<RTCStatsCollectorCallbackImpl> Create(
scoped_refptr<base::SingleThreadTaskRunner> main_thread,
std::unique_ptr<blink::WebRTCStatsReportCallback> callback);
void OnStatsDelivered(
const rtc::scoped_refptr<const webrtc::RTCStatsReport>& report) override;
protected:
RTCStatsCollectorCallbackImpl(
scoped_refptr<base::SingleThreadTaskRunner> main_thread,
blink::WebRTCStatsReportCallback* callback);
~RTCStatsCollectorCallbackImpl() override;
void OnStatsDeliveredOnMainThread(
rtc::scoped_refptr<const webrtc::RTCStatsReport> report);
const scoped_refptr<base::SingleThreadTaskRunner> main_thread_;
std::unique_ptr<blink::WebRTCStatsReportCallback> callback_;
};
CONTENT_EXPORT void WhitelistStatsForTesting(const char* type); CONTENT_EXPORT void WhitelistStatsForTesting(const char* type);
} // namespace content } // namespace content
......
...@@ -50,5 +50,7 @@ blink_modules_sources("peerconnection") { ...@@ -50,5 +50,7 @@ blink_modules_sources("peerconnection") {
"RTCVoidRequestImpl.h", "RTCVoidRequestImpl.h",
"RTCVoidRequestPromiseImpl.cpp", "RTCVoidRequestPromiseImpl.cpp",
"RTCVoidRequestPromiseImpl.h", "RTCVoidRequestPromiseImpl.h",
"WebRTCStatsReportCallbackResolver.cpp",
"WebRTCStatsReportCallbackResolver.h",
] ]
} }
...@@ -83,6 +83,7 @@ ...@@ -83,6 +83,7 @@
#include "modules/peerconnection/RTCTrackEvent.h" #include "modules/peerconnection/RTCTrackEvent.h"
#include "modules/peerconnection/RTCVoidRequestImpl.h" #include "modules/peerconnection/RTCVoidRequestImpl.h"
#include "modules/peerconnection/RTCVoidRequestPromiseImpl.h" #include "modules/peerconnection/RTCVoidRequestPromiseImpl.h"
#include "modules/peerconnection/WebRTCStatsReportCallbackResolver.h"
#include "modules/peerconnection/testing/InternalsRTCPeerConnection.h" #include "modules/peerconnection/testing/InternalsRTCPeerConnection.h"
#include "platform/InstanceCounters.h" #include "platform/InstanceCounters.h"
#include "platform/bindings/Microtask.h" #include "platform/bindings/Microtask.h"
...@@ -416,35 +417,6 @@ RTCOfferOptionsPlatform* ParseOfferOptions(const Dictionary& options, ...@@ -416,35 +417,6 @@ RTCOfferOptionsPlatform* ParseOfferOptions(const Dictionary& options,
return rtc_offer_options; return rtc_offer_options;
} }
// Helper class for
// |RTCPeerConnection::getStats(ScriptState*, MediaStreamTrack*)|
class WebRTCStatsReportCallbackResolver : public WebRTCStatsReportCallback {
public:
// Takes ownership of |resolver|.
static std::unique_ptr<WebRTCStatsReportCallback> Create(
ScriptPromiseResolver* resolver) {
return std::unique_ptr<WebRTCStatsReportCallback>(
new WebRTCStatsReportCallbackResolver(resolver));
}
~WebRTCStatsReportCallbackResolver() override {
DCHECK(
ExecutionContext::From(resolver_->GetScriptState())->IsContextThread());
}
private:
explicit WebRTCStatsReportCallbackResolver(ScriptPromiseResolver* resolver)
: resolver_(resolver) {}
void OnStatsDelivered(std::unique_ptr<WebRTCStatsReport> report) override {
DCHECK(
ExecutionContext::From(resolver_->GetScriptState())->IsContextThread());
resolver_->Resolve(new RTCStatsReport(std::move(report)));
}
Persistent<ScriptPromiseResolver> resolver_;
};
bool FingerprintMismatch(String old_sdp, String new_sdp) { bool FingerprintMismatch(String old_sdp, String new_sdp) {
// Check special case of externally generated SDP without fingerprints. // Check special case of externally generated SDP without fingerprints.
// It's impossible to generate a valid fingerprint without createOffer // It's impossible to generate a valid fingerprint without createOffer
......
#include "modules/peerconnection/WebRTCStatsReportCallbackResolver.h"
#include "core/dom/ExecutionContext.h"
namespace blink {
// static
std::unique_ptr<WebRTCStatsReportCallback>
WebRTCStatsReportCallbackResolver::Create(ScriptPromiseResolver* resolver) {
return std::unique_ptr<WebRTCStatsReportCallback>(
new WebRTCStatsReportCallbackResolver(resolver));
}
WebRTCStatsReportCallbackResolver::WebRTCStatsReportCallbackResolver(
ScriptPromiseResolver* resolver)
: resolver_(resolver) {}
WebRTCStatsReportCallbackResolver::~WebRTCStatsReportCallbackResolver() {
DCHECK(
ExecutionContext::From(resolver_->GetScriptState())->IsContextThread());
}
void WebRTCStatsReportCallbackResolver::OnStatsDelivered(
std::unique_ptr<WebRTCStatsReport> report) {
DCHECK(
ExecutionContext::From(resolver_->GetScriptState())->IsContextThread());
resolver_->Resolve(new RTCStatsReport(std::move(report)));
}
} // namespace blink
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef WebRTCStatsReportCallbackResolver_h
#define WebRTCStatsReportCallbackResolver_h
#include <memory>
#include "bindings/core/v8/ScriptPromiseResolver.h"
#include "modules/peerconnection/RTCStatsReport.h"
#include "public/platform/WebRTCStats.h"
namespace blink {
class WebRTCStatsReportCallbackResolver : public WebRTCStatsReportCallback {
public:
// Takes ownership of |resolver|.
static std::unique_ptr<WebRTCStatsReportCallback> Create(
ScriptPromiseResolver*);
~WebRTCStatsReportCallbackResolver() override;
private:
explicit WebRTCStatsReportCallbackResolver(ScriptPromiseResolver*);
void OnStatsDelivered(std::unique_ptr<WebRTCStatsReport>) override;
Persistent<ScriptPromiseResolver> resolver_;
};
} // namespace blink
#endif // WebRTCStatsReportCallbackResolver_h
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