📄 do_diff_mae_cmo.pl
字号:
#!/tool/pandora/bin/perl -w# <LIC_AMD_STD># Copyright (C) 2003-2005 Advanced Micro Devices, Inc. All Rights Reserved.# # Unless otherwise designated in writing, this software and any related # documentation are the confidential proprietary information of AMD. # THESE MATERIALS ARE PROVIDED "AS IS" WITHOUT ANY# UNLESS OTHERWISE NOTED IN WRITING, EXPRESS OR IMPLIED WARRANTY OF ANY # KIND, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, # NONINFRINGEMENT, TITLE, FITNESS FOR ANY PARTICULAR PURPOSE AND IN NO # EVENT SHALL AMD OR ITS LICENSORS BE LIABLE FOR ANY DAMAGES WHATSOEVER. # # AMD does not assume any responsibility for any errors which may appear # in the Materials nor any responsibility to support or update the# Materials. AMD retains the right to modify the Materials at any time, # without notice, and is not obligated to provide such modified # Materials to you. AMD is not obligated to furnish, support, or make# any further information available to you.# </LIC_AMD_STD> # <CTL_AMD_STD># </CTL_AMD_STD> # <DOC_AMD_STD># </DOC_AMD_STD> use strict;use FileHandle;use Getopt::Long;use Compress::Zlib;my %cl_opt;Getopt::Long::config("no_auto_abbrev");Getopt::Long::config("pass_through");Getopt::Long::GetOptions(\%cl_opt, "mae_block_diff|rbdiff|rbd=i", "iquant_diff|iqdiff|iqd=i", "mc_diff|mcdiff|mcd=i", "peak_diff|peakdiff|pd=i", "final_diff|finaldiff|fd=i", "omse=f", "ome=f", "pmse=f", "pme=f", "mp4", "mp2", "wm9", "wm9_skip", # for wm9 -g use only .CMO* files for -all "check_mc", "keep_going|k", "report", "log", "debug", "all", "final", "spew");# Prototype because used in checking command line argumentssub Msg($$);#==========================================================================## Defaults# use vars qw($mp4 $mp2 $wm9 $error); if (!defined($cl_opt{"mp4"}) and !defined($cl_opt{"mp2"}) and !defined($cl_opt{"wm9"})) { Msg('ERROR', "One of -wm9, -mp4, or -mp2 must be specified!"); } $error = 0; $mp4 = defined($cl_opt{"mp4"}) ? 1 : 0; $mp2 = defined($cl_opt{"mp2"}) ? 1 : 0; $wm9 = defined($cl_opt{"wm9"}) ? 1 : 0; use vars qw($ppe $iquant_diff $mae_block_diff $mc_diff $peak_diff $final_diff); $ppe = ($wm9 ? 0 : 1); # IQUANT is always exact, or not used on MPEG-4 $iquant_diff = defined($cl_opt{"iquant_diff"}) ? $cl_opt{"iquant_diff"} : 0; $mae_block_diff = defined($cl_opt{"mae_block_diff"}) ? $cl_opt{"mae_block_diff"} : ($wm9 ? 0 : 3); $mc_diff = defined($cl_opt{"mc_diff"}) ? $cl_opt{"mc_diff"} : ($wm9 ? 0 : 3); $peak_diff = defined($cl_opt{"peak_diff"}) ? $cl_opt{"peak_diff"} : ($wm9 ? 0 : 0); $final_diff = defined($cl_opt{"final_diff"}) ? $cl_opt{"final_diff"} : ($wm9 ? 0 : 3); use vars qw($omse $ome $pmse $pme); $omse = defined($cl_opt{"omse"}) ? $cl_opt{"omse"} : .02; $ome = defined($cl_opt{"ome"}) ? $cl_opt{"ome"} : .0015; $pmse = defined($cl_opt{"pmse"}) ? $cl_opt{"pmse"} : .06; $pme = defined($cl_opt{"pme"}) ? $cl_opt{"pme"} : .015;##==========================================================================# -------------------------------------------------sub usage() {# ------------------------------------------------- Msg('Usage', "do_diff.pl [Options] <name> [<name1> <name2>]"); Msg('Usage', ""); Msg('Usage', "Options:"); Msg('Usage', " -debug # Print verbose diff"); Msg('Usage', " -report # Print stats while running"); Msg('Usage', " -keep_going # Continue when error detected"); Msg('Usage', ""); Msg('Usage', "One of the following is required:"); Msg('Usage', " -mp4 # Use MPEG-4 allowed differences"); Msg('Usage', " -mp2 # Use MPEG-2 allowed differences"); Msg('Usage', " -wm9 # Use Windows Media 9 allowed differences"); Msg('Usage', ""); Msg('Usage', " High level checks:"); Msg('Usage', " -mae_block_diff | -rbd <max> # Fail if RefBlocks diff > <max>"); Msg('Usage', " -iquant_diff | -iqd <max> # Fail if IQUANT* diff > <max>"); Msg('Usage', " -mc_diff | -mcd <max> # Fail if MC* diff > <max>"); Msg('Usage', ""); Msg('Usage', " IDCT specific checks:"); Msg('Usage', " -omse # Specify IEEE omse maximum"); Msg('Usage', " -ome # Specify IEEE ome maximum"); Msg('Usage', " -pmse # Specify IEEE pmse maximum"); Msg('Usage', " -pme # Specify IEEE pme maximum"); Msg('Usage', ""); Msg('Usage', " Motion compensation specific checks:"); Msg('Usage', ""); Msg('Usage', " -check_mc # Verify RefBlocks -> MC doesn't increase peak error"); Msg('Usage', ""); Msg('Usage', "Notes:"); Msg('Usage', " 1. ppe is always hardcoded to 1"); Msg('Usage', " 2. Always fails if sees array values <-255 or >255"); Msg('Usage', " ***This will have to be fixed for non-MP4 IQUANT***"); Msg('Usage', " 3. -check_mc is NOT on by default"); exit(1);}#==========================================================================## State tracking use vars qw($iquant $idct $mc $mae_blocks $final);##==========================================================================#==========================================================================## IDCT tracking# use vars qw($omse_num $ome_num @pmse_num @pme_num $oe_total $pe_total); # ------------------------------------------------- sub reset_idct_tracking { # ------------------------------------------------- $omse_num = 0; # Stream total abs(diff) for all (i,j) $ome_num = 0; # Stream total diff for all (i,j) @pmse_num = ( # Stream abs(diff) at each (i,j) 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ); @pme_num = @pmse_num; # Stream diff at each (i,j) $oe_total = 0; # Stream total number of (i,j) $pe_total = 0; # Stream total number of blocks } # ------------------------------------------------- sub check_idct() { # ------------------------------------------------- Msg('Report', "Checking IDCT accuracy..."); my $calc_omse = $omse_num / $oe_total; my $calc_ome = $ome_num / $oe_total; Msg('Report', sprintf("omse: %7.4f [require < %7.4f]", $calc_omse, $omse)); Msg('Report', sprintf("ome : %7.4f [require < %7.4f]", $calc_ome, $ome)); Msg('ERROR', "$calc_omse > allowed $omse") unless ($calc_omse <= $omse); Msg('ERROR', "$calc_ome > allowed $ome") unless ($calc_ome <= $ome); my $line = ""; $line .= sprintf(" pmse [require < %7.4f] ", $pmse); $line .= sprintf(" pme [require < %7.4f]", $pme); Msg('Report', $line); my (@calc_pmse, @calc_pme); for (my $row = 0; $row < 8; $row++) { my ($pmse_line, $pme_line) = ("", ""); for (my $col = 0; $col < 8; $col++) { my $entry = $row * 8 + $col; $calc_pmse[$entry] = $pmse_num[$entry] / $pe_total; $calc_pme [$entry] = $pme_num [$entry] / $pe_total; $pmse_line .= sprintf("%7.4f ", $calc_pmse[$entry]); $pme_line .= sprintf("%7.4f ", $calc_pme [$entry]); } Msg('Report', $pmse_line." ".$pme_line); } for (my $i = 0; $i < 64; $i++) { Msg('ERROR', "$calc_pmse[$i] > allowed $pmse for entry $i") unless ($calc_pmse[$i] <= $pmse); Msg('ERROR', "$calc_pme[$i] > allowed $pme for entry $i") unless ($calc_pme[$i] <= $pme); } }##==========================================================================#==========================================================================## RefBlocks->MC tracking## Maximum peak difference in macroblock use vars qw(%peak_mae %peak_diff);##==========================================================================#==========================================================================## File I/O# use vars qw($zipped $peeked $peek_m_line $peek_r_line $M $R); sub file_open ($) { # Note: All inputs are maeerences my ($file) = @_; # Find file my $ext = ""; if (-r "$$file.mae" and -r "$$file.cmo") { $zipped = 0; $ext = ""; } elsif (-r "$$file.mae.gz" and -r "$$file.cmo.gz") { $zipped = 1; $ext = ".gz"; } else { Msg('ERROR', "Can't find $$file.(mae|cmo) or $$file.(mae|cmo).gz, player broken?"); return 0; } # Open file #$zipped = (`file $$file.mae$ext` =~ /gzip/) ? 1 : 0; if ($zipped) { Debug("Found gzip'ed file $$file"); $M = Compress::Zlib::gzopen("$$file.cmo$ext", "r"); $R = Compress::Zlib::gzopen("$$file.mae$ext", "r"); } else { $M = new FileHandle; $R = new FileHandle; $M->open("<$$file.cmo$ext") or die "can't open $$file.cmo$ext"; $R->open("<$$file.mae$ext") or die "can't open $$file.mae$ext"; } # Initial peek state $peeked = 0; return 1; } sub file_getlines($$$) { # Note: All inputs are maeerences # Note: Returns 1 if EOF my ($m_line, $r_line, $peek) = @_; # If already fetched these lines, just return them if ($peeked) { $$m_line = $peek_m_line; $$r_line = $peek_r_line; $peeked = 0; return 0; } my $eof; if ($zipped) { my $m_bytes = $M->gzreadline($$m_line); my $r_bytes = $R->gzreadline($$r_line); $eof = ($m_bytes == 0) ? 1 : 0; } else { $$m_line = $M->getline(); $$r_line = $R->getline(); $eof = defined($$m_line) ? 0 : 1; } if (!$eof) { chomp($$m_line); chomp($$r_line); if (defined($cl_opt{"spew"})) { Debug("M_PROC $$m_line"); Debug("R_PROC $$r_line"); } } if ($peek) { $peek_m_line = $$m_line; $peek_r_line = $$r_line; $peeked = 1; } return $eof; }##==========================================================================sub by_frame { my $aa = $a; $aa =~ s/(Final|MC|RefBlocksMV|IQUANT|IDCT|DB|OL|For)//g; $aa =~ s/(Intra|Inter)//; $aa =~ s/[YUV]//; $aa =~ s/[BP]//; $aa =~ s/.(mae|cmo).gz//; my $bb = $b; $bb =~ s/(Final|MC|RefBlocksMV|IQUANT|IDCT|DB|OL|For)//g; $bb =~ s/(Intra|Inter)//; $bb =~ s/[YUV]//; $bb =~ s/[BP]//; $bb =~ s/.(mae|cmo).gz//; #print "$aa $bb\n"; return $aa <=> $bb;}# -------------------------------------------------sub main() {# ------------------------------------------------- log_open("do_diff.log") if defined($cl_opt{"log"}); usage() unless (defined($cl_opt{"all"}) or ($#ARGV > -1)); my %files; my $num_idct_files = 0; my @expanded_argv; # Avoid shell limits on maximum # of files if (defined($cl_opt{"all"})) { my $all_string; if (defined($cl_opt{"wm9_skip"})) { $all_string = "*.cmo.gz *.cmo"; } else { $all_string = "*.gz *.mae *.cmo"; } foreach my $file (glob($all_string)) { if (defined($cl_opt{"final"})) { if ($file !~ /^(Final|DB|OL)/) { print "Ignoring $file\n"; next; } } print "Adding $file\n"; push(@expanded_argv, $file); } } foreach my $file (@ARGV) { if ($file =~ /\*/) { push(@expanded_argv, glob($file)); } else { push(@expanded_argv, $file); } } foreach my $file (@expanded_argv) { $file =~ s/\.cmo$//; $file =~ s/\.cmo.gz$//; $file =~ s/\.mae$//; $file =~ s/\.mae.gz$//; if (!$wm9 and ($file =~ /MCInter/)) { #$cl_opt{"check_mc"} = 1; } if ($file =~ /IDCT/) { $num_idct_files++; } $files{$file} = 1; } my $did_idct = 0; reset_idct_tracking(); foreach my $file (sort by_frame keys %files) { if ($file =~ /Final/) { ($iquant, $idct, $mc, $mae_blocks, $final) = (0, 0, 0, 0, 1); do_diff($file, $final_diff); } elsif ($file =~ /IDCT/) { ($iquant, $idct, $mc, $mae_blocks, $final) = (0, 1, 0, 0, 0); do_diff($file, $ppe); } elsif ($file =~ /VLD/) { ($iquant, $idct, $mc, $mae_blocks, $final) = (1, 0, 0, 0, 0); do_diff($file, $iquant_diff); } elsif ($file =~ /IQUANT/) { ($iquant, $idct, $mc, $mae_blocks, $final) = (1, 0, 0, 0, 0); do_diff($file, $iquant_diff); } elsif ($file =~ /MC/) { if (defined($cl_opt{"check_mc"})) { my $rb_file = $file; $rb_file =~ s/MCInter/RefBlocksMV/; undef %peak_mae; undef %peak_diff; ($iquant, $idct, $mc, $mae_blocks, $final) = (0, 0, 0, 1, 0); do_diff($rb_file, $mae_block_diff); } ($iquant, $idct, $mc, $mae_blocks, $final) = (0, 0, 1, 0, 0); do_diff($file, $mc_diff); } elsif ($file =~ /RefBlock/) { if (!defined($cl_opt{"check_mc"})) { ($iquant, $idct, $mc, $mae_blocks, $final) = (0, 0, 0, 1, 0); do_diff($file, $mae_block_diff); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -