static pattern frame cache
This commit is contained in:
@@ -15,6 +15,7 @@ type PatternInfo struct {
|
|||||||
type pattern struct {
|
type pattern struct {
|
||||||
PatternInfo
|
PatternInfo
|
||||||
kernelSource string
|
kernelSource string
|
||||||
|
dynamic bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var patterns = map[string]pattern{
|
var patterns = map[string]pattern{
|
||||||
@@ -25,6 +26,7 @@ var patterns = map[string]pattern{
|
|||||||
"ebu75-move": {
|
"ebu75-move": {
|
||||||
PatternInfo: PatternInfo{Name: "ebu75-move", Description: "EBU 75% Color Bar Signal with moving square"},
|
PatternInfo: PatternInfo{Name: "ebu75-move", Description: "EBU 75% Color Bar Signal with moving square"},
|
||||||
kernelSource: mustReadKernel("dynamic/ebu75.wgsl"),
|
kernelSource: mustReadKernel("dynamic/ebu75.wgsl"),
|
||||||
|
dynamic: true,
|
||||||
},
|
},
|
||||||
"ebu100": {
|
"ebu100": {
|
||||||
PatternInfo: PatternInfo{Name: "ebu100", Description: "EBU 100% Color Bar Signal"},
|
PatternInfo: PatternInfo{Name: "ebu100", Description: "EBU 100% Color Bar Signal"},
|
||||||
@@ -33,6 +35,7 @@ var patterns = map[string]pattern{
|
|||||||
"ebu100-move": {
|
"ebu100-move": {
|
||||||
PatternInfo: PatternInfo{Name: "ebu100-move", Description: "EBU 100% Color Bar Signal with moving square"},
|
PatternInfo: PatternInfo{Name: "ebu100-move", Description: "EBU 100% Color Bar Signal with moving square"},
|
||||||
kernelSource: mustReadKernel("dynamic/ebu100.wgsl"),
|
kernelSource: mustReadKernel("dynamic/ebu100.wgsl"),
|
||||||
|
dynamic: true,
|
||||||
},
|
},
|
||||||
"smpte": {
|
"smpte": {
|
||||||
PatternInfo: PatternInfo{Name: "smpte", Description: "SMPTE RP-219 Color Bar Signal"},
|
PatternInfo: PatternInfo{Name: "smpte", Description: "SMPTE RP-219 Color Bar Signal"},
|
||||||
@@ -41,6 +44,7 @@ var patterns = map[string]pattern{
|
|||||||
"smpte-move": {
|
"smpte-move": {
|
||||||
PatternInfo: PatternInfo{Name: "smpte-move", Description: "SMPTE RP-219 Color Bar Signal with moving square"},
|
PatternInfo: PatternInfo{Name: "smpte-move", Description: "SMPTE RP-219 Color Bar Signal with moving square"},
|
||||||
kernelSource: mustReadKernel("dynamic/smpteBars.wgsl"),
|
kernelSource: mustReadKernel("dynamic/smpteBars.wgsl"),
|
||||||
|
dynamic: true,
|
||||||
},
|
},
|
||||||
"gray-bars": {
|
"gray-bars": {
|
||||||
PatternInfo: PatternInfo{Name: "gray-bars", Description: "13-step grayscale bars (Y 64..940)"},
|
PatternInfo: PatternInfo{Name: "gray-bars", Description: "13-step grayscale bars (Y 64..940)"},
|
||||||
@@ -49,6 +53,7 @@ var patterns = map[string]pattern{
|
|||||||
"gray-bars-move": {
|
"gray-bars-move": {
|
||||||
PatternInfo: PatternInfo{Name: "gray-bars-move", Description: "13-step grayscale bars (Y 64..940) with moving square"},
|
PatternInfo: PatternInfo{Name: "gray-bars-move", Description: "13-step grayscale bars (Y 64..940) with moving square"},
|
||||||
kernelSource: mustReadKernel("dynamic/yBars.wgsl"),
|
kernelSource: mustReadKernel("dynamic/yBars.wgsl"),
|
||||||
|
dynamic: true,
|
||||||
},
|
},
|
||||||
"gray-ramp": {
|
"gray-ramp": {
|
||||||
PatternInfo: PatternInfo{Name: "gray-ramp", Description: "Y gradient (black -> 100% white)"},
|
PatternInfo: PatternInfo{Name: "gray-ramp", Description: "Y gradient (black -> 100% white)"},
|
||||||
@@ -57,6 +62,7 @@ var patterns = map[string]pattern{
|
|||||||
"gray-ramp-move": {
|
"gray-ramp-move": {
|
||||||
PatternInfo: PatternInfo{Name: "gray-ramp-move", Description: "Y gradient with moving square"},
|
PatternInfo: PatternInfo{Name: "gray-ramp-move", Description: "Y gradient with moving square"},
|
||||||
kernelSource: mustReadKernel("dynamic/yRamp.wgsl"),
|
kernelSource: mustReadKernel("dynamic/yRamp.wgsl"),
|
||||||
|
dynamic: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
package video
|
package video
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
func TestPatterns(t *testing.T) {
|
func TestPatterns(t *testing.T) {
|
||||||
got := Patterns()
|
got := Patterns()
|
||||||
@@ -43,5 +46,9 @@ func TestPatternRegistryKeysMatchNames(t *testing.T) {
|
|||||||
if pattern.kernelSource == "" {
|
if pattern.kernelSource == "" {
|
||||||
t.Errorf("pattern %q has empty kernel source", name)
|
t.Errorf("pattern %q has empty kernel source", name)
|
||||||
}
|
}
|
||||||
|
wantDynamic := strings.HasSuffix(name, "-move")
|
||||||
|
if pattern.dynamic != wantDynamic {
|
||||||
|
t.Errorf("pattern %q dynamic = %t, want %t", name, pattern.dynamic, wantDynamic)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,21 @@ func Run(ctx context.Context, inst *mxl.Instance, cfg Config) (runErr error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var staticFrame []byte
|
||||||
|
if !pattern.dynamic {
|
||||||
|
frameSize := int(cfg.Width()*cfg.Height()) * 8 / 3
|
||||||
|
staticFrame = make([]byte, frameSize)
|
||||||
|
|
||||||
|
if err := gen.GenerateFrame(staticFrame, 0); err != nil {
|
||||||
|
return fmt.Errorf("generate static frame: %w", err)
|
||||||
|
}
|
||||||
|
if overlay != nil {
|
||||||
|
if err := overlay.ApplyV210(staticFrame); err != nil {
|
||||||
|
return fmt.Errorf("apply text overlay to static frame: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
flowJSON, err := json.Marshal(cfg.Definition)
|
flowJSON, err := json.Marshal(cfg.Definition)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("marshal video flow definition: %w", err)
|
return fmt.Errorf("marshal video flow definition: %w", err)
|
||||||
@@ -70,6 +85,16 @@ func Run(ctx context.Context, inst *mxl.Instance, cfg Config) (runErr error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("open video grain %d: %w", idx, err)
|
return fmt.Errorf("open video grain %d: %w", idx, err)
|
||||||
}
|
}
|
||||||
|
if staticFrame != nil {
|
||||||
|
if len(grain.Payload) != len(staticFrame) {
|
||||||
|
return cancelGrain(grain, fmt.Errorf(
|
||||||
|
"video grain payload size %d, expected %d",
|
||||||
|
len(grain.Payload),
|
||||||
|
len(staticFrame),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
copy(grain.Payload, staticFrame)
|
||||||
|
} else {
|
||||||
if err := gen.GenerateFrame(grain.Payload, int(tick)); err != nil {
|
if err := gen.GenerateFrame(grain.Payload, int(tick)); err != nil {
|
||||||
return cancelGrain(grain, fmt.Errorf("generate frame for grain %d: %w", idx, err))
|
return cancelGrain(grain, fmt.Errorf("generate frame for grain %d: %w", idx, err))
|
||||||
}
|
}
|
||||||
@@ -78,13 +103,14 @@ func Run(ctx context.Context, inst *mxl.Instance, cfg Config) (runErr error) {
|
|||||||
return cancelGrain(grain, fmt.Errorf("apply text overlay to grain %d: %w", idx, err))
|
return cancelGrain(grain, fmt.Errorf("apply text overlay to grain %d: %w", idx, err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
tick++
|
||||||
|
}
|
||||||
if err := grain.Commit(grain.TotalSlices, 0); err != nil {
|
if err := grain.Commit(grain.TotalSlices, 0); err != nil {
|
||||||
return fmt.Errorf("commit video grain %d: %w", idx, err)
|
return fmt.Errorf("commit video grain %d: %w", idx, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
grainsWritten++
|
grainsWritten++
|
||||||
idx++
|
idx++
|
||||||
tick++
|
|
||||||
if grainsWritten%100 == 0 {
|
if grainsWritten%100 == 0 {
|
||||||
log.Printf("video grains written=%d, next index=%d", grainsWritten, idx)
|
log.Printf("video grains written=%d, next index=%d", grainsWritten, idx)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user