mirror of
https://github.com/jech/galene.git
synced 2024-11-10 02:35:58 +01:00
Flush buffered packets in diskwriter at shutdown.
This commit is contained in:
parent
b0c39fca22
commit
bcd62f190b
1 changed files with 19 additions and 1 deletions
|
@ -16,6 +16,7 @@ import (
|
||||||
"github.com/at-wat/ebml-go/webm"
|
"github.com/at-wat/ebml-go/webm"
|
||||||
"github.com/pion/rtp"
|
"github.com/pion/rtp"
|
||||||
"github.com/pion/rtp/codecs"
|
"github.com/pion/rtp/codecs"
|
||||||
|
"github.com/pion/webrtc/v3/pkg/media"
|
||||||
|
|
||||||
"github.com/jech/samplebuilder"
|
"github.com/jech/samplebuilder"
|
||||||
|
|
||||||
|
@ -184,6 +185,7 @@ func (conn *diskConn) warn(message string) {
|
||||||
func (conn *diskConn) reopen() error {
|
func (conn *diskConn) reopen() error {
|
||||||
for _, t := range conn.tracks {
|
for _, t := range conn.tracks {
|
||||||
if t.writer != nil {
|
if t.writer != nil {
|
||||||
|
t.writeBuffered(true)
|
||||||
t.writer.Close()
|
t.writer.Close()
|
||||||
t.writer = nil
|
t.writer = nil
|
||||||
}
|
}
|
||||||
|
@ -206,6 +208,7 @@ func (conn *diskConn) Close() error {
|
||||||
tracks := make([]*diskTrack, 0, len(conn.tracks))
|
tracks := make([]*diskTrack, 0, len(conn.tracks))
|
||||||
for _, t := range conn.tracks {
|
for _, t := range conn.tracks {
|
||||||
if t.writer != nil {
|
if t.writer != nil {
|
||||||
|
t.writeBuffered(true)
|
||||||
t.writer.Close()
|
t.writer.Close()
|
||||||
t.writer = nil
|
t.writer = nil
|
||||||
}
|
}
|
||||||
|
@ -545,8 +548,23 @@ func (t *diskTrack) writeRTP(p *rtp.Packet) error {
|
||||||
|
|
||||||
t.builder.Push(p)
|
t.builder.Push(p)
|
||||||
|
|
||||||
|
return t.writeBuffered(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
// writeBuffered writes any buffered samples to disk. If force is true,
|
||||||
|
// then samples will be flushed even if they are preceded by incomplete
|
||||||
|
// samples.
|
||||||
|
func (t *diskTrack) writeBuffered(force bool) error {
|
||||||
|
codec := t.remote.Codec()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
sample, ts := t.builder.PopWithTimestamp()
|
var sample *media.Sample
|
||||||
|
var ts uint32
|
||||||
|
if !force {
|
||||||
|
sample, ts = t.builder.PopWithTimestamp()
|
||||||
|
} else {
|
||||||
|
sample, ts = t.builder.ForcePopWithTimestamp()
|
||||||
|
}
|
||||||
if sample == nil {
|
if sample == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue