henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * libjingle |
| 3 | * Copyright 2012, Google Inc. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are met: |
| 7 | * |
| 8 | * 1. Redistributions of source code must retain the above copyright notice, |
| 9 | * this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * 3. The name of the author may not be used to endorse or promote products |
| 14 | * derived from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
| 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
| 28 | // This file contains a class used for gathering statistics from an ongoing |
| 29 | // libjingle PeerConnection. |
| 30 | |
| 31 | #ifndef TALK_APP_WEBRTC_STATSCOLLECTOR_H_ |
| 32 | #define TALK_APP_WEBRTC_STATSCOLLECTOR_H_ |
| 33 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 34 | #include <map> |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame^] | 35 | #include <string> |
| 36 | #include <vector> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 37 | |
| 38 | #include "talk/app/webrtc/mediastreaminterface.h" |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 39 | #include "talk/app/webrtc/peerconnectioninterface.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 40 | #include "talk/app/webrtc/statstypes.h" |
| 41 | #include "talk/app/webrtc/webrtcsession.h" |
| 42 | |
| 43 | #include "talk/base/timing.h" |
| 44 | |
| 45 | namespace webrtc { |
| 46 | |
| 47 | class StatsCollector { |
| 48 | public: |
| 49 | StatsCollector(); |
| 50 | |
| 51 | // Register the session Stats should operate on. |
| 52 | // Set to NULL if the session has ended. |
| 53 | void set_session(WebRtcSession* session) { |
| 54 | session_ = session; |
| 55 | } |
| 56 | |
| 57 | // Adds a MediaStream with tracks that can be used as a |selector| in a call |
| 58 | // to GetStats. |
| 59 | void AddStream(MediaStreamInterface* stream); |
| 60 | |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame^] | 61 | // Adds a local audio track that is used for getting some voice statistics. |
| 62 | void AddLocalAudioTrack(AudioTrackInterface* audio_track, uint32 ssrc); |
| 63 | |
| 64 | // Removes a local audio tracks that is used for getting some voice |
| 65 | // statistics. |
| 66 | void RemoveLocalAudioTrack(AudioTrackInterface* audio_track, uint32 ssrc); |
| 67 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 68 | // Gather statistics from the session and store them for future use. |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 69 | void UpdateStats(PeerConnectionInterface::StatsOutputLevel level); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 70 | |
| 71 | // Gets a StatsReports of the last collected stats. Note that UpdateStats must |
| 72 | // be called before this function to get the most recent stats. |selector| is |
| 73 | // a track label or empty string. The most recent reports are stored in |
| 74 | // |reports|. |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 75 | bool GetStats(MediaStreamTrackInterface* track, |
| 76 | StatsReports* reports); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 77 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 78 | // Prepare an SSRC report for the given ssrc. Used internally |
| 79 | // in the ExtractStatsFromList template. |
| 80 | StatsReport* PrepareLocalReport(uint32 ssrc, const std::string& transport); |
| 81 | // Prepare an SSRC report for the given remote ssrc. Used internally. |
| 82 | StatsReport* PrepareRemoteReport(uint32 ssrc, const std::string& transport); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 83 | // Extracts the ID of a Transport belonging to an SSRC. Used internally. |
| 84 | bool GetTransportIdFromProxy(const std::string& proxy, |
| 85 | std::string* transport_id); |
| 86 | |
| 87 | private: |
| 88 | bool CopySelectedReports(const std::string& selector, StatsReports* reports); |
| 89 | |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 90 | // Helper method for AddCertificateReports. |
| 91 | std::string AddOneCertificateReport( |
| 92 | const talk_base::SSLCertificate* cert, const std::string& issuer_id); |
| 93 | |
| 94 | // Adds a report for this certificate and every certificate in its chain, and |
| 95 | // returns the leaf certificate's report's ID. |
| 96 | std::string AddCertificateReports(const talk_base::SSLCertificate* cert); |
| 97 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 98 | void ExtractSessionInfo(); |
| 99 | void ExtractVoiceInfo(); |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 100 | void ExtractVideoInfo(PeerConnectionInterface::StatsOutputLevel level); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 101 | double GetTimeNow(); |
| 102 | void BuildSsrcToTransportId(); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 103 | WebRtcSession* session() { return session_; } |
| 104 | webrtc::StatsReport* GetOrCreateReport(const std::string& type, |
| 105 | const std::string& id); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame^] | 106 | webrtc::StatsReport* GetReport(const std::string& type, |
| 107 | const std::string& id); |
| 108 | |
| 109 | // Helper method to get stats from the local audio tracks. |
| 110 | void UpdateStatsFromExistingLocalAudioTracks(); |
| 111 | void UpdateReportFromAudioTrack(AudioTrackInterface* track, |
| 112 | StatsReport* report); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 113 | |
| 114 | // A map from the report id to the report. |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 115 | std::map<std::string, StatsReport> reports_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 116 | // Raw pointer to the session the statistics are gathered from. |
| 117 | WebRtcSession* session_; |
| 118 | double stats_gathering_started_; |
| 119 | talk_base::Timing timing_; |
| 120 | cricket::ProxyTransportMap proxy_to_transport_; |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame^] | 121 | |
| 122 | typedef std::vector<std::pair<AudioTrackInterface*, uint32> > |
| 123 | LocalAudioTrackVector; |
| 124 | LocalAudioTrackVector local_audio_tracks_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 125 | }; |
| 126 | |
| 127 | } // namespace webrtc |
| 128 | |
| 129 | #endif // TALK_APP_WEBRTC_STATSCOLLECTOR_H_ |