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 34 #include <string> 35 #include <map> 36 37 #include "talk/app/webrtc/mediastreaminterface.h" 38 #include "talk/app/webrtc/statstypes.h" 39 #include "talk/app/webrtc/webrtcsession.h" 40 41 #include "talk/base/timing.h" 42 43 namespace webrtc { 44 45 class StatsCollector { 46 public: 47 StatsCollector(); 48 49 // Register the session Stats should operate on. 50 // Set to NULL if the session has ended. 51 void set_session(WebRtcSession* session) { 52 session_ = session; 53 } 54 55 // Adds a MediaStream with tracks that can be used as a |selector| in a call 56 // to GetStats. 57 void AddStream(MediaStreamInterface* stream); 58 59 // Gather statistics from the session and store them for future use. 60 void UpdateStats(); 61 62 // Gets a StatsReports of the last collected stats. Note that UpdateStats must 63 // be called before this function to get the most recent stats. |selector| is 64 // a track label or empty string. The most recent reports are stored in 65 // |reports|. 66 bool GetStats(MediaStreamTrackInterface* track, StatsReports* reports); 67 68 WebRtcSession* session() { return session_; } 69 // Prepare an SSRC report for the given ssrc. Used internally. 70 StatsReport* PrepareReport(uint32 ssrc, const std::string& transport); 71 // Extracts the ID of a Transport belonging to an SSRC. Used internally. 72 bool GetTransportIdFromProxy(const std::string& proxy, 73 std::string* transport_id); 74 75 private: 76 bool CopySelectedReports(const std::string& selector, StatsReports* reports); 77 78 void ExtractSessionInfo(); 79 void ExtractVoiceInfo(); 80 void ExtractVideoInfo(); 81 double GetTimeNow(); 82 void BuildSsrcToTransportId(); 83 84 // A map from the report id to the report. 85 std::map<std::string, webrtc::StatsReport> reports_; 86 // Raw pointer to the session the statistics are gathered from. 87 WebRtcSession* session_; 88 double stats_gathering_started_; 89 talk_base::Timing timing_; 90 cricket::ProxyTransportMap proxy_to_transport_; 91 }; 92 93 } // namespace webrtc 94 95 #endif // TALK_APP_WEBRTC_STATSCOLLECTOR_H_ 96