Make inner classes public

pull/506/head
Mattia Iavarone 6 years ago
parent 17d7e03d14
commit 0fd0fad4b4
  1. 8
      cameraview/src/main/java/com/otaliastudios/cameraview/video/encoding/AudioMediaEncoder.java
  2. 15
      cameraview/src/main/java/com/otaliastudios/cameraview/video/encoding/InputBuffer.java
  3. 15
      cameraview/src/main/java/com/otaliastudios/cameraview/video/encoding/MediaEncoder.java
  4. 17
      cameraview/src/main/java/com/otaliastudios/cameraview/video/encoding/MediaEncoderEngine.java
  5. 9
      cameraview/src/main/java/com/otaliastudios/cameraview/video/encoding/OutputBuffer.java
  6. 4
      cameraview/src/main/java/com/otaliastudios/cameraview/video/encoding/TextureMediaEncoder.java
  7. 8
      cameraview/src/main/java/com/otaliastudios/cameraview/video/encoding/VideoMediaEncoder.java

@ -88,7 +88,7 @@ public class AudioMediaEncoder extends MediaEncoder {
@EncoderThread @EncoderThread
@Override @Override
void onPrepare(@NonNull MediaEncoderEngine.Controller controller, long maxLengthMillis) { protected void onPrepare(@NonNull MediaEncoderEngine.Controller controller, long maxLengthMillis) {
final MediaFormat audioFormat = MediaFormat.createAudioFormat(MIME_TYPE, SAMPLING_FREQUENCY, CHANNELS_COUNT); final MediaFormat audioFormat = MediaFormat.createAudioFormat(MIME_TYPE, SAMPLING_FREQUENCY, CHANNELS_COUNT);
audioFormat.setInteger(MediaFormat.KEY_AAC_PROFILE, MediaCodecInfo.CodecProfileLevel.AACObjectLC); audioFormat.setInteger(MediaFormat.KEY_AAC_PROFILE, MediaCodecInfo.CodecProfileLevel.AACObjectLC);
audioFormat.setInteger(MediaFormat.KEY_CHANNEL_MASK, CHANNELS); audioFormat.setInteger(MediaFormat.KEY_CHANNEL_MASK, CHANNELS);
@ -106,14 +106,14 @@ public class AudioMediaEncoder extends MediaEncoder {
@EncoderThread @EncoderThread
@Override @Override
void onStart() { protected void onStart() {
mRequestStop = false; mRequestStop = false;
mRecorder.start(); mRecorder.start();
} }
@EncoderThread @EncoderThread
@Override @Override
void onStop() { protected void onStop() {
mRequestStop = true; mRequestStop = true;
} }
@ -130,7 +130,7 @@ public class AudioMediaEncoder extends MediaEncoder {
} }
@Override @Override
int getEncodedBitRate() { protected int getEncodedBitRate() {
return mConfig.bitRate; return mConfig.bitRate;
} }

@ -6,11 +6,12 @@ import java.nio.ByteBuffer;
* Represents an input buffer, which means, * Represents an input buffer, which means,
* raw data that should be encoded by MediaCodec. * raw data that should be encoded by MediaCodec.
*/ */
class InputBuffer { @SuppressWarnings("WeakerAccess")
ByteBuffer data; public class InputBuffer {
ByteBuffer source; public ByteBuffer data;
int index; public ByteBuffer source;
int length; public int index;
long timestamp; public int length;
boolean isEndOfStream; public long timestamp;
public boolean isEndOfStream;
} }

@ -75,7 +75,7 @@ import java.nio.ByteBuffer;
*/ */
// https://github.com/saki4510t/AudioVideoRecordingSample/blob/master/app/src/main/java/com/serenegiant/encoder/MediaEncoder.java // https://github.com/saki4510t/AudioVideoRecordingSample/blob/master/app/src/main/java/com/serenegiant/encoder/MediaEncoder.java
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2) @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
abstract class MediaEncoder { public abstract class MediaEncoder {
private final static String TAG = MediaEncoder.class.getSimpleName(); private final static String TAG = MediaEncoder.class.getSimpleName();
private final static CameraLogger LOG = CameraLogger.create(TAG); private final static CameraLogger LOG = CameraLogger.create(TAG);
@ -129,7 +129,8 @@ abstract class MediaEncoder {
* Needs a readable name for the thread and for logging. * Needs a readable name for the thread and for logging.
* @param name a name * @param name a name
*/ */
MediaEncoder(@NonNull String name) { @SuppressWarnings("WeakerAccess")
protected MediaEncoder(@NonNull String name) {
mName = name; mName = name;
} }
@ -261,7 +262,7 @@ abstract class MediaEncoder {
* @param maxLengthMillis the maxLength in millis * @param maxLengthMillis the maxLength in millis
*/ */
@EncoderThread @EncoderThread
abstract void onPrepare(@NonNull final MediaEncoderEngine.Controller controller, final long maxLengthMillis); protected abstract void onPrepare(@NonNull final MediaEncoderEngine.Controller controller, final long maxLengthMillis);
/** /**
* Start recording. This might be a lightweight operation * Start recording. This might be a lightweight operation
@ -269,7 +270,7 @@ abstract class MediaEncoder {
* like a "frame available". * like a "frame available".
*/ */
@EncoderThread @EncoderThread
abstract void onStart(); protected abstract void onStart();
/** /**
* The caller notifying of a certain event occurring. * The caller notifying of a certain event occurring.
@ -278,14 +279,14 @@ abstract class MediaEncoder {
* @param data object * @param data object
*/ */
@EncoderThread @EncoderThread
void onEvent(@NonNull String event, @Nullable Object data) {} protected void onEvent(@NonNull String event, @Nullable Object data) {}
/** /**
* Stop recording. This involves signaling the end of stream and draining * Stop recording. This involves signaling the end of stream and draining
* all output left. * all output left.
*/ */
@EncoderThread @EncoderThread
abstract void onStop(); protected abstract void onStop();
/** /**
* Called by {@link #drainOutput(boolean)} when we get an EOS signal (not necessarily in the * Called by {@link #drainOutput(boolean)} when we get an EOS signal (not necessarily in the
@ -461,7 +462,7 @@ abstract class MediaEncoder {
} }
} }
abstract int getEncodedBitRate(); protected abstract int getEncodedBitRate();
/** /**
* Returns the max length setting, in milliseconds, which can be used * Returns the max length setting, in milliseconds, which can be used

@ -246,7 +246,8 @@ public class MediaEncoderEngine {
* A handle for {@link MediaEncoder}s to pass information to this engine. * A handle for {@link MediaEncoder}s to pass information to this engine.
* All methods here can be called for multiple threads. * All methods here can be called for multiple threads.
*/ */
class Controller { @SuppressWarnings("WeakerAccess")
public class Controller {
/** /**
* Request that the muxer should start. This is not guaranteed to be executed: * Request that the muxer should start. This is not guaranteed to be executed:
@ -254,7 +255,7 @@ public class MediaEncoderEngine {
* @param format the media format * @param format the media format
* @return the encoder track index * @return the encoder track index
*/ */
int notifyStarted(@NonNull MediaFormat format) { public int notifyStarted(@NonNull MediaFormat format) {
synchronized (mControllerLock) { synchronized (mControllerLock) {
if (mMediaMuxerStarted) { if (mMediaMuxerStarted) {
throw new IllegalStateException("Trying to start but muxer started already"); throw new IllegalStateException("Trying to start but muxer started already");
@ -274,10 +275,12 @@ public class MediaEncoderEngine {
} }
/** /**
* Whether the muxer is started. * Whether the muxer is started. MediaEncoders are required to avoid
* calling {@link #write(OutputBufferPool, OutputBuffer)} until this method returns true.
*
* @return true if muxer was started * @return true if muxer was started
*/ */
boolean isStarted() { public boolean isStarted() {
synchronized (mControllerLock) { synchronized (mControllerLock) {
return mMediaMuxerStarted; return mMediaMuxerStarted;
} }
@ -287,7 +290,7 @@ public class MediaEncoderEngine {
* Writes the given data to the muxer. Should be called after {@link #isStarted()} * Writes the given data to the muxer. Should be called after {@link #isStarted()}
* returns true. Note: this seems to be thread safe, no lock. * returns true. Note: this seems to be thread safe, no lock.
*/ */
void write(@NonNull OutputBufferPool pool, @NonNull OutputBuffer buffer) { public void write(@NonNull OutputBufferPool pool, @NonNull OutputBuffer buffer) {
if (!mMediaMuxerStarted) { if (!mMediaMuxerStarted) {
throw new IllegalStateException("Trying to write before muxer started"); throw new IllegalStateException("Trying to write before muxer started");
} }
@ -303,7 +306,7 @@ public class MediaEncoderEngine {
* *
* When this succeeds, {@link MediaEncoder#stop()} is called. * When this succeeds, {@link MediaEncoder#stop()} is called.
*/ */
void requestStop(int track) { public void requestStop(int track) {
synchronized (mControllerLock) { synchronized (mControllerLock) {
LOG.w("requestStop:", "Called for track", track); LOG.w("requestStop:", "Called for track", track);
if (--mStartedEncodersCount == 0) { if (--mStartedEncodersCount == 0) {
@ -318,7 +321,7 @@ public class MediaEncoderEngine {
* Notifies that the encoder was stopped. After this is called by all encoders, * Notifies that the encoder was stopped. After this is called by all encoders,
* we will actually stop the muxer. * we will actually stop the muxer.
*/ */
void notifyStopped(int track) { public void notifyStopped(int track) {
synchronized (mControllerLock) { synchronized (mControllerLock) {
LOG.w("notifyStopped:", "Called for track", track); LOG.w("notifyStopped:", "Called for track", track);
if (++mReleasedEncodersCount == mEncoders.size()) { if (++mReleasedEncodersCount == mEncoders.size()) {

@ -9,8 +9,9 @@ import java.nio.ByteBuffer;
* an encoded buffer of data that should be passed * an encoded buffer of data that should be passed
* to the muxer. * to the muxer.
*/ */
class OutputBuffer { @SuppressWarnings("WeakerAccess")
MediaCodec.BufferInfo info; public class OutputBuffer {
int trackIndex; public MediaCodec.BufferInfo info;
ByteBuffer data; public int trackIndex;
public ByteBuffer data;
} }

@ -110,7 +110,7 @@ public class TextureMediaEncoder extends VideoMediaEncoder<TextureMediaEncoder.C
@EncoderThread @EncoderThread
@Override @Override
void onPrepare(@NonNull MediaEncoderEngine.Controller controller, long maxLengthMillis) { protected void onPrepare(@NonNull MediaEncoderEngine.Controller controller, long maxLengthMillis) {
// We rotate the texture using transformRotation. Pass rotation=0 to super so that // We rotate the texture using transformRotation. Pass rotation=0 to super so that
// no rotation metadata is written into the output file. // no rotation metadata is written into the output file.
mTransformRotation = mConfig.rotation; mTransformRotation = mConfig.rotation;
@ -125,7 +125,7 @@ public class TextureMediaEncoder extends VideoMediaEncoder<TextureMediaEncoder.C
@EncoderThread @EncoderThread
@Override @Override
void onEvent(@NonNull String event, @Nullable Object data) { protected void onEvent(@NonNull String event, @Nullable Object data) {
if (!event.equals(FRAME_EVENT)) return; if (!event.equals(FRAME_EVENT)) return;
Frame frame = (Frame) data; Frame frame = (Frame) data;
if (frame == null) { if (frame == null) {

@ -68,7 +68,7 @@ abstract class VideoMediaEncoder<C extends VideoMediaEncoder.Config> extends Med
@EncoderThread @EncoderThread
@Override @Override
void onPrepare(@NonNull MediaEncoderEngine.Controller controller, long maxLengthMillis) { protected void onPrepare(@NonNull MediaEncoderEngine.Controller controller, long maxLengthMillis) {
MediaFormat format = MediaFormat.createVideoFormat(mConfig.mimeType, mConfig.width, mConfig.height); MediaFormat format = MediaFormat.createVideoFormat(mConfig.mimeType, mConfig.width, mConfig.height);
// Set some properties. Failing to specify some of these can cause the MediaCodec // Set some properties. Failing to specify some of these can cause the MediaCodec
@ -93,14 +93,14 @@ abstract class VideoMediaEncoder<C extends VideoMediaEncoder.Config> extends Med
@EncoderThread @EncoderThread
@Override @Override
void onStart() { protected void onStart() {
// Nothing to do here. Waiting for the first frame. // Nothing to do here. Waiting for the first frame.
mFrameNumber = 0; mFrameNumber = 0;
} }
@EncoderThread @EncoderThread
@Override @Override
void onStop() { protected void onStop() {
LOG.i("onStop", "setting mFrameNumber to 1 and signaling the end of input stream."); LOG.i("onStop", "setting mFrameNumber to 1 and signaling the end of input stream.");
mFrameNumber = -1; mFrameNumber = -1;
// Signals the end of input stream. This is a Video only API, as in the normal case, // Signals the end of input stream. This is a Video only API, as in the normal case,
@ -111,7 +111,7 @@ abstract class VideoMediaEncoder<C extends VideoMediaEncoder.Config> extends Med
} }
@Override @Override
int getEncodedBitRate() { protected int getEncodedBitRate() {
return mConfig.bitRate; return mConfig.bitRate;
} }
} }

Loading…
Cancel
Save