Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,16 @@ public void stopRecording() {
}
}

@Override
public void pauseRecording() {
if (DEBUG) Log.i(TAG, "Pausing");
mRunning = false;
setCapturing(false);
if (mCaptureHandler != null) {
mCaptureHandler.removeCallbacksAndMessages(null);
}
}

@Override
public void resumeRecording() {
if (DEBUG) Log.i(TAG, "Resuming");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ protected int getGrabberHeight() {
}

public abstract void stopRecording();
public abstract void pauseRecording();
public abstract void resumeRecording();
public abstract void setOrientation(int orientation);
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,13 @@ public void onReceiveStatus(boolean isCapturing) {
public void onReceive(Context context, Intent intent) {
switch (Objects.requireNonNull(intent.getAction())) {
case Intent.ACTION_SCREEN_ON:
if (DEBUG) Log.v(TAG, "ACTION_SCREEN_ON intent received");
if (mHyperionEncoder != null && !isCapturing()) {
if (DEBUG) Log.v(TAG, "Encoder not grabbing, attempting to restart");
mHyperionEncoder.resumeRecording();
}
if (mHyperionThread != null) mHyperionThread.resumeConnection();
if (mHyperionEncoder != null) mHyperionEncoder.resumeRecording();
notifyActivity();
break;
case Intent.ACTION_SCREEN_OFF:
if (DEBUG) Log.v(TAG, "ACTION_SCREEN_OFF intent received");
if (mHyperionEncoder != null) {
if (DEBUG) Log.v(TAG, "Clearing current light data");
mHyperionEncoder.clearLights();
}
if (mHyperionEncoder != null) mHyperionEncoder.pauseRecording();
if (mHyperionThread != null) mHyperionThread.pauseConnection();
break;
case Intent.ACTION_CONFIGURATION_CHANGED:
if (DEBUG) Log.v(TAG, "ACTION_CONFIGURATION_CHANGED intent received");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,46 @@ class HyperionThread(
connect()
}

/**
* Closes the current socket without shutting down the executor.
* Call [resumeConnection] to reconnect (e.g. on screen wake).
*/
fun pauseConnection() {
val pending = pendingTask
if (pending != null) {
pending.cancel(false)
pendingTask = null
}
pendingFrame = null
val client = clientRef.getAndSet(null)
if (client != null) {
try { client.disconnect() } catch (ignored: IOException) {}
}
connected.set(false)
}

/**
* Opens a fresh socket on the executor thread.
* Call after [pauseConnection] when the screen wakes up.
*/
fun resumeConnection() {
if (executor.isShutdown) return
executor.submit {
try {
val client = createClient()
if (client.isConnected()) {
clientRef.set(client)
connected.set(true)
callback.onConnected()
} else {
callback.onConnectionError(0, "Failed to reconnect")
}
} catch (e: IOException) {
callback.onConnectionError(e.hashCode(), e.message ?: "Unknown error")
}
}
}

private fun createClient(): HyperionClient {
return if (wledEnabled && wledIp != null) {
WledDdpClient(InetAddress.getByName(wledIp), 4048)
Expand Down
Loading