104 Commits

Author SHA1 Message Date
boks1971
c376d0edf9 Match codec order of remote peer
Done when creating a transceiver from remote description to respect
codec order preference of remote peer.

There was a recent change to include partial matches which overwrote
same codecs and also rtx was getting magled.

Change it by removing codecs from search space as matches are found so
that a codec match is applied only once.

Also, move RTX matching to separate block to ensure proper RTXes ar
matched.
2025-08-28 10:15:58 +05:30
SangHo
3e2a804b08 Fix MIME type comparisons to be case-insensitive 2025-04-28 05:33:44 +03:00
Andrés MANELLI
16d809cc6f Add H265 to RegisterDefaultCodecs
H265 will be available by default now
2025-04-22 10:08:22 -04:00
Joe Turki
f03eb7351f Fix linter 2025-04-18 12:29:21 +02:00
Nils Ohlmeier
5676fa4d38 Don't expose new MediaEngine functions 2025-04-15 11:54:34 -06:00
Nils Ohlmeier
be8800d522 Implemented alternative proposal via SettingEngine 2025-04-15 11:54:34 -06:00
Nils Ohlmeier
1f393efc63 Fixed bug in copy() 2025-04-15 11:54:34 -06:00
Manish
29d6e41b97 Add support for multi codec negotiation 2025-04-15 11:54:34 -06:00
Jingyang Kang
334692b122 Add findFECPayloadType (#3084)
#### Description

Before this, any interceptor that tries to read FEC payload type from
`info *interceptor.StreamInfo`, always gets 0. This PR implements the
logic to find FEC payload type.

Also, MimeType consts are moved from mediaengine.go to mimetype.go,
since mediaengine.go is not included in the WASM build.
2025-04-07 20:29:51 +08:00
3DRX
19cdd093c4 Add mime type for flexfec03 and ulpfec 2025-04-01 00:49:10 +08:00
Joe Turki
bdfe07a07c Move ErrCodecAlreadyRegistered to errors.go 2025-03-01 22:18:16 +02:00
Manish
19789447bb Return error if payload type exists in codecs list 2025-03-01 22:02:48 +02:00
Alessandro Ros
969ab684e3 Fix matching codecs with different rate or channels
Currently codecs are matched regardless of the clock
rate and the channel count, and this makes impossible to fully support
codecs that might have a clock rate or channel count different than the
default one, in particular LPCM, PCMU, PCMA and multiopus (the last one
is a custom Opus variant present in the Chrome source code to support
multichannel Opus).

For instance, let's suppose a peer (receiver) wants to receive an audio
track encoded with LPCM, 48khz sample rate and 2 channels. This receiver
doesn't know the audio codec yet, therefore it advertises all supported
sample rates in the SDP:

```
LPCM/44100
LPCM/48000
LPCM/44100/2
LPCM/48000/2
```

The other peer (sender) receives the SDP, but since the clock rate and
channel count are not taken into consideration when matching codecs, the
sender codec `LPCM/48000/2` is wrongly associated with the receiver
codec `LPCM/44100`. The result is that the audio track cannot be decoded
correctly from the receiver side.

This patch fixes the issue and has been running smoothly in MediaMTX for
almost a year.

Unfortunately, in lots of examples and tests, clock rate and/or channels
are not present (and in fact they are producing horrible SDPs that
contain `VP8/0` instead of `VP8/90000` and are incompatible with lots of
servers) therefore this new check causes troubles in existing code. In
order to maintain compatibility, default clock rates and channels are
provided for most codecs.

In the future, it might be better to update examples (i can do it in a
future patch) and remove the exception.
2025-02-15 21:16:47 -05:00
Joe Turki
47c65c81e3 Remove outdated safety comment in RegisterCodec
The removed comment predates the introduction of locks in the
RegisterCodec method.
2025-01-22 10:31:10 -06:00
Joe Turki
feeeebf251 Upgrade golangci-lint, more linters
Introduces new linters, upgrade golangci-lint to version (v1.63.4)
2025-01-18 07:16:06 -06:00
Max Strömberg
99dcc6b7bf Add H265 payloader
Add H265 payloader support to mediaengine using Pion RTP v1.8.11.
2025-01-16 11:58:29 -05:00
Sean DuBois
cbe660b713 Use intersection of codecs to generate rtcp-fb
Update MediaEngine codec creation to take into account remote
and local rtcp-fb. Before we would incorrectly always take
the remote rtcp-fb and ignore local.

Resolves #2943
Resolves #2944
Resolves #1968
2024-12-14 19:32:20 -05:00
Sean DuBois
4541b73b1a Add Retransmission and FEC to TrackLocal
If the MediaEngine contains support for them a SSRC will be generated
appropriately

Co-authored-by: aggresss <aggresss@163.com>
Co-authored-by: Kevin Wang <kevmo314@gmail.com>

Resolves #1989
Resolves #1675
2024-10-03 20:44:49 -07:00
cnderrauber
287d10638d Match header extensions to remote media sections
Firefox would send updated header extension
in renegotiation, e.g. publish a track without
simucalst then renegotiate second track with
simucalst, the two media secontions will have
different rtp header extensions in offer. Need
to match remote header extentions for each
media sections to avoid second track publish
failed.
2024-07-18 12:30:19 +08:00
Sean DuBois
836184c2c1 Update module github.com/pion/rtp to v1.8.4 2024-03-18 14:18:17 -04:00
cnderrauber
2407bf2ed2 Refine rtx support
Always handle header extensions from packet read
from interceptor, let interceptor has consistent
chance to process headers

Fix rtx is not negotiated when there is multiple
codecs has same mime but different profile (H264)

Fix rtx stream info missed when SSRC group attr
shows after base track's ssrc attr.
2024-02-05 22:48:24 +08:00
Woodrow Douglass
13450332a4 Remove the "Unknown" constant
This commit replaces the Unknown constant with
separate constants for each enumeration that
uses it.

Fixes #1293
2023-09-12 13:29:05 -04:00
Sean DuBois
dc4b591c4d Start pion/webrtc/v4
60eea43 is a breaking change
2023-09-05 11:48:14 -04:00
Evan Sonderegger
f0a5355149 Update RegisterDefaultCodecs to match libwebrtc
VP9 has been moved below AV1. Some missing H264 profiles have been added
2023-08-05 15:30:01 -04:00
Sean DuBois
90e3a83b57 Add support to AV1 in play-from-disk
Resolves pion/rtp#190
Resolves pion/rtp#191
2023-07-20 19:42:44 -04:00
Steffen Vogel
683fc837d0 Make repo REUSE compliant 2023-05-05 11:58:49 -04:00
Sean DuBois
bea005909c Improve MediaEngine docs
By default they aren't copied
2023-04-25 13:15:31 -04:00
cnderrauber
89c05b714f Generate unique extmap id for extensions
Generate unique extmap id for extesions with different uri
2022-05-23 17:06:21 -07:00
Adrian Cable
63b4529ca1 Fix conflicting/misassigned extmap IDs on re-offer
This PR addresses an issue whereby under a specific (but not unusual)
circumstance. Pion fails in two different ways to generate the correct
SDP extmap IDs for a track. Some browsers are more picky about this
than others, but Firefox is known to be picky and this issue may be
responsible for some reported incompatibilities.

Sequence to trigger the issue:

* Pion side registers audio & video codecs and audio & video header
  extensions.
* Pion side gets an audio-only offer from the remote, and responds
  with an answer.
* At some later point in time, Pion side wants to add a video track
  and prepares a new offer.
* Extmap IDs in the new offer SDP are usually incorrect
  conflicting/misassigned

Co-authored-by: Hugo Tunius <hugo@lookback.io>
Relates to: webrtc-rs/webrtc#154
2022-05-13 22:18:30 -04:00
Daniele Sluijters
b8fd4d98ea Fix incorrect conversion between integer types
The result of strconv.Atoi uses an architecture dependent bit size. It
is not safe to use when converted to an integer type of a smaller size,
without performing bounds checking.

Instead, use Parse(U)int with the desired base and size. Though this
returns a (u)int64, it can then be safely converted into a (u)int8 etc.
2022-05-09 13:07:42 -04:00
Sean DuBois
315bbfa723 Add AV1 Support
Also include example

Resolves #1670
2022-04-12 10:20:00 -04:00
Sean DuBois
157220e800 Run gofmt to add new build constraints
Also remove some 1.13 specific WASM code
2022-01-17 22:36:01 -05:00
Kevin Wang
7004fbb766 Add H265 and AV1 MimeTypes
This change adds constants for H265 and AV1. Neither are fully
supported in pion, however these constants are still useful and we will
likely send a change to add H265 and AV1 packetizer/depacketizers in
the future.
2022-01-12 11:09:02 -05:00
juberti
be49dbc5cb Use audio negotiated PTs before video builtin PTs
This avoids a bug where negotiating Opus with PT 96 in an audio-only
session results in the VP8 codec being picked for a track (because
96 is the built-in type for VP8).
2022-01-11 15:17:14 -05:00
David Zhao
5f6baf7325 Fixed locking order in SRTP and DataChannel
Two separate potential deadlocks

1. typically the locking order is SRTP first, then DataChannel.
   However, when data channel is opened, it's locking srtp when
   generating an ID.
   It also would return without unlocking when an error is encountered
2. recursive RLock could be potentially problematic. MediaEngine
   contained a section doing so.
2021-11-11 13:06:19 -08:00
Sean DuBois
cffa6afc34 Rollback pion/rtp to v0
Resolves #1908
2021-08-02 18:05:45 -04:00
Ryan Shumate
2d529be571 Improved h264 fmtp line parsing
Implements h264 fmtp parsing based on RFC 6184 Section 8.2.2
2021-07-30 13:23:07 -04:00
Atsushi Watanabe
d544be17d9 Enable VP8 PictureID by default
For using in SLI.
2021-07-29 12:22:36 -04:00
Sean DuBois
a67c66a0c5 Upgrade pion/rtp to v2
Also updates interceptor and srtp
2021-07-29 11:18:41 -04:00
digitalix
f524fea32a Implement SetCodecPreferences in RTPTransceiver
This allows to set supported codecs per transceiver.

Resolves #1847
2021-06-28 10:54:31 -04:00
cnderrauber
d2f672f343 Fixes MediaEngine: codec apt negotiation
codec has apt fmtp can't negotiation because it's
apt payloadtype can't be found in negotiation codecs.
rtx codec must be partial match if apt codec is partial.

Was reverted in eeb67e1

Fixes #1785
2021-04-24 10:00:49 -07:00
Sean DuBois
fbb9051aee Revert "Fixes MediaEngine: codec apt negotiation"
This reverts commit eeb67e1c53.
2021-04-23 10:54:25 -07:00
cnderrauber
eeb67e1c53 Fixes MediaEngine: codec apt negotiation
codec has apt fmtp can't negotiation because it's
apt payloadtype can't be found in negotiation codecs.
2021-04-20 09:04:38 -07:00
Atsushi Watanabe
07d7403cca Parse and compare FmtpLine on codec select
Exact match if fmtp parameters are not inconsistent.

e.g. default OPUS fmtp of the browsers are:
  Chrome:  minptime=10;useinbandfec=1
  Firefox: maxplaybackrate=48000;stereo=1;useinbandfec=1
They should be treated as matched.
2021-03-21 13:41:33 +09:00
David Zhao
e5c8c659ca Improve MediaEngine codec matching
Implement more sophisticated matching to prefer exact
matches over partial ones.
2021-03-04 09:08:59 -08:00
mission-liao
8474033059 Fix updateHeaderExtension for cloned MediaEngine
It addresses the issue that unable to updateHeaderExtension for cloned
MediaEngine, which is resulted from previous commit:

c8b7aa386a
2021-02-17 18:10:19 +08:00
adwpc
7069c5dc05 Fix register the same codec
Otherwise addTransceiverSDP will add duplicate codec sdp
2021-02-16 15:12:34 -08:00
Sean DuBois
24f350c926 Safari's codec matching requires video be upcased
Upcase H264, VP8 and VP9. Otherwise Safari doesn't recognize those
codecs.

Resolves pion/example-webrtc-applications#89
2021-02-11 14:05:04 -08:00
Sean DuBois
c8b7aa386a Disable MediaEngine Copy by Default
If an API is shared between PeerConnections they would use the same
MediaEngine. A MediaEngine contains negotiated PayloadTypes so if the
PeerConnections were answering you would end up in invalid states.

Add DisableMediaEngineCopy to SettingEngine in case user needs old
behavior.

Resolves #1662
2021-02-09 21:31:57 -08:00
Sean DuBois
b5fa979c08 Don't enable RID/MID Extension Headers by default
Chrome is failing to signaling if the remote peer offers RID/MID so
disabling by default.

Relates to pion/example-webrtc-applications#87
2021-02-09 14:01:10 -08:00