mirror of
https://github.com/AlexxIT/go2rtc.git
synced 2025-09-26 20:31:11 +08:00
Fix panic on AVCCToCodec #1652
This commit is contained in:
@@ -82,7 +82,15 @@ func AVCCToCodec(avcc []byte) *core.Codec {
|
||||
buf := bytes.NewBufferString("packetization-mode=1")
|
||||
|
||||
for {
|
||||
n := len(avcc)
|
||||
if n < 4 {
|
||||
break
|
||||
}
|
||||
|
||||
size := 4 + int(binary.BigEndian.Uint32(avcc))
|
||||
if n < size {
|
||||
break
|
||||
}
|
||||
|
||||
switch NALUType(avcc) {
|
||||
case NALUTypeSPS:
|
||||
@@ -95,11 +103,7 @@ func AVCCToCodec(avcc []byte) *core.Codec {
|
||||
buf.WriteString(base64.StdEncoding.EncodeToString(avcc[4:size]))
|
||||
}
|
||||
|
||||
if size < len(avcc) {
|
||||
avcc = avcc[size:]
|
||||
} else {
|
||||
break
|
||||
}
|
||||
avcc = avcc[size:]
|
||||
}
|
||||
|
||||
return &core.Codec{
|
||||
|
@@ -101,3 +101,10 @@ func TestDecodeSPS2(t *testing.T) {
|
||||
require.Equal(t, uint16(640), sps.Width())
|
||||
require.Equal(t, uint16(360), sps.Height())
|
||||
}
|
||||
|
||||
func TestAVCCToCodec(t *testing.T) {
|
||||
s := "000000196764001fac2484014016ec0440000003004000000c23c60c920000000568ee32c8b0000000d365"
|
||||
b, _ := hex.DecodeString(s)
|
||||
codec := AVCCToCodec(b)
|
||||
require.Equal(t, "packetization-mode=1;profile-level-id=64001f;sprop-parameter-sets=Z2QAH6wkhAFAFuwEQAAAAwBAAAAMI8YMkg==,aO4yyLA=", codec.FmtpLine)
|
||||
}
|
||||
|
Reference in New Issue
Block a user