Skip to content
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

start pulseaudio in standalone mode #2243

Merged
merged 1 commit into from
May 5, 2024
Merged

Conversation

edhinard
Copy link
Contributor

@edhinard edhinard commented May 3, 2024

User description

Description

In addition to #994 . this PR starts pulseaudio in standalone mode.

Motivation and Context

Feature added by #994 was available for grid mode only.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have read the contributing document.
  • My change requires a change to the documentation.
    I don't think this audio feature is documented. I found it by accident. Where should it be described?
  • I have added tests to cover my changes.
    Support for browsers to play video streams #994 added a new test (test_play_video) that is not working anymore since video link is broken. Not sure how to repair it

Type

enhancement


Description

  • Added initialization and configuration of PulseAudio in the standalone startup script to ensure audio functionality.
  • This includes starting the PulseAudio server, setting up a virtual sink, and configuring the default sink and source.

Changes walkthrough

Relevant files
Enhancement
start-selenium-standalone.sh
Configure PulseAudio for Standalone Selenium Mode               

Standalone/start-selenium-standalone.sh

  • Added commands to start the pulseaudio server in standalone mode.
  • Configured a virtual sink and set it as the default sink.
  • Set the monitor of the virtual sink as the default source.
  • +10/-0   

    PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    @CLAassistant
    Copy link

    CLAassistant commented May 3, 2024

    CLA assistant check
    All committers have signed the CLA.

    Copy link

    PR Description updated to latest commit (aa52551)

    Copy link

    PR Review

    ⏱️ Estimated effort to review [1-5]

    2, because the changes are straightforward and localized to a single script. The modifications involve starting a service and configuring it, which is typically not complex. However, understanding the context and implications of these changes in the system might require some domain knowledge about audio services in Selenium environments.

    🧪 Relevant tests

    No

    🔍 Possible issues

    Possible Bug: The script does not handle the failure of any PulseAudio commands. If any command fails (e.g., PulseAudio fails to start or a module fails to load), the script will continue executing. This could lead to hard-to-diagnose errors at runtime.

    🔒 Security concerns

    No


    ✨ Review tool usage guide:

    Overview:
    The review tool scans the PR code changes, and generates a PR review which includes several types of feedbacks, such as possible PR issues, security threats and relevant test in the PR. More feedbacks can be added by configuring the tool.

    The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on any PR.

    • When commenting, to edit configurations related to the review tool (pr_reviewer section), use the following template:
    /review --pr_reviewer.some_config1=... --pr_reviewer.some_config2=...
    
    [pr_reviewer]
    some_config1=...
    some_config2=...
    

    See the review usage page for a comprehensive guide on using this tool.

    Copy link

    PR Code Suggestions

    CategorySuggestions                                                                                                                                                       
    Enhancement
    Prevent multiple instances of pulseaudio by checking if it's already running before starting it.

    Consider checking if pulseaudio is already running before attempting to start it. This can
    prevent multiple instances which might lead to unexpected behavior.

    Standalone/start-selenium-standalone.sh [6]

    -pulseaudio -D --exit-idle-time=-1
    +if ! pgrep -x "pulseaudio" > /dev/null
    +then
    +  pulseaudio -D --exit-idle-time=-1
    +fi
     
    Best practice
    Add error handling to pacmd commands to ensure successful execution.

    Add error handling for pacmd commands to ensure each command succeeds before proceeding to
    the next. This can be done by checking the exit status of each command.

    Standalone/start-selenium-standalone.sh [9-13]

    -pacmd load-module module-virtual-sink sink_name=v1
    -pacmd set-default-sink v1
    -pacmd set-default-source v1.monitor
    +if ! pacmd load-module module-virtual-sink sink_name=v1; then
    +  echo "Failed to load virtual sink module"
    +  exit 1
    +fi
    +if ! pacmd set-default-sink v1; then
    +  echo "Failed to set default sink"
    +  exit 1
    +fi
    +if ! pacmd set-default-source v1.monitor; then
    +  echo "Failed to set default source"
    +  exit 1
    +fi
     
    Use a variable for the sink name to simplify modifications and increase flexibility.

    To avoid potential issues with hardcoded sink names, consider using a variable for the
    sink name, making it easier to modify or configure.

    Standalone/start-selenium-standalone.sh [9-13]

    -pacmd load-module module-virtual-sink sink_name=v1
    -pacmd set-default-sink v1
    -pacmd set-default-source v1.monitor
    +SINK_NAME="v1"
    +pacmd load-module module-virtual-sink sink_name=$SINK_NAME
    +pacmd set-default-sink $SINK_NAME
    +pacmd set-default-source $SINK_NAME.monitor
     
    Security
    Ensure the script is run with root privileges for necessary permissions.

    Consider adding a check to ensure the script is run with root privileges, as pulseaudio
    and pacmd might require elevated permissions.

    Standalone/start-selenium-standalone.sh [6]

    +if [ "$(id -u)" != "0" ]; then
    +  echo "This script must be run as root" >&2
    +  exit 1
    +fi
     pulseaudio -D --exit-idle-time=-1
     
    Maintainability
    Centralize pacmd command handling in a function to improve maintainability.

    To improve maintainability, consider creating a function to handle pacmd operations,
    reducing code duplication and centralizing command handling.

    Standalone/start-selenium-standalone.sh [9-13]

    -pacmd load-module module-virtual-sink sink_name=v1
    -pacmd set-default-sink v1
    -pacmd set-default-source v1.monitor
    +function pacmd_handle() {
    +  if ! pacmd "$@"; then
    +    echo "Command failed: pacmd $*"
    +    exit 1
    +  fi
    +}
    +pacmd_handle load-module module-virtual-sink sink_name=v1
    +pacmd_handle set-default-sink v1
    +pacmd_handle set-default-source v1.monitor
     

    ✨ Improve tool usage guide:

    Overview:
    The improve tool scans the PR code changes, and automatically generates suggestions for improving the PR code. The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on a PR.

    • When commenting, to edit configurations related to the improve tool (pr_code_suggestions section), use the following template:
    /improve --pr_code_suggestions.some_config1=... --pr_code_suggestions.some_config2=...
    
    [pr_code_suggestions]
    some_config1=...
    some_config2=...
    

    See the improve usage page for a comprehensive guide on using this tool.

    @VietND96
    Copy link
    Member

    VietND96 commented May 3, 2024

    We will merge this PR after few CI tests are fixed

    @VietND96 VietND96 merged commit fb260f3 into SeleniumHQ:trunk May 5, 2024
    11 checks passed
    @VietND96
    Copy link
    Member

    VietND96 commented May 5, 2024

    Thank you, @edhinard !

    @edhinard
    Copy link
    Contributor Author

    edhinard commented May 6, 2024

    thanks to you and your great job

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    3 participants