## Problem and outcome Connection recovery and packet repair could leave stale pictures, missing sound or unreliable remote input. This maintenance release repairs media/route ownership, H.264 negotiation, voice forwarding and Windows input recovery, and makes shared mobile controls and popovers easier to use. ## Release notes **Piik, now in your pocket.** Piik App supports Android screen sharing, with touch controls for a friend's computer. **手机,也能开播。** Piik App 支持 Android 屏幕分享,也能用手机控制朋友的电脑。 ### English Piik v2.5.1 improves sharing recovery, voice playback and remote control, with clearer mobile controls. It keeps the existing 2.x compatibility baseline. - Improve H.264 selection and picture recovery after reconnecting, changing sources or recovering lost packets; keep a working share when a replacement source fails. - Keep audio and room voice continuous, and prevent duplicate sound when switching playback windows. - Improve Windows input recovery and release remote-control permissions when their connection ends. - Keep mobile controls together and popovers usable after layout changes or in short viewports. - Open the appropriate Android update download, including the Gitee ZIP containing the APK. Self-hosted SFU servers refresh public addresses for new connections without a restart. - Add macOS source-thumbnail support. Update the App and self-hosted site together to receive all fixes. Browser settings and existing room data are retained. ### 中文 Piik v2.5.1 改善分享恢复、语音播放与远程控制的稳定性,让手机操作更顺手,沿用现有 2.x 兼容基线。 - 改善 H.264 编码选择,以及重连、切换分享源和丢包后的画面恢复;新分享源切换失败时保留正常分享。 - 保持声音与房间语音连续,避免切换播放窗口时出现双重声音。 - 改善 Windows 输入恢复,并在连接结束时释放远程控制授权。 - 手机控件保持成组,浮层在布局变化或可见高度较小时仍可操作。 - Android 更新打开对应下载入口,Gitee 提供内含 APK 的 ZIP;自部署 SFU 为新连接刷新公网地址,无需重启服务。 - 补齐 macOS 选源缩略图支持。 请一起更新 App 与自部署站点,以获得全部修复。浏览器设置与已有房间数据保留。 ## Validation - Full frontend typecheck, test and production-build acceptance; current Windows App/Server packaging, extracted-file checks and exact served JavaScript verified locally. - Existing Go, vulnerability, native media and controlled-network results retained at their tested revisions. The final production delta from the fully checked candidate is the shared short-viewport popover correction. - The diagnostic report supplied for #502 informed the Windows input fixes. #500 sharing is confirmed working; its missing source previews are implemented. Original-device follow-up remains separate from this release's verified local fixes. ## Compatibility and scope Preserves the published 2.x Browser/server, Native control, capture and SQLite contracts. No 3.0 or iOS implementation or external contributor patch is included. Related: #500, #502, #510, #512.
157 lines
6.4 KiB
Go
157 lines
6.4 KiB
Go
package forwarding
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/livekit/livekit-server/pkg/sfu"
|
|
"github.com/livekit/livekit-server/pkg/sfu/buffer"
|
|
"github.com/livekit/mediatransportutil"
|
|
"github.com/livekit/protocol/livekit"
|
|
"github.com/pion/interceptor"
|
|
"github.com/pion/rtcp"
|
|
"github.com/pion/rtp"
|
|
"github.com/pion/transport/v5/packetio"
|
|
"github.com/pion/webrtc/v4"
|
|
)
|
|
|
|
// Bind at Pion's public TrackLocal boundary. Source buffers and the LiveKit
|
|
// forwarder run unchanged; the writer observes the exact RTP given to SRTP.
|
|
type audioTrackContext struct {
|
|
webrtc.TrackLocalContext
|
|
codec webrtc.RTPCodecParameters
|
|
packets chan *rtp.Packet
|
|
}
|
|
|
|
func (context *audioTrackContext) CodecParameters() []webrtc.RTPCodecParameters {
|
|
return []webrtc.RTPCodecParameters{context.codec}
|
|
}
|
|
func (*audioTrackContext) SSRC() webrtc.SSRC { return 9000 }
|
|
func (*audioTrackContext) SSRCRetransmission() webrtc.SSRC { return 0 }
|
|
func (context *audioTrackContext) WriteStream() webrtc.TrackLocalWriter { return context }
|
|
func (context *audioTrackContext) WriteRTP(header *rtp.Header, payload []byte) (int, error) {
|
|
context.packets <- &rtp.Packet{Header: header.Clone(), Payload: bytes.Clone(payload)}
|
|
return header.MarshalSize() + len(payload), nil
|
|
}
|
|
func (context *audioTrackContext) Write(data []byte) (int, error) {
|
|
packet := &rtp.Packet{}
|
|
if err := packet.Unmarshal(data); err != nil {
|
|
return 0, err
|
|
}
|
|
return context.WriteRTP(&packet.Header, packet.Payload)
|
|
}
|
|
|
|
func TestAudioOutputRetainsClockAcrossInputLifetimeAndPacketLoss(t *testing.T) {
|
|
check := func(err error) {
|
|
t.Helper()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
codec := webrtc.RTPCodecParameters{PayloadType: 111, RTPCodecCapability: webrtc.RTPCodecCapability{
|
|
MimeType: webrtc.MimeTypeOpus, ClockRate: 48_000, Channels: 2, SDPFmtpLine: "minptime=10;useinbandfec=1",
|
|
}}
|
|
settings, registry := webrtc.SettingEngine{}, &interceptor.Registry{}
|
|
factory, err := ConfigureAudioForwarding(&settings, registry, func(uint32) *sfu.DownTrack { return nil })
|
|
check(err)
|
|
output, err := NewAudioOutput(AudioOutputOptions{ID: "slot", StreamID: "room", Codec: codec,
|
|
BufferFactory: factory, RTCPWriter: func([]rtcp.Packet) error { return nil },
|
|
})
|
|
check(err)
|
|
t.Cleanup(output.Close)
|
|
context := &audioTrackContext{codec: codec, packets: make(chan *rtp.Packet, 32)}
|
|
_, err = output.Track().Bind(context)
|
|
check(err)
|
|
output.SetConnected()
|
|
makeSource := func(id string, ssrc uint32) *Source {
|
|
t.Helper()
|
|
source, err := NewSource(SourceOptions{ID: id, StreamID: id, Codec: codec})
|
|
check(err)
|
|
t.Cleanup(source.Close)
|
|
check(source.BindLayer(0, ssrc, webrtc.RTPParameters{Codecs: []webrtc.RTPCodecParameters{codec}}))
|
|
if info := source.TrackInfo(); info.Type != livekit.TrackType_AUDIO || len(info.Layers) != 0 {
|
|
t.Fatalf("audio acquired video allocation metadata: %+v", info)
|
|
}
|
|
return source
|
|
}
|
|
write := func(source *Source, ssrc uint32, sequence uint16, timestamp uint32) *rtp.Packet {
|
|
t.Helper()
|
|
check(source.WriteRTP(0, &rtp.Packet{Header: rtp.Header{Version: 2, PayloadType: 111,
|
|
SSRC: ssrc, SequenceNumber: sequence, Timestamp: timestamp}, Payload: []byte{0xf8, 0xff, 0xfe}}))
|
|
select {
|
|
case packet := <-context.packets:
|
|
return packet
|
|
case <-time.After(time.Second):
|
|
t.Fatal("audio did not reach the bound output")
|
|
return nil
|
|
}
|
|
}
|
|
first := makeSource("first", 1000)
|
|
check(output.ReplaceSource(first))
|
|
stale := first.GetDownTracks()[0]
|
|
a := write(first, 1000, 20_000, 9_600_000)
|
|
b := write(first, 1000, 20_001, 9_600_960)
|
|
if b.SequenceNumber-a.SequenceNumber != 1 || b.Timestamp-a.Timestamp != 960 {
|
|
t.Fatal("ordinary audio timing changed")
|
|
}
|
|
// Preserve a lost packet's sequence/timestamp space and a later DTX gap.
|
|
c := write(first, 1000, 20_003, 9_602_880)
|
|
late := write(first, 1000, 20_002, 9_601_920)
|
|
d := write(first, 1000, 20_004, 9_607_680)
|
|
if c.SequenceNumber-b.SequenceNumber != 2 || c.Timestamp-b.Timestamp != 1920 ||
|
|
late.SequenceNumber-b.SequenceNumber != 1 || late.Timestamp-b.Timestamp != 960 ||
|
|
d.SequenceNumber-c.SequenceNumber != 1 || d.Timestamp-c.Timestamp != 4800 {
|
|
t.Fatal("loss or DTX was compressed out of the output timeline")
|
|
}
|
|
check(first.SenderReport(0, &rtcp.SenderReport{SSRC: 1000, RTPTime: 9_607_680,
|
|
NTPTime: uint64(mediatransportutil.ToNtpTime(time.Now())), PacketCount: 4, OctetCount: 12}))
|
|
if report := output.DownTrack().CreateSenderReport(); report == nil || report.SSRC != a.SSRC {
|
|
t.Fatal("output did not retain its own sender report identity")
|
|
}
|
|
next := makeSource("next", 2000)
|
|
check(output.ReplaceSource(next))
|
|
// A detached source's already queued close/report cannot retire or re-clock
|
|
// the reusable slot. The source itself may close after the new one attaches.
|
|
stale.Close()
|
|
check(stale.HandleRTCPSenderReportData(111, 0, nil))
|
|
if stale.WriteRTP(&buffer.ExtPacket{Packet: &rtp.Packet{}}, 0) != 0 {
|
|
t.Fatal("a detached broadcast wrote into the replacement")
|
|
}
|
|
first.Close()
|
|
e := write(next, 2000, 1000, 480_000)
|
|
if e.SSRC != d.SSRC || e.SequenceNumber-d.SequenceNumber != 1 || int32(e.Timestamp-d.Timestamp) <= 0 {
|
|
t.Fatalf("independent input clock escaped into the reused slot: before=%+v after=%+v", d.Header, e.Header)
|
|
}
|
|
// Closing the current input detaches it, while the same output remains usable
|
|
// for a later publication, including one which reuses its predecessor's SSRC.
|
|
next.Close()
|
|
if output.DownTrack().IsClosed() || output.receiver != output.idle {
|
|
t.Fatal("input retirement destroyed the reusable output slot")
|
|
}
|
|
last := makeSource("last", 2000)
|
|
check(output.ReplaceSource(last))
|
|
f := write(last, 2000, 100, 48_000)
|
|
if f.SSRC != e.SSRC || f.SequenceNumber-e.SequenceNumber != 1 || int32(f.Timestamp-e.Timestamp) <= 0 {
|
|
t.Fatal("a later input could not resume the existing output clock")
|
|
}
|
|
output.DetachSource()
|
|
if len(last.GetDownTracks()) != 0 || output.DownTrack().IsClosed() {
|
|
t.Fatal("subscription removal did not detach the live input")
|
|
}
|
|
// The shared factory claims only outgoing DownTrack RTCP; ingress reports
|
|
// must still be readable by the receiving connection's ordinary RTCP loop.
|
|
input := settings.BufferFactory(packetio.RTCPBufferPacket, 1234)
|
|
defer input.Close()
|
|
report, err := (&rtcp.SenderReport{SSRC: 1234}).Marshal()
|
|
check(err)
|
|
_, err = input.Write(report)
|
|
check(err)
|
|
read := make([]byte, 1500)
|
|
n, err := input.Read(read)
|
|
check(err)
|
|
if !bytes.Equal(read[:n], report) {
|
|
t.Fatal("incoming RTCP was consumed by an output callback")
|
|
}
|
|
}
|