From 72089fe88dfe83a0d01bc0d89493dcb10a42bea3 Mon Sep 17 00:00:00 2001 From: Stefan Seyfried Date: Sun, 1 Apr 2012 17:26:56 +0200 Subject: [PATCH] spark: set new videomode only if it differs from current --- libspark/video.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/libspark/video.cpp b/libspark/video.cpp index 09998ff..7bad2a1 100644 --- a/libspark/video.cpp +++ b/libspark/video.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -88,6 +89,8 @@ static int proc_get(const char *path, char *value, const int len) return pfd; ret = read(pfd, value, len); value[len-1] = '\0'; /* make sure string is terminated */ + while (ret > 0 && isspace(value[ret-1])) + value[--ret] = '\0'; /* remove trailing whitespace */ ret2 = close(pfd); if (ret2 < 0) return ret2; @@ -286,6 +289,7 @@ int cVideo::setBlank(int) int cVideo::SetVideoSystem(int video_system, bool remember) { lt_debug("%s(%d, %d)\n", __func__, video_system, remember); + char current[32]; static const char *modes[] = { "pal", // VIDEO_STD_NTSC "pal", // VIDEO_STD_SECAM @@ -307,6 +311,13 @@ int cVideo::SetVideoSystem(int video_system, bool remember) lt_info("%s: video_system (%d) > VIDEO_STD_MAX (%d)\n", __func__, video_system, VIDEO_STD_MAX); return -1; } + int ret = proc_get("/proc/stb/video/videomode", current, 32); + if (strcmp(current, modes[video_system]) == 0) + { + lt_info("%s: video_system %d (%s) already set, skipping\n", __func__, video_system, current); + return 0; + } + lt_info("%s: old: '%s' new: '%s'\n", __func__, current, modes[video_system]); bool stopped = false; if (playstate == VIDEO_PLAYING) { @@ -315,7 +326,7 @@ int cVideo::SetVideoSystem(int video_system, bool remember) stopped = true; } hdmi_out(false); - int ret = proc_put("/proc/stb/video/videomode", modes[video_system],strlen(modes[video_system])); + ret = proc_put("/proc/stb/video/videomode", modes[video_system],strlen(modes[video_system])); hdmi_out(true); if (stopped) Start();