In avcodec_open(), set return code to an error value only when an error occurs
instead of unconditionally at the start of the function.
This fixes a bug where a successful call to ff_thread_init() masks errors that
occur after that point in the function. It also makes future bugs like this
less likely since the error code is now set near to the point in the code
where the error is found.