Skip to content

Commit

Permalink
Set MediaCodec operation mode for audio/video
Browse files Browse the repository at this point in the history
Add experimental APIs to set the MediaCodecOperationMode separately
for audio and video.

PiperOrigin-RevId: 315467157
  • Loading branch information
christosts authored and icbaker committed Jun 9, 2020
1 parent a56a02d commit d23ca7b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ public class DefaultRenderersFactory implements RenderersFactory {
private long allowedVideoJoiningTimeMs;
private boolean enableDecoderFallback;
private MediaCodecSelector mediaCodecSelector;
private @MediaCodecRenderer.MediaCodecOperationMode int mediaCodecOperationMode;
private @MediaCodecRenderer.MediaCodecOperationMode int audioMediaCodecOperationMode;
private @MediaCodecRenderer.MediaCodecOperationMode int videoMediaCodecOperationMode;
private boolean enableOffload;

/** @param context A {@link Context}. */
Expand All @@ -99,7 +100,8 @@ public DefaultRenderersFactory(Context context) {
extensionRendererMode = EXTENSION_RENDERER_MODE_OFF;
allowedVideoJoiningTimeMs = DEFAULT_ALLOWED_VIDEO_JOINING_TIME_MS;
mediaCodecSelector = MediaCodecSelector.DEFAULT;
mediaCodecOperationMode = MediaCodecRenderer.OPERATION_MODE_SYNCHRONOUS;
audioMediaCodecOperationMode = MediaCodecRenderer.OPERATION_MODE_SYNCHRONOUS;
videoMediaCodecOperationMode = MediaCodecRenderer.OPERATION_MODE_SYNCHRONOUS;
}

/**
Expand Down Expand Up @@ -145,17 +147,48 @@ public DefaultRenderersFactory setExtensionRendererMode(
}

/**
* Set the {@link MediaCodecRenderer.MediaCodecOperationMode} of {@link MediaCodecRenderer}
* Set the {@link MediaCodecRenderer.MediaCodecOperationMode} of {@link MediaCodecAudioRenderer}
* instances.
*
* <p>This method is experimental, and will be renamed or removed in a future release.
*
* @param mode The {@link MediaCodecRenderer.MediaCodecOperationMode} to set.
* @return This factory, for convenience.
*/
public DefaultRenderersFactory experimental_setAudioMediaCodecOperationMode(
@MediaCodecRenderer.MediaCodecOperationMode int mode) {
audioMediaCodecOperationMode = mode;
return this;
}

/**
* Set the {@link MediaCodecRenderer.MediaCodecOperationMode} of {@link MediaCodecVideoRenderer}
* instances.
*
* <p>This method is experimental, and will be renamed or removed in a future release.
*
* @param mode The {@link MediaCodecRenderer.MediaCodecOperationMode} to set.
* @return This factory, for convenience.
*/
public DefaultRenderersFactory experimental_setVideoMediaCodecOperationMode(
@MediaCodecRenderer.MediaCodecOperationMode int mode) {
videoMediaCodecOperationMode = mode;
return this;
}

/**
* Set the {@link MediaCodecRenderer.MediaCodecOperationMode} for both {@link
* MediaCodecAudioRenderer} {@link MediaCodecVideoRenderer} instances.
*
* <p>This method is experimental, and will be renamed or removed in a future release.
*
* @param mode The {@link MediaCodecRenderer.MediaCodecOperationMode} to set.
* @return This factory, for convenience.
*/
public DefaultRenderersFactory experimental_setMediaCodecOperationMode(
@MediaCodecRenderer.MediaCodecOperationMode int mode) {
mediaCodecOperationMode = mode;
experimental_setAudioMediaCodecOperationMode(mode);
experimental_setVideoMediaCodecOperationMode(mode);
return this;
}

Expand Down Expand Up @@ -283,7 +316,7 @@ protected void buildVideoRenderers(
eventHandler,
eventListener,
MAX_DROPPED_VIDEO_FRAME_COUNT_TO_NOTIFY);
videoRenderer.experimental_setMediaCodecOperationMode(mediaCodecOperationMode);
videoRenderer.experimental_setMediaCodecOperationMode(videoMediaCodecOperationMode);
out.add(videoRenderer);

if (extensionRendererMode == EXTENSION_RENDERER_MODE_OFF) {
Expand Down Expand Up @@ -415,7 +448,7 @@ protected void buildAudioRenderers(
new DefaultAudioProcessorChain(audioProcessors),
/* enableFloatOutput= */ false,
enableOffload));
audioRenderer.experimental_setMediaCodecOperationMode(mediaCodecOperationMode);
audioRenderer.experimental_setMediaCodecOperationMode(audioMediaCodecOperationMode);
out.add(audioRenderer);

if (extensionRendererMode == EXTENSION_RENDERER_MODE_OFF) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
* <li>{@link #OPERATION_MODE_ASYNCHRONOUS_PLAYBACK_THREAD}
* <li>{@link #OPERATION_MODE_ASYNCHRONOUS_DEDICATED_THREAD}
* <li>{@link #OPERATION_MODE_ASYNCHRONOUS_DEDICATED_THREAD_MULTI_LOCK}
* <li>{@link #OPERATION_MODE_ASYNCHRONOUS_DEDICATED_THREAD_ASYNCHRONOUS_QUEUEING}
* <li>{@link #OPERATION_MODE_ASYNCHRONOUS_DEDICATED_THREAD_MULTI_LOCK_ASYNCHRONOUS_QUEUEING}
* </ul>
*/
@Documented
Expand Down

0 comments on commit d23ca7b

Please sign in to comment.