hal: accumulate written frames when error occurred during write

Frames are discarded directly but not accumulated to written frames
when pcm write failed. This can make the playback position queried
from HAL is less than actual.
Move frames accumulation into a standalone func and handle this
for both failed and successful write.

CRs-Fixed: 2093628

Change-Id: I5b222f123306de603504f6bed4d4e3cdcc7a5b36
1 file changed