Fix shutdown bug

Signed-off-by: Leo Ma <begeekmyfriend@gmail.com>
camera2
Leo Ma 9 years ago
parent 5211eb4169
commit e6bc026809

@ -301,38 +301,38 @@ public class RtmpConnection implements RtmpPublisher {
@Override @Override
public void shutdown() { public void shutdown() {
try { if (socket != null) {
// It will raise EOFException in handleRxPacketThread
socket.shutdownInput();
// It will raise SocketException in sendRtmpPacket
socket.shutdownOutput();
} catch (IOException ioe) {
ioe.printStackTrace();
}
// shutdown rxPacketHandler
if (rxPacketHandler != null) {
rxPacketHandler.interrupt();
try { try {
rxPacketHandler.join(); // It will raise EOFException in handleRxPacketThread
} catch (InterruptedException ie) { socket.shutdownInput();
// It will raise SocketException in sendRtmpPacket
socket.shutdownOutput();
} catch (IOException ioe) {
ioe.printStackTrace();
}
// shutdown rxPacketHandler
if (rxPacketHandler != null) {
rxPacketHandler.interrupt(); rxPacketHandler.interrupt();
try {
rxPacketHandler.join();
} catch (InterruptedException ie) {
rxPacketHandler.interrupt();
}
rxPacketHandler = null;
} }
rxPacketHandler = null;
}
// shutdown socket as well as its input and output stream // shutdown socket as well as its input and output stream
if (socket != null) {
try { try {
socket.close(); socket.close();
Log.d(TAG, "socket closed"); Log.d(TAG, "socket closed");
} catch (IOException ex) { } catch (IOException ex) {
Log.e(TAG, "shutdown(): failed to close socket", ex); Log.e(TAG, "shutdown(): failed to close socket", ex);
} }
}
reset(); reset();
mHandler.onRtmpDisconnected("disconnected"); mHandler.onRtmpDisconnected("disconnected");
}
} }
private void reset() { private void reset() {

Loading…
Cancel
Save