1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-11-09 02:05:59 +01:00

Implement MapContinuation.

This is used to map a continuation packet in VP8, which does
not necessarily carry a valid PID.
This commit is contained in:
Juliusz Chroboczek 2023-01-06 22:43:21 +01:00
parent 41c7114387
commit 260b80fe93
2 changed files with 61 additions and 0 deletions

View file

@ -61,6 +61,33 @@ func (m *Map) Map(seqno uint16, pid uint16) (bool, uint16, uint16) {
return m.direct(seqno)
}
// MapContinuation is like map, but used for padding packets that don't
// have a pid.
func (m *Map) MapContinuation(seqno uint16) (bool, uint16, uint16) {
m.mu.Lock()
defer m.mu.Unlock()
if m.delta == 0 && m.entries == nil {
if m.next == seqno {
m.next = seqno + 1
}
return true, seqno, 0
}
if m.next == seqno {
addMapping(m, seqno, m.delta, m.pidDelta)
m.next = seqno + 1
return true, seqno + m.delta, m.pidDelta
}
if compare(m.next, seqno) <= 0 {
return false, 0, 0
}
return m.direct(seqno)
}
func (m *Map) reset() {
m.next = 0
m.nextPid = 0

View file

@ -141,6 +141,40 @@ func TestDrop(t *testing.T) {
}
}
func TestPadding(t *testing.T) {
m := Map{}
ok, s, p := m.Map(42, 1001)
if !ok || s != 42 || p != 0 {
t.Errorf("Expected 42, 0, got %v, %v, %v", ok, s, p)
}
ok, s, p = m.MapContinuation(43)
if !ok || s != 43 || p != 0 {
t.Errorf("Expected 43, 0, got %v %v %v", ok, s, p)
}
ok, s, p = m.Map(43, 1001)
if !ok || s != 43 || p != 0 {
t.Errorf("Expected 43, 0, got %v %v %v", ok, s, p)
}
ok, s, p = m.Map(44, 1002)
if !ok || s != 44 || p != 0 {
t.Errorf("Expected 44, 0, got %v %v %v", ok, s, p)
}
ok = m.Drop(45, 1003)
if !ok {
t.Errorf("Not ok")
}
ok, s, p = m.MapContinuation(46)
if !ok || s != 45 || p != 1 {
t.Errorf("Expected 45, 0, got %v %v %v", ok, s, p)
}
}
func TestWraparound(t *testing.T) {
m := Map{}