Fix MediaCodec potential use-after-free

Fix a MediaCodec potential use-after-free problem when
MediaCodec is started and onError occurs.

When onError -> SetState(UNINITAILIZED), there is a timing that
returnBuffersToCodec() is done and mState is not set to
UNINITAILIZED. At this moment, if getBuffer(..) is call, null
buffer will be gotten. Usually, APK will use is without checking,
and it cause the problem.

Test: manual with YouTube
Test: atest CtsMediaCodecTestCases -- --feature-flags:flag-value \
            codec_fwk/android.media.codec.set_state_early=true
Bug: 298613712
Flag: codec_fwk.android.media.codec.set_state_early
Change-Id: I4e9a4d3be7227e68ef2f59df4602d75fdc454001
2 files changed