-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Chore(android): refactor drm props #3846
Changes from all commits
d3fc4fd
e1da32d
df3da43
0f33ad1
17f2385
1066898
485f867
a5e10a3
9ce1d95
fa27db7
be681d3
2fadb26
92df10d
aa61388
41e2577
755b834
dc12ff8
cdb77e5
25eaedb
1e155fc
8b0e2a6
3f37e6d
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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.brentvatne.common.api | ||
|
||
import com.brentvatne.common.toolbox.ReactBridgeUtils.safeGetArray | ||
import com.brentvatne.common.toolbox.ReactBridgeUtils.safeGetString | ||
import com.facebook.react.bridge.ReadableMap | ||
import java.util.UUID | ||
|
||
/** | ||
* Class representing DRM props for host. | ||
* Only generic code here, no reference to the player. | ||
*/ | ||
class DRMProps { | ||
/** | ||
* string version of configured UUID for drm prop | ||
*/ | ||
var drmType: String? = null | ||
|
||
/** | ||
* Configured UUID for drm prop | ||
*/ | ||
var drmUUID: UUID? = null | ||
|
||
/** | ||
* DRM license server to be used | ||
*/ | ||
var drmLicenseServer: String? = null | ||
|
||
/** | ||
* DRM Http Header to access to license server | ||
*/ | ||
var drmLicenseHeader: Array<String> = emptyArray<String>() | ||
companion object { | ||
private const val PROP_DRM_TYPE = "type" | ||
private const val PROP_DRM_LICENSE_SERVER = "licenseServer" | ||
private const val PROP_DRM_HEADERS = "headers" | ||
private const val PROP_DRM_HEADERS_KEY = "key" | ||
private const val PROP_DRM_HEADERS_VALUE = "value" | ||
|
||
/** parse the source ReadableMap received from app */ | ||
@JvmStatic | ||
fun parse(src: ReadableMap?): DRMProps? { | ||
var drm: DRMProps? = null | ||
if (src != null && src.hasKey(PROP_DRM_TYPE)) { | ||
drm = DRMProps() | ||
drm.drmType = safeGetString(src, PROP_DRM_TYPE) | ||
drm.drmLicenseServer = safeGetString(src, PROP_DRM_LICENSE_SERVER) | ||
val drmHeadersArray = safeGetArray(src, PROP_DRM_HEADERS) | ||
if (drm.drmType != null && drm.drmLicenseServer != null) { | ||
if (drmHeadersArray != null) { | ||
val drmKeyRequestPropertiesList = ArrayList<String?>() | ||
for (i in 0 until drmHeadersArray.size()) { | ||
val current = drmHeadersArray.getMap(i) | ||
drmKeyRequestPropertiesList.add(safeGetString(current, PROP_DRM_HEADERS_KEY)) | ||
drmKeyRequestPropertiesList.add(safeGetString(current, PROP_DRM_HEADERS_VALUE)) | ||
} | ||
val array = emptyArray<String>() | ||
drm.drmLicenseHeader = drmKeyRequestPropertiesList.toArray(array) | ||
} | ||
} else { | ||
return null | ||
} | ||
} | ||
return drm | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
import com.brentvatne.common.api.BufferConfig; | ||
import com.brentvatne.common.api.BufferingStrategy; | ||
import com.brentvatne.common.api.ControlsConfig; | ||
import com.brentvatne.common.api.DRMProps; | ||
import com.brentvatne.common.api.ResizeMode; | ||
import com.brentvatne.common.api.SideLoadedTextTrackList; | ||
import com.brentvatne.common.api.Source; | ||
|
@@ -39,9 +40,7 @@ public class ReactExoplayerViewManager extends ViewGroupManager<ReactExoplayerVi | |
private static final String PROP_SRC = "src"; | ||
private static final String PROP_AD_TAG_URL = "adTagUrl"; | ||
private static final String PROP_DRM = "drm"; | ||
private static final String PROP_DRM_TYPE = "type"; | ||
private static final String PROP_DRM_LICENSE_SERVER = "licenseServer"; | ||
private static final String PROP_DRM_HEADERS = "headers"; | ||
private static final String PROP_SRC_HEADERS = "requestHeaders"; | ||
private static final String PROP_RESIZE_MODE = "resizeMode"; | ||
private static final String PROP_REPEAT = "repeat"; | ||
private static final String PROP_SELECTED_AUDIO_TRACK = "selectedAudioTrack"; | ||
|
@@ -117,28 +116,9 @@ public void onDropViewInstance(ReactExoplayerView view) { | |
|
||
@ReactProp(name = PROP_DRM) | ||
public void setDRM(final ReactExoplayerView videoView, @Nullable ReadableMap drm) { | ||
if (drm != null && drm.hasKey(PROP_DRM_TYPE)) { | ||
String drmType = ReactBridgeUtils.safeGetString(drm, PROP_DRM_TYPE); | ||
String drmLicenseServer = ReactBridgeUtils.safeGetString(drm, PROP_DRM_LICENSE_SERVER); | ||
ReadableArray drmHeadersArray = ReactBridgeUtils.safeGetArray(drm, PROP_DRM_HEADERS); | ||
if (drmType != null && drmLicenseServer != null && Util.getDrmUuid(drmType) != null) { | ||
UUID drmUUID = Util.getDrmUuid(drmType); | ||
videoView.setDrmType(drmUUID); | ||
videoView.setDrmLicenseUrl(drmLicenseServer); | ||
if (drmHeadersArray != null) { | ||
ArrayList<String> drmKeyRequestPropertiesList = new ArrayList<>(); | ||
for (int i = 0; i < drmHeadersArray.size(); i++) { | ||
ReadableMap current = drmHeadersArray.getMap(i); | ||
String key = current.hasKey("key") ? current.getString("key") : null; | ||
String value = current.hasKey("value") ? current.getString("value") : null; | ||
drmKeyRequestPropertiesList.add(key); | ||
drmKeyRequestPropertiesList.add(value); | ||
} | ||
videoView.setDrmLicenseHeader(drmKeyRequestPropertiesList.toArray(new String[0])); | ||
} | ||
videoView.setUseTextureView(false); | ||
} | ||
} | ||
DRMProps drmProps = DRMProps.parse(drm); | ||
videoView.setDrm(drmProps); | ||
videoView.setUseTextureView(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. if drm props is null, we have to follow injected prop (useSecureView or useTextureView) 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. Yes you are right, thank you. I am also wondering if it can make sense to use Surface View by default? What is your opinion? 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 hard question. because it depends on what user using this library for Decision is yours🫡 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 am working to remove this videoView.setUseTextureView(false); I would prefer implement it in another way:
I will try to implement it, but I think we can merge this part now, and the next fix will come soon ! I propose to merge this PR as the setUseTextureView is already present in the code ! 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. @YangJonghun here is The patch I would to do for ensure we correctly reset the view state in the app: 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 apologize for late response. |
||
} | ||
|
||
@ReactProp(name = PROP_SRC) | ||
|
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.
I think above code could be moved inside the DrmProps.parse fn.
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.
I agree, but my problem with that is that I will have to import Utils from media3 in drmProp.kt. I really want to avoid including player specific code in the utils / data management classes ...
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.
I understand. but for that reason, it seems like parse function should be categorized in a different class. (for example, DRMUtils)
And I think removing dependencies from Utils seems hard to avoid because there's so much to prepare to implement as the SDK requires.🥲
If you worried deep dependencies, I recommend copying media3's implementation.
However, I'm not suggesting this because I think it's a serious issue, so you don't have to fix it.