Factorize some duplicated code from CAVS and H.264 into a common file.