Skip to content

utPlayer Class Manual

Ulrond edited this page Oct 15, 2024 · 2 revisions

Overview

The utPlayer class provides a simplified interface for controlling media playback during automated testing. It primarily uses GStreamer to manage media streams but can be extended to support other playback tools.

Class Definition

class utPlayer():
    """
    UT Player class
    """
    def __init__(self, session:object, playerTool:dict={'tool': 'gstreamer', 'prerequisites':[]}, log:logModule=None):
        """
        Initializes player class.

        Args:
            session (class): The session object to communicate with the device.
            log (class, optional): Parent log class. Defaults to None.
        """
        # ... (Initialization logic) ...

    def play(self, streamFile:str):
        """
        Starts the playback of a stream.
        Once started the stream is assumed to be blocking on the device.
        Unless an error occurs, it will remain running.

        Args:
            stream (str): Stream path.
        """
        # ... (Playback logic) ...

    def stop(self):
        """
        Stops the playback of a stream.

        Args:
            None
        """
        # ... (Stop logic) ...

Initialization

To use the utPlayer class, you first need to create an instance of it. The constructor takes the following arguments:

  • session: An object representing the communication session with the device under test. This object should have a write() method to send commands to the device.
  • playerTool (optional): A dictionary specifying the playback tool and any prerequisite commands. Defaults to {'tool': 'gstreamer', 'prerequisites':[]}.
  • log (optional): A logModule object for logging purposes. If not provided, a default logger will be created.

Methods

The utPlayer class has two main methods:

  • play(streamFile): Starts the playback of the specified media file. The streamFile argument should be the full path to the media file.
  • stop(): Stops the current media playback.

Example Usage

# Create an instance of the utPlayer class
player = utPlayer(session=shell)  # Assuming 'shell' is your session object

# Start playing a media file
player.play("/tmp/audioTest.mp3")

# ... (Perform other test actions) ...

# Stop the playback
player.stop()

Extending the Class

The utPlayer class can be extended to support other playback tools besides GStreamer. To do this, you can subclass utPlayer and override the play() and stop() methods to implement the specific logic for the new tool.

Notes

  • The current implementation assumes that the media playback is blocking, meaning the play() method will not return until the playback is finished or an error occurs.
  • The stop() method sends a CTRL-C signal to stop the GStreamer playback. This might need to be adjusted for other playback tools.

This manual provides a basic understanding of the utPlayer class and its usage. For more detailed information and advanced use cases, refer to the code documentation and examples.