feat(gateway): relay complete encoded frames
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package gateway
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/aes"
|
||||
"crypto/cipher"
|
||||
@@ -531,19 +532,6 @@ func TestNativeApolloSetupRequiresModernEncryptedRTSPOrder(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
awaitControl(apolloControlTypeFEC, false)
|
||||
remote := <-controlRemote
|
||||
hostTermination := sourceSealHostControl(t, material.key, 0, apolloControlTypeTerm, []byte{1, 2, 3, 4})
|
||||
if _, err := controlServer.WriteToUDP(sourceShapedENetReliablePacketOn(7, 2, apolloChannelGeneric, 1, hostTermination), remote); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
select {
|
||||
case event := <-session.Events():
|
||||
if event.Kind != ProviderEventTerminated || string(event.Payload) != string([]byte{1, 2, 3, 4}) {
|
||||
t.Fatalf("provider termination event = %#v", event)
|
||||
}
|
||||
case <-time.After(time.Second):
|
||||
t.Fatal("encrypted host termination was not forwarded")
|
||||
}
|
||||
select {
|
||||
case media := <-session.Video():
|
||||
payload := media.Payload
|
||||
@@ -562,6 +550,19 @@ func TestNativeApolloSetupRequiresModernEncryptedRTSPOrder(t *testing.T) {
|
||||
case <-time.After(time.Second):
|
||||
t.Fatal("source-shaped audio was not relayed")
|
||||
}
|
||||
remote := <-controlRemote
|
||||
hostTermination := sourceSealHostControl(t, material.key, 0, apolloControlTypeTerm, []byte{1, 2, 3, 4})
|
||||
if _, err := controlServer.WriteToUDP(sourceShapedENetReliablePacketOn(7, 2, apolloChannelGeneric, 1, hostTermination), remote); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
select {
|
||||
case event := <-session.Events():
|
||||
if event.Kind != ProviderEventTerminated || string(event.Payload) != string([]byte{1, 2, 3, 4}) {
|
||||
t.Fatalf("provider termination event = %#v", event)
|
||||
}
|
||||
case <-time.After(time.Second):
|
||||
t.Fatal("encrypted host termination was not forwarded")
|
||||
}
|
||||
terminateCtx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||
defer cancel()
|
||||
if err := session.Terminate(terminateCtx); err != nil {
|
||||
@@ -899,6 +900,55 @@ func TestPushLatestDropsExactlyOneOldPayload(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNativeProviderVideoQueueBoundsRealFrames(t *testing.T) {
|
||||
const maximumQueuedVideoBytes = 4 << 20
|
||||
session := newNativeApolloSession("bounded-video")
|
||||
frame := bytes.Repeat([]byte{0x65}, 768<<10)
|
||||
for index := 0; index < 12; index++ {
|
||||
if !session.enqueueMedia(session.video, append([]byte(nil), frame...), time.Now()) {
|
||||
t.Fatalf("frame %d was not accepted", index)
|
||||
}
|
||||
}
|
||||
|
||||
var queuedBytes int
|
||||
for {
|
||||
select {
|
||||
case media := <-session.Video():
|
||||
queuedBytes += len(media.Payload)
|
||||
default:
|
||||
if queuedBytes > maximumQueuedVideoBytes {
|
||||
t.Fatalf("video queue retained %d bytes, limit %d", queuedBytes, maximumQueuedVideoBytes)
|
||||
}
|
||||
if drops := session.Telemetry().MediaDrops; drops != 7 {
|
||||
t.Fatalf("latest-frame replacements = %d, want 7", drops)
|
||||
}
|
||||
if maximum := session.mediaQueueMaximum.Load(); maximum > nativeApolloVideoQueuePackets {
|
||||
t.Fatalf("maximum video queue entries = %d", maximum)
|
||||
}
|
||||
if maximum := session.mediaQueueMaximumBytes.Load(); maximum > maximumQueuedVideoBytes {
|
||||
t.Fatalf("maximum video queue bytes = %d", maximum)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestNativeProviderVideoQueueExpiresResidence(t *testing.T) {
|
||||
session := newNativeApolloSession("expiring-video")
|
||||
if !session.enqueueMedia(session.video, []byte("stale-frame"), time.Now()) {
|
||||
t.Fatal("video frame was not accepted")
|
||||
}
|
||||
time.Sleep(nativeApolloVideoQueueLatency + 25*time.Millisecond)
|
||||
select {
|
||||
case media := <-session.Video():
|
||||
t.Fatalf("expired video remained queued: %#v", media)
|
||||
default:
|
||||
}
|
||||
if drops := session.Telemetry().MediaDrops; drops != 1 {
|
||||
t.Fatalf("expired video drops = %d, want 1", drops)
|
||||
}
|
||||
}
|
||||
|
||||
func sourceShapedEncryptedVideoPacket(t *testing.T, key, encoded []byte) []byte {
|
||||
t.Helper()
|
||||
payload := make([]byte, apolloVideoShardPayloadSize)
|
||||
|
||||
Reference in New Issue
Block a user