Skip to content

Commit

Permalink
Improve SimpleExoPlayer flexibility
Browse files Browse the repository at this point in the history
- Allow extension and overriding of renderer creation.
  Several developers have asked for this, so that they
  can use their own renderers (typically extensions to
  the core ones) without losing the ability to use
  SimpleExoPlayer.
- Add option to not attempt extension renderer creation,
  for efficiency.
- Align build variants for internal and external demo
  apps. This is slightly unfortunate, but convergence
  seems necessary for useExtensionRenderers.
- Fix DASH playback tests to use the debug video
  renderer.

Issue #2102

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=140140915
  • Loading branch information
ojw28 committed Nov 25, 2016
1 parent cbf5988 commit 894ae1a
Show file tree
Hide file tree
Showing 9 changed files with 359 additions and 177 deletions.
19 changes: 13 additions & 6 deletions demo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,23 @@ android {
abortOnError false
}

flavorDimensions "extensions"

productFlavors {
noExtensions
withExtensions
noExtns {
dimension "extensions"
}
extns {
dimension "extensions"
}
}

}

dependencies {
compile project(':library')
withExtensionsCompile project(path: ':extension-ffmpeg')
withExtensionsCompile project(path: ':extension-flac')
withExtensionsCompile project(path: ':extension-opus')
withExtensionsCompile project(path: ':extension-vp9')
extnsCompile project(path: ':extension-ffmpeg')
extnsCompile project(path: ':extension-flac')
extnsCompile project(path: ':extension-opus')
extnsCompile project(path: ':extension-vp9')
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,19 @@ public void onCreate() {
userAgent = Util.getUserAgent(this, "ExoPlayerDemo");
}

DataSource.Factory buildDataSourceFactory(DefaultBandwidthMeter bandwidthMeter) {
public DataSource.Factory buildDataSourceFactory(DefaultBandwidthMeter bandwidthMeter) {
return new DefaultDataSourceFactory(this, bandwidthMeter,
buildHttpDataSourceFactory(bandwidthMeter));
}

HttpDataSource.Factory buildHttpDataSourceFactory(DefaultBandwidthMeter bandwidthMeter) {
public HttpDataSource.Factory buildHttpDataSourceFactory(DefaultBandwidthMeter bandwidthMeter) {
return new DefaultHttpDataSourceFactory(userAgent, bandwidthMeter);
}

public boolean useExtensionRenderers() {
// We should return BuildConfig.FLAVOR_extensions.equals("extns") here, but this is currently
// incompatible with a Google internal build system.
return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,17 @@ private void initializePlayer() {
}
}

@SimpleExoPlayer.ExtensionRendererMode int extensionRendererMode =
((DemoApplication) getApplication()).useExtensionRenderers()
? (preferExtensionDecoders ? SimpleExoPlayer.EXTENSION_RENDERER_MODE_PREFER
: SimpleExoPlayer.EXTENSION_RENDERER_MODE_ON)
: SimpleExoPlayer.EXTENSION_RENDERER_MODE_OFF;
TrackSelection.Factory videoTrackSelectionFactory =
new AdaptiveVideoTrackSelection.Factory(BANDWIDTH_METER);
trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
trackSelectionHelper = new TrackSelectionHelper(trackSelector, videoTrackSelectionFactory);
player = ExoPlayerFactory.newSimpleInstance(this, trackSelector, new DefaultLoadControl(),
drmSessionManager, preferExtensionDecoders);
drmSessionManager, extensionRendererMode);
player.addListener(this);

eventLogger = new EventLogger(trackSelector);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static SimpleExoPlayer newSimpleInstance(Context context, TrackSelector t

/**
* Creates a {@link SimpleExoPlayer} instance. Must be called from a thread that has an associated
* {@link Looper}.
* {@link Looper}. Available extension renderers are not used.
*
* @param context A {@link Context}.
* @param trackSelector The {@link TrackSelector} that will be used by the instance.
Expand All @@ -59,7 +59,8 @@ public static SimpleExoPlayer newSimpleInstance(Context context, TrackSelector t
*/
public static SimpleExoPlayer newSimpleInstance(Context context, TrackSelector trackSelector,
LoadControl loadControl, DrmSessionManager<FrameworkMediaCrypto> drmSessionManager) {
return newSimpleInstance(context, trackSelector, loadControl, drmSessionManager, false);
return newSimpleInstance(context, trackSelector, loadControl,
drmSessionManager, SimpleExoPlayer.EXTENSION_RENDERER_MODE_OFF);
}

/**
Expand All @@ -71,15 +72,15 @@ public static SimpleExoPlayer newSimpleInstance(Context context, TrackSelector t
* @param loadControl The {@link LoadControl} that will be used by the instance.
* @param drmSessionManager An optional {@link DrmSessionManager}. May be null if the instance
* will not be used for DRM protected playbacks.
* @param preferExtensionDecoders True to prefer {@link Renderer} instances defined in
* available extensions over those defined in the core library. Note that extensions must be
* included in the application build for setting this flag to have any effect.
* @param extensionRendererMode The extension renderer mode, which determines if and how available
* extension renderers are used. Note that extensions must be included in the application
* build for them to be considered available.
*/
public static SimpleExoPlayer newSimpleInstance(Context context, TrackSelector trackSelector,
LoadControl loadControl, DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
boolean preferExtensionDecoders) {
@SimpleExoPlayer.ExtensionRendererMode int extensionRendererMode) {
return newSimpleInstance(context, trackSelector, loadControl, drmSessionManager,
preferExtensionDecoders, DEFAULT_ALLOWED_VIDEO_JOINING_TIME_MS);
extensionRendererMode, DEFAULT_ALLOWED_VIDEO_JOINING_TIME_MS);
}

/**
Expand All @@ -91,17 +92,18 @@ public static SimpleExoPlayer newSimpleInstance(Context context, TrackSelector t
* @param loadControl The {@link LoadControl} that will be used by the instance.
* @param drmSessionManager An optional {@link DrmSessionManager}. May be null if the instance
* will not be used for DRM protected playbacks.
* @param preferExtensionDecoders True to prefer {@link Renderer} instances defined in
* available extensions over those defined in the core library. Note that extensions must be
* included in the application build for setting this flag to have any effect.
* @param extensionRendererMode The extension renderer mode, which determines if and how available
* extension renderers are used. Note that extensions must be included in the application
* build for them to be considered available.
* @param allowedVideoJoiningTimeMs The maximum duration for which a video renderer can attempt to
* seamlessly join an ongoing playback.
*/
public static SimpleExoPlayer newSimpleInstance(Context context, TrackSelector trackSelector,
LoadControl loadControl, DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
boolean preferExtensionDecoders, long allowedVideoJoiningTimeMs) {
@SimpleExoPlayer.ExtensionRendererMode int extensionRendererMode,
long allowedVideoJoiningTimeMs) {
return new SimpleExoPlayer(context, trackSelector, loadControl, drmSessionManager,
preferExtensionDecoders, allowedVideoJoiningTimeMs);
extensionRendererMode, allowedVideoJoiningTimeMs);
}

/**
Expand Down
Loading

0 comments on commit 894ae1a

Please sign in to comment.