File: media_stream_track_metrics.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (109 lines) | stat: -rw-r--r-- 4,229 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_PEERCONNECTION_MEDIA_STREAM_TRACK_METRICS_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_PEERCONNECTION_MEDIA_STREAM_TRACK_METRICS_H_

#include <stdint.h>

#include <memory>

#include "base/threading/thread_checker.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "third_party/blink/public/mojom/mediastream/media_stream.mojom-blink.h"
#include "third_party/blink/renderer/modules/modules_export.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"
#include "third_party/webrtc/api/peer_connection_interface.h"

namespace blink {

class MediaStreamTrackMetricsObserver;
class RTCPeerConnectionHandler;

// Responsible for observing the connected lifetimes of tracks going
// over a PeerConnection, and sending messages to the browser process
// about lifetime events.
//
// There should be exactly one of these objects owned by each
// RTCPeerConnectionHandler, and its lifetime should match the
// lifetime of its owner.
class MODULES_EXPORT MediaStreamTrackMetrics {
 public:
  explicit MediaStreamTrackMetrics();

  MediaStreamTrackMetrics(const MediaStreamTrackMetrics&) = delete;
  MediaStreamTrackMetrics& operator=(const MediaStreamTrackMetrics&) = delete;

  ~MediaStreamTrackMetrics();

  enum class Direction { kSend, kReceive };
  enum class Kind { kAudio, kVideo };
  enum class LifetimeEvent { kConnected, kDisconnected };

  // Starts tracking the lifetime of the track until |RemoveTrack| is called
  // or this object's lifetime ends.
  void AddTrack(Direction direction, Kind kind, const std::string& track_id);

  // Stops tracking the lifetime of the track.
  void RemoveTrack(Direction direction, Kind kind, const std::string& track_id);

  // Called to indicate changes in the ICE connection state for the
  // PeerConnection this object is associated with. Used to generate
  // the connected/disconnected lifetime events for these tracks.
  void IceConnectionChange(
      webrtc::PeerConnectionInterface::IceConnectionState new_state);

  // Send a lifetime message to the browser process. Virtual so that
  // it can be overridden in unit tests.
  //
  // |track_id| is the ID of the track that just got connected or
  // disconnected.
  //
  // |is_audio| is true for an audio track, false for a video track.
  //
  // |start_lifetime| is true to indicate that it just got connected,
  // false to indicate it is no longer connected.
  //
  // |is_remote| is true for remote streams (received over a
  // PeerConnection), false for local streams (sent over a
  // PeerConnection).
  virtual void SendLifetimeMessage(const std::string& track_id,
                                   Kind kind,
                                   LifetimeEvent lifetime_event,
                                   Direction direction);

 protected:
  // Calls SendLifetimeMessage for |observer| depending on |ice_state_|.
  void SendLifeTimeMessageDependingOnIceState(
      MediaStreamTrackMetricsObserver* observer);

  // Implements MakeUniqueId. |pc_id| is a cast of this object's
  // |this| pointer to a 64-bit integer, which is usable as a unique
  // ID for the PeerConnection this object is attached to (since there
  // is a one-to-one relationship).
  uint64_t MakeUniqueIdImpl(uint64_t pc_id,
                            const std::string& track,
                            Direction direction);

 private:
  // Make a unique ID for the given track, that is valid while the
  // track object and the PeerConnection it is attached to both exist.
  uint64_t MakeUniqueId(const std::string& track_id, Direction direction);

  mojo::Remote<blink::mojom::blink::MediaStreamTrackMetricsHost>&
  GetMediaStreamTrackMetricsHost();

  mojo::Remote<blink::mojom::blink::MediaStreamTrackMetricsHost>
      track_metrics_host_;

  Vector<std::unique_ptr<MediaStreamTrackMetricsObserver>> observers_;

  webrtc::PeerConnectionInterface::IceConnectionState ice_state_;

  THREAD_CHECKER(thread_checker_);
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_MODULES_PEERCONNECTION_MEDIA_STREAM_TRACK_METRICS_H_