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
c53cc20d
Commit
c53cc20d
authored
May 11, 2021
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use Write instead of WriteRTP in the downTrack interface.
parent
b09dba0e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
48 deletions
+23
-48
conn/conn.go
conn/conn.go
+1
-2
diskwriter/diskwriter.go
diskwriter/diskwriter.go
+15
-23
rtpconn/rtpconn.go
rtpconn/rtpconn.go
+4
-7
rtpconn/rtpwriter.go
rtpconn/rtpwriter.go
+3
-16
No files found.
conn/conn.go
View file @
c53cc20d
...
...
@@ -4,7 +4,6 @@ package conn
import
(
"errors"
"github.com/pion/rtp"
"github.com/pion/webrtc/v3"
)
...
...
@@ -38,7 +37,7 @@ type Down interface {
// Type DownTrack represents a track in the server to client direction.
type
DownTrack
interface
{
Write
RTP
(
packat
*
rtp
.
Packet
)
error
Write
(
buf
[]
byte
)
(
int
,
error
)
SetTimeOffset
(
ntp
uint64
,
rtp
uint32
)
SetCname
(
string
)
GetMaxBitrate
()
uint64
...
...
diskwriter/diskwriter.go
View file @
c53cc20d
...
...
@@ -338,19 +338,6 @@ func (t *diskTrack) SetTimeOffset(ntp uint64, rtp uint32) {
func
(
t
*
diskTrack
)
SetCname
(
string
)
{
}
func
clonePacket
(
packet
*
rtp
.
Packet
)
*
rtp
.
Packet
{
buf
,
err
:=
packet
.
Marshal
()
if
err
!=
nil
{
return
nil
}
var
p
rtp
.
Packet
err
=
p
.
Unmarshal
(
buf
)
if
err
!=
nil
{
return
nil
}
return
&
p
}
func
isKeyframe
(
codec
string
,
data
[]
byte
)
bool
{
switch
strings
.
ToLower
(
codec
)
{
case
"video/vp8"
:
...
...
@@ -417,20 +404,24 @@ func keyframeDimensions(codec string, data []byte, packet *rtp.Packet) (uint32,
}
}
func
(
t
*
diskTrack
)
Write
RTP
(
packet
*
rtp
.
Packet
)
error
{
func
(
t
*
diskTrack
)
Write
(
buf
[]
byte
)
(
int
,
error
)
{
// since we call initWriter, we take the connection lock for simplicity.
t
.
conn
.
mu
.
Lock
()
defer
t
.
conn
.
mu
.
Unlock
()
if
t
.
builder
==
nil
{
return
nil
return
0
,
nil
}
codec
:=
t
.
remote
.
Codec
()
p
:=
clonePacket
(
packet
)
if
p
==
nil
{
return
nil
data
:=
make
([]
byte
,
len
(
buf
))
copy
(
data
,
buf
)
p
:=
new
(
rtp
.
Packet
)
err
:=
p
.
Unmarshal
(
data
)
if
err
!=
nil
{
log
.
Printf
(
"Diskwriter: %v"
,
err
)
return
0
,
nil
}
if
strings
.
ToLower
(
codec
.
MimeType
)
==
"video/vp9"
{
...
...
@@ -459,8 +450,9 @@ func (t *diskTrack) WriteRTP(packet *rtp.Packet) error {
if
sample
==
nil
{
if
kfNeeded
{
t
.
remote
.
RequestKeyframe
()
return
0
,
nil
}
return
nil
return
len
(
buf
),
nil
}
keyframe
:=
true
...
...
@@ -479,7 +471,7 @@ func (t *diskTrack) WriteRTP(packet *rtp.Packet) error {
t
.
conn
.
warn
(
"Write to disk "
+
err
.
Error
(),
)
return
err
return
0
,
err
}
t
.
lastKf
=
ts
}
else
if
t
.
writer
!=
nil
{
...
...
@@ -498,7 +490,7 @@ func (t *diskTrack) WriteRTP(packet *rtp.Packet) error {
"Write to disk "
+
err
.
Error
(),
)
return
err
return
0
,
err
}
}
}
...
...
@@ -508,7 +500,7 @@ func (t *diskTrack) WriteRTP(packet *rtp.Packet) error {
if
!
keyframe
{
t
.
remote
.
RequestKeyframe
()
}
return
nil
return
0
,
nil
}
if
t
.
origin
==
0
{
...
...
@@ -519,7 +511,7 @@ func (t *diskTrack) WriteRTP(packet *rtp.Packet) error {
tm
:=
ts
/
(
t
.
remote
.
Codec
()
.
ClockRate
/
1000
)
_
,
err
:=
t
.
writer
.
Write
(
keyframe
,
int64
(
tm
),
sample
.
Data
)
if
err
!=
nil
{
return
err
return
0
,
err
}
}
}
...
...
rtpconn/rtpconn.go
View file @
c53cc20d
...
...
@@ -89,15 +89,12 @@ type rtpDownTrack struct {
cname
atomic
.
Value
}
func
(
down
*
rtpDownTrack
)
Write
RTP
(
packet
*
rtp
.
Packet
)
error
{
err
:=
down
.
track
.
WriteRTP
(
packet
)
func
(
down
*
rtpDownTrack
)
Write
(
buf
[]
byte
)
(
int
,
error
)
{
n
,
err
:=
down
.
track
.
Write
(
buf
)
if
err
==
nil
{
// we should account for extensions
down
.
rate
.
Accumulate
(
uint32
(
12
+
4
*
len
(
packet
.
CSRC
)
+
len
(
packet
.
Payload
)),
)
down
.
rate
.
Accumulate
(
uint32
(
n
))
}
return
err
return
n
,
err
}
func
(
down
*
rtpDownTrack
)
SetTimeOffset
(
ntp
uint64
,
rtp
uint32
)
{
...
...
rtpconn/rtpwriter.go
View file @
c53cc20d
...
...
@@ -6,8 +6,6 @@ import (
"sort"
"time"
"github.com/pion/rtp"
"github.com/jech/galene/conn"
"github.com/jech/galene/packetcache"
"github.com/jech/galene/rtptime"
...
...
@@ -211,17 +209,13 @@ func (writer *rtpWriter) add(track conn.DownTrack, add bool, max int) error {
func
sendKeyframe
(
kf
[]
uint16
,
track
conn
.
DownTrack
,
cache
*
packetcache
.
Cache
)
{
buf
:=
make
([]
byte
,
packetcache
.
BufSize
)
var
packet
rtp
.
Packet
for
_
,
seqno
:=
range
kf
{
bytes
:=
cache
.
Get
(
seqno
,
buf
)
if
bytes
==
0
{
return
}
err
:=
packet
.
Unmarshal
(
buf
[
:
bytes
])
if
err
!=
nil
{
return
}
err
=
track
.
WriteRTP
(
&
packet
)
_
,
err
:=
track
.
Write
(
buf
[
:
bytes
])
if
err
!=
nil
{
return
}
...
...
@@ -233,8 +227,6 @@ func rtpWriterLoop(writer *rtpWriter, up *rtpUpConnection, track *rtpUpTrack) {
defer
close
(
writer
.
done
)
buf
:=
make
([]
byte
,
packetcache
.
BufSize
)
var
packet
rtp
.
Packet
local
:=
make
([]
conn
.
DownTrack
,
0
)
for
{
...
...
@@ -310,13 +302,8 @@ func rtpWriterLoop(writer *rtpWriter, up *rtpUpConnection, track *rtpUpTrack) {
continue
}
err
:=
packet
.
Unmarshal
(
buf
[
:
bytes
])
if
err
!=
nil
{
continue
}
for
_
,
l
:=
range
local
{
err
:=
l
.
WriteRTP
(
&
packet
)
_
,
err
:=
l
.
Write
(
buf
[
:
bytes
]
)
if
err
!=
nil
{
continue
}
...
...
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