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
b2ea8e85
Commit
b2ea8e85
authored
May 11, 2021
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move isKeyframe into its own file.
parent
6278333a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
112 additions
and
106 deletions
+112
-106
rtpconn/codec.go
rtpconn/codec.go
+112
-0
rtpconn/rtpreader.go
rtpconn/rtpreader.go
+0
-106
No files found.
rtpconn/codec.go
0 → 100644
View file @
b2ea8e85
package
rtpconn
import
(
"strings"
"github.com/pion/rtp"
"github.com/pion/rtp/codecs"
)
// isKeyframe determines if packet is the start of a keyframe.
// It returns (true, true) if that is the case, (false, true) if that is
// definitely not the case, and (false, false) if the information cannot
// be determined.
func
isKeyframe
(
codec
string
,
packet
*
rtp
.
Packet
)
(
bool
,
bool
)
{
switch
strings
.
ToLower
(
codec
)
{
case
"video/vp8"
:
var
vp8
codecs
.
VP8Packet
_
,
err
:=
vp8
.
Unmarshal
(
packet
.
Payload
)
if
err
!=
nil
||
len
(
vp8
.
Payload
)
<
1
{
return
false
,
false
}
if
vp8
.
S
!=
0
&&
vp8
.
PID
==
0
&&
(
vp8
.
Payload
[
0
]
&
0x1
)
==
0
{
return
true
,
true
}
return
false
,
true
case
"video/vp9"
:
var
vp9
codecs
.
VP9Packet
_
,
err
:=
vp9
.
Unmarshal
(
packet
.
Payload
)
if
err
!=
nil
||
len
(
vp9
.
Payload
)
<
1
{
return
false
,
false
}
if
!
vp9
.
B
{
return
false
,
true
}
if
(
vp9
.
Payload
[
0
]
&
0xc0
)
!=
0x80
{
return
false
,
false
}
profile
:=
(
vp9
.
Payload
[
0
]
>>
4
)
&
0x3
if
profile
!=
3
{
return
(
vp9
.
Payload
[
0
]
&
0xC
)
==
0
,
true
}
return
(
vp9
.
Payload
[
0
]
&
0x6
)
==
0
,
true
case
"video/h264"
:
if
len
(
packet
.
Payload
)
<
1
{
return
false
,
false
}
nalu
:=
packet
.
Payload
[
0
]
&
0x1F
if
nalu
==
0
{
// reserved
return
false
,
false
}
else
if
nalu
<=
23
{
// simple NALU
return
nalu
==
5
,
true
}
else
if
nalu
==
24
||
nalu
==
25
||
nalu
==
26
||
nalu
==
27
{
// STAP-A, STAP-B, MTAP16 or MTAP24
i
:=
1
if
nalu
==
25
||
nalu
==
26
||
nalu
==
27
{
// skip DON
i
+=
2
}
for
i
<
len
(
packet
.
Payload
)
{
if
i
+
2
>
len
(
packet
.
Payload
)
{
return
false
,
false
}
length
:=
uint16
(
packet
.
Payload
[
i
])
<<
8
|
uint16
(
packet
.
Payload
[
i
+
1
])
i
+=
2
if
i
+
int
(
length
)
>
len
(
packet
.
Payload
)
{
return
false
,
false
}
offset
:=
0
if
nalu
==
26
{
offset
=
3
}
else
if
nalu
==
27
{
offset
=
4
}
if
offset
>=
int
(
length
)
{
return
false
,
false
}
n
:=
packet
.
Payload
[
i
+
offset
]
&
0x1F
if
n
==
5
{
return
true
,
true
}
else
if
n
>=
24
{
// is this legal?
return
false
,
false
}
i
+=
int
(
length
)
}
if
i
==
len
(
packet
.
Payload
)
{
return
false
,
true
}
return
false
,
false
}
else
if
nalu
==
28
||
nalu
==
29
{
// FU-A or FU-B
if
len
(
packet
.
Payload
)
<
2
{
return
false
,
false
}
if
(
packet
.
Payload
[
1
]
&
0x80
)
==
0
{
// not a starting fragment
return
false
,
true
}
return
(
packet
.
Payload
[
1
]
&
0x1F
==
5
),
true
}
return
false
,
false
default
:
return
false
,
false
}
}
rtpconn/rtpreader.go
View file @
b2ea8e85
...
@@ -3,120 +3,14 @@ package rtpconn
...
@@ -3,120 +3,14 @@ package rtpconn
import
(
import
(
"io"
"io"
"log"
"log"
"strings"
"github.com/pion/rtp"
"github.com/pion/rtp"
"github.com/pion/rtp/codecs"
"github.com/pion/webrtc/v3"
"github.com/pion/webrtc/v3"
"github.com/jech/galene/packetcache"
"github.com/jech/galene/packetcache"
"github.com/jech/galene/rtptime"
"github.com/jech/galene/rtptime"
)
)
// isKeyframe determines if packet is the start of a keyframe.
// It returns (true, true) if that is the case, (false, true) if that is
// definitely not the case, and (false, false) if the information cannot
// be determined.
func
isKeyframe
(
codec
string
,
packet
*
rtp
.
Packet
)
(
bool
,
bool
)
{
switch
strings
.
ToLower
(
codec
)
{
case
"video/vp8"
:
var
vp8
codecs
.
VP8Packet
_
,
err
:=
vp8
.
Unmarshal
(
packet
.
Payload
)
if
err
!=
nil
||
len
(
vp8
.
Payload
)
<
1
{
return
false
,
false
}
if
vp8
.
S
!=
0
&&
vp8
.
PID
==
0
&&
(
vp8
.
Payload
[
0
]
&
0x1
)
==
0
{
return
true
,
true
}
return
false
,
true
case
"video/vp9"
:
var
vp9
codecs
.
VP9Packet
_
,
err
:=
vp9
.
Unmarshal
(
packet
.
Payload
)
if
err
!=
nil
||
len
(
vp9
.
Payload
)
<
1
{
return
false
,
false
}
if
!
vp9
.
B
{
return
false
,
true
}
if
(
vp9
.
Payload
[
0
]
&
0xc0
)
!=
0x80
{
return
false
,
false
}
profile
:=
(
vp9
.
Payload
[
0
]
>>
4
)
&
0x3
if
profile
!=
3
{
return
(
vp9
.
Payload
[
0
]
&
0xC
)
==
0
,
true
}
return
(
vp9
.
Payload
[
0
]
&
0x6
)
==
0
,
true
case
"video/h264"
:
if
len
(
packet
.
Payload
)
<
1
{
return
false
,
false
}
nalu
:=
packet
.
Payload
[
0
]
&
0x1F
if
nalu
==
0
{
// reserved
return
false
,
false
}
else
if
nalu
<=
23
{
// simple NALU
return
nalu
==
5
,
true
}
else
if
nalu
==
24
||
nalu
==
25
||
nalu
==
26
||
nalu
==
27
{
// STAP-A, STAP-B, MTAP16 or MTAP24
i
:=
1
if
nalu
==
25
||
nalu
==
26
||
nalu
==
27
{
// skip DON
i
+=
2
}
for
i
<
len
(
packet
.
Payload
)
{
if
i
+
2
>
len
(
packet
.
Payload
)
{
return
false
,
false
}
length
:=
uint16
(
packet
.
Payload
[
i
])
<<
8
|
uint16
(
packet
.
Payload
[
i
+
1
])
i
+=
2
if
i
+
int
(
length
)
>
len
(
packet
.
Payload
)
{
return
false
,
false
}
offset
:=
0
if
nalu
==
26
{
offset
=
3
}
else
if
nalu
==
27
{
offset
=
4
}
if
offset
>=
int
(
length
)
{
return
false
,
false
}
n
:=
packet
.
Payload
[
i
+
offset
]
&
0x1F
if
n
==
5
{
return
true
,
true
}
else
if
n
>=
24
{
// is this legal?
return
false
,
false
}
i
+=
int
(
length
)
}
if
i
==
len
(
packet
.
Payload
)
{
return
false
,
true
}
return
false
,
false
}
else
if
nalu
==
28
||
nalu
==
29
{
// FU-A or FU-B
if
len
(
packet
.
Payload
)
<
2
{
return
false
,
false
}
if
(
packet
.
Payload
[
1
]
&
0x80
)
==
0
{
// not a starting fragment
return
false
,
true
}
return
(
packet
.
Payload
[
1
]
&
0x1F
==
5
),
true
}
return
false
,
false
default
:
return
false
,
false
}
}
func
readLoop
(
conn
*
rtpUpConnection
,
track
*
rtpUpTrack
)
{
func
readLoop
(
conn
*
rtpUpConnection
,
track
*
rtpUpTrack
)
{
writers
:=
rtpWriterPool
{
conn
:
conn
,
track
:
track
}
writers
:=
rtpWriterPool
{
conn
:
conn
,
track
:
track
}
defer
func
()
{
defer
func
()
{
...
...
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