Wavelength
Privacy-focused, cross-platform, and open-source communication application
Loading...
Searching...
No Matches
VideoPlayer Class Referencefinal

A QDialog overlay for playing videos with a cyberpunk aesthetic. More...

#include <video_player.h>

Inheritance diagram for VideoPlayer:
Collaboration diagram for VideoPlayer:

Public Member Functions

double GetGridOpacity () const
 Gets the current opacity value for the background grid effect.
 
double GetScanlineOpacity () const
 Gets the current opacity value for the scanline effect.
 
void ReleaseResources ()
 Stops the decoder thread, waits for it to finish, releases its resources, and resets the pointer. Ensures proper cleanup of the VideoDecoder instance.
 
void SetGridOpacity (const double opacity)
 Sets the opacity for the background grid effect. Triggers an update() to repaint the widget.
 
void SetScanlineOpacity (const double opacity)
 Sets the opacity for the scanline effect. Triggers an update() to repaint the widget.
 
 VideoPlayer (const QByteArray &video_data, const QString &mime_type, QWidget *parent=nullptr)
 Constructs a VideoPlayerOverlay dialog. Initializes the cyberpunk UI elements, sets window properties (title, size, style), creates timers for UI updates and effects, connects signals for controls, and schedules the player initialization.
 
 ~VideoPlayer () override
 Destructor. Stops timers and ensures decoder resources are released by calling ReleaseResources().
 

Protected Member Functions

void closeEvent (QCloseEvent *event) override
 Overridden close event handler. Stops timers and releases decoder resources before closing the dialog.
 
void paintEvent (QPaintEvent *event) override
 Overridden paint event handler. Draws the background grid overlay.
 

Properties

double gridOpacity
 Property controlling the opacity of the background grid effect. Animatable.
 
double scanlineOpacity
 Property controlling the opacity of the scanline effect overlay. Animatable.
 

Private Slots

void AdjustVolume (int volume) const
 Adjusts the playback volume via the VideoDecoder. Also updates the volume icon based on the new volume level.
 
void HandleError (const QString &message) const
 Slot connected to the decoder's error signal. Logs the error and displays it in the status_label_ and video_label_.
 
void HandleVideoInfo (int width, int height, double fps, double duration)
 Slot connected to the decoder's videoInfo signal. Stores video dimensions, duration, FPS. Sets the progress slider range. Updates info labels (resolution, bitrate, FPS, codec). Adjusts an update timer interval. Enables the HUD display. Extracts the first frame for a thumbnail.
 
void InitializePlayer ()
 Initializes the VideoDecoder instance and connects its signals. Creates the decoder, connects signals for frames, errors, info, finish, and position. Starts the decoder thread. Called automatically after a short delay.
 
void OnSliderPressed ()
 Slot called when the user presses the progress slider. Remembers the playback state, pauses playback temporarily, and updates the status label.
 
void OnSliderReleased ()
 Slot called when the user releases the progress slider. Performs the seek operation based on the slider's final position. Resumes playback if it was active before seeking. Updates status label.
 
void SeekVideo (int position) const
 Initiates a seek operation in the VideoDecoder. Converts the slider position (milliseconds) to seconds before calling decoder_->Seek().
 
void ToggleMute ()
 Toggles the mute state. If currently unmuted, mutes and remembers the last volume. If muted, restores the last volume.
 
void TogglePlayback ()
 Toggles the playback state (play/pause) or resets if finished. If finished, resets the decoder. Otherwise, calls Pause() on the decoder. Updates button text and status label accordingly. Triggers UI animations.
 
void TriggerGlitch ()
 Slot called periodically by glitch_timer_. Sets a random intensity for the glitch effect applied in UpdateFrame() and schedules the next glitch event.
 
void UpdateFrame (const QImage &frame)
 Slot connected to the decoder's frameReady signal. Displays the received video frame in the video_label_. Handles scaling, letterboxing, scanline effects, optional HUD elements (corners, timestamp, frame counter), and glitch effects.
 
