mirror of
https://github.com/jech/galene.git
synced 2024-11-10 02:35:58 +01:00
AV1 support.
This commit is contained in:
parent
25b70bb72a
commit
3e00bb4293
3 changed files with 80 additions and 2 deletions
5
README
5
README
|
@ -232,8 +232,9 @@ following fields are allowed:
|
||||||
Supported video codecs include:
|
Supported video codecs include:
|
||||||
|
|
||||||
- `"vp8"` (compatible with all supported browsers);
|
- `"vp8"` (compatible with all supported browsers);
|
||||||
- `"vp9"` (better video quality than `"vp8"`, but incompatible with
|
- `"vp9"` (better video quality, but incompatible with Safari);
|
||||||
older versions of Mac OS);
|
- `"av1"` (even better video quality, only supported by some browsers,
|
||||||
|
recording is not supported);
|
||||||
- `"h264"` (incompatible with Debian, Ubuntu, and some Android devices,
|
- `"h264"` (incompatible with Debian, Ubuntu, and some Android devices,
|
||||||
recording is not supported).
|
recording is not supported).
|
||||||
|
|
||||||
|
|
|
@ -145,6 +145,12 @@ func codecFromName(name string) (webrtc.RTPCodecCapability, error) {
|
||||||
"profile-id=0",
|
"profile-id=0",
|
||||||
nil,
|
nil,
|
||||||
}, nil
|
}, nil
|
||||||
|
case "av1":
|
||||||
|
return webrtc.RTPCodecCapability{
|
||||||
|
"video/AV1X", 90000, 0,
|
||||||
|
"",
|
||||||
|
nil,
|
||||||
|
}, nil
|
||||||
case "h264":
|
case "h264":
|
||||||
return webrtc.RTPCodecCapability{
|
return webrtc.RTPCodecCapability{
|
||||||
"video/H264", 90000, 0,
|
"video/H264", 90000, 0,
|
||||||
|
@ -186,6 +192,8 @@ func payloadType(codec webrtc.RTPCodecCapability) (webrtc.PayloadType, error) {
|
||||||
return 96, nil
|
return 96, nil
|
||||||
case "video/vp9":
|
case "video/vp9":
|
||||||
return 98, nil
|
return 98, nil
|
||||||
|
case "video/av1x":
|
||||||
|
return 104, nil
|
||||||
case "video/h264":
|
case "video/h264":
|
||||||
return 102, nil
|
return 102, nil
|
||||||
case "audio/opus":
|
case "audio/opus":
|
||||||
|
|
|
@ -43,6 +43,75 @@ func isKeyframe(codec string, packet *rtp.Packet) (bool, bool) {
|
||||||
return (vp9.Payload[0] & 0xC) == 0, true
|
return (vp9.Payload[0] & 0xC) == 0, true
|
||||||
}
|
}
|
||||||
return (vp9.Payload[0] & 0x6) == 0, true
|
return (vp9.Payload[0] & 0x6) == 0, true
|
||||||
|
} else if strings.EqualFold(codec, "video/av1x") {
|
||||||
|
if len(packet.Payload) < 2 {
|
||||||
|
return false, true
|
||||||
|
}
|
||||||
|
if (packet.Payload[0] & 0x88) != 0x08 {
|
||||||
|
return false, true
|
||||||
|
}
|
||||||
|
w := (packet.Payload[0] & 0x30) >> 4
|
||||||
|
|
||||||
|
getObu := func(data []byte) ([]byte, int) {
|
||||||
|
offset := 0
|
||||||
|
length := 0
|
||||||
|
for {
|
||||||
|
if len(data) <= offset {
|
||||||
|
return nil, 0
|
||||||
|
}
|
||||||
|
l := data[offset]
|
||||||
|
length = length*128 + int(l&0x7f)
|
||||||
|
offset++
|
||||||
|
if (l & 0x80) == 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(data) < offset+length {
|
||||||
|
return nil, 0
|
||||||
|
}
|
||||||
|
return data[offset : offset+length], offset + length
|
||||||
|
}
|
||||||
|
var obu1, obu2 []byte
|
||||||
|
if w == 1 {
|
||||||
|
obu1 = packet.Payload[1:]
|
||||||
|
} else {
|
||||||
|
var o int
|
||||||
|
obu1, o = getObu(packet.Payload[1:])
|
||||||
|
if len(obu1) == 0 {
|
||||||
|
return false, false
|
||||||
|
}
|
||||||
|
if w == 2 {
|
||||||
|
obu2 = packet.Payload[1+o:]
|
||||||
|
} else {
|
||||||
|
obu2, _ = getObu(packet.Payload[1+o:])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(obu1) < 1 {
|
||||||
|
return false, false
|
||||||
|
}
|
||||||
|
header := obu1[0]
|
||||||
|
tpe := (header & 0x38) >> 3
|
||||||
|
if tpe != 1 {
|
||||||
|
return false, true
|
||||||
|
}
|
||||||
|
if w == 1 {
|
||||||
|
return false, false
|
||||||
|
}
|
||||||
|
if len(obu2) < 1 {
|
||||||
|
return false, false
|
||||||
|
}
|
||||||
|
header2 := obu2[0]
|
||||||
|
tpe2 := (header2 & 0x38) >> 3
|
||||||
|
if tpe2 != 6 {
|
||||||
|
return false, false
|
||||||
|
}
|
||||||
|
if len(obu2) < 2 {
|
||||||
|
return false, false
|
||||||
|
}
|
||||||
|
if (obu2[1] & 0x80) != 0 {
|
||||||
|
return false, true
|
||||||
|
}
|
||||||
|
return (obu2[1] & 0x60) == 0, false
|
||||||
} else if strings.EqualFold(codec, "video/h264") {
|
} else if strings.EqualFold(codec, "video/h264") {
|
||||||
if len(packet.Payload) < 1 {
|
if len(packet.Payload) < 1 {
|
||||||
return false, false
|
return false, false
|
||||||
|
|
Loading…
Reference in a new issue