Skip to content

Commit

Permalink
Adding more logging
Browse files Browse the repository at this point in the history
  • Loading branch information
COMTOP1 committed Feb 16, 2024
1 parent 339915d commit 8688644
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion recorder/recorder_start.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,22 @@ import (
)

func (v *Views) start(transporter commonTransporter.Transporter) error {
log.Println(1)
array := strings.Split(transporter.Payload.(commonTransporter.RecorderStart).PathOut, "/")
valid := false
var path string
log.Println(2)

if len(array) == 0 || array == nil {
return fmt.Errorf("failed to get path out array")
}

log.Println(3)
if len(array) == 1 {
valid = true
log.Println(4)
} else {
log.Println(5)
for i := 0; i < len(array)-1; i++ {
path += array[i] + "/"
}
Expand All @@ -39,60 +44,75 @@ func (v *Views) start(transporter commonTransporter.Transporter) error {
}
valid = true
}
log.Println(6)
if !valid {
return fmt.Errorf("invalid path: %+v", transporter)
}

log.Println(7)
tempBaseFileName := strings.Split(array[len(array)-1], ".")
if len(tempBaseFileName) < 2 || tempBaseFileName == nil {
return fmt.Errorf("failed to get base file name: %s", tempBaseFileName)
}
log.Println(8)
baseFileNameArray := tempBaseFileName[0 : len(tempBaseFileName)-1]
var baseFileName string
for _, s := range baseFileNameArray {
baseFileName += s
}
log.Println(9)

streamIn := fmt.Sprintf("%s://%s%s", v.Config.StreamServerScheme, v.Config.StreamServer, transporter.Payload.(commonTransporter.RecorderStart).StreamIn)
path = v.Config.RecordingLocation + path

log.Println(10)
finish := make(chan bool)

err := v.cache.Add(fmt.Sprintf("%s_%s", transporter.Unique, finishChannelNameAppend), finish, cache.NoExpiration)
if err != nil {
return fmt.Errorf("failed to add finishing channel to cache: %w", err)
}

log.Println(11)
go func() {
log.Println(14)
var i uint64
for {
v.cache.Delete(transporter.Unique)
select {
case <-finish:
return
default:
log.Println(15)
// Checking if file exists
_, err = os.Stat(fmt.Sprintf("\"%s%s_%d.mkv", path, baseFileName, i))
if err == nil {
break
}
log.Println(16)
err = v.helperStart(transporter, fmt.Sprintf("\"%s\"", streamIn), path, baseFileName, i)
log.Println(17)
if err != nil {
log.Printf("failed to record: %+v", err)
return
}
log.Println(18)
time.Sleep(500 * time.Millisecond)
}
i++
}
}()
log.Println(12)

go func() {
log.Println(13)
for {
select {
case <-finish:
cmd, ok := v.cache.Get(transporter.Unique)
if !ok {
log.Println("unable to get cmd from cache")
return
}
c1 := cmd.(*exec.Cmd)
err = c1.Process.Kill()
Expand All @@ -113,7 +133,7 @@ func (v *Views) start(transporter commonTransporter.Transporter) error {
}

func (v *Views) helperStart(transporter commonTransporter.Transporter, streamIn, path, baseFileName string, i uint64) error {
c := exec.Command("ffmpeg", "-i", streamIn, "-c", "copy", fmt.Sprintf("\"%s%s_%d.mkv", path, baseFileName, i))
c := exec.Command("ffmpeg", "-i", streamIn, "-c", "copy", fmt.Sprintf("\"%s%s_%d.mkv\"", path, baseFileName, i))
err := v.cache.Add(transporter.Unique+strconv.FormatUint(i, 10), c, cache.NoExpiration)
if err != nil {
return fmt.Errorf("failed to add command to cache: %w", err)
Expand Down

0 comments on commit 8688644

Please sign in to comment.