format: restore the hls-ts sniff and assert adapter capabilities

Sniff identifies TS assets for the coming policy-driven alignment even
though nothing reaches it through repack today. Compile-time assertions
now state each adapter's capabilities explicitly.
This commit is contained in:
Chris Lu
2026-08-10 20:03:58 -07:00
parent 56468c83e4
commit 0b5d1c0c64
3 changed files with 32 additions and 0 deletions
+15
View File
@@ -23,6 +23,8 @@ const (
// interior chunk cuts land on packet boundaries.
TSPacketSize = 188
tsSyncByte = 0x47
PlaylistContentType = "application/vnd.apple.mpegurl"
MediaContentType = "video/MP2T"
)
@@ -33,8 +35,21 @@ func init() {
type Adapter struct{}
var (
_ format.Sniffer = Adapter{}
_ format.SidecarIndexer = Adapter{}
_ format.Viewer = Adapter{}
)
func (Adapter) Name() string { return FormatName }
func (Adapter) Sniff(h format.Hint) bool {
if len(h.Head) > TSPacketSize {
return h.Head[0] == tsSyncByte && h.Head[TSPacketSize] == tsSyncByte
}
return len(h.Head) > 0 && h.Head[0] == tsSyncByte
}
// playlistInfo is the adapter payload: what the generated playback playlist
// needs beyond the extent sizes.
type playlistInfo struct {
+12
View File
@@ -168,6 +168,18 @@ func TestViewSegmentHonorsMediaSequence(t *testing.T) {
}
}
func TestSniff(t *testing.T) {
head := make([]byte, 400)
head[0], head[TSPacketSize] = tsSyncByte, tsSyncByte
if !(Adapter{}).Sniff(format.Hint{Head: head}) {
t.Fatalf("Sniff() rejected TS head")
}
head[TSPacketSize] = 0
if (Adapter{}).Sniff(format.Hint{Head: head}) {
t.Fatalf("Sniff() accepted non-TS head")
}
}
// The ingest bound admits mediaSequence = MaxInt64-(count-1); the payload
// decoder must accept the same boundary or every view of such an asset fails.
func TestMediaSequenceBoundaryRoundTrip(t *testing.T) {
+5
View File
@@ -25,6 +25,11 @@ func init() {
type Adapter struct{}
var (
_ format.Sniffer = Adapter{}
_ format.Indexer = Adapter{}
)
func (Adapter) Name() string { return FormatName }
func (Adapter) Sniff(h format.Hint) bool {