app run in app.go
This commit is contained in:
+8
-43
@@ -5,7 +5,6 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
@@ -26,8 +25,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
APP_NAME = "MXL pattern generator"
|
APP_NAME = app.Name
|
||||||
APP_VER = "0.1.0"
|
APP_VER = app.Version
|
||||||
)
|
)
|
||||||
|
|
||||||
type appArgs struct {
|
type appArgs struct {
|
||||||
@@ -424,7 +423,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func run(ctx context.Context, args appArgs) (runErr error) {
|
func run(ctx context.Context, args appArgs) error {
|
||||||
videoCfg, err := buildVideoConfig(args)
|
videoCfg, err := buildVideoConfig(args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("video configuration: %w", err)
|
return fmt.Errorf("video configuration: %w", err)
|
||||||
@@ -434,43 +433,9 @@ func run(ctx context.Context, args appArgs) (runErr error) {
|
|||||||
return fmt.Errorf("audio configuration: %w", err)
|
return fmt.Errorf("audio configuration: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("%s %s", APP_NAME, APP_VER)
|
return app.Run(ctx, app.Config{
|
||||||
log.Printf("Domain: %s", args.domain)
|
Domain: args.domain,
|
||||||
log.Printf("Video: %dx%d %d/%d",
|
Video: videoCfg,
|
||||||
videoCfg.Width(), videoCfg.Height(), videoCfg.Rate().Num, videoCfg.Rate().Den)
|
Audio: audioCfg,
|
||||||
log.Printf("Video ID: %s", videoCfg.ID())
|
})
|
||||||
if audioCfg != nil {
|
|
||||||
log.Printf("Audio: %d channels %d/%d Hz %.0f dBFS",
|
|
||||||
audioCfg.Channels(), audioCfg.Rate().Num, audioCfg.Rate().Den, audioCfg.LevelDBFS)
|
|
||||||
log.Printf("Audio ID: %s", audioCfg.ID())
|
|
||||||
}
|
|
||||||
|
|
||||||
inst, err := mxl.NewInstance(args.domain, "")
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("initialize MXL domain %q: %w", args.domain, err)
|
|
||||||
}
|
|
||||||
defer func() {
|
|
||||||
if err := inst.Close(); err != nil {
|
|
||||||
runErr = errors.Join(runErr, fmt.Errorf("close MXL instance: %w", err))
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
runners := []app.Runner{
|
|
||||||
{
|
|
||||||
Name: "video",
|
|
||||||
Run: func(ctx context.Context) error {
|
|
||||||
return video.Run(ctx, inst, videoCfg)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
if audioCfg != nil {
|
|
||||||
runners = append(runners, app.Runner{
|
|
||||||
Name: "audio",
|
|
||||||
Run: func(ctx context.Context) error {
|
|
||||||
return audio.Run(ctx, inst, *audioCfg)
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return app.RunConcurrent(ctx, runners...)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
|
||||||
|
"mxl-pattern-generator/internal/audio"
|
||||||
|
"mxl-pattern-generator/internal/video"
|
||||||
|
|
||||||
|
"github.com/qvest-digital/go-mxl/mxl"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
Name = "MXL pattern generator"
|
||||||
|
Version = "0.1.0"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
Domain string
|
||||||
|
Video video.Config
|
||||||
|
Audio *audio.Config
|
||||||
|
}
|
||||||
|
|
||||||
|
func Run(ctx context.Context, cfg Config) (runErr error) {
|
||||||
|
log.Printf("%s %s", Name, Version)
|
||||||
|
log.Printf("Domain: %s", cfg.Domain)
|
||||||
|
log.Printf("Video: %dx%d %d/%d",
|
||||||
|
cfg.Video.Width(), cfg.Video.Height(), cfg.Video.Rate().Num, cfg.Video.Rate().Den)
|
||||||
|
log.Printf("Video ID: %s", cfg.Video.ID())
|
||||||
|
if cfg.Audio != nil {
|
||||||
|
log.Printf("Audio: %d channels %d/%d Hz %.0f dBFS",
|
||||||
|
cfg.Audio.Channels(), cfg.Audio.Rate().Num, cfg.Audio.Rate().Den, cfg.Audio.LevelDBFS)
|
||||||
|
log.Printf("Audio ID: %s", cfg.Audio.ID())
|
||||||
|
}
|
||||||
|
|
||||||
|
inst, err := mxl.NewInstance(cfg.Domain, "")
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("initialize MXL domain %q: %w", cfg.Domain, err)
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
if err := inst.Close(); err != nil {
|
||||||
|
runErr = errors.Join(runErr, fmt.Errorf("close MXL instance: %w", err))
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
runners := []Runner{
|
||||||
|
{
|
||||||
|
Name: "video",
|
||||||
|
Run: func(ctx context.Context) error {
|
||||||
|
return video.Run(ctx, inst, cfg.Video)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
if cfg.Audio != nil {
|
||||||
|
runners = append(runners, Runner{
|
||||||
|
Name: "audio",
|
||||||
|
Run: func(ctx context.Context) error {
|
||||||
|
return audio.Run(ctx, inst, *cfg.Audio)
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return RunConcurrent(ctx, runners...)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user