1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-11-22 08:35:57 +01:00

Define a type maybeUint32 and use it in diskwriter.

This commit is contained in:
Juliusz Chroboczek 2021-07-11 22:44:50 +02:00
parent eec6c8a5b0
commit 39d8cf72fe

View file

@ -250,6 +250,22 @@ func openDiskFile(directory, username string) (*os.File, error) {
return nil, errors.New("couldn't create file") return nil, errors.New("couldn't create file")
} }
type maybeUint32 uint64
const none maybeUint32 = 0
func some(value uint32) maybeUint32 {
return maybeUint32(uint64(1 << 32) | uint64(value))
}
func valid(m maybeUint32) bool {
return (m & (1 << 32)) != 0
}
func value(m maybeUint32) uint32 {
return uint32(m)
}
type diskTrack struct { type diskTrack struct {
remote conn.UpTrack remote conn.UpTrack
conn *diskConn conn *diskConn
@ -257,8 +273,7 @@ type diskTrack struct {
writer webm.BlockWriteCloser writer webm.BlockWriteCloser
builder *samplebuilder.SampleBuilder builder *samplebuilder.SampleBuilder
// bit 32 is a boolean indicating that the origin is valid origin maybeUint32
origin uint64
kfRequested time.Time kfRequested time.Time
lastKf time.Time lastKf time.Time
@ -546,10 +561,10 @@ func (t *diskTrack) Write(buf []byte) (int, error) {
continue continue
} }
if t.origin == 0 { if !valid(t.origin) {
t.origin = uint64(ts) | (1 << 32) t.origin = some(ts)
} }
ts -= uint32(t.origin) ts -= value(t.origin)
tm := ts / (t.remote.Codec().ClockRate / 1000) tm := ts / (t.remote.Codec().ClockRate / 1000)
_, err := t.writer.Write(keyframe, int64(tm), sample.Data) _, err := t.writer.Write(keyframe, int64(tm), sample.Data)