-
Notifications
You must be signed in to change notification settings - Fork 28
ALL-3936/Player Builder #57
Changes from 5 commits
604c7b7
6a0f17d
678e07d
48a6e98
2c87f0d
2b09917
5688de5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,22 +7,20 @@ | |
class SecurityDowngradingCodecSelector implements MediaCodecSelector { | ||
|
||
private final InternalMediaCodecUtil internalMediaCodecUtil; | ||
private final boolean downgradeSecureDecoder; | ||
|
||
public static SecurityDowngradingCodecSelector newInstance(boolean downgradeSecureDecoder) { | ||
public static SecurityDowngradingCodecSelector newInstance() { | ||
InternalMediaCodecUtil internalMediaCodecUtil = new InternalMediaCodecUtil(); | ||
return new SecurityDowngradingCodecSelector(internalMediaCodecUtil, downgradeSecureDecoder); | ||
return new SecurityDowngradingCodecSelector(internalMediaCodecUtil); | ||
} | ||
|
||
SecurityDowngradingCodecSelector(InternalMediaCodecUtil internalMediaCodecUtil, boolean downgradeSecureDecoder) { | ||
SecurityDowngradingCodecSelector(InternalMediaCodecUtil internalMediaCodecUtil) { | ||
this.internalMediaCodecUtil = internalMediaCodecUtil; | ||
this.downgradeSecureDecoder = downgradeSecureDecoder; | ||
} | ||
|
||
@Override | ||
public MediaCodecInfo getDecoderInfo(String mimeType, boolean contentRequiresSecureDecoder) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't notice it was from the exoplayer one, ok then 👍 |
||
throws MediaCodecUtil.DecoderQueryException { | ||
return internalMediaCodecUtil.getDecoderInfo(mimeType, contentRequiresSecureDecoder && !downgradeSecureDecoder); | ||
return internalMediaCodecUtil.getDecoderInfo(mimeType, false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you extract that boolean? I have no idea what's false there :P |
||
} | ||
|
||
@Override | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.novoda.noplayer.player; | ||
|
||
import android.content.Context; | ||
|
||
import com.novoda.noplayer.Player; | ||
import com.novoda.noplayer.drm.DrmHandler; | ||
import com.novoda.noplayer.drm.DrmType; | ||
import com.novoda.noplayer.exoplayer.NoPlayerExoPlayerCreator; | ||
import com.novoda.noplayer.exoplayer.drm.DrmSessionCreator; | ||
import com.novoda.noplayer.exoplayer.drm.DrmSessionCreatorFactory; | ||
import com.novoda.noplayer.mediaplayer.NoPlayerMediaPlayerCreator; | ||
|
||
class NoPlayerCreator { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the old |
||
|
||
private final Context context; | ||
private final PrioritizedPlayerTypes prioritizedPlayerTypes; | ||
private final NoPlayerExoPlayerCreator noPlayerExoPlayerCreator; | ||
private final NoPlayerMediaPlayerCreator noPlayerMediaPlayerCreator; | ||
private final DrmSessionCreatorFactory drmSessionCreatorFactory; | ||
|
||
NoPlayerCreator(Context context, | ||
PrioritizedPlayerTypes prioritizedPlayerTypes, | ||
NoPlayerExoPlayerCreator noPlayerExoPlayerCreator, | ||
NoPlayerMediaPlayerCreator noPlayerMediaPlayerCreator, | ||
DrmSessionCreatorFactory drmSessionCreatorFactory) { | ||
this.context = context; | ||
this.prioritizedPlayerTypes = prioritizedPlayerTypes; | ||
this.noPlayerExoPlayerCreator = noPlayerExoPlayerCreator; | ||
this.noPlayerMediaPlayerCreator = noPlayerMediaPlayerCreator; | ||
this.drmSessionCreatorFactory = drmSessionCreatorFactory; | ||
} | ||
|
||
Player create(DrmType drmType, DrmHandler drmHandler, boolean downgradeSecureDecoder) { | ||
for (PlayerType player : prioritizedPlayerTypes) { | ||
if (player.supports(drmType)) { | ||
return createPlayerForType(player, drmType, drmHandler, downgradeSecureDecoder); | ||
} | ||
} | ||
throw UnableToCreatePlayerException.unhandledDrmType(drmType); | ||
} | ||
|
||
private Player createPlayerForType(PlayerType playerType, DrmType drmType, DrmHandler drmHandler, boolean downgradeSecureDecoder) { | ||
switch (playerType) { | ||
case MEDIA_PLAYER: | ||
return noPlayerMediaPlayerCreator.createMediaPlayer(context); | ||
case EXO_PLAYER: | ||
DrmSessionCreator drmSessionCreator = drmSessionCreatorFactory.createFor(drmType, drmHandler); | ||
return noPlayerExoPlayerCreator.createExoPlayer(context, drmSessionCreator, downgradeSecureDecoder); | ||
default: | ||
throw UnableToCreatePlayerException.unhandledPlayerType(playerType); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.novoda.noplayer.player; | ||
|
||
import android.content.Context; | ||
import android.os.Handler; | ||
import android.os.Looper; | ||
|
||
import com.novoda.noplayer.Player; | ||
import com.novoda.noplayer.drm.DownloadedModularDrm; | ||
import com.novoda.noplayer.drm.DrmHandler; | ||
import com.novoda.noplayer.drm.DrmType; | ||
import com.novoda.noplayer.drm.StreamingModularDrm; | ||
import com.novoda.noplayer.exoplayer.NoPlayerExoPlayerCreator; | ||
import com.novoda.noplayer.exoplayer.drm.DrmSessionCreatorFactory; | ||
import com.novoda.noplayer.mediaplayer.NoPlayerMediaPlayerCreator; | ||
import com.novoda.utils.AndroidDeviceVersion; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class PlayerBuilder { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
private DrmType drmType = DrmType.NONE; | ||
private DrmHandler drmHandler = DrmHandler.NO_DRM; | ||
private PrioritizedPlayerTypes prioritizedPlayerTypes = PrioritizedPlayerTypes.prioritizeExoPlayer(); | ||
private boolean downgradeSecureDecoder = false; | ||
|
||
public PlayerBuilder withWidevineClassicDrm() { | ||
return withDrm(DrmType.WIDEVINE_CLASSIC, DrmHandler.NO_DRM); | ||
} | ||
|
||
public PlayerBuilder withWidevineModularStreamingDrm(StreamingModularDrm streamingModularDrm) { | ||
return withDrm(DrmType.WIDEVINE_MODULAR_STREAM, streamingModularDrm); | ||
} | ||
|
||
public PlayerBuilder withWidevineModularDownloadDrm(DownloadedModularDrm downloadedModularDrm) { | ||
return withDrm(DrmType.WIDEVINE_MODULAR_DOWNLOAD, downloadedModularDrm); | ||
} | ||
|
||
public PlayerBuilder withDrm(DrmType drmType, DrmHandler drmHandler) { | ||
this.drmType = drmType; | ||
this.drmHandler = drmHandler; | ||
return this; | ||
} | ||
|
||
public PlayerBuilder withPriority(PlayerType playerType, PlayerType... playerTypes) { | ||
List<PlayerType> types = new ArrayList<>(); | ||
types.add(playerType); | ||
types.addAll(Arrays.asList(playerTypes)); | ||
prioritizedPlayerTypes = new PrioritizedPlayerTypes(types); | ||
return this; | ||
} | ||
|
||
public PlayerBuilder withDowngradedSecureDecoder() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
downgradeSecureDecoder = true; | ||
return this; | ||
} | ||
|
||
public Player build(Context context) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as a user of the library I can still use Is this intentional? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see how to avoid this without flattening all the packages 😢 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😢 I have taken a look and I don't see either There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I don't think it's problem or enough of a reason to flatten the entire library. There's no issue or side effects of a client creating a single player directly via the public player creators, if anything it's an architectural feature. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed offline, we'll expose these creators as part of the public API |
||
Handler handler = new Handler(Looper.getMainLooper()); | ||
DrmSessionCreatorFactory drmSessionCreatorFactory = new DrmSessionCreatorFactory(AndroidDeviceVersion.newInstance(), handler); | ||
NoPlayerCreator noPlayerCreator = new NoPlayerCreator( | ||
context, | ||
prioritizedPlayerTypes, | ||
NoPlayerExoPlayerCreator.newInstance(handler), | ||
NoPlayerMediaPlayerCreator.newInstance(handler), | ||
drmSessionCreatorFactory | ||
); | ||
return noPlayerCreator.create(drmType, drmHandler, downgradeSecureDecoder); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
boolean downgradeSecureDecoder
is transformed into the associatedMediaCodecSelector
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@joetimmins the boolean now lives on
PlayerBuilder
->NoPlayerCreator
and finally here where it gets converted to the codec selector