2013-07-10 00:45:36 +00:00
|
|
|
/*
|
2016-02-10 07:54:43 -08:00
|
|
|
* Copyright 2012 The WebRTC project authors. All Rights Reserved.
|
2013-07-10 00:45:36 +00:00
|
|
|
*
|
2016-02-10 07:54:43 -08:00
|
|
|
* 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.
|
2013-07-10 00:45:36 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// This file contains a class used for gathering statistics from an ongoing
|
|
|
|
|
// libjingle PeerConnection.
|
|
|
|
|
|
2016-02-10 10:53:12 +01:00
|
|
|
#ifndef WEBRTC_API_STATSCOLLECTOR_H_
|
|
|
|
|
#define WEBRTC_API_STATSCOLLECTOR_H_
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
#include <map>
|
2014-03-03 18:30:11 +00:00
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2016-02-10 10:53:12 +01:00
|
|
|
#include "webrtc/api/mediastreaminterface.h"
|
|
|
|
|
#include "webrtc/api/peerconnectioninterface.h"
|
|
|
|
|
#include "webrtc/api/statstypes.h"
|
|
|
|
|
#include "webrtc/api/webrtcsession.h"
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
2015-10-14 11:33:11 -07:00
|
|
|
class PeerConnection;
|
|
|
|
|
|
2014-12-16 23:01:31 +00:00
|
|
|
// Conversion function to convert candidate type string to the corresponding one
|
|
|
|
|
// from enum RTCStatsIceCandidateType.
|
|
|
|
|
const char* IceCandidateTypeToStatsType(const std::string& candidate_type);
|
|
|
|
|
|
|
|
|
|
// Conversion function to convert adapter type to report string which are more
|
|
|
|
|
// fitting to the general style of http://w3c.github.io/webrtc-stats. This is
|
|
|
|
|
// only used by stats collector.
|
|
|
|
|
const char* AdapterTypeToStatsType(rtc::AdapterType type);
|
|
|
|
|
|
2015-06-22 15:06:43 -07:00
|
|
|
// A mapping between track ids and their StatsReport.
|
|
|
|
|
typedef std::map<std::string, StatsReport*> TrackIdMap;
|
|
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
class StatsCollector {
|
|
|
|
|
public:
|
2015-10-14 11:33:11 -07:00
|
|
|
// The caller is responsible for ensuring that the pc outlives the
|
2014-07-14 20:15:26 +00:00
|
|
|
// StatsCollector instance.
|
2015-10-14 11:33:11 -07:00
|
|
|
explicit StatsCollector(PeerConnection* pc);
|
2014-07-14 20:15:26 +00:00
|
|
|
virtual ~StatsCollector();
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
// Adds a MediaStream with tracks that can be used as a |selector| in a call
|
|
|
|
|
// to GetStats.
|
|
|
|
|
void AddStream(MediaStreamInterface* stream);
|
|
|
|
|
|
2014-03-03 18:30:11 +00:00
|
|
|
// Adds a local audio track that is used for getting some voice statistics.
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
void AddLocalAudioTrack(AudioTrackInterface* audio_track, uint32_t ssrc);
|
2014-03-03 18:30:11 +00:00
|
|
|
|
|
|
|
|
// Removes a local audio tracks that is used for getting some voice
|
|
|
|
|
// statistics.
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
void RemoveLocalAudioTrack(AudioTrackInterface* audio_track, uint32_t ssrc);
|
2014-03-03 18:30:11 +00:00
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
// Gather statistics from the session and store them for future use.
|
2014-02-13 23:18:49 +00:00
|
|
|
void UpdateStats(PeerConnectionInterface::StatsOutputLevel level);
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
// Gets a StatsReports of the last collected stats. Note that UpdateStats must
|
|
|
|
|
// be called before this function to get the most recent stats. |selector| is
|
|
|
|
|
// a track label or empty string. The most recent reports are stored in
|
|
|
|
|
// |reports|.
|
2014-08-15 08:38:30 +00:00
|
|
|
// TODO(tommi): Change this contract to accept a callback object instead
|
|
|
|
|
// of filling in |reports|. As is, there's a requirement that the caller
|
|
|
|
|
// uses |reports| immediately without allowing any async activity on
|
|
|
|
|
// the thread (message handling etc) and then discard the results.
|
|
|
|
|
void GetStats(MediaStreamTrackInterface* track,
|
2014-02-13 23:18:49 +00:00
|
|
|
StatsReports* reports);
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2015-01-21 11:36:18 +00:00
|
|
|
// Prepare a local or remote SSRC report for the given ssrc. Used internally
|
2013-10-25 21:18:33 +00:00
|
|
|
// in the ExtractStatsFromList template.
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
StatsReport* PrepareReport(bool local,
|
|
|
|
|
uint32_t ssrc,
|
|
|
|
|
const StatsReport::Id& transport_id,
|
|
|
|
|
StatsReport::Direction direction);
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2014-07-09 07:38:38 +00:00
|
|
|
// Method used by the unittest to force a update of stats since UpdateStats()
|
|
|
|
|
// that occur less than kMinGatherStatsPeriod number of ms apart will be
|
|
|
|
|
// ignored.
|
2014-12-15 09:44:48 +00:00
|
|
|
void ClearUpdateStatsCacheForTest();
|
2014-07-09 07:38:38 +00:00
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
private:
|
2014-12-16 23:01:31 +00:00
|
|
|
friend class StatsCollectorTest;
|
|
|
|
|
|
2015-02-03 22:09:37 +00:00
|
|
|
// Overridden in unit tests to fake timing.
|
|
|
|
|
virtual double GetTimeNow();
|
|
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
bool CopySelectedReports(const std::string& selector, StatsReports* reports);
|
|
|
|
|
|
2013-10-09 15:37:36 +00:00
|
|
|
// Helper method for AddCertificateReports.
|
2015-03-12 16:35:55 +00:00
|
|
|
StatsReport* AddOneCertificateReport(
|
|
|
|
|
const rtc::SSLCertificate* cert, const StatsReport* issuer);
|
2013-10-09 15:37:36 +00:00
|
|
|
|
2014-12-16 23:01:31 +00:00
|
|
|
// Helper method for creating IceCandidate report. |is_local| indicates
|
|
|
|
|
// whether this candidate is local or remote.
|
2015-03-12 16:35:55 +00:00
|
|
|
StatsReport* AddCandidateReport(const cricket::Candidate& candidate,
|
|
|
|
|
bool local);
|
2014-12-16 23:01:31 +00:00
|
|
|
|
2013-10-09 15:37:36 +00:00
|
|
|
// Adds a report for this certificate and every certificate in its chain, and
|
2015-03-12 16:35:55 +00:00
|
|
|
// returns the leaf certificate's report.
|
|
|
|
|
StatsReport* AddCertificateReports(const rtc::SSLCertificate* cert);
|
|
|
|
|
|
|
|
|
|
StatsReport* AddConnectionInfoReport(const std::string& content_name,
|
|
|
|
|
int component, int connection_id,
|
|
|
|
|
const StatsReport::Id& channel_report_id,
|
|
|
|
|
const cricket::ConnectionInfo& info);
|
2013-10-09 15:37:36 +00:00
|
|
|
|
2015-01-15 22:55:07 +00:00
|
|
|
void ExtractDataInfo();
|
2013-07-10 00:45:36 +00:00
|
|
|
void ExtractSessionInfo();
|
|
|
|
|
void ExtractVoiceInfo();
|
2014-02-13 23:18:49 +00:00
|
|
|
void ExtractVideoInfo(PeerConnectionInterface::StatsOutputLevel level);
|
2016-04-01 01:10:42 -07:00
|
|
|
void ExtractSenderInfo();
|
2013-07-10 00:45:36 +00:00
|
|
|
void BuildSsrcToTransportId();
|
2015-01-21 11:36:18 +00:00
|
|
|
webrtc::StatsReport* GetReport(const StatsReport::StatsType& type,
|
2014-06-12 14:57:05 +00:00
|
|
|
const std::string& id,
|
2015-01-21 11:36:18 +00:00
|
|
|
StatsReport::Direction direction);
|
2014-03-03 18:30:11 +00:00
|
|
|
|
|
|
|
|
// Helper method to get stats from the local audio tracks.
|
|
|
|
|
void UpdateStatsFromExistingLocalAudioTracks();
|
|
|
|
|
void UpdateReportFromAudioTrack(AudioTrackInterface* track,
|
|
|
|
|
StatsReport* report);
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2014-06-12 14:57:05 +00:00
|
|
|
// Helper method to get the id for the track identified by ssrc.
|
|
|
|
|
// |direction| tells if the track is for sending or receiving.
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
bool GetTrackIdBySsrc(uint32_t ssrc,
|
|
|
|
|
std::string* track_id,
|
2015-01-21 11:36:18 +00:00
|
|
|
StatsReport::Direction direction);
|
2014-06-12 14:57:05 +00:00
|
|
|
|
2015-06-22 15:06:43 -07:00
|
|
|
// Helper method to update the timestamp of track records.
|
|
|
|
|
void UpdateTrackReports();
|
|
|
|
|
|
2015-01-21 11:36:18 +00:00
|
|
|
// A collection for all of our stats reports.
|
|
|
|
|
StatsCollection reports_;
|
2015-06-22 15:06:43 -07:00
|
|
|
TrackIdMap track_ids_;
|
2015-10-14 11:33:11 -07:00
|
|
|
// Raw pointer to the peer connection the statistics are gathered from.
|
|
|
|
|
PeerConnection* const pc_;
|
2013-07-10 00:45:36 +00:00
|
|
|
double stats_gathering_started_;
|
2015-10-14 15:02:44 -07:00
|
|
|
ProxyTransportMap proxy_to_transport_;
|
2014-03-03 18:30:11 +00:00
|
|
|
|
2015-03-12 16:35:55 +00:00
|
|
|
// TODO(tommi): We appear to be holding on to raw pointers to reference
|
|
|
|
|
// counted objects? We should be using scoped_refptr here.
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
typedef std::vector<std::pair<AudioTrackInterface*, uint32_t> >
|
2014-03-03 18:30:11 +00:00
|
|
|
LocalAudioTrackVector;
|
|
|
|
|
LocalAudioTrackVector local_audio_tracks_;
|
2013-07-10 00:45:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
|
2016-02-10 10:53:12 +01:00
|
|
|
#endif // WEBRTC_API_STATSCOLLECTOR_H_
|