-
Notifications
You must be signed in to change notification settings - Fork 7
feat: add pipeline-level endOfStream() method #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| #!/usr/bin/env node | ||
| import { Pipeline } from "../dist/esm/index.mjs"; | ||
|
|
||
| // Demonstrates sending an EOS event directly to the pipeline. | ||
| // This works with any source type (hardware cameras, network streams, test sources) | ||
| // unlike appsrc.endOfStream() which only works on appsrc elements. | ||
|
|
||
| const pipeline = new Pipeline("videotestsrc ! videoconvert ! autovideosink"); | ||
|
|
||
| await pipeline.play(); | ||
| console.log("▶️ Pipeline playing. Sending EOS in 5 seconds..."); | ||
|
|
||
| setTimeout(() => { | ||
| console.log("🏁 Sending End-of-Stream to pipeline now!"); | ||
| const sent = pipeline.endOfStream(); | ||
| console.log(` endOfStream() returned: ${sent}`); | ||
| }, 5000); | ||
|
|
||
| while (true) { | ||
| const message = await pipeline.busPop(100); | ||
| if (!message) continue; | ||
| if (message.type === "eos") { | ||
| await pipeline.stop(); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| console.log("🎉 End-of-Stream received! Pipeline stopped cleanly."); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { Pipeline, type GstMessage } from "."; | ||
|
|
||
| describe.concurrent("Pipeline EOS - State-Gated Dispatch", () => { | ||
| it("should return true when pipeline is in PLAYING state", async () => { | ||
| const pipeline = new Pipeline("videotestsrc ! fakesink"); | ||
|
|
||
| await pipeline.play(); | ||
|
|
||
| const result = pipeline.endOfStream(); | ||
| expect(result).toBe(true); | ||
|
|
||
| await pipeline.stop(); | ||
| }); | ||
|
|
||
| it("should return true when pipeline is in PAUSED state", async () => { | ||
| const pipeline = new Pipeline("videotestsrc ! fakesink async=false"); | ||
|
|
||
| await pipeline.pause(); | ||
|
|
||
| const result = pipeline.endOfStream(); | ||
| expect(result).toBe(true); | ||
|
|
||
| await pipeline.stop(); | ||
| }); | ||
|
|
||
| it("should return false when pipeline is in NULL state (freshly constructed)", async () => { | ||
| const pipeline = new Pipeline("videotestsrc ! fakesink"); | ||
|
|
||
| const result = pipeline.endOfStream(); | ||
| expect(result).toBe(false); | ||
|
|
||
| await pipeline.stop(); | ||
| }); | ||
|
|
||
| it("should propagate EOS message on the bus after endOfStream", async () => { | ||
| const pipeline = new Pipeline("videotestsrc ! fakesink"); | ||
|
|
||
| await pipeline.play(); | ||
|
|
||
| const sent = pipeline.endOfStream(); | ||
| expect(sent).toBe(true); | ||
|
|
||
| // Poll busPop for an EOS message within a reasonable timeout | ||
| let eosMessage: GstMessage | null = null; | ||
| const maxAttempts = 20; | ||
|
|
||
| for (let i = 0; i < maxAttempts; i++) { | ||
| const message = await pipeline.busPop(500); | ||
| if (message && message.type === "eos") { | ||
| eosMessage = message; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| await pipeline.stop(); | ||
|
|
||
| expect(eosMessage).not.toBeNull(); | ||
| expect(eosMessage!.type).toBe("eos"); | ||
| }); | ||
|
|
||
| it("should handle multiple endOfStream calls on a PLAYING pipeline without exception", async () => { | ||
| const pipeline = new Pipeline("videotestsrc ! fakesink"); | ||
|
|
||
| await pipeline.play(); | ||
|
|
||
| const result1 = pipeline.endOfStream(); | ||
| const result2 = pipeline.endOfStream(); | ||
| const result3 = pipeline.endOfStream(); | ||
|
|
||
| expect(result1).toBe(true); | ||
| expect(result2).toBe(true); | ||
| expect(result3).toBe(true); | ||
|
|
||
| await pipeline.stop(); | ||
| }); | ||
|
|
||
| it("should return false when endOfStream is called after stopping the pipeline", async () => { | ||
| const pipeline = new Pipeline("videotestsrc ! fakesink"); | ||
|
|
||
| await pipeline.play(); | ||
|
|
||
| const resultWhilePlaying = pipeline.endOfStream(); | ||
| expect(resultWhilePlaying).toBe(true); | ||
|
|
||
| await pipeline.stop(); | ||
|
|
||
| const resultAfterStop = pipeline.endOfStream(); | ||
| expect(resultAfterStop).toBe(false); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.