MediaCodec: ensure reply does not get lost

The following operations store mReplyID to wait for a codec event
before replying:

- init, configure, start, flush, stop:
  These operations causes state transitions.
  Defer if mReplyID is set.
  When handling operation complete event, check current state and
  don't reply if the state is not an expected value.

- signalEOS, createInputSurface, setInputSurface:
  These operations do not cause state transitions.
  Defer if mReplyID is set.
  When handling operation complete event, check current state and
  don't reply if the state is not an expected value.

- release:
  Release is special, as we want to release even if we are in the middle
  of handling other operations.
  Reply to current operation to unblock app and start releasing.
  Release complete event is always handled.

Bug: 154678891
Test: atest CtsMediaTestCases -- --module-arg CtsMediaTestCases:size:small
Merged-In: I08286bffb13150813a1d237e49ab1bbf8f544f32
Change-Id: I08286bffb13150813a1d237e49ab1bbf8f544f32
2 files changed