avidec: Factor out the sync fucntionality.