pion / webrtc

Pure Go implementation of the WebRTC API
https://pion.ly
MIT License
13.44k stars 1.63k forks source link

Issue accessing ICECandidatePairStats #2779

Open danjenkins opened 3 months ago

danjenkins commented 3 months ago

Your environment.

What did you do?

go and grab the candidate pair from the SCTP transport. use that candidate pair to get stats on it

What did you expect?

an ok result and some stats

What happened?

a non ok response and no stats

when you print out what c.statsID is from a candidate pair gathered from pc.SCTP().Transport().ICETransport().GetSelectedCandidatePair() you get no statsID

using this blank statsID results in obviously no data retrieved from the stats report.

However... even if I go and remake the candidate pair stats ID I still get no results...

func (r StatsReport) GetICECandidatePairStats(c *ICECandidatePair) (ICECandidatePairStats, bool) {
    //statsID := c.statsID

    statsID := newICECandidatePairStatsID(c.Local.statsID, c.Remote.statsID)

    fmt.Printf("A-B: %+v\n", statsID)

    stats, ok := r[statsID]
    if !ok {
        fmt.Printf("Stats ID doesnt exist in Stats\n")

        return ICECandidatePairStats{}, false
    }

    candidateStats, ok := stats.(ICECandidatePairStats)
    if !ok {
        return ICECandidatePairStats{}, false
    }
    return candidateStats, true
}

Something isn't right... I know its in the StatsReport

StatsID was created candidate:lVBDYOJqfkVwKbIM/L5ecWIjLzWJ0Fvv-candidate:JbxBaOLbcbgaqbkIV7O/MUFkN54kCH/f

INFO[0002] Offerer Stats                           statsKey="candidate:lVBDYOJqfkVwKbIM/L5ecWIjLzWJ0Fvv-candidate:JbxBaOLbcbgaqbkIV7O/MUFkN54kCH/f" statsValue="{1.717063734593e+12 candidate-pair candidate:lVBDYOJqfkVwKbIM/L5ecWIjLzWJ0Fvv-candidate:JbxBaOLbcbgaqbkIV7O/MUFkN54kCH/f  candidate:lVBDYOJqfkVwKbIM/L5ecWIjLzWJ0Fvv candidate:JbxBaOLbcbgaqbkIV7O/MUFkN54kCH/f succeeded true 0 0 0 0 -6.795364578871e+12 -6.795364578871e+12 -6.795364578871e+12 -6.795364578871e+12 -6.795364578871e+12 0 0 0 0 0 0 0 0 0 0 0 0 -6.795364578871e+12}"

Other than adding some debugging to stats_go.go I haven't gone much further with this yet.

theres two issues here.... the statsID in a candidatePair doesn't seem to get stored properly. When you do have a statsID you still can't retrieve the stat

danjenkins commented 1 month ago

Looking into this a bit more...

If I go get the stats and loop through them...

stats := pc.GetStats()

    for _, report := range stats {
        if candidatePairStats, ok := report.(webrtc.ICECandidatePairStats); ok {
            // Check if this candidate pair is the selected one
            // if candidatePairStats.Nominated {
            fmt.Printf("Candidate Pair %+v\n", candidatePairStats)
            //          }
        }
    }

I end up with stats that don't change... and have no BytesSent/Received etc.

Candidate Pair {Timestamp:1.723193118292e+12 Type:candidate-pair ID:candidate:8P1w36kyIljTeMqueMkM6hdTTDTDdAl8-candidate:utpvQgEY0b4+QBQIb+mLNYNNCHDK1aV6 TransportID: LocalCandidateID:candidate:8P1w36kyIljTeMqueMkM6hdTTDTDdAl8 RemoteCandidateID:candidate:utpvQgEY0b4+QBQIb+mLNYNNCHDK1aV6 State:succeeded Nominated:true PacketsSent:0 PacketsReceived:0 BytesSent:0 BytesReceived:0 LastPacketSentTimestamp:-6.795364578871e+12 LastPacketReceivedTimestamp:-6.795364578871e+12 FirstRequestTimestamp:-6.795364578871e+12 LastRequestTimestamp:-6.795364578871e+12 LastResponseTimestamp:-6.795364578871e+12 TotalRoundTripTime:0 CurrentRoundTripTime:0 AvailableOutgoingBitrate:0 AvailableIncomingBitrate:0 CircuitBreakerTriggerCount:0 RequestsReceived:0 RequestsSent:0 ResponsesReceived:0 ResponsesSent:0 RetransmissionsReceived:0 RetransmissionsSent:0 ConsentRequestsSent:0 ConsentExpiredTimestamp:-6.795364578871e+12}

Are CandidatePairStats even implemented properly?

danjenkins commented 1 month ago

Nope they're not...

https://github.com/pion/ice/blob/master/agent_stats.go#L23-L44