ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/doomfrontend/doomfrontend
(Generate patch)

Comparing doomfrontend/doomfrontend (file contents):
Revision 1.3 by root, Mon Apr 17 12:32:17 2023 UTC vs.
Revision 1.5 by root, Mon Oct 2 13:56:07 2023 UTC

6# {\blur0\bord0\1c&H000000\iclip(4, m 30472 10072 l 30008 10072 l 30008 7584 l 30093 7500 l 30388 7500 l 30472 7584 l 30472 10072)}{\alpha&H62&}{\pos(0.000000,0.000000)}{\p4} m 30000 6720 l 30480 6720 l 30480 7412 l 30396 7496 l 30480 7580 l 30480 10080 l 30000 10080 l 30000 7580 l 30084 7496 l 30000 7412 l 30000 6720{\p0} 6# {\blur0\bord0\1c&H000000\iclip(4, m 30472 10072 l 30008 10072 l 30008 7584 l 30093 7500 l 30388 7500 l 30472 7584 l 30472 10072)}{\alpha&H62&}{\pos(0.000000,0.000000)}{\p4} m 30000 6720 l 30480 6720 l 30480 7412 l 30396 7496 l 30480 7580 l 30480 10080 l 30000 10080 l 30000 7580 l 30084 7496 l 30000 7412 l 30000 6720{\p0}
7# {\blur0\bord0\1c&Hffffff}{\alpha&H4C&}{\pos(0.000000,0.000000)}{\p4} m 30472 10072 l 30008 10072 l 30008 7584 l 30093 7500 l 30388 7500 l 30472 7584 l 30472 10072{\p0} 7# {\blur0\bord0\1c&Hffffff}{\alpha&H4C&}{\pos(0.000000,0.000000)}{\p4} m 30472 10072 l 30008 10072 l 30008 7584 l 30093 7500 l 30388 7500 l 30472 7584 l 30472 10072{\p0}
8# {\blur0\bord0\shad0\1c&H000000\fnDroid Sans\fs27\clip(4, m 30472 10072 l 30008 10072 l 30008 7584 l 30093 7500 l 30388 7500 l 30472 7584 l 30472 10072)}{\alpha&H36&}{\pos(3780.000000,1248.000000)}{\an2}100 8# {\blur0\bord0\shad0\1c&H000000\fnDroid Sans\fs27\clip(4, m 30472 10072 l 30008 10072 l 30008 7584 l 30093 7500 l 30388 7500 l 30472 7584 l 30472 10072)}{\alpha&H36&}{\pos(3780.000000,1248.000000)}{\an2}100
9# {\blur0\bord1\shad0\1c&Hffffff\3c&H000000}{\alpha&H4C&}{\pos(0.000000,0.000000)}{\p4} m 30098 10262 l 30156 10262 l 30232 10194 l 30232 10446 l 30156 10379 l 30098 10379 m 30274 10270 l 30274 10371 l 30299 10371 l 30299 10270 m 30333 10220 l 30333 10421 l 30358 10421 l 30358 10220{\p0} 9# {\blur0\bord1\shad0\1c&Hffffff\3c&H000000}{\alpha&H4C&}{\pos(0.000000,0.000000)}{\p4} m 30098 10262 l 30156 10262 l 30232 10194 l 30232 10446 l 30156 10379 l 30098 10379 m 30274 10270 l 30274 10371 l 30299 10371 l 30299 10270 m 30333 10220 l 30333 10421 l 30358 10421 l 30358 10220{\p0}
10 10
11$END{__GL_SYNC_TO_VBLANK} = 0;
11 12
12BEGIN { 13BEGIN {
13 if ($ARGV[0] eq "-=reloaded=-") { 14 if ($ARGV[0] eq "-=reloaded=-") {
14 shift; 15 shift;
16 } elsif ($^C) {
17 # nop
15 } elsif (-e "/root/mlockall.so") { 18 } elsif (-e "/root/mlockall.so") {
16 $ENV{LD_PRELOAD} = "/root/mlockall.so:/root/libmimalloc.so.1.7"; 19 $ENV{LD_PRELOAD} = "/root/mlockall.so:/root/libmimalloc.so.1.7";
17 $ENV{MIMALLOC_LARGE_OS_PAGES} = 1; 20 $ENV{MIMALLOC_LARGE_OS_PAGES} = 1;
18 system "echo always >/sys/kernel/mm/transparent_hugepage/defrag"; 21 system "echo always >/sys/kernel/mm/transparent_hugepage/defrag";
19 system "echo 3 > /proc/sys/vm/drop_caches"; 22 #system "echo 3 > /proc/sys/vm/drop_caches";
20 system "echo 1 > /proc/sys/vm/compact_memory"; 23 system "echo 1 > /proc/sys/vm/compact_memory";
21 exec "taskset", "-c", "12-15", "nice", "-n-20", "ionice", "-c1", $0, "-=reloaded=-", @ARGV; 24 #exec "taskset", "-c", "12-15", "nice", "-n-20", "ionice", "-c1", $0, "-=reloaded=-", @ARGV;
25 exec "nice", "-n-20", "ionice", "-c1", $0, "-=reloaded=-", @ARGV;
22 exit 255; 26 exit 255;
23 } 27 }
24} 28}
25 29
26use common::sense; 30use common::sense;
49use List::Util qw(min max); 53use List::Util qw(min max);
50use Text::Wrap (); 54use Text::Wrap ();
51use Format::Human::Bytes (); 55use Format::Human::Bytes ();
52use AnyEvent::MPV (); 56use AnyEvent::MPV ();
53 57
54IO::AIO::min_parallel 16; 58IO::AIO::min_parallel 32;
55 59
56sub MAX_ISLANDS () { 5 } 60sub MAX_ISLANDS () { 5 }
57 61
58sub enc($) { 62sub enc($) {
59 my $s = shift; 63 my $s = shift;
72 76
73our $TESTING = $ARGV[0] eq "--testing"; 77our $TESTING = $ARGV[0] eq "--testing";
74#our $DPMS_DISABLE = $DOOM; 78#our $DPMS_DISABLE = $DOOM;
75 79
76our ($SW, $SH) = (3840, 2160); 80our ($SW, $SH) = (3840, 2160);
77our $FONTSIZE = $NODENAME eq "doom" ? 32 : 18; 81our $FONTSIZE = $NODENAME eq "doom" ? 18 : 18;
78our $FONT = "xft:inputmonocondensed:minspace:medium:hintstyle=hintfull:matrix=1 0 0 0.95:size=$FONTSIZE"; 82our $FONT = "xft:inputmonocondensed:minspace:medium:hintstyle=hintfull:matrix=1 0 0 0.95:size=$FONTSIZE";
79 83
80# MUST be canonical, same as dfe 84# MUST be canonical, same as dfe
81our $STATE_FILE = "/fs/doom/db/doomfrontend.state"; 85our $STATE_FILE = "/fs/doom/db/doomfrontend.state";
82our $STATE_SHM = "/dev/shm/doomfrontend.state"; 86our $STATE_SHM = "/dev/shm/doomfrontend.state";
965 && !exists $CONF_PLAYLIST{$_}, 969 && !exists $CONF_PLAYLIST{$_},
966 sort keys %STATE 970 sort keys %STATE
967 ) 971 )
968} 972}
969 973
974sub sanitize {
975 local $_ = shift;
976
977 s/\n/\\n/g;
978 s/([\x00-\x1f\xa0-\xbf])/sprintf "\\x%02x", ord $1/ge;
979
980 $_
981}
982
970sub stat_video($;$) { 983sub stat_video($;$) {
971 my ($path, $prefix) = @_; 984 my ($path, $prefix) = @_;
972 985
973 my $display = $path =~ s%^.*/%%r; 986 my $display = $path =~ s%^.*/%%r;
974 987
993 sub dfe::mangle_name (); 1006 sub dfe::mangle_name ();
994 dfe::mangle_name; 1007 dfe::mangle_name;
995 1008
996 # "improve" some filenames/episode numbers, mostly for sorting 1009 # "improve" some filenames/episode numbers, mostly for sorting
997 s{(?:\bpart|\bep\.?|episode|Ch\.|Chapter|\bE)\s*#?(\d+)\b}{sprintf "Ep.%03d", $1}geia; 1010 s{(?:\bpart|\bep\.?|episode|Ch\.|Chapter|\bE)\s*#?(\d+)\b}{sprintf "Ep.%03d", $1}geia;
1011 s{\bE(\d+)\b}{sprintf "Ep.%03d", $1}geia;
998 #s{(-\s*)(\d{1,4})(\s*-)}{sprintf "%s#%03d%s", $1, $2, $3}geia; 1012 #s{(-\s*)(\d{1,4})(\s*-)}{sprintf "%s#%03d%s", $1, $2, $3}geia;
999 s{\s+#(\d+)}{sprintf " #%03d", $1}geia; 1013 s{\s+#(\d+)}{sprintf " #%03d", $1}geia;
1000 s{\[#?(\d+)\]}{sprintf "#%03d", $1}geia; 1014 s{\[#?(\d+)\]}{sprintf "#%03d", $1}geia;
1001 s{\bs(\d+)e(\d+)\b}{sprintf "S%02dE%02d", $1, $2}geia; 1015 s{\bs(\d+)e(\d+)\b}{sprintf "S%02dE%02d", $1, $2}geia;
1002
1003 s{-20(\d\d)(\d\d)(\d\d)\.([^.]+)\z}{-20$1.$2.$3.$4}a; 1016 s{-20(\d\d)(\d\d)(\d\d)\.([^.]+)\z}{-20$1.$2.$3.$4}a;
1004 1017
1005 s/\s+/ /g; 1018 s/\s+/ /g;
1006 } 1019 }
1020
1021 $display = sanitize $display;
1007 1022
1008 $display = sprintf "%s [%dMB]", $display, (-s _) * 1e-6; 1023 $display = sprintf "%s [%dMB]", $display, (-s _) * 1e-6;
1009 1024
1010 [$display, $path] 1025 [$display, $path]
1011} 1026}
1071 ( 1086 (
1072 "", 1087 "",
1073 [ 1088 [
1074 video_sort #d# 1089 video_sort #d#
1075 @{ scan_video_dir $VIDEO_DIR }, 1090 @{ scan_video_dir $VIDEO_DIR },
1076 @{ scan_video_dir "/fs/doom/root/ytnew" }, 1091 #@{ scan_video_dir "/fs/doom/root/ytnew" },
1077 @{ scan_video_dir "/seagate2tb/sinatar" }, 1092 #@{ scan_video_dir "/seagate2tb/sinatar" },
1078 ] 1093 ]
1079 ) 1094 )
1080} 1095}
1081 1096
1082sub scan_islands($) { 1097sub scan_islands($) {
1118 for (sort readdir $fh) { 1133 for (sort readdir $fh) {
1119 next if /^\.\.?$/; 1134 next if /^\.\.?$/;
1120 stat "$path/$_" or next; 1135 stat "$path/$_" or next;
1121 1136
1122 if (-d _) { 1137 if (-d _) {
1123 my $dis = dec $_; 1138 my $dis = sanitize dec $_;
1124 $dis = length $dis > 25 ? (substr $dis, 0, 24) . "…" : $dis; 1139 $dis = length $dis > 25 ? (substr $dis, 0, 24) . "…" : $dis;
1125 1140
1126 push @dirs, ["$path/$_", "$display/$dis"]; 1141 push @dirs, ["$path/$_", "$display/$dis"];
1127 1142
1128 } elsif (-f _) { 1143 } elsif (-f _) {
1129 my $dis = dec $_; 1144 my $dis = sanitize dec $_;
1130 push @list, [(substr "$display/$dis", 1), "$path/$_"]; 1145 push @list, [(substr "$display/$dis", 1), "$path/$_"];
1131 } 1146 }
1132 } 1147 }
1133 1148
1134 __SUB__->(@$_) 1149 __SUB__->(@$_)
1179 if ($STATE{curdir} eq $playlist) { 1194 if ($STATE{curdir} eq $playlist) {
1180 $STATE{curdir} = "/playlist"; 1195 $STATE{curdir} = "/playlist";
1181 ::state_save; 1196 ::state_save;
1182 external "--playlist=playlist"; 1197 external "--playlist=playlist";
1183 } 1198 }
1184}
1185
1186our ($PLAYING_STATE, $PLAYING_PATH);
1187
1188sub play_video_speed_mult {
1189 sprintf "%.2f", 1.032 ** $PLAYING_STATE->{speed}
1190}
1191
1192sub play_video_set_speed {
1193 my $speed = play_video_speed_mult;
1194 delete $PLAYING_STATE->{speed} unless $PLAYING_STATE->{speed};
1195
1196 $mpv->cmd ("set", "speed", "$speed");
1197 $mpv->cmd ("show-text", "playback speed $speed");
1198}
1199
1200our $OSD_LEVEL = $DOOM ? 3 : 3; # was 1 on doom
1201
1202sub sprintf_time($$) {
1203 sprintf $_[0],
1204 sprintf "%02d:%02d:%02d.%03d",
1205 $_[1] / 60 / 60 % 60,
1206 $_[1] / 60 % 60,
1207 $_[1] % 60,
1208 $_[1] * 1000 % 1000;
1209} 1199}
1210 1200
1211my $curfps; 1201my $curfps;
1212 1202
1213sub set_fps { 1203sub set_fps {
1228 } 1218 }
1229 } 1219 }
1230 } 1220 }
1231 } 1221 }
1232 1222
1223 warn "target fps $target, cur_fps $new\n";#d#
1224
1233 if ($curfps != $new && defined $new) { 1225 if ($curfps != $new && defined $new) {
1234 warn "REFRESHRATE CHANGE current=$curfps, target=$target, selected=$new\n"; 1226 warn "REFRESHRATE CHANGE current=$curfps, target=$target, selected=$new\n";
1235 system "xrandr", "--output", $XRANDR_OUTPUT, "--mode", $XRANDR_MODE, "--rate", $new; 1227 system "xrandr", "--output", $XRANDR_OUTPUT, "--mode", $XRANDR_MODE, "--rate", $new;
1236 $curfps = $new; 1228 $curfps = $new;
1237 } 1229 }
1238} 1230}
1239 1231
1232our ($PLAYING_STATE, $PLAYING_PATH);
1233
1234sub play_video_speed_mult {
1235 sprintf "%.2f", 1.032 ** $PLAYING_STATE->{speed}
1236}
1237
1238sub play_video_set_speed {
1239 my $speed = play_video_speed_mult;
1240 delete $PLAYING_STATE->{speed} unless $PLAYING_STATE->{speed};
1241
1242 $mpv->cmd ("set", "speed", "$speed");
1243 #$mpv->cmd ("show-text", "playback speed $speed");
1244}
1245
1246our $OSD_LEVEL = $DOOM ? 3 : 3; # was 1 on doom
1247
1248sub sprintf_time($$) {
1249 sprintf $_[0],
1250 sprintf "%02d:%02d:%02d.%03d",
1251 $_[1] / 60 / 60 % 60,
1252 $_[1] / 60 % 60,
1253 $_[1] % 60,
1254 $_[1] * 1000 % 1000;
1255}
1256
1240# does not work: deinterlace, because it returns a boolean and expects i have no clue 1257# does not work: deinterlace, because it returns a boolean and expects i have no clue
1241our %SAVE_PROPERTY = (aid => 1, sid => 1, "audio-delay" => 1); 1258our %SAVE_PROPERTY = (aid => 1, sid => 1, "audio-delay" => 1);
1242 1259
1243sub mpv_init { 1260sub mpv_init {
1244 $mpv->start ("--idle=yes", "--pause", "--force-window=no"); # "--start=$playback_start", "--", $mpv_path; 1261 if ($mpv->start ("--idle=yes", "--pause", "--force-window=no")) { # "--start=$playback_start", "--", $mpv_path)
1262 $mpv->{info_page} = 0;
1263 }
1245 1264
1246 for ( 1265 for (
1247 List::Util::pairs qw( 1266 List::Util::pairs qw(
1248 ESC return 1267 ESC return
1249 q return 1268 q return
1278 1297
1279sub play_video { 1298sub play_video {
1280 ($PLAYING_STATE, $PLAYING_PATH, my $continue) = @_; 1299 ($PLAYING_STATE, $PLAYING_PATH, my $continue) = @_;
1281 1300
1282 my $playback_start = 0; 1301 my $playback_start = 0;
1302 my $target_fps;
1303
1304 my $update_speed = sub {
1305 play_video_set_speed;
1306 my $speed = play_video_speed_mult;
1307 my $fps = $target_fps * $speed;
1308 set_fps $fps;
1309 $mpv->cmd ("show-text", "speed $speed, fps target $target_fps, requested $fps, actual $curfps", 4000)
1310 };
1283 1311
1284 if ($continue) { 1312 if ($continue) {
1285 $playback_start = $PLAYING_STATE->{curpos} // 0; 1313 $playback_start = $PLAYING_STATE->{curpos} // 0;
1286 } else { 1314 } else {
1287 my @menu = ([beginning => 0], [cancel => undef]); 1315 my @menu = ([beginning => 0], [cancel => undef]);
1316 $playback_start = 0; 1344 $playback_start = 0;
1317 } 1345 }
1318 } 1346 }
1319 1347
1320 win_clear; 1348 win_clear;
1321 win_set 0, "starting video..."; 1349 win_set 0, "starting video..."; _win_refresh;
1322 _win_refresh;
1323 1350
1324 my $mpv_path = $PLAYING_PATH; 1351 my $mpv_path = $PLAYING_PATH;
1325 my $initial_deinterlace; 1352 my $initial_deinterlace;
1326 1353
1327 if (is_myth $mpv_path) { 1354 if (is_myth $mpv_path) {
1383 last; 1410 last;
1384 1411
1385 } elsif ($INPUT eq "mpv/file-loaded") { # start playing, configure video 1412 } elsif ($INPUT eq "mpv/file-loaded") { # start playing, configure video
1386 #$mpv->cmd ("seek", $playback_start, "absolute+exact") if $playback_start > 0; 1413 #$mpv->cmd ("seek", $playback_start, "absolute+exact") if $playback_start > 0;
1387 1414
1388 my $target_fps = eval { $mpv->cmd_recv ("get_property", "container-fps") } || 60; 1415 $target_fps = eval { $mpv->cmd_recv ("get_property", "container-fps") } || 60;
1389 $target_fps *= play_video_speed_mult;
1390 set_fps $target_fps;
1391 1416
1392 unless (eval { $mpv->cmd_recv ("get_property", "video-format") }) { 1417 unless (eval { $mpv->cmd_recv ("get_property", "video-format") }) {
1393 # assume audio-only TODO: better test 1418 # assume audio-only TODO: better test
1394 $mpv->cmd ("set", "file-local-options/lavfi-complex", "[aid1] asplit [ao], showcqt=fps=60:size=hd720:count=1:bar_g=2:sono_g=3:sono_v=9:fontcolor='st(0, (midi(f)-53.5)/12); st(1, 0.5 - 0.5 * cos(PI*ld(0))); r(1-ld(1)) + b(ld(1))':tc=0.33:tlength='st(0,0.17); 384*tc / (384 / ld(0) + tc*f /(1-ld(0))) + 384*tc / (tc*f / ld(0) + 384 /(1-ld(0)))', format=yuv420p [vo]"); 1419 $mpv->cmd ("set", "file-local-options/lavfi-complex", "[aid1] asplit [ao], showcqt=fps=60:size=hd720:count=1:bar_g=2:sono_g=3:sono_v=9:fontcolor='st(0, (midi(f)-53.5)/12); st(1, 0.5 - 0.5 * cos(PI*ld(0))); r(1-ld(1)) + b(ld(1))':tc=0.33:tlength='st(0,0.17); 384*tc / (384 / ld(0) + tc*f /(1-ld(0))) + 384*tc / (tc*f / ld(0) + 384 /(1-ld(0)))', format=yuv420p [vo]");
1395 }; 1420 };
1400 } 1425 }
1401 1426
1402 $mpv->cmd ("observe_property", ++$oid, $prop); 1427 $mpv->cmd ("observe_property", ++$oid, $prop);
1403 } 1428 }
1404 1429
1405 play_video_set_speed; 1430 $update_speed->();
1406 $mpv->cmd ("set", "osd-level", "$OSD_LEVEL"); 1431 $mpv->cmd ("set", "osd-level", "$OSD_LEVEL");
1407 $mpv->cmd ("observe_property", ++$oid, "osd-level"); 1432 $mpv->cmd ("observe_property", ++$oid, "osd-level");
1408 $mpv->cmd ("set", "pause", "no");
1409 1433
1410 $mpv->cmd ("set_property", "deinterlace", "yes") 1434 $mpv->cmd ("set_property", "deinterlace", "yes")
1411 if $initial_deinterlace; 1435 if $initial_deinterlace;
1412 1436
1413 $mpv->cmd ("show-text", "FPS: target $target_fps, current $curfps", 2000) 1437 $mpv->cmd ("seek", 0, "relative+exact"); # workaround for sometimes not playing(?) mpv 0.35.1
1414 if $curfps != $fps;#d# 1438 $mpv->cmd ("set", "pause", "no");
1415
1416 win_clear; 1439 win_clear;
1417 1440
1418 } elsif ($INPUT eq "stepfwd") { 1441 } elsif ($INPUT eq "stepfwd") {
1419 ++$PLAYING_STATE->{speed}; 1442 ++$PLAYING_STATE->{speed};
1420 play_video_set_speed; 1443 $update_speed->();
1421 ::state_save; 1444 ::state_save;
1422 } elsif ($INPUT eq "steprev") { 1445 } elsif ($INPUT eq "steprev") {
1423 --$PLAYING_STATE->{speed}; 1446 --$PLAYING_STATE->{speed};
1424 play_video_set_speed; 1447 $update_speed->();
1425 ::state_save; 1448 ::state_save;
1426 1449
1427 } elsif ($INPUT eq "pause") { 1450 } elsif ($INPUT eq "pause") {
1428 $mpv->cmd ("cycle", "pause"); 1451 $mpv->cmd ("cycle", "pause");
1429 $PLAYING_STATE->{curpos} = $mpv->cmd_recv ("get_property", "playback-time"); 1452 $PLAYING_STATE->{curpos} = $mpv->cmd_recv ("get_property", "playback-time");
1439 $arg = sprintf "%02d:%02d:%02d", $arg / 100 / 100, $arg / 100 % 100, $arg % 100; 1462 $arg = sprintf "%02d:%02d:%02d", $arg / 100 / 100, $arg / 100 % 100, $arg % 100;
1440 } 1463 }
1441 $mpv->cmd ("osd-msg", "seek", $arg, "absolute+exact"); 1464 $mpv->cmd ("osd-msg", "seek", $arg, "absolute+exact");
1442 } else { 1465 } else {
1443 #$mpv->cmd ("osd-msg-bar", "show-progress"); 1466 #$mpv->cmd ("osd-msg-bar", "show-progress");
1467
1468 my $info_page = $mpv->{info_page};
1469
1470 if (!$info_page) {
1444 $mpv->cmd ("script-binding", "stats/display-stats-toggle"); 1471 $mpv->cmd ("script-binding", "stats/display-stats-toggle");
1472 }
1473
1474 ++$info_page;
1475
1476 if ($info_page == 4) {
1477 $info_page = 0;
1478 $mpv->cmd ("script-binding", "stats/display-page-1");
1479 $mpv->cmd ("script-binding", "stats/display-stats-toggle");
1480 } else {
1481 $mpv->cmd ("script-binding", "stats/display-page-$info_page");
1482 }
1483
1484 $mpv->{info_page} = $info_page;
1445 } 1485 }
1446 1486
1447 } elsif ($INPUT eq "yellow") { 1487 } elsif ($INPUT eq "yellow") {
1448 $mpv->cmd ("osd-auto", "cycle-values", "osd-level", "2", "3", "0", "1"); 1488 $mpv->cmd ("osd-auto", "cycle-values", "osd-level", "2", "3", "0", "1");
1449 1489

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines