-
Notifications
You must be signed in to change notification settings - Fork 33
feat: add a GStreamer runner to launch pipelines #323
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
Open
ylatuya
wants to merge
1
commit into
master
Choose a base branch
from
gst-runner
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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,105 @@ | ||
| # Fluster - testing framework for decoders conformance | ||
| # Copyright (C) 2025, Fluendo, S.A. | ||
| # Author: Andoni Morales Alastruey <amorales@fluendo.com>, Fluendo, S.A. | ||
| # | ||
| # This library is free software; you can redistribute it and/or | ||
| # modify it under the terms of the GNU Lesser General Public License | ||
| # as published by the Free Software Foundation, either version 3 | ||
| # of the License, or (at your option) any later version. | ||
| # | ||
| # This library is distributed in the hope that it will be useful, | ||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| # Lesser General Public License for more details. | ||
| # | ||
| # You should have received a copy of the GNU Lesser General Public | ||
| # License along with this library. If not, see <https://www.gnu.org/licenses/>. | ||
|
|
||
| """ | ||
| GStreamer utilities for Fluster. | ||
|
|
||
| This package provides ctypes bindings for GStreamer and a pipeline runner | ||
| that can be used to run GStreamer pipelines without depending on the | ||
| GStreamer Python bindings (gi.repository.Gst). | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import os | ||
| import subprocess | ||
| import sys | ||
| from typing import Optional | ||
|
|
||
| from fluster.decoder import NotSupportedError | ||
| from fluster.gstreamer.gst_ctypes import GStreamerInstallation | ||
| from fluster.gstreamer.runner import ExitCode as ExitCode | ||
|
|
||
|
|
||
| def run_pipeline( | ||
| pipeline: str, | ||
| timeout: Optional[int] = None, | ||
| verbose: bool = False, | ||
| quiet: bool = False, | ||
| print_messages: bool = False, | ||
| no_fault: bool = True, | ||
| ) -> subprocess.CompletedProcess[str]: | ||
| """ | ||
| Run a GStreamer pipeline in a subprocess with proper environment setup. | ||
|
|
||
| This is a convenience function that handles environment configuration and | ||
| spawns the GStreamer runner as a subprocess. It's the recommended way to | ||
| run GStreamer pipelines from fluster. | ||
|
|
||
| Args: | ||
| pipeline: The GStreamer pipeline description string (gst-launch format). | ||
| timeout: Timeout in seconds for the pipeline to complete. None for no timeout. | ||
| verbose: Enable verbose output from the runner. | ||
| quiet: Suppress output except errors. | ||
| print_messages: Print all bus messages (like gst-launch -m). | ||
| no_fault: Disable fault handling in the runner. | ||
|
|
||
| Returns: | ||
| subprocess.CompletedProcess with returncode, stdout, and stderr. | ||
|
|
||
| Raises: | ||
| subprocess.TimeoutExpired: When a timeout occurs. | ||
| subprocess.CalledProcessError: For other non-zero exit codes. | ||
|
|
||
| Exit codes (see ExitCode enum): | ||
| SUCCESS (0) - Pipeline completed successfully (EOS) | ||
| ERROR (1) - Pipeline error occurred | ||
| INIT_ERROR (2) - Invalid arguments or initialization error | ||
| TIMEOUT (3) - Timeout occurred | ||
| """ | ||
| cmd = [sys.executable, "-m", "fluster.gstreamer.runner"] | ||
| if verbose: | ||
| cmd.append("--verbose") | ||
| if quiet: | ||
| cmd.append("--quiet") | ||
| if print_messages: | ||
| cmd.append("--messages") | ||
| if no_fault: | ||
| cmd.append("--no-fault") | ||
| if timeout is not None: | ||
| cmd.extend(["--timeout", str(timeout)]) | ||
| cmd.append(pipeline) | ||
| env = os.environ.copy() | ||
| env.update(GStreamerInstallation().get_environment()) | ||
| result = subprocess.run(cmd, env=env, capture_output=True, text=True, check=False) | ||
| if result.returncode == ExitCode.SUCCESS: | ||
| return result | ||
| elif result.returncode == ExitCode.NOT_SUPPORTED: | ||
| raise NotSupportedError(f"GStreamer runner not supported error: {result.stderr.strip()}") | ||
| elif result.returncode == ExitCode.TIMEOUT: | ||
| raise subprocess.TimeoutExpired( | ||
| result.args, | ||
| timeout if timeout is not None else 0, | ||
| output=result.stdout, | ||
| stderr=result.stderr, | ||
| ) | ||
| raise subprocess.CalledProcessError( | ||
| result.returncode, | ||
| result.args, | ||
| output=result.stdout, | ||
| stderr=result.stderr, | ||
| ) | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add something like:
NOT_SUPPORTED (4) - Format/codec not supported