refactor code to eliminate potential div by 0

review at:
https://rbcommons.com/s/OpenH264/r/595/