hwcontext_vaapi: Factorise out common connection code