Element Policies
Policies choose for some type of elements (PolicyDrivenElement) what media to provide from upstream to downstream. The mechanism is quite extensible and anyone can implement such elements (or policies) in their own element module.
In the standard element library that comes with whisperStreamLib, there is one such a source: SwitchingElement. There are also several standard policies:
RandomPolicy
Randomly chooses a media from the ones that can be listed through the driven element's ListMedia interface.
Parameters:
- int max_history_size_
- keeps at most these many items in the list of media that was played.
- optional bigint state_timeout_sec_
- this determines (in seconds) when the state for such a policy expires after it was last used (we strongly advise to set this for policies associated with non-global elements, else the state would explode)
PlaylistPolicy
Plays media from a list, one item after another, switching upon EOS of one element.
Parameters:
- array<string> playlist_
- a list of media names to play from
- bool loop_playlist_
- determines what to do at the end of the playlist. If this is turned on, will continue from the beginning, else, it will mark an EOS.
- optional bigint state_timeout_sec_
- this determines (in seconds) when the state for such a policy expires after it was last used (we strongly advise to set this for policies associated with non-global elements, else the state would explode)
TimedPlaylistPolicy
Same as PlaylistPolicy, but plays each item in a playlist for at most a period of time
Parameters:
- array<TimePolicySpec?> playlist_
- list of media names to play from (and associated play time - see bellow)
- int empty_policy_
- what to do when a particular playlist element ends befor its allocated time.
Choice of:
- 0 - we replay the playlist item until the time ends
- 1 - we go to the next item in playlist
- 2 - we do nothing and just end for the time to end (basically a big blank in time)
- what to do when a particular playlist element ends befor its allocated time.
Choice of:
- bool loop_playlist_
- determines what to do at the end of the playlist. If this is turned on, will continue from the beginning, else, it will mark an EOS.
- optional bigint state_timeout_sec_
- this determines (in seconds) when the state for such a policy expires after it was last used (we strongly advise to set this for policies associated with non-global elements, else the state would explode)
Parameters for TimePolicySpec:
- bigint time_in_ms_
- how lont to play the current media_name_ (in miliseconds)
- string media_name_
- the playlist item media name.
OnCommandPolicy
This is a policy that switches from one media to another on an RPC command received from the user.
Parameters:
- int max_history_size_
- keeps at most these many items in the list of media that was played.
- string default_media_name_
- when is nothing set by the user (upon EOS in some media), we set automatically this media to be player
- optional bigint state_timeout_sec_
- this determines (in seconds) when the state for such a policy expires after it was last used (we strongly advise to set this for policies associated with non-global elements, else the state would explode)
