Documentation
¶
Index ¶
- func DrainTS188Aligned(carry *[]byte, chunk []byte, emit func([]byte))
- func FeedWirePacket(ts []byte, av *domain.AVPacket, mux **FromAV, onTS func([]byte))
- func FindH264ParameterSets(raw []byte) (sps, pps []byte)
- func KeyFrameH264(annexB []byte) bool
- func KeyFrameH265(annexB []byte) bool
- type FromAV
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DrainTS188Aligned ¶
DrainTS188Aligned appends chunk to carry, then calls emit once per aligned 188-byte MPEG-TS packet (sync 0x47). Used so FFmpeg stdin receives transport-aligned writes.
func FeedWirePacket ¶
FeedWirePacket forwards raw TS chunks or muxes one AVPacket to TS via mux (lazily allocated).
func FindH264ParameterSets ¶ added in v0.0.103
FindH264ParameterSets scans raw bytes for the first NAL units of type 7 (SPS) and type 8 (PPS) and returns their bodies (without start codes). Detects both 4-byte (00 00 00 01) and 3-byte (00 00 01) Annex-B start codes. Returns nil for any NAL not present.
Use case: the publisher's serve_rtmp pipeline needs SPS/PPS to build the AVCDecoderConfigurationRecord seq header tag, but receives raw TS from the buffer hub (no AV packets). gomedia's TSDemuxer should preserve SPS/PPS in OnFrame access-unit bytes per its source, but some upstream code paths or stream variations have produced frames without parameter sets. Scanning raw TS bytes is a defensive fallback that does NOT depend on the demuxer's frame-splitting behaviour.
SPS validation: every candidate (byte after a start code with low-5 bits == 7) is parsed via mp4ff's avc.ParseSPSNALUnit. False positives — random payload bytes that look like an Annex-B start code followed by a byte whose nal_unit_type bits equal 7 — fail parsing, so we keep scanning forward. Without this validation we returned ~1KB blobs of payload as "SPS" and pushed garbage AVC sequence headers to RTMP clients (observed: width=16, height=16, ProfileIdc=1 — impossible for real video).
This is a best-effort scan: NAL units split across TS-packet boundaries (with adaptation-field stuffing) may be missed. For SPS (~30 bytes for typical 1080p H264) this is unlikely since the whole NAL fits within a single 184-byte TS payload. PPS is even smaller.
Caller should retain the returned slices (do not reference into the input — we copy out so subsequent buffer reuse cannot corrupt the cached parameter sets).
func KeyFrameH264 ¶
KeyFrameH264 reports whether Annex-B H.264 payload contains an IDR slice.
func KeyFrameH265 ¶
KeyFrameH265 reports whether Annex-B H.265 payload contains an IRAP slice.
Types ¶
type FromAV ¶
type FromAV struct {
// contains filtered or unexported fields
}
FromAV wraps a gomedia TSMuxer and converts AVPackets into 188-byte MPEG-TS packets. One instance per output pipeline (segmenter, publisher pump, transcoder stdin feeder, …).