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

livepeer: add a -hevcDecoding flag #3119

Merged
merged 1 commit into from
Aug 8, 2024
Merged
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
6 changes: 6 additions & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

## vX.X

This release includes a new `-hevcDecoding` flag for transcoders to configure HEVC decoding. If the flag is omitted, the default behavior on GPUs is unchanged, which is to auto-detect HEVC decoding support at transcoder start-up. Transcoders can disable HEVC decoding on GPUs if there is an issue with HEVC jobs via `-hevcDecoding=false`. CPU transcoders now have HEVC decoding disabled by default since processing HEVC jobs is CPU-heavy, but this can be enabled by setting the `-hevcDecoding` flag.

### Breaking Changes 🚨🚨

- [#3119](https://github.com/livepeer/go-livepeer/pull/3119) CPU transcoders no longer decode HEVC or VP9 by default

### Features ⚒

#### General
Expand All @@ -14,6 +18,8 @@

#### Transcoder

- [#3119](https://github.com/livepeer/go-livepeer/pull/3119) Add `-hevcDecoding` flag to toggle HEVC decoding

### Bug Fixes 🐞

#### CLI
Expand Down
4 changes: 4 additions & 0 deletions cmd/livepeer/livepeer.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
cfg.Nvidia = flag.String("nvidia", *cfg.Nvidia, "Comma-separated list of Nvidia GPU device IDs (or \"all\" for all available devices)")
cfg.Netint = flag.String("netint", *cfg.Netint, "Comma-separated list of NetInt device GUIDs (or \"all\" for all available devices)")
cfg.TestTranscoder = flag.Bool("testTranscoder", *cfg.TestTranscoder, "Test Nvidia GPU transcoding at startup")
cfg.HevcDecoding = flag.Bool("hevcDecoding", *cfg.HevcDecoding, "Enable or disable HEVC decoding")

// Onchain:
cfg.EthAcctAddr = flag.String("ethAcctAddr", *cfg.EthAcctAddr, "Existing Eth account address. For use when multiple ETH accounts exist in the keystore directory")
Expand Down Expand Up @@ -237,6 +238,9 @@
if !isFlagSet["localVerify"] {
res.LocalVerify = nil
}
if !isFlagSet["hevcDecoding"] {
res.HevcDecoding = nil

Check warning on line 242 in cmd/livepeer/livepeer.go

View check run for this annotation

Codecov / codecov/patch

cmd/livepeer/livepeer.go#L241-L242

Added lines #L241 - L242 were not covered by tests
}

return res
}
27 changes: 25 additions & 2 deletions cmd/livepeer/starter/starter.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
CurrentManifest *bool
Nvidia *string
Netint *string
HevcDecoding *bool
TestTranscoder *bool
EthAcctAddr *string
EthPassword *string
Expand Down Expand Up @@ -181,6 +182,7 @@
defaultCurrentManifest := false
defaultNvidia := ""
defaultNetint := ""
defaultHevcDecoding := false

Check warning on line 185 in cmd/livepeer/starter/starter.go

View check run for this annotation

Codecov / codecov/patch

cmd/livepeer/starter/starter.go#L185

Added line #L185 was not covered by tests
defaultTestTranscoder := true

// Onchain:
Expand Down Expand Up @@ -270,6 +272,7 @@
CurrentManifest: &defaultCurrentManifest,
Nvidia: &defaultNvidia,
Netint: &defaultNetint,
HevcDecoding: &defaultHevcDecoding,

Check warning on line 275 in cmd/livepeer/starter/starter.go

View check run for this annotation

Codecov / codecov/patch

cmd/livepeer/starter/starter.go#L275

Added line #L275 was not covered by tests
TestTranscoder: &defaultTestTranscoder,

// Onchain:
Expand Down Expand Up @@ -489,10 +492,30 @@
// Initialize LB transcoder
n.Transcoder = core.NewLoadBalancingTranscoder(devices, tf)
} else {
// for local software mode, enable all capabilities
transcoderCaps = append(core.DefaultCapabilities(), core.OptionalCapabilities()...)
// for local software mode, enable most capabilities but remove expensive decoders and non-H264 encoders
capsToRemove := []core.Capability{core.Capability_HEVC_Decode, core.Capability_HEVC_Encode, core.Capability_VP8_Encode, core.Capability_VP9_Decode, core.Capability_VP9_Encode}
caps := core.OptionalCapabilities()
for _, c := range capsToRemove {
caps = core.RemoveCapability(caps, c)

Check warning on line 499 in cmd/livepeer/starter/starter.go

View check run for this annotation

Codecov / codecov/patch

cmd/livepeer/starter/starter.go#L496-L499

Added lines #L496 - L499 were not covered by tests
}
transcoderCaps = append(core.DefaultCapabilities(), caps...)

Check warning on line 501 in cmd/livepeer/starter/starter.go

View check run for this annotation

Codecov / codecov/patch

cmd/livepeer/starter/starter.go#L501

Added line #L501 was not covered by tests
n.Transcoder = core.NewLocalTranscoder(*cfg.Datadir)
}

