~ubuntu-branches/ubuntu/precise/flac/precise-updates

« back to all changes in this revision

Viewing changes to src/libFLAC/format.c

  • Committer: Bazaar Package Importer
  • Author(s): Joshua Kwan
  • Date: 2007-05-29 22:56:36 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070529225636-ljeff8xxip09qaap
Tags: 1.1.4-1
* New upstream release. closes: #405167, #411311
  - libOggFLAC and libOggFLAC++ have been merged into libFLAC, so
    remove their corresponding packages.
  - Because of the API changes required to effect the above, there has
    been yet another soname bump. libflac7 -> libflac8 and
    libflac++5 -> libflac++6. Emails have been dispatched to the
    maintainers of dependent packages.
* Some notes on patches that were removed:
  - 02_stdin_stdout, 06_manpage_mention_utf8_convert: merged upstream
  - 08_manpage_warnings: Upstream has changed the manpage so it defintely
    can't fit in in 80 cols, so just forget about it. We'll live.
  - 05_eof_warnings_are_errors: Upstream decided to add a -w option to
    flac to treat all warnings as errors. I am going to defer to that
    for now, but if people think it's stupid let me know and I'll port
    the patch forward.
  - 04_stack_smasher: was a backport from 1.1.3, so it's obsolete.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* libFLAC - Free Lossless Audio Codec library
2
 
 * Copyright (C) 2000,2001,2002,2003,2004,2005  Josh Coalson
 
2
 * Copyright (C) 2000,2001,2002,2003,2004,2005,2006,2007  Josh Coalson
3
3
 *
4
4
 * Redistribution and use in source and binary forms, with or without
5
5
 * modification, are permitted provided that the following conditions
29
29
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
30
 */
31
31
 
 
32
#if HAVE_CONFIG_H
 
33
#  include <config.h>
 
34
#endif
 
35
 
32
36
#include <stdio.h>
33
37
#include <stdlib.h> /* for qsort() */
34
38
#include "FLAC/assert.h"
35
39
#include "FLAC/format.h"
36
40
#include "private/format.h"
37
41
 
38
 
#ifdef HAVE_CONFIG_H
39
 
#include <config.h>
40
 
#endif
41
 
 
42
42
#ifdef min
43
43
#undef min
44
44
#endif
54
54
/* VERSION should come from configure */
55
55
FLAC_API const char *FLAC__VERSION_STRING = VERSION;
56
56
 
57
 
#if defined _MSC_VER || defined __MINW32__
 
57
#if defined _MSC_VER || defined __BORLANDC__ || defined __MINW32__
58
58
/* yet one more hack because of MSVC6: */
59
 
FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC 1.1.2 20050205";
 
59
FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC 1.1.4 20070213";
60
60
#else
61
 
FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC " VERSION " 20050205";
 
61
FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC " VERSION " 20070213";
62
62
#endif
63
63
 
64
64
FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4] = { 'f','L','a','C' };
65
65
FLAC_API const unsigned FLAC__STREAM_SYNC = 0x664C6143;
66
 
FLAC_API const unsigned FLAC__STREAM_SYNC_LEN = 32; /* bits */;
 
66
FLAC_API const unsigned FLAC__STREAM_SYNC_LEN = 32; /* bits */
67
67
 
68
68
FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN = 16; /* bits */
69
69
FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN = 16; /* bits */
104
104
FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN = 7+258*8; /* bits */
105
105
FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN = 8; /* bits */
106
106
 
 
107
FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_TYPE_LEN = 32; /* bits */
 
108
FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN = 32; /* bits */
 
109
FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN = 32; /* bits */
 
110
FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN = 32; /* bits */
 
111
FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN = 32; /* bits */
 
112
FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN = 32; /* bits */
 
113
FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_COLORS_LEN = 32; /* bits */
 
114
FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN = 32; /* bits */
 
115
 
107
116
FLAC_API const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN = 1; /* bits */
108
117
FLAC_API const unsigned FLAC__STREAM_METADATA_TYPE_LEN = 7; /* bits */
109
118
FLAC_API const unsigned FLAC__STREAM_METADATA_LENGTH_LEN = 24; /* bits */
168
177
        "APPLICATION",
169
178
        "SEEKTABLE",
170
179
        "VORBIS_COMMENT",
171
 
        "CUESHEET"
 
180
        "CUESHEET",
 
181
        "PICTURE"
 
182
};
 
183
 
 
184
FLAC_API const char * const FLAC__StreamMetadata_Picture_TypeString[] = {
 
185
        "Other",
 
186
        "32x32 pixels 'file icon' (PNG only)",
 
187
        "Other file icon",
 
188
        "Cover (front)",
 
189
        "Cover (back)",
 
190
        "Leaflet page",
 
191
        "Media (e.g. label side of CD)",
 
192
        "Lead artist/lead performer/soloist",
 
193
        "Artist/performer",
 
194
        "Conductor",
 
195
        "Band/Orchestra",
 
196
        "Composer",
 
197
        "Lyricist/text writer",
 
198
        "Recording Location",
 
199
        "During recording",
 
200
        "During performance",
 
201
        "Movie/video screen capture",
 
202
        "A bright coloured fish",
 
203
        "Illustration",
 
204
        "Band/artist logotype",
 
205
        "Publisher/Studio logotype"
172
206
};
173
207
 
