Commit Graph

47 Commits

Author SHA1 Message Date
Raja Subramanian
ee7bb0a1ad Log both estimate and nack ratio when congestion detected (#608) 2022-04-10 12:09:11 +05:30
Raja Subramanian
92009b6428 Consistently stop tickers (#593) 2022-04-05 20:42:06 +05:30
David Colburn
0b8a180554 Code inspection (#581)
* Code inspection

* fix [4]int64 conversiong
2022-03-30 13:49:53 -07:00
Raja Subramanian
f694dad105 Reset available layers when removing all trackers (#575) 2022-03-29 08:16:18 +05:30
Raja Subramanian
757a59fbcd Use windowing for NACK monitoring (#557)
* Use windowing for NACK monitoring

* Fix test
2022-03-23 13:42:29 +05:30
Raja Subramanian
076eb1c8ae Dampen stream allocator (#551)
* WIP commit

* WIP commit

* WIP commit

* format

* NACK window

* Remove layer when it is expected to stop

* Remove debug
2022-03-22 22:23:22 +05:30
Raja Subramanian
0a88dee95e A minimum channel capacity config (#549) 2022-03-22 13:13:48 +05:30
Raja Subramanian
641858832a Address edge case stream allocation (#544)
* Handle an edge in layer lock.

A very edge case
- Available layer: [0, 1, 2], but bitrate is not yet available.
We set it to layer 2 awaiting measurement.
- Measurement for layers 0 and 1 come through.
- Still no key frame for layer 2.
- Finalize layers runs and sees that bitrate is available for 0 and 1.
It finalizes layer 1.
- Layer 1 key frame comes (because we asked key frame of layer 2,
publisher sends key frame for all layers). Locks to layer 1.
- No more events happen to switch to layer 2.

Changes
-------
- Move bit rate measurement to StreamTrackerManager. Allows re-use
in relay.
- Make bit rate availability (from zero -> non-zero) an event
and let it flow through the stream allocation flow so that we
always have an event when bit rate measurement becomes available.
This gets rid of finalization which I was unhappy with it anyway as
it was polling every second.
- Removing REMB stuff from buffer. We do not use it.
It is incorrect anyway. REMB should be ay peer connection level.

* Fix test

* fix test

* Simplify allocate

* Simplify/clean up
2022-03-21 14:53:31 +05:30
Raja Subramanian
d738424173 Catch a few edge cases in stream allocator. (#532)
* Catch a few edge cases in stream allocator.

- More useful logging

* fire probe cluster done callback only when there is an active cluster
2022-03-18 20:42:15 +05:30
Raja Subramanian
b6975bf7cd Track source based stream tracker config (#503)
* Track source based stream tracker config

* SCREEN_SHARE_AUDIO is an audio source
2022-03-11 12:15:12 +05:30
Raja Subramanian
13e21e7c45 Callback queue for a couple of modules (#468)
* callback queue for stream tracker

* Ops queue for down track

* fix test
2022-03-01 09:55:13 +05:30
Raja Subramanian
778d1aa141 utils.AtomicFlag -> atomic.Bool (#466)
* Replacing hand rolled ion-sfu atomic with uber/atomic

* Remove another hand rolled atomic

* utils.AtomicFlag -> atomic.Bool
2022-02-25 12:19:49 +05:30
Raja Subramanian
f209e9319a Reset channel observer in resetState (#449)
* Reset channel observer in resetState

* Spelling fix
2022-02-20 20:52:17 +05:30
Raja Subramanian
1e459e91cc Stream priority (#448) 2022-02-19 13:17:55 +05:30
Raja Subramanian
dd4cec7724 Deleting unused code in stream allocator (#447) 2022-02-18 21:10:52 +05:30
Raja Subramanian
babbfb37aa Include NACK ratio in congestion control (#443)
* WIP commit

* WIP commit

* WIP commit

* WIP commit

* WIP commit

* WIP commit

* WIP commit

* WIP commit

* Clean up

* Remove debug

* Remove unneeded change

* fix test

* Remove incorrect comment

* WIP commit

* Reset probe after estimate trends down

* WIP commit

* variable name change

* WIP commit

* WIP commit

* out-of-order test

* WIP commit

* Clean up

* more strict probe NACKs
2022-02-18 14:21:30 +05:30
Raja Subramanian
d04f4d12d1 Throttle RTX under certain conditions to prevent RTX storm (#440)
* WIP commit

* WIP commit

* WIP commit

* WIP commit

* WIP commit

* WIP commit

* WIP commit

* WIP commit

* Clean up

* Remove debug

* Remove unneeded change

* fix test

* Remove incorrect comment

* WIP commit

* Reset probe after estimate trends down

* WIP commit

* variable name change

* Clean up

* Remove debug logs

* gofmt
2022-02-17 13:33:44 +05:30
Raja Subramanian
0bbed7f0bd Use padding for probing (#434)
* WIP commit

* WIP commit

* WIP commit

* WIP commit

* WIP commit

* WIP commit

* WIP commit

* WIP commit

* Clean up

* Remove debug

* Remove unneeded change

* fix test

* Remove incorrect comment

* Reset probe after estimate trends down
2022-02-17 11:03:23 +05:30
Raja Subramanian
f3a6f58006 Use correct publisher id in stream state update (#432) 2022-02-11 12:09:48 +05:30
Raja Subramanian
a6338992e8 Stop forwarding on congestion (#429)
* WIP commit

* comment out debug stuff
2022-02-11 09:17:53 +05:30
David Colburn
7bbd238188 clean up logs and imports (#400) 2022-02-03 14:20:19 -07:00
Raja Subramanian
247807b2cc Use an atomic flag to stop stream allocator (#395)
* Use an atomic flag to stop stream allocator

* use a mutex for event channel

* RLock while posting event

* lock isStopped flag to prevent posting to closed channel
2022-02-01 12:41:37 +05:30
Raja Subramanian
0178a004dd Compile in send-side bandwidth estimation. (#351)
Still not using it. But, now that Pion has merged the initial
version of GCC (Google Congestion Control) for send side bandwidth
estimation, we can integrate it.

We will enable once we have tested and feel comfortable.
2022-01-19 22:36:41 +05:30
David Colburn
5bea9debb7 Code cleanup (#353) 2022-01-19 02:13:06 -08:00
Raja Subramanian
017ed13338 Prevent multiple resume notifications on track (#334)
* Prevent multiple resume notifications on track

When returning previous allocation as is, reset change to none.
Ideally, would like to have change as a separate return and not in last
allocation. But, also prefer to have last allocation state. For now,
resetting change.

* log bandwidth estimate only on decrease
2022-01-12 23:19:56 +05:30
Raja Subramanian
995c1e8676 type aliases -> type definitions (#312)
* type alias -> type definition

* participantSid -> participantID in a comment

* Update protocol
2022-01-03 12:43:58 +05:30
Raja Subramanian
66a1ffe414 Allow cooperative allocation (#309) 2022-01-01 13:43:34 +05:30
Raja Subramanian
fc95757c7d Do not pause if pause is not allowed (#307) 2021-12-31 09:58:13 +05:30
Raja Subramanian
98586c2490 A simple configuration for congestion control. (#305) 2021-12-31 00:26:29 +05:30
Raja Subramanian
107e7bbb39 Configurable bandwidth estimation side (#298)
* Fix tests

Add back adding track to publishedTracks for testing purposes.

* WIP branch

* Don't know why merge from `master` did not catch this change.

* WIP commit

* Hook up all the bits for TWCC to work

* Fix typo

* WIP commit

* Catch up to latest API

* Move RTP/RTCP info config

* Instantiate GCC/TWCC interceptor only when in use

* comment SSBWE parts

* RTCP feedback in publisher config
2021-12-30 20:09:03 +05:30
Raja Subramanian
ee99a323d2 Publisher controlled flex permissions (#284)
* WIP commit

* Add some tests

* allowedSubscribers uses participant sid

* correct variable name

* correct another variable name

* Add ParticipantSid to SubscriptionPermissionUpdate message

* protocol v0.11.2

* WIP commit

* WIP commit

* fix tests

* Remove unused code

* Close uptrack manager

* Remove duplicate close

* move comment to the correct line where the loop could be long

* Fix disallowed list revocation, thank you Jie

* Remove unneeded interface method

* RemoveSubscriber in Participant

* Clean up disallowed subscriptions and handle permissions on new track addition

* add test for track addition after permission set

* Remove unnecessary check
2021-12-24 14:14:40 +05:30
David Colburn
0b71a46239 missed some typos 2021-12-17 13:25:41 -08:00
David Colburn
faa870de3d Move callbacks out of messageRouter (#269)
* move callbacks out of messageRouter

* OCD

* more OCD

* fix forwarder test

* even more OCD

* maximum OCD

* package name collision, copy lock by value
2021-12-17 13:19:23 -08:00
Raja Subramanian
e504b6678c Deficient state handling when a track needs a change (#261)
* WIP commit

* deficient handling

* Add missing ProvisionalAllocatePrepare

* adjust state on track removal

* Increase test timeout

* - Add comments about cooperative routines
- Take down transition if available in cooperative scheme
- Use layer comparison when taking down transition. Because of when the
  bitrate is measured, it is not always guaranteed bandwidthDelta is -ve
  when moving down.
- Do not add track to stream allocator till bind.

* make comment better

* a bit more clear comments

* Use OnBind on subscribed track
2021-12-16 10:58:34 +05:30
Raja Subramanian
e54ce4f674 Stream Allocator Try 3 (#257)
* Stream Allocator Try 3

Making an intermediate PR to do
- Special treatment for screen share tracks
- When allocating all tracks,
  o try to stream all tracks by starting with the lowest layer
  o multi-pass across tracks to get a more even distribution

Not yet done:
-------------
In deficient state,
o Allocate a specific track on a change
o Steal from other tracks

* Correct sense of managed track

* have to range to copy

* generate

* fix VideoLayers compare

* Use t.simulcasted
2021-12-14 12:48:09 +05:30
David Zhao
8abd734d16 Use participant and room specific loggers (#252) 2021-12-10 15:51:05 -08:00
Raja Subramanian
7948fabce0 StreamAllocator tweaks (#240)
* WIP commit

* test padding only with a gap scenario

* Debug

* Fix video corruption, need buffer to include payload and translated header size

* Revert incorrect change

* Fix VP8 translation to return buffer with proper length

* Restore 7-bit mode

* WIP commit

* Clean up

* More clean up and tests compiling again

* Fix tests
2021-12-08 21:56:07 +05:30
Raja Subramanian
5dc0a43b29 Unit tests for sfu.Forwarder (#239) 2021-12-07 02:51:08 +05:30
Raja Subramanian
45690bc301 Use StreamStateChange with a single list (#235)
* Use StreamStateChange with a single list

Use enum for state change indication on associated track.

* update protocol version
2021-12-04 11:57:23 +05:30
Raja Subramanian
5e7f93c954 Stream allocator - v0.2 (#216)
* Use protocol friendly StreamedTracksUpdate

* WIP commit

* Stream allocator update

* subtract the requested bandwidth as delta from Allocate could be adding to bandwidth

* Calculate delta correctly

* correct comment

* Simplify eventCh per David's suggestion
2021-12-01 01:05:19 +05:30
Raja Subramanian
e996c185ce Simplifying (hopefully) sfu.DownTrack (#213)
* Simplifying (hopefully) sfu.DownTrack

* Remove unnecessary check as pdding only packets are dropped before that check

* Temporal filtering max layer

* - Split out forwarder bits into a separate structure
- Address comments from Jie and David

* Remove debug and unneeded stuff

* Fix test

* Remove unneeded default initialization
2021-11-28 09:15:36 +05:30
Raja Subramanian
092789a08f Stream allocator fixes (#212)
* Stream allocator fixes

- Treat simple track like simulcast track with one layer to make
it stream allocator friendly.

* Address David's comments
2021-11-27 09:22:39 +05:30
Raja Subramanian
98695cdd22 downstream allocator (#155)
* WIP branch to hash out down stream allocator.

* Plug more bits of stream allocator

* update protocol

* remove SignalRequest_Simulcast (#154)

* Plug more bits of stream allocator

* Handle simulcast track available layers change

* WIP branch to hash out down stream allocator.

* Plug more bits of stream allocator

* Handle simulcast track available layers change

* Adopt signature of call to AdjustAllocation

* Move StreamAllocator to PCTransport and allocate only for subscriber.

* Move streamallocator to ion-sfu

* Start/Stop of streamallocator

* Use StreamAllocator for subscriber bandwidth management.

* Do not allocate in ADD_TRACK

* Set payload in constructor

* - Add some logging
- Protocol message to notify clients of paused/resumed streams

* named return

* oops correct sense of isPausing

* Update pkg/sfu/streamallocator.go

Committing David's suggestion.

Co-authored-by: David Zhao <david@davidzhao.com>

* - Log estimate changes/commits.
- Catch more than epsilon change oscillating for long time.

Co-authored-by: David Colburn <xero73@gmail.com>
Co-authored-by: David Zhao <david@davidzhao.com>
2021-11-26 09:11:04 +05:30
Raja Subramanian
2f35128ac2 Prioritize down tracks based on max layer(s) (#202)
Use max layer subscription of down tracks to
prioritize bandwidth allocation. The ordering is
- Highest spatial layer
- Highest temporal layer, if spatial layer matches
- Down track id if both layers match (this is to
  prevent unnecessary re-ordering)

Testing:
--------
(Really need to make a DownTrack interface so that
we can mock it and use it in tests)
For now, just a sanity check.
2021-11-22 23:21:26 +05:30
Raja Subramanian
391e2f8b31 Separate out max layer setting (#201)
Small step on the way to making StreamAllocator prioritization of tracks.
With the new callback into StreamAllocator, the idea is to use the
max layer information to do track prioritization.

Testing:
--------
Sanity check that sample app works
2021-11-22 14:01:25 +05:30
David Zhao
749446274f Use time.Unix instead of UnixMilli (for Go 1.15 compat) 2021-11-08 20:47:41 -08:00
cnderrauber
1e1aaeb86b Separate from ion-sfu (#171)
* Separate from ion-sfu

changes:
1. extract pkg/buffer, twcc, sfu, relay, stats, logger

2. to solve cycle import, move ion-sfu/pkg/logger to pkg/sfu/logger

3. replace pion/ion-sfu => ./
reason: will change import pion/ion-sfu/pkg/* to livekit-server/pkg/*
after this pr merged. Just not change any code in this pr, because it
will confused with the separate code from ion-sfu in review.

* Move code from ion-sfu to pkg/sfu

* fix build error for resovle conflict

Co-authored-by: cnderrauber <zengjie9004@gmail.com>
2021-11-09 12:03:16 +08:00