@@ -2,8 +2,11 @@ package transcode
22
33import (
44 "errors"
5+ "fmt"
6+ "os"
57 "path/filepath"
68 "slices"
9+ "strings"
710 "testing"
811)
912
@@ -172,6 +175,52 @@ func TestResolveHardwareDecodeFallsBackToSoftwareWhenProbeFails(t *testing.T) {
172175 }
173176}
174177
178+ func TestDefaultHardwareProbeRejectsVAAPIWhenDeviceInitializationFails (t * testing.T ) {
179+ tempDir := t .TempDir ()
180+ ffmpegPath := filepath .Join (tempDir , "ffmpeg" )
181+ callsPath := filepath .Join (tempDir , "calls" )
182+ script := fmt .Sprintf (`#!/bin/sh
183+ echo "$@" >> %q
184+ case " $* " in
185+ *" -hwaccels "*)
186+ printf 'Hardware acceleration methods:\nvaapi\n'
187+ exit 0
188+ ;;
189+ *" -init_hw_device "*)
190+ echo 'Failed to initialise VAAPI connection' >&2
191+ exit 1
192+ ;;
193+ esac
194+ exit 0
195+ ` , callsPath )
196+ if err := os .WriteFile (ffmpegPath , []byte (script ), 0o755 ); err != nil {
197+ t .Fatal (err )
198+ }
199+ devicePath := filepath .Join (tempDir , "renderD128" )
200+ if err := os .WriteFile (devicePath , nil , 0o600 ); err != nil {
201+ t .Fatal (err )
202+ }
203+
204+ err := defaultHardwareProbe (ffmpegPath , FFmpegOptions {
205+ HardwareDecode : "vaapi" ,
206+ HardwareDevice : devicePath ,
207+ })
208+
209+ if err == nil {
210+ t .Fatal ("expected VAAPI device initialization failure" )
211+ }
212+ if ! strings .Contains (err .Error (), "vaapi device init probe failed" ) {
213+ t .Fatalf ("error = %v" , err )
214+ }
215+ calls , err := os .ReadFile (callsPath )
216+ if err != nil {
217+ t .Fatal (err )
218+ }
219+ if ! strings .Contains (string (calls ), "-init_hw_device vaapi=probe:" + devicePath ) {
220+ t .Fatalf ("ffmpeg calls should initialize the configured VAAPI device, calls=%s" , calls )
221+ }
222+ }
223+
175224func TestNewManagerFallsBackToSoftwareDecodeWhenHardwareProbeFails (t * testing.T ) {
176225 manager := NewManager (Options {
177226 FFmpegPath : "/usr/bin/ffmpeg" ,
0 commit comments