mirror of
https://github.com/livekit/livekit.git
synced 2026-06-03 21:51:44 +00:00
9551c52c85
* Normalize mime type and add utilities. An attempt to normalize mime type and avoid string compares remembering to do case insensitive search. Not the best solution. Open to ideas. But, define our own mime types (just in case Pion changes things and Pion also does not have red mime type defined which should be easy to add though) and tried to use it everywhere. But, as we get a bunch of callbacks and info from Pion, needed conversion in more places than I anticipated. And also makes it necessary to carry that cognitive load of what comes from Pion and needing to process it properly. * more locations * test * Paul feedback * MimeType type * more consolidation * Remove unused * test * test * mime type as int * use string method * Pass error details and timeouts. (#3402) * go mod tidy (#3408) * Rename CHANGELOG to CHANGELOG.md (#3391) Enables markdown features in this otherwise already markdown'ish formatted document * Update config.go to properly process bool env vars (#3382) Fixes issue https://github.com/livekit/livekit/issues/3381 * fix(deps): update go deps (#3341) Generated by renovateBot Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Use a Twirp server hook to send API call details to telemetry. (#3401) * Use a Twirp server hook to send API call details to telemetry. * mage generate and clean up * Add project_id * deps * - Redact requests - Do not store responses - Extract top level fields room_name, room_id, participant_identity, participant_id, track_id as appropriate - Store status as int * deps * Update pkg/sfu/mime/mimetype.go * Fix prefer codec test * handle down track mime changes --------- Co-authored-by: Denys Smirnov <dennwc@pm.me> Co-authored-by: Philzen <Philzen@users.noreply.github.com> Co-authored-by: Pablo Fuente Pérez <pablofuenteperez@gmail.com> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Paul Wells <paulwe@gmail.com> Co-authored-by: cnderrauber <zengjie9004@gmail.com>
92 lines
3.0 KiB
Go
92 lines
3.0 KiB
Go
// Copyright 2023 LiveKit, Inc.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package utils
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
|
|
"github.com/livekit/livekit-server/pkg/sfu/mime"
|
|
"github.com/pion/interceptor"
|
|
"github.com/pion/rtp"
|
|
"github.com/pion/webrtc/v4"
|
|
)
|
|
|
|
// Do a fuzzy find for a codec in the list of codecs
|
|
// Used for lookup up a codec in an existing list to find a match
|
|
func CodecParametersFuzzySearch(needle webrtc.RTPCodecParameters, haystack []webrtc.RTPCodecParameters) (webrtc.RTPCodecParameters, error) {
|
|
// First attempt to match on MimeType + SDPFmtpLine
|
|
for _, c := range haystack {
|
|
if mime.IsMimeTypeStringEqual(c.RTPCodecCapability.MimeType, needle.RTPCodecCapability.MimeType) &&
|
|
c.RTPCodecCapability.SDPFmtpLine == needle.RTPCodecCapability.SDPFmtpLine {
|
|
return c, nil
|
|
}
|
|
}
|
|
|
|
// Fallback to just MimeType
|
|
for _, c := range haystack {
|
|
if mime.IsMimeTypeStringEqual(c.RTPCodecCapability.MimeType, needle.RTPCodecCapability.MimeType) {
|
|
return c, nil
|
|
}
|
|
}
|
|
|
|
return webrtc.RTPCodecParameters{}, webrtc.ErrCodecNotFound
|
|
}
|
|
|
|
// Given a CodecParameters find the RTX CodecParameters if one exists
|
|
func FindRTXPayloadType(needle webrtc.PayloadType, haystack []webrtc.RTPCodecParameters) webrtc.PayloadType {
|
|
aptStr := fmt.Sprintf("apt=%d", needle)
|
|
for _, c := range haystack {
|
|
if aptStr == c.SDPFmtpLine {
|
|
return c.PayloadType
|
|
}
|
|
}
|
|
|
|
return webrtc.PayloadType(0)
|
|
}
|
|
|
|
// GetHeaderExtensionID returns the ID of a header extension, or 0 if not found
|
|
func GetHeaderExtensionID(extensions []interceptor.RTPHeaderExtension, extension webrtc.RTPHeaderExtensionCapability) int {
|
|
for _, h := range extensions {
|
|
if extension.URI == h.URI {
|
|
return h.ID
|
|
}
|
|
}
|
|
return 0
|
|
}
|
|
|
|
var (
|
|
ErrInvalidRTPVersion = errors.New("invalid RTP version")
|
|
ErrRTPPayloadTypeMismatch = errors.New("RTP payload type mismatch")
|
|
ErrRTPSSRCMismatch = errors.New("RTP SSRC mismatch")
|
|
)
|
|
|
|
// ValidateRTPPacket checks for a valid RTP packet and returns an error if fields are incorrect
|
|
func ValidateRTPPacket(pkt *rtp.Packet, expectedPayloadType uint8, expectedSSRC uint32) error {
|
|
if pkt.Version != 2 {
|
|
return fmt.Errorf("%w, expected: 2, actual: %d", ErrInvalidRTPVersion, pkt.Version)
|
|
}
|
|
|
|
if expectedPayloadType != 0 && pkt.PayloadType != expectedPayloadType {
|
|
return fmt.Errorf("%w, expected: %d, actual: %d", ErrRTPPayloadTypeMismatch, expectedPayloadType, pkt.PayloadType)
|
|
}
|
|
|
|
if expectedSSRC != 0 && pkt.SSRC != expectedSSRC {
|
|
return fmt.Errorf("%w, expected: %d, actual: %d", ErrRTPSSRCMismatch, expectedSSRC, pkt.SSRC)
|
|
}
|
|
|
|
return nil
|
|
}
|