forked from yutopp/go-rtmp
-
Notifications
You must be signed in to change notification settings - Fork 2
/
server_data_publish_handler.go
63 lines (53 loc) · 1.42 KB
/
server_data_publish_handler.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
//
// Copyright (c) 2018- yutopp ([email protected])
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
//
package rtmp
import (
"github.com/yutopp/go-rtmp/internal"
"github.com/yutopp/go-rtmp/message"
)
var _ stateHandler = (*serverDataPublishHandler)(nil)
// serverDataPublishHandler Handle data messages from a publisher at server side.
// transitions:
// | _ -> self
type serverDataPublishHandler struct {
sh *streamHandler
}
func (h *serverDataPublishHandler) onMessage(
chunkStreamID int,
timestamp uint32,
msg message.Message,
) error {
switch msg := msg.(type) {
case *message.AudioMessage:
return h.sh.stream.userHandler().OnAudio(timestamp, msg.Payload)
case *message.VideoMessage:
return h.sh.stream.userHandler().OnVideo(timestamp, msg.Payload)
default:
return internal.ErrPassThroughMsg
}
}
func (h *serverDataPublishHandler) onData(
chunkStreamID int,
timestamp uint32,
dataMsg *message.DataMessage,
body interface{},
) error {
switch data := body.(type) {
case *message.NetStreamSetDataFrame:
return h.sh.stream.userHandler().OnSetDataFrame(timestamp, data)
default:
return internal.ErrPassThroughMsg
}
}
func (h *serverDataPublishHandler) onCommand(
chunkStreamID int,
timestamp uint32,
cmdMsg *message.CommandMessage,
body interface{},
) error {
return internal.ErrPassThroughMsg
}