Update MPEG-TS consumer compatibility

This commit is contained in:
Alexey Khit
2023-08-20 18:43:12 +03:00
parent da02a97a00
commit 2ffd859f0e
6 changed files with 71 additions and 36 deletions
+2
View File
@@ -12,6 +12,8 @@ const (
TypeAACMain = 1
TypeAACLC = 2
TypeESCAPE = 31
AUTime = 1024
)
// streamtype=5 - audio stream
+10
View File
@@ -70,6 +70,16 @@ func WriteADTSSize(b []byte, size uint16) {
return
}
func ADTSTimeSize(b []byte) uint32 {
var units uint32
for len(b) > ADTSHeaderSize {
auSize := ReadADTSSize(b)
b = b[auSize:]
units++
}
return units * AUTime
}
func CodecToADTS(codec *core.Codec) []byte {
s := core.Between(codec.FmtpLine, "config=", ";")
conf, err := hex.DecodeString(s)
+2 -2
View File
@@ -32,7 +32,7 @@ func RTPDepay(handler core.HandlerFunc) core.HandlerFunc {
headers = headers[2:]
units = units[unitSize:]
timestamp += 1024
timestamp += AUTime
clone := *packet
clone.Version = RTPPacketVersionAAC
@@ -92,7 +92,7 @@ func ADTStoRTP(src []byte) (dst []byte) {
func RTPTimeSize(b []byte) uint32 {
// convert RTP header size to units count
units := binary.BigEndian.Uint16(b) >> 4
return 1024 * uint32(units)
return uint32(units) * AUTime
}
func RTPToADTS(codec *core.Codec, handler core.HandlerFunc) core.HandlerFunc {