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
65124632
authored
Jul 14, 2021
by
claincly
Committed by
Oliver Woodman
Jul 14, 2021
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Make network-based DataSource implementations use ErrorCode.
PiperOrigin-RevId: 384666131
parent
f9f93c5a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
16 deletions
library/common/src/main/java/com/google/android/exoplayer2/upstream/DefaultHttpDataSource.java
library/core/src/main/java/com/google/android/exoplayer2/upstream/UdpDataSource.java
library/rtsp/src/main/java/com/google/android/exoplayer2/source/rtsp/UdpDataSourceRtpDataChannel.java
library/common/src/main/java/com/google/android/exoplayer2/upstream/DefaultHttpDataSource.java
View file @
65124632
...
...
@@ -465,13 +465,11 @@ public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSou
}
}
catch
(
IOException
e
)
{
closeConnectionQuietly
();
@PlaybackException
.
ErrorCode
int
errorCode
=
PlaybackException
.
ERROR_CODE_IO_UNSPECIFIED
;
if
(
e
instanceof
DataSourceException
)
{
errorCode
=
((
DataSourceException
)
e
).
reason
;
}
throw
new
HttpDataSourceException
(
e
,
dataSpec
,
errorCode
,
HttpDataSourceException
.
TYPE_OPEN
);
throw
new
HttpDataSourceException
(
e
,
dataSpec
,
PlaybackException
.
ERROR_CODE_IO_UNSPECIFIED
,
HttpDataSourceException
.
TYPE_OPEN
);
}
return
bytesToRead
;
...
...
library/core/src/main/java/com/google/android/exoplayer2/upstream/UdpDataSource.java
View file @
65124632
...
...
@@ -20,22 +20,32 @@ import static java.lang.Math.min;
import
android.net.Uri
;
import
androidx.annotation.Nullable
;
import
com.google.android.exoplayer2.C
;
import
com.google.android.exoplayer2.PlaybackException
;
import
java.io.IOException
;
import
java.net.DatagramPacket
;
import
java.net.DatagramSocket
;
import
java.net.InetAddress
;
import
java.net.InetSocketAddress
;
import
java.net.MulticastSocket
;
import
java.net.PortUnreachableException
;
import
java.net.SocketException
;
import
java.net.SocketTimeoutException
;
/** A UDP {@link DataSource}. */
public
final
class
UdpDataSource
extends
BaseDataSource
{
/** Thrown when an error is encountered when trying to read from a {@link UdpDataSource}. */
public
static
final
class
UdpDataSourceException
extends
IOException
{
public
UdpDataSourceException
(
IOException
cause
)
{
super
(
cause
);
public
static
final
class
UdpDataSourceException
extends
DataSourceException
{
/**
* Creates a {@code UdpDataSourceException}.
*
* @param cause The error cause.
* @param errorCode Reason of the error, should be one of the {@code ERROR_CODE_IO_*} in {@link
* PlaybackException.ErrorCode}.
*/
public
UdpDataSourceException
(
IOException
cause
,
@PlaybackException
.
ErrorCode
int
errorCode
)
{
super
(
cause
,
errorCode
);
}
}
...
...
@@ -104,13 +114,14 @@ public final class UdpDataSource extends BaseDataSource {
socket
=
new
DatagramSocket
(
socketAddress
);
}
}
catch
(
IOException
e
)
{
throw
new
UdpDataSourceException
(
e
);
throw
new
UdpDataSourceException
(
e
,
PlaybackException
.
ERROR_CODE_IO_NETWORK_CONNECTION_FAILED
);
}
try
{
socket
.
setSoTimeout
(
socketTimeoutMillis
);
}
catch
(
SocketException
e
)
{
throw
new
UdpDataSourceException
(
e
);
throw
new
UdpDataSourceException
(
e
,
PlaybackException
.
ERROR_CODE_IO_UNSPECIFIED
);
}
opened
=
true
;
...
...
@@ -129,7 +140,7 @@ public final class UdpDataSource extends BaseDataSource {
try
{
socket
.
receive
(
packet
);
}
catch
(
IOException
e
)
{
throw
new
UdpDataSource
Exception
(
e
);
throw
createRead
Exception
(
e
);
}
packetRemaining
=
packet
.
getLength
();
bytesTransferred
(
packetRemaining
);
...
...
@@ -182,4 +193,15 @@ public final class UdpDataSource extends BaseDataSource {
}
return
socket
.
getLocalPort
();
}
private
static
UdpDataSourceException
createReadException
(
IOException
e
)
{
if
(
e
instanceof
PortUnreachableException
)
{
return
new
UdpDataSourceException
(
e
,
PlaybackException
.
ERROR_CODE_IO_NETWORK_UNAVAILABLE
);
}
else
if
(
e
instanceof
SocketTimeoutException
)
{
return
new
UdpDataSourceException
(
e
,
PlaybackException
.
ERROR_CODE_IO_NETWORK_CONNECTION_TIMEOUT
);
}
else
{
return
new
UdpDataSourceException
(
e
,
PlaybackException
.
ERROR_CODE_IO_UNSPECIFIED
);
}
}
}
library/rtsp/src/main/java/com/google/android/exoplayer2/source/rtsp/UdpDataSourceRtpDataChannel.java
View file @
65124632
...
...
@@ -21,13 +21,13 @@ import static com.google.android.exoplayer2.util.Assertions.checkState;
import
android.net.Uri
;
import
androidx.annotation.Nullable
;
import
com.google.android.exoplayer2.C
;
import
com.google.android.exoplayer2.PlaybackException
;
import
com.google.android.exoplayer2.upstream.DataSpec
;
import
com.google.android.exoplayer2.upstream.TransferListener
;
import
com.google.android.exoplayer2.upstream.UdpDataSource
;
import
com.google.android.exoplayer2.util.Util
;
import
com.google.common.primitives.Ints
;
import
java.io.IOException
;
import
java.net.SocketTimeoutException
;
/** An {@link RtpDataChannel} for UDP transport. */
/* package */
final
class
UdpDataSourceRtpDataChannel
implements
RtpDataChannel
{
...
...
@@ -98,7 +98,7 @@ import java.net.SocketTimeoutException;
try
{
return
dataSource
.
read
(
target
,
offset
,
length
);
}
catch
(
UdpDataSource
.
UdpDataSourceException
e
)
{
if
(
e
.
getCause
()
instanceof
SocketTimeoutException
)
{
if
(
e
.
reason
==
PlaybackException
.
ERROR_CODE_IO_NETWORK_CONNECTION_TIMEOUT
)
{
return
C
.
RESULT_END_OF_INPUT
;
}
else
{
throw
e
;
...
...
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