Skip to content

Commit 8ba1c8c

Browse files
committed
Merge branch 'dev'
2 parents bae68f8 + b26f59f commit 8ba1c8c

File tree

361 files changed

+26196
-5279
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

361 files changed

+26196
-5279
lines changed

.github_build/Build.alpine.env

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# CORE ALPINE BASE IMAGE
22
OS_NAME=alpine
3-
OS_VERSION=3.15
4-
GOLANG_IMAGE=golang:1.18.6-alpine3.15
5-
CORE_VERSION=16.10.1
3+
OS_VERSION=3.16
4+
GOLANG_IMAGE=golang:1.19.3-alpine3.16
5+
CORE_VERSION=16.11.0

.github_build/Build.bundle.cuda.env

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# CORE NVIDIA CUDA BUNDLE
2-
FFMPEG_VERSION=4.4.2
3-
CUDA_VERSION=11.4.2
2+
FFMPEG_VERSION=5.1.2
3+
CUDA_VERSION=11.7.1

.github_build/Build.bundle.env

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# CORE BUNDLE
2-
FFMPEG_VERSION=4.4.2
2+
FFMPEG_VERSION=5.1.2

.github_build/Build.bundle.rpi.env

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# CORE RASPBERRY-PI BUNDLE
2-
FFMPEG_VERSION=4.4.2
2+
FFMPEG_VERSION=5.1.2

.github_build/Build.bundle.vaapi.env

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# CORE BUNDLE
2-
FFMPEG_VERSION=4.4.2
2+
FFMPEG_VERSION=5.1.2

