Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
SDK
/
exoplayer
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
d8369571
authored
May 22, 2019
by
olly
Committed by
Toni
May 23, 2019
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Remove some DataSource implementations from nullness blacklist
PiperOrigin-RevId: 249419193
parent
a4d18a74
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
119 additions
and
64 deletions
library/core/src/main/java/com/google/android/exoplayer2/upstream/AssetDataSource.java
library/core/src/main/java/com/google/android/exoplayer2/upstream/ByteArrayDataSink.java
library/core/src/main/java/com/google/android/exoplayer2/upstream/ByteArrayDataSource.java
library/core/src/main/java/com/google/android/exoplayer2/upstream/ContentDataSource.java
library/core/src/main/java/com/google/android/exoplayer2/upstream/DataSchemeDataSource.java
library/core/src/main/java/com/google/android/exoplayer2/upstream/DummyDataSource.java
library/core/src/main/java/com/google/android/exoplayer2/upstream/FileDataSource.java
library/core/src/main/java/com/google/android/exoplayer2/upstream/RawResourceDataSource.java
library/core/src/main/java/com/google/android/exoplayer2/upstream/UdpDataSource.java
library/core/src/main/java/com/google/android/exoplayer2/upstream/crypto/AesCipherDataSink.java
library/core/src/main/java/com/google/android/exoplayer2/upstream/crypto/AesCipherDataSource.java
library/core/src/main/java/com/google/android/exoplayer2/upstream/crypto/CryptoUtil.java
library/core/src/main/java/com/google/android/exoplayer2/upstream/AssetDataSource.java
View file @
d8369571
...
...
@@ -15,11 +15,14 @@
*/
package
com
.
google
.
android
.
exoplayer2
.
upstream
;
import
static
com
.
google
.
android
.
exoplayer2
.
util
.
Util
.
castNonNull
;
import
android.content.Context
;
import
android.content.res.AssetManager
;
import
android.net.Uri
;
import
androidx.annotation.Nullable
;
import
com.google.android.exoplayer2.C
;
import
com.google.android.exoplayer2.util.Assertions
;
import
java.io.EOFException
;
import
java.io.IOException
;
import
java.io.InputStream
;
...
...
@@ -40,8 +43,8 @@ public final class AssetDataSource extends BaseDataSource {
private
final
AssetManager
assetManager
;
private
@Nullabl
e
Uri
uri
;
private
@Nullabl
e
InputStream
inputStream
;
@Nullable
privat
e
Uri
uri
;
@Nullable
privat
e
InputStream
inputStream
;
private
long
bytesRemaining
;
private
boolean
opened
;
...
...
@@ -55,7 +58,7 @@ public final class AssetDataSource extends BaseDataSource {
public
long
open
(
DataSpec
dataSpec
)
throws
AssetDataSourceException
{
try
{
uri
=
dataSpec
.
uri
;
String
path
=
uri
.
getPath
(
);
String
path
=
Assertions
.
checkNotNull
(
uri
.
getPath
()
);
if
(
path
.
startsWith
(
"/android_asset/"
))
{
path
=
path
.
substring
(
15
);
}
else
if
(
path
.
startsWith
(
"/"
))
{
...
...
@@ -101,7 +104,7 @@ public final class AssetDataSource extends BaseDataSource {
try
{
int
bytesToRead
=
bytesRemaining
==
C
.
LENGTH_UNSET
?
readLength
:
(
int
)
Math
.
min
(
bytesRemaining
,
readLength
);
bytesRead
=
inputStream
.
read
(
buffer
,
offset
,
bytesToRead
);
bytesRead
=
castNonNull
(
inputStream
)
.
read
(
buffer
,
offset
,
bytesToRead
);
}
catch
(
IOException
e
)
{
throw
new
AssetDataSourceException
(
e
);
}
...
...
@@ -121,7 +124,8 @@ public final class AssetDataSource extends BaseDataSource {
}
@Override
public
@Nullable
Uri
getUri
()
{
@Nullable
public
Uri
getUri
()
{
return
uri
;
}
...
...
library/core/src/main/java/com/google/android/exoplayer2/upstream/ByteArrayDataSink.java
View file @
d8369571
...
...
@@ -15,20 +15,24 @@
*/
package
com
.
google
.
android
.
exoplayer2
.
upstream
;
import
static
com
.
google
.
android
.
exoplayer2
.
util
.
Util
.
castNonNull
;
import
androidx.annotation.Nullable
;
import
com.google.android.exoplayer2.C
;
import
com.google.android.exoplayer2.util.Assertions
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
org.checkerframework.checker.nullness.qual.MonotonicNonNull
;
/**
* A {@link DataSink} for writing to a byte array.
*/
public
final
class
ByteArrayDataSink
implements
DataSink
{
private
ByteArrayOutputStream
stream
;
@MonotonicNonNull
private
ByteArrayOutputStream
stream
;
@Override
public
void
open
(
DataSpec
dataSpec
)
throws
IOException
{
public
void
open
(
DataSpec
dataSpec
)
{
if
(
dataSpec
.
length
==
C
.
LENGTH_UNSET
)
{
stream
=
new
ByteArrayOutputStream
();
}
else
{
...
...
@@ -39,18 +43,19 @@ public final class ByteArrayDataSink implements DataSink {
@Override
public
void
close
()
throws
IOException
{
stream
.
close
();
castNonNull
(
stream
)
.
close
();
}
@Override
public
void
write
(
byte
[]
buffer
,
int
offset
,
int
length
)
throws
IOException
{
stream
.
write
(
buffer
,
offset
,
length
);
public
void
write
(
byte
[]
buffer
,
int
offset
,
int
length
)
{
castNonNull
(
stream
)
.
write
(
buffer
,
offset
,
length
);
}
/**
* Returns the data written to the sink since the last call to {@link #open(DataSpec)}, or null if
* {@link #open(DataSpec)} has never been called.
*/
@Nullable
public
byte
[]
getData
()
{
return
stream
==
null
?
null
:
stream
.
toByteArray
();
}
...
...
library/core/src/main/java/com/google/android/exoplayer2/upstream/ByteArrayDataSource.java
View file @
d8369571
...
...
@@ -26,7 +26,7 @@ public final class ByteArrayDataSource extends BaseDataSource {
private
final
byte
[]
data
;
private
@Nullabl
e
Uri
uri
;
@Nullable
privat
e
Uri
uri
;
private
int
readPosition
;
private
int
bytesRemaining
;
private
boolean
opened
;
...
...
@@ -58,7 +58,7 @@ public final class ByteArrayDataSource extends BaseDataSource {
}
@Override
public
int
read
(
byte
[]
buffer
,
int
offset
,
int
readLength
)
throws
IOException
{
public
int
read
(
byte
[]
buffer
,
int
offset
,
int
readLength
)
{
if
(
readLength
==
0
)
{
return
0
;
}
else
if
(
bytesRemaining
==
0
)
{
...
...
@@ -74,12 +74,13 @@ public final class ByteArrayDataSource extends BaseDataSource {
}
@Override
public
@Nullable
Uri
getUri
()
{
@Nullable
public
Uri
getUri
()
{
return
uri
;
}
@Override
public
void
close
()
throws
IOException
{
public
void
close
()
{
if
(
opened
)
{
opened
=
false
;
transferEnded
();
...
...
library/core/src/main/java/com/google/android/exoplayer2/upstream/ContentDataSource.java
View file @
d8369571
...
...
@@ -15,6 +15,8 @@
*/
package
com
.
google
.
android
.
exoplayer2
.
upstream
;
import
static
com
.
google
.
android
.
exoplayer2
.
util
.
Util
.
castNonNull
;
import
android.content.ContentResolver
;
import
android.content.Context
;
import
android.content.res.AssetFileDescriptor
;
...
...
@@ -43,9 +45,9 @@ public final class ContentDataSource extends BaseDataSource {
private
final
ContentResolver
resolver
;
private
@Nullabl
e
Uri
uri
;
private
@Nullabl
e
AssetFileDescriptor
assetFileDescriptor
;
private
@Nullabl
e
FileInputStream
inputStream
;
@Nullable
privat
e
Uri
uri
;
@Nullable
privat
e
AssetFileDescriptor
assetFileDescriptor
;
@Nullable
privat
e
FileInputStream
inputStream
;
private
long
bytesRemaining
;
private
boolean
opened
;
...
...
@@ -60,13 +62,18 @@ public final class ContentDataSource extends BaseDataSource {
@Override
public
long
open
(
DataSpec
dataSpec
)
throws
ContentDataSourceException
{
try
{
uri
=
dataSpec
.
uri
;
Uri
uri
=
dataSpec
.
uri
;
this
.
uri
=
uri
;
transferInitializing
(
dataSpec
);
assetFileDescriptor
=
resolver
.
openAssetFileDescriptor
(
uri
,
"r"
);
AssetFileDescriptor
assetFileDescriptor
=
resolver
.
openAssetFileDescriptor
(
uri
,
"r"
);
this
.
assetFileDescriptor
=
assetFileDescriptor
;
if
(
assetFileDescriptor
==
null
)
{
throw
new
FileNotFoundException
(
"Could not open file descriptor for: "
+
uri
);
}
inputStream
=
new
FileInputStream
(
assetFileDescriptor
.
getFileDescriptor
());
FileInputStream
inputStream
=
new
FileInputStream
(
assetFileDescriptor
.
getFileDescriptor
());
this
.
inputStream
=
inputStream
;
long
assetStartOffset
=
assetFileDescriptor
.
getStartOffset
();
long
skipped
=
inputStream
.
skip
(
assetStartOffset
+
dataSpec
.
position
)
-
assetStartOffset
;
if
(
skipped
!=
dataSpec
.
position
)
{
...
...
@@ -110,7 +117,7 @@ public final class ContentDataSource extends BaseDataSource {
try
{
int
bytesToRead
=
bytesRemaining
==
C
.
LENGTH_UNSET
?
readLength
:
(
int
)
Math
.
min
(
bytesRemaining
,
readLength
);
bytesRead
=
inputStream
.
read
(
buffer
,
offset
,
bytesToRead
);
bytesRead
=
castNonNull
(
inputStream
)
.
read
(
buffer
,
offset
,
bytesToRead
);
}
catch
(
IOException
e
)
{
throw
new
ContentDataSourceException
(
e
);
}
...
...
@@ -130,7 +137,8 @@ public final class ContentDataSource extends BaseDataSource {
}
@Override
public
@Nullable
Uri
getUri
()
{
@Nullable
public
Uri
getUri
()
{
return
uri
;
}
...
...
library/core/src/main/java/com/google/android/exoplayer2/upstream/DataSchemeDataSource.java
View file @
d8369571
...
...
@@ -15,6 +15,8 @@
*/
package
com
.
google
.
android
.
exoplayer2
.
upstream
;
import
static
com
.
google
.
android
.
exoplayer2
.
util
.
Util
.
castNonNull
;
import
android.net.Uri
;
import
androidx.annotation.Nullable
;
import
android.util.Base64
;
...
...
@@ -29,9 +31,10 @@ public final class DataSchemeDataSource extends BaseDataSource {
public
static
final
String
SCHEME_DATA
=
"data"
;
private
@Nullable
DataSpec
dataSpec
;
@Nullable
private
DataSpec
dataSpec
;
@Nullable
private
byte
[]
data
;
private
int
dataLength
;
private
int
bytesRead
;
private
@Nullable
byte
[]
data
;
public
DataSchemeDataSource
()
{
super
(
/* isNetwork= */
false
);
...
...
@@ -54,15 +57,17 @@ public final class DataSchemeDataSource extends BaseDataSource {
if
(
uriParts
[
0
].
contains
(
";base64"
))
{
try
{
data
=
Base64
.
decode
(
dataString
,
0
);
dataLength
=
data
.
length
;
}
catch
(
IllegalArgumentException
e
)
{
throw
new
ParserException
(
"Error while parsing Base64 encoded string: "
+
dataString
,
e
);
}
}
else
{
// TODO: Add support for other charsets.
data
=
Util
.
getUtf8Bytes
(
URLDecoder
.
decode
(
dataString
,
C
.
ASCII_NAME
));
dataLength
=
data
.
length
;
}
transferStarted
(
dataSpec
);
return
data
.
l
ength
;
return
data
L
ength
;
}
@Override
...
...
@@ -70,19 +75,20 @@ public final class DataSchemeDataSource extends BaseDataSource {
if
(
readLength
==
0
)
{
return
0
;
}
int
remainingBytes
=
data
.
l
ength
-
bytesRead
;
int
remainingBytes
=
data
L
ength
-
bytesRead
;
if
(
remainingBytes
==
0
)
{
return
C
.
RESULT_END_OF_INPUT
;
}
readLength
=
Math
.
min
(
readLength
,
remainingBytes
);
System
.
arraycopy
(
data
,
bytesRead
,
buffer
,
offset
,
readLength
);
System
.
arraycopy
(
castNonNull
(
data
)
,
bytesRead
,
buffer
,
offset
,
readLength
);
bytesRead
+=
readLength
;
bytesTransferred
(
readLength
);
return
readLength
;
}
@Override
public
@Nullable
Uri
getUri
()
{
@Nullable
public
Uri
getUri
()
{
return
dataSpec
!=
null
?
dataSpec
.
uri
:
null
;
}
...
...
library/core/src/main/java/com/google/android/exoplayer2/upstream/DummyDataSource.java
View file @
d8369571
...
...
@@ -42,17 +42,18 @@ public final class DummyDataSource implements DataSource {
}
@Override
public
int
read
(
byte
[]
buffer
,
int
offset
,
int
readLength
)
throws
IOException
{
public
int
read
(
byte
[]
buffer
,
int
offset
,
int
readLength
)
{
throw
new
UnsupportedOperationException
();
}
@Override
public
@Nullable
Uri
getUri
()
{
@Nullable
public
Uri
getUri
()
{
return
null
;
}
@Override
public
void
close
()
throws
IOException
{
public
void
close
()
{
// do nothing.
}
}
library/core/src/main/java/com/google/android/exoplayer2/upstream/FileDataSource.java
View file @
d8369571
...
...
@@ -15,9 +15,12 @@
*/
package
com
.
google
.
android
.
exoplayer2
.
upstream
;
import
static
com
.
google
.
android
.
exoplayer2
.
util
.
Util
.
castNonNull
;
import
android.net.Uri
;
import
androidx.annotation.Nullable
;
import
com.google.android.exoplayer2.C
;
import
com.google.android.exoplayer2.util.Assertions
;
import
java.io.EOFException
;
import
java.io.IOException
;
import
java.io.RandomAccessFile
;
...
...
@@ -36,8 +39,8 @@ public final class FileDataSource extends BaseDataSource {
}
private
@Nullabl
e
RandomAccessFile
file
;
private
@Nullabl
e
Uri
uri
;
@Nullable
privat
e
RandomAccessFile
file
;
@Nullable
privat
e
Uri
uri
;
private
long
bytesRemaining
;
private
boolean
opened
;
...
...
@@ -48,9 +51,13 @@ public final class FileDataSource extends BaseDataSource {
@Override
public
long
open
(
DataSpec
dataSpec
)
throws
FileDataSourceException
{
try
{
uri
=
dataSpec
.
uri
;
Uri
uri
=
dataSpec
.
uri
;
this
.
uri
=
uri
;
transferInitializing
(
dataSpec
);
file
=
new
RandomAccessFile
(
dataSpec
.
uri
.
getPath
(),
"r"
);
RandomAccessFile
file
=
new
RandomAccessFile
(
Assertions
.
checkNotNull
(
uri
.
getPath
()),
"r"
);
this
.
file
=
file
;
file
.
seek
(
dataSpec
.
position
);
bytesRemaining
=
dataSpec
.
length
==
C
.
LENGTH_UNSET
?
file
.
length
()
-
dataSpec
.
position
:
dataSpec
.
length
;
...
...
@@ -76,7 +83,8 @@ public final class FileDataSource extends BaseDataSource {
}
else
{
int
bytesRead
;
try
{
bytesRead
=
file
.
read
(
buffer
,
offset
,
(
int
)
Math
.
min
(
bytesRemaining
,
readLength
));
bytesRead
=
castNonNull
(
file
).
read
(
buffer
,
offset
,
(
int
)
Math
.
min
(
bytesRemaining
,
readLength
));
}
catch
(
IOException
e
)
{
throw
new
FileDataSourceException
(
e
);
}
...
...
@@ -91,7 +99,8 @@ public final class FileDataSource extends BaseDataSource {
}
@Override
public
@Nullable
Uri
getUri
()
{
@Nullable
public
Uri
getUri
()
{
return
uri
;
}
...
...
library/core/src/main/java/com/google/android/exoplayer2/upstream/RawResourceDataSource.java
View file @
d8369571
...
...
@@ -15,6 +15,8 @@
*/
package
com
.
google
.
android
.
exoplayer2
.
upstream
;
import
static
com
.
google
.
android
.
exoplayer2
.
util
.
Util
.
castNonNull
;
import
android.content.Context
;
import
android.content.res.AssetFileDescriptor
;
import
android.content.res.Resources
;
...
...
@@ -22,6 +24,7 @@ import android.net.Uri;
import
androidx.annotation.Nullable
;
import
android.text.TextUtils
;
import
com.google.android.exoplayer2.C
;
import
com.google.android.exoplayer2.util.Assertions
;
import
java.io.EOFException
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
...
...
@@ -64,9 +67,9 @@ public final class RawResourceDataSource extends BaseDataSource {
private
final
Resources
resources
;
private
@Nullabl
e
Uri
uri
;
private
@Nullabl
e
AssetFileDescriptor
assetFileDescriptor
;
private
@Nullabl
e
InputStream
inputStream
;
@Nullable
privat
e
Uri
uri
;
@Nullable
privat
e
AssetFileDescriptor
assetFileDescriptor
;
@Nullable
privat
e
InputStream
inputStream
;
private
long
bytesRemaining
;
private
boolean
opened
;
...
...
@@ -81,21 +84,28 @@ public final class RawResourceDataSource extends BaseDataSource {
@Override
public
long
open
(
DataSpec
dataSpec
)
throws
RawResourceDataSourceException
{
try
{
uri
=
dataSpec
.
uri
;
Uri
uri
=
dataSpec
.
uri
;
this
.
uri
=
uri
;
if
(!
TextUtils
.
equals
(
RAW_RESOURCE_SCHEME
,
uri
.
getScheme
()))
{
throw
new
RawResourceDataSourceException
(
"URI must use scheme "
+
RAW_RESOURCE_SCHEME
);
}
int
resourceId
;
try
{
resourceId
=
Integer
.
parseInt
(
uri
.
getLastPathSegment
(
));
resourceId
=
Integer
.
parseInt
(
Assertions
.
checkNotNull
(
uri
.
getLastPathSegment
()
));
}
catch
(
NumberFormatException
e
)
{
throw
new
RawResourceDataSourceException
(
"Resource identifier must be an integer."
);
}
transferInitializing
(
dataSpec
);
assetFileDescriptor
=
resources
.
openRawResourceFd
(
resourceId
);
inputStream
=
new
FileInputStream
(
assetFileDescriptor
.
getFileDescriptor
());
AssetFileDescriptor
assetFileDescriptor
=
resources
.
openRawResourceFd
(
resourceId
);
this
.
assetFileDescriptor
=
assetFileDescriptor
;
if
(
assetFileDescriptor
==
null
)
{
throw
new
RawResourceDataSourceException
(
"Resource is compressed: "
+
uri
);
}
FileInputStream
inputStream
=
new
FileInputStream
(
assetFileDescriptor
.
getFileDescriptor
());
this
.
inputStream
=
inputStream
;
inputStream
.
skip
(
assetFileDescriptor
.
getStartOffset
());
long
skipped
=
inputStream
.
skip
(
dataSpec
.
position
);
if
(
skipped
<
dataSpec
.
position
)
{
...
...
@@ -133,7 +143,7 @@ public final class RawResourceDataSource extends BaseDataSource {
try
{
int
bytesToRead
=
bytesRemaining
==
C
.
LENGTH_UNSET
?
readLength
:
(
int
)
Math
.
min
(
bytesRemaining
,
readLength
);
bytesRead
=
inputStream
.
read
(
buffer
,
offset
,
bytesToRead
);
bytesRead
=
castNonNull
(
inputStream
)
.
read
(
buffer
,
offset
,
bytesToRead
);
}
catch
(
IOException
e
)
{
throw
new
RawResourceDataSourceException
(
e
);
}
...
...
@@ -153,7 +163,8 @@ public final class RawResourceDataSource extends BaseDataSource {
}
@Override
public
@Nullable
Uri
getUri
()
{
@Nullable
public
Uri
getUri
()
{
return
uri
;
}
...
...
library/core/src/main/java/com/google/android/exoplayer2/upstream/UdpDataSource.java
View file @
d8369571
...
...
@@ -52,11 +52,11 @@ public final class UdpDataSource extends BaseDataSource {
private
final
byte
[]
packetBuffer
;
private
final
DatagramPacket
packet
;
private
@Nullabl
e
Uri
uri
;
private
@Nullabl
e
DatagramSocket
socket
;
private
@Nullabl
e
MulticastSocket
multicastSocket
;
private
@Nullabl
e
InetAddress
address
;
private
@Nullabl
e
InetSocketAddress
socketAddress
;
@Nullable
privat
e
Uri
uri
;
@Nullable
privat
e
DatagramSocket
socket
;
@Nullable
privat
e
MulticastSocket
multicastSocket
;
@Nullable
privat
e
InetAddress
address
;
@Nullable
privat
e
InetSocketAddress
socketAddress
;
private
boolean
opened
;
private
int
packetRemaining
;
...
...
@@ -144,7 +144,8 @@ public final class UdpDataSource extends BaseDataSource {
}
@Override
public
@Nullable
Uri
getUri
()
{
@Nullable
public
Uri
getUri
()
{
return
uri
;
}
...
...
library/core/src/main/java/com/google/android/exoplayer2/upstream/crypto/AesCipherDataSink.java
View file @
d8369571
...
...
@@ -15,6 +15,9 @@
*/
package
com
.
google
.
android
.
exoplayer2
.
upstream
.
crypto
;
import
static
com
.
google
.
android
.
exoplayer2
.
util
.
Util
.
castNonNull
;
import
androidx.annotation.Nullable
;
import
com.google.android.exoplayer2.upstream.DataSink
;
import
com.google.android.exoplayer2.upstream.DataSpec
;
import
java.io.IOException
;
...
...
@@ -27,9 +30,9 @@ public final class AesCipherDataSink implements DataSink {
private
final
DataSink
wrappedDataSink
;
private
final
byte
[]
secretKey
;
private
final
byte
[]
scratch
;
@Nullable
private
final
byte
[]
scratch
;
private
AesFlushingCipher
cipher
;
@Nullable
private
AesFlushingCipher
cipher
;
/**
* Create an instance whose {@code write} methods have the side effect of overwriting the input
...
...
@@ -52,9 +55,10 @@ public final class AesCipherDataSink implements DataSink {
* @param scratch Scratch space. Data is decrypted into this array before being written to the
* wrapped {@link DataSink}. It should be of appropriate size for the expected writes. If a
* write is larger than the size of this array the write will still succeed, but multiple
* cipher calls will be required to complete the operation.
* cipher calls will be required to complete the operation. If {@code null} then decryption
* will overwrite the input {@code data}.
*/
public
AesCipherDataSink
(
byte
[]
secretKey
,
DataSink
wrappedDataSink
,
byte
[]
scratch
)
{
public
AesCipherDataSink
(
byte
[]
secretKey
,
DataSink
wrappedDataSink
,
@Nullable
byte
[]
scratch
)
{
this
.
wrappedDataSink
=
wrappedDataSink
;
this
.
secretKey
=
secretKey
;
this
.
scratch
=
scratch
;
...
...
@@ -72,15 +76,16 @@ public final class AesCipherDataSink implements DataSink {
public
void
write
(
byte
[]
data
,
int
offset
,
int
length
)
throws
IOException
{
if
(
scratch
==
null
)
{
// In-place mode. Writes over the input data.
c
ipher
.
updateInPlace
(
data
,
offset
,
length
);
c
astNonNull
(
cipher
)
.
updateInPlace
(
data
,
offset
,
length
);
wrappedDataSink
.
write
(
data
,
offset
,
length
);
}
else
{
// Use scratch space. The original data remains intact.
int
bytesProcessed
=
0
;
while
(
bytesProcessed
<
length
)
{
int
bytesToProcess
=
Math
.
min
(
length
-
bytesProcessed
,
scratch
.
length
);
cipher
.
update
(
data
,
offset
+
bytesProcessed
,
bytesToProcess
,
scratch
,
0
);
wrappedDataSink
.
write
(
scratch
,
0
,
bytesToProcess
);
castNonNull
(
cipher
)
.
update
(
data
,
offset
+
bytesProcessed
,
bytesToProcess
,
scratch
,
/* outOffset= */
0
);
wrappedDataSink
.
write
(
scratch
,
/* offset= */
0
,
bytesToProcess
);
bytesProcessed
+=
bytesToProcess
;
}
}
...
...
library/core/src/main/java/com/google/android/exoplayer2/upstream/crypto/AesCipherDataSource.java
View file @
d8369571
...
...
@@ -15,6 +15,8 @@
*/
package
com
.
google
.
android
.
exoplayer2
.
upstream
.
crypto
;
import
static
com
.
google
.
android
.
exoplayer2
.
util
.
Util
.
castNonNull
;
import
android.net.Uri
;
import
androidx.annotation.Nullable
;
import
com.google.android.exoplayer2.C
;
...
...
@@ -34,7 +36,7 @@ public final class AesCipherDataSource implements DataSource {
private
final
DataSource
upstream
;
private
final
byte
[]
secretKey
;
private
@Nullabl
e
AesFlushingCipher
cipher
;
@Nullable
privat
e
AesFlushingCipher
cipher
;
public
AesCipherDataSource
(
byte
[]
secretKey
,
DataSource
upstream
)
{
this
.
upstream
=
upstream
;
...
...
@@ -64,7 +66,7 @@ public final class AesCipherDataSource implements DataSource {
if
(
read
==
C
.
RESULT_END_OF_INPUT
)
{
return
C
.
RESULT_END_OF_INPUT
;
}
c
ipher
.
updateInPlace
(
data
,
offset
,
read
);
c
astNonNull
(
cipher
)
.
updateInPlace
(
data
,
offset
,
read
);
return
read
;
}
...
...
library/core/src/main/java/com/google/android/exoplayer2/upstream/crypto/CryptoUtil.java
View file @
d8369571
...
...
@@ -15,6 +15,8 @@
*/
package
com
.
google
.
android
.
exoplayer2
.
upstream
.
crypto
;
import
androidx.annotation.Nullable
;
/**
* Utility functions for the crypto package.
*/
...
...
@@ -24,10 +26,10 @@ package com.google.android.exoplayer2.upstream.crypto;
/**
* Returns the hash value of the input as a long using the 64 bit FNV-1a hash function. The hash
* values produced by this function are less likely to collide than those produced by
*
{@link
#hashCode()}.
* values produced by this function are less likely to collide than those produced by
{@link
* #hashCode()}.
*/
public
static
long
getFNV64Hash
(
String
input
)
{
public
static
long
getFNV64Hash
(
@Nullable
String
input
)
{
if
(
input
==
null
)
{
return
0
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment