media: Fix memory leak when recording duration exceeds duration limit.

When recording got to the duration limit, MPEG4Writer should also stop the source
before exiting the loop. This will stop the video/audio encoder from copying
and encoding buffer. Otherwise, those encoded buffers will be leaked as they are
not released inside MPEG4Writer.

Also fix the other cases when malformed file is generated.

Bug:31530524
Change-Id: I0233f13e3d2a9110b35375a7394e6c8c36494342
1 file changed