174
208
FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate)
254
288
        return j;
255
289
}
256
290
 
 
291
/*
 
292
 * also disallows non-shortest-form encodings, c.f.
 
293
 *   http://www.unicode.org/versions/corrigendum1.html
 
294
 * and a more clear explanation at the end of this section:
 
295
 *   http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
 
296
 */
257
297
static __inline unsigned utf8len_(const FLAC__byte *utf8)
258
298
{
259
299
        FLAC__ASSERT(0 != utf8);
260
 
        if ((utf8[0] & 0x80) == 0)
 
300
        if ((utf8[0] & 0x80) == 0) {
261
301
                return 1;
262
 
        else if ((utf8[0] & 0xE0) == 0xC0 && (utf8[1] & 0xC0) == 0x80)
 
302
        }
 
303
        else if ((utf8[0] & 0xE0) == 0xC0 && (utf8[1] & 0xC0) == 0x80) {
 
304
                if ((utf8[0] & 0xFE) == 0xC0) /* overlong sequence check */
 
305
                        return 0;
263
306
                return 2;
264
 
        else if ((utf8[0] & 0xF0) == 0xE0 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80)
 
307
        }
 
308
        else if ((utf8[0] & 0xF0) == 0xE0 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80) {
 
309
                if (utf8[0] == 0xE0 && (utf8[1] & 0xE0) == 0x80) /* overlong sequence check */
 
310
                        return 0;
 
311
                /* illegal surrogates check (U+D800...U+DFFF and U+FFFE...U+FFFF) */
 
312
                if (utf8[0] == 0xED && (utf8[1] & 0xE0) == 0xA0) /* D800-DFFF */
 
313
                        return 0;
 
314
                if (utf8[0] == 0xEF && utf8[1] == 0xBF && (utf8[2] & 0xFE) == 0xBE) /* FFFE-FFFF */
 
315
                        return 0;
265
316
                return 3;
266
 
        else
 
317
        }
 
318
        else if ((utf8[0] & 0xF8) == 0xF0 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80) {
 
319
                if (utf8[0] == 0xF0 && (utf8[1] & 0xF0) == 0x80) /* overlong sequence check */
 
320
                        return 0;
 
321
                return 4;
 
322
        }
 
323
        else if ((utf8[0] & 0xFC) == 0xF8 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80 && (utf8[4] & 0xC0) == 0x80) {
 
324
                if (utf8[0] == 0xF8 && (utf8[1] & 0xF8) == 0x80) /* overlong sequence check */
 
325
                        return 0;
 
326
                return 5;
 
327
        }
 
328
        else if ((utf8[0] & 0xFE) == 0xFC && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80 && (utf8[4] & 0xC0) == 0x80 && (utf8[5] & 0xC0) == 0x80) {
 
329
                if (utf8[0] == 0xFC && (utf8[1] & 0xFC) == 0x80) /* overlong sequence check */
 
330
                        return 0;
 
331
                return 6;
 
332
        }
 
333
        else {
267
334
                return 0;
 
335
        }
268
336
}
269
337
 
270
338
FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_name_is_legal(const char *name)
364
432
                }
365
433
 
366
434
                if(check_cd_da_subset && cue_sheet->tracks[i].offset % 588 != 0) {
367
 
                        if(violation) *violation = "CD-DA cue sheet track offset must be evenly divisible by 588 samples";
 
435
                        if(violation) {
 
436
                                if(i == cue_sheet->num_tracks-1) /* the lead-out track... */
 
437
                                        *violation = "CD-DA cue sheet lead-out offset must be evenly divisible by 588 samples";
 
438
                                else
 
439
                                        *violation = "CD-DA cue sheet track offset must be evenly divisible by 588 samples";
 
440
                        }
368
441
                        return false;
369
442
                }
370
443
 
398
471
        return true;
399
472
}
400
473
 
 
474
FLAC_API FLAC__bool FLAC__format_picture_is_legal(const FLAC__StreamMetadata_Picture *picture, const char **violation)
 
475
{
 
476
        char *p;
 
477
        FLAC__byte *b;
 
478
 
 
479
        for(p = picture->mime_type; *p; p++) {
 
480
                if(*p < 0x20 || *p > 0x7e) {
 
481
                        if(violation) *violation = "MIME type string must contain only printable ASCII characters (0x20-0x7e)";
 
482
                        return false;
 
483
                }
 
484
        }
 
485
 
 
486
        for(b = picture->description; *b; ) {
 
487
                unsigned n = utf8len_(b);
 
488
                if(n == 0) {
 
489
                        if(violation) *violation = "description string must be valid UTF-8";
 
490
                        return false;
 
491
                }
 
492
                b += n;
 
493
        }
 
494
 
 
495
        return true;
 
496
}
 
497
 
401
498
/*
402
499
 * These routines are private to libFLAC
403
500
 */