Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SessionID to interceptors #38

Closed
wants to merge 1 commit into from
Closed

Conversation

jeremija
Copy link
Member

@jeremija jeremija commented Apr 22, 2021

Closes #37. This commit addresses the changes discussed here.

I added SessionID to all interceptor methods and ensured that the existing interceptors can be shared by different PeerConnections.

I defined an interceptor.Factory following AtWat's suggestion. It took a while for this to click for me: I didn't realize that the interceptor.Registry contained already prebuilt interceptors. I like the idea of a Factory better than implementing Copy. I added the interceptor.Registry.AddFactory method and modified the internals a little. The new interceptor.NewChainFromFactories will now be called from the Registry.

The interceptor.SharedFactory allows us to easily keep the current behavior with existing interceptors.

I left a number of TODOs which are the main reason the build is currently failing. The main points are:

  1. I think binding anything before calling BindRTCPWriter should be an error, because otherwise it becomes difficult to track state (e.g. if we've started a write loop). But I did not want to add an error return value to all methods before discussing it.

    If we do decide that calling BindRTCPWriter is the first step, then I think it would make sense to pass RTCPWriter as an argument to interceptor.Registry.Build?

  2. We could modify the interceptors to only have a single loop goroutine which would go through all SSRCs for all bound sessions at once, but I'm not sure what's the best way to concurrently handle RTCP writes - I'm sure we wouldn't want a hanging RTCPWrite to slow down any other processing or writes.

    I also don't think that spinning up an unbounded number of goroutines just to do these writes is a good idea, so I'm not sure how to processed. I'm open to suggestions.

    Maybe this shouldn't be a part of this change, but it's something to think about.

@codecov
Copy link

codecov bot commented Apr 22, 2021

Codecov Report

Merging #38 (22fe480) into master (fb01515) will increase coverage by 1.62%.
The diff coverage is 79.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #38      +/-   ##
==========================================
+ Coverage   79.02%   80.65%   +1.62%     
==========================================
  Files          20       22       +2     
  Lines         577      641      +64     
==========================================
+ Hits          456      517      +61     
- Misses         81       82       +1     
- Partials       40       42       +2     
Flag Coverage Δ
go 80.65% <79.33%> (+1.62%) ⬆️
wasm 78.31% <79.33%> (+1.88%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
interceptor.go 66.66% <ø> (ø)
noop.go 71.42% <ø> (ø)
chain.go 35.00% <55.55%> (+35.00%) ⬆️
registry.go 60.00% <60.00%> (+60.00%) ⬆️
pkg/nack/generator_interceptor.go 77.46% <78.72%> (+3.22%) ⬆️
pkg/report/sender_interceptor.go 85.29% <80.64%> (-0.92%) ⬇️
pkg/nack/responder_interceptor.go 68.08% <82.35%> (+2.96%) ⬆️
pkg/report/receiver_interceptor.go 79.48% <82.35%> (+1.87%) ⬆️
factory.go 100.00% <100.00%> (ø)
internal/test/mock_stream.go 74.68% <100.00%> (ø)
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fb01515...22fe480. Read the comment docs.

Closes #37. This commit addresses the changes discussed [here][1].

I added `SessionID` to all interceptor methods and ensured that the
existing interceptors can be shared by different `PeerConnection`s.

I defined an `interceptor.Factory` following AtWat's suggestion. It
took a while for this to click for me: I didn't realize that the
`interceptor.Registry` contained already prebuilt interceptors. I like
the idea of a `Factory` better than implementing `Copy`. I added the
`interceptor.Registry.AddFactory` method and modified the internals a
little. The new `interceptor.NewChainFromFactories` will now be called
from the `Registry`.

The `interceptor.SharedFactory` allows us to easily keep the current
behavior with existing interceptors.

I left a number of TODOs, main bullet points being:

1. I think binding anything before calling `BindRTCPWriter` should be an
   error, because otherwise it becomes difficult to track state (e.g. if
   we've started a write loop). But I did not want to add an error
   return value to all methods before discussing it.

   If we do decide that calling `BindRTCPWriter` is the first step, then
   I think it would make sense to pass `RTCPWriter` as an argument to
   `interceptor.Registry.Build`?

2. We could modify the interceptors to only have a single `loop`
   goroutine which would go through all SSRCs for all bound sessions at
   once, but I'm not sure what's the best way to concurrently handle
   RTCP writes - I'm sure we wouldn't want a hanging RTCPWrite to slow
   down any other processing or writes.

   I also think that spinning up an unbounded number of goroutines just
   to do these writes is not a good idea, so I'm not sure how to
   processed. I'm open to suggestions.

   Maybe this shouldn't be a part of this change, but it's something to
   think about.

[1]: pion/webrtc#1749
@Sean-Der
Copy link
Member

Fixed with fd0ded9

We instead went with a factory pattern. State can now be re-used inside of them.

@Sean-Der Sean-Der closed this Nov 15, 2021
@Sean-Der Sean-Der deleted the jeremija/issue-1749 branch November 15, 2021 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Interceptors cannot be shared between different sessions
2 participants