Rewrite MP4, HLS, MPEG-TS consumers

This commit is contained in:
Alexey Khit
2023-08-20 09:57:46 +03:00
parent f67f6e5b9f
commit 2e4e75e386
17 changed files with 492 additions and 635 deletions
+1 -1
View File
@@ -107,7 +107,7 @@ func (c *Consumer) WriteTo(wr io.Writer) (int64, error) {
return c.wr.WriteTo(wr)
}
func (c *Consumer) Close() error {
func (c *Consumer) Stop() error {
_ = c.SuperConsumer.Close()
return c.wr.Close()
}
+10 -1
View File
@@ -45,17 +45,26 @@ func (m *Muxer) GetHeader() []byte {
func (m *Muxer) GetPayload(pid uint16, pts uint32, payload []byte) []byte {
pes := m.pes[pid]
size := 8 + len(payload)
b := make([]byte, 14+len(payload))
_ = b[14] // bounds
b[0] = 0
b[1] = 0
b[2] = 1
b[3] = pes.StreamID
binary.BigEndian.PutUint16(b[4:], 8+uint16(len(payload)))
b[6] = 0x80 // Marker bits (binary)
b[7] = 0x80 // PTS indicator
b[8] = 5 // PES header length
// zero size is OK for video stream
if size <= 0xFFFF {
binary.BigEndian.PutUint16(b[4:], uint16(size))
}
WriteTime(b[9:], pts)
copy(b[14:], payload)
switch pes.StreamType {