@24i/smartapps-bigscreen-rnv-build-engine 0.17.2-alpha.2165 → 0.17.2-alpha.2166
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
package com.twentyfouri.tvbridge.global.utils
|
|
2
|
-
|
|
3
|
-
import android.net.Uri
|
|
4
|
-
import android.text.TextUtils
|
|
5
|
-
import android.util.Base64
|
|
6
|
-
import android.util.Log
|
|
7
|
-
import com.google.android.exoplayer2.C
|
|
8
|
-
import com.google.android.exoplayer2.drm.ExoMediaDrm
|
|
9
|
-
import com.google.android.exoplayer2.upstream.DataSourceInputStream
|
|
10
|
-
import com.google.android.exoplayer2.upstream.DataSpec
|
|
11
|
-
import com.google.android.exoplayer2.upstream.HttpDataSource
|
|
12
|
-
import com.google.android.exoplayer2.util.Assertions
|
|
13
|
-
import com.google.android.exoplayer2.util.Util
|
|
14
|
-
import com.twentyfouri.smartexoplayer.drm.SmartMediaDrmCallback
|
|
15
|
-
import com.twentyfouri.smartexoplayer.model.DrmConfiguration
|
|
16
|
-
import com.twentyfouri.tvbridge.BuildConfig
|
|
17
|
-
import org.json.JSONException
|
|
18
|
-
import org.json.JSONObject
|
|
19
|
-
import java.io.BufferedReader
|
|
20
|
-
import java.io.IOException
|
|
21
|
-
import java.io.InputStreamReader
|
|
22
|
-
import java.net.MalformedURLException
|
|
23
|
-
import java.net.URL
|
|
24
|
-
import java.net.URLEncoder
|
|
25
|
-
import java.util.HashMap
|
|
26
|
-
import java.util.UUID
|
|
27
|
-
|
|
28
|
-
class HttpMediaDrmCallback(
|
|
29
|
-
private val defaultLicenseUrl: String?,
|
|
30
|
-
private val forceDefaultLicenseUrl: Boolean,
|
|
31
|
-
private val dataSourceFactory: HttpDataSource.Factory
|
|
32
|
-
) : SmartMediaDrmCallback {
|
|
33
|
-
|
|
34
|
-
private val keyRequestProperties = HashMap<String, String>()
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* @param defaultLicenseUrl The default license URL. Used for key requests that do not specify
|
|
38
|
-
* their own license URL.
|
|
39
|
-
* @param dataSourceFactory A factory from which to obtain [HttpDataSource] instances.
|
|
40
|
-
*/
|
|
41
|
-
constructor(defaultLicenseUrl: String, dataSourceFactory: HttpDataSource.Factory) : this(defaultLicenseUrl, false, dataSourceFactory) {}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Sets a header for key requests made by the callback.
|
|
45
|
-
*
|
|
46
|
-
* @param name The name of the header field.
|
|
47
|
-
* @param value The value of the field.
|
|
48
|
-
*/
|
|
49
|
-
override fun setKeyRequestProperty(name: String, value: String) {
|
|
50
|
-
Log.d(TAG, "setKeyRequestProperty")
|
|
51
|
-
Assertions.checkNotNull(name)
|
|
52
|
-
Assertions.checkNotNull(value)
|
|
53
|
-
synchronized(keyRequestProperties) { keyRequestProperties.put(name, value) }
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Clears a header for key requests made by the callback.
|
|
58
|
-
*
|
|
59
|
-
* @param name The name of the header field.
|
|
60
|
-
*/
|
|
61
|
-
override fun clearKeyRequestProperty(name: String) {
|
|
62
|
-
Log.d(TAG, "clearKeyRequestProperty")
|
|
63
|
-
Assertions.checkNotNull(name)
|
|
64
|
-
synchronized(keyRequestProperties) { keyRequestProperties.remove(name) }
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Clears all headers for key requests made by the callback.
|
|
69
|
-
*/
|
|
70
|
-
override fun clearAllKeyRequestProperties() {
|
|
71
|
-
Log.d(TAG, "clearAllKeyRequestProperties")
|
|
72
|
-
synchronized(keyRequestProperties) { keyRequestProperties.clear() }
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
@Throws(IOException::class)
|
|
76
|
-
override fun executeProvisionRequest(uuid: UUID, request: ExoMediaDrm.ProvisionRequest): ByteArray {
|
|
77
|
-
Log.d(TAG, "executeProvisionRequest")
|
|
78
|
-
val url = request.defaultUrl + "&signedRequest=" + String(request.data)
|
|
79
|
-
return executePost(dataSourceFactory, url, ByteArray(0), null)
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
@Throws(Exception::class)
|
|
83
|
-
override fun executeKeyRequest(uuid: UUID, request: ExoMediaDrm.KeyRequest): ByteArray {
|
|
84
|
-
Log.d(TAG, "executeKeyRequest")
|
|
85
|
-
var url: String? = request.licenseServerUrl
|
|
86
|
-
if (forceDefaultLicenseUrl || url.isNullOrEmpty()) {
|
|
87
|
-
url = defaultLicenseUrl
|
|
88
|
-
}
|
|
89
|
-
val requestProperties: MutableMap<String, String> = HashMap()
|
|
90
|
-
// Add standard request properties for supported schemes.
|
|
91
|
-
val contentType = "text/plain"
|
|
92
|
-
requestProperties["Content-Type"] = contentType
|
|
93
|
-
if (C.PLAYREADY_UUID == uuid) {
|
|
94
|
-
requestProperties["SOAPAction"] = "http://schemas.microsoft.com/DRM/2007/03/protocols/AcquireLicense"
|
|
95
|
-
}
|
|
96
|
-
// Add additional request properties.
|
|
97
|
-
synchronized(keyRequestProperties) { requestProperties.putAll(keyRequestProperties) }
|
|
98
|
-
|
|
99
|
-
//adding data to url
|
|
100
|
-
val challenge = request.data
|
|
101
|
-
val encoded = URLEncoder.encode(Base64.encodeToString(challenge, Base64.NO_WRAP), "UTF-8")
|
|
102
|
-
url = appendQuery(url, "_widevineChallenge=$encoded")
|
|
103
|
-
if (BuildConfig.DEBUG) {
|
|
104
|
-
Log.d(TAG, "Executing post on url $url with content type $contentType")
|
|
105
|
-
}
|
|
106
|
-
return executeGet(url)
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
class Factory(
|
|
110
|
-
private val licenseUrl: String?,
|
|
111
|
-
private val forceDefaultUrl: Boolean
|
|
112
|
-
) : SmartMediaDrmCallback.Factory {
|
|
113
|
-
override fun build(drm: DrmConfiguration, dataSourceFactory: HttpDataSource.Factory): SmartMediaDrmCallback =
|
|
114
|
-
HttpMediaDrmCallback(licenseUrl, forceDefaultUrl, dataSourceFactory)
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
companion object {
|
|
118
|
-
private const val TAG = "DrmCallback"
|
|
119
|
-
|
|
120
|
-
private fun executeGet(urlString: String): ByteArray {
|
|
121
|
-
var licenserRequest: URL? = null
|
|
122
|
-
try {
|
|
123
|
-
licenserRequest = URL(urlString)
|
|
124
|
-
val yc = licenserRequest.openConnection()
|
|
125
|
-
val input = BufferedReader(InputStreamReader(yc.getInputStream()))
|
|
126
|
-
val builder = StringBuilder()
|
|
127
|
-
var inputLine: String?
|
|
128
|
-
while (input.readLine().also { inputLine = it } != null) {
|
|
129
|
-
builder.append(inputLine)
|
|
130
|
-
}
|
|
131
|
-
input.close()
|
|
132
|
-
val jsonObject = JSONObject(builder.toString())
|
|
133
|
-
val container = jsonObject.getJSONObject("getWidevineLicenseResponse")
|
|
134
|
-
val license = container.getString("license")
|
|
135
|
-
if (BuildConfig.DEBUG) {
|
|
136
|
-
Log.d(TAG, "Finished post: $license")
|
|
137
|
-
}
|
|
138
|
-
return Base64.decode(license, Base64.NO_WRAP)
|
|
139
|
-
} catch (e: MalformedURLException) {
|
|
140
|
-
e.printStackTrace()
|
|
141
|
-
} catch (e: IOException) {
|
|
142
|
-
e.printStackTrace()
|
|
143
|
-
} catch (e: JSONException) {
|
|
144
|
-
e.printStackTrace()
|
|
145
|
-
}
|
|
146
|
-
return byteArrayOf()
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
@Throws(IOException::class)
|
|
150
|
-
private fun executePost(
|
|
151
|
-
dataSourceFactory: HttpDataSource.Factory,
|
|
152
|
-
url: String,
|
|
153
|
-
data: ByteArray,
|
|
154
|
-
requestProperties: Map<String, String>?
|
|
155
|
-
): ByteArray {
|
|
156
|
-
Log.d(TAG, "executePost")
|
|
157
|
-
val dataSource = dataSourceFactory.createDataSource()
|
|
158
|
-
if (requestProperties != null) {
|
|
159
|
-
for ((key, value) in requestProperties) {
|
|
160
|
-
dataSource.setRequestProperty(key, value)
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
val dataSpec = DataSpec(Uri.parse(url), data, 0, 0, C.LENGTH_UNSET.toLong(), null,
|
|
164
|
-
DataSpec.FLAG_ALLOW_GZIP)
|
|
165
|
-
val inputStream = DataSourceInputStream(dataSource, dataSpec)
|
|
166
|
-
return try {
|
|
167
|
-
Util.toByteArray(inputStream)
|
|
168
|
-
} finally {
|
|
169
|
-
Util.closeQuietly(inputStream)
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
fun appendQuery(url: String?, appendQuery: String): String {
|
|
174
|
-
val oldUri = Uri.parse(url)
|
|
175
|
-
var newQuery = oldUri.query
|
|
176
|
-
if (newQuery == null) {
|
|
177
|
-
newQuery = appendQuery
|
|
178
|
-
} else {
|
|
179
|
-
newQuery += "&$appendQuery"
|
|
180
|
-
}
|
|
181
|
-
return oldUri.scheme + "://" + oldUri.authority + oldUri.path + "?" + newQuery
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|