@@ -396,13 +396,19 @@ bool Room::trySetOnAudioFrameCallback(const std::string& participant_identity, c
396396 std::move (callback), opts)) {
397397 return false ;
398398 }
399+
400+ // If we've already subscribed to the track, handle it immediately
399401 auto track = findSubscribedRemoteTrack (participant_identity, track_name);
400- if (!track) {
401- LK_LOG_ERROR (" Room::trySetOnAudioFrameCallback: track not found for participant={} track_name={}" ,
402- participant_identity, track_name);
403- return false ;
402+ if (track) {
403+ subscription_thread_dispatcher_->handleTrackSubscribed (participant_identity, track_name, track);
404+ } else {
405+ // The track is not subscribed yet. The callback is registered; the reader
406+ // starts when the track is subscribed (see kTrackSubscribed in onEvent).
407+ LK_LOG_DEBUG (
408+ " Room::trySetOnAudioFrameCallback: track not yet subscribed for participant={} track_name={}; "
409+ " callback registered for deferred start" ,
410+ participant_identity, track_name);
404411 }
405- subscription_thread_dispatcher_->handleTrackSubscribed (participant_identity, track_name, track);
406412 return true ;
407413}
408414
@@ -416,13 +422,19 @@ bool Room::trySetOnVideoFrameCallback(const std::string& participant_identity, c
416422 std::move (callback), opts)) {
417423 return false ;
418424 }
425+
426+ // If we've already subscribed to the track, handle it immediately
419427 auto track = findSubscribedRemoteTrack (participant_identity, track_name);
420- if (!track) {
421- LK_LOG_ERROR (" Room::trySetOnVideoFrameCallback: track not found for participant={} track_name={}" ,
422- participant_identity, track_name);
423- return false ;
428+ if (track) {
429+ subscription_thread_dispatcher_->handleTrackSubscribed (participant_identity, track_name, track);
430+ } else {
431+ // The track is not subscribed yet. The callback is registered; the reader
432+ // starts when the track is subscribed (see kTrackSubscribed in onEvent).
433+ LK_LOG_DEBUG (
434+ " Room::trySetOnVideoFrameCallback: track not yet subscribed for participant={} track_name={}; "
435+ " callback registered for deferred start" ,
436+ participant_identity, track_name);
424437 }
425- subscription_thread_dispatcher_->handleTrackSubscribed (participant_identity, track_name, track);
426438 return true ;
427439}
428440
@@ -436,13 +448,19 @@ bool Room::trySetOnVideoFrameEventCallback(const std::string& participant_identi
436448 std::move (callback), opts)) {
437449 return false ;
438450 }
451+
452+ // If we've already subscribed to the track, handle it immediately
439453 auto track = findSubscribedRemoteTrack (participant_identity, track_name);
440- if (!track) {
441- LK_LOG_ERROR (" Room::trySetOnVideoFrameEventCallback: track not found for participant={} track_name={}" ,
442- participant_identity, track_name);
443- return false ;
454+ if (track) {
455+ subscription_thread_dispatcher_->handleTrackSubscribed (participant_identity, track_name, track);
456+ } else {
457+ // The track is not subscribed yet. The callback is registered; the reader
458+ // starts when the track is subscribed (see kTrackSubscribed in onEvent).
459+ LK_LOG_DEBUG (
460+ " Room::trySetOnVideoFrameEventCallback: track not yet subscribed for participant={} track_name={}; "
461+ " callback registered for deferred start" ,
462+ participant_identity, track_name);
444463 }
445- subscription_thread_dispatcher_->handleTrackSubscribed (participant_identity, track_name, track);
446464 return true ;
447465}
448466
0 commit comments