Skip to content

Commit c227bed

Browse files
committed
updates
1 parent 591ff91 commit c227bed

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

app/src/main/java/com/mobilenext/devicekit/AvcServer.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ class AvcServer(private val bitrate: Int, private val scale: Float, private val
207207
Log.d(TAG, "AVC encoder started")
208208

209209
val bufferInfo = MediaCodec.BufferInfo()
210-
val timeout = -1L // Block indefinitely until buffer is available
210+
val timeout = 100_000L // 100ms timeout for responsive shutdown (matches REPEAT_FRAME_DELAY)
211211

212212
// Get FileChannel for stdout to write directly from ByteBuffer (zero-copy)
213213
val stdoutChannel = FileOutputStream(FileDescriptor.out).channel
@@ -244,9 +244,17 @@ class AvcServer(private val bitrate: Int, private val scale: Float, private val
244244
}
245245
} catch (e: IOException) {
246246
// Pipe broken - client disconnected
247-
Log.d(TAG, "Output pipe broken, shutting down")
248-
shutdown()
249-
break
247+
Log.d(TAG, "Output pipe broken, cleaning up")
248+
// Clean up resources before exiting
249+
try {
250+
stdoutChannel.close()
251+
codec.stop()
252+
codec.release()
253+
virtualDisplay.release()
254+
} catch (ex: Exception) {
255+
Log.e(TAG, "Error during cleanup", ex)
256+
}
257+
exitProcess(0)
250258
}
251259

252260
// Log frame info

0 commit comments

Comments
 (0)