File: track_media_info_map.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; 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,629 bytes parent folder | download | duplicates (5)
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 2016 The WebRTC Project Authors. All rights reserved.
 *
 *  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.
 */

#ifndef PC_TRACK_MEDIA_INFO_MAP_H_
#define PC_TRACK_MEDIA_INFO_MAP_H_

#include <stdint.h>

#include <map>
#include <memory>
#include <optional>
#include <string>
#include <vector>

#include "api/array_view.h"
#include "api/media_stream_interface.h"
#include "api/scoped_refptr.h"
#include "media/base/media_channel.h"
#include "pc/rtp_receiver.h"
#include "pc/rtp_sender.h"
#include "rtc_base/ref_count.h"

namespace webrtc {

// Audio/video tracks and sender/receiver statistical information are associated
// with each other based on attachments to RTP senders/receivers. This class
// maps that relationship so that "infos" can be obtained from SSRCs and tracks
// can be obtained from "infos".
class TrackMediaInfoMap {
 public:
  TrackMediaInfoMap();

  // Takes ownership of the "infos". Does not affect the lifetime of the senders
  // or receivers, but TrackMediaInfoMap will keep their associated tracks alive
  // through reference counting until the map is destroyed.
  void Initialize(std::optional<VoiceMediaInfo> voice_media_info,
                  std::optional<VideoMediaInfo> video_media_info,
                  ArrayView<scoped_refptr<RtpSenderInternal>> rtp_senders,
                  ArrayView<scoped_refptr<RtpReceiverInternal>> rtp_receivers);

  const std::optional<VoiceMediaInfo>& voice_media_info() const {
    RTC_DCHECK(is_initialized_);
    return voice_media_info_;
  }
  const std::optional<VideoMediaInfo>& video_media_info() const {
    RTC_DCHECK(is_initialized_);
    return video_media_info_;
  }

  const VoiceSenderInfo* GetVoiceSenderInfoBySsrc(uint32_t ssrc) const;
  const VoiceReceiverInfo* GetVoiceReceiverInfoBySsrc(uint32_t ssrc) const;
  const VideoSenderInfo* GetVideoSenderInfoBySsrc(uint32_t ssrc) const;
  const VideoReceiverInfo* GetVideoReceiverInfoBySsrc(uint32_t ssrc) const;

  scoped_refptr<AudioTrackInterface> GetAudioTrack(
      const VoiceSenderInfo& voice_sender_info) const;
  scoped_refptr<AudioTrackInterface> GetAudioTrack(
      const VoiceReceiverInfo& voice_receiver_info) const;
  scoped_refptr<VideoTrackInterface> GetVideoTrack(
      const VideoSenderInfo& video_sender_info) const;
  scoped_refptr<VideoTrackInterface> GetVideoTrack(
      const VideoReceiverInfo& video_receiver_info) const;

  // TODO(hta): Remove this function, and redesign the callers not to need it.
  // It is not going to work if a track is attached multiple times, and
  // it is not going to work if a received track is attached as a sending
  // track (loopback).
  std::optional<int> GetAttachmentIdByTrack(
      const MediaStreamTrackInterface* track) const;

 private:
  bool is_initialized_ = false;
  std::optional<VoiceMediaInfo> voice_media_info_;
  std::optional<VideoMediaInfo> video_media_info_;
  // These maps map info objects to their corresponding tracks. They are always
  // the inverse of the maps above. One info object always maps to only one
  // track. The use of scoped_refptr<> here ensures the tracks outlive
  // TrackMediaInfoMap.
  std::map<const VoiceSenderInfo*, scoped_refptr<AudioTrackInterface>>
      audio_track_by_sender_info_;
  std::map<const VoiceReceiverInfo*, scoped_refptr<AudioTrackInterface>>
      audio_track_by_receiver_info_;
  std::map<const VideoSenderInfo*, scoped_refptr<VideoTrackInterface>>
      video_track_by_sender_info_;
  std::map<const VideoReceiverInfo*, scoped_refptr<VideoTrackInterface>>
      video_track_by_receiver_info_;
  // Map of tracks to attachment IDs.
  // Necessary because senders and receivers live on the signaling thread,
  // but the attachment IDs are needed while building stats on the networking
  // thread, so we can't look them up in the senders/receivers without
  // thread jumping.
  std::map<const MediaStreamTrackInterface*, int> attachment_id_by_track_;
  // These maps map SSRCs to the corresponding voice or video info objects.
  std::map<uint32_t, VoiceSenderInfo*> voice_info_by_sender_ssrc_;
  std::map<uint32_t, VoiceReceiverInfo*> voice_info_by_receiver_ssrc_;
  std::map<uint32_t, VideoSenderInfo*> video_info_by_sender_ssrc_;
  std::map<uint32_t, VideoReceiverInfo*> video_info_by_receiver_ssrc_;
};

}  // namespace webrtc

#endif  // PC_TRACK_MEDIA_INFO_MAP_H_