.github_build/Build.ubuntu.env

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# CORE UBUNTU BASE IMAGE
22
OS_NAME=ubuntu
33
OS_VERSION=20.04
4-
GOLANG_IMAGE=golang:1.18.6-alpine3.15
5-
CORE_VERSION=16.10.1
4+
GOLANG_IMAGE=golang:1.19.3-alpine3.16
5+
CORE_VERSION=16.11.0

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
.env
33
/core*
44
/import*
5+
/ffmigrate*
56
/data/**
67
/test/**
78
.vscode

CHANGELOG.md

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# Core
22

3+
### Core v16.10.1 > v16.11.0
4+
5+
- Add FFmpeg 4.4 to FFmpeg 5.1 migration tool
6+
- Add alternative SRT streamid
7+
- Mod bump FFmpeg to v5.1.2 (datarhei/core:tag bundles)
8+
- Fix crash with custom SSL certificates ([restreamer/#425](https://github.com/datarhei/restreamer/issues/425))
9+
- Fix proper version handling for config
10+
- Fix widged session data
11+
- Fix resetting process stats when process stopped
12+
- Fix stale FFmpeg process detection for streams with only audio
13+
- Fix wrong return status code ([#6](https://github.com/datarhei/core/issues/6)))
14+
- Fix use SRT defaults for key material exchange
15+
316
### Core v16.10.0 > v16.10.1
417

518
- Add email address in TLS config for Let's Encrypt
@@ -20,11 +33,11 @@
2033
- Fix process cleanup on delete, remove empty directories from disk
2134
- Fix SRT blocking port on restart (upgrade datarhei/gosrt)
2235
- Fix RTMP communication (Blackmagic Web Presenter, thx 235 MEDIA)
23-
- Fix RTMP communication (Blackmagic ATEM Mini, datarhei/restreamer#385)
36+
- Fix RTMP communication (Blackmagic ATEM Mini, [#385](https://github.com/datarhei/restreamer/issues/385))
2437
- Fix injecting commit, branch, and build info
2538
- Fix API metadata endpoints responses
2639

27-
#### Core v16.9.0 > v16.9.1
40+
#### Core v16.9.0 > v16.9.1^
2841

2942
- Fix v1 import app
3043
- Fix race condition

Dockerfile

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
1-
ARG GOLANG_IMAGE=golang:1.18.4-alpine3.15
1+
ARG GOLANG_IMAGE=golang:1.19.3-alpine3.16
22

3-
ARG BUILD_IMAGE=alpine:3.15
3+
ARG BUILD_IMAGE=alpine:3.16
44

55
FROM $GOLANG_IMAGE as builder
66

77
COPY . /dist/core
88

99
RUN apk add \
10-
git \
11-
make && \
10+
git \
11+
make && \
1212
cd /dist/core && \
1313
go version && \
1414
make release_linux && \
15-
make import_linux
15+
make import_linux && \
16+
make ffmigrate_linux
1617

1718
FROM $BUILD_IMAGE
1819

1920
COPY --from=builder /dist/core/core /core/bin/core
2021
COPY --from=builder /dist/core/import /core/bin/import
22+
COPY --from=builder /dist/core/ffmigrate /core/bin/ffmigrate
2123
COPY --from=builder /dist/core/mime.types /core/mime.types
2224
COPY --from=builder /dist/core/run.sh /core/bin/run.sh
2325

Dockerfile.test

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
FROM golang:1.18.3-alpine3.15
1+
FROM golang:1.19.3-alpine3.16
22

33
RUN apk add alpine-sdk
44

55
COPY . /dist/core
66

77
RUN cd /dist/core && \
8-
go test -coverprofile=coverage.out -covermode=atomic -v ./...
8+
go test -coverprofile=coverage.out -covermode=atomic -v ./...

Makefile

+9-1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ import:
7575
import_linux:
7676
cd app/import && CGO_ENABLED=0 GOOS=linux GOARCH=${OSARCH} go build -o ../../import -ldflags="-s -w"
7777

78+
## ffmigrate: Build ffmpeg migration binary
79+
ffmigrate:
80+
cd app/ffmigrate && CGO_ENABLED=${CGO_ENABLED} GOOS=${GOOS} GOARCH=${GOARCH} go build -o ../../ffmigrate -ldflags="-s -w"
81+
82+
# github workflow workaround
83+
ffmigrate_linux:
84+
cd app/ffmigrate && CGO_ENABLED=0 GOOS=linux GOARCH=${OSARCH} go build -o ../../ffmigrate -ldflags="-s -w"
85+
7886
## coverage: Generate code coverage analysis
7987
coverage:
8088
go test -race -coverprofile test/cover.out ./...
@@ -96,7 +104,7 @@ release_linux:
96104
docker:
97105
docker build -t core:$(SHORTCOMMIT) .
98106

99-
.PHONY: help init build swagger test vet fmt vulncheck vendor commit coverage lint release import update
107+
.PHONY: help init build swagger test vet fmt vulncheck vendor commit coverage lint release import ffmigrate update
100108

101109
## help: Show all commands
102110
help: Makefile

app/api/api.go

+79-85
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import (
1616

1717
"github.com/datarhei/core/v16/app"
1818
"github.com/datarhei/core/v16/config"
19+
configstore "github.com/datarhei/core/v16/config/store"
20+
configvars "github.com/datarhei/core/v16/config/vars"
1921
"github.com/datarhei/core/v16/ffmpeg"
2022
"github.com/datarhei/core/v16/http"
2123
"github.com/datarhei/core/v16/http/cache"
@@ -96,7 +98,7 @@ type api struct {
9698

9799
config struct {
98100
path string
99-
store config.Store
101+
store configstore.Store
100102
config *config.Config
101103
}
102104

@@ -145,7 +147,7 @@ func (a *api) Reload() error {
145147

146148
logger := log.New("Core").WithOutput(log.NewConsoleWriter(a.log.writer, log.Lwarn, true))
147149

148-
store, err := config.NewJSONStore(a.config.path, func() {
150+
store, err := configstore.NewJSON(a.config.path, func() {
149151
a.errorChan <- ErrConfigReload
150152
})
151153
if err != nil {
@@ -157,7 +159,7 @@ func (a *api) Reload() error {
157159
cfg.Merge()
158160

159161
if len(cfg.Host.Name) == 0 && cfg.Host.Auto {
160-
cfg.SetPublicIPs()
162+
cfg.Host.Name = net.GetPublicIPs(5 * time.Second)
161163
}
162164

163165
cfg.Validate(false)
@@ -226,7 +228,7 @@ func (a *api) Reload() error {
226228
logger.Info().WithFields(logfields).Log("")
227229

228230
configlogger := logger.WithComponent("Config")
229-
cfg.Messages(func(level string, v config.Variable, message string) {
231+
cfg.Messages(func(level string, v configvars.Variable, message string) {
230232
configlogger = configlogger.WithFields(log.Fields{
231233
"variable": v.Name,
232234
"value": v.Value,
@@ -362,11 +364,6 @@ func (a *api) start() error {
362364
a.sessions = sessions
363365
}
364366

365-
store := store.NewJSONStore(store.JSONConfig{
366-
Dir: cfg.DB.Dir,
367-
Logger: a.log.logger.core.WithComponent("ProcessStore"),
368-
})
369-
370367
diskfs, err := fs.NewDiskFilesystem(fs.DiskConfig{
371368
Dir: cfg.Storage.Disk.Dir,
372369
Size: cfg.Storage.Disk.Size * 1024 * 1024,
@@ -481,6 +478,12 @@ func (a *api) start() error {
481478
a.replacer.RegisterTemplate("srt", template)
482479
}
483480

481+
store := store.NewJSONStore(store.JSONConfig{
482+
Filepath: cfg.DB.Dir + "/db.json",
483+
FFVersion: a.ffmpeg.Skills().FFmpeg.Version,
484+
Logger: a.log.logger.core.WithComponent("ProcessStore"),
485+
})
486+
484487
restream, err := restream.New(restream.Config{
485488
ID: cfg.ID,
486489
Name: cfg.Name,
@@ -649,98 +652,88 @@ func (a *api) start() error {
649652

650653
var autocertManager *certmagic.Config
651654

652-
if cfg.TLS.Enable && cfg.TLS.Auto {
653-
if len(cfg.Host.Name) == 0 {
654-
return fmt.Errorf("at least one host must be provided in host.name or RS_HOST_NAME")
655-
}
655+
if cfg.TLS.Enable {
656+
if cfg.TLS.Auto {
657+
if len(cfg.Host.Name) == 0 {
658+
return fmt.Errorf("at least one host must be provided in host.name or RS_HOST_NAME")
659+
}
656660

657-
certmagic.DefaultACME.Agreed = true
658-
certmagic.DefaultACME.Email = cfg.TLS.Email
659-
certmagic.DefaultACME.CA = certmagic.LetsEncryptProductionCA
660-
certmagic.DefaultACME.DisableHTTPChallenge = false
661-
certmagic.DefaultACME.DisableTLSALPNChallenge = true
662-
certmagic.DefaultACME.Logger = nil
661+
certmagic.DefaultACME.Agreed = true
662+
certmagic.DefaultACME.Email = cfg.TLS.Email
663+
certmagic.DefaultACME.CA = certmagic.LetsEncryptProductionCA
664+
certmagic.DefaultACME.DisableHTTPChallenge = false
665+
certmagic.DefaultACME.DisableTLSALPNChallenge = true
666+
certmagic.DefaultACME.Logger = nil
663667

664-
certmagic.Default.Storage = &certmagic.FileStorage{
665-
Path: cfg.DB.Dir + "/cert",
666-
}
667-
certmagic.Default.DefaultServerName = cfg.Host.Name[0]
668-
certmagic.Default.Logger = nil
669-
certmagic.Default.OnEvent = func(event string, data interface{}) {
670-
message := ""
671-
672-
switch data := data.(type) {
673-
case string:
674-
message = data
675-
case fmt.Stringer:
676-
message = data.String()
668+
certmagic.Default.Storage = &certmagic.FileStorage{
669+
Path: cfg.DB.Dir + "/cert",
677670
}
671+
certmagic.Default.DefaultServerName = cfg.Host.Name[0]
672+
certmagic.Default.Logger = nil
678673

679-
if len(message) != 0 {
680-
a.log.logger.core.WithComponent("certmagic").Info().WithField("event", event).Log(message)
681-
}
682-
}
674+
magic := certmagic.NewDefault()
675+
acme := certmagic.NewACMEIssuer(magic, certmagic.DefaultACME)
683676

684-
magic := certmagic.NewDefault()
685-
acme := certmagic.NewACMEIssuer(magic, certmagic.DefaultACME)
677+
magic.Issuers = []certmagic.Issuer{acme}
686678

687-
magic.Issuers = []certmagic.Issuer{acme}
679+
autocertManager = magic
688680

689-
autocertManager = magic
681+
// Start temporary http server on configured port
682+
tempserver := &gohttp.Server{
683+
Addr: cfg.Address,
684+
Handler: acme.HTTPChallengeHandler(gohttp.HandlerFunc(func(w gohttp.ResponseWriter, r *gohttp.Request) {
685+
w.WriteHeader(gohttp.StatusNotFound)
686+
})),
687+
ReadTimeout: 10 * time.Second,
688+
WriteTimeout: 10 * time.Second,
689+
MaxHeaderBytes: 1 << 20,
690+
}
690691

691-
// Start temporary http server on configured port
692-
tempserver := &gohttp.Server{
693-
Addr: cfg.Address,
694-
Handler: acme.HTTPChallengeHandler(gohttp.HandlerFunc(func(w gohttp.ResponseWriter, r *gohttp.Request) {
695-
w.WriteHeader(gohttp.StatusNotFound)
696-
})),
697-
ReadTimeout: 10 * time.Second,
698-
WriteTimeout: 10 * time.Second,
699-
MaxHeaderBytes: 1 << 20,
700-
}
692+
wg := sync.WaitGroup{}
693+
wg.Add(1)
701694

702-
wg := sync.WaitGroup{}
703-
wg.Add(1)
695+
go func() {
696+
tempserver.ListenAndServe()
697+
wg.Done()
698+
}()
704699

705-
go func() {
706-
tempserver.ListenAndServe()
707-
wg.Done()
708-
}()
700+
var certerror bool
709701

710-
var certerror bool
702+
// For each domain, get the certificate
703+
for _, host := range cfg.Host.Name {
704+
logger := a.log.logger.core.WithComponent("Let's Encrypt").WithField("host", host)
705+
logger.Info().Log("Acquiring certificate ...")
711706

712-
// For each domain, get the certificate
713-
for _, host := range cfg.Host.Name {
714-
logger := a.log.logger.core.WithComponent("Let's Encrypt").WithField("host", host)
715-
logger.Info().Log("Acquiring certificate ...")
707+
ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(5*time.Minute))
716708

717-
ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(5*time.Minute))
709+
err := autocertManager.ManageSync(ctx, []string{host})
718710

719-
err := autocertManager.ManageSync(ctx, []string{host})
711+
cancel()
720712

721-
cancel()
713+
if err != nil {
714+
logger.Error().WithField("error", err).Log("Failed to acquire certificate")
715+
certerror = true
716+
break
717+
}
722718

723-
if err != nil {
724-
logger.Error().WithField("error", err).Log("Failed to acquire certificate")
725-
certerror = true
726-
break
719+
logger.Info().Log("Successfully acquired certificate")
727720
}
728721

729-
logger.Info().Log("Successfully acquired certificate")
730-
}
731-
732-
// Shut down the temporary http server
733-
tempserver.Close()
722+
// Shut down the temporary http server
723+
tempserver.Close()
734724

735-
wg.Wait()
725+
wg.Wait()
736726

737-
if certerror {
738-
a.log.logger.core.Warn().Log("Continuing with disabled TLS")
739-
autocertManager = nil
740-
cfg.TLS.Enable = false
727+
if certerror {
728+
a.log.logger.core.Warn().Log("Continuing with disabled TLS")
729+
autocertManager = nil
730+
cfg.TLS.Enable = false
731+
} else {
732+
cfg.TLS.CertFile = ""
733+
cfg.TLS.KeyFile = ""
734+
}
741735
} else {
742-
cfg.TLS.CertFile = ""
743-
cfg.TLS.KeyFile = ""
736+
a.log.logger.core.Info().Log("Enabling TLS with cert and key files")
744737
}
745738
}
746739

@@ -756,14 +749,15 @@ func (a *api) start() error {
756749
Collector: a.sessions.Collector("rtmp"),
757750
}
758751

759-
if autocertManager != nil && cfg.RTMP.EnableTLS {
760-
config.TLSConfig = &tls.Config{
761-
GetCertificate: autocertManager.GetCertificate,
762-
}
763-
752+
if cfg.RTMP.EnableTLS {
764753
config.Logger = config.Logger.WithComponent("RTMP/S")
765754

766755
a.log.logger.rtmps = a.log.logger.core.WithComponent("RTMPS").WithField("address", cfg.RTMP.AddressTLS)
756+
if autocertManager != nil {
757+
config.TLSConfig = &tls.Config{
758+
GetCertificate: autocertManager.GetCertificate,
759+
}
760+
}
767761
}
768762

769763
rtmpserver, err := rtmp.New(config)

0 commit comments

Comments
 (0)