Add sync group mapping to TrackIdStreamLabelMap

Bug: webrtc:11381
Change-Id: I0f4c590d5474d1aa84c8a6e7a8b3fab252b0b3fc
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/178362
Commit-Queue: Andrey Logvin <landrey@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Artem Titov <titovartem@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31601}
This commit is contained in:
Andrey Logvin
2020-07-01 08:32:15 +00:00
committed by Commit Bot
parent ed1fb19be2
commit 20f45823e3
15 changed files with 127 additions and 76 deletions

View File

@ -296,9 +296,10 @@ rtc_source_set("video_quality_analyzer_api") {
]
}
rtc_source_set("track_id_stream_label_map") {
rtc_source_set("track_id_stream_info_map") {
visibility = [ "*" ]
sources = [ "test/track_id_stream_label_map.h" ]
sources = [ "test/track_id_stream_info_map.h" ]
absl_deps = [ "//third_party/abseil-cpp/absl/strings" ]
}
rtc_source_set("rtp_transceiver_direction") {
@ -345,7 +346,7 @@ rtc_source_set("audio_quality_analyzer_api") {
deps = [
":stats_observer_interface",
":track_id_stream_label_map",
":track_id_stream_info_map",
]
}
@ -377,7 +378,7 @@ rtc_source_set("peer_connection_quality_test_fixture_api") {
":rtp_parameters",
":simulated_network_api",
":stats_observer_interface",
":track_id_stream_label_map",
":track_id_stream_info_map",
":video_quality_analyzer_api",
"../media:rtc_media_base",
"../rtc_base:deprecation",

View File

@ -14,7 +14,7 @@
#include <string>
#include "api/test/stats_observer_interface.h"
#include "api/test/track_id_stream_label_map.h"
#include "api/test/track_id_stream_info_map.h"
namespace webrtc {
namespace webrtc_pc_e2e {
@ -31,7 +31,7 @@ class AudioQualityAnalyzerInterface : public StatsObserverInterface {
// stream_id matching. The caller is responsible for ensuring the
// AnalyzerHelper outlives the instance of the AudioQualityAnalyzerInterface.
virtual void Start(std::string test_case_name,
TrackIdStreamLabelMap* analyzer_helper) = 0;
TrackIdStreamInfoMap* analyzer_helper) = 0;
// Will be called by the framework at the end of the test. The analyzer
// has to finalize all its stats and it should report them.

View File

@ -32,7 +32,7 @@
#include "api/test/frame_generator_interface.h"
#include "api/test/simulated_network.h"
#include "api/test/stats_observer_interface.h"
#include "api/test/track_id_stream_label_map.h"
#include "api/test/track_id_stream_info_map.h"
#include "api/test/video_quality_analyzer_interface.h"
#include "api/transport/network_control.h"
#include "api/units/time_delta.h"
@ -416,10 +416,10 @@ class PeerConnectionE2EQualityTestFixture {
// metrics.
// |reporter_helper| is a pointer to a class that will allow track_id to
// stream_id matching. The caller is responsible for ensuring the
// TrackIdStreamLabelMap will be valid from Start() to
// TrackIdStreamInfoMap will be valid from Start() to
// StopAndReportResults().
virtual void Start(absl::string_view test_case_name,
const TrackIdStreamLabelMap* reporter_helper) = 0;
const TrackIdStreamInfoMap* reporter_helper) = 0;
// This method has been added for backwards compatibility with upstream
// project.
void Start(absl::string_view test_case_name) {

View File

@ -0,0 +1,42 @@
/*
* Copyright (c) 2019 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 API_TEST_TRACK_ID_STREAM_INFO_MAP_H_
#define API_TEST_TRACK_ID_STREAM_INFO_MAP_H_
#include "absl/strings/string_view.h"
namespace webrtc {
namespace webrtc_pc_e2e {
// Instances of |TrackIdStreamInfoMap| provide bookkeeping capabilities that
// are useful to associate stats reports track_ids to the remote stream info.
class TrackIdStreamInfoMap {
public:
virtual ~TrackIdStreamInfoMap() = default;
// These methods must be called on the same thread where
// StatsObserverInterface::OnStatsReports is invoked.
// Returns a reference to a stream label owned by the TrackIdStreamInfoMap.
// Precondition: |track_id| must be already mapped to stream label.
virtual absl::string_view GetStreamLabelFromTrackId(
absl::string_view track_id) const = 0;
// Returns a reference to a sync group name owned by the TrackIdStreamInfoMap.
// Precondition: |track_id| must be already mapped to sync group.
virtual absl::string_view GetSyncGroupLabelFromTrackId(
absl::string_view track_id) const = 0;
};
} // namespace webrtc_pc_e2e
} // namespace webrtc
#endif // API_TEST_TRACK_ID_STREAM_INFO_MAP_H_

View File

@ -1,36 +0,0 @@
/*
* Copyright (c) 2019 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 API_TEST_TRACK_ID_STREAM_LABEL_MAP_H_
#define API_TEST_TRACK_ID_STREAM_LABEL_MAP_H_
#include <string>
namespace webrtc {
namespace webrtc_pc_e2e {
// Instances of |TrackIdStreamLabelMap| provide bookkeeping capabilities that
// are useful to associate stats reports track_ids to the remote stream_id.
class TrackIdStreamLabelMap {
public:
virtual ~TrackIdStreamLabelMap() = default;
// This method must be called on the same thread where
// StatsObserverInterface::OnStatsReports is invoked.
// Returns a reference to a stream label owned by the TrackIdStreamLabelMap.
// Precondition: |track_id| must be already mapped to a stream_label.
virtual const std::string& GetStreamLabelFromTrackId(
const std::string& track_id) const = 0;
};
} // namespace webrtc_pc_e2e
} // namespace webrtc
#endif // API_TEST_TRACK_ID_STREAM_LABEL_MAP_H_

View File

@ -534,10 +534,11 @@ if (!build_with_chromium) {
"analyzer_helper.h",
]
deps = [
"../../../api:track_id_stream_label_map",
"../../../api:track_id_stream_info_map",
"../../../rtc_base:macromagic",
"../../../rtc_base/synchronization:sequence_checker",
]
absl_deps = [ "//third_party/abseil-cpp/absl/strings" ]
}
rtc_library("default_audio_quality_analyzer") {
@ -553,13 +554,14 @@ if (!build_with_chromium) {
"../../../api:audio_quality_analyzer_api",
"../../../api:rtc_stats_api",
"../../../api:stats_observer_interface",
"../../../api:track_id_stream_label_map",
"../../../api:track_id_stream_info_map",
"../../../api/units:time_delta",
"../../../api/units:timestamp",
"../../../rtc_base:criticalsection",
"../../../rtc_base:logging",
"../../../rtc_base:rtc_numerics",
]
absl_deps = [ "//third_party/abseil-cpp/absl/strings" ]
}
rtc_library("example_video_quality_analyzer") {
@ -593,7 +595,7 @@ if (!build_with_chromium) {
"../..:perf_test",
"../../../api:peer_connection_quality_test_fixture_api",
"../../../api:rtc_stats_api",
"../../../api:track_id_stream_label_map",
"../../../api:track_id_stream_info_map",
"../../../api/units:data_rate",
"../../../api/units:data_size",
"../../../api/units:time_delta",
@ -601,6 +603,7 @@ if (!build_with_chromium) {
"../../../rtc_base:criticalsection",
"../../../rtc_base:rtc_numerics",
]
absl_deps = [ "//third_party/abseil-cpp/absl/strings" ]
}
rtc_library("default_video_quality_analyzer") {
@ -647,12 +650,13 @@ if (!build_with_chromium) {
"../../../api:network_emulation_manager_api",
"../../../api:peer_connection_quality_test_fixture_api",
"../../../api:rtc_stats_api",
"../../../api:track_id_stream_label_map",
"../../../api:track_id_stream_info_map",
"../../../api/units:data_size",
"../../../rtc_base:criticalsection",
"../../../rtc_base:rtc_event",
"../../../system_wrappers:field_trial",
]
absl_deps = [ "//third_party/abseil-cpp/absl/strings" ]
}
rtc_library("sdp_changer") {

View File

@ -17,9 +17,8 @@
namespace webrtc {
namespace webrtc_pc_e2e {
void DefaultAudioQualityAnalyzer::Start(
std::string test_case_name,
TrackIdStreamLabelMap* analyzer_helper) {
void DefaultAudioQualityAnalyzer::Start(std::string test_case_name,
TrackIdStreamInfoMap* analyzer_helper) {
test_case_name_ = std::move(test_case_name);
analyzer_helper_ = analyzer_helper;
}
@ -53,8 +52,8 @@ void DefaultAudioQualityAnalyzer::OnStatsReports(
sample.jitter_buffer_emitted_count =
stat->jitter_buffer_emitted_count.ValueOrDefault(0ul);
const std::string& stream_label =
analyzer_helper_->GetStreamLabelFromTrackId(*stat->track_identifier);
const std::string stream_label = std::string(
analyzer_helper_->GetStreamLabelFromTrackId(*stat->track_identifier));
rtc::CritScope crit(&lock_);
StatsSample prev_sample = last_stats_sample_[stream_label];

View File

@ -14,8 +14,9 @@
#include <map>
#include <string>
#include "absl/strings/string_view.h"
#include "api/test/audio_quality_analyzer_interface.h"
#include "api/test/track_id_stream_label_map.h"
#include "api/test/track_id_stream_info_map.h"
#include "api/units/time_delta.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/numerics/samples_stats_counter.h"
@ -35,7 +36,7 @@ struct AudioStreamStats {
class DefaultAudioQualityAnalyzer : public AudioQualityAnalyzerInterface {
public:
void Start(std::string test_case_name,
TrackIdStreamLabelMap* analyzer_helper) override;
TrackIdStreamInfoMap* analyzer_helper) override;
void OnStatsReports(
absl::string_view pc_label,
const rtc::scoped_refptr<const RTCStatsReport>& report) override;
@ -63,7 +64,7 @@ class DefaultAudioQualityAnalyzer : public AudioQualityAnalyzerInterface {
webrtc::test::ImproveDirection improve_direction) const;
std::string test_case_name_;
TrackIdStreamLabelMap* analyzer_helper_;
TrackIdStreamInfoMap* analyzer_helper_;
rtc::CriticalSection lock_;
std::map<std::string, AudioStreamStats> streams_stats_ RTC_GUARDED_BY(lock_);

View File

@ -21,7 +21,7 @@ namespace webrtc_pc_e2e {
void VideoQualityMetricsReporter::Start(
absl::string_view test_case_name,
const TrackIdStreamLabelMap* /*reporter_helper*/) {
const TrackIdStreamInfoMap* /*reporter_helper*/) {
test_case_name_ = std::string(test_case_name);
start_time_ = Now();
}

View File

@ -14,8 +14,9 @@
#include <map>
#include <string>
#include "absl/strings/string_view.h"
#include "api/test/peerconnection_quality_test_fixture.h"
#include "api/test/track_id_stream_label_map.h"
#include "api/test/track_id_stream_info_map.h"
#include "api/units/data_size.h"
#include "api/units/timestamp.h"
#include "rtc_base/critical_section.h"
@ -38,7 +39,7 @@ class VideoQualityMetricsReporter
~VideoQualityMetricsReporter() override = default;
void Start(absl::string_view test_case_name,
const TrackIdStreamLabelMap* reporter_helper) override;
const TrackIdStreamInfoMap* reporter_helper) override;
void OnStatsReports(
absl::string_view pc_label,
const rtc::scoped_refptr<const RTCStatsReport>& report) override;

View File

@ -22,16 +22,36 @@ AnalyzerHelper::AnalyzerHelper() {
void AnalyzerHelper::AddTrackToStreamMapping(std::string track_id,
std::string stream_label) {
RTC_DCHECK_RUN_ON(&signaling_sequence_checker_);
track_to_stream_map_.insert({std::move(track_id), std::move(stream_label)});
track_to_stream_map_.insert(
{std::move(track_id), StreamInfo{stream_label, stream_label}});
}
const std::string& AnalyzerHelper::GetStreamLabelFromTrackId(
const std::string& track_id) const {
void AnalyzerHelper::AddTrackToStreamMapping(std::string track_id,
std::string stream_label,
std::string sync_group) {
RTC_DCHECK_RUN_ON(&signaling_sequence_checker_);
auto track_to_stream_pair = track_to_stream_map_.find(track_id);
track_to_stream_map_.insert(
{std::move(track_id),
StreamInfo{std::move(stream_label), std::move(sync_group)}});
}
const AnalyzerHelper::StreamInfo& AnalyzerHelper::GetStreamInfoFromTrackId(
absl::string_view track_id) const {
RTC_DCHECK_RUN_ON(&signaling_sequence_checker_);
auto track_to_stream_pair = track_to_stream_map_.find(std::string(track_id));
RTC_CHECK(track_to_stream_pair != track_to_stream_map_.end());
return track_to_stream_pair->second;
}
absl::string_view AnalyzerHelper::GetStreamLabelFromTrackId(
absl::string_view track_id) const {
return GetStreamInfoFromTrackId(track_id).stream_label;
}
absl::string_view AnalyzerHelper::GetSyncGroupLabelFromTrackId(
absl::string_view track_id) const {
return GetStreamInfoFromTrackId(track_id).sync_group;
}
} // namespace webrtc_pc_e2e
} // namespace webrtc

View File

@ -14,7 +14,8 @@
#include <map>
#include <string>
#include "api/test/track_id_stream_label_map.h"
#include "absl/strings/string_view.h"
#include "api/test/track_id_stream_info_map.h"
#include "rtc_base/synchronization/sequence_checker.h"
#include "rtc_base/thread_annotations.h"
@ -22,25 +23,40 @@ namespace webrtc {
namespace webrtc_pc_e2e {
// This class is a utility that provides bookkeeping capabilities that
// are useful to associate stats reports track_ids to the remote stream_id.
// are useful to associate stats reports track_ids to the remote stream info.
// The framework will populate an instance of this class and it will pass
// it to the Start method of Media Quality Analyzers.
// An instance of AnalyzerHelper must only be accessed from a single
// thread and since stats collection happens on the signaling thread,
// both AddTrackToStreamMapping and GetStreamLabelFromTrackId must be
// invoked from the signaling thread.
class AnalyzerHelper : public TrackIdStreamLabelMap {
// AddTrackToStreamMapping, GetStreamLabelFromTrackId and
// GetSyncGroupLabelFromTrackId must be invoked from the signaling thread. Get
// methods should be invoked only after all data is added. Mixing Get methods
// with adding new data may lead to undefined behaviour.
class AnalyzerHelper : public TrackIdStreamInfoMap {
public:
AnalyzerHelper();
void AddTrackToStreamMapping(std::string track_id, std::string stream_label);
void AddTrackToStreamMapping(std::string track_id,
std::string stream_label,
std::string sync_group);
const std::string& GetStreamLabelFromTrackId(
const std::string& track_id) const override;
absl::string_view GetStreamLabelFromTrackId(
absl::string_view track_id) const override;
absl::string_view GetSyncGroupLabelFromTrackId(
absl::string_view track_id) const override;
private:
struct StreamInfo {
std::string stream_label;
std::string sync_group;
};
const StreamInfo& GetStreamInfoFromTrackId(absl::string_view track_id) const;
SequenceChecker signaling_sequence_checker_;
std::map<std::string, std::string> track_to_stream_map_
std::map<std::string, StreamInfo> track_to_stream_map_
RTC_GUARDED_BY(signaling_sequence_checker_);
};

View File

@ -31,7 +31,7 @@ constexpr char kUseStandardBytesStats[] = "WebRTC-UseStandardBytesStats";
void NetworkQualityMetricsReporter::Start(
absl::string_view test_case_name,
const TrackIdStreamLabelMap* /*reporter_helper*/) {
const TrackIdStreamInfoMap* /*reporter_helper*/) {
test_case_name_ = std::string(test_case_name);
// Check that network stats are clean before test execution.
EmulatedNetworkStats alice_stats = PopulateStats(alice_network_);

View File

@ -13,9 +13,10 @@
#include <string>
#include "absl/strings/string_view.h"
#include "api/test/network_emulation_manager.h"
#include "api/test/peerconnection_quality_test_fixture.h"
#include "api/test/track_id_stream_label_map.h"
#include "api/test/track_id_stream_info_map.h"
#include "api/units/data_size.h"
#include "rtc_base/critical_section.h"
@ -32,7 +33,7 @@ class NetworkQualityMetricsReporter
// Network stats must be empty when this method will be invoked.
void Start(absl::string_view test_case_name,
const TrackIdStreamLabelMap* reporter_helper) override;
const TrackIdStreamInfoMap* reporter_helper) override;
void OnStatsReports(
absl::string_view pc_label,
const rtc::scoped_refptr<const RTCStatsReport>& report) override;

View File

@ -385,8 +385,10 @@ void PeerConnectionE2EQualityTest::OnTrackCallback(
transceiver->receiver()->track();
RTC_CHECK_EQ(transceiver->receiver()->stream_ids().size(), 2)
<< "Expected 2 stream ids: 1st - sync group, 2nd - unique stream label";
std::string sync_group = transceiver->receiver()->stream_ids()[0];
std::string stream_label = transceiver->receiver()->stream_ids()[1];
analyzer_helper_.AddTrackToStreamMapping(track->id(), stream_label);
analyzer_helper_.AddTrackToStreamMapping(track->id(), stream_label,
sync_group);
if (track->kind() != MediaStreamTrackInterface::kVideoKind) {
return;
}