Split metadata and text outputs from their renderer classes

There will be non-ExoPlayer players that can output text
and metadata, so the outputs should be standalone. There
may also be ExoPlayer instances that use non-standard
text and metadata renderers, for which this change also
makes sense.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=165628420
This commit is contained in:
olly 2017-08-17 14:20:56 -07:00 committed by Oliver Woodman
parent 4917929a3a
commit 2470b39d95
11 changed files with 128 additions and 81 deletions

View File

@ -29,7 +29,7 @@ import com.google.android.exoplayer2.audio.AudioRendererEventListener;
import com.google.android.exoplayer2.decoder.DecoderCounters;
import com.google.android.exoplayer2.drm.DefaultDrmSessionManager;
import com.google.android.exoplayer2.metadata.Metadata;
import com.google.android.exoplayer2.metadata.MetadataRenderer;
import com.google.android.exoplayer2.metadata.MetadataOutput;
import com.google.android.exoplayer2.metadata.emsg.EventMessage;
import com.google.android.exoplayer2.metadata.id3.ApicFrame;
import com.google.android.exoplayer2.metadata.id3.CommentFrame;
@ -55,10 +55,9 @@ import java.util.Locale;
/**
* Logs player events using {@link Log}.
*/
/* package */ final class EventLogger implements Player.EventListener, AudioRendererEventListener,
VideoRendererEventListener, AdaptiveMediaSourceEventListener,
ExtractorMediaSource.EventListener, DefaultDrmSessionManager.EventListener,
MetadataRenderer.Output {
/* package */ final class EventLogger implements Player.EventListener, MetadataOutput,
AudioRendererEventListener, VideoRendererEventListener, AdaptiveMediaSourceEventListener,
ExtractorMediaSource.EventListener, DefaultDrmSessionManager.EventListener {
private static final String TAG = "EventLogger";
private static final int MAX_TIMELINE_ITEM_LINES = 3;
@ -205,7 +204,7 @@ import java.util.Locale;
Log.d(TAG, "]");
}
// MetadataRenderer.Output
// MetadataOutput
@Override
public void onMetadata(Metadata metadata) {

View File

@ -28,7 +28,9 @@ import com.google.android.exoplayer2.audio.MediaCodecAudioRenderer;
import com.google.android.exoplayer2.drm.DrmSessionManager;
import com.google.android.exoplayer2.drm.FrameworkMediaCrypto;
import com.google.android.exoplayer2.mediacodec.MediaCodecSelector;
import com.google.android.exoplayer2.metadata.MetadataOutput;
import com.google.android.exoplayer2.metadata.MetadataRenderer;
import com.google.android.exoplayer2.text.TextOutput;
import com.google.android.exoplayer2.text.TextRenderer;
import com.google.android.exoplayer2.trackselection.TrackSelector;
import com.google.android.exoplayer2.video.MediaCodecVideoRenderer;
@ -137,8 +139,8 @@ public class DefaultRenderersFactory implements RenderersFactory {
@Override
public Renderer[] createRenderers(Handler eventHandler,
VideoRendererEventListener videoRendererEventListener,
AudioRendererEventListener audioRendererEventListener, TextRenderer.Output textRendererOutput,
MetadataRenderer.Output metadataRendererOutput) {
AudioRendererEventListener audioRendererEventListener,
TextOutput textRendererOutput, MetadataOutput metadataRendererOutput) {
ArrayList<Renderer> renderersList = new ArrayList<>();
buildVideoRenderers(context, drmSessionManager, allowedVideoJoiningTimeMs,
eventHandler, videoRendererEventListener, extensionRendererMode, renderersList);
@ -283,8 +285,8 @@ public class DefaultRenderersFactory implements RenderersFactory {
* @param extensionRendererMode The extension renderer mode.
* @param out An array to which the built renderers should be appended.
*/
protected void buildTextRenderers(Context context, TextRenderer.Output output,
Looper outputLooper, @ExtensionRendererMode int extensionRendererMode,
protected void buildTextRenderers(Context context, TextOutput output, Looper outputLooper,
@ExtensionRendererMode int extensionRendererMode,
ArrayList<Renderer> out) {
out.add(new TextRenderer(output, outputLooper));
}
@ -299,9 +301,8 @@ public class DefaultRenderersFactory implements RenderersFactory {
* @param extensionRendererMode The extension renderer mode.
* @param out An array to which the built renderers should be appended.
*/
protected void buildMetadataRenderers(Context context, MetadataRenderer.Output output,
Looper outputLooper, @ExtensionRendererMode int extensionRendererMode,
ArrayList<Renderer> out) {
protected void buildMetadataRenderers(Context context, MetadataOutput output, Looper outputLooper,
@ExtensionRendererMode int extensionRendererMode, ArrayList<Renderer> out) {
out.add(new MetadataRenderer(output, outputLooper));
}

View File

@ -17,8 +17,8 @@ package com.google.android.exoplayer2;
import android.os.Handler;
import com.google.android.exoplayer2.audio.AudioRendererEventListener;
import com.google.android.exoplayer2.metadata.MetadataRenderer;
import com.google.android.exoplayer2.text.TextRenderer;
import com.google.android.exoplayer2.metadata.MetadataOutput;
import com.google.android.exoplayer2.text.TextOutput;
import com.google.android.exoplayer2.video.VideoRendererEventListener;
/**
@ -38,7 +38,7 @@ public interface RenderersFactory {
*/
Renderer[] createRenderers(Handler eventHandler,
VideoRendererEventListener videoRendererEventListener,
AudioRendererEventListener audioRendererEventListener,
TextRenderer.Output textRendererOutput, MetadataRenderer.Output metadataRendererOutput);
AudioRendererEventListener audioRendererEventListener, TextOutput textRendererOutput,
MetadataOutput metadataRendererOutput);
}

View File

@ -31,11 +31,11 @@ import com.google.android.exoplayer2.audio.AudioAttributes;
import com.google.android.exoplayer2.audio.AudioRendererEventListener;
import com.google.android.exoplayer2.decoder.DecoderCounters;
import com.google.android.exoplayer2.metadata.Metadata;
import com.google.android.exoplayer2.metadata.MetadataRenderer;
import com.google.android.exoplayer2.metadata.MetadataOutput;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.text.Cue;
import com.google.android.exoplayer2.text.TextRenderer;
import com.google.android.exoplayer2.text.TextOutput;
import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
import com.google.android.exoplayer2.trackselection.TrackSelector;
import com.google.android.exoplayer2.util.Util;
@ -89,8 +89,8 @@ public class SimpleExoPlayer implements ExoPlayer {
private final ExoPlayer player;
private final ComponentListener componentListener;
private final CopyOnWriteArraySet<VideoListener> videoListeners;
private final CopyOnWriteArraySet<TextRenderer.Output> textOutputs;
private final CopyOnWriteArraySet<MetadataRenderer.Output> metadataOutputs;
private final CopyOnWriteArraySet<TextOutput> textOutputs;
private final CopyOnWriteArraySet<MetadataOutput> metadataOutputs;
private final int videoRendererCount;
private final int audioRendererCount;
@ -491,7 +491,7 @@ public class SimpleExoPlayer implements ExoPlayer {
*
* @param listener The output to register.
*/
public void addTextOutput(TextRenderer.Output listener) {
public void addTextOutput(TextOutput listener) {
textOutputs.add(listener);
}
@ -500,7 +500,7 @@ public class SimpleExoPlayer implements ExoPlayer {
*
* @param listener The output to remove.
*/
public void removeTextOutput(TextRenderer.Output listener) {
public void removeTextOutput(TextOutput listener) {
textOutputs.remove(listener);
}
@ -508,10 +508,10 @@ public class SimpleExoPlayer implements ExoPlayer {
* Sets an output to receive text events, removing all existing outputs.
*
* @param output The output.
* @deprecated Use {@link #addTextOutput(TextRenderer.Output)}.
* @deprecated Use {@link #addTextOutput(TextOutput)}.
*/
@Deprecated
public void setTextOutput(TextRenderer.Output output) {
public void setTextOutput(TextOutput output) {
textOutputs.clear();
if (output != null) {
addTextOutput(output);
@ -519,13 +519,13 @@ public class SimpleExoPlayer implements ExoPlayer {
}
/**
* Equivalent to {@link #removeTextOutput(TextRenderer.Output)}.
* Equivalent to {@link #removeTextOutput(TextOutput)}.
*
* @param output The output to clear.
* @deprecated Use {@link #removeTextOutput(TextRenderer.Output)}.
* @deprecated Use {@link #removeTextOutput(TextOutput)}.
*/
@Deprecated
public void clearTextOutput(TextRenderer.Output output) {
public void clearTextOutput(TextOutput output) {
removeTextOutput(output);
}
@ -534,7 +534,7 @@ public class SimpleExoPlayer implements ExoPlayer {
*
* @param listener The output to register.
*/
public void addMetadataOutput(MetadataRenderer.Output listener) {
public void addMetadataOutput(MetadataOutput listener) {
metadataOutputs.add(listener);
}
@ -543,7 +543,7 @@ public class SimpleExoPlayer implements ExoPlayer {
*
* @param listener The output to remove.
*/
public void removeMetadataOutput(MetadataRenderer.Output listener) {
public void removeMetadataOutput(MetadataOutput listener) {
metadataOutputs.remove(listener);
}
@ -551,10 +551,10 @@ public class SimpleExoPlayer implements ExoPlayer {
* Sets an output to receive metadata events, removing all existing outputs.
*
* @param output The output.
* @deprecated Use {@link #addMetadataOutput(MetadataRenderer.Output)}.
* @deprecated Use {@link #addMetadataOutput(MetadataOutput)}.
*/
@Deprecated
public void setMetadataOutput(MetadataRenderer.Output output) {
public void setMetadataOutput(MetadataOutput output) {
metadataOutputs.clear();
if (output != null) {
addMetadataOutput(output);
@ -562,13 +562,13 @@ public class SimpleExoPlayer implements ExoPlayer {
}
/**
* Equivalent to {@link #removeMetadataOutput(MetadataRenderer.Output)}.
* Equivalent to {@link #removeMetadataOutput(MetadataOutput)}.
*
* @param output The output to clear.
* @deprecated Use {@link #removeMetadataOutput(MetadataRenderer.Output)}.
* @deprecated Use {@link #removeMetadataOutput(MetadataOutput)}.
*/
@Deprecated
public void clearMetadataOutput(MetadataRenderer.Output output) {
public void clearMetadataOutput(MetadataOutput output) {
removeMetadataOutput(output);
}
@ -849,8 +849,8 @@ public class SimpleExoPlayer implements ExoPlayer {
}
private final class ComponentListener implements VideoRendererEventListener,
AudioRendererEventListener, TextRenderer.Output, MetadataRenderer.Output,
SurfaceHolder.Callback, TextureView.SurfaceTextureListener {
AudioRendererEventListener, TextOutput, MetadataOutput, SurfaceHolder.Callback,
TextureView.SurfaceTextureListener {
// VideoRendererEventListener implementation
@ -973,20 +973,20 @@ public class SimpleExoPlayer implements ExoPlayer {
audioSessionId = C.AUDIO_SESSION_ID_UNSET;
}
// TextRenderer.Output implementation
// TextOutput implementation
@Override
public void onCues(List<Cue> cues) {
for (TextRenderer.Output textOutput : textOutputs) {
for (TextOutput textOutput : textOutputs) {
textOutput.onCues(cues);
}
}
// MetadataRenderer.Output implementation
// MetadataOutput implementation
@Override
public void onMetadata(Metadata metadata) {
for (MetadataRenderer.Output metadataOutput : metadataOutputs) {
for (MetadataOutput metadataOutput : metadataOutputs) {
metadataOutput.onMetadata(metadata);
}
}

View File

@ -0,0 +1,30 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.exoplayer2.metadata;
/**
* Receives metadata output.
*/
public interface MetadataOutput {
/**
* Called when there is metadata associated with current playback time.
*
* @param metadata The metadata.
*/
void onMetadata(Metadata metadata);
}

View File

@ -33,18 +33,10 @@ import java.util.Arrays;
public final class MetadataRenderer extends BaseRenderer implements Callback {
/**
* Receives output from a {@link MetadataRenderer}.
* @deprecated Use {@link MetadataOutput}.
*/
public interface Output {
/**
* Called each time there is a metadata associated with current playback time.
*
* @param metadata The metadata.
*/
void onMetadata(Metadata metadata);
}
@Deprecated
public interface Output extends MetadataOutput {}
private static final int MSG_INVOKE_RENDERER = 0;
// TODO: Holding multiple pending metadata objects is temporary mitigation against
@ -53,7 +45,7 @@ public final class MetadataRenderer extends BaseRenderer implements Callback {
private static final int MAX_PENDING_METADATA_COUNT = 5;
private final MetadataDecoderFactory decoderFactory;
private final Output output;
private final MetadataOutput output;
private final Handler outputHandler;
private final FormatHolder formatHolder;
private final MetadataInputBuffer buffer;
@ -73,7 +65,7 @@ public final class MetadataRenderer extends BaseRenderer implements Callback {
* {@link android.app.Activity#getMainLooper()}. Null may be passed if the output should be
* called directly on the player's internal rendering thread.
*/
public MetadataRenderer(Output output, Looper outputLooper) {
public MetadataRenderer(MetadataOutput output, Looper outputLooper) {
this(output, outputLooper, MetadataDecoderFactory.DEFAULT);
}
@ -86,7 +78,7 @@ public final class MetadataRenderer extends BaseRenderer implements Callback {
* called directly on the player's internal rendering thread.
* @param decoderFactory A factory from which to obtain {@link MetadataDecoder} instances.
*/
public MetadataRenderer(Output output, Looper outputLooper,
public MetadataRenderer(MetadataOutput output, Looper outputLooper,
MetadataDecoderFactory decoderFactory) {
super(C.TRACK_TYPE_METADATA);
this.output = Assertions.checkNotNull(output);

View File

@ -0,0 +1,32 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.exoplayer2.text;
import java.util.List;
/**
* Receives text output.
*/
public interface TextOutput {
/**
* Called when there is a change in the {@link Cue}s.
*
* @param cues The {@link Cue}s.
*/
void onCues(List<Cue> cues);
}

View File

@ -37,23 +37,15 @@ import java.util.List;
* <p>
* {@link Subtitle}s are decoded from sample data using {@link SubtitleDecoder} instances obtained
* from a {@link SubtitleDecoderFactory}. The actual rendering of the subtitle {@link Cue}s is
* delegated to an {@link Output}.
* delegated to an {@link TextOutput}.
*/
public final class TextRenderer extends BaseRenderer implements Callback {
/**
* Receives output from a {@link TextRenderer}.
* @deprecated Use {@link TextOutput}.
*/
public interface Output {
/**
* Called each time there is a change in the {@link Cue}s.
*
* @param cues The {@link Cue}s.
*/
void onCues(List<Cue> cues);
}
@Deprecated
public interface Output extends TextOutput {}
@Retention(RetentionPolicy.SOURCE)
@IntDef({REPLACEMENT_STATE_NONE, REPLACEMENT_STATE_SIGNAL_END_OF_STREAM,
@ -79,7 +71,7 @@ public final class TextRenderer extends BaseRenderer implements Callback {
private static final int MSG_UPDATE_OUTPUT = 0;
private final Handler outputHandler;
private final Output output;
private final TextOutput output;
private final SubtitleDecoderFactory decoderFactory;
private final FormatHolder formatHolder;
@ -101,7 +93,7 @@ public final class TextRenderer extends BaseRenderer implements Callback {
* using {@link android.app.Activity#getMainLooper()}. Null may be passed if the output
* should be called directly on the player's internal rendering thread.
*/
public TextRenderer(Output output, Looper outputLooper) {
public TextRenderer(TextOutput output, Looper outputLooper) {
this(output, outputLooper, SubtitleDecoderFactory.DEFAULT);
}
@ -114,7 +106,8 @@ public final class TextRenderer extends BaseRenderer implements Callback {
* should be called directly on the player's internal rendering thread.
* @param decoderFactory A factory from which to obtain {@link SubtitleDecoder} instances.
*/
public TextRenderer(Output output, Looper outputLooper, SubtitleDecoderFactory decoderFactory) {
public TextRenderer(TextOutput output, Looper outputLooper,
SubtitleDecoderFactory decoderFactory) {
super(C.TRACK_TYPE_TEXT);
this.output = Assertions.checkNotNull(output);
this.outputHandler = outputLooper == null ? null : new Handler(outputLooper, this);

View File

@ -43,7 +43,7 @@ import com.google.android.exoplayer2.metadata.Metadata;
import com.google.android.exoplayer2.metadata.id3.ApicFrame;
import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.text.Cue;
import com.google.android.exoplayer2.text.TextRenderer;
import com.google.android.exoplayer2.text.TextOutput;
import com.google.android.exoplayer2.trackselection.TrackSelection;
import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout.ResizeMode;
@ -844,10 +844,10 @@ public final class SimpleExoPlayerView extends FrameLayout {
aspectRatioFrame.setResizeMode(resizeMode);
}
private final class ComponentListener implements SimpleExoPlayer.VideoListener,
TextRenderer.Output, Player.EventListener {
private final class ComponentListener implements TextOutput, SimpleExoPlayer.VideoListener,
Player.EventListener {
// TextRenderer.Output implementation
// TextOutput implementation
@Override
public void onCues(List<Cue> cues) {
@ -856,7 +856,7 @@ public final class SimpleExoPlayerView extends FrameLayout {
}
}
// SimpleExoPlayer.VideoListener implementation
// SimpleExoPlayer.VideoInfoListener implementation
@Override
public void onVideoSizeChanged(int width, int height, int unappliedRotationDegrees,

View File

@ -25,7 +25,7 @@ import android.view.View;
import android.view.accessibility.CaptioningManager;
import com.google.android.exoplayer2.text.CaptionStyleCompat;
import com.google.android.exoplayer2.text.Cue;
import com.google.android.exoplayer2.text.TextRenderer;
import com.google.android.exoplayer2.text.TextOutput;
import com.google.android.exoplayer2.util.Util;
import java.util.ArrayList;
import java.util.List;
@ -33,7 +33,7 @@ import java.util.List;
/**
* A view for displaying subtitle {@link Cue}s.
*/
public final class SubtitleView extends View implements TextRenderer.Output {
public final class SubtitleView extends View implements TextOutput {
/**
* The default fractional text size.

View File

@ -29,12 +29,12 @@ import com.google.android.exoplayer2.RenderersFactory;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.audio.AudioRendererEventListener;
import com.google.android.exoplayer2.metadata.MetadataRenderer;
import com.google.android.exoplayer2.metadata.MetadataOutput;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.testutil.ExoPlayerTestRunner.Builder.PlayerFactory;
import com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition;
import com.google.android.exoplayer2.text.TextRenderer.Output;
import com.google.android.exoplayer2.text.TextOutput;
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
import com.google.android.exoplayer2.trackselection.MappingTrackSelector;
import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
@ -164,8 +164,8 @@ public final class ExoPlayerTestRunner implements Player.EventListener {
@Override
public Renderer[] createRenderers(Handler eventHandler,
VideoRendererEventListener videoRendererEventListener,
AudioRendererEventListener audioRendererEventListener, Output textRendererOutput,
MetadataRenderer.Output metadataRendererOutput) {
AudioRendererEventListener audioRendererEventListener, TextOutput textRendererOutput,
MetadataOutput metadataRendererOutput) {
return renderers;
}
};