mirror of
https://github.com/aler9/rtsp-simple-server
synced 2025-10-12 19:10:19 +08:00
rtmp: rewrite implementation of rtmp connection (#1047)
* rtmp: improve MsgCommandAMF0 * rtmp: fix MsgSetPeerBandwidth * rtmp: add message tests * rtmp: replace implementation with new one * rtmp: rename handshake functions * rtmp: avoid calling useless function * rtmp: use time.Duration for PTSDelta * rtmp: fix decoding chunks with relevant size * rtmp: rewrite implementation of rtmp connection * rtmp: fix tests * rtmp: improve error message * rtmp: replace h264 config implementation * link against github.com/notedit/rtmp * normalize MessageStreamID * rtmp: make acknowledge optional * rtmp: fix decoding of chunk2 + chunk3 * avoid using encoding/binary
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package message
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/notedit/rtmp/format/flv/flvio"
|
||||
|
||||
"github.com/aler9/rtsp-simple-server/internal/rtmp/chunk"
|
||||
@@ -11,7 +13,9 @@ import (
|
||||
type MsgCommandAMF0 struct {
|
||||
ChunkStreamID byte
|
||||
MessageStreamID uint32
|
||||
Payload []interface{}
|
||||
Name string
|
||||
CommandID int
|
||||
Arguments []interface{}
|
||||
}
|
||||
|
||||
// Unmarshal implements Message.
|
||||
@@ -23,7 +27,24 @@ func (m *MsgCommandAMF0) Unmarshal(raw *rawmessage.Message) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
m.Payload = payload
|
||||
|
||||
if len(payload) < 3 {
|
||||
return fmt.Errorf("invalid command payload")
|
||||
}
|
||||
|
||||
var ok bool
|
||||
m.Name, ok = payload[0].(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("invalid command payload")
|
||||
}
|
||||
|
||||
tmp, ok := payload[1].(float64)
|
||||
if !ok {
|
||||
return fmt.Errorf("invalid command payload")
|
||||
}
|
||||
m.CommandID = int(tmp)
|
||||
|
||||
m.Arguments = payload[2:]
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -34,6 +55,9 @@ func (m MsgCommandAMF0) Marshal() (*rawmessage.Message, error) {
|
||||
ChunkStreamID: m.ChunkStreamID,
|
||||
Type: chunk.MessageTypeCommandAMF0,
|
||||
MessageStreamID: m.MessageStreamID,
|
||||
Body: flvio.FillAMF0ValsMalloc(m.Payload),
|
||||
Body: flvio.FillAMF0ValsMalloc(append([]interface{}{
|
||||
m.Name,
|
||||
float64(m.CommandID),
|
||||
}, m.Arguments...)),
|
||||
}, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user