feat(protocol): freeze M4 native session RC6 contract

This commit is contained in:
sechmachine
2026-08-13 07:18:03 +07:00
parent 4693102b3c
commit 8eacc4fda9
35 changed files with 5334 additions and 473 deletions
+44
View File
@@ -2,6 +2,7 @@ package main
import (
"crypto/sha256"
"encoding/binary"
"encoding/hex"
"encoding/json"
"fmt"
@@ -101,6 +102,15 @@ func evaluate(version, kind, input string) string {
Profile: protocol.ManifestProfile{ID: "standard", Bounds: protocol.ManifestBounds{MinimumKbps: 1, TargetKbps: 2, MaximumKbps: 3}},
Grant: protocol.GrantReference{OpaqueValue: parts["grant"], ExpiresAt: parts["expires_at"], Audience: parts["audience"]},
CorrelationID: "correlation-1",
SelectedDescriptor: protocol.SelectedSessionDescriptor{
VideoProfile: protocol.VideoProfile{Codec: "h264", BitDepth: 8, ChromaSubsampling: "4:2:0", ColorSpace: "bt709-limited", TransferFunction: "sdr"},
AudioProfile: protocol.AudioProfile{Codec: "opus", SampleRateHz: 48000, Channels: 2, ChannelLayout: "stereo", PacketDurationMs: 5},
DisplayMode: protocol.DisplayMode{ResolutionWidth: 1920, ResolutionHeight: 1080, Fps: 60},
BitrateTargetKbps: 12000,
BitrateMaximumKbps: 20000,
Adjustment: protocol.SessionAdjustment{DisplayReason: "none", BitrateReason: "none"},
MediaTimestampBasis: "gateway-send-wall-clock-ms",
},
}
if value.Validate() == nil {
return "valid"
@@ -123,6 +133,8 @@ func evaluate(version, kind, input string) string {
value := protocol.SessionRequest{
ClientDeviceID: parts["client_device_id"], DeviceKeyID: parts["device_key_id"],
PoolID: parts["pool_id"], IdempotencyKey: parts["idempotency_key"],
VideoProfiles: []protocol.VideoProfile{{Codec: "h264", BitDepth: 8, ChromaSubsampling: "4:2:0", ColorSpace: "bt709-limited", TransferFunction: "sdr"}},
BitratePreference: protocol.BitratePreference{Mode: "auto"},
}
if value.Validate() == nil {
return "valid"
@@ -309,6 +321,13 @@ func classifyGatewayInput(encoded string) string {
if len(body) != 4 {
return "invalid:length"
}
case 8:
if len(body) != 8 {
return "invalid:length"
}
if body[0] > 15 || body[3] > 3 {
return "invalid:field"
}
default:
return "invalid:kind"
}
@@ -352,6 +371,22 @@ func classifyGatewayFeedback(encoded string) string {
if len(body) == 0 {
return "valid"
}
case 4:
if len(body) != 24 {
return "invalid:length"
}
if binary.BigEndian.Uint64(body[16:]) == 0 || allZero(body[:16]) {
return "invalid:field"
}
return "valid"
case 5:
if len(body) != 16 {
return "invalid:length"
}
if allZero(body) {
return "invalid:field"
}
return "valid"
default:
return "invalid:type"
}
@@ -386,6 +421,15 @@ func classifyGatewayFeedback(encoded string) string {
return "invalid:field"
}
func allZero(value []byte) bool {
for _, item := range value {
if item != 0 {
return false
}
}
return true
}
func validFECStatus(body []byte) bool {
if len(body) != 21 || int(body[10])<<8|int(body[11]) == 0 || int(body[14])<<8|int(body[15]) > int(body[10])<<8|int(body[11]) || int(body[16])<<8|int(body[17]) > int(body[12])<<8|int(body[13]) || body[18] > 100 || body[20] == 0 || body[19] >= body[20] {
return false