private void shutdownImpl() {
        // Shut down read/write threads, if necessary
        if (Thread.activeCount() > 1) {
            L.i("shutdown(): Shutting down read/write threads");
            Thread[] threads = new Thread[Thread.activeCount()];
            Thread.enumerate(threads);
            for (Thread thread : threads) {
                if (thread instanceof ReadThread && thread.isAlive()) {
                    ((ReadThread) thread).shutdown();
                } else if (thread instanceof WriteThread && thread.isAlive()) {
                    ((WriteThread) thread).shutdown();
                }
            }
        }
        if (socket != null) {
            try {
                socket.close();
            } catch (Exception ex) {
                L.w("shutdown(): failed to close socket", ex);
            }
        }
        if (rtmpStreamWriter != null) {
            rtmpStreamWriter.close();
        }
    }