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.

103 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"
Revert "Add a prefix for objc category." This reverts commit 181ea6e414c5982015ce161e6368120be3658ec4. Reason for revert: Breaks downstream project. Kári will help to land it next week. Original change's description: > Add a prefix for objc category. > > According to the Google Objective-C style [1], category names should > start with an appropriate prefix. WebRTC has some category definitions > for system interfaces, but it doesn't use prefixes. > > $ otool -ov WebRTC.framework/WebRTC | grep -E "^[0-9a-z]{16} 0x[0-9a-z]+ __OBJC_._CATEGORY" | grep -v "_RTC" > 0000000002160840 0x217c3c0 __OBJC_$_CATEGORY_UIDevice_$_H264Profile > 0000000002160850 0x21808b8 __OBJC_$_CATEGORY_AVCaptureSession_$_DevicePosition > 0000000002160858 0x2180968 __OBJC_$_CATEGORY_NSString_$_StdString > 0000000002160860 0x21809c8 __OBJC_$_CATEGORY_NSString_$_AbslStringView > > To avoid conflicts, prefix the names and methods of those categories. > Also remove sdk/objc/Framework/Classes/Common/NSString+StdString.h as > it is not used by any other files. > > [1] https://google.github.io/styleguide/objcguide.html#category-naming > > Bug: webrtc:13884 > Change-Id: I2cf2742af198ab4e0bfb15c0476d72971e50ceee > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/262341 > Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> > Reviewed-by: Kári Helgason <kthelgason@webrtc.org> > Commit-Queue: Daniel.L (Byoungchan) Lee <daniel.l@hpcnt.com> > Reviewed-by: Artem Titov <titovartem@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#36880} Bug: webrtc:13884 Change-Id: I85257088e4a3a62e01ff925ab5e77af83b078ef3 No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/262420 Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> Commit-Queue: Artem Titov <titovartem@webrtc.org> Auto-Submit: Artem Titov <titovartem@webrtc.org> Owners-Override: Artem Titov <titovartem@webrtc.org> Cr-Commit-Position: refs/heads/main@{#36885}
2022-05-13 14:46:42 +00:00
#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 =
rtc::make_ref_counted<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 =
rtc::make_ref_counted<webrtc::StatsCollectorCallbackAdapter>(completionHandler);
self.nativePeerConnection->GetStats(receiver.nativeRtpReceiver, collector);
}
- (void)statisticsWithCompletionHandler:(RTCStatisticsCompletionHandler)completionHandler {
rtc::scoped_refptr<webrtc::StatsCollectorCallbackAdapter> collector =
rtc::make_ref_counted<webrtc::StatsCollectorCallbackAdapter>(completionHandler);
self.nativePeerConnection->GetStats(collector.get());
}
- (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 =
rtc::make_ref_counted<webrtc::StatsObserverAdapter>(completionHandler);
webrtc::PeerConnectionInterface::StatsOutputLevel nativeOutputLevel =
[[self class] nativeStatsOutputLevelForLevel:statsOutputLevel];
self.nativePeerConnection->GetStats(
observer.get(), mediaStreamTrack.nativeTrack.get(), nativeOutputLevel);
}
@end