mirror of
https://github.com/jech/galene.git
synced 2024-11-22 08:35:57 +01:00
Use strings.EqualFold for comparing codec names.
This commit is contained in:
parent
1212c7cb04
commit
1130295e0b
2 changed files with 22 additions and 28 deletions
|
@ -271,15 +271,14 @@ func newDiskConn(client *Client, directory string, up conn.Up, remoteTracks []co
|
||||||
for _, remote := range remoteTracks {
|
for _, remote := range remoteTracks {
|
||||||
var builder *samplebuilder.SampleBuilder
|
var builder *samplebuilder.SampleBuilder
|
||||||
codec := remote.Codec()
|
codec := remote.Codec()
|
||||||
switch strings.ToLower(codec.MimeType) {
|
if strings.EqualFold(codec.MimeType, "audio/opus") {
|
||||||
case "audio/opus":
|
|
||||||
builder = samplebuilder.New(
|
builder = samplebuilder.New(
|
||||||
16, &codecs.OpusPacket{}, codec.ClockRate,
|
16, &codecs.OpusPacket{}, codec.ClockRate,
|
||||||
samplebuilder.WithPartitionHeadChecker(
|
samplebuilder.WithPartitionHeadChecker(
|
||||||
&codecs.OpusPartitionHeadChecker{},
|
&codecs.OpusPartitionHeadChecker{},
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
case "video/vp8":
|
} else if strings.EqualFold(codec.MimeType, "video/vp8") {
|
||||||
if conn.hasVideo {
|
if conn.hasVideo {
|
||||||
return nil, errors.New("multiple video tracks not supported")
|
return nil, errors.New("multiple video tracks not supported")
|
||||||
}
|
}
|
||||||
|
@ -290,7 +289,7 @@ func newDiskConn(client *Client, directory string, up conn.Up, remoteTracks []co
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
conn.hasVideo = true
|
conn.hasVideo = true
|
||||||
case "video/vp9":
|
} else if strings.EqualFold(codec.MimeType, "video/vp9") {
|
||||||
if conn.hasVideo {
|
if conn.hasVideo {
|
||||||
return nil, errors.New("multiple video tracks not supported")
|
return nil, errors.New("multiple video tracks not supported")
|
||||||
}
|
}
|
||||||
|
@ -301,7 +300,7 @@ func newDiskConn(client *Client, directory string, up conn.Up, remoteTracks []co
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
conn.hasVideo = true
|
conn.hasVideo = true
|
||||||
default:
|
} else {
|
||||||
client.group.WallOps(
|
client.group.WallOps(
|
||||||
"Cannot record codec " + codec.MimeType,
|
"Cannot record codec " + codec.MimeType,
|
||||||
)
|
)
|
||||||
|
@ -339,13 +338,12 @@ func (t *diskTrack) SetCname(string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func isKeyframe(codec string, data []byte) bool {
|
func isKeyframe(codec string, data []byte) bool {
|
||||||
switch strings.ToLower(codec) {
|
if strings.EqualFold(codec, "video/vp8") {
|
||||||
case "video/vp8":
|
|
||||||
if len(data) < 1 {
|
if len(data) < 1 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return (data[0] & 0x1) == 0
|
return (data[0] & 0x1) == 0
|
||||||
case "video/vp9":
|
} else if strings.EqualFold(codec, "video/vp9") {
|
||||||
if len(data) < 1 {
|
if len(data) < 1 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -357,14 +355,13 @@ func isKeyframe(codec string, data []byte) bool {
|
||||||
return (data[0] & 0xC) == 0
|
return (data[0] & 0xC) == 0
|
||||||
}
|
}
|
||||||
return (data[0] & 0x6) == 0
|
return (data[0] & 0x6) == 0
|
||||||
default:
|
} else {
|
||||||
panic("Eek!")
|
panic("Eek!")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func keyframeDimensions(codec string, data []byte, packet *rtp.Packet) (uint32, uint32) {
|
func keyframeDimensions(codec string, data []byte, packet *rtp.Packet) (uint32, uint32) {
|
||||||
switch strings.ToLower(codec) {
|
if strings.EqualFold(codec, "video/vp8") {
|
||||||
case "video/vp8":
|
|
||||||
if len(data) < 10 {
|
if len(data) < 10 {
|
||||||
return 0, 0
|
return 0, 0
|
||||||
}
|
}
|
||||||
|
@ -373,7 +370,7 @@ func keyframeDimensions(codec string, data []byte, packet *rtp.Packet) (uint32,
|
||||||
width := raw & 0x3FFF
|
width := raw & 0x3FFF
|
||||||
height := (raw >> 16) & 0x3FFF
|
height := (raw >> 16) & 0x3FFF
|
||||||
return width, height
|
return width, height
|
||||||
case "video/vp9":
|
} else if strings.EqualFold(codec, "video/vp9") {
|
||||||
if packet == nil {
|
if packet == nil {
|
||||||
return 0, 0
|
return 0, 0
|
||||||
}
|
}
|
||||||
|
@ -399,7 +396,7 @@ func keyframeDimensions(codec string, data []byte, packet *rtp.Packet) (uint32,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return w, h
|
return w, h
|
||||||
default:
|
} else {
|
||||||
return 0, 0
|
return 0, 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -424,7 +421,7 @@ func (t *diskTrack) Write(buf []byte) (int, error) {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.ToLower(codec.MimeType) == "video/vp9" {
|
if strings.EqualFold(codec.MimeType, "video/vp9") {
|
||||||
var vp9 codecs.VP9Packet
|
var vp9 codecs.VP9Packet
|
||||||
_, err := vp9.Unmarshal(p.Payload)
|
_, err := vp9.Unmarshal(p.Payload)
|
||||||
if err == nil && vp9.B && len(vp9.Payload) >= 1 {
|
if err == nil && vp9.B && len(vp9.Payload) >= 1 {
|
||||||
|
@ -457,8 +454,8 @@ func (t *diskTrack) Write(buf []byte) (int, error) {
|
||||||
|
|
||||||
keyframe := true
|
keyframe := true
|
||||||
|
|
||||||
switch strings.ToLower(codec.MimeType) {
|
if strings.EqualFold(codec.MimeType, "video/vp8") ||
|
||||||
case "video/vp8", "video/vp9":
|
strings.EqualFold(codec.MimeType, "video/vp9") {
|
||||||
keyframe = isKeyframe(codec.MimeType, sample.Data)
|
keyframe = isKeyframe(codec.MimeType, sample.Data)
|
||||||
if keyframe {
|
if keyframe {
|
||||||
err := t.conn.initWriter(
|
err := t.conn.initWriter(
|
||||||
|
@ -481,7 +478,7 @@ func (t *diskTrack) Write(buf []byte) (int, error) {
|
||||||
kfNeeded = true
|
kfNeeded = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default:
|
} else {
|
||||||
if t.writer == nil {
|
if t.writer == nil {
|
||||||
if !t.conn.hasVideo {
|
if !t.conn.hasVideo {
|
||||||
err := t.conn.initWriter(0, 0)
|
err := t.conn.initWriter(0, 0)
|
||||||
|
@ -525,8 +522,7 @@ func (conn *diskConn) initWriter(width, height uint32) error {
|
||||||
for i, t := range conn.tracks {
|
for i, t := range conn.tracks {
|
||||||
var entry webm.TrackEntry
|
var entry webm.TrackEntry
|
||||||
codec := t.remote.Codec()
|
codec := t.remote.Codec()
|
||||||
switch strings.ToLower(codec.MimeType) {
|
if strings.EqualFold(codec.MimeType, "audio/opus") {
|
||||||
case "audio/opus":
|
|
||||||
entry = webm.TrackEntry{
|
entry = webm.TrackEntry{
|
||||||
Name: "Audio",
|
Name: "Audio",
|
||||||
TrackNumber: uint64(i + 1),
|
TrackNumber: uint64(i + 1),
|
||||||
|
@ -537,7 +533,7 @@ func (conn *diskConn) initWriter(width, height uint32) error {
|
||||||
Channels: uint64(codec.Channels),
|
Channels: uint64(codec.Channels),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
case "video/vp8":
|
} else if strings.EqualFold(codec.MimeType, "video/vp8") {
|
||||||
entry = webm.TrackEntry{
|
entry = webm.TrackEntry{
|
||||||
Name: "Video",
|
Name: "Video",
|
||||||
TrackNumber: uint64(i + 1),
|
TrackNumber: uint64(i + 1),
|
||||||
|
@ -548,7 +544,7 @@ func (conn *diskConn) initWriter(width, height uint32) error {
|
||||||
PixelHeight: uint64(height),
|
PixelHeight: uint64(height),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
case "video/vp9":
|
} else if strings.EqualFold(codec.MimeType, "video/vp9") {
|
||||||
entry = webm.TrackEntry{
|
entry = webm.TrackEntry{
|
||||||
Name: "Video",
|
Name: "Video",
|
||||||
TrackNumber: uint64(i + 1),
|
TrackNumber: uint64(i + 1),
|
||||||
|
@ -559,7 +555,7 @@ func (conn *diskConn) initWriter(width, height uint32) error {
|
||||||
PixelHeight: uint64(height),
|
PixelHeight: uint64(height),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
default:
|
} else {
|
||||||
return errors.New("unknown track type")
|
return errors.New("unknown track type")
|
||||||
}
|
}
|
||||||
entries = append(entries, entry)
|
entries = append(entries, entry)
|
||||||
|
|
|
@ -12,8 +12,7 @@ import (
|
||||||
// definitely not the case, and (false, false) if the information cannot
|
// definitely not the case, and (false, false) if the information cannot
|
||||||
// be determined.
|
// be determined.
|
||||||
func isKeyframe(codec string, packet *rtp.Packet) (bool, bool) {
|
func isKeyframe(codec string, packet *rtp.Packet) (bool, bool) {
|
||||||
switch strings.ToLower(codec) {
|
if strings.EqualFold(codec, "video/vp8") {
|
||||||
case "video/vp8":
|
|
||||||
var vp8 codecs.VP8Packet
|
var vp8 codecs.VP8Packet
|
||||||
_, err := vp8.Unmarshal(packet.Payload)
|
_, err := vp8.Unmarshal(packet.Payload)
|
||||||
if err != nil || len(vp8.Payload) < 1 {
|
if err != nil || len(vp8.Payload) < 1 {
|
||||||
|
@ -24,7 +23,7 @@ func isKeyframe(codec string, packet *rtp.Packet) (bool, bool) {
|
||||||
return true, true
|
return true, true
|
||||||
}
|
}
|
||||||
return false, true
|
return false, true
|
||||||
case "video/vp9":
|
} else if strings.EqualFold(codec, "video/vp9") {
|
||||||
var vp9 codecs.VP9Packet
|
var vp9 codecs.VP9Packet
|
||||||
_, err := vp9.Unmarshal(packet.Payload)
|
_, err := vp9.Unmarshal(packet.Payload)
|
||||||
if err != nil || len(vp9.Payload) < 1 {
|
if err != nil || len(vp9.Payload) < 1 {
|
||||||
|
@ -43,7 +42,7 @@ 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
|
||||||
case "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
|
||||||
}
|
}
|
||||||
|
@ -105,8 +104,7 @@ func isKeyframe(codec string, packet *rtp.Packet) (bool, bool) {
|
||||||
return (packet.Payload[1]&0x1F == 5), true
|
return (packet.Payload[1]&0x1F == 5), true
|
||||||
}
|
}
|
||||||
return false, false
|
return false, false
|
||||||
|
} else {
|
||||||
default:
|
|
||||||
return false, false
|
return false, false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue