mirror of
https://github.com/jech/galene.git
synced 2024-11-10 02:35:58 +01:00
Request a keyframe every 10s when saving to disk.
This commit is contained in:
parent
5e845eb493
commit
2a516674f2
1 changed files with 19 additions and 4 deletions
|
@ -2,11 +2,11 @@ package diskwriter
|
||||||
|
|
||||||
import (
|
import (
|
||||||
crand "crypto/rand"
|
crand "crypto/rand"
|
||||||
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"encoding/hex"
|
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -206,6 +206,8 @@ type diskTrack struct {
|
||||||
|
|
||||||
// bit 32 is a boolean indicating that the origin is valid
|
// bit 32 is a boolean indicating that the origin is valid
|
||||||
origin uint64
|
origin uint64
|
||||||
|
|
||||||
|
lastKf uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
func newDiskConn(directory, label string, up conn.Up, remoteTracks []conn.UpTrack) (*diskConn, error) {
|
func newDiskConn(directory, label string, up conn.Up, remoteTracks []conn.UpTrack) (*diskConn, error) {
|
||||||
|
@ -219,12 +221,12 @@ func newDiskConn(directory, label string, up conn.Up, remoteTracks []conn.UpTrac
|
||||||
var builder *samplebuilder.SampleBuilder
|
var builder *samplebuilder.SampleBuilder
|
||||||
switch remote.Codec().Name {
|
switch remote.Codec().Name {
|
||||||
case webrtc.Opus:
|
case webrtc.Opus:
|
||||||
builder = samplebuilder.New(16, &codecs.OpusPacket{})
|
builder = samplebuilder.New(128, &codecs.OpusPacket{})
|
||||||
case webrtc.VP8:
|
case webrtc.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")
|
||||||
}
|
}
|
||||||
builder = samplebuilder.New(32, &codecs.VP8Packet{})
|
builder = samplebuilder.New(128, &codecs.VP8Packet{})
|
||||||
conn.hasVideo = true
|
conn.hasVideo = true
|
||||||
}
|
}
|
||||||
track := &diskTrack{
|
track := &diskTrack{
|
||||||
|
@ -277,11 +279,16 @@ func (t *diskTrack) WriteRTP(packet *rtp.Packet) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
kfNeeded := false
|
||||||
|
|
||||||
t.builder.Push(p)
|
t.builder.Push(p)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
sample, ts := t.builder.PopWithTimestamp()
|
sample, ts := t.builder.PopWithTimestamp()
|
||||||
if sample == nil {
|
if sample == nil {
|
||||||
|
if kfNeeded {
|
||||||
|
return conn.ErrKeyframeNeeded
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -290,7 +297,7 @@ func (t *diskTrack) WriteRTP(packet *rtp.Packet) error {
|
||||||
switch t.remote.Codec().Name {
|
switch t.remote.Codec().Name {
|
||||||
case webrtc.VP8:
|
case webrtc.VP8:
|
||||||
if len(sample.Data) < 1 {
|
if len(sample.Data) < 1 {
|
||||||
return nil
|
continue
|
||||||
}
|
}
|
||||||
keyframe = (sample.Data[0]&0x1 == 0)
|
keyframe = (sample.Data[0]&0x1 == 0)
|
||||||
if keyframe {
|
if keyframe {
|
||||||
|
@ -298,6 +305,14 @@ func (t *diskTrack) WriteRTP(packet *rtp.Packet) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
t.lastKf = ts
|
||||||
|
} else if t.writer != nil {
|
||||||
|
// Request a keyframe every 10s
|
||||||
|
delta := ts - t.lastKf
|
||||||
|
if (delta&0x80000000) == 0 &&
|
||||||
|
delta > 10*90000 {
|
||||||
|
kfNeeded = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
if t.writer == nil {
|
if t.writer == nil {
|
||||||
|
|
Loading…
Reference in a new issue