void UpdateSliderPosition (double position) const
 Slot connected to the decoder's positionChanged signal. Updates the progress slider's position and the time label display based on the decoder's current playback position. Blocks slider signals during update to prevent feedback loops.
 
void UpdateTimeLabel (int position) const
 Slot called when the progress slider's value changes (e.g., user dragging). Updates the time label display based on the slider's current position (without seeking yet).
 
void UpdateUI ()
 Slot called periodically by update_timer_. Updates UI elements like pulsing effects (scanline/grid opacity) and occasionally updates the status label with random "technical" info. Triggers widget repaint.
 
void UpdateVolumeIcon (float volume) const
 Updates the volume button icon based on the current volume level. Shows different icons for muted, low volume, and high volume.
 

Private Attributes

QLabel * bitrate_label_
 Label displaying estimated video bitrate.
 
QLabel * codec_label_
 Label displaying detected video codec information.
 
double current_glitch_intensity_ = 0.0
 Current intensity level for the random glitch effect.
 
std::shared_ptr< VideoDecoderdecoder_
 Shared pointer to the VideoDecoder instance responsible for decoding and playback.
 
QLabel * fps_label_
 Label displaying video frames per second.
 
int frame_counter_ = 0
 Counter for the frame number displayed in the HUD.
 
QTimer * glitch_timer_
 Timer for triggering random glitch effects.
 
double grid_opacity_
 Current opacity value for the background grid effect (property).
 
int last_volume_ = 100
 Stores the volume level before muting.
 
CyberPushButtonplay_button_
 Custom button for play/pause/replay control.
 
bool playback_finished_ = false
 Flag indicating if playback has reached the end.
 
bool playback_started_ = false
 Flag indicating if the decoder has started processing (video info received).
 
CyberSliderprogress_slider_
 Custom slider for displaying and seeking playback progress.
 
QLabel * resolution_label_
 Label displaying video resolution.
 
double scanline_opacity_
 Current opacity value for the scanline effect (property).
 
bool show_hud_ = false
 Flag indicating whether to draw the HUD elements (corners, etc.). Enabled after video info is ready.
 
bool slider_dragging_ = false
 Flag indicating if the user is currently dragging the progress slider.
 
QLabel * status_label_
 Label displaying playback status (Initializing, Ready, Playing, Paused, Error, Finished).
 
QImage thumbnail_frame_
 Stores the first frame extracted from the video, used as a thumbnail/fallback.
 
QLabel * time_label_
 Label displaying current time / total duration (MM:SS / MM:SS).
 
TranslationManagertranslator_ = nullptr
 Pointer to the translation manager for handling UI translations.
 
QTimer * update_timer_
 Timer for triggering periodic UI updates (pulsing effects, status).
 
QByteArray video_data_
 Stores the raw video data passed in the constructor.
 
double video_duration_ = 0
 Total duration of the video in seconds. Set by HandleVideoInfo.
 
double video_fps_ = 60.0
 Video frame rate in frames per second. Set by HandleVideoInfo.
 
int video_height_ = 0
 Original height of the video in pixels. Set by HandleVideoInfo.
 
QLabel * video_label_
 QLabel used to display the video frames.
 
int video_width_ = 0
 Original width of the video in pixels. Set by HandleVideoInfo.
 
CyberPushButtonvolume_button_
 Custom button for toggling mute. Icon changes based on volume.
 
CyberSlidervolume_slider_
 Custom slider for controlling playback volume.
 
bool was_playing_ = false
 Stores whether playback was active before the user started dragging the slider.
 

Detailed Description

A QDialog overlay for playing videos with a cyberpunk aesthetic.

