Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export min and max delay in header extension #281

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions playoutdelayextension.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ var errPlayoutDelayInvalidValue = errors.New("invalid playout delay value")
// | ID | len=2 | MIN delay | MAX delay |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
type PlayoutDelayExtension struct {
minDelay, maxDelay uint16
MinDelay, MaxDelay uint16
}

// Marshal serializes the members to buffer
func (p PlayoutDelayExtension) Marshal() ([]byte, error) {
if p.minDelay > playoutDelayMaxValue || p.maxDelay > playoutDelayMaxValue {
if p.MinDelay > playoutDelayMaxValue || p.MaxDelay > playoutDelayMaxValue {
return nil, errPlayoutDelayInvalidValue
}

return []byte{
byte(p.minDelay >> 4),
byte(p.minDelay<<4) | byte(p.maxDelay>>8),
byte(p.maxDelay),
byte(p.MinDelay >> 4),
byte(p.MinDelay<<4) | byte(p.MaxDelay>>8),
byte(p.MaxDelay),
}, nil
}

Expand All @@ -44,7 +44,7 @@ func (p *PlayoutDelayExtension) Unmarshal(rawData []byte) error {
if len(rawData) < playoutDelayExtensionSize {
return errTooSmall
}
p.minDelay = binary.BigEndian.Uint16(rawData[0:2]) >> 4
p.maxDelay = binary.BigEndian.Uint16(rawData[1:3]) & 0x0FFF
p.MinDelay = binary.BigEndian.Uint16(rawData[0:2]) >> 4
p.MaxDelay = binary.BigEndian.Uint16(rawData[1:3]) & 0x0FFF
return nil
}
6 changes: 3 additions & 3 deletions playoutdelayextension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestPlayoutDelayExtensionTooSmall(t *testing.T) {
}

func TestPlayoutDelayExtensionTooLarge(t *testing.T) {
t1 := PlayoutDelayExtension{minDelay: 1 << 12, maxDelay: 1 << 12}
t1 := PlayoutDelayExtension{MinDelay: 1 << 12, MaxDelay: 1 << 12}

if _, err := t1.Marshal(); !errors.Is(err, errPlayoutDelayInvalidValue) {
t.Fatal("err != errPlayoutDelayInvalidValue")
Expand All @@ -39,7 +39,7 @@ func TestPlayoutDelayExtension(t *testing.T) {
}

t2 := PlayoutDelayExtension{
minDelay: 1 << 4, maxDelay: 1 << 8,
MinDelay: 1 << 4, MaxDelay: 1 << 8,
}

if t1 != t2 {
Expand All @@ -64,7 +64,7 @@ func TestPlayoutDelayExtensionExtraBytes(t *testing.T) {
}

t2 := PlayoutDelayExtension{
minDelay: 1 << 4, maxDelay: 1 << 8,
MinDelay: 1 << 4, MaxDelay: 1 << 8,
}

if t1 != t2 {
Expand Down
Loading