File: ogg.t

package info (click to toggle)
libaudio-scan-perl 0.93%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 6,152 kB
  • sloc: ansic: 11,482; perl: 241; sh: 48; makefile: 2
file content (271 lines) | stat: -rw-r--r-- 8,114 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
use strict;

use File::Spec::Functions;
use FindBin ();
use Test::More tests => 70;

use Audio::Scan;

my $HAS_ENCODE;
eval {
    require Encode;
    $HAS_ENCODE = 1;
};

# Basics
{
    my $s = Audio::Scan->scan( _f('test.ogg'), { md5_size => 4096 } );

    my $info = $s->{info};
    my $tags = $s->{tags};
    
    SKIP:
    {
        skip 'Encode is not available', 1 unless $HAS_ENCODE;
        my $utf8 = Encode::decode_utf8('シチヅヲ');
        is($tags->{PERFORMER}, $utf8, 'PERFORMER (UTF8) Tag ok');
    }

    is($tags->{ARTIST}, 'Test Artist', 'ASCII Tag ok');
    is($tags->{YEAR}, 2009, 'Year Tag ok');
    ok($tags->{VENDOR} =~ /Xiph/, 'Vendor ok');

    is($info->{bitrate_average}, 757, 'Bitrate ok');
    is($info->{channels}, 2, 'Channels ok');
    is($info->{file_size}, 4553, 'File size ok' );
    is($info->{stereo}, 1, 'Stereo ok');
    is($info->{samplerate}, 44100, 'Sample Rate ok');
    is($info->{song_length_ms}, 3684, 'Song length ok');
    is($info->{audio_offset}, 4204, 'Audio offset ok');
    is($info->{audio_size}, 349, 'Audio size ok');
    is($info->{audio_md5}, '9b38152aacb22c128375274add565f99', 'Audio MD5 ok' );
}

# Multiple tags.
{
    my $s = Audio::Scan->scan( _f('multiple.ogg') );

    my $tags = $s->{tags};

    is($tags->{ARTIST}[0], 'Multi 1', 'Multiple Artist 1 ok');
    is($tags->{ARTIST}[1], 'Multi 2', 'Multiple Artist 1 ok');
    is($tags->{ARTIST}[2], 'Multi 3', 'Multiple Artist 1 ok');
}

# Equals char in tag.
{
    my $s = Audio::Scan->scan( _f('equals-char.ogg') );

    my $tags = $s->{tags};

    is($tags->{TITLE}, 'Me - You = Loneliness', 'Equals char in tag ok');
}

# Large page size.
{
    my $s = Audio::Scan->scan( _f('large-pagesize.ogg') );

    my $info = $s->{info};
    my $tags = $s->{tags};

    is($info->{audio_offset}, 110616, 'Large page size audio offset ok');
    is($tags->{TITLE}, 'Deadzy', 'Large page title tag ok');
    is($tags->{ARTIST}, 'Medeski Scofield Martin & Wood', 'Large page artist tag ok');
    is($tags->{ALBUM}, 'Out Louder (bonus disc)', 'Large page album tag ok');
}

# Test COVERART
{
    local $ENV{AUDIO_SCAN_NO_ARTWORK} = 1;
    
    my $s = Audio::Scan->scan( _f('large-pagesize.ogg') );
    
    my $tags = $s->{tags};
    my $pic = $tags->{ALLPICTURES}->[0];
    
    is( $pic->{color_index}, 0, 'COVERART color_index ok' );
    is( $pic->{depth}, 0, 'COVERART depth ok' );
    is( $pic->{description}, '', 'COVERART description ok' );
    is( $pic->{height}, 0, 'COVERART height ok' );
    is( $pic->{image_data}, 104704, 'COVERART length ok' ); # this is the base64-encoded length
    is( $pic->{mime_type}, 'image/', 'COVERART mime_type ok' );
    is( $pic->{picture_type}, 0, 'COVERART picture_type ok' );
    is( $pic->{width}, 0, 'COVERART width ok' );
}

# Test COVERART data
{
    my $s = Audio::Scan->scan( _f('large-pagesize.ogg') );
    
    my $tags = $s->{tags};
    my $pic = $tags->{ALLPICTURES}->[0];
    
    is( length( $pic->{image_data} ), 78527, 'COVERART real length ok' ); # without base64 encoding
    is( unpack( 'H*', substr( $pic->{image_data}, 0, 4 ) ), 'ffd8ffe0', 'COVERART JPEG picture data ok ');
}

# Test METADATA_BLOCK_PICTURE
{
    local $ENV{AUDIO_SCAN_NO_ARTWORK} = 1;
    
    my $s = Audio::Scan->scan( _f('metadata-block-picture.ogg') );
    
    my $tags = $s->{tags};
    my $pic  = $tags->{ALLPICTURES}->[0];
    my $pic2 = $tags->{ALLPICTURES}->[1];
    
    is( $pic->{color_index}, 0, 'METADATA_BLOCK_PICTURE color_index ok' );
    is( $pic->{depth}, 0, 'METADATA_BLOCK_PICTURE depth ok' );
    is( $pic->{description}, '', 'METADATA_BLOCK_PICTURE description ok' );
    is( $pic->{height}, 0, 'METADATA_BLOCK_PICTURE height ok' );
    is( $pic->{image_data}, 25078, 'METADATA_BLOCK_PICTURE length ok' );
    is( $pic->{mime_type}, 'image/jpeg', 'METADATA_BLOCK_PICTURE mime_type ok' );
    is( $pic->{picture_type}, 3, 'METADATA_BLOCK_PICTURE picture_type ok' );
    is( $pic->{width}, 0, 'METADATA_BLOCK_PICTURE width ok' );
    
    is( $pic2->{image_data}, 1761, 'METADATA_BLOCK_PICTURE pic2 length ok' );
}

