diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..3560ccb --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,33 @@ +name: release + +on: + push: + tags: + - "v*" + +permissions: + contents: write + +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v4 + + - name: Install UPX + uses: crazy-max/ghaction-upx@v3 + with: + install-only: true + + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v5 + with: + distribution: goreleaser + version: latest + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/server/server.go b/server/server.go index 6708529..08e8a49 100644 --- a/server/server.go +++ b/server/server.go @@ -109,10 +109,9 @@ func (s *Server) handleWebSocket(c *gin.Context) { go func() { ticker := time.NewTicker(1 * time.Second) for range ticker.C { - currentVideoPath, _ := streamer.GlobalStreamer.GetCurrentVideoPath() s.Broadcast(mywebsocket.Date{ Timestamp: time.Now().UnixMilli(), - CurrentVideoPath: currentVideoPath, + CurrentVideoPath: streamer.GlobalStreamer.GetCurrentVideoPath(), VideoList: streamer.GlobalStreamer.GetVideoListPath(), Output: streamer.GlobalStreamer.GetOutput(), }) diff --git a/streamer/streamer.go b/streamer/streamer.go index 6ba3a5b..6c66989 100644 --- a/streamer/streamer.go +++ b/streamer/streamer.go @@ -3,7 +3,6 @@ package streamer import ( "bufio" "context" - "errors" "fmt" "io" "live-streamer/config" @@ -21,6 +20,7 @@ type playState struct { cmd *exec.Cmd ctx context.Context cancel context.CancelFunc + waitDone chan any } type Streamer struct { @@ -52,6 +52,7 @@ func (s *Streamer) start() { currentVideo := s.videoList[s.playState.currentVideoIndex] videoPath := currentVideo.Path s.playState.cmd = exec.CommandContext(s.playState.ctx, "ffmpeg", s.buildFFmpegArgs(currentVideo)...) + s.playState.waitDone = make(chan any) cmd := s.playState.cmd s.playStateMu.Unlock() @@ -89,6 +90,7 @@ func (s *Streamer) start() { } s.videoMu.RUnlock() } + close(s.playState.waitDone) s.playStateMu.Unlock() } @@ -108,7 +110,7 @@ func (s *Streamer) Stop() { s.playState.cancel = nil cmd := s.playState.cmd s.playState.cmd = nil - ctx := s.playState.ctx + done := s.playState.waitDone s.playStateMu.Unlock() if cancel == nil || cmd == nil { @@ -119,7 +121,7 @@ func (s *Streamer) Stop() { if cmd.Process != nil { select { - case <-ctx.Done(): + case <-done: case <-time.After(3 * time.Second): _ = cmd.Process.Kill() } @@ -220,7 +222,7 @@ func (s *Streamer) log(reader *bufio.Reader) { for { n, err := reader.Read(buf) if n > 0 { - videoPath, _ := s.GetCurrentVideoPath() + videoPath := s.GetCurrentVideoPath() buf = append([]byte(videoPath), buf...) s.writeOutput(string(buf[:n+len(videoPath)])) } @@ -234,13 +236,13 @@ func (s *Streamer) log(reader *bufio.Reader) { } } -func (s *Streamer) GetCurrentVideoPath() (string, error) { +func (s *Streamer) GetCurrentVideoPath() string { s.videoMu.RLock() defer s.videoMu.RUnlock() if len(s.videoList) == 0 { - return "", errors.New("no video streaming") + return "" } - return s.videoList[s.GetCurrentIndex()].Path, nil + return s.videoList[s.GetCurrentIndex()].Path } func (s *Streamer) GetVideoList() []config.InputItem {