Wavelength
Privacy-focused, cross-platform, and open-source communication application
Loading...
Searching...
No Matches
video_player.h
Go to the documentation of this file.
1#ifndef VIDEO_PLAYER_OVERLAY_H
2#define VIDEO_PLAYER_OVERLAY_H
3
4#ifdef Q_OS_WINDOWS
5#include <windows.h>
6#include <dwmapi.h>
7#pragma comment(lib, "dwmapi.lib")
8#endif
9
10#include <QDialog>
11
12class VideoDecoder;
13class CyberSlider;
14class CyberPushButton;
15class QLabel;
17
28class VideoPlayer final : public QDialog {
29 Q_OBJECT
33 Q_PROPERTY(double gridOpacity READ GetGridOpacity WRITE SetGridOpacity)
34
35public:
45 explicit VideoPlayer(const QByteArray &video_data, const QString &mime_type, QWidget *parent = nullptr);
46
51 ~VideoPlayer() override;
52
57 void ReleaseResources();
58
63 [[nodiscard]] double GetScanlineOpacity() const { return scanline_opacity_; }
64
70 void SetScanlineOpacity(const double opacity) {
71 scanline_opacity_ = opacity;
72 update();
73 }
74
79 [[nodiscard]] double GetGridOpacity() const { return grid_opacity_; }
80
86 void SetGridOpacity(const double opacity) {
87 grid_opacity_ = opacity;
88 update();
89 }
90
91protected:
96 void paintEvent(QPaintEvent *event) override;
97
103 void closeEvent(QCloseEvent *event) override;
104
105private slots:
111 void InitializePlayer();
112
118 void TogglePlayback();
119
124 void OnSliderPressed();
125
131 void OnSliderReleased();
132
138 void UpdateTimeLabel(int position) const;
139
146 void UpdateSliderPosition(double position) const;
147
153 void SeekVideo(int position) const;
154
161 void UpdateFrame(const QImage &frame);
162
168 void UpdateUI();
169
175 void HandleError(const QString &message) const;
176
187 void HandleVideoInfo(int width, int height, double fps, double duration);
188
194 void AdjustVolume(int volume) const;
195
200 void ToggleMute();
201
207 void UpdateVolumeIcon(float volume) const;
208
214 void TriggerGlitch();
215
216private:
224 QLabel *time_label_;
238 QLabel *fps_label_;
239
241 std::shared_ptr<VideoDecoder> decoder_;
246
248 QByteArray video_data_;
249
255 double video_duration_ = 0;
257 bool slider_dragging_ = false;
259 int last_volume_ = 100;
261 bool playback_finished_ = false;
263 bool was_playing_ = false;
266
272 bool show_hud_ = false;
276 bool playback_started_ = false;
280 double video_fps_ = 60.0; // Default FPS
283};
284
285#endif //VIDEO_PLAYER_OVERLAY_H
A custom QPushButton styled with a cyberpunk aesthetic, featuring pulsing glow effects.
Definition cyber_push_button.h:15
A custom QSlider styled with a general cyberpunk aesthetic (blue theme).
Definition cyber_slider.h:13
Manages the loading and delivery of translations for applications.
Definition translation_manager.h:15
Decodes video data frame by frame using FFmpeg libraries in a separate thread.
Definition video_decoder.h:42
bool slider_dragging_
Flag indicating if the user is currently dragging the progress slider.
Definition video_player.h:257
std::shared_ptr< VideoDecoder > decoder_
Shared pointer to the VideoDecoder instance responsible for decoding and playback.
Definition video_player.h:241
QLabel * bitrate_label_
Label displaying estimated video bitrate.
Definition video_player.h:236
CyberPushButton * play_button_
Custom button for play/pause/replay control.
Definition video_player.h:220
bool playback_started_
Flag indicating if the decoder has started processing (video info received).
Definition video_player.h:276
void SetScanlineOpacity(const double opacity)
Sets the opacity for the scanline effect. Triggers an update() to repaint the widget.
Definition video_player.h:70
void TriggerGlitch()
Slot called periodically by glitch_timer_. Sets a random intensity for the glitch effect applied in U...
Definition video_player.cpp:579
double gridOpacity
Property controlling the opacity of the background grid effect. Animatable.
Definition video_player.h:33
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...
Definition video_player.cpp:514
void OnSliderPressed()
Slot called when the user presses the progress slider. Remembers the playback state,...
Definition video_player.cpp:320
void UpdateFrame(const QImage &frame)
Slot connected to the decoder's frameReady signal. Displays the received video frame in the video_lab...
Definition video_player.cpp:388
QLabel * codec_label_
Label displaying detected video codec information.
Definition video_player.h:232
QTimer * glitch_timer_
Timer for triggering random glitch effects.
Definition video_player.h:245
void AdjustVolume(int volume) const
Adjusts the playback volume via the VideoDecoder. Also updates the volume icon based on the new volum...
Definition video_player.cpp:550
void UpdateSliderPosition(double position) const
Slot connected to the decoder's positionChanged signal. Updates the progress slider's position and th...
Definition video_player.cpp:360
QLabel * resolution_label_
Label displaying video resolution.
Definition video_player.h:234
QByteArray video_data_
Stores the raw video data passed in the constructor.
Definition video_player.h:248
void SeekVideo(int position) const
Initiates a seek operation in the VideoDecoder. Converts the slider position (milliseconds) to second...
Definition video_player.cpp:380
void paintEvent(QPaintEvent *event) override
Overridden paint event handler. Draws the background grid overlay.
Definition video_player.cpp:216
void ReleaseResources()
Stops the decoder thread, waits for it to finish, releases its resources, and resets the pointer....
Definition video_player.cpp:206
QLabel * video_label_
QLabel used to display the video frames.
Definition video_player.h:218
VideoPlayer(const QByteArray &video_data, const QString &mime_type, QWidget *parent=nullptr)
Constructs a VideoPlayerOverlay dialog. Initializes the cyberpunk UI elements, sets window properties...
Definition video_player.cpp:16
void InitializePlayer()
Initializes the VideoDecoder instance and connects its signals. Creates the decoder,...
Definition video_player.cpp:249
void UpdateTimeLabel(int position) const
Slot called when the progress slider's value changes (e.g., user dragging). Updates the time label di...
Definition video_player.cpp:341
void ToggleMute()
Toggles the mute state. If currently unmuted, mutes and remembers the last volume....
Definition video_player.cpp:558
QImage thumbnail_frame_
Stores the first frame extracted from the video, used as a thumbnail/fallback.
Definition video_player.h:265
void UpdateUI()
Slot called periodically by update_timer_. Updates UI elements like pulsing effects (scanline/grid op...
Definition video_player.cpp:487
CyberPushButton * volume_button_
Custom button for toggling mute. Icon changes based on volume.
Definition video_player.h:226
int video_height_
Original height of the video in pixels. Set by HandleVideoInfo.
Definition video_player.h:253
double video_duration_
Total duration of the video in seconds. Set by HandleVideoInfo.
Definition video_player.h:255
double scanlineOpacity
Property controlling the opacity of the scanline effect overlay. Animatable.
Definition video_player.h:31
void UpdateVolumeIcon(float volume) const
Updates the volume button icon based on the current volume level. Shows different icons for muted,...
Definition video_player.cpp:569
QLabel * time_label_
Label displaying current time / total duration (MM:SS / MM:SS).
Definition video_player.h:224
double GetScanlineOpacity() const
Gets the current opacity value for the scanline effect.
Definition video_player.h:63
void HandleVideoInfo(int width, int height, double fps, double duration)
Slot connected to the decoder's videoInfo signal. Stores video dimensions, duration,...
Definition video_player.cpp:520
QTimer * update_timer_
Timer for triggering periodic UI updates (pulsing effects, status).
Definition video_player.h:243
double scanline_opacity_
Current opacity value for the scanline effect (property).
Definition video_player.h:268
int frame_counter_
Counter for the frame number displayed in the HUD.
Definition video_player.h:274
bool show_hud_
Flag indicating whether to draw the HUD elements (corners, etc.). Enabled after video info is ready.
Definition video_player.h:272
double current_glitch_intensity_
Current intensity level for the random glitch effect.
Definition video_player.h:278
void SetGridOpacity(const double opacity)
Sets the opacity for the background grid effect. Triggers an update() to repaint the widget.
Definition video_player.h:86
double GetGridOpacity() const
Gets the current opacity value for the background grid effect.
Definition video_player.h:79
int video_width_
Original width of the video in pixels. Set by HandleVideoInfo.
Definition video_player.h:251
bool playback_finished_
Flag indicating if playback has reached the end.
Definition video_player.h:261
QLabel * fps_label_
Label displaying video frames per second.
Definition video_player.h:238
int last_volume_
Stores the volume level before muting.
Definition video_player.h:259
QLabel * status_label_
Label displaying playback status (Initializing, Ready, Playing, Paused, Error, Finished).
Definition video_player.h:230
void closeEvent(QCloseEvent *event) override
Overridden close event handler. Stops timers and releases decoder resources before closing the dialog...
Definition video_player.cpp:237
CyberSlider * progress_slider_
Custom slider for displaying and seeking playback progress.
Definition video_player.h:222
TranslationManager * translator_
Pointer to the translation manager for handling UI translations.
Definition video_player.h:282
CyberSlider * volume_slider_
Custom slider for controlling playback volume.
Definition video_player.h:228
void TogglePlayback()
Toggles the playback state (play/pause) or resets if finished. If finished, resets the decoder....
Definition video_player.cpp:278
void OnSliderReleased()
Slot called when the user releases the progress slider. Performs the seek operation based on the slid...
Definition video_player.cpp:329
bool was_playing_
Stores whether playback was active before the user started dragging the slider.
Definition video_player.h:263
double video_fps_
Video frame rate in frames per second. Set by HandleVideoInfo.
Definition video_player.h:280
double grid_opacity_
Current opacity value for the background grid effect (property).
Definition video_player.h:270