This class provides a full-featured video player in a separate dialog window. It uses VideoDecoder for decoding and playback, includes custom cyberpunk-styled UI controls (buttons, sliders), displays video information (codec, resolution, etc.), and incorporates visual effects like scanlines, grid overlays, and random glitches. It handles playback control (play/pause, seek, volume), manages decoder resources, and provides visual feedback on the player's status.

Constructor & Destructor Documentation

◆ VideoPlayer()

VideoPlayer::VideoPlayer ( const QByteArray & video_data,
const QString & mime_type,
QWidget * parent = nullptr )
explicit

Constructs a VideoPlayerOverlay dialog. Initializes the cyberpunk UI elements, sets window properties (title, size, style), creates timers for UI updates and effects, connects signals for controls, and schedules the player initialization.

Parameters
video_dataThe raw video data to be played.
mime_typeThe MIME type of the video data (currently unused).
parentOptional parent widget.
Here is the call graph for this function:

◆ ~VideoPlayer()

VideoPlayer::~VideoPlayer ( )
override

Destructor. Stops timers and ensures decoder resources are released by calling ReleaseResources().

Here is the call graph for this function:

Member Function Documentation

◆ AdjustVolume

void VideoPlayer::AdjustVolume ( int volume) const
privateslot

Adjusts the playback volume via the VideoDecoder. Also updates the volume icon based on the new volume level.

Parameters
volumeThe desired volume level (0-100, corresponding to 0.0-1.0 float).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ closeEvent()

void VideoPlayer::closeEvent ( QCloseEvent * event)
overrideprotected

Overridden close event handler. Stops timers and releases decoder resources before closing the dialog.

Parameters
eventThe close event.
Here is the call graph for this function:

◆ GetGridOpacity()

double VideoPlayer::GetGridOpacity ( ) const
inlinenodiscard

Gets the current opacity value for the background grid effect.

Returns
The grid opacity (0.0 to 1.0).

◆ GetScanlineOpacity()

double VideoPlayer::GetScanlineOpacity ( ) const
inlinenodiscard

Gets the current opacity value for the scanline effect.

Returns
The scanline opacity (0.0 to 1.0).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ HandleError

void VideoPlayer::HandleError ( const QString & message) const
privateslot

Slot connected to the decoder's error signal. Logs the error and displays it in the status_label_ and video_label_.

Parameters
messageThe error message from the decoder.
Here is the caller graph for this function:

◆ HandleVideoInfo

void VideoPlayer::HandleVideoInfo ( int width,
int height,
double fps,
double duration )
privateslot

Slot connected to the decoder's videoInfo signal. Stores video dimensions, duration, FPS. Sets the progress slider range. Updates info labels (resolution, bitrate, FPS, codec). Adjusts an update timer interval. Enables the HUD display. Extracts the first frame for a thumbnail.

Parameters
widthVideo width in pixels.
heightVideo height in pixels.
fpsVideo frame rate.
durationVideo duration in seconds.
Here is the caller graph for this function:

◆ InitializePlayer

void VideoPlayer::InitializePlayer ( )
privateslot

Initializes the VideoDecoder instance and connects its signals. Creates the decoder, connects signals for frames, errors, info, finish, and position. Starts the decoder thread. Called automatically after a short delay.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnSliderPressed

void VideoPlayer::OnSliderPressed ( )
privateslot

Slot called when the user presses the progress slider. Remembers the playback state, pauses playback temporarily, and updates the status label.

Here is the caller graph for this function:

◆ OnSliderReleased

void VideoPlayer::OnSliderReleased ( )
privateslot

Slot called when the user releases the progress slider. Performs the seek operation based on the slider's final position. Resumes playback if it was active before seeking. Updates status label.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ paintEvent()

void VideoPlayer::paintEvent ( QPaintEvent * event)
overrideprotected

Overridden paint event handler. Draws the background grid overlay.

Parameters
eventThe paint event.

◆ ReleaseResources()

void VideoPlayer::ReleaseResources ( )

Stops the decoder thread, waits for it to finish, releases its resources, and resets the pointer. Ensures proper cleanup of the VideoDecoder instance.

