Try 2 to consolidate mime type (#3407)

* 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>
This commit is contained in:
Raja Subramanian
2025-02-10 10:44:15 +05:30
committed by GitHub
co-authored by Denys Smirnov Philzen Pablo Fuente Pérez renovate[bot] Paul Wells cnderrauber
parent 045bd785a9
commit 9551c52c85
40 changed files with 727 additions and 579 deletions
+5 -5
View File
@@ -22,7 +22,6 @@ import (
"net/http"
"net/url"
"path/filepath"
"strings"
"sync"
"time"
@@ -43,6 +42,7 @@ import (
"github.com/livekit/livekit-server/pkg/rtc/transport/transportfakes"
"github.com/livekit/livekit-server/pkg/rtc/types"
"github.com/livekit/livekit-server/pkg/sfu/buffer"
"github.com/livekit/livekit-server/pkg/sfu/mime"
)
type SignalRequestHandler func(msg *livekit.SignalRequest) error
@@ -103,9 +103,9 @@ var (
},
}
extMimeMapping = map[string]string{
".ivf": webrtc.MimeTypeVP8,
".h264": webrtc.MimeTypeH264,
".ogg": webrtc.MimeTypeOpus,
".ivf": mime.MimeTypeVP8.String(),
".h264": mime.MimeTypeH264.String(),
".ogg": mime.MimeTypeOpus.String(),
}
)
@@ -195,7 +195,7 @@ func NewRTCClient(conn *websocket.Conn, opts *Options) (*RTCClient, error) {
var disabled bool
if opts != nil {
for _, dc := range opts.DisabledCodecs {
if strings.EqualFold(dc.MimeType, codec.Mime) && (dc.SDPFmtpLine == "" || dc.SDPFmtpLine == codec.FmtpLine) {
if mime.IsMimeTypeStringEqual(dc.MimeType, codec.Mime) && (dc.SDPFmtpLine == "" || dc.SDPFmtpLine == codec.FmtpLine) {
disabled = true
break
}
+11 -9
View File
@@ -18,7 +18,6 @@ import (
"context"
"io"
"os"
"strings"
"time"
"github.com/pion/webrtc/v4"
@@ -27,6 +26,7 @@ import (
"github.com/pion/webrtc/v4/pkg/media/ivfreader"
"github.com/pion/webrtc/v4/pkg/media/oggreader"
"github.com/livekit/livekit-server/pkg/sfu/mime"
"github.com/livekit/protocol/logger"
)
@@ -37,7 +37,7 @@ type TrackWriter struct {
cancel context.CancelFunc
track *webrtc.TrackLocalStaticSample
filePath string
mime string
mime mime.MimeType
ogg *oggreader.OggReader
ivfheader *ivfreader.IVFFileHeader
@@ -52,7 +52,7 @@ func NewTrackWriter(ctx context.Context, track *webrtc.TrackLocalStaticSample, f
cancel: cancel,
track: track,
filePath: filePath,
mime: track.Codec().MimeType,
mime: mime.NormalizeMimeType(track.Codec().MimeType),
}
}
@@ -67,23 +67,25 @@ func (w *TrackWriter) Start() error {
return err
}
logger.Debugw("starting track writer",
logger.Debugw(
"starting track writer",
"trackID", w.track.ID(),
"mime", w.mime)
"mime", w.mime,
)
switch w.mime {
case webrtc.MimeTypeOpus:
case mime.MimeTypeOpus:
w.ogg, _, err = oggreader.NewWith(file)
if err != nil {
return err
}
go w.writeOgg()
case webrtc.MimeTypeVP8:
case mime.MimeTypeVP8:
w.ivf, w.ivfheader, err = ivfreader.NewWith(file)
if err != nil {
return err
}
go w.writeVP8()
case webrtc.MimeTypeH264:
case mime.MimeTypeH264:
w.h264, err = h264reader.NewReader(file)
if err != nil {
return err
@@ -104,7 +106,7 @@ func (w *TrackWriter) writeNull() {
for {
select {
case <-time.After(20 * time.Millisecond):
if strings.EqualFold(w.mime, webrtc.MimeTypeH264) {
if w.mime == mime.MimeTypeH264 {
w.track.WriteSample(h264Sample)
} else {
w.track.WriteSample(sample)
+10 -9
View File
@@ -38,6 +38,7 @@ import (
"github.com/livekit/livekit-server/pkg/config"
"github.com/livekit/livekit-server/pkg/rtc"
"github.com/livekit/livekit-server/pkg/sfu/datachannel"
"github.com/livekit/livekit-server/pkg/sfu/mime"
"github.com/livekit/livekit-server/pkg/testutils"
testclient "github.com/livekit/livekit-server/test/client"
)
@@ -156,7 +157,7 @@ func TestSinglePublisher(t *testing.T) {
waitUntilConnected(t, c1, c2)
// publish a track and ensure clients receive it ok
t1, err := c1.AddStaticTrack("audio/opus", "audio", "webcamaudio")
t1, err := c1.AddStaticTrack("audio/OPUS", "audio", "webcamaudio")
require.NoError(t, err)
defer t1.Stop()
t2, err := c1.AddStaticTrack("video/vp8", "video", "webcamvideo")
@@ -280,7 +281,7 @@ func Test_RenegotiationWithDifferentCodecs(t *testing.T) {
tracks := c2.SubscribedTracks()[c1.ID()]
for _, t := range tracks {
if strings.EqualFold(t.Codec().MimeType, "video/vp8") {
if mime.IsMimeTypeStringVP8(t.Codec().MimeType) {
return ""
}
@@ -308,9 +309,9 @@ func Test_RenegotiationWithDifferentCodecs(t *testing.T) {
var vp8Found, h264Found bool
tracks := c2.SubscribedTracks()[c1.ID()]
for _, t := range tracks {
if strings.EqualFold(t.Codec().MimeType, "video/vp8") {
if mime.IsMimeTypeStringVP8(t.Codec().MimeType) {
vp8Found = true
} else if strings.EqualFold(t.Codec().MimeType, "video/h264") {
} else if mime.IsMimeTypeStringH264(t.Codec().MimeType) {
h264Found = true
}
}
@@ -594,8 +595,8 @@ func TestDeviceCodecOverride(t *testing.T) {
hasSeenVP8 := false
for _, a := range desc.Attributes {
if a.Key == "rtpmap" {
require.NotContains(t, a.Value, "H264", "should not contain H264 codec")
if strings.Contains(a.Value, "VP8") {
require.NotContains(t, a.Value, mime.MimeTypeCodecH264.String(), "should not contain H264 codec")
if strings.Contains(a.Value, mime.MimeTypeCodecVP8.String()) {
hasSeenVP8 = true
}
}
@@ -641,7 +642,7 @@ func TestSubscribeToCodecUnsupported(t *testing.T) {
tracks := c2.SubscribedTracks()[c1.ID()]
for _, t := range tracks {
if strings.EqualFold(t.Codec().MimeType, "video/vp8") {
if mime.IsMimeTypeStringVP8(t.Codec().MimeType) {
return ""
}
}
@@ -663,7 +664,7 @@ func TestSubscribeToCodecUnsupported(t *testing.T) {
remoteC1 := c2.GetRemoteParticipant(c1.ID())
require.NotNil(t, remoteC1)
for _, track := range remoteC1.Tracks {
if strings.EqualFold(track.MimeType, "video/h264") {
if mime.IsMimeTypeStringH264(track.MimeType) {
h264TrackID = track.Sid
return true
}
@@ -698,7 +699,7 @@ func TestSubscribeToCodecUnsupported(t *testing.T) {
var vp8Count int
tracks := c2.SubscribedTracks()[c1.ID()]
for _, t := range tracks {
if strings.EqualFold(t.Codec().MimeType, "video/vp8") {
if mime.IsMimeTypeStringVP8(t.Codec().MimeType) {
vp8Count++
}
}