OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2016 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/api/rtcstatscollector.h" | 11 #include "webrtc/api/rtcstatscollector.h" |
12 | 12 |
13 #include <memory> | 13 #include <memory> |
14 #include <ostream> | 14 #include <ostream> |
15 #include <string> | 15 #include <string> |
16 #include <vector> | 16 #include <vector> |
17 | 17 |
| 18 #include "webrtc/api/mediastream.h" |
| 19 #include "webrtc/api/mediastreamtrack.h" |
18 #include "webrtc/api/jsepsessiondescription.h" | 20 #include "webrtc/api/jsepsessiondescription.h" |
19 #include "webrtc/api/stats/rtcstats_objects.h" | 21 #include "webrtc/api/stats/rtcstats_objects.h" |
20 #include "webrtc/api/stats/rtcstatsreport.h" | 22 #include "webrtc/api/stats/rtcstatsreport.h" |
21 #include "webrtc/api/test/mock_datachannel.h" | 23 #include "webrtc/api/test/mock_datachannel.h" |
22 #include "webrtc/api/test/mock_peerconnection.h" | 24 #include "webrtc/api/test/mock_peerconnection.h" |
23 #include "webrtc/api/test/mock_webrtcsession.h" | 25 #include "webrtc/api/test/mock_webrtcsession.h" |
24 #include "webrtc/base/checks.h" | 26 #include "webrtc/base/checks.h" |
25 #include "webrtc/base/fakeclock.h" | 27 #include "webrtc/base/fakeclock.h" |
26 #include "webrtc/base/fakesslidentity.h" | 28 #include "webrtc/base/fakesslidentity.h" |
27 #include "webrtc/base/gunit.h" | 29 #include "webrtc/base/gunit.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 } | 65 } |
64 | 66 |
65 void PrintTo(const RTCRemoteIceCandidateStats& stats, ::std::ostream* os) { | 67 void PrintTo(const RTCRemoteIceCandidateStats& stats, ::std::ostream* os) { |
66 *os << stats.ToString(); | 68 *os << stats.ToString(); |
67 } | 69 } |
68 | 70 |
69 void PrintTo(const RTCPeerConnectionStats& stats, ::std::ostream* os) { | 71 void PrintTo(const RTCPeerConnectionStats& stats, ::std::ostream* os) { |
70 *os << stats.ToString(); | 72 *os << stats.ToString(); |
71 } | 73 } |
72 | 74 |
| 75 void PrintTo(const RTCMediaStreamStats& stats, ::std::ostream* os) { |
| 76 *os << stats.ToString(); |
| 77 } |
| 78 |
| 79 void PrintTo(const RTCMediaStreamTrackStats& stats, ::std::ostream* os) { |
| 80 *os << stats.ToString(); |
| 81 } |
| 82 |
73 void PrintTo(const RTCInboundRTPStreamStats& stats, ::std::ostream* os) { | 83 void PrintTo(const RTCInboundRTPStreamStats& stats, ::std::ostream* os) { |
74 *os << stats.ToString(); | 84 *os << stats.ToString(); |
75 } | 85 } |
76 | 86 |
77 void PrintTo(const RTCOutboundRTPStreamStats& stats, ::std::ostream* os) { | 87 void PrintTo(const RTCOutboundRTPStreamStats& stats, ::std::ostream* os) { |
78 *os << stats.ToString(); | 88 *os << stats.ToString(); |
79 } | 89 } |
80 | 90 |
81 void PrintTo(const RTCTransportStats& stats, ::std::ostream* os) { | 91 void PrintTo(const RTCTransportStats& stats, ::std::ostream* os) { |
82 *os << stats.ToString(); | 92 *os << stats.ToString(); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 const std::string& candidate_type, | 153 const std::string& candidate_type, |
144 uint32_t priority) { | 154 uint32_t priority) { |
145 std::unique_ptr<cricket::Candidate> candidate(new cricket::Candidate()); | 155 std::unique_ptr<cricket::Candidate> candidate(new cricket::Candidate()); |
146 candidate->set_address(rtc::SocketAddress(hostname, port)); | 156 candidate->set_address(rtc::SocketAddress(hostname, port)); |
147 candidate->set_protocol(protocol); | 157 candidate->set_protocol(protocol); |
148 candidate->set_type(candidate_type); | 158 candidate->set_type(candidate_type); |
149 candidate->set_priority(priority); | 159 candidate->set_priority(priority); |
150 return candidate; | 160 return candidate; |
151 } | 161 } |
152 | 162 |
| 163 class FakeAudioProcessorForStats |
| 164 : public rtc::RefCountedObject<AudioProcessorInterface> { |
| 165 public: |
| 166 FakeAudioProcessorForStats( |
| 167 AudioProcessorInterface::AudioProcessorStats stats) |
| 168 : stats_(stats) { |
| 169 } |
| 170 |
| 171 void GetStats(AudioProcessorInterface::AudioProcessorStats* stats) override { |
| 172 *stats = stats_; |
| 173 } |
| 174 |
| 175 private: |
| 176 AudioProcessorInterface::AudioProcessorStats stats_; |
| 177 }; |
| 178 |
| 179 class FakeAudioTrackForStats |
| 180 : public MediaStreamTrack<AudioTrackInterface> { |
| 181 public: |
| 182 static rtc::scoped_refptr<FakeAudioTrackForStats> Create( |
| 183 const std::string& id, |
| 184 MediaStreamTrackInterface::TrackState state, |
| 185 int signal_level, |
| 186 rtc::scoped_refptr<FakeAudioProcessorForStats> processor) { |
| 187 rtc::scoped_refptr<FakeAudioTrackForStats> audio_track_stats( |
| 188 new rtc::RefCountedObject<FakeAudioTrackForStats>( |
| 189 id, signal_level, processor)); |
| 190 audio_track_stats->set_state(state); |
| 191 return audio_track_stats; |
| 192 } |
| 193 |
| 194 FakeAudioTrackForStats( |
| 195 const std::string& id, |
| 196 int signal_level, |
| 197 rtc::scoped_refptr<FakeAudioProcessorForStats> processor) |
| 198 : MediaStreamTrack<AudioTrackInterface>(id), |
| 199 signal_level_(signal_level), |
| 200 processor_(processor) { |
| 201 } |
| 202 |
| 203 std::string kind() const override { |
| 204 return MediaStreamTrackInterface::kAudioKind; |
| 205 } |
| 206 webrtc::AudioSourceInterface* GetSource() const override { return nullptr; } |
| 207 void AddSink(webrtc::AudioTrackSinkInterface* sink) override {} |
| 208 void RemoveSink(webrtc::AudioTrackSinkInterface* sink) override {} |
| 209 bool GetSignalLevel(int* level) override { |
| 210 *level = signal_level_; |
| 211 return true; |
| 212 } |
| 213 rtc::scoped_refptr<AudioProcessorInterface> GetAudioProcessor() override { |
| 214 return processor_; |
| 215 } |
| 216 |
| 217 private: |
| 218 int signal_level_; |
| 219 rtc::scoped_refptr<FakeAudioProcessorForStats> processor_; |
| 220 }; |
| 221 |
| 222 class FakeVideoTrackSourceForStats |
| 223 : public rtc::RefCountedObject<VideoTrackSourceInterface> { |
| 224 public: |
| 225 FakeVideoTrackSourceForStats(VideoTrackSourceInterface::Stats stats) |
| 226 : stats_(stats) { |
| 227 } |
| 228 |
| 229 MediaSourceInterface::SourceState state() const override { |
| 230 return MediaSourceInterface::kLive; |
| 231 } |
| 232 bool remote() const override { return false; } |
| 233 void RegisterObserver(ObserverInterface* observer) override {} |
| 234 void UnregisterObserver(ObserverInterface* observer) override {} |
| 235 void AddOrUpdateSink(rtc::VideoSinkInterface<cricket::VideoFrame>* sink, |
| 236 const rtc::VideoSinkWants& wants) override {} |
| 237 void RemoveSink(rtc::VideoSinkInterface<cricket::VideoFrame>* sink) override { |
| 238 } |
| 239 bool is_screencast() const override { return false; } |
| 240 rtc::Optional<bool> needs_denoising() const override { |
| 241 return rtc::Optional<bool>(); |
| 242 } |
| 243 bool GetStats(VideoTrackSourceInterface::Stats* stats) override { |
| 244 *stats = stats_; |
| 245 return true; |
| 246 } |
| 247 |
| 248 private: |
| 249 VideoTrackSourceInterface::Stats stats_; |
| 250 }; |
| 251 |
| 252 class FakeVideoTrackForStats |
| 253 : public MediaStreamTrack<VideoTrackInterface> { |
| 254 public: |
| 255 static rtc::scoped_refptr<FakeVideoTrackForStats> Create( |
| 256 const std::string& id, |
| 257 MediaStreamTrackInterface::TrackState state, |
| 258 rtc::scoped_refptr<VideoTrackSourceInterface> source) { |
| 259 rtc::scoped_refptr<FakeVideoTrackForStats> video_track( |
| 260 new rtc::RefCountedObject<FakeVideoTrackForStats>(id, source)); |
| 261 video_track->set_state(state); |
| 262 return video_track; |
| 263 } |
| 264 |
| 265 FakeVideoTrackForStats( |
| 266 const std::string& id, |
| 267 rtc::scoped_refptr<VideoTrackSourceInterface> source) |
| 268 : MediaStreamTrack<VideoTrackInterface>(id), |
| 269 source_(source) { |
| 270 } |
| 271 |
| 272 std::string kind() const override { |
| 273 return MediaStreamTrackInterface::kVideoKind; |
| 274 } |
| 275 VideoTrackSourceInterface* GetSource() const override { |
| 276 return source_; |
| 277 } |
| 278 |
| 279 private: |
| 280 rtc::scoped_refptr<VideoTrackSourceInterface> source_; |
| 281 }; |
| 282 |
153 class RTCStatsCollectorTestHelper : public SetSessionDescriptionObserver { | 283 class RTCStatsCollectorTestHelper : public SetSessionDescriptionObserver { |
154 public: | 284 public: |
155 RTCStatsCollectorTestHelper() | 285 RTCStatsCollectorTestHelper() |
156 : worker_thread_(rtc::Thread::Current()), | 286 : worker_thread_(rtc::Thread::Current()), |
157 network_thread_(rtc::Thread::Current()), | 287 network_thread_(rtc::Thread::Current()), |
158 media_engine_(new cricket::FakeMediaEngine()), | 288 media_engine_(new cricket::FakeMediaEngine()), |
159 channel_manager_( | 289 channel_manager_( |
160 new cricket::ChannelManager(media_engine_, | 290 new cricket::ChannelManager(media_engine_, |
161 worker_thread_, | 291 worker_thread_, |
162 network_thread_)), | 292 network_thread_)), |
163 media_controller_( | 293 media_controller_( |
164 MediaControllerInterface::Create(cricket::MediaConfig(), | 294 MediaControllerInterface::Create(cricket::MediaConfig(), |
165 worker_thread_, | 295 worker_thread_, |
166 channel_manager_.get(), | 296 channel_manager_.get(), |
167 &event_log_)), | 297 &event_log_)), |
168 session_(media_controller_.get()), | 298 session_(media_controller_.get()), |
169 pc_() { | 299 pc_() { |
170 // Default return values for mocks. | 300 // Default return values for mocks. |
| 301 EXPECT_CALL(pc_, local_streams()).WillRepeatedly(Return(nullptr)); |
| 302 EXPECT_CALL(pc_, remote_streams()).WillRepeatedly(Return(nullptr)); |
171 EXPECT_CALL(pc_, session()).WillRepeatedly(Return(&session_)); | 303 EXPECT_CALL(pc_, session()).WillRepeatedly(Return(&session_)); |
172 EXPECT_CALL(pc_, sctp_data_channels()).WillRepeatedly( | 304 EXPECT_CALL(pc_, sctp_data_channels()).WillRepeatedly( |
173 ReturnRef(data_channels_)); | 305 ReturnRef(data_channels_)); |
174 EXPECT_CALL(session_, video_channel()).WillRepeatedly(ReturnNull()); | 306 EXPECT_CALL(session_, video_channel()).WillRepeatedly(ReturnNull()); |
175 EXPECT_CALL(session_, voice_channel()).WillRepeatedly(ReturnNull()); | 307 EXPECT_CALL(session_, voice_channel()).WillRepeatedly(ReturnNull()); |
176 EXPECT_CALL(session_, GetTransportStats(_)).WillRepeatedly(Return(false)); | 308 EXPECT_CALL(session_, GetTransportStats(_)).WillRepeatedly(Return(false)); |
177 EXPECT_CALL(session_, GetLocalCertificate(_, _)).WillRepeatedly( | 309 EXPECT_CALL(session_, GetLocalCertificate(_, _)).WillRepeatedly( |
178 Return(false)); | 310 Return(false)); |
179 EXPECT_CALL(session_, GetRemoteSSLCertificate_ReturnsRawPointer(_)) | 311 EXPECT_CALL(session_, GetRemoteSSLCertificate_ReturnsRawPointer(_)) |
180 .WillRepeatedly(Return(nullptr)); | 312 .WillRepeatedly(Return(nullptr)); |
(...skipping 10 matching lines...) Expand all Loading... |
191 } | 323 } |
192 | 324 |
193 // SetSessionDescriptionObserver overrides. | 325 // SetSessionDescriptionObserver overrides. |
194 void OnSuccess() override {} | 326 void OnSuccess() override {} |
195 void OnFailure(const std::string& error) override { | 327 void OnFailure(const std::string& error) override { |
196 RTC_NOTREACHED() << error; | 328 RTC_NOTREACHED() << error; |
197 } | 329 } |
198 | 330 |
199 private: | 331 private: |
200 rtc::ScopedFakeClock fake_clock_; | 332 rtc::ScopedFakeClock fake_clock_; |
201 webrtc::RtcEventLogNullImpl event_log_; | 333 RtcEventLogNullImpl event_log_; |
202 rtc::Thread* const worker_thread_; | 334 rtc::Thread* const worker_thread_; |
203 rtc::Thread* const network_thread_; | 335 rtc::Thread* const network_thread_; |
204 cricket::FakeMediaEngine* media_engine_; | 336 cricket::FakeMediaEngine* media_engine_; |
205 std::unique_ptr<cricket::ChannelManager> channel_manager_; | 337 std::unique_ptr<cricket::ChannelManager> channel_manager_; |
206 std::unique_ptr<webrtc::MediaControllerInterface> media_controller_; | 338 std::unique_ptr<MediaControllerInterface> media_controller_; |
207 MockWebRtcSession session_; | 339 MockWebRtcSession session_; |
208 MockPeerConnection pc_; | 340 MockPeerConnection pc_; |
209 | 341 |
210 std::vector<rtc::scoped_refptr<DataChannel>> data_channels_; | 342 std::vector<rtc::scoped_refptr<DataChannel>> data_channels_; |
211 }; | 343 }; |
212 | 344 |
213 class RTCTestStats : public RTCStats { | 345 class RTCTestStats : public RTCStats { |
214 public: | 346 public: |
215 WEBRTC_RTCSTATS_DECL(); | 347 WEBRTC_RTCSTATS_DECL(); |
216 | 348 |
(...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
972 // channels that have been opened and closed, not the numbers currently | 1104 // channels that have been opened and closed, not the numbers currently |
973 // open/closed, we would expect opened >= closed and (opened - closed) to be | 1105 // open/closed, we would expect opened >= closed and (opened - closed) to be |
974 // the number currently open. crbug.com/636818. | 1106 // the number currently open. crbug.com/636818. |
975 const RTCPeerConnectionStats& pcstats = | 1107 const RTCPeerConnectionStats& pcstats = |
976 stats->cast_to<RTCPeerConnectionStats>(); | 1108 stats->cast_to<RTCPeerConnectionStats>(); |
977 EXPECT_EQ(*pcstats.data_channels_opened, static_cast<uint32_t>(1)); | 1109 EXPECT_EQ(*pcstats.data_channels_opened, static_cast<uint32_t>(1)); |
978 EXPECT_EQ(*pcstats.data_channels_closed, static_cast<uint32_t>(3)); | 1110 EXPECT_EQ(*pcstats.data_channels_closed, static_cast<uint32_t>(3)); |
979 } | 1111 } |
980 } | 1112 } |
981 | 1113 |
| 1114 TEST_F(RTCStatsCollectorTest, |
| 1115 CollectRTCMediaStreamStatsAndRTCMediaStreamTrackStats_Audio) { |
| 1116 rtc::scoped_refptr<StreamCollection> local_streams = |
| 1117 StreamCollection::Create(); |
| 1118 rtc::scoped_refptr<StreamCollection> remote_streams = |
| 1119 StreamCollection::Create(); |
| 1120 EXPECT_CALL(test_->pc(), local_streams()) |
| 1121 .WillRepeatedly(Return(local_streams)); |
| 1122 EXPECT_CALL(test_->pc(), remote_streams()) |
| 1123 .WillRepeatedly(Return(remote_streams)); |
| 1124 |
| 1125 rtc::scoped_refptr<MediaStream> local_stream = |
| 1126 MediaStream::Create("LocalStreamLabel"); |
| 1127 local_streams->AddStream(local_stream); |
| 1128 rtc::scoped_refptr<MediaStream> remote_stream = |
| 1129 MediaStream::Create("RemoteStreamLabel"); |
| 1130 remote_streams->AddStream(remote_stream); |
| 1131 |
| 1132 // Local audio track |
| 1133 AudioProcessorInterface::AudioProcessorStats local_audio_processor_stats; |
| 1134 local_audio_processor_stats.echo_return_loss = 42; |
| 1135 local_audio_processor_stats.echo_return_loss_enhancement = 52; |
| 1136 rtc::scoped_refptr<FakeAudioTrackForStats> local_audio_track = |
| 1137 FakeAudioTrackForStats::Create( |
| 1138 "LocalAudioTrackID", |
| 1139 MediaStreamTrackInterface::TrackState::kEnded, |
| 1140 32767, |
| 1141 new FakeAudioProcessorForStats(local_audio_processor_stats)); |
| 1142 local_stream->AddTrack(local_audio_track); |
| 1143 |
| 1144 // Remote audio track |
| 1145 AudioProcessorInterface::AudioProcessorStats remote_audio_processor_stats; |
| 1146 remote_audio_processor_stats.echo_return_loss = 13; |
| 1147 remote_audio_processor_stats.echo_return_loss_enhancement = 37; |
| 1148 rtc::scoped_refptr<FakeAudioTrackForStats> remote_audio_track = |
| 1149 FakeAudioTrackForStats::Create( |
| 1150 "RemoteAudioTrackID", |
| 1151 MediaStreamTrackInterface::TrackState::kLive, |
| 1152 0, |
| 1153 new FakeAudioProcessorForStats(remote_audio_processor_stats)); |
| 1154 remote_stream->AddTrack(remote_audio_track); |
| 1155 |
| 1156 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); |
| 1157 |
| 1158 RTCMediaStreamStats expected_local_stream( |
| 1159 "RTCMediaStream_LocalStreamLabel", report->timestamp_us()); |
| 1160 expected_local_stream.stream_identifier = local_stream->label(); |
| 1161 expected_local_stream.track_ids = std::vector<std::string>(); |
| 1162 expected_local_stream.track_ids->push_back( |
| 1163 "RTCMediaStreamTrack_LocalAudioTrackID"); |
| 1164 EXPECT_TRUE(report->Get(expected_local_stream.id())); |
| 1165 EXPECT_EQ(expected_local_stream, |
| 1166 report->Get(expected_local_stream.id())->cast_to< |
| 1167 RTCMediaStreamStats>()); |
| 1168 |
| 1169 RTCMediaStreamStats expected_remote_stream( |
| 1170 "RTCMediaStream_RemoteStreamLabel", report->timestamp_us()); |
| 1171 expected_remote_stream.stream_identifier = remote_stream->label(); |
| 1172 expected_remote_stream.track_ids = std::vector<std::string>(); |
| 1173 expected_remote_stream.track_ids->push_back( |
| 1174 "RTCMediaStreamTrack_RemoteAudioTrackID"); |
| 1175 EXPECT_TRUE(report->Get(expected_remote_stream.id())); |
| 1176 EXPECT_EQ(expected_remote_stream, |
| 1177 report->Get(expected_remote_stream.id())->cast_to< |
| 1178 RTCMediaStreamStats>()); |
| 1179 |
| 1180 RTCMediaStreamTrackStats expected_local_audio_track( |
| 1181 "RTCMediaStreamTrack_LocalAudioTrackID", report->timestamp_us()); |
| 1182 expected_local_audio_track.track_identifier = local_audio_track->id(); |
| 1183 expected_local_audio_track.remote_source = false; |
| 1184 expected_local_audio_track.ended = true; |
| 1185 expected_local_audio_track.detached = false; |
| 1186 expected_local_audio_track.audio_level = 1.0; |
| 1187 expected_local_audio_track.echo_return_loss = 42.0; |
| 1188 expected_local_audio_track.echo_return_loss_enhancement = 52.0; |
| 1189 EXPECT_TRUE(report->Get(expected_local_audio_track.id())); |
| 1190 EXPECT_EQ(expected_local_audio_track, |
| 1191 report->Get(expected_local_audio_track.id())->cast_to< |
| 1192 RTCMediaStreamTrackStats>()); |
| 1193 |
| 1194 RTCMediaStreamTrackStats expected_remote_audio_track( |
| 1195 "RTCMediaStreamTrack_RemoteAudioTrackID", report->timestamp_us()); |
| 1196 expected_remote_audio_track.track_identifier = remote_audio_track->id(); |
| 1197 expected_remote_audio_track.remote_source = true; |
| 1198 expected_remote_audio_track.ended = false; |
| 1199 expected_remote_audio_track.detached = false; |
| 1200 expected_remote_audio_track.audio_level = 0.0; |
| 1201 expected_remote_audio_track.echo_return_loss = 13.0; |
| 1202 expected_remote_audio_track.echo_return_loss_enhancement = 37.0; |
| 1203 EXPECT_TRUE(report->Get(expected_remote_audio_track.id())); |
| 1204 EXPECT_EQ(expected_remote_audio_track, |
| 1205 report->Get(expected_remote_audio_track.id())->cast_to< |
| 1206 RTCMediaStreamTrackStats>()); |
| 1207 } |
| 1208 |
| 1209 TEST_F(RTCStatsCollectorTest, |
| 1210 CollectRTCMediaStreamStatsAndRTCMediaStreamTrackStats_Video) { |
| 1211 rtc::scoped_refptr<StreamCollection> local_streams = |
| 1212 StreamCollection::Create(); |
| 1213 rtc::scoped_refptr<StreamCollection> remote_streams = |
| 1214 StreamCollection::Create(); |
| 1215 EXPECT_CALL(test_->pc(), local_streams()) |
| 1216 .WillRepeatedly(Return(local_streams)); |
| 1217 EXPECT_CALL(test_->pc(), remote_streams()) |
| 1218 .WillRepeatedly(Return(remote_streams)); |
| 1219 |
| 1220 rtc::scoped_refptr<MediaStream> local_stream = |
| 1221 MediaStream::Create("LocalStreamLabel"); |
| 1222 local_streams->AddStream(local_stream); |
| 1223 rtc::scoped_refptr<MediaStream> remote_stream = |
| 1224 MediaStream::Create("RemoteStreamLabel"); |
| 1225 remote_streams->AddStream(remote_stream); |
| 1226 |
| 1227 // Local video track |
| 1228 VideoTrackSourceInterface::Stats local_video_track_source_stats; |
| 1229 local_video_track_source_stats.input_width = 1234; |
| 1230 local_video_track_source_stats.input_height = 4321; |
| 1231 rtc::scoped_refptr<FakeVideoTrackSourceForStats> local_video_track_source = |
| 1232 new FakeVideoTrackSourceForStats(local_video_track_source_stats); |
| 1233 rtc::scoped_refptr<FakeVideoTrackForStats> local_video_track = |
| 1234 FakeVideoTrackForStats::Create( |
| 1235 "LocalVideoTrackID", |
| 1236 MediaStreamTrackInterface::TrackState::kLive, |
| 1237 local_video_track_source); |
| 1238 local_stream->AddTrack(local_video_track); |
| 1239 |
| 1240 // Remote video track |
| 1241 VideoTrackSourceInterface::Stats remote_video_track_source_stats; |
| 1242 remote_video_track_source_stats.input_width = 1234; |
| 1243 remote_video_track_source_stats.input_height = 4321; |
| 1244 rtc::scoped_refptr<FakeVideoTrackSourceForStats> remote_video_track_source = |
| 1245 new FakeVideoTrackSourceForStats(remote_video_track_source_stats); |
| 1246 rtc::scoped_refptr<FakeVideoTrackForStats> remote_video_track = |
| 1247 FakeVideoTrackForStats::Create( |
| 1248 "RemoteVideoTrackID", |
| 1249 MediaStreamTrackInterface::TrackState::kEnded, |
| 1250 remote_video_track_source); |
| 1251 remote_stream->AddTrack(remote_video_track); |
| 1252 |
| 1253 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); |
| 1254 |
| 1255 RTCMediaStreamStats expected_local_stream( |
| 1256 "RTCMediaStream_LocalStreamLabel", report->timestamp_us()); |
| 1257 expected_local_stream.stream_identifier = local_stream->label(); |
| 1258 expected_local_stream.track_ids = std::vector<std::string>(); |
| 1259 expected_local_stream.track_ids->push_back( |
| 1260 "RTCMediaStreamTrack_LocalVideoTrackID"); |
| 1261 EXPECT_TRUE(report->Get(expected_local_stream.id())); |
| 1262 EXPECT_EQ(expected_local_stream, |
| 1263 report->Get(expected_local_stream.id())->cast_to< |
| 1264 RTCMediaStreamStats>()); |
| 1265 |
| 1266 RTCMediaStreamStats expected_remote_stream( |
| 1267 "RTCMediaStream_RemoteStreamLabel", report->timestamp_us()); |
| 1268 expected_remote_stream.stream_identifier = remote_stream->label(); |
| 1269 expected_remote_stream.track_ids = std::vector<std::string>(); |
| 1270 expected_remote_stream.track_ids->push_back( |
| 1271 "RTCMediaStreamTrack_RemoteVideoTrackID"); |
| 1272 EXPECT_TRUE(report->Get(expected_remote_stream.id())); |
| 1273 EXPECT_EQ(expected_remote_stream, |
| 1274 report->Get(expected_remote_stream.id())->cast_to< |
| 1275 RTCMediaStreamStats>()); |
| 1276 |
| 1277 RTCMediaStreamTrackStats expected_local_video_track( |
| 1278 "RTCMediaStreamTrack_LocalVideoTrackID", report->timestamp_us()); |
| 1279 expected_local_video_track.track_identifier = local_video_track->id(); |
| 1280 expected_local_video_track.remote_source = false; |
| 1281 expected_local_video_track.ended = false; |
| 1282 expected_local_video_track.detached = false; |
| 1283 expected_local_video_track.frame_width = 1234; |
| 1284 expected_local_video_track.frame_height = 4321; |
| 1285 EXPECT_TRUE(report->Get(expected_local_video_track.id())); |
| 1286 EXPECT_EQ(expected_local_video_track, |
| 1287 report->Get(expected_local_video_track.id())->cast_to< |
| 1288 RTCMediaStreamTrackStats>()); |
| 1289 |
| 1290 RTCMediaStreamTrackStats expected_remote_video_track( |
| 1291 "RTCMediaStreamTrack_RemoteVideoTrackID", report->timestamp_us()); |
| 1292 expected_remote_video_track.track_identifier = remote_video_track->id(); |
| 1293 expected_remote_video_track.remote_source = true; |
| 1294 expected_remote_video_track.ended = true; |
| 1295 expected_remote_video_track.detached = false; |
| 1296 expected_remote_video_track.frame_width = 1234; |
| 1297 expected_remote_video_track.frame_height = 4321; |
| 1298 EXPECT_TRUE(report->Get(expected_remote_video_track.id())); |
| 1299 EXPECT_EQ(expected_remote_video_track, |
| 1300 report->Get(expected_remote_video_track.id())->cast_to< |
| 1301 RTCMediaStreamTrackStats>()); |
| 1302 } |
| 1303 |
982 TEST_F(RTCStatsCollectorTest, CollectRTCInboundRTPStreamStats_Audio) { | 1304 TEST_F(RTCStatsCollectorTest, CollectRTCInboundRTPStreamStats_Audio) { |
983 MockVoiceMediaChannel* voice_media_channel = new MockVoiceMediaChannel(); | 1305 MockVoiceMediaChannel* voice_media_channel = new MockVoiceMediaChannel(); |
984 cricket::VoiceChannel voice_channel( | 1306 cricket::VoiceChannel voice_channel( |
985 test_->worker_thread(), test_->network_thread(), test_->media_engine(), | 1307 test_->worker_thread(), test_->network_thread(), test_->media_engine(), |
986 voice_media_channel, nullptr, "VoiceContentName", false); | 1308 voice_media_channel, nullptr, "VoiceContentName", false); |
987 | 1309 |
988 cricket::VoiceMediaInfo voice_media_info; | 1310 cricket::VoiceMediaInfo voice_media_info; |
989 voice_media_info.receivers.push_back(cricket::VoiceReceiverInfo()); | 1311 voice_media_info.receivers.push_back(cricket::VoiceReceiverInfo()); |
990 voice_media_info.receivers[0].local_stats.push_back( | 1312 voice_media_info.receivers[0].local_stats.push_back( |
991 cricket::SsrcReceiverInfo()); | 1313 cricket::SsrcReceiverInfo()); |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1313 rtc::scoped_refptr<FakeRTCStatsCollector> collector_; | 1635 rtc::scoped_refptr<FakeRTCStatsCollector> collector_; |
1314 }; | 1636 }; |
1315 | 1637 |
1316 TEST_F(RTCStatsCollectorTestWithFakeCollector, ThreadUsageAndResultsMerging) { | 1638 TEST_F(RTCStatsCollectorTestWithFakeCollector, ThreadUsageAndResultsMerging) { |
1317 collector_->VerifyThreadUsageAndResultsMerging(); | 1639 collector_->VerifyThreadUsageAndResultsMerging(); |
1318 } | 1640 } |
1319 | 1641 |
1320 } // namespace | 1642 } // namespace |
1321 | 1643 |
1322 } // namespace webrtc | 1644 } // namespace webrtc |
OLD | NEW |