fix(gateway): preserve qualification wire pacing

This commit is contained in:
sechmachine
2026-08-09 15:59:15 +07:00
parent 0b7e7b8b31
commit aa4f948fbc
4 changed files with 24 additions and 16 deletions
+10 -10
View File
@@ -762,7 +762,7 @@ func (f *qualificationApolloFixture) sendVideo(ctx context.Context, packets [][]
if len(packets) == 0 {
return nil
}
packetsPerMillisecond, batchSize := qualificationApolloVideoPacing(len(packets[0]))
packetsPerMillisecond, batchSize := qualificationApolloVideoPacing(apolloVideoRawPacketSize)
if packetsPerMillisecond == 0 || batchSize == 0 {
return ErrProviderMalformed
}
@@ -773,14 +773,11 @@ func (f *qualificationApolloFixture) sendVideo(ctx context.Context, packets [][]
if f.videoNext.After(frameStart) {
frameStart = f.videoNext
}
framePackets, groupPackets := 0, 0
framePackets := 0
for batchStart := 0; batchStart < len(packets); batchStart += batchSize {
if framePackets == 0 || groupPackets >= packetsPerMillisecond {
due := frameStart.Add(time.Millisecond * time.Duration(framePackets) / time.Duration(packetsPerMillisecond))
if err := qualificationWaitContext(ctx, due); err != nil {
return err
}
groupPackets = 0
due := frameStart.Add(qualificationApolloVideoOffset(framePackets, packetsPerMillisecond))
if err := qualificationWaitContext(ctx, due); err != nil {
return err
}
batchEnd := min(batchStart+batchSize, len(packets))
for _, packet := range packets[batchStart:batchEnd] {
@@ -794,9 +791,8 @@ func (f *qualificationApolloFixture) sendVideo(ctx context.Context, packets [][]
}
currentBatch := batchEnd - batchStart
framePackets += currentBatch
groupPackets += currentBatch
}
f.videoNext = frameStart.Add(time.Millisecond * time.Duration(framePackets) / time.Duration(packetsPerMillisecond))
f.videoNext = frameStart.Add(qualificationApolloVideoOffset(framePackets, packetsPerMillisecond))
return nil
}
@@ -809,6 +805,10 @@ func qualificationApolloVideoPacing(packetBytes int) (packetsPerMillisecond, bat
return packetsPerMillisecond, batchSize
}
func qualificationApolloVideoOffset(packets, packetsPerMillisecond int) time.Duration {
return time.Millisecond * time.Duration(packets) / time.Duration(packetsPerMillisecond)
}
func qualificationWaitContext(ctx context.Context, due time.Time) error {
delay := time.Until(due)
if delay <= 0 {