Skip to content

Migrate video_player/android from SurfaceTexture->SurfaceProducer. #6456

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ final class VideoPlayer {

private Surface surface;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't need to cache surface.


private final TextureRegistry.SurfaceTextureEntry textureEntry;
private final TextureRegistry.SurfaceProducer surfaceProducer;

private QueuingEventSink eventSink;

Expand All @@ -67,13 +67,13 @@ final class VideoPlayer {
VideoPlayer(
Context context,
EventChannel eventChannel,
TextureRegistry.SurfaceTextureEntry textureEntry,
TextureRegistry.SurfaceProducer surfaceProducer,
String dataSource,
String formatHint,
@NonNull Map<String, String> httpHeaders,
VideoPlayerOptions options) {
this.eventChannel = eventChannel;
this.textureEntry = textureEntry;
this.surfaceProducer = surfaceProducer;
this.options = options;

ExoPlayer exoPlayer = new ExoPlayer.Builder(context).build();
Expand All @@ -96,12 +96,12 @@ final class VideoPlayer {
VideoPlayer(
ExoPlayer exoPlayer,
EventChannel eventChannel,
TextureRegistry.SurfaceTextureEntry textureEntry,
TextureRegistry.SurfaceProducer surfaceProducer,
VideoPlayerOptions options,
QueuingEventSink eventSink,
DefaultHttpDataSource.Factory httpDataSourceFactory) {
this.eventChannel = eventChannel;
this.textureEntry = textureEntry;
this.surfaceProducer = surfaceProducer;
this.options = options;
this.httpDataSourceFactory = httpDataSourceFactory;

Expand Down Expand Up @@ -186,7 +186,7 @@ public void onCancel(Object o) {
}
});

surface = new Surface(textureEntry.surfaceTexture());
surface = surfaceProducer.getSurface();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, the returned Surface may become invalid after a suspend / resume. Is there a place in the plugin that will be notified when we resume? We should update the video surface in that callback.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to look at this still.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made this activity aware. It now tears down the exoplayer on pause and recreates on reusme.

exoPlayer.setVideoSurface(surface);
setAudioAttributes(exoPlayer, options.mixWithOthers);

Expand Down Expand Up @@ -334,7 +334,7 @@ void dispose() {
if (isInitialized) {
exoPlayer.stop();
}
textureEntry.release();
surfaceProducer.release();
eventChannel.setStreamHandler(null);
if (surface != null) {
surface.release();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ public void initialize() {
}

public @NonNull TextureMessage create(@NonNull CreateMessage arg) {
TextureRegistry.SurfaceTextureEntry handle =
flutterState.textureRegistry.createSurfaceTexture();
TextureRegistry.SurfaceProducer handle =
flutterState.textureRegistry.createSurfaceProducer();
EventChannel eventChannel =
new EventChannel(
flutterState.binaryMessenger, "flutter.io/videoPlayer/videoEvents" + handle.id());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
public class VideoPlayerTest {
private ExoPlayer fakeExoPlayer;
private EventChannel fakeEventChannel;
private TextureRegistry.SurfaceTextureEntry fakeSurfaceTextureEntry;
private TextureRegistry.SurfaceProducer fakeSurfaceProducer;
private VideoPlayerOptions fakeVideoPlayerOptions;
private QueuingEventSink fakeEventSink;
private DefaultHttpDataSource.Factory httpDataSourceFactorySpy;
Expand All @@ -51,7 +51,7 @@ public void before() {

fakeExoPlayer = mock(ExoPlayer.class);
fakeEventChannel = mock(EventChannel.class);
fakeSurfaceTextureEntry = mock(TextureRegistry.SurfaceTextureEntry.class);
fakeSurfaceProducer = mock(TextureRegistry.SurfaceProducer.class);
fakeVideoPlayerOptions = mock(VideoPlayerOptions.class);
fakeEventSink = mock(QueuingEventSink.class);
httpDataSourceFactorySpy = spy(new DefaultHttpDataSource.Factory());
Expand All @@ -63,7 +63,7 @@ public void videoPlayer_buildsHttpDataSourceFactoryProperlyWhenHttpHeadersNull()
new VideoPlayer(
fakeExoPlayer,
fakeEventChannel,
fakeSurfaceTextureEntry,
fakeSurfaceProducer,
fakeVideoPlayerOptions,
fakeEventSink,
httpDataSourceFactorySpy);
Expand All @@ -82,7 +82,7 @@ public void videoPlayer_buildsHttpDataSourceFactoryProperlyWhenHttpHeadersNull()
new VideoPlayer(
fakeExoPlayer,
fakeEventChannel,
fakeSurfaceTextureEntry,
fakeSurfaceProducer,
fakeVideoPlayerOptions,
fakeEventSink,
httpDataSourceFactorySpy);
Expand All @@ -108,7 +108,7 @@ public void videoPlayer_buildsHttpDataSourceFactoryProperlyWhenHttpHeadersNull()
new VideoPlayer(
fakeExoPlayer,
fakeEventChannel,
fakeSurfaceTextureEntry,
fakeSurfaceProducer,
fakeVideoPlayerOptions,
fakeEventSink,
httpDataSourceFactorySpy);
Expand All @@ -132,7 +132,7 @@ public void sendInitializedSendsExpectedEvent_90RotationDegrees() {
new VideoPlayer(
fakeExoPlayer,
fakeEventChannel,
fakeSurfaceTextureEntry,
fakeSurfaceProducer,
fakeVideoPlayerOptions,
fakeEventSink,
httpDataSourceFactorySpy);
Expand Down Expand Up @@ -161,7 +161,7 @@ public void sendInitializedSendsExpectedEvent_270RotationDegrees() {
new VideoPlayer(
fakeExoPlayer,
fakeEventChannel,
fakeSurfaceTextureEntry,
fakeSurfaceProducer,
fakeVideoPlayerOptions,
fakeEventSink,
httpDataSourceFactorySpy);
Expand Down Expand Up @@ -190,7 +190,7 @@ public void sendInitializedSendsExpectedEvent_0RotationDegrees() {
new VideoPlayer(
fakeExoPlayer,
fakeEventChannel,
fakeSurfaceTextureEntry,
fakeSurfaceProducer,
fakeVideoPlayerOptions,
fakeEventSink,
httpDataSourceFactorySpy);
Expand Down Expand Up @@ -219,7 +219,7 @@ public void sendInitializedSendsExpectedEvent_180RotationDegrees() {
new VideoPlayer(
fakeExoPlayer,
fakeEventChannel,
fakeSurfaceTextureEntry,
fakeSurfaceProducer,
fakeVideoPlayerOptions,
fakeEventSink,
httpDataSourceFactorySpy);
Expand Down Expand Up @@ -248,7 +248,7 @@ public void onIsPlayingChangedSendsExpectedEvent() {
new VideoPlayer(
fakeExoPlayer,
fakeEventChannel,
fakeSurfaceTextureEntry,
fakeSurfaceProducer,
fakeVideoPlayerOptions,
fakeEventSink,
httpDataSourceFactorySpy);
Expand Down Expand Up @@ -293,7 +293,7 @@ public void behindLiveWindowErrorResetsPlayerToDefaultPosition() {
new VideoPlayer(
fakeExoPlayer,
fakeEventChannel,
fakeSurfaceTextureEntry,
fakeSurfaceProducer,
fakeVideoPlayerOptions,
fakeEventSink,
httpDataSourceFactorySpy);
Expand Down