connect object processing, stream key checking
This commit is contained in:
parent
7782f14eb5
commit
0c054b67c0
2 changed files with 60 additions and 5 deletions
|
@ -1,15 +1,45 @@
|
|||
package amf
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
type AMFObj map[interface{}]interface{}
|
||||
|
||||
func DecodeAMF(data *[]byte) (AMFObj, error) {
|
||||
obj := make(AMFObj)
|
||||
test := make(AMFObj)
|
||||
fmt.Println("a")
|
||||
obj[0] = "connect"
|
||||
obj[1] = float64(1)
|
||||
obj[2] = test
|
||||
fmt.Println(obj)
|
||||
test["tcUrl"] = "test"
|
||||
test["tcUrl"] = "rtmp://test-domain.nil/Desktop/tmp"
|
||||
return obj, nil
|
||||
}
|
||||
|
||||
func (amf_obj_root AMFObj) ProcessConnect() (string, error) {
|
||||
err := errors.New("Bad AMF connect command")
|
||||
if _, ok := amf_obj_root[0]; !ok {
|
||||
return "", err
|
||||
} else if command_string, ok := amf_obj_root[0].(string); !ok || command_string != "connect" {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if _, ok := amf_obj_root[1]; !ok {
|
||||
return "", err
|
||||
} else if transac_id_float, ok := amf_obj_root[1].(float64); !ok || transac_id_float != 1.0 {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if _, ok := amf_obj_root[2]; !ok {
|
||||
return "", err
|
||||
} else if _, ok := amf_obj_root[2].(AMFObj); !ok {
|
||||
return "", err
|
||||
} else if _, ok := amf_obj_root[2].(AMFObj)["tcUrl"]; !ok {
|
||||
return "", err
|
||||
} else if tcUrl, ok := amf_obj_root[2].(AMFObj)["tcUrl"].(string); ok {
|
||||
return tcUrl, nil
|
||||
} else {
|
||||
return "", err
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,6 +4,10 @@ import (
|
|||
"net"
|
||||
"encoding/binary"
|
||||
"stream_server/rtmp/amf"
|
||||
"errors"
|
||||
"strings"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
type ChunkWrapper struct {
|
||||
|
@ -66,6 +70,27 @@ func (chnk_wrp_ptr *ChunkWrapper) ReadConnectCommand() (error) {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
chnk_wrp_ptr.params.stream_key = amf_obj[2].(amf.AMFObj)["tcUrl"].(string)
|
||||
tcUrl, err := amf_obj.ProcessConnect()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if chnk_wrp_ptr.params.stream_key, err = check_stream_key(tcUrl); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func check_stream_key(tcUrl string) (string, error) {
|
||||
err := errors.New("bad stream key")
|
||||
tcUrl_split := strings.Split(tcUrl, "/")
|
||||
if len(tcUrl_split) != 5 {
|
||||
return "", err
|
||||
}
|
||||
base_dir, _ := os.UserHomeDir()
|
||||
stream_dir := base_dir + "/live/" + tcUrl_split[4]
|
||||
fileinfo, err := os.Stat(stream_dir)
|
||||
if err == nil && fileinfo.IsDir() {
|
||||
return tcUrl_split[4], nil
|
||||
}
|
||||
return "", err
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue