From bdd95325ce3b8b3f95316b206b3c4c210ef81c80 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 2 Oct 2022 07:40:14 +0200 Subject: Add mpv option --- src/main.cpp | 187 ++++++++++++++++++++++++++++++------ src/mpv.cpp | 266 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/window_texture.c | 2 +- 3 files changed, 423 insertions(+), 32 deletions(-) create mode 100644 src/mpv.cpp (limited to 'src') diff --git a/src/main.cpp b/src/main.cpp index 0278da1..268a86d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -33,6 +33,7 @@ #include #include "../include/window_texture.h" +#include "../include/mpv.hpp" #include #include @@ -224,6 +225,8 @@ private: // OpenGL bookkeeping FramebufferDesc leftEyeDesc; FramebufferDesc rightEyeDesc; + FramebufferDesc mpvDesc; + bool CreateFrameBuffer( int nWidth, int nHeight, FramebufferDesc &framebufferDesc ); uint32_t m_nRenderWidth; @@ -244,11 +247,17 @@ private: // X compositor bool follow_focused = false; bool focused_window_changed = true; bool focused_window_set = false; - - int mouse_x; - int mouse_y; - int window_width; - int window_height; + const char *mpv_file = nullptr; + Mpv mpv; + bool mpv_render_update = false; + int64_t mpv_video_width = 0; + int64_t mpv_video_height = 0; + bool mpv_video_loaded = false; + + int mouse_x = 0; + int mouse_y = 0; + int window_width = 1; + int window_height = 1; Uint32 window_resize_time; bool window_resized = false; @@ -258,8 +267,8 @@ private: // X compositor int x_fixes_error_base; int prev_visibility_state = VisibilityFullyObscured; - GLint pixmap_texture_width = 0; - GLint pixmap_texture_height = 0; + GLint pixmap_texture_width = 1; + GLint pixmap_texture_height = 1; enum class ViewMode { LEFT_RIGHT, @@ -383,25 +392,26 @@ void dprintf( const char *fmt, ... ) } static void usage() { - fprintf(stderr, "usage: vr-video-player [--sphere|--sphere360|--flat|--plane] [--left-right|--right-left] [--stretch|--no-stretch] [--zoom zoom-level] [--cursor-scale scale] [--cursor-wrap|--no-cursor-wrap] [--follow-focused] \n"); + fprintf(stderr, "usage: vr-video-player [--sphere|--sphere360|--flat|--plane] [--left-right|--right-left] [--stretch|--no-stretch] [--zoom zoom-level] [--cursor-scale scale] [--cursor-wrap|--no-cursor-wrap] [--follow-focused] [--video video] \n"); fprintf(stderr, "\n"); fprintf(stderr, "OPTIONS\n"); - fprintf(stderr, " --sphere View the window as a stereoscopic 180 degrees screen (half sphere). The view will be attached to your head in vr. This is recommended for 180 degrees videos. This is the default value\n"); - fprintf(stderr, " --sphere360 View the window as an equirectangular cube map. This is what is mostly used on youtube, where the video is split into top and bottom as a cubemap. The view will be attached to your head in vr\n"); - fprintf(stderr, " --flat View the window as a stereoscopic flat screen. This is recommended for stereoscopic videos and games\n"); - fprintf(stderr, " --left-right This option is used together with --flat, to specify if the left side of the window is meant to be viewed with the left eye and the right side is meant to be viewed by the right eye. This is the default value\n"); - fprintf(stderr, " --right-left This option is used together with --flat, to specify if the left side of the window is meant to be viewed with the right eye and the right side is meant to be viewed by the left eye\n"); - fprintf(stderr, " --plane View the window as a slightly curved screen. This is recommended for non-stereoscopic content\n"); - fprintf(stderr, " --stretch This option is used together with --flat, To specify if the size of both sides of the window should be combined and stretch to that size when viewed in vr. This is the default value\n"); - fprintf(stderr, " --no-stretch This option is used together with --flat, To specify if the size of one side of the window should be the size of the whole window when viewed in vr. This is the option you want if the window looks too wide\n"); - fprintf(stderr, " --zoom Change the distance to the window. This should be a positive value. In flat and plane modes, this is the distance to the window when the window is reset (with W key or controller trigger button). The default value is 0 for all modes except sphere mode, where the default value is 1. This value is unused for sphere360 mode\n"); - fprintf(stderr, " --cursor-scale Change the size of the cursor. This should be a positive value. If set to 0, then the cursor is hidden. The default value is 1 for all modes except sphere mode, where the default value is 0. The cursor is always hidden in sphere360 mode\n"); - fprintf(stderr, " --cursor-wrap If this option is set, then the cursor position in the vr view will wrap around when it reached the center of the window (i.e when it reaches the edge of one side of the stereoscopic view). This option is only valid for stereoscopic view (flat and sphere modes)\n"); - fprintf(stderr, " --no-cursor-wrap If this option is set, then the cursor position in the vr view will match the the real cursor position inside the window\n"); - fprintf(stderr, " --follow-focused If this option is set, then the selected window will be the focused window. vr-video-player will automatically update when the focused window changes. Either this option or window_id should be used\n"); - fprintf(stderr, " --free-camera If this option is set, then the camera wont follow your position. This option is only applicable when not using --sphere or --sphere360\n"); - fprintf(stderr, " --reduce-flicker A hack to reduce flickering in low resolution text when the headset is not moving by moving the window around quickly by a few pixels\n"); - fprintf(stderr, " window_id The X11 window id of the window to view in vr. This option or --follow-focused is required\n"); + fprintf(stderr, " --sphere View the window as a stereoscopic 180 degrees screen (half sphere). The view will be attached to your head in vr. This is recommended for 180 degrees videos. This is the default value\n"); + fprintf(stderr, " --sphere360 View the window as an equirectangular cube map. This is what is mostly used on youtube, where the video is split into top and bottom as a cubemap. The view will be attached to your head in vr\n"); + fprintf(stderr, " --flat View the window as a stereoscopic flat screen. This is recommended for stereoscopic videos and games\n"); + fprintf(stderr, " --left-right This option is used together with --flat, to specify if the left side of the window is meant to be viewed with the left eye and the right side is meant to be viewed by the right eye. This is the default value\n"); + fprintf(stderr, " --right-left This option is used together with --flat, to specify if the left side of the window is meant to be viewed with the right eye and the right side is meant to be viewed by the left eye\n"); + fprintf(stderr, " --plane View the window as a slightly curved screen. This is recommended for non-stereoscopic content\n"); + fprintf(stderr, " --stretch This option is used together with --flat, To specify if the size of both sides of the window should be combined and stretch to that size when viewed in vr. This is the default value\n"); + fprintf(stderr, " --no-stretch This option is used together with --flat, To specify if the size of one side of the window should be the size of the whole window when viewed in vr. This is the option you want if the window looks too wide\n"); + fprintf(stderr, " --zoom Change the distance to the window. This should be a positive value. In flat and plane modes, this is the distance to the window when the window is reset (with W key or controller trigger button). The default value is 0 for all modes except sphere mode, where the default value is 1. This value is unused for sphere360 mode\n"); + fprintf(stderr, " --cursor-scale Change the size of the cursor. This should be a positive value. If set to 0, then the cursor is hidden. The default value is 1 for all modes except sphere mode, where the default value is 0. The cursor is always hidden in sphere360 mode\n"); + fprintf(stderr, " --cursor-wrap If this option is set, then the cursor position in the vr view will wrap around when it reached the center of the window (i.e when it reaches the edge of one side of the stereoscopic view). This option is only valid for stereoscopic view (flat and sphere modes)\n"); + fprintf(stderr, " --no-cursor-wrap If this option is set, then the cursor position in the vr view will match the the real cursor position inside the window\n"); + fprintf(stderr, " --reduce-flicker A hack to reduce flickering in low resolution text when the headset is not moving by moving the window around quickly by a few pixels\n"); + fprintf(stderr, " --free-camera If this option is set, then the camera wont follow your position\n"); + fprintf(stderr, " --follow-focused If this option is set, then the selected window will be the focused window. vr-video-player will automatically update when the focused window changes. Either this option, --video or window_id should be used\n"); + fprintf(stderr, " --video