fix(webkit): implement auto hardware decoding mode with software fallback to fix Twitch Error #4000
- commit
- 214a5d34e6da828135a3e1af60819c2b37f37a2b
- author
- brice · · 2025-12-18 18:27 UTC
- parent
- 94c2fc4
- signature
- unsigned
1 file · +21 -3
M internal/infrastructure/webkit/settings.go +21 -3
| @@ -95,9 +95,27 @@ func (sm *SettingsManager) applySettings(ctx context.Context, settings *webkit.S | |||
| 95 | 95 | settings.SetEnableEncryptedMedia(true) | |
| 96 | 96 | settings.SetMediaPlaybackRequiresUserGesture(true) | |
| 97 | 97 | settings.SetMediaPlaybackAllowsInline(true) | |
| 98 | - | // Force hardware decoding for video content via GStreamer VA-API/NVDEC | |
| 99 | - | hwMediaTypes := "video/mp4;video/webm;video/x-h264;video/av01" | |
| 100 | - | settings.SetMediaContentTypesRequiringHardwareSupport(&hwMediaTypes) | |
| 98 | + | ||
| 99 | + | // Hardware decoding mode - THE FIX for Twitch Error #4000 | |
| 100 | + | // Default "auto" allows GStreamer to choose best decoder with software fallback | |
| 101 | + | switch cfg.Media.HardwareDecodingMode { | |
| 102 | + | case config.HardwareDecodingForce: | |
| 103 | + | // Force hardware - will fail if unavailable (not recommended) | |
| 104 | + | // Prioritize AV1 (most efficient codec) when user wants forced HW | |
| 105 | + | hwTypes := "video/av01;video/mp4;video/webm;video/x-h264;video/x-h265" | |
| 106 | + | settings.SetMediaContentTypesRequiringHardwareSupport(&hwTypes) | |
| 107 | + | log.Debug().Msg("hardware decoding: forced (may fail without hw support)") | |
| 108 | + | case config.HardwareDecodingDisable: | |
| 109 | + | // Force software only | |
| 110 | + | settings.SetHardwareAccelerationPolicy(webkit.HardwareAccelerationPolicyNeverValue) | |
| 111 | + | log.Debug().Msg("hardware decoding: disabled (software only)") | |
| 112 | + | default: // HardwareDecodingAuto | |
| 113 | + | // Empty string = let GStreamer choose best decoder with software fallback | |
| 114 | + | // This fixes Twitch Error #4000 by allowing playback when HW unavailable | |
| 115 | + | emptyTypes := "" | |
| 116 | + | settings.SetMediaContentTypesRequiringHardwareSupport(&emptyTypes) | |
| 117 | + | log.Debug().Msg("hardware decoding: auto (hw preferred, software fallback)") | |
| 118 | + | } | |
| 101 | 119 | ||
| 102 | 120 | // HTML5 storage | |
| 103 | 121 | settings.SetEnableHtml5LocalStorage(true) | |
| @@ -95,9 +95,27 @@ func (sm *SettingsManager) applySettings(ctx context.Context, settings *webkit.S | |||||
| 95 | settings.SetEnableEncryptedMedia(true) | 95 | settings.SetEnableEncryptedMedia(true) | ||
| 96 | settings.SetMediaPlaybackRequiresUserGesture(true) | 96 | settings.SetMediaPlaybackRequiresUserGesture(true) | ||
| 97 | settings.SetMediaPlaybackAllowsInline(true) | 97 | settings.SetMediaPlaybackAllowsInline(true) | ||
| 98 | - | // Force hardware decoding for video content via GStreamer VA-API/NVDEC | 98 | + | |
| 99 | - | hwMediaTypes := "video/mp4;video/webm;video/x-h264;video/av01" | 99 | + | // Hardware decoding mode - THE FIX for Twitch Error #4000 |
| 100 | - | settings.SetMediaContentTypesRequiringHardwareSupport(&hwMediaTypes) | 100 | + | // Default "auto" allows GStreamer to choose best decoder with software fallback |
| 101 | + | switch cfg.Media.HardwareDecodingMode { | |||
| 102 | + | case config.HardwareDecodingForce: | |||
| 103 | + | // Force hardware - will fail if unavailable (not recommended) | |||
| 104 | + | // Prioritize AV1 (most efficient codec) when user wants forced HW | |||
| 105 | + | hwTypes := "video/av01;video/mp4;video/webm;video/x-h264;video/x-h265" | |||
| 106 | + | settings.SetMediaContentTypesRequiringHardwareSupport(&hwTypes) | |||
| 107 | + | log.Debug().Msg("hardware decoding: forced (may fail without hw support)") | |||
| 108 | + | case config.HardwareDecodingDisable: | |||
| 109 | + | // Force software only | |||
| 110 | + | settings.SetHardwareAccelerationPolicy(webkit.HardwareAccelerationPolicyNeverValue) | |||
| 111 | + | log.Debug().Msg("hardware decoding: disabled (software only)") | |||
| 112 | + | default: // HardwareDecodingAuto | |||
| 113 | + | // Empty string = let GStreamer choose best decoder with software fallback | |||
| 114 | + | // This fixes Twitch Error #4000 by allowing playback when HW unavailable | |||
| 115 | + | emptyTypes := "" | |||
| 116 | + | settings.SetMediaContentTypesRequiringHardwareSupport(&emptyTypes) | |||
| 117 | + | log.Debug().Msg("hardware decoding: auto (hw preferred, software fallback)") | |||
| 118 | + | } | |||
| 101 | 119 | ||||
| 102 | // HTML5 storage | 120 | // HTML5 storage | ||
| 103 | settings.SetEnableHtml5LocalStorage(true) | 121 | settings.SetEnableHtml5LocalStorage(true) | ||