aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-06-14 08:54:55 +0200
committerdec05eba <dec05eba@protonmail.com>2021-06-14 08:54:55 +0200
commit2c0347ff7a13896dcc64c1deb4447449790bad73 (patch)
tree9d12802eef11fda8646454e6e79e25546359181f
parentd37b3a7aac87e5f60c49202c824d985e53b7b544 (diff)
Workaround shitty mpv pulseaudio issue where the video is frozen. Try reloading video on failure to load
-rw-r--r--TODO2
-rw-r--r--src/QuickMedia.cpp31
-rw-r--r--src/VideoPlayer.cpp1
-rw-r--r--src/plugins/Youtube.cpp22
4 files changed, 35 insertions, 21 deletions
diff --git a/TODO b/TODO
index ee42725..da02130 100644
--- a/TODO
+++ b/TODO
@@ -166,4 +166,4 @@ Add youtube chapters.
Disable drop shadow on pinephone.
Load the next page in chapter list when reaching the bottom (when going to previous chapters in image view).
Loading image background should be rounded.
-Workaround mpv issue where video is frozen after seeking (with and without cache enabled, but more often with cache enabled). \ No newline at end of file
+Workaround mpv issue where video is frozen after seeking (with and without cache enabled, but more often with cache enabled). This happens because of audio. Reloading audio fixes this but audio will then be gone. \ No newline at end of file
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index c6a1d2f..0513862 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -2451,7 +2451,6 @@ namespace QuickMedia {
void Program::video_content_page(Page *parent_page, VideoPage *video_page, std::string video_title, bool download_if_streaming_fails, BodyItems &next_play_items, int play_index, int *parent_body_page, const std::string &parent_page_search) {
PageType previous_page = pop_page_stack();
- sf::Clock time_watched_timer;
bool video_loaded = false;
std::string youtube_video_id_dummy;
const bool is_youtube = youtube_url_extract_id(video_page->get_url(), youtube_video_id_dummy);
@@ -2483,7 +2482,11 @@ namespace QuickMedia {
sf::Clock seeking_start_timer;
const float seeking_restart_timeout_sec = 4.0f; // TODO: Test if this timeout is good on slow hardware such as pinephone and slow internet
- auto load_video_error_check = [this, &in_seeking, &video_url, &audio_url, &video_title, &video_tasks, &channel_url, previous_page, &go_to_previous_page, &time_watched_timer, &video_loaded, video_page, &video_event_callback, &on_window_create, &video_player_window, is_youtube, is_matrix, download_if_streaming_fails](std::string start_time = "", bool reuse_media_source = false) mutable {
+ const int num_load_tries_max = 3;
+ int load_try = 0;
+ std::string prev_start_time;
+
+ auto load_video_error_check = [this, &prev_start_time, &in_seeking, &video_url, &audio_url, &video_title, &video_tasks, &channel_url, previous_page, &go_to_previous_page, &video_loaded, video_page, &video_event_callback, &on_window_create, &video_player_window, is_youtube, is_matrix, download_if_streaming_fails](std::string start_time = "", bool reuse_media_source = false) mutable {
video_player.reset();
channel_url.clear();
video_loaded = false;
@@ -2541,8 +2544,8 @@ namespace QuickMedia {
const bool is_resume_go_back = !start_time.empty();
if(is_youtube && start_time.empty())
start_time = youtube_url_extract_timestamp(video_page->get_url());
+ prev_start_time = start_time;
- time_watched_timer.restart();
watched_videos.insert(video_page->get_url());
video_player = std::make_unique<VideoPlayer>(is_audio_only, use_system_mpv_config, is_matrix && !is_youtube, video_event_callback, on_window_create, resources_root, largest_monitor_height);
@@ -2602,7 +2605,7 @@ namespace QuickMedia {
}
};
- video_event_callback = [&time_watched_timer, &video_loaded, &in_seeking, &seeking_start_timer](const char *event_name) mutable {
+ video_event_callback = [&load_try, &video_loaded, &in_seeking, &seeking_start_timer](const char *event_name) mutable {
if(strcmp(event_name, "seek") == 0) {
in_seeking = true;
seeking_start_timer.restart();
@@ -2615,16 +2618,17 @@ namespace QuickMedia {
} else if(strcmp(event_name, "playback-restart") == 0) {
//video_player->set_paused(false);
in_seeking = false;
+ load_try = 0;
} else if(strcmp(event_name, "file-loaded") == 0) {
- time_watched_timer.restart();
video_loaded = true;
in_seeking = false;
+ load_try = 0;
} else if(strcmp(event_name, "video-reconfig") == 0 || strcmp(event_name, "audio-reconfig") == 0) {
if(!video_loaded) {
video_loaded = true;
- time_watched_timer.restart();
}
in_seeking = false;
+ load_try = 0;
}
//fprintf(stderr, "event name: %s\n", event_name);
@@ -2802,6 +2806,7 @@ namespace QuickMedia {
in_seeking = false;
double resume_start_time = 0.0;
if(video_player->get_time_in_file(&resume_start_time) == VideoPlayer::Error::OK) {
+ fprintf(stderr, "Video seems to be stuck after seeking, reloading...\n");
// TODO: Set the second argument to false if the video url is no longer valid (or always?)
load_video_error_check(std::to_string((int)resume_start_time), true);
}
@@ -2902,10 +2907,16 @@ namespace QuickMedia {
load_video_error_check();
} else if(update_err != VideoPlayer::Error::OK) {
- show_notification("QuickMedia", "Failed to play the video (error code " + std::to_string((int)update_err) + ")", Urgency::CRITICAL);
- current_page = previous_page;
- go_to_previous_page = true;
- break;
+ if(load_try < num_load_tries_max) {
+ fprintf(stderr, "Failed to play the media, retrying (try %d out of %d)\n", 1 + load_try, num_load_tries_max);
+ ++load_try;
+ load_video_error_check(prev_start_time);
+ } else {
+ show_notification("QuickMedia", "Failed to play the video (error code " + std::to_string((int)update_err) + ")", Urgency::CRITICAL);
+ current_page = previous_page;
+ go_to_previous_page = true;
+ break;
+ }
}
AsyncImageLoader::get_instance().update();
diff --git a/src/VideoPlayer.cpp b/src/VideoPlayer.cpp
index fe4643e..379b5b4 100644
--- a/src/VideoPlayer.cpp
+++ b/src/VideoPlayer.cpp
@@ -105,6 +105,7 @@ namespace QuickMedia {
// TODO: Disable hr seek on low power devices?
"--hr-seek=yes",
//"--cache=no",
+ "--cache-pause=no",
input_conf.c_str(),
wid_arg.c_str()
});
diff --git a/src/plugins/Youtube.cpp b/src/plugins/Youtube.cpp
index 49d7b83..1f8c103 100644
--- a/src/plugins/Youtube.cpp
+++ b/src/plugins/Youtube.cpp
@@ -1864,29 +1864,31 @@ namespace QuickMedia {
return "";
}
+ const YoutubeVideoFormat *chosen_video_format = nullptr;
const YoutubeVideoFormat *best_mp4 = get_highest_resolution_mp4_non_av1(video_formats, max_height);
const YoutubeVideoFormat *best_non_mp4 = get_highest_resolution_non_mp4(video_formats, max_height);
// We prefer mp4 (h264) because it has the best hardware decoding support
if(best_mp4 && (!best_non_mp4 || (best_mp4->height >= best_non_mp4->height && best_mp4->fps >= best_non_mp4->fps))) {
- print_chosen_format(*best_mp4);
- has_embedded_audio = best_mp4->has_embedded_audio;
- return best_mp4->base.url;
+ chosen_video_format = best_mp4;
} else if(best_non_mp4) {
- print_chosen_format(*best_non_mp4);
- has_embedded_audio = best_non_mp4->has_embedded_audio;
- return best_non_mp4->base.url;
+ chosen_video_format = best_non_mp4;
}
+
+ if(!chosen_video_format)
+ chosen_video_format = &video_formats.back();
- print_chosen_format(video_formats.back());
- has_embedded_audio = video_formats.back().has_embedded_audio;
- return video_formats.back().base.url;
+ print_chosen_format(*chosen_video_format);
+ has_embedded_audio = chosen_video_format->has_embedded_audio;
+ return chosen_video_format->base.url;
}
std::string YoutubeVideoPage::get_audio_url() {
if(audio_formats.empty())
return "";
- return audio_formats.front().base.url;
+ const YoutubeAudioFormat *chosen_audio_format = &audio_formats.front();
+ fprintf(stderr, "Choosing youtube audio format: bitrate: %d, mime type: %s\n", chosen_audio_format->base.bitrate, chosen_audio_format->base.mime_type.c_str());
+ return chosen_audio_format->base.url;
}
PluginResult YoutubeVideoPage::load(std::string &title, std::string &channel_url) {