if cfg.HevcDecoding == nil {

Check warning on line 505 in cmd/livepeer/starter/starter.go

View check run for this annotation

Codecov / codecov/patch

cmd/livepeer/starter/starter.go#L505

Added line #L505 was not covered by tests
// do nothing; keep defaults
} else if *cfg.HevcDecoding {
if !core.HasCapability(transcoderCaps, core.Capability_HEVC_Decode) {
if accel != ffmpeg.Software {
glog.Info("Enabling HEVC decoding when the hardware does not support it")
} else {
glog.Info("Enabling HEVC decoding on CPU, may be slow")

Check warning on line 512 in cmd/livepeer/starter/starter.go

View check run for this annotation

Codecov / codecov/patch

cmd/livepeer/starter/starter.go#L507-L512

Added lines #L507 - L512 were not covered by tests
}
transcoderCaps = core.AddCapability(transcoderCaps, core.Capability_HEVC_Decode)

Check warning on line 514 in cmd/livepeer/starter/starter.go

View check run for this annotation

Codecov / codecov/patch

cmd/livepeer/starter/starter.go#L514

Added line #L514 was not covered by tests
}
} else if !*cfg.HevcDecoding {
transcoderCaps = core.RemoveCapability(transcoderCaps, core.Capability_HEVC_Decode)

Check warning on line 517 in cmd/livepeer/starter/starter.go

View check run for this annotation

Codecov / codecov/patch

cmd/livepeer/starter/starter.go#L516-L517

Added lines #L516 - L517 were not covered by tests
}
}

if *cfg.Redeemer {
Expand Down
14 changes: 14 additions & 0 deletions core/capabilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,20 @@
}
}

func RemoveCapability(haystack []Capability, needle Capability) []Capability {
for i, c := range haystack {
if c == needle {
// TODO use slices.Delete once go-livepeer updates to latest golang
return append(haystack[:i], haystack[i+1:]...)
}
}
return haystack
}

func AddCapability(caps []Capability, newCap Capability) []Capability {
return append(caps, newCap)

Check warning on line 202 in core/capabilities.go

View check run for this annotation

Codecov / codecov/patch

core/capabilities.go#L201-L202

Added lines #L201 - L202 were not covered by tests
}

func NewCapabilityString(caps []Capability) CapabilityString {
capStr := CapabilityString{}
for _, v := range caps {
Expand Down
44 changes: 44 additions & 0 deletions core/capabilities_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,50 @@ func TestCapabilities_LegacyCheck(t *testing.T) {
assert.Len(legacyCapabilities, legacyLen) // sanity check no modifications
}

func TestCapability_RemoveCapability(t *testing.T) {
tests := []struct {
name string
caps []Capability
toRemove Capability
expect []Capability
}{{
name: "empty capability list",
caps: nil,
toRemove: Capability_H264,
expect: nil,
}, {
name: "capability not in list",
caps: []Capability{Capability_H264, Capability_MPEGTS},
toRemove: Capability_MP4,
expect: []Capability{Capability_H264, Capability_MPEGTS},
}, {
name: "capability at beginning of list",
caps: []Capability{Capability_H264, Capability_MPEGTS},
toRemove: Capability_H264,
expect: []Capability{Capability_MPEGTS},
}, {
name: "capability in middle of list",
caps: []Capability{Capability_H264, Capability_MP4, Capability_MPEGTS},
toRemove: Capability_MP4,
expect: []Capability{Capability_H264, Capability_MPEGTS},
}, {
name: "capability at end of list",
caps: []Capability{Capability_H264, Capability_MPEGTS},
toRemove: Capability_MPEGTS,
expect: []Capability{Capability_H264},
}, {
name: "last capability",
caps: []Capability{Capability_H264},
toRemove: Capability_H264,
expect: []Capability{},
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.expect, RemoveCapability(tt.caps, tt.toRemove))
})
}
}

func TestLiveeerVersionCompatibleWith(t *testing.T) {
tests := []struct {
name string
Expand Down
Loading