Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
galene
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
galene
Commits
1130295e
Commit
1130295e
authored
May 12, 2021
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use strings.EqualFold for comparing codec names.
parent
1212c7cb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
28 deletions
+22
-28
diskwriter/diskwriter.go
diskwriter/diskwriter.go
+18
-22
rtpconn/codec.go
rtpconn/codec.go
+4
-6
No files found.
diskwriter/diskwriter.go
View file @
1130295e
...
@@ -271,15 +271,14 @@ func newDiskConn(client *Client, directory string, up conn.Up, remoteTracks []co
...
@@ -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
...
@@ -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
...
@@ -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) {
...
@@ -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 {
...
@@ -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,
...
@@ -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,
...
@@ -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) {
...
@@ -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) {
...
@@ -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) {
...
@@ -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 {
...
@@ -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 {
...
@@ -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 {
...
@@ -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 {
...
@@ -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
)
...
...
rtpconn/codec.go
View file @
1130295e
...
@@ -12,8 +12,7 @@ import (
...
@@ -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) {
...
@@ -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) {
...
@@ -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) {
...
@@ -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
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment