mirror of
https://github.com/livekit/livekit.git
synced 2026-08-07 01:49:47 +00:00
Added Xiaomi 2201117TI to devices that does not support H.264 (#1728)
This commit is contained in:
+25
-2
@@ -48,6 +48,7 @@ type RTCClient struct {
|
||||
publisherFullyEstablished atomic.Bool
|
||||
subscriberFullyEstablished atomic.Bool
|
||||
pongReceivedAt atomic.Int64
|
||||
lastAnswer atomic.Pointer[webrtc.SessionDescription]
|
||||
|
||||
// tracks waiting to be acked, cid => trackInfo
|
||||
pendingPublishedTracks map[string]*livekit.TrackInfo
|
||||
@@ -81,6 +82,7 @@ var (
|
||||
type Options struct {
|
||||
AutoSubscribe bool
|
||||
Publish string
|
||||
ClientInfo *livekit.ClientInfo
|
||||
}
|
||||
|
||||
func NewWebSocketConn(host, token string, opts *Options) (*websocket.Conn, error) {
|
||||
@@ -93,8 +95,18 @@ func NewWebSocketConn(host, token string, opts *Options) (*websocket.Conn, error
|
||||
|
||||
connectUrl := u.String()
|
||||
if opts != nil {
|
||||
connectUrl = fmt.Sprintf("%s&auto_subscribe=%t&publish=%s",
|
||||
connectUrl, opts.AutoSubscribe, opts.Publish)
|
||||
connectUrl = fmt.Sprintf("%s&auto_subscribe=%t", connectUrl, opts.AutoSubscribe)
|
||||
if opts.Publish != "" {
|
||||
connectUrl += encodeQueryParam("publish", opts.Publish)
|
||||
}
|
||||
if opts.ClientInfo != nil {
|
||||
if opts.ClientInfo.DeviceModel != "" {
|
||||
connectUrl += encodeQueryParam("device_model", opts.ClientInfo.DeviceModel)
|
||||
}
|
||||
if opts.ClientInfo.Os != "" {
|
||||
connectUrl += encodeQueryParam("os", opts.ClientInfo.Os)
|
||||
}
|
||||
}
|
||||
}
|
||||
conn, _, err := websocket.DefaultDialer.Dial(connectUrl, requestHeader)
|
||||
return conn, err
|
||||
@@ -610,6 +622,11 @@ func (c *RTCClient) GetPublishedTrackIDs() []string {
|
||||
return trackIDs
|
||||
}
|
||||
|
||||
// LastAnswer return SDP of the last answer for the publisher connection
|
||||
func (c *RTCClient) LastAnswer() *webrtc.SessionDescription {
|
||||
return c.lastAnswer.Load()
|
||||
}
|
||||
|
||||
func (c *RTCClient) ensurePublisherConnected() error {
|
||||
if c.publisher.HasEverConnected() {
|
||||
return nil
|
||||
@@ -654,6 +671,8 @@ func (c *RTCClient) handleOffer(desc webrtc.SessionDescription) {
|
||||
// the client handles answer on the publisher PC
|
||||
func (c *RTCClient) handleAnswer(desc webrtc.SessionDescription) {
|
||||
logger.Infow("handling server answer", "participant", c.localParticipant.Identity)
|
||||
|
||||
c.lastAnswer.Store(&desc)
|
||||
// remote answered the offer, establish connection
|
||||
c.publisher.HandleRemoteDescription(desc)
|
||||
}
|
||||
@@ -744,3 +763,7 @@ func (c *RTCClient) SendNacks(count int) {
|
||||
|
||||
_ = c.subscriber.WriteRTCP(packets)
|
||||
}
|
||||
|
||||
func encodeQueryParam(key, value string) string {
|
||||
return fmt.Sprintf("&%s=%s", url.QueryEscape(key), url.QueryEscape(value))
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/pion/sdp/v3"
|
||||
"github.com/pion/webrtc/v3"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/thoas/go-funk"
|
||||
@@ -22,6 +23,11 @@ import (
|
||||
testclient "github.com/livekit/livekit-server/test/client"
|
||||
)
|
||||
|
||||
const (
|
||||
waitTick = 10 * time.Millisecond
|
||||
waitTimeout = 5 * time.Second
|
||||
)
|
||||
|
||||
func TestClientCouldConnect(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.SkipNow()
|
||||
@@ -477,3 +483,63 @@ func TestSingleNodeUpdateSubscriptionPermissions(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// TestDeviceCodecOverride checks that codecs that are incompatible with a device is not
|
||||
// negotiated by the server
|
||||
func TestDeviceCodecOverride(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.SkipNow()
|
||||
return
|
||||
}
|
||||
|
||||
_, finish := setupSingleNodeTest("TestDeviceCodecOverride")
|
||||
defer finish()
|
||||
|
||||
// simulate device that isn't compatible with H.264
|
||||
c1 := createRTCClient("c1", defaultServerPort, &testclient.Options{
|
||||
ClientInfo: &livekit.ClientInfo{
|
||||
Os: "android",
|
||||
DeviceModel: "Xiaomi 2201117TI",
|
||||
},
|
||||
})
|
||||
defer c1.Stop()
|
||||
waitUntilConnected(t, c1)
|
||||
|
||||
// it doesn't really matter what the codec set here is, uses default Pion MediaEngine codecs
|
||||
tw, err := c1.AddStaticTrack("video/h264", "video", "webcam")
|
||||
require.NoError(t, err)
|
||||
defer stopWriters(tw)
|
||||
|
||||
// wait for server to receive track
|
||||
require.Eventually(t, func() bool {
|
||||
return c1.LastAnswer() != nil
|
||||
}, waitTimeout, waitTick, "did not receive answer")
|
||||
|
||||
sd := webrtc.SessionDescription{
|
||||
Type: webrtc.SDPTypeAnswer,
|
||||
SDP: c1.LastAnswer().SDP,
|
||||
}
|
||||
answer, err := sd.Unmarshal()
|
||||
require.NoError(t, err)
|
||||
|
||||
// video and data channel
|
||||
require.Len(t, answer.MediaDescriptions, 2)
|
||||
var desc *sdp.MediaDescription
|
||||
for _, md := range answer.MediaDescriptions {
|
||||
if md.MediaName.Media == "video" {
|
||||
desc = md
|
||||
break
|
||||
}
|
||||
}
|
||||
require.NotNil(t, desc)
|
||||
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") {
|
||||
hasSeenVP8 = true
|
||||
}
|
||||
}
|
||||
}
|
||||
require.True(t, hasSeenVP8, "should have seen VP8 codec in SDP")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user