From 98c4c684e2bc70633e9ebb0e8f0d7aa683e75def Mon Sep 17 00:00:00 2001 From: Mattia Iavarone Date: Mon, 17 Sep 2018 22:36:21 -0300 Subject: [PATCH] Add comments --- .../cameraview/AudioMediaEncoder.java | 3 +- .../cameraview/MediaEncoder.java | 35 ++++++++++++++++++- .../cameraview/VideoMediaEncoder.java | 7 ++-- 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/cameraview/src/main/gles/com/otaliastudios/cameraview/AudioMediaEncoder.java b/cameraview/src/main/gles/com/otaliastudios/cameraview/AudioMediaEncoder.java index 25a066ac..810f911c 100644 --- a/cameraview/src/main/gles/com/otaliastudios/cameraview/AudioMediaEncoder.java +++ b/cameraview/src/main/gles/com/otaliastudios/cameraview/AudioMediaEncoder.java @@ -41,9 +41,8 @@ class AudioMediaEncoder extends MediaEncoder { } - @EncoderThread @Override void release() { - + super.release(); } } diff --git a/cameraview/src/main/gles/com/otaliastudios/cameraview/MediaEncoder.java b/cameraview/src/main/gles/com/otaliastudios/cameraview/MediaEncoder.java index 2bf5534c..629d742d 100644 --- a/cameraview/src/main/gles/com/otaliastudios/cameraview/MediaEncoder.java +++ b/cameraview/src/main/gles/com/otaliastudios/cameraview/MediaEncoder.java @@ -21,23 +21,56 @@ abstract class MediaEncoder { private MediaEncoderEngine.Controller mController; private int mTrackIndex; + /** + * Called to prepare this encoder before starting. + * Any initialization should be done here as it does not interfere with the original + * thread (that, generally, is the rendering thread). + * + * At this point subclasses MUST create the {@link #mMediaCodec} object. + * + * @param controller the muxer controller + */ @EncoderThread void prepare(MediaEncoderEngine.Controller controller) { mController = controller; mBufferInfo = new MediaCodec.BufferInfo(); } + /** + * Start recording. This might be a lightweight operation + * in case the encoder needs to wait for a certain event + * like a "frame available". + */ @EncoderThread abstract void start(); + /** + * The caller notifying of a certain event occurring. + * Should analyze the string and see if the event is important. + * @param event what happened + * @param data object + */ @EncoderThread abstract void notify(String event, Object data); + /** + * Stop recording. + * This MUST happen SYNCHRONOUSLY! + */ @EncoderThread abstract void stop(); + /** + * Release resources here. + */ @EncoderThread - abstract void release(); + void release() { + if (mMediaCodec != null) { + mMediaCodec.stop(); + mMediaCodec.release(); + mMediaCodec = null; + } + } /** * Extracts all pending data from the encoder and forwards it to the muxer. diff --git a/cameraview/src/main/gles/com/otaliastudios/cameraview/VideoMediaEncoder.java b/cameraview/src/main/gles/com/otaliastudios/cameraview/VideoMediaEncoder.java index 334a8c78..f6c97316 100644 --- a/cameraview/src/main/gles/com/otaliastudios/cameraview/VideoMediaEncoder.java +++ b/cameraview/src/main/gles/com/otaliastudios/cameraview/VideoMediaEncoder.java @@ -16,6 +16,7 @@ import java.nio.ByteBuffer; /** * This alone does nothing. * Subclasses must make sure they write each frame onto the given Surface {@link #mSurface}. + * * @param the config object. */ @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2) @@ -90,10 +91,6 @@ abstract class VideoMediaEncoder extends Med @EncoderThread @Override void release() { - if (mMediaCodec != null) { - mMediaCodec.stop(); - mMediaCodec.release(); - mMediaCodec = null; - } + super.release(); } }