Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(deps): update dependency @iconify-json/material-symbols to v1.2.1 #511

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"format": "prettier . --write --ignore-path .gitignore"
},
"dependencies": {
"@iconify-json/material-symbols": "1.2.0",
"@iconify-json/material-symbols": "1.2.1",
"@iconify/vue": "4.1.2",
"@types/chromecast-caf-sender": "1.0.10",
"@vitejs/plugin-vue": "5.1.3",
Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ require (
github.com/dustin/go-humanize v1.0.1
github.com/gopxl/beep/v2 v2.0.3
github.com/labstack/echo/v5 v5.0.0-20230722203903-ec5b858dab61
github.com/lmittmann/tint v1.0.5
github.com/mattn/go-isatty v0.0.20
github.com/pocketbase/dbx v1.10.1
github.com/pocketbase/pocketbase v0.22.20
github.com/prometheus/client_golang v1.20.2
github.com/samber/slog-multi v1.2.1
github.com/spf13/cobra v1.8.1
github.com/stretchr/testify v1.9.0
github.com/u2takey/ffmpeg-go v0.5.0
github.com/viert/go-lame v0.0.0-20201108052322-bb552596b11d
golang.org/x/sync v0.8.0
Expand Down Expand Up @@ -43,7 +45,6 @@ require (
github.com/aws/smithy-go v1.20.4 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/disintegration/imaging v1.6.2 // indirect
github.com/domodwyer/mailyak/v3 v3.6.2 // indirect
github.com/fatih/color v1.17.0 // indirect
Expand All @@ -65,19 +66,18 @@ require (
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-sqlite3 v1.14.22 // indirect
github.com/mewkiz/flac v1.0.12 // indirect
github.com/mewkiz/pkg v0.0.0-20230226050401-4010bf0fec14 // indirect
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/ncruces/go-strftime v0.1.9 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/samber/lo v1.38.1 // indirect
github.com/spf13/cast v1.7.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/u2takey/go-utils v0.3.1 // indirect
Expand All @@ -86,6 +86,7 @@ require (
go.opencensus.io v0.24.0 // indirect
gocloud.dev v0.39.0 // indirect
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/exp v0.0.0-20231108232855-2478ac86f678 // indirect
golang.org/x/image v0.19.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/oauth2 v0.22.0 // indirect
Expand All @@ -98,7 +99,6 @@ require (
google.golang.org/genproto/googleapis/rpc v0.0.0-20240827150818-7e3bb234dfed // indirect
google.golang.org/grpc v1.65.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
modernc.org/gc/v3 v3.0.0-20240801135723-a856999a2e4a // indirect
modernc.org/libc v1.55.3 // indirect
modernc.org/mathutil v1.6.0 // indirect
Expand Down
10 changes: 8 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/labstack/echo/v5 v5.0.0-20230722203903-ec5b858dab61 h1:FwuzbVh87iLiUQj1+uQUsuw9x5t9m5n5g7rG7o4svW4=
github.com/labstack/echo/v5 v5.0.0-20230722203903-ec5b858dab61/go.mod h1:paQfF1YtHe+GrGg5fOgjsjoCX/UKDr9bc1DoWpZfns8=
github.com/lmittmann/tint v1.0.5 h1:NQclAutOfYsqs2F1Lenue6OoWCajs5wJcP3DfWVpePw=
github.com/lmittmann/tint v1.0.5/go.mod h1:HIS3gSy7qNwGCj+5oRjAutErFBl4BzdQP6cJZ0NfMwE=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
Expand Down Expand Up @@ -248,6 +250,10 @@ github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qq
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/samber/lo v1.38.1 h1:j2XEAqXKb09Am4ebOg31SpvzUTTs6EN3VfgeLUhPdXM=
github.com/samber/lo v1.38.1/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA=
github.com/samber/slog-multi v1.2.1 h1:MRVc6JxvGiZ+ubyANneZkMREAFAykoW0CACJZagT7so=
github.com/samber/slog-multi v1.2.1/go.mod h1:uLAvHpGqbYgX4FSL0p1ZwoLuveIAJvBECtE07XmYvFo=
github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
github.com/spf13/cast v1.7.0 h1:ntdiHjuueXFgm5nzDRdOS4yfT43P5Fnud6DH50rz/7w=
github.com/spf13/cast v1.7.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
Expand Down Expand Up @@ -297,6 +303,8 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20231108232855-2478ac86f678 h1:mchzmB1XO2pMaKFRqk/+MV3mgGG96aqaPXaMifQU47w=
golang.org/x/exp v0.0.0-20231108232855-2478ac86f678/go.mod h1:zk2irFbV9DP96SEBUUAy67IdHUaZuSnrz1n472HUCLE=
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.5.0/go.mod h1:FVC7BI/5Ym8R25iw5OLsgshdUBbT1h5jZTpA+mvAdZ4=
golang.org/x/image v0.19.0 h1:D9FX4QWkLfkeqaC62SonffIIuYdOk/UE2XKUBgRIBIQ=
Expand Down Expand Up @@ -408,8 +416,6 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Expand Down
12 changes: 4 additions & 8 deletions internal/encoder/encode/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ import (
// Encode writes a duration of the audio stream in PCM format.
//
// Format precision must be 1 or 2 bytes.
func Encode(ctx context.Context, duration time.Duration, entry *streamcache.Entry) error {
func Encode(ctx context.Context, entry *streamcache.Entry) error {
durationPerLoop := time.Second / 10
samples := make([][2]float64, entry.Format.SampleRate.N(durationPerLoop))
buffer := make([]byte, len(samples)*entry.Format.Width())

var writtenDuration time.Duration
for {
n, ok := entry.Mix.Stream(samples)
if !ok {
Expand All @@ -41,14 +40,11 @@ func Encode(ctx context.Context, duration time.Duration, entry *streamcache.Entr
case <-ctx.Done():
return nil
default:
_, err := entry.Encoder.Write(buffer[:n*entry.Format.Width()])
if err != nil {
if _, err := entry.Encoder.Write(buffer[:n*entry.Format.Width()]); err != nil {
return err
}

writtenDuration += durationPerLoop
if writtenDuration >= duration {
return nil
if entry.Writer.Err != nil {
return entry.Writer.Err
}
}
}
Expand Down
84 changes: 29 additions & 55 deletions internal/handlers/mix.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ import (
"errors"
"fmt"
"io"
"log/slog"
"net/http"
"os"
"path/filepath"
"strconv"
"strings"
"syscall"
"time"

"github.com/gabe565/relax-sounds/internal/encoder/encode"
"github.com/gabe565/relax-sounds/internal/encoder/filetype"
Expand All @@ -23,21 +21,8 @@ import (
"github.com/labstack/echo/v5/middleware"
"github.com/pocketbase/pocketbase"
"github.com/pocketbase/pocketbase/apis"
"github.com/spf13/cobra"
)

func MixFlags(cmd *cobra.Command) {
chunkLengthDefault := 2 * time.Minute
if env := os.Getenv("STREAM_CHUNK_LENGTH"); env != "" {
var err error
chunkLengthDefault, err = time.ParseDuration(env)
if err != nil {
slog.Warn("Failed to parse STREAM_CHUNK_LENGTH env", "error", err)
}
}
cmd.PersistentFlags().Duration("stream-chunk-length", chunkLengthDefault, "Sets the length of each chunk when casting")
}

func NewMix(app *pocketbase.PocketBase) *Mix {
return &Mix{
app: app,
Expand All @@ -57,10 +42,11 @@ func (m *Mix) RegisterRoutes(e *echo.Echo) {

func (m *Mix) Mix() echo.HandlerFunc {
dataFs := os.DirFS(filepath.Join(m.app.DataDir(), "storage"))
chunkLength, err := m.app.RootCmd.PersistentFlags().GetDuration("stream-chunk-length")
if err != nil {
panic(err)
}

const (
TotalSize = 1500 * 1024 * 1024
ChunkSize = 2 * 1024 * 1024
)

return func(c echo.Context) error {
var err error
Expand Down Expand Up @@ -131,7 +117,7 @@ func (m *Mix) Mix() echo.HandlerFunc {
}

// Get current filetype encoder
entry.Encoder, err = fileType.NewEncoder(entry.Buffer, entry.Format)
entry.Encoder, err = fileType.NewEncoder(entry.Writer, entry.Format)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -165,49 +151,37 @@ func (m *Mix) Mix() echo.HandlerFunc {
}
}

var currChunkLength time.Duration
// First chunks will be smaller to minimize delay
switch entry.ChunkNum {
case 0:
currChunkLength = 15 * time.Second
case 1:
currChunkLength = time.Minute
default:
currChunkLength = chunkLength
}

// Ensure a single stream isn't fetched in parallel
entry.Mu.Lock()
defer entry.Mu.Unlock()

// Mux streams to encoder
if err = encode.Encode(c.Request().Context(), currChunkLength, entry); err != nil {
panic(err)
}

if entry.TotalSize == 0 {
// Set total length to ~24 hours
// Actual length will vary when using VBR
entry.TotalSize = entry.Buffer.Len() * int(24*time.Hour/currChunkLength)
}

c.Response().Header().Set("Content-Length", strconv.Itoa(entry.Buffer.Len()))
lastByteIdx := firstByteIdx + entry.Buffer.Len() - 1
c.Response().Header().Set(
"Content-Range",
fmt.Sprintf("bytes %d-%d/%d", firstByteIdx, lastByteIdx, entry.TotalSize),
)
chunkSize := ChunkSize + entry.Writer.Buffered()
c.Response().Header().Set("Content-Length", strconv.Itoa(chunkSize))
c.Response().Header().Set("Content-Range", fmt.Sprintf(
"bytes %d-%d/%d",
firstByteIdx,
firstByteIdx+chunkSize-1,
TotalSize,
))
entry.Writer.SetWriter(c.Response())
entry.Writer.Limit = chunkSize

// Write buffered stream data to client
c.Response().WriteHeader(http.StatusPartialContent)
n, err := io.Copy(c.Response(), entry.Buffer)
if err != nil {
if !errors.Is(err, syscall.EPIPE) && !errors.Is(err, syscall.ECONNRESET) {
panic(err)
defer func() {
entry.Transferred += c.Response().Size
}()

// Mux streams to encoder
if err = encode.Encode(c.Request().Context(), entry); err != nil {
switch {
case errors.Is(err, io.ErrShortWrite):
case errors.Is(err, syscall.EPIPE):
case errors.Is(err, syscall.ECONNRESET):
default:
return apis.NewApiError(http.StatusInternalServerError, "", err)
}
}
entry.Transferred += uint64(n)
entry.ChunkNum++

return nil
}
}
Expand Down
77 changes: 0 additions & 77 deletions internal/stream/streamcache/buffer.go

This file was deleted.

Loading
Loading