Here is the caller graph for this function:

◆ SeekVideo

void VideoPlayer::SeekVideo ( int position) const
privateslot

Initiates a seek operation in the VideoDecoder. Converts the slider position (milliseconds) to seconds before calling decoder_->Seek().

Parameters
positionThe target position in milliseconds.
Here is the caller graph for this function:

◆ SetGridOpacity()

void VideoPlayer::SetGridOpacity ( const double opacity)
inline

Sets the opacity for the background grid effect. Triggers an update() to repaint the widget.

Parameters
opacityThe desired grid opacity (0.0 to 1.0).
Here is the caller graph for this function:

◆ SetScanlineOpacity()

void VideoPlayer::SetScanlineOpacity ( const double opacity)
inline

Sets the opacity for the scanline effect. Triggers an update() to repaint the widget.

Parameters
opacityThe desired scanline opacity (0.0 to 1.0).
Here is the caller graph for this function:

◆ ToggleMute

void VideoPlayer::ToggleMute ( )
privateslot

Toggles the mute state. If currently unmuted, mutes and remembers the last volume. If muted, restores the last volume.

Here is the caller graph for this function:

◆ TogglePlayback

void VideoPlayer::TogglePlayback ( )
privateslot

Toggles the playback state (play/pause) or resets if finished. If finished, resets the decoder. Otherwise, calls Pause() on the decoder. Updates button text and status label accordingly. Triggers UI animations.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TriggerGlitch

void VideoPlayer::TriggerGlitch ( )
privateslot

Slot called periodically by glitch_timer_. Sets a random intensity for the glitch effect applied in UpdateFrame() and schedules the next glitch event.

Here is the caller graph for this function:

◆ UpdateFrame

void VideoPlayer::UpdateFrame ( const QImage & frame)
privateslot

Slot connected to the decoder's frameReady signal. Displays the received video frame in the video_label_. Handles scaling, letterboxing, scanline effects, optional HUD elements (corners, timestamp, frame counter), and glitch effects.

Parameters
frameThe newly decoded video frame.
Here is the caller graph for this function:

◆ UpdateSliderPosition

void VideoPlayer::UpdateSliderPosition ( double position) const
privateslot

Slot connected to the decoder's positionChanged signal. Updates the progress slider's position and the time label display based on the decoder's current playback position. Blocks slider signals during update to prevent feedback loops.

Parameters
positionThe current playback position in seconds.
Here is the caller graph for this function:

◆ UpdateTimeLabel

void VideoPlayer::UpdateTimeLabel ( int position) const
privateslot

Slot called when the progress slider's value changes (e.g., user dragging). Updates the time label display based on the slider's current position (without seeking yet).

Parameters
positionThe slider's current value (milliseconds).
Here is the caller graph for this function:

◆ UpdateUI

void VideoPlayer::UpdateUI ( )
privateslot

Slot called periodically by update_timer_. Updates UI elements like pulsing effects (scanline/grid opacity) and occasionally updates the status label with random "technical" info. Triggers widget repaint.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ UpdateVolumeIcon

void VideoPlayer::UpdateVolumeIcon ( float volume) const
privateslot

Updates the volume button icon based on the current volume level. Shows different icons for muted, low volume, and high volume.

Parameters
volumeThe current volume level (0.0 to 1.0).
Here is the caller graph for this function:

Member Data Documentation

◆ bitrate_label_

QLabel* VideoPlayer::bitrate_label_
private

Label displaying estimated video bitrate.

◆ codec_label_

QLabel* VideoPlayer::codec_label_
private

Label displaying detected video codec information.

◆ current_glitch_intensity_

double VideoPlayer::current_glitch_intensity_ = 0.0
private

Current intensity level for the random glitch effect.

◆ decoder_

std::shared_ptr<VideoDecoder> VideoPlayer::decoder_
private

