Skip to content
This repository has been archived by the owner on May 6, 2022. It is now read-only.

Commit

Permalink
Fix: force pipeline stages to reset on deactivate
Browse files Browse the repository at this point in the history
This change causes a manual pipeline deactivation to
force all pipeline stages to reset, releasing any resources
they hold. It also performs a full reset on the speech context,
releasing it from any external management registered during
the activation.
  • Loading branch information
space-pope committed Sep 30, 2020
1 parent 0546186 commit 67b5372
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
9 changes: 8 additions & 1 deletion src/main/java/io/spokestack/spokestack/SpeechPipeline.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,14 @@ public void activate() {

/** manually deactivate the speech pipeline. */
public void deactivate() {
this.context.setActive(false);
this.context.reset();
for (SpeechProcessor stage : this.stages) {
try {
stage.reset();
} catch (Exception e) {
raiseError(e);
}
}
}

/**
Expand Down
15 changes: 12 additions & 3 deletions src/test/java/io/spokestack/spokestack/SpeechPipelineTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,20 @@ public void testContextManagement() throws Exception {

// still no event, and the external activation isn't overridden by the
// stage, which would normally deactivate on the second frame
pipeline.getContext().setActive(true);
pipeline.activate();
transact(true);
assertTrue(this.events.isEmpty());
assertTrue(pipeline.getContext().isActive());

// turn off external management and get the expected activations/events
pipeline.getContext().setManaged(false);
// ensure that manual deactivation resets stages
assertFalse(Stage.reset);
pipeline.deactivate();
assertTrue(Stage.reset);
assertFalse(pipeline.getContext().isActive());
assertFalse(pipeline.getContext().isManaged());

// now that external management is off,
// we get the expected activations/events
transact(false);
assertEquals(SpeechContext.Event.ACTIVATE, this.events.get(0));
assertTrue(pipeline.getContext().isActive());
Expand Down Expand Up @@ -291,12 +298,14 @@ public void read(SpeechContext context, ByteBuffer frame)

public static class Stage implements SpeechProcessor {
public static boolean open;
public static boolean reset = false;

public Stage(SpeechConfig config) {
open = true;
}

public void reset() {
reset = true;
close();
}

Expand Down

0 comments on commit 67b5372

Please sign in to comment.