-
Notifications
You must be signed in to change notification settings - Fork 54
/
packet.go
68 lines (54 loc) · 1.57 KB
/
packet.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package rtcp
// Packet represents an RTCP packet, a protocol used for out-of-band statistics and control information for an RTP session
type Packet interface {
Header() Header
// DestinationSSRC returns an array of SSRC values that this packet refers to.
DestinationSSRC() []uint32
Marshal() ([]byte, error)
Unmarshal(rawPacket []byte) error
}
// unmarshal is a factory which pulls the first RTCP packet from a bytestream,
// and returns it's parsed representation, and the amount of data that was processed.
func unmarshal(rawData []byte) (packet Packet, bytesprocessed int, err error) {
var h Header
err = h.Unmarshal(rawData)
if err != nil {
return nil, 0, err
}
bytesprocessed = int(h.Length+1) * 4
inPacket := rawData[:bytesprocessed]
switch h.Type {
case TypeSenderReport:
packet = new(SenderReport)
case TypeReceiverReport:
packet = new(ReceiverReport)
case TypeSourceDescription:
packet = new(SourceDescription)
case TypeGoodbye:
packet = new(Goodbye)
case TypeTransportSpecificFeedback:
switch h.Count {
case FormatTLN:
packet = new(TransportLayerNack)
case FormatRRR:
packet = new(RapidResynchronizationRequest)
default:
packet = new(RawPacket)
}
case TypePayloadSpecificFeedback:
switch h.Count {
case FormatPLI:
packet = new(PictureLossIndication)
case FormatSLI:
packet = new(SliceLossIndication)
case FormatREMB:
packet = new(ReceiverEstimatedMaximumBitrate)
default:
packet = new(RawPacket)
}
default:
packet = new(RawPacket)
}
err = packet.Unmarshal(inPacket)
return packet, bytesprocessed, err
}