Rewrite AnnexB/AVCC parsers

This commit is contained in:
Alexey Khit
2023-08-16 16:50:55 +03:00
parent e1be2d9e48
commit 1dd3dbbcd8
28 changed files with 513 additions and 176 deletions
+1 -1
View File
@@ -86,7 +86,7 @@ func (c *Consumer) AddTrack(media *core.Media, _ *core.Codec, track *core.Receiv
if track.Codec.IsRTP() {
handler.Handler = h264.RTPDepay(track.Codec, handler.Handler)
} else {
handler.Handler = h264.RepairAVC(track.Codec, handler.Handler)
handler.Handler = h264.RepairAVCC(track.Codec, handler.Handler)
}
case core.CodecH265:
+4 -6
View File
@@ -6,9 +6,7 @@ import (
"github.com/AlexxIT/go2rtc/pkg/core"
"github.com/AlexxIT/go2rtc/pkg/h264"
"github.com/AlexxIT/go2rtc/pkg/h264/avc"
"github.com/AlexxIT/go2rtc/pkg/h265"
"github.com/AlexxIT/go2rtc/pkg/h265/hvc"
"github.com/AlexxIT/go2rtc/pkg/iso"
"github.com/pion/rtp"
)
@@ -74,13 +72,13 @@ func (m *Muxer) GetInit(codecs []*core.Codec) ([]byte, error) {
pps = []byte{0x68, 0xce, 0x38, 0x80}
}
s := avc.DecodeSPS(sps)
s := h264.DecodeSPS(sps)
if s == nil {
return nil, errors.New("mp4: can't parse SPS")
}
mv.WriteVideoTrack(
uint32(i+1), codec.Name, codec.ClockRate, s.Width(), s.Heigth(), avc.EncodeConfig(sps, pps),
uint32(i+1), codec.Name, codec.ClockRate, s.Width(), s.Height(), h264.EncodeConfig(sps, pps),
)
case core.CodecH265:
@@ -96,13 +94,13 @@ func (m *Muxer) GetInit(codecs []*core.Codec) ([]byte, error) {
pps = []byte{0x44, 0x01, 0xc0, 0x73, 0xc0, 0x4c, 0x90}
}
s := avc.DecodeSPS(sps)
s := h265.DecodeSPS(sps)
if s == nil {
return nil, errors.New("mp4: can't parse SPS")
}
mv.WriteVideoTrack(
uint32(i+1), codec.Name, codec.ClockRate, s.Width(), s.Heigth(), hvc.EncodeConfig(vps, sps, pps),
uint32(i+1), codec.Name, codec.ClockRate, s.Width(), s.Height(), h265.EncodeConfig(vps, sps, pps),
)
case core.CodecAAC:
+2 -1
View File
@@ -2,6 +2,7 @@ package mp4
import (
"encoding/json"
"github.com/AlexxIT/go2rtc/pkg/core"
"github.com/AlexxIT/go2rtc/pkg/h264"
"github.com/AlexxIT/go2rtc/pkg/h265"
@@ -101,7 +102,7 @@ func (c *Segment) AddTrack(media *core.Media, _ *core.Codec, track *core.Receive
if track.Codec.IsRTP() {
handler.Handler = h264.RTPDepay(track.Codec, handler.Handler)
} else {
handler.Handler = h264.RepairAVC(track.Codec, handler.Handler)
handler.Handler = h264.RepairAVCC(track.Codec, handler.Handler)
}
case core.CodecH265: