51 lines
1.3 KiB
Go
51 lines
1.3 KiB
Go
package storage
|
|
|
|
import (
|
|
"git.insit.tech/sas/rtsp_proxy/protos"
|
|
"log"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
// CutURI returns the last part of the URI after "/".
|
|
func CutURI(URI string) (CutterURI string) {
|
|
splitted := strings.Split(URI, "/")
|
|
return splitted[len(splitted)-1]
|
|
}
|
|
|
|
// CreateFileName creates FileName structure.
|
|
func CreateFileName(dir string, resolutions []string, URI string, period int) *protos.FileName {
|
|
fn := protos.FileName{
|
|
Path: dir + "/data/" + URI + "/" + resolutions[0],
|
|
TimeNow: time.Now().Format("15-04-05_02-01-2006"),
|
|
Name: "videoFragment",
|
|
Number: -1,
|
|
Duration: float64(period),
|
|
}
|
|
|
|
return &fn
|
|
}
|
|
|
|
// WaitPeriod waits for the next period.
|
|
func WaitPeriod(period int) {
|
|
periodTD := time.Duration(period) * time.Second
|
|
|
|
now := time.Now()
|
|
nextSegment := now.Truncate(periodTD).Add(periodTD)
|
|
waitDuration := nextSegment.Sub(now)
|
|
log.Printf("waiting for start recording: %v\n", waitDuration)
|
|
time.Sleep(waitDuration)
|
|
}
|
|
|
|
func FindResolution(Body []byte) string {
|
|
split := strings.Split(string(Body), "\n")
|
|
for _, line := range split {
|
|
if strings.Contains(line, "a=x-dimensions:") {
|
|
s, _ := strings.CutPrefix(line, "a=x-dimensions:")
|
|
resolution := strings.Join(strings.Split(s, ","), "-")
|
|
return resolution
|
|
}
|
|
}
|
|
return "resolution"
|
|
}
|