Skip to content

Commit ee4db28

Browse files
authored
Fix RTC stats on desktop platforms (#160)
1 parent eac7fec commit ee4db28

File tree

2 files changed

+38
-33
lines changed

2 files changed

+38
-33
lines changed

crates/libwebrtc-sys/src/cpp/stats.cc

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -101,21 +101,6 @@ RTCOutboundRTPStreamStatsWrap cast_to_rtc_outbound_rtp_stream_stats(
101101
track_id->set_value(rust::String(*cast->remote_id));
102102
}
103103

104-
auto frame_width = init_option_u32();
105-
if (cast->frame_width.has_value()) {
106-
frame_width->set_value(*cast->frame_width);
107-
}
108-
109-
auto frame_height = init_option_u32();
110-
if (cast->frame_width.has_value()) {
111-
frame_width->set_value(*cast->frame_width);
112-
}
113-
114-
auto frames_per_second = init_option_f64();
115-
if (cast->frames_per_second.has_value()) {
116-
frames_per_second->set_value(*cast->frames_per_second);
117-
}
118-
119104
auto bytes_sent = init_option_u64();
120105
if (cast->bytes_sent.has_value()) {
121106
bytes_sent->set_value(*cast->bytes_sent);
@@ -131,7 +116,27 @@ RTCOutboundRTPStreamStatsWrap cast_to_rtc_outbound_rtp_stream_stats(
131116
media_source_id->set_value(rust::String(*cast->media_source_id));
132117
}
133118

134-
MediaKind kind = MediaKind::Video;
119+
auto frame_width = init_option_u32();
120+
auto frame_height = init_option_u32();
121+
auto frames_per_second = init_option_f64();
122+
MediaKind kind;
123+
if (*cast->kind == "audio") {
124+
kind = MediaKind::Audio;
125+
} else {
126+
kind = MediaKind::Video;
127+
128+
if (cast->frame_width.has_value()) {
129+
frame_width->set_value(*cast->frame_width);
130+
}
131+
132+
if (cast->frame_height.has_value()) {
133+
frame_height->set_value(*cast->frame_height);
134+
}
135+
136+
if (cast->frames_per_second.has_value()) {
137+
frames_per_second->set_value(*cast->frames_per_second);
138+
}
139+
}
135140

136141
return RTCOutboundRTPStreamStatsWrap{
137142
std::move(track_id), kind,
@@ -246,22 +251,22 @@ RTCInboundRTPStreamStatsWrap cast_to_rtc_inbound_rtp_stream_stats(
246251
if (cast->frames_received.has_value()) {
247252
frames_received->set_value(*cast->frames_received);
248253
}
254+
}
249255

250-
if (cast->bytes_received.has_value()) {
251-
bytes_received->set_value(*cast->bytes_received);
252-
}
256+
if (cast->bytes_received.has_value()) {
257+
bytes_received->set_value(*cast->bytes_received);
258+
}
253259

254-
if (cast->packets_received.has_value()) {
255-
packets_received->set_value(*cast->packets_received);
256-
}
260+
if (cast->packets_received.has_value()) {
261+
packets_received->set_value(*cast->packets_received);
262+
}
257263

258-
if (cast->total_decode_time.has_value()) {
259-
total_decode_time->set_value(*cast->total_decode_time);
260-
}
261-
if (cast->jitter_buffer_emitted_count.has_value()) {
262-
jitter_buffer_emitted_count->set_value(
263-
*cast->jitter_buffer_emitted_count);
264-
}
264+
if (cast->total_decode_time.has_value()) {
265+
total_decode_time->set_value(*cast->total_decode_time);
266+
}
267+
if (cast->jitter_buffer_emitted_count.has_value()) {
268+
jitter_buffer_emitted_count->set_value(
269+
*cast->jitter_buffer_emitted_count);
265270
}
266271

267272
return RTCInboundRTPStreamStatsWrap{

lib/src/model/stats.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -693,12 +693,12 @@ class RtcOutboundRtpStreamStats extends RtcStatsType {
693693
ffi.RtcStatsType_RtcOutboundRtpStreamStats stats) {
694694
RtcOutboundRtpStreamStatsMediaType? mediaType;
695695
var kind = stats.mediaType.runtimeType.toString().substring(2);
696-
if (kind == 'RtcOutboundRtpStreamStatsKind_Audio') {
696+
if (kind == 'RtcOutboundRtpStreamStatsMediaType_AudioImpl') {
697697
var cast =
698698
stats.mediaType as ffi.RtcOutboundRtpStreamStatsMediaType_Audio;
699699
mediaType = RtcOutboundRtpStreamStatsAudio(
700700
cast.totalSamplesSent, cast.voiceActivityFlag);
701-
} else if (kind == 'RtcOutboundRtpStreamStatsKind_Video') {
701+
} else if (kind == 'RtcOutboundRtpStreamStatsMediaType_VideoImpl') {
702702
var cast =
703703
stats.mediaType as ffi.RtcOutboundRtpStreamStatsMediaType_Video;
704704
mediaType = RtcOutboundRtpStreamStatsVideo(
@@ -919,7 +919,7 @@ class RtcInboundRtpStreamStats extends RtcStatsType {
919919
ffi.RtcStatsType_RtcInboundRtpStreamStats stats) {
920920
RtcInboundRtpStreamMediaType? mediaType;
921921
var type = stats.mediaType.runtimeType.toString().substring(2);
922-
if (type == 'RtcInboundRtpStreamMediaType_Audio') {
922+
if (type == 'RtcInboundRtpStreamMediaType_AudioImpl') {
923923
var cast = stats.mediaType as ffi.RtcInboundRtpStreamMediaType_Audio;
924924
mediaType = RtcInboundRtpStreamAudio(
925925
cast.totalSamplesReceived,
@@ -929,7 +929,7 @@ class RtcInboundRtpStreamStats extends RtcStatsType {
929929
cast.totalAudioEnergy,
930930
cast.totalSamplesDuration,
931931
cast.voiceActivityFlag);
932-
} else if (type == 'RtcInboundRtpStreamMediaType_Video') {
932+
} else if (type == 'RtcInboundRtpStreamMediaType_VideoImpl') {
933933
var cast = stats.mediaType as ffi.RtcInboundRtpStreamMediaType_Video;
934934
mediaType = RtcInboundRtpStreamVideo(
935935
cast.framesDecoded,

0 commit comments

Comments
 (0)