Ticket #5643: gen-refresh-rate-map.pl

File gen-refresh-rate-map.pl, 1.3 KB (added by Boleslaw Ciesielski <bolek-mythtv@…>, 11 years ago)

script to generate refresh rate map file

Line 
1#!/usr/bin/perl -w
2
3use strict;
4
5sub xrandr {
6    my ($width, $height, $xrate) = @_;
7    my $xrandr_cmd = sprintf("xrandr -s %dx%d -r %d", $width, $height, $xrate);
8    system($xrandr_cmd) == 0 or die "$xrandr_cmd\nfailed";
9}
10
11my $save_width;
12my $save_height;
13my $save_xrate;
14
15open(XRANDR, "xrandr |") or die "Cannot execute xrandr";
16while (<XRANDR>) {
17    if (/^\s+(\d+)x(\d+)\s+(.+)/) {
18        my $width = $1;
19        my $height = $2;
20        my $rates = $3;
21        my @rates = split(' ', $rates);
22        foreach my $xrate (@rates) {
23            if ($xrate =~ /\*$/) {
24                chop($xrate);
25                $save_width = $width;
26                $save_height = $height;
27                $save_xrate = $xrate;
28            }
29            xrandr($width, $height, $xrate);
30
31            my $xvidtune = `xvidtune -show`;
32            my ($mode, $pclk,
33                $hdisp, $hstart, $hend, $htotal,
34                $vdisp, $vstart, $vend, $vtotal) = split(' ', $xvidtune);
35            my $drate = ($pclk * 1000000.0) / ($htotal * $vtotal);
36            my $drate_str =
37                ($xvidtune =~ /interlace/i ?
38                 sprintf("%.2fi,", $drate * 2.0) :
39                 sprintf("%.2f,", $drate));
40            printf "%d,%d,%s%2d\n", $width, $height, $drate_str, $xrate;
41        }
42    }
43}
44
45close(XRANDR);
46xrandr($save_width, $save_height, $save_xrate);