78 Commits

Author SHA1 Message Date
Raja Subramanian
b8ddd0f98c Taking interface{} -> any modernize bits (#4204) 2025-12-28 05:22:12 +05:30
Raja Subramanian
1216113b35 Do not need to just clean up receivers. Remove that interface. (#3760)
The tracks are always closed.
2025-06-24 12:54:34 -07:00
Raja Subramanian
13417c01c6 Send mute event only on change (#3537) 2025-03-19 19:22:49 +05:30
Raja Subramanian
23285744ba Server side metrics (#3198)
* mbb WIP

* deps

* WIP

* WIP

* remove unused file

* Switch to enabled

* misc

* deps

* mediatransportutil update

* Typo

* Set ParticipantIdentity in metrics data packets

* use uint32 as JSON decoder does not unmarshal time.Duration
2024-11-25 13:10:48 +05:30
Raja Subramanian
affcd1ffdb Support updating local track features when pending. (#2863) 2024-07-15 23:51:39 +05:30
Raja Subramanian
ef838e4fa2 Indicate if track is expectd to be resumed in onClose callback. (#2800)
That is the main change. Changed variable name to `isExpectedToResume`
everywhere to be consistent.

Planning to use the callback value in relays to determine if the down
track should be closed or switched to a different up track.
2024-06-17 23:51:00 +05:30
Raja Subramanian
73852d0a13 Reduce large sequence number jump threshold for logging. (#2770)
Seeing some unexplained large jumps on remotes across relay. Unclear if
there was a jump on origin side at some point. Reducing threshold for
large jump so that we can catch unexpected jumps more.
2024-06-07 12:36:02 +05:30
Raja Subramanian
79f6506553 Clean up UpdateVideoLayers (#2685) 2024-04-26 12:21:40 +05:30
Raja Subramanian
90b47424b5 Handle UpdateLocalAudioTrack and UpdateLocalVideoTrack. (#2684)
* Handle UpdateLocalAudioTrack and UpdateLocalVideoTrack.

- Update the TrackInfo
- NOTE: populating Stereo and DisableDtx fields although there are
  features now.
- The audio features in UpdateLocalAudioTrack is applied as is,
  i. e. the update has the latest set of features.
- Emits a track update which will broadcast a participant update.

TODO:
-----
- Telemetry event with track update?

* update deps
2024-04-26 12:06:35 +05:30
Paul Wells
0f597e7e46 update protocol (#2593)
* update protocol

* cleanup

* deps
2024-03-21 02:48:26 -07:00
Raja Subramanian
324c5f35cb handle nil resolver. (#2556) 2024-03-08 19:06:28 +05:30
Raja Subramanian
6c94185aa6 Bring back soft close. (#2553)
Remote media track needs it.
2024-03-07 12:52:48 +05:30
Raja Subramanian
6696c1e63d Close published track always. (#2508)
Simplify and close published track always. Avoid the round about path of
unbind to close.
2024-02-25 13:46:55 +05:30
Paul Wells
e5b8e25064 use shared psrpc utils (#2506)
* use shared psrpc utils

* fix

* deps
2024-02-24 00:38:49 -08:00
akarl10
7658e1b60d make 64bit atomics also align on 32bit (#2386)
do this by simply putting them at the front of each struct
see https://pkg.go.dev/sync/atomic#pkg-note-BUG

fixes #2383

Co-authored-by: akarl10 <mike@mwys.mine.bz>
2024-02-17 11:44:55 -08:00
Raja Subramanian
b7147efb87 Close published tracks on participant close (#2446) 2024-02-05 13:41:41 +05:30
Raja Subramanian
bcf9fe3f0f Use a participant worker queue in room. (#2420)
* Use a participant worker queue in room.

Removes selectively needing to call things in goroutine from
participant.

Also, a bit of drive-by clean up.

* spelling

* prevent race

* don't need to remove in goroutine as it is already running in the worker

* worker will get cleaned up in state change callback

* create participant worker only if not created already

* ref count participant worker

* maintain participant list

* clean up oldState
2024-01-28 22:10:35 +05:30
David Zhao
3fe124c87f Log cleanup pass (#2285)
* Log cleanup pass

Demoted a bunch of logs to DEBUG, consolidated logs.

* use context logger and fix context var usage

* moved common error types, fixed tests
2023-12-02 15:07:31 -08:00
Paul Wells
43703538c6 clean up proto logging (#2221) 2023-11-04 10:32:03 -07:00
Raja Subramanian
8c99a9e307 Move GetAudioLevel interface. (#1992)
To allow use with RemoteParticipant/RemoteMediaTrack too.
2023-08-24 13:25:49 +05:30
David Zhao
981fb7cac7 Adding license notices (#1913)
* Adding license notices

* remove from config
2023-07-27 16:43:19 -07:00
Paul Wells
745410bd69 only increment participant version after updates (#1646)
* only increment participant version after updates

* fix test util

* cleanup

* test uptrackmanager permission update version check
2023-04-22 17:48:10 -07:00
Raja Subramanian
65ad4b2c43 Doing a pass at demoting logs (#1531)
A few more candidates to think about demoting
- Publisher mute changes
- Forwarder -> layer lock/upgrade/downgrade/overshoot adjusting
- StreamAllocator
2023-03-20 12:22:08 +05:30
Paul Wells
b35d64ae86 finish timed version migration (#1443)
* finish timed version migration

* update protocol dep
2023-02-18 12:08:08 -08:00
David Zhao
2851a8ac98 Improved robustness of subscription stack (#1382)
UpdateSubscription had a shortcoming where when it couldn't find the
participant, it ignored the request.

This PR further removes the reliance of current publisher state from
subscribers.
- SubscribeToTrack only takes in a trackID
- Introduced RoomTrackManager to maintain all published tracks to a room
- Added TrackUnpublished event to clearly indicate when a track has been removed
- SubscribeRequested event no longer include information about the publisher
2023-02-06 18:08:26 -08:00
David Zhao
cd6b8b80b9 feat: SubscriptionManager to consolidate subscription handling (#1317)
Added a new manager to handle all subscription needs. Implemented using reconciler pattern. The goals are:

improve subscription resilience by separating desired state and current state
reduce complexity of synchronous processing
better detect failures with the ability to trigger full reconnect
2023-01-24 23:06:16 -08:00
David Zhao
17236799bb Fix handling of non-monotonic timestamps (#1304)
* Fix handling of non-monotonic timestamps

Timed version is inspired by Hybrid Clock. We used to have a mixed behavior
by using time.Time:
* during local comparisons, it does increment monotonically
* when deserializing remote timestamps, we lose that attribute

So it's possible for two requests to be sent in the same microsecond, and
for the latter one to be dropped.

To fix that behavior, I'm switching it to keeping timestamps to consolidate
that behavior, and accepting multiple updates in the same ms by incrementing ticks.

Also using @paulwe's idea of a version generator.
2023-01-12 11:57:26 -08:00
David Zhao
112d6fc18b Reduced log verbosity for pieces that are stable (#1274) 2022-12-29 23:47:36 -08:00
Raja Subramanian
086009f05a Do not forward media till peer connection is connected. (#1194)
There were some failures with missing media. The only thing I could
see between working and non-working case is when media forwarding
starts. So, delay media forwarding till peer connection is connected.

Also, add a subscribe op only if a subscribe/unsubscribe queuing is
successful. There was a recent change to not queue a subscribe when
the participant is closed/disconnected. This got the subscribe op
counter out of whack.
2022-11-26 21:42:19 +05:30
Raja Subramanian
3074cb862f Force 'allowed; even on subscription.' (#1187)
Also not holding lock while resolving by sid. Not pretty.
But, we should deprecate SID based permissions.

Also, wire changes, possibly due to redis cluster PR?
2022-11-23 14:13:20 +05:30
Raja Subramanian
fe0502c886 Demote some stable logs to Debugw (#1158)
* Demote some stable logs to Debugw

* Add 'discard message from' to ignore list
2022-11-11 10:17:47 +05:30
David Zhao
1019faa0e6 Cleanup pass through logging (#1073)
* added filtering for noisy pion logs
* demoted some logs to debug
* using consistent trackID / participant / publisher / subscriber terminology
* removed ice candidate log lines, deferring to combined log
2022-10-06 23:48:37 -07:00
Raja Subramanian
30e5037418 Minor clean up of media track & friends module (#1067) 2022-10-04 05:23:18 +05:30
Raja Subramanian
dfc71d5bf8 Add a flag to signal need to close underlying media track. (#1038)
With migration in, once the local track is published, the
remote track should be closed. Add a flag to `RemovePublishedTrack`
to control the close behaviour. Invoke `Close` if specified.

Without, the remote track is not closed if it is waiting to resolve,
i. e. not yet attached. That remote track is left hanging.
2022-09-26 15:32:22 +05:30
Raja Subramanian
34bab018dc Do not initialize subscription version until explicitly set. (#951)
Initializing with current time means some updates are ignored.
Do not initialize until explicitly set.
2022-08-24 20:50:23 +05:30
Raja Subramanian
f5627c3859 Prevent track subscriptions/adding receivers after close (#924)
* Prevent track subscriptions/adding receivers after close

With subscribe/unsubscribe queuing, a subscribe may be
attempted after a call to `RemoveAllSubscribers`.
So, renaming `RemoveAllSubscribers` to `InitiateClose`
and maintaining state that track is in the process of closing.

* Mime specific remove

* Remove unused error

* do not add receiver when closing
2022-08-17 13:07:59 +05:30
Raja Subramanian
d9fdcf8c2b Promoting a few logs to Info (#921)
* Promoting a few logs to Info

Also, adding a couple of more info logs which I will remove later
after some debugging.

* mime type

* Protect pause/max layer

* notify even if not bound
2022-08-16 13:03:14 +05:30
Raja Subramanian
4d7df612ec Refactor DynacastQuality & MediaLossProxy into separate modules (#894)
* WIP commit

* Refactor media loss proxy

* Use DynacastQuality and MediaLossProxy from MediaTrack

* fix test

* Remove unused param

* Remove unused interfaces

* Move interface methods to local

* Split out DynacastManager

* have to add codec to dynacast manager

* RUnlock

* fix restart

* Adding API to force quality and also maintain closed state

* Address PR comments
2022-08-09 11:47:06 +05:30
Raja Subramanian
51073e8918 Use TimedVersion for subscription permission update (#839)
* Use a read version for subscription permission

* Use TimedVersion for subscription permission updates

* Minor clean up

* latest protocol
2022-07-21 08:52:37 +05:30
Raja Subramanian
177061712c Do not hold lock while invoking resolver. (#816)
* Do not hold lock while invoking resolver.

Resolver is in room and it will grab its lock.
It is called from partcipant when checking permissions.
Permissions processing uses the participant lock.
So, not a good idea to call a room function with
participant lock held. Avoid that.

Also, use a full lock in the add/remove subscription
path. This is to ensure that permissions path and
subscription path (like subscribing to new participant's
tracks) do not race. As subscriptions are queued now
on the subscriber side, this should be fine.

* Revoke path resolution in ops queue goroutine

* fix test
2022-07-07 13:24:26 +05:30
Raja Subramanian
ef66404a1a Keep track of pending subscriber operations. (#814)
* Keep track of pending subscriber operations.

This is required to determine if a receiver does not have
any subscription.

* correct spelling of queuing

* lock around hasPermission
2022-07-06 23:48:28 +05:30
Raja Subramanian
7c35184944 Send permissions update on subscribe. (#805)
* Send permissions update on subscribe.

The permission `allowed` update was happening only when
processing pending subscriptions (which happens only on
subscription permissions update).

It is possible that subscription happens through other
paths (like subscribing new participant to tracks).
In that path, we were checking if the track has permissions
and adding to pending. But, we were not checking if
the track is in pending and if it is in there, removing
in on successful subscription and sending an update.
Fix that.

* log more fields in error
2022-07-03 12:17:22 +05:30
Raja Subramanian
1428ab3713 Add logs around permissions handling (#803) 2022-07-03 10:56:00 +05:30
Raja Subramanian
03b0a01aad Use a queue for add/remove subscribe operations. (#797)
* Use a queue for add/remove subscribe operations.

If subscribe/unsubscribe happens very quickly, the subscription
state gets mixed up as things are keyed off of subscriberID.

Use a queue of subscribe operations and process it serially.

* set up callback for down track added

* move the queue on unexpected type

* move the queue if removeSubscirber does not have a subscribed track
2022-07-02 10:52:55 +05:30
Raja Subramanian
856cc1798f RemoveSubscriber while revoking. (#796)
Else, a quick turn around of permissions tries to subscribe
again and the subscriber is already in the subscribed list.
2022-07-01 11:31:47 +05:30
Raja Subramanian
e5f53a0d21 Pass willBeResumed into RemovePublishedTrack (#789) 2022-06-26 11:39:27 +05:30
Raja Subramanian
20512151c6 Prevent subscribe renegotiation if tracks will be resumed. (#781) 2022-06-24 00:06:37 +05:30
David Zhao
7ad51f49f1 Fixed unclean DownTrack close when removed before bound. (#736)
* Fixed unclean DownTrack close when removed before bound.

When a DownTrack is closed before it had a chance to be bound to a
transceiver, we'd skip close and leave it hanging. This is unlikely in
normal operations. However, it can be seen with permissions and
subscription APIs.

* remove remaining peerID references
2022-05-29 22:09:02 -07:00
cnderrauber
f958fbcc1c simulcast codecs support (#720)
simulcast codecs support 

Co-authored-by: David Zhao <dz@livekit.io>
2022-05-27 19:55:50 +08:00
Raja Subramanian
fe8c355a32 Support participant identity in permissions (#663)
* Support participant identity in permissions

It is harder for clients to update permissions by SID as remote
reconnecting means a new SID for that participant. Using participant
identity is a better option.

For now, participant SID is also supported. Internally, it will
get mapped to identity. Server code uses identity throughout after
doing any necessary conversion from SID -> Identity.

* Address comments
2022-05-02 12:35:20 +05:30