Skip to content

Commit ab00289

Browse files
committed
Set the mHasSentInitialICECandidates from WebRTCProviderManager
1 parent b73c542 commit ab00289

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

examples/camera-app/linux/include/webrtc-transport.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ class WebrtcTransport : public Transport
137137
void SetRequestArgs(const RequestArgs & args);
138138
RequestArgs & GetRequestArgs();
139139

140+
void SetHasSentInitialICECandidates(bool hasSent) { mHasSentInitialICECandidates = hasSent; }
141+
bool GetHasSentInitialICECandidates() const { return mHasSentInitialICECandidates; }
142+
140143
private:
141144
CommandType mCommandType = CommandType::kUndefined;
142145
State mState = State::Idle;

examples/camera-app/linux/src/clusters/webrtc-provider/webrtc-provider-manager.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,10 @@ CHIP_ERROR WebRTCProviderManager::HandleProvideAnswer(uint16_t sessionId, const
369369
transport->MoveToState(WebrtcTransport::State::SendingICECandidates);
370370
ScheduleICECandidatesSend(sessionId);
371371

372+
// Set the flag after successfully handling the answer and scheduling ICE candidates
373+
transport->SetHasSentInitialICECandidates(true);
374+
ChipLogProgress(Camera, "Initial ICE candidates batch will be sent for sessionID: %u, trickle ICE enabled", sessionId);
375+
372376
return CHIP_NO_ERROR;
373377
}
374378

@@ -409,6 +413,13 @@ CHIP_ERROR WebRTCProviderManager::HandleProvideICECandidates(uint16_t sessionId,
409413
transport->MoveToState(WebrtcTransport::State::SendingICECandidates);
410414
ScheduleICECandidatesSend(sessionId);
411415

416+
if (!transport->GetHasSentInitialICECandidates())
417+
{
418+
// Set the flag after successfully handling ICE candidates
419+
transport->SetHasSentInitialICECandidates(true);
420+
ChipLogProgress(Camera, "Initial ICE candidates batch will be sent for sessionID: %u, trickle ICE enabled", sessionId);
421+
}
422+
412423
return CHIP_NO_ERROR;
413424
}
414425

@@ -712,6 +723,10 @@ void WebRTCProviderManager::OnDeviceConnected(void * context, Messaging::Exchang
712723
}
713724

714725
err = self->SendEndCommand(exchangeMgr, sessionHandle, sessionId, endReason);
726+
727+
// Unset the flag when session closes
728+
transport->SetHasSentInitialICECandidates(false);
729+
715730
// Release the Video and Audio Streams from the CameraAVStreamManagement
716731
// cluster and update the reference counts.
717732
self->ReleaseAudioVideoStreams(sessionId);

examples/camera-app/linux/src/webrtc-transport.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,6 @@ const char * WebrtcTransport::GetStateStr() const
128128

129129
void WebrtcTransport::MoveToState(const State targetState)
130130
{
131-
// When transitioning from SendingICECandidates to Idle for the first time, enable trickle ICE mode
132-
// (subsequent transitions will be for trickle ICE updates, so we only set the flag once)
133-
if (mState == State::SendingICECandidates && targetState == State::Idle && !mHasSentInitialICECandidates)
134-
{
135-
mHasSentInitialICECandidates = true;
136-
ChipLogProgress(Camera, "Initial ICE candidates batch sent for sessionID: %u, trickle ICE enabled", mRequestArgs.sessionId);
137-
}
138-
139131
mState = targetState;
140132
ChipLogProgress(Camera, "WebrtcTransport moving to [ %s ]", GetStateStr());
141133
}

0 commit comments

Comments
 (0)