mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-11-09 21:22:39 -05:00
songdb.pl now calculates the checksum for Ogg Vorbis files by starting at the first page of audio data
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7124 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
b3437ecbfe
commit
40a8401cd3
2 changed files with 59 additions and 3 deletions
|
|
@ -106,6 +106,16 @@ sub get_oggtag {
|
||||||
return \%hash;
|
return \%hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub get_ogginfo {
|
||||||
|
my $fn = shift;
|
||||||
|
my %hash;
|
||||||
|
|
||||||
|
my $ogg = vorbiscomm->new($fn);
|
||||||
|
|
||||||
|
my $h= $ogg->load;
|
||||||
|
|
||||||
|
return $ogg->{'INFO'};
|
||||||
|
}
|
||||||
|
|
||||||
# return ALL directory entries in the given dir
|
# return ALL directory entries in the given dir
|
||||||
sub getdir {
|
sub getdir {
|
||||||
|
|
@ -231,17 +241,19 @@ sub crc32 {
|
||||||
sub singlefile {
|
sub singlefile {
|
||||||
my ($file) = @_;
|
my ($file) = @_;
|
||||||
my $hash;
|
my $hash;
|
||||||
|
my $info;
|
||||||
|
|
||||||
if($file =~ /\.ogg$/i) {
|
if($file =~ /\.ogg$/i) {
|
||||||
$hash = get_oggtag($file);
|
$hash = get_oggtag($file);
|
||||||
|
|
||||||
# CRC from 0 until we figure out exactly where the audio data starts!
|
$info = get_ogginfo($file);
|
||||||
$hash->{FILECRC} = crc32($file, 0);
|
|
||||||
|
$hash->{FILECRC} = crc32($file, $info->{audio_offset});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$hash = get_mp3tag($file);
|
$hash = get_mp3tag($file);
|
||||||
|
|
||||||
my $info = get_mp3info($file);
|
$info = get_mp3info($file);
|
||||||
|
|
||||||
$hash->{FILECRC} = crc32($file, $info->{headersize});
|
$hash->{FILECRC} = crc32($file, $info->{headersize});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -415,6 +415,50 @@ sub _loadComments
|
||||||
$data->{'INFO'}{'offset'} = $byteCount;
|
$data->{'INFO'}{'offset'} = $byteCount;
|
||||||
|
|
||||||
$data->{'COMMENTS'} = \%comments;
|
$data->{'COMMENTS'} = \%comments;
|
||||||
|
|
||||||
|
# Now find the offset of the first page
|
||||||
|
# with audio data.
|
||||||
|
while(_findPage($fh))
|
||||||
|
{
|
||||||
|
$byteCount = tell($fh) - 4;
|
||||||
|
|
||||||
|
# version flag
|
||||||
|
read($fh, $buffer, 1);
|
||||||
|
if (ord($buffer) != 0x00)
|
||||||
|
{
|
||||||
|
warn "Invalid stream structure version: " .
|
||||||
|
sprintf("%x", ord($buffer));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
# header type flag
|
||||||
|
read($fh, $buffer, 1);
|
||||||
|
# Audio data starts as a fresh packet on a new page, so
|
||||||
|
# if header_type is odd it's not a fresh packet
|
||||||
|
next if ( ord($buffer) % 2 );
|
||||||
|
|
||||||
|
# skip past granule position, stream_serial_number,
|
||||||
|
# page_sequence_number, and crc
|
||||||
|
read($fh, $buffer, 20);
|
||||||
|
|
||||||
|
# page_segments
|
||||||
|
read($fh, $buffer, 1);
|
||||||
|
my $page_segments = ord($buffer);
|
||||||
|
|
||||||
|
# skip past the segment table
|
||||||
|
read($fh, $buffer, $page_segments);
|
||||||
|
|
||||||
|
# read packet_type byte
|
||||||
|
read($fh, $buffer, 1);
|
||||||
|
|
||||||
|
# Not an audio packet. All audio packet numbers are even
|
||||||
|
next if ( ord($buffer) % 2 );
|
||||||
|
|
||||||
|
# Found the first audio packet
|
||||||
|
last;
|
||||||
|
}
|
||||||
|
|
||||||
|
$data->{'INFO'}{'audio_offset'} = $byteCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub _calculateTrackLength
|
sub _calculateTrackLength
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue