mirror of https://bitbucket.org/ausocean/av.git
rtp: client only needs to specify padding length and then padding indicator is set based on this
This commit is contained in:
parent
5eb7225da9
commit
0531b9542b
|
@ -83,7 +83,6 @@ func (e *Encoder) Write(data []byte) (int, error) {
|
|||
func (e *Encoder) Encode(payload []byte) error {
|
||||
pkt := Pkt{
|
||||
V: rtpVer, // version
|
||||
P: no, // padding
|
||||
X: no, // header extension
|
||||
CC: no, // CSRC count
|
||||
M: no, // NOTE: need to check if this works (decoders should ignore this)
|
||||
|
|
|
@ -37,9 +37,10 @@ const (
|
|||
)
|
||||
|
||||
// Pkt provides fields consistent with RFC3550 definition of an rtp packet
|
||||
// The padding indicator does not need to be set manually, only the padding length
|
||||
type Pkt struct {
|
||||
V byte // Version (currently 2)
|
||||
P byte // Padding indicator (0 => padding, 1 => padding)
|
||||
p byte // Padding indicator (0 => padding, 1 => padding)
|
||||
X byte // Extension header indicator
|
||||
CC byte // CSRC count
|
||||
M byte // Marker bit
|
||||
|
@ -57,10 +58,8 @@ func (p *Pkt) Bytes() []byte {
|
|||
p.V = rtpVer
|
||||
}
|
||||
|
||||
if p.P != 0 && p.Padding == 0 {
|
||||
panic("Padding bit set to something other than 1, but there is no padding size defined.")
|
||||
} else if p.P == 0 && p.Padding != 0 {
|
||||
panic("Padding bit is set to zero, but it's indicated that there is padding.")
|
||||
if p.Padding > 0 {
|
||||
p.p = 1
|
||||
}
|
||||
|
||||
if p.CC != 0 {
|
||||
|
@ -78,7 +77,7 @@ func (p *Pkt) Bytes() []byte {
|
|||
const headSize = 3 * 4 // bytes
|
||||
buf := make([]byte, headSize, headSize+len(p.Payload)+int(p.Padding))
|
||||
|
||||
buf[0] = p.V<<6 | p.P<<5 | p.CC
|
||||
buf[0] = p.V<<6 | p.p<<5 | p.CC
|
||||
buf[1] = p.M<<7 | p.PT
|
||||
buf[2] = byte(p.SN >> 8)
|
||||
buf[3] = byte(p.SN)
|
||||
|
|
|
@ -42,7 +42,7 @@ var rtpTests = []struct {
|
|||
num: 1,
|
||||
pkt: Pkt{
|
||||
V: 2,
|
||||
P: 0,
|
||||
p: 0,
|
||||
X: 0,
|
||||
CC: 0,
|
||||
M: 0,
|
||||
|
|
Loading…
Reference in New Issue