mirror of
https://github.com/lkmio/lkm.git
synced 2025-10-05 15:16:49 +08:00
统一sourceid格式
This commit is contained in:
53
stream/source_utils.go
Normal file
53
stream/source_utils.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package stream
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func (s SourceType) ToString() string {
|
||||
if SourceTypeRtmp == s {
|
||||
return "rtmp"
|
||||
} else if SourceType28181 == s {
|
||||
return "28181"
|
||||
} else if SourceType1078 == s {
|
||||
return "jt1078"
|
||||
}
|
||||
|
||||
panic(fmt.Sprintf("unknown source type %d", s))
|
||||
}
|
||||
|
||||
func (p Protocol) ToString() string {
|
||||
if ProtocolRtmp == p {
|
||||
return "rtmp"
|
||||
} else if ProtocolFlv == p {
|
||||
return "flv"
|
||||
} else if ProtocolRtsp == p {
|
||||
return "rtsp"
|
||||
} else if ProtocolHls == p {
|
||||
return "hls"
|
||||
} else if ProtocolRtc == p {
|
||||
return "rtc"
|
||||
}
|
||||
|
||||
panic(fmt.Sprintf("unknown stream protocol %d", p))
|
||||
}
|
||||
|
||||
func Path2SourceId(path string, suffix string) (string, error) {
|
||||
source := strings.TrimSpace(path)
|
||||
if strings.HasPrefix(source, "/") {
|
||||
source = source[1:]
|
||||
}
|
||||
|
||||
if len(suffix) > 0 && strings.HasSuffix(source, suffix) {
|
||||
source = source[:len(source)-len(suffix)]
|
||||
}
|
||||
|
||||
source = strings.TrimSpace(source)
|
||||
|
||||
if len(strings.TrimSpace(source)) == 0 {
|
||||
return "", fmt.Errorf("the request source cannot be empty")
|
||||
}
|
||||
|
||||
return source, nil
|
||||
}
|
Reference in New Issue
Block a user