Commit 117ce33a by claincly Committed by christosts

Add public API and render messages for setting effects.

PiperOrigin-RevId: 509165378
parent 4f77ac7f
...@@ -58,6 +58,7 @@ import com.google.android.exoplayer2.upstream.BandwidthMeter; ...@@ -58,6 +58,7 @@ import com.google.android.exoplayer2.upstream.BandwidthMeter;
import com.google.android.exoplayer2.upstream.DataSource; import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter; import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter;
import com.google.android.exoplayer2.util.Clock; import com.google.android.exoplayer2.util.Clock;
import com.google.android.exoplayer2.util.Effect;
import com.google.android.exoplayer2.util.PriorityTaskManager; import com.google.android.exoplayer2.util.PriorityTaskManager;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
import com.google.android.exoplayer2.video.MediaCodecVideoRenderer; import com.google.android.exoplayer2.video.MediaCodecVideoRenderer;
...@@ -1457,6 +1458,24 @@ public interface ExoPlayer extends Player { ...@@ -1457,6 +1458,24 @@ public interface ExoPlayer extends Player {
boolean getSkipSilenceEnabled(); boolean getSkipSilenceEnabled();
/** /**
* Sets a {@link List} of {@linkplain Effect video effects} that will be applied to each video
* frame.
*
* <p>The following limitations exist for using {@linkplain Effect video effects}:
*
* <ul>
* <li>This feature works only with the default {@link MediaCodecVideoRenderer} and not custom
* or extension {@linkplain Renderer video renderers}.
* <li>This feature does not work with DRM-protected contents.
* <li>This method should be called before calling {@link #prepare}.
* </ul>
*
* @param videoEffects The {@link List} of {@linkplain Effect video effects} to apply.
*/
@RequiresApi(18)
void setVideoEffects(List<Effect> videoEffects);
/**
* Sets the {@link C.VideoScalingMode}. * Sets the {@link C.VideoScalingMode}.
* *
* <p>The scaling mode only applies if a {@link MediaCodec}-based video {@link Renderer} is * <p>The scaling mode only applies if a {@link MediaCodec}-based video {@link Renderer} is
......
...@@ -26,6 +26,7 @@ import static com.google.android.exoplayer2.Renderer.MSG_SET_CHANGE_FRAME_RATE_S ...@@ -26,6 +26,7 @@ import static com.google.android.exoplayer2.Renderer.MSG_SET_CHANGE_FRAME_RATE_S
import static com.google.android.exoplayer2.Renderer.MSG_SET_PREFERRED_AUDIO_DEVICE; import static com.google.android.exoplayer2.Renderer.MSG_SET_PREFERRED_AUDIO_DEVICE;
import static com.google.android.exoplayer2.Renderer.MSG_SET_SCALING_MODE; import static com.google.android.exoplayer2.Renderer.MSG_SET_SCALING_MODE;
import static com.google.android.exoplayer2.Renderer.MSG_SET_SKIP_SILENCE_ENABLED; import static com.google.android.exoplayer2.Renderer.MSG_SET_SKIP_SILENCE_ENABLED;
import static com.google.android.exoplayer2.Renderer.MSG_SET_VIDEO_EFFECTS;
import static com.google.android.exoplayer2.Renderer.MSG_SET_VIDEO_FRAME_METADATA_LISTENER; import static com.google.android.exoplayer2.Renderer.MSG_SET_VIDEO_FRAME_METADATA_LISTENER;
import static com.google.android.exoplayer2.Renderer.MSG_SET_VIDEO_OUTPUT; import static com.google.android.exoplayer2.Renderer.MSG_SET_VIDEO_OUTPUT;
import static com.google.android.exoplayer2.Renderer.MSG_SET_VIDEO_OUTPUT_RESOLUTION; import static com.google.android.exoplayer2.Renderer.MSG_SET_VIDEO_OUTPUT_RESOLUTION;
...@@ -86,6 +87,7 @@ import com.google.android.exoplayer2.trackselection.TrackSelectorResult; ...@@ -86,6 +87,7 @@ import com.google.android.exoplayer2.trackselection.TrackSelectorResult;
import com.google.android.exoplayer2.upstream.BandwidthMeter; import com.google.android.exoplayer2.upstream.BandwidthMeter;
import com.google.android.exoplayer2.util.Clock; import com.google.android.exoplayer2.util.Clock;
import com.google.android.exoplayer2.util.ConditionVariable; import com.google.android.exoplayer2.util.ConditionVariable;
import com.google.android.exoplayer2.util.Effect;
import com.google.android.exoplayer2.util.HandlerWrapper; import com.google.android.exoplayer2.util.HandlerWrapper;
import com.google.android.exoplayer2.util.ListenerSet; import com.google.android.exoplayer2.util.ListenerSet;
import com.google.android.exoplayer2.util.Log; import com.google.android.exoplayer2.util.Log;
...@@ -1229,6 +1231,12 @@ import java.util.concurrent.TimeoutException; ...@@ -1229,6 +1231,12 @@ import java.util.concurrent.TimeoutException;
} }
@Override @Override
public void setVideoEffects(List<Effect> videoEffects) {
verifyApplicationThread();
sendRendererMessage(TRACK_TYPE_VIDEO, MSG_SET_VIDEO_EFFECTS, videoEffects);
}
@Override
public void setVideoScalingMode(@C.VideoScalingMode int videoScalingMode) { public void setVideoScalingMode(@C.VideoScalingMode int videoScalingMode) {
verifyApplicationThread(); verifyApplicationThread();
this.videoScalingMode = videoScalingMode; this.videoScalingMode = videoScalingMode;
......
...@@ -37,6 +37,7 @@ import java.lang.annotation.Documented; ...@@ -37,6 +37,7 @@ import java.lang.annotation.Documented;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
import java.util.List;
/** /**
* Renders media read from a {@link SampleStream}. * Renders media read from a {@link SampleStream}.
...@@ -82,8 +83,8 @@ public interface Renderer extends PlayerMessage.Target { ...@@ -82,8 +83,8 @@ public interface Renderer extends PlayerMessage.Target {
* #MSG_SET_SCALING_MODE}, {@link #MSG_SET_CHANGE_FRAME_RATE_STRATEGY}, {@link * #MSG_SET_SCALING_MODE}, {@link #MSG_SET_CHANGE_FRAME_RATE_STRATEGY}, {@link
* #MSG_SET_AUX_EFFECT_INFO}, {@link #MSG_SET_VIDEO_FRAME_METADATA_LISTENER}, {@link * #MSG_SET_AUX_EFFECT_INFO}, {@link #MSG_SET_VIDEO_FRAME_METADATA_LISTENER}, {@link
* #MSG_SET_CAMERA_MOTION_LISTENER}, {@link #MSG_SET_SKIP_SILENCE_ENABLED}, {@link * #MSG_SET_CAMERA_MOTION_LISTENER}, {@link #MSG_SET_SKIP_SILENCE_ENABLED}, {@link
* #MSG_SET_AUDIO_SESSION_ID}, {@link #MSG_SET_WAKEUP_LISTENER} or {@link * #MSG_SET_AUDIO_SESSION_ID}, {@link #MSG_SET_WAKEUP_LISTENER}, {@link #MSG_SET_VIDEO_EFFECTS} or
* #MSG_SET_VIDEO_OUTPUT_RESOLUTION}. May also be an app-defined value (see {@link * {@link #MSG_SET_VIDEO_OUTPUT_RESOLUTION}. May also be an app-defined value (see {@link
* #MSG_CUSTOM_BASE}). * #MSG_CUSTOM_BASE}).
*/ */
@Documented @Documented
...@@ -103,6 +104,7 @@ public interface Renderer extends PlayerMessage.Target { ...@@ -103,6 +104,7 @@ public interface Renderer extends PlayerMessage.Target {
MSG_SET_SKIP_SILENCE_ENABLED, MSG_SET_SKIP_SILENCE_ENABLED,
MSG_SET_AUDIO_SESSION_ID, MSG_SET_AUDIO_SESSION_ID,
MSG_SET_WAKEUP_LISTENER, MSG_SET_WAKEUP_LISTENER,
MSG_SET_VIDEO_EFFECTS,
MSG_SET_VIDEO_OUTPUT_RESOLUTION MSG_SET_VIDEO_OUTPUT_RESOLUTION
}) })
public @interface MessageType {} public @interface MessageType {}
...@@ -206,11 +208,16 @@ public interface Renderer extends PlayerMessage.Target { ...@@ -206,11 +208,16 @@ public interface Renderer extends PlayerMessage.Target {
*/ */
int MSG_SET_PREFERRED_AUDIO_DEVICE = 12; int MSG_SET_PREFERRED_AUDIO_DEVICE = 12;
/** /**
* The type of a message that can be passed to a video renderer. The message payload should be a
* {@link List} containing {@linkplain Effect video effects}.
*/
int MSG_SET_VIDEO_EFFECTS = 13;
/**
* The type of a message that can be passed to a video renderer to set the desired output * The type of a message that can be passed to a video renderer to set the desired output
* resolution. The message payload should be a {@link Size} of the desired output width and * resolution. The message payload should be a {@link Size} of the desired output width and
* height. Use this method only when playing with video {@linkplain Effect effects}. * height. Use this method only when playing with video {@linkplain Effect effects}.
*/ */
int MSG_SET_VIDEO_OUTPUT_RESOLUTION = 13; int MSG_SET_VIDEO_OUTPUT_RESOLUTION = 14;
/** /**
* Applications or extensions may define custom {@code MSG_*} constants that can be passed to * Applications or extensions may define custom {@code MSG_*} constants that can be passed to
* renderers. These custom constants must be greater than or equal to this value. * renderers. These custom constants must be greater than or equal to this value.
......
...@@ -45,6 +45,7 @@ import com.google.android.exoplayer2.trackselection.TrackSelector; ...@@ -45,6 +45,7 @@ import com.google.android.exoplayer2.trackselection.TrackSelector;
import com.google.android.exoplayer2.upstream.BandwidthMeter; import com.google.android.exoplayer2.upstream.BandwidthMeter;
import com.google.android.exoplayer2.util.Clock; import com.google.android.exoplayer2.util.Clock;
import com.google.android.exoplayer2.util.ConditionVariable; import com.google.android.exoplayer2.util.ConditionVariable;
import com.google.android.exoplayer2.util.Effect;
import com.google.android.exoplayer2.util.PriorityTaskManager; import com.google.android.exoplayer2.util.PriorityTaskManager;
import com.google.android.exoplayer2.util.Size; import com.google.android.exoplayer2.util.Size;
import com.google.android.exoplayer2.video.VideoFrameMetadataListener; import com.google.android.exoplayer2.video.VideoFrameMetadataListener;
...@@ -654,6 +655,12 @@ public class SimpleExoPlayer extends BasePlayer ...@@ -654,6 +655,12 @@ public class SimpleExoPlayer extends BasePlayer
} }
@Override @Override
public void setVideoEffects(List<Effect> videoEffects) {
blockUntilConstructorFinished();
player.setVideoEffects(videoEffects);
}
@Override
public void setSkipSilenceEnabled(boolean skipSilenceEnabled) { public void setSkipSilenceEnabled(boolean skipSilenceEnabled) {
blockUntilConstructorFinished(); blockUntilConstructorFinished();
player.setSkipSilenceEnabled(skipSilenceEnabled); player.setSkipSilenceEnabled(skipSilenceEnabled);
......
...@@ -684,6 +684,11 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer { ...@@ -684,6 +684,11 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
} }
} }
break; break;
case MSG_SET_VIDEO_EFFECTS:
@SuppressWarnings("unchecked")
List<Effect> videoEffects = (List<Effect>) checkNotNull(message);
frameProcessorManager.setVideoEffects(videoEffects);
break;
case MSG_SET_VIDEO_OUTPUT_RESOLUTION: case MSG_SET_VIDEO_OUTPUT_RESOLUTION:
Size outputResolution = (Size) checkNotNull(message); Size outputResolution = (Size) checkNotNull(message);
if (outputResolution.getWidth() != 0 if (outputResolution.getWidth() != 0
......
...@@ -36,6 +36,7 @@ import com.google.android.exoplayer2.source.TrackGroupArray; ...@@ -36,6 +36,7 @@ import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.trackselection.TrackSelectionArray; import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
import com.google.android.exoplayer2.trackselection.TrackSelector; import com.google.android.exoplayer2.trackselection.TrackSelector;
import com.google.android.exoplayer2.util.Clock; import com.google.android.exoplayer2.util.Clock;
import com.google.android.exoplayer2.util.Effect;
import com.google.android.exoplayer2.util.PriorityTaskManager; import com.google.android.exoplayer2.util.PriorityTaskManager;
import com.google.android.exoplayer2.video.VideoFrameMetadataListener; import com.google.android.exoplayer2.video.VideoFrameMetadataListener;
import com.google.android.exoplayer2.video.spherical.CameraMotionListener; import com.google.android.exoplayer2.video.spherical.CameraMotionListener;
...@@ -251,6 +252,11 @@ public class StubExoPlayer extends StubPlayer implements ExoPlayer { ...@@ -251,6 +252,11 @@ public class StubExoPlayer extends StubPlayer implements ExoPlayer {
} }
@Override @Override
public void setVideoEffects(List<Effect> videoEffects) {
throw new UnsupportedOperationException();
}
@Override
public void setVideoScalingMode(int videoScalingMode) { public void setVideoScalingMode(int videoScalingMode) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment