Move SplitAVC to public function
This commit is contained in:
@@ -58,3 +58,21 @@ func RepairAVC(track *streamer.Track) streamer.WrapperFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SplitAVC(data []byte) [][]byte {
|
||||||
|
var nals [][]byte
|
||||||
|
for {
|
||||||
|
// get AVC length
|
||||||
|
size := int(binary.BigEndian.Uint32(data))
|
||||||
|
|
||||||
|
// check if multiple items in one packet
|
||||||
|
if size+4 < len(data) {
|
||||||
|
nals = append(nals, data[:size+4])
|
||||||
|
data = data[size+4:]
|
||||||
|
} else {
|
||||||
|
nals = append(nals, data)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nals
|
||||||
|
}
|
||||||
|
|||||||
+1
-20
@@ -2,7 +2,6 @@ package rtmp
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/binary"
|
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/AlexxIT/go2rtc/pkg/h264"
|
"github.com/AlexxIT/go2rtc/pkg/h264"
|
||||||
@@ -134,7 +133,7 @@ func (c *Client) Handle() (err error) {
|
|||||||
|
|
||||||
var payloads [][]byte
|
var payloads [][]byte
|
||||||
if track.Codec.Name == streamer.CodecH264 {
|
if track.Codec.Name == streamer.CodecH264 {
|
||||||
payloads = splitAVC(pkt.Data)
|
payloads = h264.SplitAVC(pkt.Data)
|
||||||
} else {
|
} else {
|
||||||
payloads = [][]byte{pkt.Data}
|
payloads = [][]byte{pkt.Data}
|
||||||
}
|
}
|
||||||
@@ -156,21 +155,3 @@ func (c *Client) Close() error {
|
|||||||
c.closed = true
|
c.closed = true
|
||||||
return c.conn.Close()
|
return c.conn.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func splitAVC(data []byte) [][]byte {
|
|
||||||
var nals [][]byte
|
|
||||||
for {
|
|
||||||
// get AVC length
|
|
||||||
size := int(binary.BigEndian.Uint32(data))
|
|
||||||
|
|
||||||
// check if multiple items in one packet
|
|
||||||
if size+4 < len(data) {
|
|
||||||
nals = append(nals, data[:size+4])
|
|
||||||
data = data[size+4:]
|
|
||||||
} else {
|
|
||||||
nals = append(nals, data)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nals
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user