Files
webrtc/internal/fmtp/av1.go
aler9 31c2c0dfc1 Fix AV1 and VP9 codec matching
Currently, AV1 or VP9 formats are matched regardless of the profile
parameter. This was not noticeable until browsers started advertising
multiple VP9 formats at the same time, each with a different profile
ID, in order to allow the counterpart to send different streams on the
basis of supported profiles.

This causes two issues: first, the library includes in the SDP all
formats passed by the browser, regardless of the fact that the profile
ID is registered in the API or not. Then, the library is unable to
choose the correct format for streaming, causing an intermittent
failure.

This patch fixes the matching algorithm and also covers the case in
which the profile ID is missing, by using values dictated by
specifications.

Tests were refactored since previous ones covered the same lines
multiple times.
2024-06-25 22:10:39 +02:00

41 lines
750 B
Go

// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT
package fmtp
type av1FMTP struct {
parameters map[string]string
}
func (h *av1FMTP) MimeType() string {
return "video/av1"
}
func (h *av1FMTP) Match(b FMTP) bool {
c, ok := b.(*av1FMTP)
if !ok {
return false
}
// AV1 RTP specification:
// If the profile parameter is not present, it MUST be inferred to be 0 (“Main” profile).
hProfile, ok := h.parameters["profile"]
if !ok {
hProfile = "0"
}
cProfile, ok := c.parameters["profile"]
if !ok {
cProfile = "0"
}
if hProfile != cProfile {
return false
}
return true
}
func (h *av1FMTP) Parameter(key string) (string, bool) {
v, ok := h.parameters[key]
return v, ok
}