riff: Move muxing code to a separate file