[go: nahoru, domu]

Skip to content
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

Enables a configurable SocketFactory for the RTSP client #9606

Merged
merged 21 commits into from
Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
PR feedback
  • Loading branch information
Sebastian Roth committed Nov 2, 2021
commit 0830c06cd7e72695543978484446180512fad842
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ public interface PlaybackEventListener {
private final SessionInfoListener sessionInfoListener;
private final PlaybackEventListener playbackEventListener;
private final String userAgent;
private final SocketFactory socketFactory;
private final boolean debugLoggingEnabled;
@Nullable private final SocketFactory socketFactory;
private final ArrayDeque<RtpLoadInfo> pendingSetupRtpLoadInfos;
// TODO(b/172331505) Add a timeout monitor for pending requests.
private final SparseArray<RtspRequest> pendingRequests;
Expand Down Expand Up @@ -156,14 +156,16 @@ public interface PlaybackEventListener {
* @param playbackEventListener The {@link PlaybackEventListener}.
* @param userAgent The user agent.
* @param uri The RTSP playback URI.
* @param socketFactory The {@link SocketFactory} for the client connection.
* @param debugLoggingEnabled Whether to print RTSP messages.
*/
public RtspClient(
SessionInfoListener sessionInfoListener,
PlaybackEventListener playbackEventListener,
String userAgent,
Uri uri,
boolean debugLoggingEnabled,
@Nullable SocketFactory socketFactory) {
SocketFactory socketFactory,
boolean debugLoggingEnabled) {
this.sessionInfoListener = sessionInfoListener;
this.playbackEventListener = playbackEventListener;
this.userAgent = userAgent;
Expand Down Expand Up @@ -293,9 +295,6 @@ private Socket getSocket(Uri uri) throws IOException {
checkArgument(uri.getHost() != null);
int rtspPort = uri.getPort() > 0 ? uri.getPort() : DEFAULT_RTSP_PORT;

SocketFactory socketFactory =
this.socketFactory != null ? this.socketFactory : SocketFactory.getDefault();

return socketFactory.createSocket(checkNotNull(uri.getHost()), rtspPort);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,16 @@ interface Listener {
* @param listener A {@link Listener} to receive session information updates.
* @param userAgent The user agent.
* @param debugLoggingEnabled Whether to log RTSP messages.
* @param socketFactory A socket factory.
* @param socketFactory A socket factory for {@link RtspClient}'s connection.
ened marked this conversation as resolved.
Show resolved Hide resolved
*/
public RtspMediaPeriod(
Allocator allocator,
RtpDataChannel.Factory rtpDataChannelFactory,
Uri uri,
Listener listener,
String userAgent,
boolean debugLoggingEnabled,
@Nullable SocketFactory socketFactory) {
SocketFactory socketFactory,
boolean debugLoggingEnabled) {
this.allocator = allocator;
this.rtpDataChannelFactory = rtpDataChannelFactory;
this.listener = listener;
Expand All @@ -125,8 +125,8 @@ public RtspMediaPeriod(
/* playbackEventListener= */ internalListener,
/* userAgent= */ userAgent,
/* uri= */ uri,
debugLoggingEnabled,
socketFactory);
socketFactory,
debugLoggingEnabled);
rtspLoaderWrappers = new ArrayList<>();
selectedLoadInfos = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ public static final class Factory implements MediaSourceFactory {

private long timeoutMs;
private String userAgent;
@Nullable private SocketFactory socketFactory;
private boolean forceUseRtpTcp;
private boolean debugLoggingEnabled;
private SocketFactory socketFactory;

public Factory() {
timeoutMs = DEFAULT_TIMEOUT_MS;
Expand Down Expand Up @@ -120,9 +120,8 @@ public Factory setDebugLoggingEnabled(boolean debugLoggingEnabled) {
}

/**
* Configures a socket factory to be used for client connections.
*
* When unspecified, {@link SocketFactory#getDefault()} is used.
* Sets a socket factory for {@link RtspClient}'s connection, the default value is {@link
* SocketFactory#getDefault()}.
*
* @param socketFactory A socket factory.
* @return This Factory, for convenience.
Expand Down Expand Up @@ -217,8 +216,8 @@ public RtspMediaSource createMediaSource(MediaItem mediaItem) {
? new TransferRtpDataChannelFactory(timeoutMs)
: new UdpDataSourceRtpDataChannelFactory(timeoutMs),
userAgent,
debugLoggingEnabled,
socketFactory);
socketFactory == null ? SocketFactory.getDefault() : socketFactory,
debugLoggingEnabled);
}
}

Expand All @@ -241,10 +240,8 @@ public RtspPlaybackException(String message, Throwable e) {
private final RtpDataChannel.Factory rtpDataChannelFactory;
private final String userAgent;
private final Uri uri;
private final boolean debugLoggingEnabled;

@Nullable
private final SocketFactory socketFactory;
private final boolean debugLoggingEnabled;

private long timelineDurationUs;
private boolean timelineIsSeekable;
Expand All @@ -256,8 +253,8 @@ public RtspPlaybackException(String message, Throwable e) {
MediaItem mediaItem,
RtpDataChannel.Factory rtpDataChannelFactory,
String userAgent,
boolean debugLoggingEnabled,
@Nullable SocketFactory socketFactory) {
SocketFactory socketFactory,
boolean debugLoggingEnabled) {
this.mediaItem = mediaItem;
this.rtpDataChannelFactory = rtpDataChannelFactory;
this.userAgent = userAgent;
Expand Down Expand Up @@ -302,8 +299,8 @@ public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator, long star
notifySourceInfoRefreshed();
},
userAgent,
debugLoggingEnabled,
socketFactory);
socketFactory,
debugLoggingEnabled);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ public void onSessionTimelineRequestFailed(
EMPTY_PLAYBACK_LISTENER,
/* userAgent= */ "ExoPlayer:RtspClientTest",
RtspTestUtils.getTestUri(rtspServer.startAndGetPortNumber()),
/* debugLoggingEnabled= */ false,
socketFactory);
socketFactory,
/* debugLoggingEnabled= */ false);
rtspClient.start();
RobolectricUtil.runMainLooperUntil(() -> tracksInSession.get() != null);

Expand Down Expand Up @@ -190,8 +190,8 @@ public void onSessionTimelineRequestFailed(
EMPTY_PLAYBACK_LISTENER,
/* userAgent= */ "ExoPlayer:RtspClientTest",
RtspTestUtils.getTestUri(rtspServer.startAndGetPortNumber()),
/* debugLoggingEnabled= */ false,
/* socketFactory */ null);
/* socketFactory */ null,
ened marked this conversation as resolved.
Show resolved Hide resolved
/* debugLoggingEnabled= */ false);
rtspClient.start();
RobolectricUtil.runMainLooperUntil(() -> tracksInSession.get() != null);

Expand Down Expand Up @@ -242,8 +242,8 @@ public void onSessionTimelineRequestFailed(
EMPTY_PLAYBACK_LISTENER,
/* userAgent= */ "ExoPlayer:RtspClientTest",
RtspTestUtils.getTestUri(rtspServer.startAndGetPortNumber()),
/* debugLoggingEnabled= */ false,
/* socketFactory */ null);
/* socketFactory */ SocketFactory.getDefault(),
/* debugLoggingEnabled= */ false);
rtspClient.start();
RobolectricUtil.runMainLooperUntil(() -> tracksInSession.get() != null);

Expand Down Expand Up @@ -286,8 +286,8 @@ public void onSessionTimelineRequestFailed(
EMPTY_PLAYBACK_LISTENER,
/* userAgent= */ "ExoPlayer:RtspClientTest",
RtspTestUtils.getTestUri(rtspServer.startAndGetPortNumber()),
/* debugLoggingEnabled= */ false,
/* socketFactory */ null);
/* socketFactory */ SocketFactory.getDefault(),
/* debugLoggingEnabled= */ false);
rtspClient.start();
RobolectricUtil.runMainLooperUntil(() -> tracksInSession.get() != null);

Expand Down Expand Up @@ -333,8 +333,8 @@ public void onSessionTimelineRequestFailed(
EMPTY_PLAYBACK_LISTENER,
/* userAgent= */ "ExoPlayer:RtspClientTest",
RtspTestUtils.getTestUri(rtspServer.startAndGetPortNumber()),
/* debugLoggingEnabled= */ false,
/* socketFactory */ null);
/* socketFactory */ SocketFactory.getDefault(),
/* debugLoggingEnabled= */ false);
rtspClient.start();
RobolectricUtil.runMainLooperUntil(() -> failureMessage.get() != null);

Expand Down Expand Up @@ -380,8 +380,8 @@ public void onSessionTimelineRequestFailed(
EMPTY_PLAYBACK_LISTENER,
/* userAgent= */ "ExoPlayer:RtspClientTest",
RtspTestUtils.getTestUri(rtspServer.startAndGetPortNumber()),
/* debugLoggingEnabled= */ false,
/* socketFactory */ null);
/* socketFactory */ SocketFactory.getDefault(),
/* debugLoggingEnabled= */ false);
rtspClient.start();

RobolectricUtil.runMainLooperUntil(() -> failureCause.get() != null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.google.common.collect.ImmutableList;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import javax.net.SocketFactory;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -84,8 +85,8 @@ public RtspResponse getDescribeResponse(Uri requestedUri) {
RtspTestUtils.getTestUri(rtspServer.startAndGetPortNumber()),
/* listener= */ timing -> refreshedSourceDurationMs.set(timing.getDurationMs()),
/* userAgent= */ "ExoPlayer:RtspPeriodTest",
/* debugLoggingEnabled= */ false,
/* socketFactory */ null);
/* socketFactory */ SocketFactory.getDefault(),
/* debugLoggingEnabled= */ false);

mediaPeriod.prepare(
new MediaPeriod.Callback() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import java.util.List;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicReference;
import javax.net.SocketFactory;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
Expand Down Expand Up @@ -156,8 +157,8 @@ private ExoPlayer createExoPlayer(
MediaItem.fromUri(RtspTestUtils.getTestUri(serverRtspPortNumber)),
rtpDataChannelFactory,
"ExoPlayer:PlaybackTest",
/* debugLoggingEnabled= */ false,
/* socketFactory */ null),
/* socketFactory */ SocketFactory.getDefault(),
/* debugLoggingEnabled= */ false),
false);
return player;
}
Expand Down