Skip to content

Commit 75c6a1c

Browse files
authored
Merge pull request #15 from video-audio/master
gofmt, golint, golangci-lint, panic prevent
2 parents 27fbd34 + 9c6100a commit 75c6a1c

File tree

11 files changed

+411
-397
lines changed

11 files changed

+411
-397
lines changed

README.md

Lines changed: 92 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,92 @@
1-
# RTP/RTCP stack for Go
2-
3-
This Go package implements a RTP/RTCP stack for Go. The package is a
4-
sub-package of the standard Go _net_ package and uses standard _net_ package
5-
functions.
6-
7-
## How to build
8-
9-
The _rtp_ sources use the GOPATH directory structure. To build, test, and run
10-
the software just add the main goRTP directory to GOPATH. For further
11-
information about this structure run `go help gopath` and follow the
12-
instructions. The _rtp_ package is below the package _net_ to make clear that
13-
_rtp_ is a network related package.
14-
15-
To build the package just run `go build net/rtp` and then `go install
16-
net/rtp`. To excecute the tests just run `go test net/rtp`. The tests check if
17-
the code works with the current Go installation on your system. It should
18-
PASS.
19-
20-
A demo program is available and is called _rtpmain_. Use `go build
21-
net/rtpmain` to build it. The command `go install net/rtpmain` installs it in
22-
the `bin` directory of the main directory.
23-
24-
## How to use
25-
26-
This is a pure RTP / RTCP stack and it does not contain any media processing,
27-
for example generating or packing the payload for audio or video codecs.
28-
29-
The directory `src/net/rtpmain` contains an example Go program that performs a
30-
RTP some tests on _localhost_ that shows how to setup a RTP session, an
31-
output stream and how to send and receive RTP data and control events. Parts
32-
of this program are used in the package documentation.
33-
34-
The software should be ready to use for many RTP applications. Standard
35-
point-to-point RTP applications should not pose any problems. RTP multi-cast
36-
using IP multi-cast addresses is not supported. If somebody really requires IP
37-
multi-cast it could be added at the transport level.
38-
39-
RTCP reporting works without support from application. The stack reports RTCP
40-
packets and if the stack created new input streams and an application may
41-
connect to the control channel to receive the RTCP events. Just have a look
42-
into the example program. The RTCP fields in the stream structures are
43-
accessible - however, to use them you may need to have some know-how of the
44-
RTCP definitions and reporting.
45-
46-
## The documentation
47-
48-
After you downloaded the code you may use standard _godoc_ to get a nice
49-
formatted documentation. Just change into the `src` directory, run `godoc
50-
-http=:6060 -path="."`, point your browser at _localhost:6060_, and select
51-
`src` at the top of the page.
52-
53-
I've added some package global documentation and tried to document the
54-
globally visible methods and functions.
55-
56-
Before you start hacking please have a look into the documentation first, in
57-
particular the package documentation (doc.go).
58-
59-
## Some noteable features
60-
61-
* The current release V1.0.0 computes the RTCP intervals based on the length of
62-
RTCP compound packets and the bandwidth allocated to RTCP. The application may
63-
set the bandwidth, if no set GoRTP makes somes educated guesses.
64-
65-
* The application may set the maximum number of output and input streams even
66-
while the RTP session is active. If the application des not set GoRTP sets
67-
the values to 5 and 30 respectively.
68-
69-
* GoRTP produces SR and RR reports and the associated SDES for active streams
70-
only, thus it implements the activity check as defined in chapter 6.4
71-
72-
* An appplication may use GoRTP in _simple RTP_ mode. In this mode only RTP
73-
data packets are exchanged between the peers. No RTCP service is active, no
74-
statistic counters, and GoRTP discards RTCP packets it receives.
75-
76-
* GoRTP limits the number of RR to 31 per RTCP report interval. GoRTP does not
77-
add an additional RR packet in case it detects more than 31 active input
78-
streams. This restriction is mainly due to MTU contraints of modern Ethernet
79-
or DSL based networks. The MTU is usually about 1500 bytes, GoRTP limits
80-
the RTP/RTCP packet size to 1200 bytes. The length of an RR is 24 bytes,
81-
thus 31 RR already require 774 bytes. Adding some data for SR and SDES fills
82-
the rest.
83-
84-
* An application may register to a control event channel and GoRTP delivers a
85-
nice set of control and error events. The events cover:
86-
- Creation of a new input stream when receiving an RTP or RTCP packet and
87-
the SSRC was not known
88-
- RTCP events to inform about RTCP packets and received reports
89-
- Error events
90-
91-
* Currently GoRTP supports only SR, RR, SDES, and BYE RTCP packets. Inside
92-
SDES GoRTP does not support SDES Private and SDES H.323 items.
1+
# RTP/RTCP stack for Go
2+
3+
This Go package implements a RTP/RTCP stack for Go. The package is a
4+
sub-package of the standard Go _net_ package and uses standard _net_ package
5+
functions.
6+
7+
## How to build
8+
9+
The _rtp_ sources use the GOPATH directory structure. To build, test, and run
10+
the software just add the main goRTP directory to GOPATH. For further
11+
information about this structure run `go help gopath` and follow the
12+
instructions. The _rtp_ package is below the package _net_ to make clear that
13+
_rtp_ is a network related package.
14+
15+
To build the package just run `go build net/rtp` and then `go install
16+
net/rtp`. To excecute the tests just run `go test net/rtp`. The tests check if
17+
the code works with the current Go installation on your system. It should
18+
PASS.
19+
20+
A demo program is available and is called _rtpmain_. Use `go build
21+
net/rtpmain` to build it. The command `go install net/rtpmain` installs it in
22+
the `bin` directory of the main directory.
23+
24+
## How to use
25+
26+
This is a pure RTP / RTCP stack and it does not contain any media processing,
27+
for example generating or packing the payload for audio or video codecs.
28+
29+
The directory `src/net/rtpmain` contains an example Go program that performs a
30+
RTP some tests on _localhost_ that shows how to setup a RTP session, an
31+
output stream and how to send and receive RTP data and control events. Parts
32+
of this program are used in the package documentation.
33+
34+
The software should be ready to use for many RTP applications. Standard
35+
point-to-point RTP applications should not pose any problems. RTP multi-cast
36+
using IP multi-cast addresses is not supported. If somebody really requires IP
37+
multi-cast it could be added at the transport level.
38+
39+
RTCP reporting works without support from application. The stack reports RTCP
40+
packets and if the stack created new input streams and an application may
41+
connect to the control channel to receive the RTCP events. Just have a look
42+
into the example program. The RTCP fields in the stream structures are
43+
accessible - however, to use them you may need to have some know-how of the
44+
RTCP definitions and reporting.
45+
46+
## The documentation
47+
48+
After you downloaded the code you may use standard _godoc_ to get a nice
49+
formatted documentation. Just change into the `src` directory, run `godoc
50+
-http=:6060 -path="."`, point your browser at _localhost:6060_, and select
51+
`src` at the top of the page.
52+
53+
I've added some package global documentation and tried to document the
54+
globally visible methods and functions.
55+
56+
Before you start hacking please have a look into the documentation first, in
57+
particular the package documentation (doc.go).
58+
59+
## Some noteable features
60+
61+
* The current release V1.0.0 computes the RTCP intervals based on the length of
62+
RTCP compound packets and the bandwidth allocated to RTCP. The application may
63+
set the bandwidth, if no set GoRTP makes somes educated guesses.
64+
65+
* The application may set the maximum number of output and input streams even
66+
while the RTP session is active. If the application des not set GoRTP sets
67+
the values to 5 and 30 respectively.
68+
69+
* GoRTP produces SR and RR reports and the associated SDES for active streams
70+
only, thus it implements the activity check as defined in chapter 6.4
71+
72+
* An appplication may use GoRTP in _simple RTP_ mode. In this mode only RTP
73+
data packets are exchanged between the peers. No RTCP service is active, no
74+
statistic counters, and GoRTP discards RTCP packets it receives.
75+
76+
* GoRTP limits the number of RR to 31 per RTCP report interval. GoRTP does not
77+
add an additional RR packet in case it detects more than 31 active input
78+
streams. This restriction is mainly due to MTU contraints of modern Ethernet
79+
or DSL based networks. The MTU is usually about 1500 bytes, GoRTP limits
80+
the RTP/RTCP packet size to 1200 bytes. The length of an RR is 24 bytes,
81+
thus 31 RR already require 774 bytes. Adding some data for SR and SDES fills
82+
the rest.
83+
84+
* An application may register to a control event channel and GoRTP delivers a
85+
nice set of control and error events. The events cover:
86+
- Creation of a new input stream when receiving an RTP or RTCP packet and
87+
the SSRC was not known
88+
- RTCP events to inform about RTCP packets and received reports
89+
- Error events
90+
91+
* Currently GoRTP supports only SR, RR, SDES, and BYE RTCP packets. Inside
92+
SDES GoRTP does not support SDES Private and SDES H.323 items.

