webrtc_m130/sdk/objc/api/peerconnection/RTCPeerConnection+Stats.mm

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

104 lines
4.0 KiB
Plaintext
Raw Normal View History

/*
* Copyright 2015 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#import "RTCPeerConnection+Private.h"
#import "RTCLegacyStatsReport+Private.h"
#import "RTCMediaStreamTrack+Private.h"
#import "RTCRtpReceiver+Private.h"
#import "RTCRtpSender+Private.h"
#import "RTCStatisticsReport+Private.h"
#import "helpers/NSString+StdString.h"
#include "rtc_base/checks.h"
namespace webrtc {
class StatsCollectorCallbackAdapter : public RTCStatsCollectorCallback {
public:
StatsCollectorCallbackAdapter(RTCStatisticsCompletionHandler completion_handler)
: completion_handler_(completion_handler) {}
void OnStatsDelivered(const rtc::scoped_refptr<const RTCStatsReport> &report) override {
RTC_DCHECK(completion_handler_);
RTC_OBJC_TYPE(RTCStatisticsReport) *statisticsReport =
[[RTC_OBJC_TYPE(RTCStatisticsReport) alloc] initWithReport:*report];
completion_handler_(statisticsReport);
completion_handler_ = nil;
}
private:
RTCStatisticsCompletionHandler completion_handler_;
};
class StatsObserverAdapter : public StatsObserver {
public:
StatsObserverAdapter(
void (^completionHandler)(NSArray<RTC_OBJC_TYPE(RTCLegacyStatsReport) *> *stats)) {
completion_handler_ = completionHandler;
}
~StatsObserverAdapter() override { completion_handler_ = nil; }
Revert of New method StatsObserver::OnCompleteReports, passing ownership. (patchset #2 id:20001 of https://codereview.webrtc.org/2584553002/ ) Reason for revert: The new method doesn't work as intended. It can't pass ownership, because the StatsReports is a vector of raw pointers to StatReport objects owned by the StatsCollector. Original issue's description: > New method StatsObserver::OnCompleteReports, passing ownership. > > The new name, OnCompleteReports rather than OnComplete, is needed > because in C++ method lookup, overriding a method hides all otherwise > inherited methods with the same name, even if they have a different > signature. And here, the intention is that each subclass should > override one or the other of the two methods, and inherit the method it > doesn't override. > > This cl is a prerequisite for > https://codereview.webrtc.org/2567143003/, because the Chrome glue > code needs to retain the stats report after the OnComplete method has > returned. > > Currently, Chrome makes a copy of the stats mapping (which breaks when > changing ValuePtr from an rtc::linked_ptr to an std::unique_ptr). After > this cl, Chrome can be fixed to take ownership and no longer needs to > copy anything, unblocking cl 2567143003. > > BUG=webrtc:6424 > > Review-Url: https://codereview.webrtc.org/2584553002 > Cr-Commit-Position: refs/heads/master@{#15708} > Committed: https://chromium.googlesource.com/external/webrtc/+/b36ee8d498be2fa58fde3f3f3d69a74e4d3b817d TBR=solenberg@webrtc.org,magjed@webrtc.org,tkchin@webrtc.org,hbos@webrtc.org # Not skipping CQ checks because original CL landed more than 1 days ago. BUG=webrtc:6424 Review-Url: https://codereview.webrtc.org/2641783002 Cr-Commit-Position: refs/heads/master@{#16144}
2017-01-18 05:00:34 -08:00
void OnComplete(const StatsReports& reports) override {
RTC_DCHECK(completion_handler_);
Revert of New method StatsObserver::OnCompleteReports, passing ownership. (patchset #2 id:20001 of https://codereview.webrtc.org/2584553002/ ) Reason for revert: The new method doesn't work as intended. It can't pass ownership, because the StatsReports is a vector of raw pointers to StatReport objects owned by the StatsCollector. Original issue's description: > New method StatsObserver::OnCompleteReports, passing ownership. > > The new name, OnCompleteReports rather than OnComplete, is needed > because in C++ method lookup, overriding a method hides all otherwise > inherited methods with the same name, even if they have a different > signature. And here, the intention is that each subclass should > override one or the other of the two methods, and inherit the method it > doesn't override. > > This cl is a prerequisite for > https://codereview.webrtc.org/2567143003/, because the Chrome glue > code needs to retain the stats report after the OnComplete method has > returned. > > Currently, Chrome makes a copy of the stats mapping (which breaks when > changing ValuePtr from an rtc::linked_ptr to an std::unique_ptr). After > this cl, Chrome can be fixed to take ownership and no longer needs to > copy anything, unblocking cl 2567143003. > > BUG=webrtc:6424 > > Review-Url: https://codereview.webrtc.org/2584553002 > Cr-Commit-Position: refs/heads/master@{#15708} > Committed: https://chromium.googlesource.com/external/webrtc/+/b36ee8d498be2fa58fde3f3f3d69a74e4d3b817d TBR=solenberg@webrtc.org,magjed@webrtc.org,tkchin@webrtc.org,hbos@webrtc.org # Not skipping CQ checks because original CL landed more than 1 days ago. BUG=webrtc:6424 Review-Url: https://codereview.webrtc.org/2641783002 Cr-Commit-Position: refs/heads/master@{#16144}
2017-01-18 05:00:34 -08:00
NSMutableArray *stats = [NSMutableArray arrayWithCapacity:reports.size()];
for (const auto* report : reports) {
RTC_OBJC_TYPE(RTCLegacyStatsReport) *statsReport =
[[RTC_OBJC_TYPE(RTCLegacyStatsReport) alloc] initWithNativeReport:*report];
[stats addObject:statsReport];
}
completion_handler_(stats);
completion_handler_ = nil;
}
private:
void (^completion_handler_)(NSArray<RTC_OBJC_TYPE(RTCLegacyStatsReport) *> *stats);
};
} // namespace webrtc
@implementation RTC_OBJC_TYPE (RTCPeerConnection)
(Stats)
- (void)statisticsForSender : (RTC_OBJC_TYPE(RTCRtpSender) *)sender completionHandler
: (RTCStatisticsCompletionHandler)completionHandler {
rtc::scoped_refptr<webrtc::StatsCollectorCallbackAdapter> collector(
new rtc::RefCountedObject<webrtc::StatsCollectorCallbackAdapter>(completionHandler));
self.nativePeerConnection->GetStats(sender.nativeRtpSender, collector);
}
- (void)statisticsForReceiver:(RTC_OBJC_TYPE(RTCRtpReceiver) *)receiver
completionHandler:(RTCStatisticsCompletionHandler)completionHandler {
rtc::scoped_refptr<webrtc::StatsCollectorCallbackAdapter> collector(
new rtc::RefCountedObject<webrtc::StatsCollectorCallbackAdapter>(completionHandler));
self.nativePeerConnection->GetStats(receiver.nativeRtpReceiver, collector);
}
- (void)statisticsWithCompletionHandler:(RTCStatisticsCompletionHandler)completionHandler {
rtc::scoped_refptr<webrtc::StatsCollectorCallbackAdapter> collector(
new rtc::RefCountedObject<webrtc::StatsCollectorCallbackAdapter>(completionHandler));
self.nativePeerConnection->GetStats(collector);
}
- (void)statsForTrack:(RTC_OBJC_TYPE(RTCMediaStreamTrack) *)mediaStreamTrack
statsOutputLevel:(RTCStatsOutputLevel)statsOutputLevel
completionHandler:
(void (^)(NSArray<RTC_OBJC_TYPE(RTCLegacyStatsReport) *> *stats))completionHandler {
rtc::scoped_refptr<webrtc::StatsObserverAdapter> observer(
new rtc::RefCountedObject<webrtc::StatsObserverAdapter>
(completionHandler));
webrtc::PeerConnectionInterface::StatsOutputLevel nativeOutputLevel =
[[self class] nativeStatsOutputLevelForLevel:statsOutputLevel];
self.nativePeerConnection->GetStats(
observer, mediaStreamTrack.nativeTrack, nativeOutputLevel);
}
@end