-
Notifications
You must be signed in to change notification settings - Fork 5
/
protocol.go
76 lines (61 loc) · 1.52 KB
/
protocol.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
69
70
71
72
73
74
75
76
package amp
// "A Media Protocol"
// Mini-protocol to initiate and control an RTP/RTCP media stream.
import (
"encoding/gob"
"fmt"
"net"
"strconv"
"github.com/antongulenko/RTP/protocols"
)
var (
Protocol *ampProtocol
MiniProtocol = protocols.NewMiniProtocol(Protocol)
)
const (
CodeStartStream = protocols.Code(15 + iota)
CodeStopStream
)
// ======================= Packets =======================
type ClientDescription struct {
ReceiverHost string
Port int
}
type StartStream struct {
ClientDescription
MediaFile string
}
type StopStream struct {
ClientDescription
}
func (client *ClientDescription) Client() string {
return net.JoinHostPort(client.ReceiverHost, strconv.Itoa(client.Port))
}
// ======================= Protocol =======================
type ampProtocol struct {
}
func (*ampProtocol) Name() string {
return "AMP"
}
func (proto *ampProtocol) Decoders() protocols.DecoderMap {
return protocols.DecoderMap{
CodeStartStream: proto.decodeStartStream,
CodeStopStream: proto.decodeStopStream,
}
}
func (proto *ampProtocol) decodeStartStream(decoder *gob.Decoder) (interface{}, error) {
var val StartStream
err := decoder.Decode(&val)
if err != nil {
return nil, fmt.Errorf("Error decoding AMP StartStream value: %v", err)
}
return &val, nil
}
func (proto *ampProtocol) decodeStopStream(decoder *gob.Decoder) (interface{}, error) {
var val StopStream
err := decoder.Decode(&val)
if err != nil {
return nil, fmt.Errorf("Error decoding AMP StopStream value: %v", err)
}
return &val, nil
}