Unify the thread cleanup code, enable threading on android

https://rbcommons.com/s/OpenH264/r/169/