src/net/rtp/ctrlpacket_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ import (
2525
)
2626

2727
// V=2, P=0, chunks=2; PT=SDES; length=5 32bit words (24 bytes)
28-
var sdes_1 = []byte{0x81, 202, 0x00, 0x05,
28+
var sdes1 = []byte{0x81, 202, 0x00, 0x05,
2929
0x01, 0x02, 0x03, 0x04, // SSRC 0x01020304
3030
0x01, 0x01, 0x02, // CNAME, len=1, content=2
3131
0x00, // END (chunk length: 8)
3232
0x05, 0x06, 0x07, 0x08, // SSRC 0x05060707
3333
0x01, 0x03, 0x05, 0x06, 0x07, // CNAME, len=3, content=5,6,7
3434
0x00, 0x00, 0x00} // END plus 2 padding (chunk length: 12)
3535
// V=2, P=0, chunks=2; PT=SDES; length=8 32bit words (36 bytes)
36-
var sdes_2 = []byte{0x81, 202, 0x00, 0x08,
36+
var sdes2 = []byte{0x81, 202, 0x00, 0x08,
3737
// first chunk, two items: CNAME, NAME, END)
3838
0x01, 0x02, 0x03, 0x04, // SSRC 0x01020304
3939
0x01, 0x01, 0x02, // CNAME, len=1, content=2 (item length: 3)
@@ -46,7 +46,7 @@ var sdes_2 = []byte{0x81, 202, 0x00, 0x08,
4646
0x00, 0x00, 0x00} // END plus 2 padding (chunk length: 12)
4747

4848
// V=2, P=0, chunks=2; PT=SDES; length=5 32bit words (24 bytes)
49-
var sdes_1_wrong = []byte{0x81, 202, 0x00, 0x05,
49+
var sdes1wrong = []byte{0x81, 202, 0x00, 0x05,
5050
0x01, 0x02, 0x03, 0x04, // SSRC 0x01020304
5151
0x01, 0x03, 0x02, // CNAME, len=3 (wrong, should be 1), content=2
5252
0x00, // END (chunk length: 8)
@@ -58,7 +58,7 @@ func sdesCheck(t *testing.T) (result bool) {
5858
result = false
5959

6060
rp := new(CtrlPacket) // allocate a new CTRL packet.
61-
rp.buffer = sdes_1
61+
rp.buffer = sdes1
6262

6363
cnt := int((rp.Length(0) + 1) * 4) // SDES Length incl. header word
6464
if cnt != 24 {
@@ -87,7 +87,7 @@ func sdesCheck(t *testing.T) (result bool) {
8787
return
8888
}
8989

90-
rp.buffer = sdes_2
90+
rp.buffer = sdes2
9191
cnt = int((rp.Length(0) + 1) * 4) // SDES Length incl. header word
9292
if cnt != 36 {
9393
t.Error(fmt.Sprintf("Basic second SDES length check failed. Expected: 36, got: %d\n", cnt))
@@ -115,7 +115,7 @@ func sdesCheck(t *testing.T) (result bool) {
115115
return
116116
}
117117

118-
rp.buffer = sdes_1_wrong
118+
rp.buffer = sdes1wrong
119119
offset = 4
120120
// SDES chunk starts ofter first header word
121121
sdesChunk = rp.toSdesChunk(offset, cnt-4)

src/net/rtp/datapacket_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ var payloadNull = []byte{}
3636
var initialPacket = []byte{0x80, 0x03, 0x47, 0x11, 0xf0, 0xe0, 0xd0, 0xc0, 0x01, 0x02, 0x03, 0x04,
3737
0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x20}
3838

39-
var csrc_1 = []uint32{0x21435465, 0x65544322}
40-
var csrc_2 = []uint32{0x23445566, 0x66554423, 0x87766554}
41-
var csrc_3 = []uint32{}
39+
var csrc1 = []uint32{0x21435465, 0x65544322}
40+
var csrc2 = []uint32{0x23445566, 0x66554423, 0x87766554}
41+
var csrc3 = []uint32{}
4242

4343
// profile ID length
44-
var ext_1 = []byte{0x77, 0x88, 0x00, 0x02, 0x01, 0x02, 0x03, 0x04, 0x04, 0x03, 0x02, 0x01} // len: 12
45-
var ext_2 = []byte{0x77, 0x89, 0x00, 0x03, 0x01, 0x02, 0x03, 0x04, 0x04, 0x03, 0x02, 0x01, 0x11, 0x22, 0x33, 0x44} // len: 16
46-
var ext_3 = []byte{0x77, 0x8a, 0x00, 0x00} // len: 4
47-
var ext_4 = []byte{}
44+
var ext1 = []byte{0x77, 0x88, 0x00, 0x02, 0x01, 0x02, 0x03, 0x04, 0x04, 0x03, 0x02, 0x01} // len: 12
45+
var ext2 = []byte{0x77, 0x89, 0x00, 0x03, 0x01, 0x02, 0x03, 0x04, 0x04, 0x03, 0x02, 0x01, 0x11, 0x22, 0x33, 0x44} // len: 16
46+
var ext3 = []byte{0x77, 0x8a, 0x00, 0x00} // len: 4
47+
var ext4 = []byte{}
4848

4949
func headerCheck(rp *DataPacket, t *testing.T) (result bool) {
5050
result = false
@@ -275,7 +275,7 @@ func rtpPacket(t *testing.T) {
275275
rp.SetPayload(payload)
276276

277277
// Now check CSRC list handling. These modify InUse and shift the payload inside the packet buffer.
278-
if !csrcTest(rp, t, csrc_1, 1) || !csrcTest(rp, t, csrc_2, 2) || !csrcTest(rp, t, csrc_3, 3) {
278+
if !csrcTest(rp, t, csrc1, 1) || !csrcTest(rp, t, csrc2, 2) || !csrcTest(rp, t, csrc3, 3) {
279279
return
280280
}
281281
// After last CSCR test the packet shall be in initial state, check it.
@@ -291,7 +291,7 @@ func rtpPacket(t *testing.T) {
291291
return
292292
}
293293
}
294-
if !extTest(rp, t, ext_1, 1) || !extTest(rp, t, ext_2, 2) || !extTest(rp, t, ext_3, 3) || !extTest(rp, t, ext_4, 4) {
294+
if !extTest(rp, t, ext1, 1) || !extTest(rp, t, ext2, 2) || !extTest(rp, t, ext3, 3) || !extTest(rp, t, ext4, 4) {
295295
return
296296
}
297297
// After last EXT test the packet shall be in initial state, check it.
@@ -307,14 +307,14 @@ func rtpPacket(t *testing.T) {
307307
return
308308
}
309309
}
310-
if !csrcTest(rp, t, csrc_1, 1) || !extTest(rp, t, ext_1, 1) {
310+
if !csrcTest(rp, t, csrc1, 1) || !extTest(rp, t, ext1, 1) {
311311
return
312312
}
313313
if *verbose {
314314
rp.Print("CSCR/EXT combined")
315315
}
316316
use = rp.InUse()
317-
expected := rtpHeaderLength + len(payload) + len(csrc_1)*4 + len(ext_1)
317+
expected := rtpHeaderLength + len(payload) + len(csrc1)*4 + len(ext1)
318318
if use != expected {
319319
t.Error(fmt.Sprintf("Packet length check afer CSRC/EXT failed. Expected: %d, got: %d\n", expected, use))
320320
return

src/net/rtp/doc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
//
1818

1919
/*
20-
The GoRTP package rtp implements the RTP/RTCP protocol.
20+
Package GoRTP implements the RTP/RTCP protocol.
2121
2222
This Go implementation of the RTP/RTCP protocol uses a set of structures to
2323
provide a high degree of flexibility and to adhere to the RFC 3550 notation of

0 commit comments

Comments
 (0)