mirror of
https://github.com/zhangpeihao/gortmp
synced 2025-09-26 20:01:11 +08:00
Append Call function
This commit is contained in:
@@ -46,7 +46,7 @@ type OutboundConn interface {
|
||||
Send(message *Message) error
|
||||
// Calls a command or method on Flash Media Server
|
||||
// or on an application server running Flash Remoting.
|
||||
Call(customParameters ...interface{}) (err error)
|
||||
Call(name string, customParameters ...interface{}) (err error)
|
||||
// Get network connect instance
|
||||
Conn() Conn
|
||||
}
|
||||
@@ -376,8 +376,41 @@ func (obConn *outboundConn) Send(message *Message) error {
|
||||
|
||||
// Calls a command or method on Flash Media Server
|
||||
// or on an application server running Flash Remoting.
|
||||
func (obConn *outboundConn) Call(customParameters ...interface{}) (err error) {
|
||||
return errors.New("Unimplemented")
|
||||
func (obConn *outboundConn) Call(name string, customParameters ...interface{}) (err error) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
err = r.(error)
|
||||
if obConn.err == nil {
|
||||
obConn.err = err
|
||||
}
|
||||
}
|
||||
}()
|
||||
// Create command
|
||||
transactionID := obConn.conn.NewTransactionID()
|
||||
cmd := &Command{
|
||||
IsFlex: false,
|
||||
Name: name,
|
||||
TransactionID: transactionID,
|
||||
Objects: make([]interface{}, 1+len(customParameters)),
|
||||
}
|
||||
cmd.Objects[0] = nil
|
||||
for index, param := range customParameters {
|
||||
cmd.Objects[index+1] = param
|
||||
}
|
||||
buf := new(bytes.Buffer)
|
||||
err = cmd.Write(buf)
|
||||
CheckError(err, "Call() Create command")
|
||||
obConn.transactions[transactionID] = name
|
||||
|
||||
message := &Message{
|
||||
ChunkStreamID: CS_ID_COMMAND,
|
||||
Type: COMMAND_AMF0,
|
||||
Size: uint32(buf.Len()),
|
||||
Buf: buf,
|
||||
}
|
||||
message.Dump(name)
|
||||
return obConn.conn.Send(message)
|
||||
|
||||
}
|
||||
|
||||
// Get network connect instance
|
||||
|
@@ -47,6 +47,8 @@ type OutboundStream interface {
|
||||
PublishVideoData(data []byte, deltaTimestamp uint32) error
|
||||
// Publish data
|
||||
PublishData(dataType uint8, data []byte, deltaTimestamp uint32) error
|
||||
// Call
|
||||
Call(name string, customParameters ...interface{}) error
|
||||
}
|
||||
|
||||
// A publish stream
|
||||
@@ -144,13 +146,11 @@ func (stream *outboundStream) Publish(streamName, howToPublish string) (err erro
|
||||
func (stream *outboundStream) Play(streamName string, start, duration *uint32, reset *bool) (err error) {
|
||||
conn := stream.conn.Conn()
|
||||
// Keng-die: in stream transaction ID always been 0
|
||||
// Get transaction ID
|
||||
transactionID := conn.NewTransactionID()
|
||||
// Create play command
|
||||
cmd := &Command{
|
||||
IsFlex: false,
|
||||
Name: "play",
|
||||
TransactionID: transactionID,
|
||||
TransactionID: 0,
|
||||
Objects: make([]interface{}, 2),
|
||||
}
|
||||
cmd.Objects[0] = nil
|
||||
@@ -196,6 +196,41 @@ func (stream *outboundStream) Play(streamName string, start, duration *uint32, r
|
||||
return nil
|
||||
}
|
||||
|
||||
func (stream *outboundStream) Call(name string, customParameters ...interface{}) (err error) {
|
||||
conn := stream.conn.Conn()
|
||||
// Create play command
|
||||
cmd := &Command{
|
||||
IsFlex: false,
|
||||
Name: name,
|
||||
TransactionID: 0,
|
||||
Objects: make([]interface{}, 1+len(customParameters)),
|
||||
}
|
||||
cmd.Objects[0] = nil
|
||||
for index, param := range customParameters {
|
||||
cmd.Objects[index+1] = param
|
||||
}
|
||||
|
||||
// Construct message
|
||||
message := NewMessage(stream.chunkStreamID, COMMAND_AMF0, stream.id, 0, nil)
|
||||
if err = cmd.Write(message.Buf); err != nil {
|
||||
return
|
||||
}
|
||||
message.Dump(name)
|
||||
|
||||
err = conn.Send(message)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// Set Buffer Length
|
||||
// Buffer length
|
||||
if stream.bufferLength < MIN_BUFFER_LENGTH {
|
||||
stream.bufferLength = MIN_BUFFER_LENGTH
|
||||
}
|
||||
stream.conn.Conn().SetStreamBufferSize(stream.id, stream.bufferLength)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (stream *outboundStream) Received(message *Message) bool {
|
||||
if message.Type == VIDEO_TYPE || message.Type == AUDIO_TYPE {
|
||||
return false
|
||||
|
Reference in New Issue
Block a user