# Test METADATA_BLOCK_PICTURE data
{
    my $s = Audio::Scan->scan( _f('metadata-block-picture.ogg') );
    
    my $tags = $s->{tags};
    my $pic  = $tags->{ALLPICTURES}->[0];
    my $pic2 = $tags->{ALLPICTURES}->[1];
    
    is( length( $pic->{image_data} ), 25078, 'METADATA_BLOCK_PICTURE real length ok' );
    is( unpack( 'H*', substr( $pic->{image_data}, 0, 4 ) ), 'ffd8ffe0', 'METADATA_BLOCK_PICTURE JPEG picture data ok ');
    
    is( length( $pic2->{image_data} ), 1761, 'METADATA_BLOCK_PICTURE pic2 real length ok' );
    is( unpack( 'H*', substr( $pic2->{image_data}, 0, 4 ) ), 'ffd8ffe0', 'METADATA_BLOCK_PICTURE JPEG pic2 data ok ');
}

# Old encoder files.
{
    my $s1 = Audio::Scan->scan( _f('old1.ogg') );
    is($s1->{tags}->{ALBUM}, 'AutoTests', 'Old encoded album tag ok');
    is($s1->{info}->{samplerate}, 8000, 'Old encoded rate ok');

    my $s2 = Audio::Scan->scan( _f('old2.ogg') );
    is($s2->{tags}->{ALBUM}, 'AutoTests', 'Old encoded album tag ok');
    is($s2->{info}->{samplerate}, 12000, 'Old encoded rate ok');
}

# SC bugs
{
    my $s = Audio::Scan->scan( _f('bug1155-1.ogg') );

    my $info = $s->{info};

    is($info->{bitrate_nominal}, 206723, 'Bug1155 nominal bitrate ok');
    is($info->{bitrate_average}, 922, 'Bug1155 avg bitrate ok');
    is($info->{song_length_ms}, 187146, 'Bug1155 duration ok');
}

{
    my $s = Audio::Scan->scan( _f('bug1155-2.ogg') );

    my $info = $s->{info};

    is($info->{bitrate_average}, 2028, 'Bug1155-2 bitrate ok');
    is($info->{song_length_ms}, 5864, 'Bug1155-2 duration ok');
}

{
    my $s = Audio::Scan->scan( _f('bug803.ogg') );

    my $info = $s->{info};
    
    is($info->{bitrate_average}, 633, 'Bug803 bitrate ok');
    is($info->{song_length_ms}, 219104, 'Bug803 song length ok');
}

{
    my $s = Audio::Scan->scan( _f('bug905.ogg') );

    my $info = $s->{info};
    my $tags = $s->{tags};
    
    is($info->{bitrate_average}, 534, 'Bug905 bitrate ok');
    is($info->{song_length_ms}, 223484, 'Bug905 song length ok');
    is($tags->{DATE}, '08-05-1998', 'Bug905 date ok');
}

# Scan via a filehandle
{
    open my $fh, '<', _f('test.ogg');
    
    my $s = Audio::Scan->scan_fh( ogg => $fh );
    
    my $info = $s->{info};
    my $tags = $s->{tags};

    is($tags->{ARTIST}, 'Test Artist', 'ASCII Tag ok via filehandle');
    is($tags->{YEAR}, 2009, 'Year Tag ok via filehandle');

    is($info->{bitrate_average}, 757, 'Bitrate ok via filehandle');
    
    close $fh;
}

# Find frame offset
{
    my $offset = Audio::Scan->find_frame( _f('normal.ogg'), 800 );
    
    is( $offset, 12439, 'Find frame ok' );
}

# Test special case where target sample is in the first frame
{
    my $offset = Audio::Scan->find_frame( _f('normal.ogg'), 300 );
    
    is( $offset, 3979, 'Find sample in first frame ok' );
}

{
    open my $fh, '<', _f('normal.ogg');
    
    my $offset = Audio::Scan->find_frame_fh( ogg => $fh, 600 );
    
    is( $offset, 8259, 'Find frame via filehandle ok' );
    
    close $fh;
}

# Bug 12615, aoTuV-encoded file uncovered bug in offset calculation
{
    my $s = Audio::Scan->scan( _f('bug12615-aotuv.ogg') );
    
    my $info = $s->{info};
    my $tags = $s->{tags};
    
    is( $info->{audio_offset}, 3970, 'Bug 12615 aoTuV offset ok' );
    
    like( $tags->{VENDOR}, qr/aoTuV/, 'Bug 12615 aoTuV tags ok' );
}

# Test file with page segments > 128
{
    my $s = Audio::Scan->scan( _f('large-page-segments.ogg') );
    
    my $info = $s->{info};
    my $tags = $s->{tags};
    
    is( $info->{audio_offset}, 41740, 'Large page segments audio offset ok' );
    is( $tags->{ARTIST}, 'Led Zeppelin', 'Large page segments comments ok' );
}

# Test file with multiple logical bitstreams
{
    my $s = Audio::Scan->scan( _f('multiple-bitstreams.ogg') );
    
    my $info = $s->{info};
    
    is( $info->{bitrate_average}, 128000, 'Multiple bitstreams bitrate ok' );
    is( $info->{song_length_ms}, 0, 'Multiple bitstreams length ok' );
}

sub _f {
    return catfile( $FindBin::Bin, 'ogg', shift );
}