Input.java

Overview

`Input.java` defines an enumeration `Input` representing the various input events or triggers that drive the state transitions within a finite state machine (FSM) managing media playback and ad interactions in the Tubi TV media player system.

Each enum constant corresponds to a specific input event expected by one or more concrete FSM states. These inputs represent key moments in ad fetching, ad playing, movie playback, error handling, and user interactions with ads. By modeling inputs as an enum, the FSM implementation gains type safety, clarity, and easier maintenance.

This file is a core part of the FSM subsystem (`com.tubitv.media.fsm` package), enabling different FSM states (found in subpackages such as `concrete` and specific classes like `VastAdInteractionSandBoxState`) to react consistently to external and internal triggers.


Enum: Input

`Input` is an enum that enumerates all possible input events recognizable by the media FSM. Each input corresponds to a particular state or group of states within the FSM, as indicated by associated comments referencing those states.

Enum Constants and Their Intended Contexts

Input Constant

Expected State(s) / Usage Context

Description

`HAS_PREROLL_AD`

`FetchCuePointState`

Indicates that a pre-roll ad is available after fetching cue points.

`NO_PREROLL_AD`

`FetchCuePointState`

Indicates that no pre-roll ad is available.

`PRE_ROLL_AD_RECEIVED`

`MakingPrerollAdCallState`

Signals that the pre-roll ad has been successfully received.

`AD_RECEIVED`

`MakingAdCallState`

Signals that an ad has been successfully received during an ad call.

`EMPTY_AD`

`MakingAdCallState`

Indicates that no ad was returned in the ad call.

`SHOW_ADS`

`ReceiveAdState`

Triggers the state to show ads to the user.

`NEXT_AD`

`AdPlayingState`

Command to play the next ad in the sequence.

`AD_CLICK`

`AdPlayingState`

Input triggered when the user clicks on an ad.

`AD_FINISH`

`AdPlayingState`

Indicates that the current ad has finished playing.

`VPAID_MANIFEST`

`AdPlayingState`

Indicates receipt of a VPAID (Video Player-Ad Interface Definition) manifest.

`VPAID_FINISH`

`VpaidState`

Signals the completion of a VPAID ad.

`BACK_TO_PLAYER_FROM_VAST_AD`

`VastAdInteractionSandBoxState`

Signals returning to the main player from the VAST ad interaction sandbox.

`MAKE_AD_CALL`

`MoviePlayingState`

Command to initiate an ad call during movie playback.

`MOVIE_FINISH`

`MoviePlayingState`

Indicates that the movie playback has finished.

`ERROR`

Error handling input

Represents an error state or event in the FSM.

`INITIALIZE`

Generic initialization input

Used to initialize or reset the FSM or related components.

Usage Example

// Example usage in FSM state transition logic:
switch (input) {
    case HAS_PREROLL_AD:
        // Transition to preroll ad setup state
        fsm.transitionTo(PrerollAdSetupState.class);
        break;
    case AD_FINISH:
        // Proceed to next ad or resume content playback
        fsm.transitionTo(NextAdOrContentState.class);
        break;
    case ERROR:
        // Handle error scenario
        fsm.transitionTo(ErrorState.class);
        break;
    default:
        // Handle other inputs or ignore
        break;
}

Implementation Details


Interactions with Other Components


Visual Diagram

The following Mermaid class diagram illustrates the `Input` enum with its constants, highlighting its role as an event source for FSM states.

classDiagram
    class Input {
        <<enumeration>>
        +HAS_PREROLL_AD
        +NO_PREROLL_AD
        +PRE_ROLL_AD_RECEIVED
        +AD_RECEIVED
        +EMPTY_AD
        +SHOW_ADS
        +NEXT_AD
        +AD_CLICK
        +AD_FINISH
        +VPAID_MANIFEST
        +VPAID_FINISH
        +BACK_TO_PLAYER_FROM_VAST_AD
        +MAKE_AD_CALL
        +MOVIE_FINISH
        +ERROR
        +INITIALIZE
    }

    %% FSM States that consume Input events
    class FetchCuePointState
    class MakingPrerollAdCallState
    class MakingAdCallState
    class ReceiveAdState
    class AdPlayingState
    class VpaidState
    class VastAdInteractionSandBoxState
    class MoviePlayingState
    class ErrorState

    Input <|-- FetchCuePointState : expects HAS_PREROLL_AD, NO_PREROLL_AD
    Input <|-- MakingPrerollAdCallState : expects PRE_ROLL_AD_RECEIVED
    Input <|-- MakingAdCallState : expects AD_RECEIVED, EMPTY_AD
    Input <|-- ReceiveAdState : expects SHOW_ADS
    Input <|-- AdPlayingState : expects NEXT_AD, AD_CLICK, AD_FINISH, VPAID_MANIFEST
    Input <|-- VpaidState : expects VPAID_FINISH
    Input <|-- VastAdInteractionSandBoxState : expects BACK_TO_PLAYER_FROM_VAST_AD
    Input <|-- MoviePlayingState : expects MAKE_AD_CALL, MOVIE_FINISH
    Input <|-- ErrorState : expects ERROR

Summary


This documentation should allow developers and architects to understand the role, usage, and context of `Input.java` within the wider media FSM system.