summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2008-05-18 00:14:34 +0000
committerMichael Sevakis <jethead71@rockbox.org>2008-05-18 00:14:34 +0000
commit1f2df74079ecb399d33069a6f6ba9eb1744b0e8a (patch)
tree09ba2f1fdc7a4a84abcb5643bdb16d4218aae23f
parent18f13b149a4ce6d3b16c0b91de4d571d1860b66f (diff)
downloadrockbox-1f2df74079ecb399d33069a6f6ba9eb1744b0e8a.tar.gz
rockbox-1f2df74079ecb399d33069a6f6ba9eb1744b0e8a.zip
MPEGPlayer quickie: add an option to set the backlight brightness to a plugin-specified value when playing video or interacting. Nice when one likes a dim backlight normally but that isn't sufficient when viewing video for instance. Suggested in FS#8417 in addition to my own desire for this.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@17563 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/plugins/lib/helper.c17
-rw-r--r--apps/plugins/lib/helper.h11
-rw-r--r--apps/plugins/mpegplayer/mpeg_settings.c83
-rw-r--r--apps/plugins/mpegplayer/mpeg_settings.h13
-rw-r--r--apps/plugins/mpegplayer/mpegplayer.c64
5 files changed, 172 insertions, 16 deletions
diff --git a/apps/plugins/lib/helper.c b/apps/plugins/lib/helper.c
index 691a17f15c..273b066599 100644
--- a/apps/plugins/lib/helper.c
+++ b/apps/plugins/lib/helper.c
@@ -91,3 +91,20 @@ void buttonlight_use_settings(const struct plugin_api* rb)
91 rb->buttonlight_set_timeout(rb->global_settings->buttonlight_timeout); 91 rb->buttonlight_set_timeout(rb->global_settings->buttonlight_timeout);
92} 92}
93#endif /* HAVE_BUTTON_LIGHT */ 93#endif /* HAVE_BUTTON_LIGHT */
94
95#ifdef HAVE_BACKLIGHT_BRIGHTNESS
96void backlight_brightness_set(const struct plugin_api *rb,
97 int brightness)
98{
99 if (!rb)
100 return;
101 rb->backlight_set_brightness(brightness);
102}
103
104void backlight_brightness_use_setting(const struct plugin_api *rb)
105{
106 if (!rb)
107 return;
108 rb->backlight_set_brightness(rb->global_settings->brightness);
109}
110#endif /* HAVE_BACKLIGHT_BRIGHTNESS */
diff --git a/apps/plugins/lib/helper.h b/apps/plugins/lib/helper.h
index d34e6334f0..eb52a8bfdc 100644
--- a/apps/plugins/lib/helper.h
+++ b/apps/plugins/lib/helper.h
@@ -34,4 +34,15 @@ void remote_backlight_use_settings(const struct plugin_api* rb);
34void buttonlight_force_on(const struct plugin_api* rb); 34void buttonlight_force_on(const struct plugin_api* rb);
35void buttonlight_use_settings(const struct plugin_api* rb); 35void buttonlight_use_settings(const struct plugin_api* rb);
36#endif 36#endif
37
38/**
39 * Backlight brightness adjustment settings
40 */
41#ifdef HAVE_BACKLIGHT_BRIGHTNESS
42void backlight_brightness_set(const struct plugin_api *rb,
43 int brightness);
44void backlight_brightness_use_setting(const struct plugin_api *rb);
37#endif 45#endif
46
47
48#endif /* _LIB_HELPER_H_ */
diff --git a/apps/plugins/mpegplayer/mpeg_settings.c b/apps/plugins/mpegplayer/mpeg_settings.c
index 06083dfe10..9e8c153cc4 100644
--- a/apps/plugins/mpegplayer/mpeg_settings.c
+++ b/apps/plugins/mpegplayer/mpeg_settings.c
@@ -1,4 +1,5 @@
1#include "plugin.h" 1#include "plugin.h"
2#include "helper.h"
2#include "lib/configfile.h" 3#include "lib/configfile.h"
3#include "lib/oldmenuapi.h" 4#include "lib/oldmenuapi.h"
4 5
@@ -172,6 +173,10 @@ static struct configdata config[] =
172 {TYPE_INT, 0, 2, &settings.crossfeed, "Crossfeed", NULL, NULL}, 173 {TYPE_INT, 0, 2, &settings.crossfeed, "Crossfeed", NULL, NULL},
173 {TYPE_INT, 0, 2, &settings.equalizer, "Equalizer", NULL, NULL}, 174 {TYPE_INT, 0, 2, &settings.equalizer, "Equalizer", NULL, NULL},
174 {TYPE_INT, 0, 2, &settings.dithering, "Dithering", NULL, NULL}, 175 {TYPE_INT, 0, 2, &settings.dithering, "Dithering", NULL, NULL},
176#ifdef HAVE_BACKLIGHT_BRIGHTNESS
177 {TYPE_INT, -1, INT_MAX, &settings.backlight_brightness,
178 "Backlight brightness", NULL, NULL},
179#endif
175}; 180};
176 181
177static const struct opt_items noyes[2] = { 182static const struct opt_items noyes[2] = {
@@ -189,6 +194,10 @@ static const struct opt_items globaloff[2] = {
189 { "Use sound setting", -1 }, 194 { "Use sound setting", -1 },
190}; 195};
191 196
197#ifdef HAVE_BACKLIGHT_BRIGHTNESS
198#define BACKLIGHT_OPTION_DEFAULT "Use setting"
199#endif
200
192static long mpeg_menu_sysevent_id; 201static long mpeg_menu_sysevent_id;
193 202
194void mpeg_menu_sysevent_clear(void) 203void mpeg_menu_sysevent_clear(void)
@@ -252,6 +261,55 @@ static bool mpeg_set_option(const char* string,
252 return usb; 261 return usb;
253} 262}
254 263
264static bool mpeg_set_int(const char *string, const char *unit,
265 int voice_unit, const int *variable,
266 void (*function)(int), int step,
267 int min,
268 int max,
269 void (*formatter)(char*, size_t, int, const char*))
270{
271 mpeg_menu_sysevent_clear();
272
273 bool usb = rb->set_int(string, unit, voice_unit, variable, function,
274 step, min, max, formatter);
275
276 if (usb)
277 mpeg_menu_sysevent_id = ACTION_STD_CANCEL;
278
279 return usb;
280}
281
282#ifdef HAVE_BACKLIGHT_BRIGHTNESS
283void mpeg_backlight_update_brightness(int value)
284{
285 if (value >= 0)
286 {
287 value += MIN_BRIGHTNESS_SETTING;
288 backlight_brightness_set(rb, value);
289 }
290 else
291 {
292 backlight_brightness_use_setting(rb);
293 }
294}
295
296static void backlight_brightness_function(int value)
297{
298 mpeg_backlight_update_brightness(value);
299}
300
301static void backlight_brightness_formatter(char *buf, size_t length,
302 int value, const char *input)
303{
304 if (value < 0)
305 rb->strncpy(buf, BACKLIGHT_OPTION_DEFAULT, length);
306 else
307 rb->snprintf(buf, length, "%d", value + MIN_BRIGHTNESS_SETTING);
308
309 (void)input;
310}
311#endif /* HAVE_BACKLIGHT_BRIGHTNESS */
312
255/* Sync a particular audio setting to global or mpegplayer forced off */ 313/* Sync a particular audio setting to global or mpegplayer forced off */
256static void sync_audio_setting(int setting, bool global) 314static void sync_audio_setting(int setting, bool global)
257{ 315{
@@ -816,6 +874,10 @@ static void display_options(void)
816 { "Limit FPS", NULL }, 874 { "Limit FPS", NULL },
817 [MPEG_OPTION_SKIP_FRAMES] = 875 [MPEG_OPTION_SKIP_FRAMES] =
818 { "Skip frames", NULL }, 876 { "Skip frames", NULL },
877#ifdef HAVE_BACKLIGHT_BRIGHTNESS
878 [MPEG_OPTION_BACKLIGHT_BRIGHTNESS] =
879 { "Backlight brightness", NULL },
880#endif
819 }; 881 };
820 882
821 menu_id = menu_init(rb, items, ARRAYLEN(items), 883 menu_id = menu_init(rb, items, ARRAYLEN(items),
@@ -856,6 +918,19 @@ static void display_options(void)
856 noyes, 2, NULL); 918 noyes, 2, NULL);
857 break; 919 break;
858 920
921#ifdef HAVE_BACKLIGHT_BRIGHTNESS
922 case MPEG_OPTION_BACKLIGHT_BRIGHTNESS:
923 result = settings.backlight_brightness;
924 mpeg_backlight_update_brightness(result);
925 mpeg_set_int("Backlight brightness", NULL, -1, &result,
926 backlight_brightness_function, 1, -1,
927 MAX_BRIGHTNESS_SETTING - MIN_BRIGHTNESS_SETTING,
928 backlight_brightness_formatter);
929 settings.backlight_brightness = result;
930 mpeg_backlight_update_brightness(-1);
931 break;
932#endif /* HAVE_BACKLIGHT_BRIGHTNESS */
933
859 default: 934 default:
860 menu_quit = true; 935 menu_quit = true;
861 break; 936 break;
@@ -1057,6 +1132,9 @@ void init_settings(const char* filename)
1057 settings.skipframes = 1; /* Skip frames */ 1132 settings.skipframes = 1; /* Skip frames */
1058 settings.resume_options = MPEG_RESUME_MENU_ALWAYS; /* Enable start menu */ 1133 settings.resume_options = MPEG_RESUME_MENU_ALWAYS; /* Enable start menu */
1059 settings.resume_count = -1; 1134 settings.resume_count = -1;
1135#ifdef HAVE_BACKLIGHT_BRIGHTNESS
1136 settings.backlight_brightness = -1; /* Use default setting */
1137#endif
1060#if MPEG_OPTION_DITHERING_ENABLED 1138#if MPEG_OPTION_DITHERING_ENABLED
1061 settings.displayoptions = 0; /* No visual effects */ 1139 settings.displayoptions = 0; /* No visual effects */
1062#endif 1140#endif
@@ -1126,6 +1204,11 @@ void save_settings(void)
1126 ++settings.resume_count); 1204 ++settings.resume_count);
1127 } 1205 }
1128 1206
1207#ifdef HAVE_BACKLIGHT_BRIGHTNESS
1208 configfile_update_entry(SETTINGS_FILENAME, "Backlight brightness",
1209 settings.backlight_brightness);
1210#endif
1211
1129#if MPEG_OPTION_DITHERING_ENABLED 1212#if MPEG_OPTION_DITHERING_ENABLED
1130 configfile_update_entry(SETTINGS_FILENAME, "Display options", 1213 configfile_update_entry(SETTINGS_FILENAME, "Display options",
1131 settings.displayoptions); 1214 settings.displayoptions);
diff --git a/apps/plugins/mpegplayer/mpeg_settings.h b/apps/plugins/mpegplayer/mpeg_settings.h
index 1557ff433e..d00dc197cb 100644
--- a/apps/plugins/mpegplayer/mpeg_settings.h
+++ b/apps/plugins/mpegplayer/mpeg_settings.h
@@ -1,7 +1,7 @@
1 1
2#include "plugin.h" 2#include "plugin.h"
3 3
4#define SETTINGS_VERSION 4 4#define SETTINGS_VERSION 5
5#define SETTINGS_MIN_VERSION 1 5#define SETTINGS_MIN_VERSION 1
6#define SETTINGS_FILENAME "mpegplayer.cfg" 6#define SETTINGS_FILENAME "mpegplayer.cfg"
7 7
@@ -22,6 +22,9 @@ enum mpeg_option_id
22 MPEG_OPTION_DISPLAY_FPS, 22 MPEG_OPTION_DISPLAY_FPS,
23 MPEG_OPTION_LIMIT_FPS, 23 MPEG_OPTION_LIMIT_FPS,
24 MPEG_OPTION_SKIP_FRAMES, 24 MPEG_OPTION_SKIP_FRAMES,
25#ifdef HAVE_BACKLIGHT_BRIGHTNESS
26 MPEG_OPTION_BACKLIGHT_BRIGHTNESS,
27#endif
25}; 28};
26 29
27enum mpeg_audio_option_id 30enum mpeg_audio_option_id
@@ -78,6 +81,10 @@ struct mpeg_settings {
78 int crossfeed; 81 int crossfeed;
79 int equalizer; 82 int equalizer;
80 int dithering; 83 int dithering;
84 /* Backlight options */
85#ifdef HAVE_BACKLIGHT_BRIGHTNESS
86 int backlight_brightness;
87#endif
81}; 88};
82 89
83extern struct mpeg_settings settings; 90extern struct mpeg_settings settings;
@@ -97,3 +104,7 @@ void mpeg_menu_sysevent_handle(void);
97 104
98void init_settings(const char* filename); 105void init_settings(const char* filename);
99void save_settings(void); 106void save_settings(void);
107
108#ifdef HAVE_BACKLIGHT_BRIGHTNESS
109void mpeg_backlight_update_brightness(int value);
110#endif
diff --git a/apps/plugins/mpegplayer/mpegplayer.c b/apps/plugins/mpegplayer/mpegplayer.c
index 82703ca840..5b92ccced1 100644
--- a/apps/plugins/mpegplayer/mpegplayer.c
+++ b/apps/plugins/mpegplayer/mpegplayer.c
@@ -587,6 +587,30 @@ static void draw_putsxy_oriented(int x, int y, const char *str)
587} 587}
588#endif /* LCD_PORTRAIT */ 588#endif /* LCD_PORTRAIT */
589 589
590static void wvs_backlight_on_video_mode(bool video_on)
591{
592 if (video_on) {
593 /* Turn off backlight timeout */
594 /* backlight control in lib/helper.c */
595 backlight_force_on(rb);
596 } else {
597 /* Revert to user's backlight settings */
598 backlight_use_settings(rb);
599 }
600}
601
602#ifdef HAVE_BACKLIGHT_BRIGHTNESS
603static void wvs_backlight_brightness_video_mode(bool video_on)
604{
605 if (settings.backlight_brightness < 0)
606 return;
607
608 mpeg_backlight_update_brightness(
609 video_on ? settings.backlight_brightness : -1);
610}
611#else
612#define wvs_backlight_brightness_video_mode(video_on)
613#endif /* HAVE_BACKLIGHT_BRIGHTNESS */
590 614
591static void wvs_text_init(void) 615static void wvs_text_init(void)
592{ 616{
@@ -1012,6 +1036,11 @@ static void wvs_show(unsigned show)
1012 1036
1013 wvs.flags |= WVS_SHOW; 1037 wvs.flags |= WVS_SHOW;
1014 1038
1039 if (wvs.status != WVS_STATUS_PLAYING) {
1040 /* Not playing - set brightness to mpegplayer setting */
1041 wvs_backlight_brightness_video_mode(true);
1042 }
1043
1015 stream_vo_set_clip(&rc); 1044 stream_vo_set_clip(&rc);
1016 1045
1017 if (!(show & WVS_NODRAW)) 1046 if (!(show & WVS_NODRAW))
@@ -1032,6 +1061,11 @@ static void wvs_show(unsigned show)
1032 } else { 1061 } else {
1033 stream_vo_set_clip(NULL); 1062 stream_vo_set_clip(NULL);
1034 } 1063 }
1064
1065 if (wvs.status != WVS_STATUS_PLAYING) {
1066 /* Not playing - restore backlight brightness */
1067 wvs_backlight_brightness_video_mode(false);
1068 }
1035 } 1069 }
1036} 1070}
1037 1071
@@ -1227,6 +1261,8 @@ static int wvs_play(uint32_t time)
1227 retval = stream_seek(time, SEEK_SET); 1261 retval = stream_seek(time, SEEK_SET);
1228 1262
1229 if (retval >= STREAM_OK) { 1263 if (retval >= STREAM_OK) {
1264 wvs_backlight_on_video_mode(true);
1265 wvs_backlight_brightness_video_mode(true);
1230 stream_show_vo(true); 1266 stream_show_vo(true);
1231 retval = stream_play(); 1267 retval = stream_play();
1232 1268
@@ -1251,6 +1287,8 @@ static int wvs_halt(void)
1251 /* Cancel some auto refreshes - caller will restart them if desired */ 1287 /* Cancel some auto refreshes - caller will restart them if desired */
1252 wvs_cancel_refresh(WVS_REFRESH_VIDEO | WVS_REFRESH_RESUME); 1288 wvs_cancel_refresh(WVS_REFRESH_VIDEO | WVS_REFRESH_RESUME);
1253 1289
1290 /* No backlight fiddling here - callers does the right thing */
1291
1254 return status; 1292 return status;
1255} 1293}
1256 1294
@@ -1267,14 +1305,19 @@ static int wvs_pause(void)
1267 1305
1268 wvs_set_status(WVS_STATUS_PAUSED); 1306 wvs_set_status(WVS_STATUS_PAUSED);
1269 1307
1308 wvs_backlight_on_video_mode(false);
1309 /* Leave brightness alone and restore it when WVS is hidden */
1310
1270 return status; 1311 return status;
1271} 1312}
1272 1313
1273/* Resume playback if halted or paused */ 1314/* Resume playback if halted or paused */
1274static void wvs_resume(void) 1315static void wvs_resume(void)
1275{ 1316{
1276 /* Cancel video and resume auto refresh - the resyc when starting playback 1317 /* Cancel video and resume auto refresh - the resyc when starting
1277 * will perform those tasks */ 1318 * playback will perform those tasks */
1319 wvs_backlight_on_video_mode(true);
1320 wvs_backlight_brightness_video_mode(true);
1278 wvs_cancel_refresh(WVS_REFRESH_VIDEO | WVS_REFRESH_RESUME); 1321 wvs_cancel_refresh(WVS_REFRESH_VIDEO | WVS_REFRESH_RESUME);
1279 wvs_set_status(WVS_STATUS_PLAYING); 1322 wvs_set_status(WVS_STATUS_PLAYING);
1280 stream_resume(); 1323 stream_resume();
@@ -1295,6 +1338,9 @@ static void wvs_stop(void)
1295 1338
1296 if (resume_time != INVALID_TIMESTAMP) 1339 if (resume_time != INVALID_TIMESTAMP)
1297 settings.resume_time = resume_time; 1340 settings.resume_time = resume_time;
1341
1342 wvs_backlight_on_video_mode(false);
1343 wvs_backlight_brightness_video_mode(false);
1298} 1344}
1299 1345
1300/* Perform a seek if seeking is possible for this stream - if playing, a delay 1346/* Perform a seek if seeking is possible for this stream - if playing, a delay
@@ -1343,14 +1389,12 @@ static void wvs_handle_phone_plug(bool inserted)
1343 if (inserted) { 1389 if (inserted) {
1344 if (rb->global_settings->unplug_mode > 1) { 1390 if (rb->global_settings->unplug_mode > 1) {
1345 if (status == STREAM_PAUSED) { 1391 if (status == STREAM_PAUSED) {
1346 backlight_force_on(rb);
1347 wvs_resume(); 1392 wvs_resume();
1348 } 1393 }
1349 } 1394 }
1350 } else { 1395 } else {
1351 if (status == STREAM_PLAYING) { 1396 if (status == STREAM_PLAYING) {
1352 wvs_pause(); 1397 wvs_pause();
1353 backlight_use_settings(rb);
1354 1398
1355 if (stream_can_seek() && rb->global_settings->unplug_rw) { 1399 if (stream_can_seek() && rb->global_settings->unplug_rw) {
1356 stream_seek(-rb->global_settings->unplug_rw*TS_SECOND, 1400 stream_seek(-rb->global_settings->unplug_rw*TS_SECOND,
@@ -1371,10 +1415,6 @@ static void button_loop(void)
1371 rb->lcd_clear_display(); 1415 rb->lcd_clear_display();
1372 rb->lcd_update(); 1416 rb->lcd_update();
1373 1417
1374 /* Turn off backlight timeout */
1375 /* backlight control in lib/helper.c */
1376 backlight_force_on(rb);
1377
1378 wvs_init(); 1418 wvs_init();
1379 1419
1380 /* Start playback at the specified starting time */ 1420 /* Start playback at the specified starting time */
@@ -1442,7 +1482,7 @@ static void button_loop(void)
1442 /* Hide video output */ 1482 /* Hide video output */
1443 wvs_show(WVS_HIDE | WVS_NODRAW); 1483 wvs_show(WVS_HIDE | WVS_NODRAW);
1444 stream_show_vo(false); 1484 stream_show_vo(false);
1445 backlight_use_settings(rb); 1485 wvs_backlight_brightness_video_mode(false);
1446 1486
1447 result = mpeg_menu(0); 1487 result = mpeg_menu(0);
1448 1488
@@ -1464,7 +1504,6 @@ static void button_loop(void)
1464 1504
1465 /* If stream was playing, restart it */ 1505 /* If stream was playing, restart it */
1466 if (state == STREAM_PLAYING) { 1506 if (state == STREAM_PLAYING) {
1467 backlight_force_on(rb);
1468 wvs_resume(); 1507 wvs_resume();
1469 } 1508 }
1470 break; 1509 break;
@@ -1495,11 +1534,9 @@ static void button_loop(void)
1495 if (status == STREAM_PLAYING) { 1534 if (status == STREAM_PLAYING) {
1496 /* Playing => Paused */ 1535 /* Playing => Paused */
1497 wvs_pause(); 1536 wvs_pause();
1498 backlight_use_settings(rb);
1499 } 1537 }
1500 else if (status == STREAM_PAUSED) { 1538 else if (status == STREAM_PAUSED) {
1501 /* Paused => Playing */ 1539 /* Paused => Playing */
1502 backlight_force_on(rb);
1503 wvs_resume(); 1540 wvs_resume();
1504 } 1541 }
1505 1542
@@ -1539,9 +1576,6 @@ static void button_loop(void)
1539 wvs_stop(); 1576 wvs_stop();
1540 1577
1541 rb->lcd_setfont(FONT_UI); 1578 rb->lcd_setfont(FONT_UI);
1542
1543 /* Turn on backlight timeout (revert to settings) */
1544 backlight_use_settings(rb);
1545} 1579}
1546 1580
1547enum plugin_status plugin_start(const struct plugin_api* api, const void* parameter) 1581enum plugin_status plugin_start(const struct plugin_api* api, const void* parameter)