stream-server/srt/stream_ids.go

44 lines
941 B
Go
Raw Normal View History

2023-09-21 13:36:11 +05:00
package srt
import (
"os"
"io"
"strings"
2023-09-22 12:33:55 +05:00
"stream_server/transcoder"
2023-09-21 13:36:11 +05:00
)
func NewWriter(stream_key string) (io.WriteCloser, error) {
2023-09-22 12:33:55 +05:00
transcoder_in, err := transcoder.NewTranscoder(stream_key)
2023-09-21 13:36:11 +05:00
if err != nil {
return nil, err
}
2023-09-22 12:33:55 +05:00
return transcoder_in, nil
2023-09-21 13:36:11 +05:00
}
func CheckStreamID(stream_id []byte) (io.WriteCloser, bool) {
stream_key := make([]byte, 0)
for i := len(stream_id) - 1; i >= 0; i-- {
if stream_id[i] == 0 {
break
}
stream_key = append(stream_key, stream_id[i])
}
stream_key_string := strings.TrimSpace(string(stream_key))
if check_stream_key(stream_key_string) {
writer, err := NewWriter(stream_key_string)
if err != nil {
return nil, false
}
return writer, true
}
return nil, false
}
func check_stream_key(stream_key string) (bool) {
base_dir, _ := os.UserHomeDir()
if fileinfo, err := os.Stat(base_dir + "/live/" + stream_key); err == nil && fileinfo.IsDir() {
return true
}
return false
}