From 73b077835dc6085c2642451fa7dbde629b9eadfc Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 9 Aug 2019 03:35:56 +0200 Subject: Readd video seek, make search asynchronous --- include/Body.hpp | 4 +++- include/QuickMedia.hpp | 4 +++- include/VideoPlayer.hpp | 31 +++++++++++++++++++++++++------ 3 files changed, 31 insertions(+), 8 deletions(-) (limited to 'include') diff --git a/include/Body.hpp b/include/Body.hpp index 5d16898..a2db62a 100644 --- a/include/Body.hpp +++ b/include/Body.hpp @@ -20,6 +20,8 @@ namespace QuickMedia { bool visible; }; + using BodyItems = std::vector>; + class Body { public: Body(sf::Font &font); @@ -46,7 +48,7 @@ namespace QuickMedia { sf::Text title_text; sf::Text progress_text; int selected_item; - std::vector> items; + BodyItems items; std::thread thumbnail_load_thread; bool draw_thumbnails; private: diff --git a/include/QuickMedia.hpp b/include/QuickMedia.hpp index 7534439..90ceddd 100644 --- a/include/QuickMedia.hpp +++ b/include/QuickMedia.hpp @@ -1,5 +1,6 @@ #pragma once +#include "Body.hpp" #include "SearchBar.hpp" #include "Page.hpp" #include "Storage.hpp" @@ -9,9 +10,9 @@ #include #include #include +#include namespace QuickMedia { - class Body; class Plugin; class Program { @@ -43,5 +44,6 @@ namespace QuickMedia { Path content_storage_file; Json::Value content_storage_json; std::unordered_set watched_videos; + std::future search_suggestion_future; }; } \ No newline at end of file diff --git a/include/VideoPlayer.hpp b/include/VideoPlayer.hpp index 9d30dc5..2266a16 100644 --- a/include/VideoPlayer.hpp +++ b/include/VideoPlayer.hpp @@ -4,12 +4,14 @@ #include #include #include -#include +#include #include +#include namespace QuickMedia { using EventCallbackFunc = std::function; + using VideoPlayerWindowCreateCallback = std::function; // Currently this video player launches mpv and embeds it into the QuickMedia window class VideoPlayer { @@ -22,11 +24,17 @@ namespace QuickMedia { FAIL_TO_CONNECT_TIMEOUT, FAIL_NOT_CONNECTED, FAIL_TO_SEND, + FAIL_TO_FIND_WINDOW, + FAIL_TO_FIND_WINDOW_TIMEOUT, + UNEXPECTED_WINDOW_ERROR, + FAIL_TO_READ, + READ_TIMEOUT, + READ_INCORRECT_TYPE, INIT_FAILED }; // @event_callback is called from another thread - VideoPlayer(EventCallbackFunc event_callback); + VideoPlayer(EventCallbackFunc event_callback, VideoPlayerWindowCreateCallback window_create_callback); ~VideoPlayer(); VideoPlayer(const VideoPlayer&) = delete; VideoPlayer& operator=(const VideoPlayer&) = delete; @@ -37,20 +45,31 @@ namespace QuickMedia { Error update(); Error toggle_pause(); + + // Progress is in range [0..1] + Error get_progress(double *result); + // Progress is in range [0..1] + Error set_progress(double progress); private: Error send_command(const char *cmd, size_t size); Error launch_video_process(const char *path, sf::WindowHandle parent_window); - void read_ipc_func(); + VideoPlayer::Error read_ipc_func(); private: pid_t video_process_id; int ipc_socket; bool connected_to_ipc; - sf::Clock ipc_connect_retry_timer; + sf::Clock retry_timer; int connect_tries; + int find_window_tries; struct sockaddr_un ipc_addr; char ipc_server_path[L_tmpnam]; EventCallbackFunc event_callback; - std::thread event_read_thread; - bool alive; + VideoPlayerWindowCreateCallback window_create_callback; + sf::WindowHandle window_handle; + sf::WindowHandle parent_window; + Display *display; + unsigned int request_id; + unsigned int expected_request_id; + Json::Value request_response_data; }; } -- cgit v1.2.3-70-g09d2