Fix panic on AVCCToCodec #1652
This commit is contained in:
+8
-4
@@ -82,7 +82,15 @@ func AVCCToCodec(avcc []byte) *core.Codec {
|
|||||||
buf := bytes.NewBufferString("packetization-mode=1")
|
buf := bytes.NewBufferString("packetization-mode=1")
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
n := len(avcc)
|
||||||
|
if n < 4 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
size := 4 + int(binary.BigEndian.Uint32(avcc))
|
size := 4 + int(binary.BigEndian.Uint32(avcc))
|
||||||
|
if n < size {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
switch NALUType(avcc) {
|
switch NALUType(avcc) {
|
||||||
case NALUTypeSPS:
|
case NALUTypeSPS:
|
||||||
@@ -95,11 +103,7 @@ func AVCCToCodec(avcc []byte) *core.Codec {
|
|||||||
buf.WriteString(base64.StdEncoding.EncodeToString(avcc[4:size]))
|
buf.WriteString(base64.StdEncoding.EncodeToString(avcc[4:size]))
|
||||||
}
|
}
|
||||||
|
|
||||||
if size < len(avcc) {
|
|
||||||
avcc = avcc[size:]
|
avcc = avcc[size:]
|
||||||
} else {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return &core.Codec{
|
return &core.Codec{
|
||||||
|
|||||||
@@ -101,3 +101,10 @@ func TestDecodeSPS2(t *testing.T) {
|
|||||||
require.Equal(t, uint16(640), sps.Width())
|
require.Equal(t, uint16(640), sps.Width())
|
||||||
require.Equal(t, uint16(360), sps.Height())
|
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