Shared pointer to the VideoDecoder instance responsible for decoding and playback.

◆ fps_label_

QLabel* VideoPlayer::fps_label_
private

Label displaying video frames per second.

◆ frame_counter_

int VideoPlayer::frame_counter_ = 0
private

Counter for the frame number displayed in the HUD.

◆ glitch_timer_

QTimer* VideoPlayer::glitch_timer_
private

Timer for triggering random glitch effects.

◆ grid_opacity_

double VideoPlayer::grid_opacity_
private

Current opacity value for the background grid effect (property).

◆ last_volume_

int VideoPlayer::last_volume_ = 100
private

Stores the volume level before muting.

◆ play_button_

CyberPushButton* VideoPlayer::play_button_
private

Custom button for play/pause/replay control.

◆ playback_finished_

bool VideoPlayer::playback_finished_ = false
private

Flag indicating if playback has reached the end.

◆ playback_started_

bool VideoPlayer::playback_started_ = false
private

Flag indicating if the decoder has started processing (video info received).

◆ progress_slider_

CyberSlider* VideoPlayer::progress_slider_
private

Custom slider for displaying and seeking playback progress.

◆ resolution_label_

QLabel* VideoPlayer::resolution_label_
private

Label displaying video resolution.

◆ scanline_opacity_

double VideoPlayer::scanline_opacity_
private

Current opacity value for the scanline effect (property).

◆ show_hud_

bool VideoPlayer::show_hud_ = false
private

Flag indicating whether to draw the HUD elements (corners, etc.). Enabled after video info is ready.

◆ slider_dragging_

bool VideoPlayer::slider_dragging_ = false
private

Flag indicating if the user is currently dragging the progress slider.

◆ status_label_

QLabel* VideoPlayer::status_label_
private

Label displaying playback status (Initializing, Ready, Playing, Paused, Error, Finished).

◆ thumbnail_frame_

QImage VideoPlayer::thumbnail_frame_
private

Stores the first frame extracted from the video, used as a thumbnail/fallback.

◆ time_label_

QLabel* VideoPlayer::time_label_
private

Label displaying current time / total duration (MM:SS / MM:SS).

◆ translator_

TranslationManager* VideoPlayer::translator_ = nullptr
private

Pointer to the translation manager for handling UI translations.

◆ update_timer_

QTimer* VideoPlayer::update_timer_
private

Timer for triggering periodic UI updates (pulsing effects, status).

◆ video_data_

QByteArray VideoPlayer::video_data_
private

Stores the raw video data passed in the constructor.

◆ video_duration_

double VideoPlayer::video_duration_ = 0
private

Total duration of the video in seconds. Set by HandleVideoInfo.

◆ video_fps_

double VideoPlayer::video_fps_ = 60.0
private

Video frame rate in frames per second. Set by HandleVideoInfo.

◆ video_height_

int VideoPlayer::video_height_ = 0
private

Original height of the video in pixels. Set by HandleVideoInfo.

◆ video_label_

QLabel* VideoPlayer::video_label_
private

QLabel used to display the video frames.

◆ video_width_

int VideoPlayer::video_width_ = 0
private

Original width of the video in pixels. Set by HandleVideoInfo.

◆ volume_button_

CyberPushButton* VideoPlayer::volume_button_
private

Custom button for toggling mute. Icon changes based on volume.

◆ volume_slider_

CyberSlider* VideoPlayer::volume_slider_
private

Custom slider for controlling playback volume.

◆ was_playing_

bool VideoPlayer::was_playing_ = false
private

Stores whether playback was active before the user started dragging the slider.

Property Documentation

◆ gridOpacity

double VideoPlayer::gridOpacity
readwrite

Property controlling the opacity of the background grid effect. Animatable.

◆ scanlineOpacity

double VideoPlayer::scanlineOpacity
readwrite

Property controlling the opacity of the scanline effect overlay. Animatable.


The documentation for this class was generated from the following files: