Rename RtspMessageChannel.openSocket() to open().

The method openSocket in RtspMessageChannel does not actually open a socket.
The 'open' term refers more to opening the message channel.

#minor-release

PiperOrigin-RevId: 375908999
This commit is contained in:
claincly 2021-05-26 11:52:57 +01:00 committed by Oliver Woodman
parent b10f4363b9
commit f49c14479e
4 changed files with 15 additions and 16 deletions

View File

@ -140,7 +140,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
*/ */
public void start() throws IOException { public void start() throws IOException {
try { try {
messageChannel.openSocket(openSocket()); messageChannel.open(getSocket(uri));
} catch (IOException e) { } catch (IOException e) {
Util.closeQuietly(messageChannel); Util.closeQuietly(messageChannel);
throw e; throw e;
@ -148,13 +148,6 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
messageSender.sendOptionsRequest(uri, sessionId); messageSender.sendOptionsRequest(uri, sessionId);
} }
/** Opens a {@link Socket} to the session {@link #uri}. */
private Socket openSocket() throws IOException {
checkArgument(uri.getHost() != null);
int rtspPort = uri.getPort() > 0 ? uri.getPort() : DEFAULT_RTSP_PORT;
return SocketFactory.getDefault().createSocket(checkNotNull(uri.getHost()), rtspPort);
}
/** Sets the {@link PlaybackEventListener} to receive playback events. */ /** Sets the {@link PlaybackEventListener} to receive playback events. */
public void setPlaybackEventListener(PlaybackEventListener playbackEventListener) { public void setPlaybackEventListener(PlaybackEventListener playbackEventListener) {
this.playbackEventListener = playbackEventListener; this.playbackEventListener = playbackEventListener;
@ -217,7 +210,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
try { try {
close(); close();
messageChannel = new RtspMessageChannel(new MessageListener()); messageChannel = new RtspMessageChannel(new MessageListener());
messageChannel.openSocket(openSocket()); messageChannel.open(getSocket(uri));
sessionId = null; sessionId = null;
} catch (IOException e) { } catch (IOException e) {
checkNotNull(playbackEventListener).onPlaybackError(new RtspPlaybackException(e)); checkNotNull(playbackEventListener).onPlaybackError(new RtspPlaybackException(e));
@ -239,6 +232,13 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
messageSender.sendSetupRequest(loadInfo.getTrackUri(), loadInfo.getTransport(), sessionId); messageSender.sendSetupRequest(loadInfo.getTrackUri(), loadInfo.getTransport(), sessionId);
} }
/** Returns a {@link Socket} that is connected to the {@code uri}. */
private static Socket getSocket(Uri uri) throws IOException {
checkArgument(uri.getHost() != null);
int rtspPort = uri.getPort() > 0 ? uri.getPort() : DEFAULT_RTSP_PORT;
return SocketFactory.getDefault().createSocket(checkNotNull(uri.getHost()), rtspPort);
}
/** /**
* Returns whether the RTSP server supports the DESCRIBE method. * Returns whether the RTSP server supports the DESCRIBE method.
* *

View File

@ -109,9 +109,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
/** /**
* Constructs a new instance. * Constructs a new instance.
* *
* <p>An RTSP {@link Socket socket} must be constructed, and used to call {@link #openSocket} to * <p>A connected {@link Socket} must be provided in {@link #open} in order to send and receive
* open the connection before being able to send and receive. {@link #close} must be called when * RTSP messages. {@link #close} must be called when done, which would also close the socket.
* done.
* *
* <p>{@link MessageListener} and {@link InterleavedBinaryDataListener} implementations must not * <p>{@link MessageListener} and {@link InterleavedBinaryDataListener} implementations must not
* make assumptions about which thread called their listener methods; and must be thread-safe. * make assumptions about which thread called their listener methods; and must be thread-safe.
@ -132,9 +131,9 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
* <p>Note: If an {@link IOException} is thrown, callers must still call {@link #close()} to * <p>Note: If an {@link IOException} is thrown, callers must still call {@link #close()} to
* ensure that any partial effects of the invocation are cleaned up. * ensure that any partial effects of the invocation are cleaned up.
* *
* @param socket An accepted {@link Socket}. * @param socket A connected {@link Socket}.
*/ */
public void openSocket(Socket socket) throws IOException { public void open(Socket socket) throws IOException {
this.socket = socket; this.socket = socket;
sender = new Sender(socket.getOutputStream()); sender = new Sender(socket.getOutputStream());

View File

@ -128,7 +128,7 @@ public final class RtspMessageChannelTest {
rtspMessageChannel.registerInterleavedBinaryDataListener( rtspMessageChannel.registerInterleavedBinaryDataListener(
/* channel= */ 1, data -> receivedInterleavedData.put(1, Bytes.asList(data))); /* channel= */ 1, data -> receivedInterleavedData.put(1, Bytes.asList(data)));
rtspMessageChannel.openSocket(clientSideSocket); rtspMessageChannel.open(clientSideSocket);
RobolectricUtil.runMainLooperUntil(receivingFinished::get); RobolectricUtil.runMainLooperUntil(receivingFinished::get);
Util.closeQuietly(rtspMessageChannel); Util.closeQuietly(rtspMessageChannel);

View File

@ -87,7 +87,7 @@ public final class RtspServer implements Closeable {
private void handleNewClientConnected(Socket socket) { private void handleNewClientConnected(Socket socket) {
try { try {
connectedClient = new RtspMessageChannel(new MessageListener()); connectedClient = new RtspMessageChannel(new MessageListener());
connectedClient.openSocket(socket); connectedClient.open(socket);
} catch (IOException e) { } catch (IOException e) {
Util.closeQuietly(connectedClient); Util.closeQuietly(connectedClient);
// Log the error. // Log the error.