From d3f830aa5d35804e7c206b973a8734058cb08fbe Mon Sep 17 00:00:00 2001 From: dec05eba Date: Tue, 6 Aug 2019 16:49:24 +0200 Subject: Fix uninitialized value in videoplayer --- src/QuickMedia.cpp | 5 +++-- src/VideoPlayer.cpp | 17 +++++++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 88c74f9..a9087b1 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -281,12 +281,13 @@ namespace QuickMedia { search_bar->onTextUpdateCallback = nullptr; search_bar->onTextSubmitCallback = nullptr; - std::unique_ptr video_player; + std::unique_ptr video_player = nullptr; try { printf("Play video: %s\n", video_url.c_str()); - video_player = std::make_unique(window_size.x, window_size.y, window.getSystemHandle(), video_url.c_str()); + video_player.reset(new VideoPlayer(window_size.x, window_size.y, window.getSystemHandle(), video_url.c_str())); } catch(VideoInitializationException &e) { fprintf(stderr, "Failed to create video player!. TODO: Show this to the user"); + video_player = nullptr; } std::vector> related_media = current_plugin->get_related_media(video_url); diff --git a/src/VideoPlayer.cpp b/src/VideoPlayer.cpp index 51caa8c..7ce5f19 100644 --- a/src/VideoPlayer.cpp +++ b/src/VideoPlayer.cpp @@ -79,7 +79,11 @@ namespace QuickMedia { if(mpv_initialize(mpv) < 0) throw VideoInitializationException("Failed to initialize mpv"); - //check_error(mpv_set_option_string(mpv, "vo", "opengl-cb")); + // TODO: Enabling vo=gpu will make mpv create its own window, or take over the QuickMedia window fully + // if "wid" option is used. To take advantage of vo=gpu, QuickMedia should create a parent window + // and make mpv use that and then embed that into the parent QuickMedia window. + // This will also remove the need for rendering with sfml (no need for texture copy!). + //check_error(mpv_set_option_string(mpv, "vo", "gpu")); //check_error(mpv_set_option_string(mpv, "hwdec", "auto")); check_error(mpv_set_option_string(mpv, "terminal", "yes")); @@ -95,6 +99,7 @@ namespace QuickMedia { mpv_opengl_init_params opengl_init_params; opengl_init_params.get_proc_address = getProcAddressMpv; opengl_init_params.get_proc_address_ctx = nullptr; + opengl_init_params.extra_exts = nullptr; mpv_render_param params[] = { { MPV_RENDER_PARAM_API_TYPE, (void*)MPV_RENDER_API_TYPE_OPENGL }, { MPV_RENDER_PARAM_OPENGL_INIT_PARAMS, &opengl_init_params }, @@ -114,15 +119,16 @@ namespace QuickMedia { VideoPlayer::~VideoPlayer() { if(mpvGl) { - mpv_render_context_set_update_callback(mpvGl, nullptr, nullptr); + //mpv_render_context_set_update_callback(mpvGl, nullptr, nullptr); mpv_render_context_free(mpvGl); } free(textureBuffer); if(mpv) { - mpv_set_wakeup_callback(mpv, nullptr, nullptr); - mpv_detach_destroy(mpv); + //mpv_set_wakeup_callback(mpv, nullptr, nullptr); + //mpv_detach_destroy(mpv); + mpv_terminate_destroy(mpv); } } @@ -202,8 +208,7 @@ namespace QuickMedia { } void VideoPlayer::draw(sf::RenderWindow &window) { - bool do_event_update = event_update.exchange(false); - if(do_event_update) + if(event_update.exchange(false)) handle_events(); if(textureBuffer && redraw) { -- cgit v1.2.3