Roll src/third_party/WebKit eac3800:0237a66 (svn 202606:202607)
[chromium-blink-merge.git] / content / renderer / media / webrtc / media_stream_track_metrics.h
blobaaf669d0d0c7a9e0da16d733c30ea5593b66d905
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_RENDERER_MEDIA_WEBRTC_MEDIA_STREAM_TRACK_METRICS_H_
6 #define CONTENT_RENDERER_MEDIA_WEBRTC_MEDIA_STREAM_TRACK_METRICS_H_
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_vector.h"
10 #include "base/threading/non_thread_safe.h"
11 #include "content/common/content_export.h"
12 #include "third_party/libjingle/source/talk/app/webrtc/peerconnectioninterface.h"
14 namespace webrtc {
15 class MediaStreamInterface;
16 class MediaStreamTrackInterface;
19 namespace content {
21 class MediaStreamTrackMetricsObserver;
22 class RTCPeerConnectionHandler;
24 // Responsible for observing the connected lifetimes of tracks going
25 // over a PeerConnection, and sending messages to the browser process
26 // about lifetime events.
28 // There should be exactly one of these objects owned by each
29 // RTCPeerConnectionHandler, and its lifetime should match the
30 // lifetime of its owner.
31 class CONTENT_EXPORT MediaStreamTrackMetrics : public base::NonThreadSafe {
32 public:
33 explicit MediaStreamTrackMetrics();
34 ~MediaStreamTrackMetrics();
36 enum StreamType { SENT_STREAM, RECEIVED_STREAM };
38 enum TrackType { AUDIO_TRACK, VIDEO_TRACK };
40 enum LifetimeEvent { CONNECTED, DISCONNECTED };
42 // Starts tracking lifetimes of all the tracks in |stream| and any
43 // tracks added or removed to/from the stream until |RemoveStream|
44 // is called or this object's lifetime ends.
45 void AddStream(StreamType type, webrtc::MediaStreamInterface* stream);
47 // Stops tracking lifetimes of tracks in |stream|.
48 void RemoveStream(StreamType type, webrtc::MediaStreamInterface* stream);
50 // Called to indicate changes in the ICE connection state for the
51 // PeerConnection this object is associated with. Used to generate
52 // the connected/disconnected lifetime events for these tracks.
53 void IceConnectionChange(
54 webrtc::PeerConnectionInterface::IceConnectionState new_state);
56 // Send a lifetime message to the browser process. Virtual so that
57 // it can be overridden in unit tests.
59 // |track_id| is the ID of the track that just got connected or
60 // disconnected.
62 // |is_audio| is true for an audio track, false for a video track.
64 // |start_lifetime| is true to indicate that it just got connected,
65 // false to indicate it is no longer connected.
67 // |is_remote| is true for remote streams (received over a
68 // PeerConnection), false for local streams (sent over a
69 // PeerConnection).
70 virtual void SendLifetimeMessage(const std::string& track_id,
71 TrackType track_type,
72 LifetimeEvent lifetime_event,
73 StreamType stream_type);
75 protected:
76 // Calls SendLifetimeMessage for |observer| depending on |ice_state_|.
77 void SendLifeTimeMessageDependingOnIceState(
78 MediaStreamTrackMetricsObserver* observer);
80 // Implements MakeUniqueId. |pc_id| is a cast of this object's
81 // |this| pointer to a 64-bit integer, which is usable as a unique
82 // ID for the PeerConnection this object is attached to (since there
83 // is a one-to-one relationship).
84 uint64 MakeUniqueIdImpl(uint64 pc_id,
85 const std::string& track,
86 StreamType stream_type);
88 private:
89 // Make a unique ID for the given track, that is valid while the
90 // track object and the PeerConnection it is attached to both exist.
91 uint64 MakeUniqueId(const std::string& track, StreamType stream_type);
93 typedef ScopedVector<MediaStreamTrackMetricsObserver> ObserverVector;
94 ObserverVector observers_;
96 webrtc::PeerConnectionInterface::IceConnectionState ice_state_;
99 } // namespace
101 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_MEDIA_STREAM_TRACK_METRICS_H_