Index: webrtc/api/rtcstatscollector_unittest.cc |
diff --git a/webrtc/api/rtcstatscollector_unittest.cc b/webrtc/api/rtcstatscollector_unittest.cc |
index e03238423870c6dbd2e34ab07a417d31e7077af4..fd57ad5970622276f9bdb8e6d15cddceb8ad8b15 100644 |
--- a/webrtc/api/rtcstatscollector_unittest.cc |
+++ b/webrtc/api/rtcstatscollector_unittest.cc |
@@ -15,9 +15,10 @@ |
#include <string> |
#include <vector> |
+#include "webrtc/api/jsepsessiondescription.h" |
#include "webrtc/api/mediastream.h" |
#include "webrtc/api/mediastreamtrack.h" |
-#include "webrtc/api/jsepsessiondescription.h" |
+#include "webrtc/api/rtpparameters.h" |
#include "webrtc/api/stats/rtcstats_objects.h" |
#include "webrtc/api/stats/rtcstatsreport.h" |
#include "webrtc/api/test/mock_datachannel.h" |
@@ -52,6 +53,10 @@ void PrintTo(const RTCCertificateStats& stats, ::std::ostream* os) { |
*os << stats.ToString(); |
} |
+void PrintTo(const RTCCodecStats& stats, ::std::ostream* os) { |
+ *os << stats.ToString(); |
+} |
+ |
void PrintTo(const RTCDataChannelStats& stats, ::std::ostream* os) { |
*os << stats.ToString(); |
} |
@@ -806,6 +811,117 @@ TEST_F(RTCStatsCollectorTest, CollectRTCCertificateStatsSingle) { |
ExpectReportContainsCertificateInfo(report, *remote_certinfo.get()); |
} |
+TEST_F(RTCStatsCollectorTest, CollectRTCCodecStats) { |
+ MockVoiceMediaChannel* voice_media_channel = new MockVoiceMediaChannel(); |
+ cricket::VoiceChannel voice_channel( |
+ test_->worker_thread(), test_->network_thread(), test_->media_engine(), |
+ voice_media_channel, nullptr, "VoiceContentName", false); |
+ |
+ MockVideoMediaChannel* video_media_channel = new MockVideoMediaChannel(); |
+ cricket::VideoChannel video_channel( |
+ test_->worker_thread(), test_->network_thread(), video_media_channel, |
+ nullptr, "VideoContentName", false); |
Taylor Brandstetter
2016/11/17 22:01:51
To test the scenario I described where a payload t
|
+ |
+ // Audio |
+ cricket::VoiceMediaInfo voice_media_info; |
+ |
+ RtpCodecParameters inbound_audio_codec; |
+ inbound_audio_codec.payload_type = 1; |
+ inbound_audio_codec.mime_type = "opus"; |
+ inbound_audio_codec.clock_rate = 1337; |
+ voice_media_info.receive_codecs.insert( |
+ std::make_pair(inbound_audio_codec.payload_type, inbound_audio_codec)); |
+ |
+ RtpCodecParameters outbound_audio_codec; |
+ outbound_audio_codec.payload_type = 2; |
+ outbound_audio_codec.mime_type = "isac"; |
+ outbound_audio_codec.clock_rate = 1338; |
+ voice_media_info.send_codecs.insert( |
+ std::make_pair(outbound_audio_codec.payload_type, outbound_audio_codec)); |
+ |
+ EXPECT_CALL(*voice_media_channel, GetStats(_)) |
+ .WillOnce(DoAll(SetArgPointee<0>(voice_media_info), Return(true))); |
+ |
+ // Video |
+ cricket::VideoMediaInfo video_media_info; |
+ |
+ RtpCodecParameters inbound_video_codec; |
+ inbound_video_codec.payload_type = 3; |
+ inbound_video_codec.mime_type = "H264"; |
+ inbound_video_codec.clock_rate = 1339; |
+ video_media_info.receive_codecs.insert( |
+ std::make_pair(inbound_video_codec.payload_type, inbound_video_codec)); |
+ |
+ RtpCodecParameters outbound_video_codec; |
+ outbound_video_codec.payload_type = 4; |
+ outbound_video_codec.mime_type = "VP8"; |
+ outbound_video_codec.clock_rate = 1340; |
+ video_media_info.send_codecs.insert( |
+ std::make_pair(outbound_video_codec.payload_type, outbound_video_codec)); |
+ |
+ EXPECT_CALL(*video_media_channel, GetStats(_)) |
+ .WillOnce(DoAll(SetArgPointee<0>(video_media_info), Return(true))); |
+ |
+ SessionStats session_stats; |
+ session_stats.proxy_to_transport["VoiceContentName"] = "TransportName"; |
+ session_stats.proxy_to_transport["VideoContentName"] = "TransportName"; |
+ session_stats.transport_stats["TransportName"].transport_name = |
+ "TransportName"; |
+ |
+ EXPECT_CALL(test_->session(), GetTransportStats(_)) |
+ .WillRepeatedly(DoAll(SetArgPointee<0>(session_stats), Return(true))); |
+ EXPECT_CALL(test_->session(), voice_channel()) |
+ .WillRepeatedly(Return(&voice_channel)); |
+ EXPECT_CALL(test_->session(), video_channel()) |
+ .WillRepeatedly(Return(&video_channel)); |
+ |
+ rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); |
+ |
+ RTCCodecStats expected_inbound_audio_codec( |
+ "RTCCodec_InboundAudio_1", report->timestamp_us()); |
+ expected_inbound_audio_codec.payload_type = 1; |
+ expected_inbound_audio_codec.codec = "audio/opus"; |
+ expected_inbound_audio_codec.clock_rate = 1337; |
+ |
+ RTCCodecStats expected_outbound_audio_codec( |
+ "RTCCodec_OutboundAudio_2", report->timestamp_us()); |
+ expected_outbound_audio_codec.payload_type = 2; |
+ expected_outbound_audio_codec.codec = "audio/isac"; |
+ expected_outbound_audio_codec.clock_rate = 1338; |
+ |
+ RTCCodecStats expected_inbound_video_codec( |
+ "RTCCodec_InboundVideo_3", report->timestamp_us()); |
+ expected_inbound_video_codec.payload_type = 3; |
+ expected_inbound_video_codec.codec = "video/H264"; |
+ expected_inbound_video_codec.clock_rate = 1339; |
+ |
+ RTCCodecStats expected_outbound_video_codec( |
+ "RTCCodec_OutboundVideo_4", report->timestamp_us()); |
+ expected_outbound_video_codec.payload_type = 4; |
+ expected_outbound_video_codec.codec = "video/VP8"; |
+ expected_outbound_video_codec.clock_rate = 1340; |
+ |
+ ASSERT(report->Get(expected_inbound_audio_codec.id())); |
+ EXPECT_EQ(expected_inbound_audio_codec, |
+ report->Get(expected_inbound_audio_codec.id())->cast_to< |
+ RTCCodecStats>()); |
+ |
+ ASSERT(report->Get(expected_outbound_audio_codec.id())); |
+ EXPECT_EQ(expected_outbound_audio_codec, |
+ report->Get(expected_outbound_audio_codec.id())->cast_to< |
+ RTCCodecStats>()); |
+ |
+ ASSERT(report->Get(expected_inbound_video_codec.id())); |
+ EXPECT_EQ(expected_inbound_video_codec, |
+ report->Get(expected_inbound_video_codec.id())->cast_to< |
+ RTCCodecStats>()); |
+ |
+ ASSERT(report->Get(expected_outbound_video_codec.id())); |
+ EXPECT_EQ(expected_outbound_video_codec, |
+ report->Get(expected_outbound_video_codec.id())->cast_to< |
+ RTCCodecStats>()); |
+} |
+ |
TEST_F(RTCStatsCollectorTest, CollectRTCCertificateStatsMultiple) { |
std::unique_ptr<CertificateInfo> audio_local_certinfo = |
CreateFakeCertificateAndInfoFromDers( |
@@ -1326,6 +1442,7 @@ TEST_F(RTCStatsCollectorTest, CollectRTCInboundRTPStreamStats_Audio) { |
voice_media_info.receivers[0].local_stats[0].ssrc = 1; |
voice_media_info.receivers[0].packets_rcvd = 2; |
voice_media_info.receivers[0].bytes_rcvd = 3; |
+ voice_media_info.receivers[0].codec_payload_type = rtc::Optional<int>(42); |
voice_media_info.receivers[0].jitter_ms = 4500; |
voice_media_info.receivers[0].fraction_lost = 5.5f; |
EXPECT_CALL(*voice_media_channel, GetStats(_)) |
@@ -1356,6 +1473,7 @@ TEST_F(RTCStatsCollectorTest, CollectRTCInboundRTPStreamStats_Audio) { |
expected_audio.media_type = "audio"; |
expected_audio.transport_id = "RTCTransport_TransportName_" + |
rtc::ToString<>(cricket::ICE_CANDIDATE_COMPONENT_RTP); |
+ expected_audio.codec_id = "RTCCodec_InboundAudio_42"; |
expected_audio.packets_received = 2; |
expected_audio.bytes_received = 3; |
expected_audio.jitter = 4.5; |
@@ -1383,6 +1501,7 @@ TEST_F(RTCStatsCollectorTest, CollectRTCInboundRTPStreamStats_Video) { |
video_media_info.receivers[0].packets_rcvd = 2; |
video_media_info.receivers[0].bytes_rcvd = 3; |
video_media_info.receivers[0].fraction_lost = 4.5f; |
+ video_media_info.receivers[0].codec_payload_type = rtc::Optional<int>(42); |
EXPECT_CALL(*video_media_channel, GetStats(_)) |
.WillOnce(DoAll(SetArgPointee<0>(video_media_info), Return(true))); |
@@ -1404,23 +1523,24 @@ TEST_F(RTCStatsCollectorTest, CollectRTCInboundRTPStreamStats_Video) { |
rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); |
- RTCInboundRTPStreamStats expected_audio( |
+ RTCInboundRTPStreamStats expected_video( |
"RTCInboundRTPVideoStream_1", report->timestamp_us()); |
- expected_audio.ssrc = "1"; |
- expected_audio.is_remote = false; |
- expected_audio.media_type = "video"; |
- expected_audio.transport_id = "RTCTransport_TransportName_" + |
+ expected_video.ssrc = "1"; |
+ expected_video.is_remote = false; |
+ expected_video.media_type = "video"; |
+ expected_video.transport_id = "RTCTransport_TransportName_" + |
rtc::ToString<>(cricket::ICE_CANDIDATE_COMPONENT_RTP); |
- expected_audio.packets_received = 2; |
- expected_audio.bytes_received = 3; |
- expected_audio.fraction_lost = 4.5; |
+ expected_video.codec_id = "RTCCodec_InboundVideo_42"; |
hta-webrtc
2016/11/23 07:37:35
Nit: Since IDs are defined by the spec to be opaqu
hbos
2016/11/23 09:40:59
Done here and three other places. (in/out audio/vi
|
+ expected_video.packets_received = 2; |
+ expected_video.bytes_received = 3; |
+ expected_video.fraction_lost = 4.5; |
- ASSERT(report->Get(expected_audio.id())); |
+ ASSERT(report->Get(expected_video.id())); |
const RTCInboundRTPStreamStats& audio = report->Get( |
- expected_audio.id())->cast_to<RTCInboundRTPStreamStats>(); |
- EXPECT_EQ(audio, expected_audio); |
+ expected_video.id())->cast_to<RTCInboundRTPStreamStats>(); |
+ EXPECT_EQ(audio, expected_video); |
- EXPECT_TRUE(report->Get(*expected_audio.transport_id)); |
+ EXPECT_TRUE(report->Get(*expected_video.transport_id)); |
} |
TEST_F(RTCStatsCollectorTest, CollectRTCOutboundRTPStreamStats_Audio) { |
@@ -1436,6 +1556,7 @@ TEST_F(RTCStatsCollectorTest, CollectRTCOutboundRTPStreamStats_Audio) { |
voice_media_info.senders[0].packets_sent = 2; |
voice_media_info.senders[0].bytes_sent = 3; |
voice_media_info.senders[0].rtt_ms = 4500; |
+ voice_media_info.senders[0].codec_payload_type = rtc::Optional<int>(42); |
EXPECT_CALL(*voice_media_channel, GetStats(_)) |
.WillOnce(DoAll(SetArgPointee<0>(voice_media_info), Return(true))); |
@@ -1464,6 +1585,7 @@ TEST_F(RTCStatsCollectorTest, CollectRTCOutboundRTPStreamStats_Audio) { |
expected_audio.media_type = "audio"; |
expected_audio.transport_id = "RTCTransport_TransportName_" + |
rtc::ToString<>(cricket::ICE_CANDIDATE_COMPONENT_RTP); |
+ expected_audio.codec_id = "RTCCodec_OutboundAudio_42"; |
hta-webrtc
2016/11/23 07:37:35
As above.
hbos
2016/11/23 09:40:59
Done.
|
expected_audio.packets_sent = 2; |
expected_audio.bytes_sent = 3; |
expected_audio.round_trip_time = 4.5; |
@@ -1492,6 +1614,7 @@ TEST_F(RTCStatsCollectorTest, CollectRTCOutboundRTPStreamStats_Video) { |
video_media_info.senders[0].packets_sent = 5; |
video_media_info.senders[0].bytes_sent = 6; |
video_media_info.senders[0].rtt_ms = 7500; |
+ video_media_info.senders[0].codec_payload_type = rtc::Optional<int>(42); |
EXPECT_CALL(*video_media_channel, GetStats(_)) |
.WillOnce(DoAll(SetArgPointee<0>(video_media_info), Return(true))); |
@@ -1520,6 +1643,7 @@ TEST_F(RTCStatsCollectorTest, CollectRTCOutboundRTPStreamStats_Video) { |
expected_video.media_type = "video"; |
expected_video.transport_id = "RTCTransport_TransportName_" + |
rtc::ToString<>(cricket::ICE_CANDIDATE_COMPONENT_RTP); |
+ expected_video.codec_id = "RTCCodec_OutboundVideo_42"; |
expected_video.fir_count = 2; |
expected_video.pli_count = 3; |
expected_video.nack_count = 4; |