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
|
package amf
|
||||||
|
|
||||||
import "fmt"
|
import (
|
||||||
|
"errors"
|
||||||
|
)
|
||||||
|
|
||||||
type AMFObj map[interface{}]interface{}
|
type AMFObj map[interface{}]interface{}
|
||||||
|
|
||||||
func DecodeAMF(data *[]byte) (AMFObj, error) {
|
func DecodeAMF(data *[]byte) (AMFObj, error) {
|
||||||
obj := make(AMFObj)
|
obj := make(AMFObj)
|
||||||
test := make(AMFObj)
|
test := make(AMFObj)
|
||||||
fmt.Println("a")
|
obj[0] = "connect"
|
||||||
|
obj[1] = float64(1)
|
||||||
obj[2] = test
|
obj[2] = test
|
||||||
fmt.Println(obj)
|
test["tcUrl"] = "rtmp://test-domain.nil/Desktop/tmp"
|
||||||
test["tcUrl"] = "test"
|
|
||||||
return obj, nil
|
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"
|
"net"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"stream_server/rtmp/amf"
|
"stream_server/rtmp/amf"
|
||||||
|
"errors"
|
||||||
|
"strings"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ChunkWrapper struct {
|
type ChunkWrapper struct {
|
||||||
|
@ -66,6 +70,27 @@ func (chnk_wrp_ptr *ChunkWrapper) ReadConnectCommand() (error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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
|
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