Skip to content

Reuse closed m= sections in Firefox#149

Open
snnz wants to merge 19 commits into
versatica:v3from
snnz:firefox-m-reuse
Open

Reuse closed m= sections in Firefox#149
snnz wants to merge 19 commits into
versatica:v3from
snnz:firefox-m-reuse

Conversation

@snnz
Copy link
Copy Markdown

@snnz snnz commented Dec 27, 2020

This PR handles m= sections reuse in Firefox by synchronizing RemoteSdp with the local description regardless of where the new transceiver's section is placed by the browser.

@ibc
Copy link
Copy Markdown
Member

ibc commented Dec 28, 2020

Thanks. AFAIR there is a reason for me to not do this that way in the past, but I cannot recall which one now. I have to take a deeper look to this. IMHO if this works it must be done for all handlers and not just for Firefox.

Comment thread src/handlers/sdp/RemoteSdp.ts Outdated
if (!this._firstMid)
this._firstMid = newMediaSection.mid;

// Append new section to the existing vector and the SDP object
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dot after en of comments.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Comment thread src/handlers/sdp/RemoteSdp.ts Outdated
this._mediaSections.push(newMediaSection);
this._sdpObject.media.push(newMediaSection.getObject());

// Add it to the map
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for all the added comments.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Periods added to the comments.

Comment thread src/handlers/sdp/RemoteSdp.ts Outdated
// Recreate map
this._midToIndex.clear();
for (idx = 0; idx < this._mediaSections.length; ++idx)
this._midToIndex.set(this._mediaSections[idx].mid, idx);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

braces missing.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Braces added.

@ibc
Copy link
Copy Markdown
Member

ibc commented Apr 23, 2024

I will come back to this PR next week.

Copy link
Copy Markdown
Member

@ibc ibc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please explain in detail what this PR does and what it fixes? And why does it allow closing the first media section? That will break/close the ICE connection globally.

@snnz
Copy link
Copy Markdown
Author

snnz commented Apr 24, 2026

It does not allow closing the first media section, since it uses regular _remoteSdp.closeMediaSection function, which checks for the first section.

The purpose of this PR was to allow the Firefox handler to reuse closed media section on sending, as other handlers do. Currently, when some producers are closed, and new ones created later, it just keep adding new media sections to SDP, so in case a lot of producers are created and closed in the lifetime of the connection, SDP can grow quite a lot. The problem with Firefox is that when adding new transceiver, it uses not first available closed section, but the one with media type (audio/video) matching the type of the new transceiver. Thus, the method of finding next media section in the internal array (which seaches for the first closed section) does not work with Firefox. This is why closing any sections was disabled the Firefox handler.
But still Firefox reuses closed media section quite normally. It just that some other method should be used to determine where the new transceiver is landed in the SDP.

I used the fork from which the PR is created in the real system for quite a while without any problems. But recently Firefox started to fail on the mismatching media types in the receiving connection. I took a look at the commits in the upstream, saw the one that fixes that problem, merged the changes into the fork, and the PR was bumped up. After all these years, I almost forgot about it. :)
And actually, I don't remember why rather complex way of dealing with the problem was chosen, with recreating and rearranging entire media sections array. It seems that after the index of the new trainsceiver is found in the local SDP, the mid of the previous section to reuse can be simple obtained by this index, and then used in the same way as in the other handlers. The only addition necessary for RemoteSdp class is a public function that returns media section by index (providing that the index within the boundaries of the array).
Please take a look at the new version, it should be much сlearer what it does.

@ibc
Copy link
Copy Markdown
Member

ibc commented Apr 24, 2026

Thanks. I will check in next week.

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.

3 participants