ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Convert-CD/lib/Convert/CD/Analyze.pm
Revision: 1.1
Committed: Wed Jun 11 10:50:58 2003 UTC (23 years, 3 months ago) by root
Branch: MAIN
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 =head1 NAME
2    
3     Convert::CD::Analyze - dirty incorrect guessing of img tracks.
4    
5     =head1 SYNOPSIS
6    
7     use Convert::CD::Analyze;
8    
9     # see Convert::CD::TOCFile
10    
11     =head1 DESCRIPTION
12    
13     Try to autodetect the tracks in a monolithic cd image.
14    
15     Audio tracks cannot be guessed (they are basically just binary data),
16     while many other formats can. So far, only ISO filesystems are detected,
17     and the space before and after them is tagged as audio.
18    
19     Also, it is assumed that the whole image file uses the same blocksize.
20    
21     This even works for some uncompressed .fcd files.
22    
23     =head2 Convert:CD::Analyze METHODS
24    
25     =over 4
26    
27     =cut
28    
29     package Convert::CD::Analyze;
30    
31     $VERSION = 0.01;
32    
33     use Carp;
34    
35     use Convert::CD::Track;
36    
37     use base Convert::CD::TOCFile;
38    
39     =item new param => value...
40    
41     Create a new Convert::CD::Analyze object.
42    
43     Parameters:
44    
45     path the base image filename
46    
47     =cut
48    
49     sub new {
50     my $class = shift;
51     my $self = bless { @_, }, $class;
52    
53     $self;
54     }
55    
56     sub _read {
57     my ($self, $cd) = @_;
58    
59     defined $self->{path}
60     or croak "no path specified";
61    
62     open my $img, "<", $self->{path}
63     or croak "$self->{path}: $!";
64    
65     # scan through the image, if necessary through the full image
66     # we are dumb, to instead of using an intelligent algorithm, we just
67     # use an overlapping buffer
68     my $buf;
69     my $secsize;
70     my $isoofs;
71    
72     my $bcd60 = join "", map sprintf ("\\x%02d", $_), 0..59;
73     my $bcd75 = join "", map sprintf ("\\x%02d", $_), 0..74;
74     my $sync = "\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00";
75     my $msf = qr<(.)([$bcd60])([$bcd75])([\x00\x01\x02])>o;
76    
77     #my $
78    
79     while (sysread $img, $buf, 256*1024, length $buf) {
80     # check sync 00 ff ff ff ff ff ff ff ff ff ff 00 M S F mode
81     # form1: 00 00 08 00 00 00 08 00 # form1
82     # XA subheader format: FileNumber, ChannelNumber, SubMode, CodingInformation
83     # FileNumber = the unique ID for a single XA file
84     # ChannelNumber = the file is multimedia (1) or not (0)
85     # SubMode = XA content description: struct SubMode { uint8 EndOfRecord:1;
86     # CodingInformation = type of data: uint8 VideoData:1;
87     # 0x00 = empty/data sector uint8 ADCPM:1;
88     # 0x0f = video sector uint8 Data:1;
89     # 0x7f = audio sector uint8 TriggerOn:1;
90     # 0x80 = MPEG2 (SVCD) uint8 Form2:1;
91     # uint8 RealTime:1;
92     # uint8 EndOfFile:1; };
93    
94     # check for sync, then header and subheader
95     if ($buf =~ /$sync $msf (........)/sox) {
96     my ($m, $s, $f, $mode, $sub) = (
97     (sprintf "%x", (ord $1) % 0xa0),
98     (sprintf "%x", ord $2),
99     (sprintf "%x", ord $3),
100     ord $4,
101     $5
102     );
103     $|=1;
104     print "found raw sector $m:$s:$f $mode ".(unpack "H*", $sub)."\n";
105     }
106    
107     # check for iso
108     if ($buf =~ /\001CD001\001/g) {
109     my $dataofs;
110     my $mode;
111     my $ofs;
112     my $ofs1 = $-[0];
113    
114     if ($ofs1 > 24 && $sync eq substr $buf, $ofs1 - 24, 12) {
115     $dataofs = 24;
116     $ofs = $ofs1 - $dataofs;
117     $mode = MODE_MODE2;
118     } elsif ($ofs1 > 16 && $sync eq substr $buf, $ofs1 - 16, 12) {
119     $dataofs = 16;
120     $ofs = $ofs1 - $dataofs;
121     $mode = MODE_MODE1;
122     } else {
123     $dataofs = 0;
124     $mode = MODE_MODE1;
125     $ofs = $ofs1;
126     }
127    
128     my $size = unpack "N", substr $buf, $ofs1 + 80 + 4, 4;
129    
130     if ($buf =~ /[\000\001\002\003\004\377]CD001\001/g) {
131     my $ofs2 = $-[0];
132    
133     $secsize = $ofs2 - $ofs1;
134    
135     $ofs -= 16 * $secsize;
136    
137     warn "found ISO $dataofs $secsize $ofs $mode $size\n";
138     $cd->append_track (
139     mode => $mode,
140     secsize => $secsize,
141     rawsize => $size * $secsize,
142     offset => $ofs,
143     datasize => 2048,
144     dataoffset => $dataofs,
145     );
146     last;
147     }
148     }
149    
150     substr $buf, 0, (length $buf) - 2448, ""; # some overlap + change
151     }
152     }
153    
154     #sub _write {
155     # my ($self, $cd) = @_;
156     #}
157    
158     1;
159    
160     =back
161    
162     =head1 AUTHOR
163    
164     Marc Lehmann <pcg@goof.com>
165    
166     =cut
167