Skip to content

Commit

Permalink
Unwrap all nested IntDef values
Browse files Browse the repository at this point in the history
This seems to work with R8 but interact badly with ProGuard.

issue:#6771
PiperOrigin-RevId: 286215262
  • Loading branch information
icbaker authored and ojw28 committed Dec 18, 2019
1 parent 8b0f5b0 commit ed1de00
Show file tree
Hide file tree
Showing 11 changed files with 229 additions and 214 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public DefaultRenderersFactory(Context context) {
extensionRendererMode = EXTENSION_RENDERER_MODE_OFF;
allowedVideoJoiningTimeMs = DEFAULT_ALLOWED_VIDEO_JOINING_TIME_MS;
mediaCodecSelector = MediaCodecSelector.DEFAULT;
mediaCodecOperationMode = MediaCodecRenderer.MediaCodecOperationMode.SYNCHRONOUS;
mediaCodecOperationMode = MediaCodecRenderer.OPERATION_MODE_SYNCHRONOUS;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@
/* package */ final class DedicatedThreadAsyncMediaCodecAdapter extends MediaCodec.Callback
implements MediaCodecAdapter {

@IntDef({State.CREATED, State.STARTED, State.SHUT_DOWN})
private @interface State {
int CREATED = 0;
int STARTED = 1;
int SHUT_DOWN = 2;
}
@IntDef({STATE_CREATED, STATE_STARTED, STATE_SHUT_DOWN})
private @interface State {}

private static final int STATE_CREATED = 0;
private static final int STATE_STARTED = 1;
private static final int STATE_SHUT_DOWN = 2;

private final MediaCodecAsyncCallback mediaCodecAsyncCallback;
private final MediaCodec codec;
Expand Down Expand Up @@ -76,7 +76,7 @@
mediaCodecAsyncCallback = new MediaCodecAsyncCallback();
this.codec = codec;
this.handlerThread = handlerThread;
state = State.CREATED;
state = STATE_CREATED;
onCodecStart = codec::start;
}

Expand All @@ -90,17 +90,17 @@
* @throws IllegalStateException If this method has been called already.
*/
public synchronized void start() {
Assertions.checkState(state == State.CREATED);
Assertions.checkState(state == STATE_CREATED);

handlerThread.start();
handler = new Handler(handlerThread.getLooper());
codec.setCallback(this, handler);
state = State.STARTED;
state = STATE_STARTED;
}

@Override
public synchronized int dequeueInputBufferIndex() {
Assertions.checkState(state == State.STARTED);
Assertions.checkState(state == STATE_STARTED);

if (isFlushing()) {
return MediaCodec.INFO_TRY_AGAIN_LATER;
Expand All @@ -112,7 +112,7 @@ public synchronized int dequeueInputBufferIndex() {

@Override
public synchronized int dequeueOutputBufferIndex(MediaCodec.BufferInfo bufferInfo) {
Assertions.checkState(state == State.STARTED);
Assertions.checkState(state == STATE_STARTED);

if (isFlushing()) {
return MediaCodec.INFO_TRY_AGAIN_LATER;
Expand All @@ -124,14 +124,14 @@ public synchronized int dequeueOutputBufferIndex(MediaCodec.BufferInfo bufferInf

@Override
public synchronized MediaFormat getOutputFormat() {
Assertions.checkState(state == State.STARTED);
Assertions.checkState(state == STATE_STARTED);

return mediaCodecAsyncCallback.getOutputFormat();
}

@Override
public synchronized void flush() {
Assertions.checkState(state == State.STARTED);
Assertions.checkState(state == STATE_STARTED);

codec.flush();
++pendingFlushCount;
Expand All @@ -140,12 +140,12 @@ public synchronized void flush() {

@Override
public synchronized void shutdown() {
if (state == State.STARTED) {
if (state == STATE_STARTED) {
handlerThread.quit();
mediaCodecAsyncCallback.flush();
}

state = State.SHUT_DOWN;
state = STATE_SHUT_DOWN;
}

@Override
Expand Down Expand Up @@ -182,7 +182,7 @@ public synchronized void onOutputFormatChanged(
}

private synchronized void onFlushCompleted() {
if (state != State.STARTED) {
if (state != STATE_STARTED) {
// The adapter has been shutdown.
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,46 @@
public abstract class MediaCodecRenderer extends BaseRenderer {

/**
* Thrown when a failure occurs instantiating a decoder.
* The modes to operate the {@link MediaCodec}.
*
* <p>Allowed values:
*
* <ul>
* <li>{@link #OPERATION_MODE_SYNCHRONOUS}
* <li>{@link #OPERATION_MODE_ASYNCHRONOUS_PLAYBACK_THREAD}
* <li>{@link #OPERATION_MODE_ASYNCHRONOUS_DEDICATED_THREAD}
* <li>{@link #OPERATION_MODE_ASYNCHRONOUS_DEDICATED_THREAD_MULTI_LOCK}
* </ul>
*/
@Documented
@Retention(RetentionPolicy.SOURCE)
@IntDef({
OPERATION_MODE_SYNCHRONOUS,
OPERATION_MODE_ASYNCHRONOUS_PLAYBACK_THREAD,
OPERATION_MODE_ASYNCHRONOUS_DEDICATED_THREAD,
OPERATION_MODE_ASYNCHRONOUS_DEDICATED_THREAD_MULTI_LOCK
})
public @interface MediaCodecOperationMode {}

/** Operates the {@link MediaCodec} in synchronous mode. */
public static final int OPERATION_MODE_SYNCHRONOUS = 0;
/**
* Operates the {@link MediaCodec} in asynchronous mode and routes {@link MediaCodec.Callback}
* callbacks to the playback Thread.
*/
public static final int OPERATION_MODE_ASYNCHRONOUS_PLAYBACK_THREAD = 1;
/**
* Operates the {@link MediaCodec} in asynchronous mode and routes {@link MediaCodec.Callback}
* callbacks to a dedicated Thread.
*/
public static final int OPERATION_MODE_ASYNCHRONOUS_DEDICATED_THREAD = 2;
/**
* Operates the {@link MediaCodec} in asynchronous mode and routes {@link MediaCodec.Callback}
* callbacks to a dedicated Thread. Uses granular locking for input and output buffers.
*/
public static final int OPERATION_MODE_ASYNCHRONOUS_DEDICATED_THREAD_MULTI_LOCK = 3;

/** Thrown when a failure occurs instantiating a decoder. */
public static class DecoderInitializationException extends Exception {

private static final int CUSTOM_ERROR_CODE_BASE = -50000;
Expand Down Expand Up @@ -191,36 +229,6 @@ private static String getDiagnosticInfoV21(Throwable cause) {
}
}

/** The modes to operate the {@link MediaCodec}. */
@Documented
@Retention(RetentionPolicy.SOURCE)
@IntDef({
MediaCodecOperationMode.SYNCHRONOUS,
MediaCodecOperationMode.ASYNCHRONOUS_PLAYBACK_THREAD,
MediaCodecOperationMode.ASYNCHRONOUS_DEDICATED_THREAD,
MediaCodecOperationMode.ASYNCHRONOUS_DEDICATED_THREAD_MULTI_LOCK
})
public @interface MediaCodecOperationMode {

/** Operates the {@link MediaCodec} in synchronous mode. */
int SYNCHRONOUS = 0;
/**
* Operates the {@link MediaCodec} in asynchronous mode and routes {@link MediaCodec.Callback}
* callbacks to the playback Thread.
*/
int ASYNCHRONOUS_PLAYBACK_THREAD = 1;
/**
* Operates the {@link MediaCodec} in asynchronous mode and routes {@link MediaCodec.Callback}
* callbacks to a dedicated Thread.
*/
int ASYNCHRONOUS_DEDICATED_THREAD = 2;
/**
* Operates the {@link MediaCodec} in asynchronous mode and routes {@link MediaCodec.Callback}
* callbacks to a dedicated Thread. Uses granular locking for input and output buffers.
*/
int ASYNCHRONOUS_DEDICATED_THREAD_MULTI_LOCK = 3;
}

/** Indicates no codec operating rate should be set. */
protected static final float CODEC_OPERATING_RATE_UNSET = -1;

Expand Down Expand Up @@ -447,7 +455,7 @@ public MediaCodecRenderer(
outputBufferInfo = new MediaCodec.BufferInfo();
rendererOperatingRate = 1f;
renderTimeLimitMs = C.TIME_UNSET;
mediaCodecOperationMode = MediaCodecOperationMode.SYNCHRONOUS;
mediaCodecOperationMode = OPERATION_MODE_SYNCHRONOUS;
resetCodecStateForRelease();
}

Expand All @@ -473,23 +481,24 @@ public void experimental_setRenderTimeLimitMs(long renderTimeLimitMs) {
*
* @param mode The mode of the MediaCodec. The supported modes are:
* <ul>
* <li>{@link MediaCodecOperationMode#SYNCHRONOUS}: The {@link MediaCodec} will operate in
* synchronous mode.
* <li>{@link MediaCodecOperationMode#ASYNCHRONOUS_PLAYBACK_THREAD}: The {@link MediaCodec}
* will operate in asynchronous mode and {@link MediaCodec.Callback} callbacks will be
* routed to the Playback Thread. This mode requires API level &ge; 21; if the API level
* is &le; 20, the operation mode will be set to {@link
* MediaCodecOperationMode#SYNCHRONOUS}.
* <li>{@link MediaCodecOperationMode#ASYNCHRONOUS_DEDICATED_THREAD}: The {@link MediaCodec}
* will operate in asynchronous mode and {@link MediaCodec.Callback} callbacks will be
* routed to a dedicated Thread. This mode requires API level &ge; 23; if the API level
* is &le; 22, the operation mode will be set to {@link
* MediaCodecOperationMode#SYNCHRONOUS}.
* <li>{@link MediaCodecOperationMode#ASYNCHRONOUS_DEDICATED_THREAD_MULTI_LOCK}: Same as
* {@link MediaCodecOperationMode#ASYNCHRONOUS_DEDICATED_THREAD} but it will internally
* use a finer grained locking mechanism for increased performance.
* <li>{@link MediaCodecRenderer#OPERATION_MODE_SYNCHRONOUS}: The {@link MediaCodec} will
* operate in synchronous mode.
* <li>{@link MediaCodecRenderer#OPERATION_MODE_ASYNCHRONOUS_PLAYBACK_THREAD}: The {@link
* MediaCodec} will operate in asynchronous mode and {@link MediaCodec.Callback}
* callbacks will be routed to the Playback Thread. This mode requires API level &ge;
* 21; if the API level is &le; 20, the operation mode will be set to {@link
* MediaCodecRenderer#OPERATION_MODE_SYNCHRONOUS}.
* <li>{@link MediaCodecRenderer#OPERATION_MODE_ASYNCHRONOUS_DEDICATED_THREAD}: The {@link
* MediaCodec} will operate in asynchronous mode and {@link MediaCodec.Callback}
* callbacks will be routed to a dedicated Thread. This mode requires API level &ge; 23;
* if the API level is &le; 22, the operation mode will be set to {@link
* MediaCodecRenderer#OPERATION_MODE_SYNCHRONOUS}.
* <li>{@link MediaCodecRenderer#OPERATION_MODE_ASYNCHRONOUS_DEDICATED_THREAD_MULTI_LOCK}:
* Same as {@link MediaCodecRenderer#OPERATION_MODE_ASYNCHRONOUS_DEDICATED_THREAD} but
* it will internally use a finer grained locking mechanism for increased performance.
* </ul>
* By default, the operation mode is set to {@link MediaCodecOperationMode#SYNCHRONOUS}.
* By default, the operation mode is set to {@link
* MediaCodecRenderer#OPERATION_MODE_SYNCHRONOUS}.
*/
public void experimental_setMediaCodecOperationMode(@MediaCodecOperationMode int mode) {
mediaCodecOperationMode = mode;
Expand Down Expand Up @@ -980,15 +989,14 @@ private void initCodec(MediaCodecInfo codecInfo, MediaCrypto crypto) throws Exce
codecInitializingTimestamp = SystemClock.elapsedRealtime();
TraceUtil.beginSection("createCodec:" + codecName);
codec = MediaCodec.createByCodecName(codecName);
if (mediaCodecOperationMode == MediaCodecOperationMode.ASYNCHRONOUS_PLAYBACK_THREAD
if (mediaCodecOperationMode == OPERATION_MODE_ASYNCHRONOUS_PLAYBACK_THREAD
&& Util.SDK_INT >= 21) {
codecAdapter = new AsynchronousMediaCodecAdapter(codec);
} else if (mediaCodecOperationMode == MediaCodecOperationMode.ASYNCHRONOUS_DEDICATED_THREAD
} else if (mediaCodecOperationMode == OPERATION_MODE_ASYNCHRONOUS_DEDICATED_THREAD
&& Util.SDK_INT >= 23) {
codecAdapter = new DedicatedThreadAsyncMediaCodecAdapter(codec, getTrackType());
((DedicatedThreadAsyncMediaCodecAdapter) codecAdapter).start();
} else if (mediaCodecOperationMode
== MediaCodecOperationMode.ASYNCHRONOUS_DEDICATED_THREAD_MULTI_LOCK
} else if (mediaCodecOperationMode == OPERATION_MODE_ASYNCHRONOUS_DEDICATED_THREAD_MULTI_LOCK
&& Util.SDK_INT >= 23) {
codecAdapter = new MultiLockAsynchMediaCodecAdapter(codec, getTrackType());
((MultiLockAsynchMediaCodecAdapter) codecAdapter).start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@
/* package */ final class MultiLockAsynchMediaCodecAdapter extends MediaCodec.Callback
implements MediaCodecAdapter {

@IntDef({State.CREATED, State.STARTED, State.SHUT_DOWN})
private @interface State {
int CREATED = 0;
int STARTED = 1;
int SHUT_DOWN = 2;
}
@IntDef({STATE_CREATED, STATE_STARTED, STATE_SHUT_DOWN})
private @interface State {}

private static final int STATE_CREATED = 0;
private static final int STATE_STARTED = 1;
private static final int STATE_SHUT_DOWN = 2;

private final MediaCodec codec;
private final Object inputBufferLock;
Expand Down Expand Up @@ -112,7 +112,7 @@
bufferInfos = new ArrayDeque<>();
formats = new ArrayDeque<>();
codecException = null;
state = State.CREATED;
state = STATE_CREATED;
this.handlerThread = handlerThread;
onCodecStart = codec::start;
}
Expand All @@ -128,19 +128,19 @@
*/
public void start() {
synchronized (objectStateLock) {
Assertions.checkState(state == State.CREATED);
Assertions.checkState(state == STATE_CREATED);

handlerThread.start();
handler = new Handler(handlerThread.getLooper());
codec.setCallback(this, handler);
state = State.STARTED;
state = STATE_STARTED;
}
}

@Override
public int dequeueInputBufferIndex() {
synchronized (objectStateLock) {
Assertions.checkState(state == State.STARTED);
Assertions.checkState(state == STATE_STARTED);

if (isFlushing()) {
return MediaCodec.INFO_TRY_AGAIN_LATER;
Expand All @@ -154,7 +154,7 @@ public int dequeueInputBufferIndex() {
@Override
public int dequeueOutputBufferIndex(MediaCodec.BufferInfo bufferInfo) {
synchronized (objectStateLock) {
Assertions.checkState(state == State.STARTED);
Assertions.checkState(state == STATE_STARTED);

if (isFlushing()) {
return MediaCodec.INFO_TRY_AGAIN_LATER;
Expand All @@ -168,7 +168,7 @@ public int dequeueOutputBufferIndex(MediaCodec.BufferInfo bufferInfo) {
@Override
public MediaFormat getOutputFormat() {
synchronized (objectStateLock) {
Assertions.checkState(state == State.STARTED);
Assertions.checkState(state == STATE_STARTED);

if (currentFormat == null) {
throw new IllegalStateException();
Expand All @@ -181,7 +181,7 @@ public MediaFormat getOutputFormat() {
@Override
public void flush() {
synchronized (objectStateLock) {
Assertions.checkState(state == State.STARTED);
Assertions.checkState(state == STATE_STARTED);

codec.flush();
pendingFlush++;
Expand All @@ -192,10 +192,10 @@ public void flush() {
@Override
public void shutdown() {
synchronized (objectStateLock) {
if (state == State.STARTED) {
if (state == STATE_STARTED) {
handlerThread.quit();
}
state = State.SHUT_DOWN;
state = STATE_SHUT_DOWN;
}
}

Expand Down Expand Up @@ -289,7 +289,7 @@ public void onOutputFormatChanged(@NonNull MediaCodec codec, @NonNull MediaForma

private void onFlushComplete() {
synchronized (objectStateLock) {
if (state == State.SHUT_DOWN) {
if (state == STATE_SHUT_DOWN) {
return;
}

Expand Down
Loading

0 comments on commit ed1de00

Please sign in to comment.