Commit 39d8cf72 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Define a type maybeUint32 and use it in diskwriter.

parent eec6c8a5
...@@ -250,6 +250,22 @@ func openDiskFile(directory, username string) (*os.File, error) { ...@@ -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 { ...@@ -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) { ...@@ -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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment