d8da792633d2036b946b00eca20cbf4ee8d7b78a
[platform/upstream/flac.git] / include / FLAC / format.h
1 /* libFLAC - Free Lossless Audio Codec library
2  * Copyright (C) 2000,2001,2002  Josh Coalson
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA  02111-1307, USA.
18  */
19
20 #ifndef FLAC__FORMAT_H
21 #define FLAC__FORMAT_H
22
23 #include "ordinals.h"
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 /** \file include/FLAC/format.h
30  *
31  *  \brief
32  *  This module contains structure definitions for the representation
33  *  of FLAC format components in memory.  These are the basic
34  *  structures used by the rest of the interfaces.
35  *
36  *  See the detailed documentation in the
37  *  \link flac_format format \endlink module.
38  */
39
40 /** \defgroup flac_format FLAC/format.h: format components
41  *  \ingroup flac
42  *
43  *  \brief
44  *  This module contains structure definitions for the representation
45  *  of FLAC format components in memory.  These are the basic
46  *  structures used by the rest of the interfaces.
47  *
48  *  First, you should be familiar with the
49  *  <A HREF="../format.html">FLAC format</A>.  Many of the values here
50  *  follow directly from the specification.  As a user of libFLAC, the
51  *  interesting parts really are the structures that describe the frame
52  *  header and metadata blocks.
53  *
54  *  The format structures here are very primitive, designed to store
55  *  information in an efficient way.  Reading information from the
56  *  structures is easy but creating or modifying them directly is
57  *  more complex.  For the most part, as a user of a library, editing
58  *  is not necessary; however, for metadata blocks it is, so there are
59  *  convenience functions provided in the \link flac_metadata metadata
60  *  module \endlink to simplify the manipulation of metadata blocks.
61  *
62  * \note
63  * It's not the best convention, but symbols ending in _LEN are in bits
64  * and _LENGTH are in bytes.  _LENGTH symbols are \#defines instead of
65  * global variables because they are usually used when declaring byte
66  * arrays and some compilers require compile-time knowledge of array
67  * sizes when declared on the stack.
68  *
69  * \{
70  */
71
72
73 /*
74         Most of the values described in this file are defined by the FLAC
75         format specification.  There is nothing to tune here.
76 */
77
78 /** The minimum block size, in samples, permitted by the format. */
79 #define FLAC__MIN_BLOCK_SIZE (16u)
80
81 /** The maximum block size, in samples, permitted by the format. */
82 #define FLAC__MAX_BLOCK_SIZE (65535u)
83
84 /** The maximum number of channels permitted by the format. */
85 #define FLAC__MAX_CHANNELS (8u)
86
87 /** The minimum sample resolution permitted by the format. */
88 #define FLAC__MIN_BITS_PER_SAMPLE (4u)
89
90 /** The maximum sample resolution permitted by the format. */
91 #define FLAC__MAX_BITS_PER_SAMPLE (32u)
92
93 /** The maximum sample resolution permitted by libFLAC.
94  *
95  * \warning
96  * FLAC__MAX_BITS_PER_SAMPLE is the limit of the FLAC format.  However,
97  * the reference encoder/decoder is currently limited to 24 bits because
98  * of prevalent 32-bit math, so make sure and use this value when
99  * appropriate.
100  */
101 #define FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE (24u)
102
103 /** The maximum sample rate permitted by the format.  The value is
104  *  ((2 ^ 16) - 1) * 10; see <A HREF="../format.html">FLAC format</A>
105  *  as to why.
106  */
107 #define FLAC__MAX_SAMPLE_RATE (655350u)
108
109 /** The maximum LPC order permitted by the format. */
110 #define FLAC__MAX_LPC_ORDER (32u)
111
112 /** The minimum quantized linear predictor coefficient precision
113  *  permitted by the format.
114  */
115 #define FLAC__MIN_QLP_COEFF_PRECISION (5u)
116
117 /** The maximum quantized linear predictor coefficient precision
118  *  permitted by the format.
119  */
120 #define FLAC__MAX_QLP_COEFF_PRECISION (15u)
121
122 /** The maximum order of the fixed predictors permitted by the format. */
123 #define FLAC__MAX_FIXED_ORDER (4u)
124
125 /** The maximum Rice partition order permitted by the format. */
126 #define FLAC__MAX_RICE_PARTITION_ORDER (15u)
127
128 /** The maximum Rice partition order permitted by the FLAC Subset. */
129 #define FLAC__SUBSET_MAX_RICE_PARTITION_ORDER (8u)
130
131 /** The version string of the release, stamped onto the libraries and binaries.
132  *
133  * \note
134  * This does not correspond to the shared library version number, which
135  * is used to determine binary compatibility.
136  */
137 extern const char *FLAC__VERSION_STRING;
138
139 /** The vendor string inserted by the encoder into the VORBIS_COMMENT block.
140  *  This is a nulL-terminated ASCII string; when inserted into the
141  *  VORBIS_COMMENT the trailing null is stripped.
142  */
143 extern const char *FLAC__VENDOR_STRING;
144
145 /** The byte string representation of the beginning of a FLAC stream. */
146 extern const FLAC__byte FLAC__STREAM_SYNC_STRING[4]; /* = "fLaC" */
147
148 /** The 32-bit integer big-endian representation of the beginning of
149  *  a FLAC stream.
150  */
151 extern const unsigned FLAC__STREAM_SYNC; /* = 0x664C6143 */
152
153 /** The length of the FLAC signature in bits. */
154 extern const unsigned FLAC__STREAM_SYNC_LEN; /* = 32 bits */
155
156 /** The length of the FLAC signature in bytes. */
157 #define FLAC__STREAM_SYNC_LENGTH (4u)
158
159
160 /*****************************************************************************
161  *
162  * Subframe structures
163  *
164  *****************************************************************************/
165
166 /*****************************************************************************/
167
168 /** An enumeration of the available entropy coding methods. */
169 typedef enum {
170         FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE = 0
171         /**< Residual is coded by partitioning into contexts, each with it's own
172          * Rice parameter. */
173 } FLAC__EntropyCodingMethodType;
174
175 /** Maps a FLAC__EntropyCodingMethodType to a C string.
176  *
177  *  Using a FLAC__EntropyCodingMethodType as the index to this array will
178  *  give the string equivalent.  The contents should not be modified.
179  */
180 extern const char * const FLAC__EntropyCodingMethodTypeString[];
181
182
183 /** Contents of a Rice partitioned residual
184  */
185 typedef struct {
186
187         unsigned *parameters;
188         /**< The Rice parameters for each context. */
189
190         unsigned *raw_bits;
191         /**< Widths for escape-coded partitions. */
192
193         unsigned capacity_by_order;
194         /**< The capacity of the \a parameters and \a raw_bits arrays
195          * specified as an order, i.e. the number of array elements
196          * allocated is 2 ^ \a capacity_by_order.
197          */
198 } FLAC__EntropyCodingMethod_PartitionedRiceContents;
199
200 /** Header for a Rice partitioned residual.  (c.f. <A HREF="../format.html#partitioned_rice">format specification</A>)
201  */
202 typedef struct {
203
204         unsigned order;
205         /**< The partition order, i.e. # of contexts = 2 ^ \a order. */
206
207         const FLAC__EntropyCodingMethod_PartitionedRiceContents *contents;
208         /**< The context's Rice parameters and/or raw bits. */
209
210 } FLAC__EntropyCodingMethod_PartitionedRice;
211
212 extern const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN; /**< == 4 (bits) */
213 extern const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN; /**< == 4 (bits) */
214 extern const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN; /**< == 5 (bits) */
215
216 extern const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
217 /**< == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN)-1 */
218
219 /** Header for the entropy coding method.  (c.f. <A HREF="../format.html#residual">format specification</A>)
220  */
221 typedef struct {
222         FLAC__EntropyCodingMethodType type;
223         union {
224                 FLAC__EntropyCodingMethod_PartitionedRice partitioned_rice;
225         } data;
226 } FLAC__EntropyCodingMethod;
227
228 extern const unsigned FLAC__ENTROPY_CODING_METHOD_TYPE_LEN; /**< == 2 (bits) */
229
230 /*****************************************************************************/
231
232 /** An enumeration of the available subframe types. */
233 typedef enum {
234         FLAC__SUBFRAME_TYPE_CONSTANT = 0, /**< constant signal */
235         FLAC__SUBFRAME_TYPE_VERBATIM = 1, /**< uncompressed signal */
236         FLAC__SUBFRAME_TYPE_FIXED = 2, /**< fixed polynomial prediction */
237         FLAC__SUBFRAME_TYPE_LPC = 3 /**< linear prediction */
238 } FLAC__SubframeType;
239
240 /** Maps a FLAC__SubframeType to a C string.
241  *
242  *  Using a FLAC__SubframeType as the index to this array will
243  *  give the string equivalent.  The contents should not be modified.
244  */
245 extern const char * const FLAC__SubframeTypeString[];
246
247
248 /** CONSTANT subframe.  (c.f. <A HREF="../format.html#subframe_constant">format specification</A>)
249  */
250 typedef struct {
251         FLAC__int32 value; /**< The constant signal value. */
252 } FLAC__Subframe_Constant;
253
254
255 /** VERBATIM subframe.  (c.f. <A HREF="../format.html#subframe_verbatim">format specification</A>)
256  */
257 typedef struct {
258         const FLAC__int32 *data; /**< A pointer to verbatim signal. */
259 } FLAC__Subframe_Verbatim;
260
261
262 /** FIXED subframe.  (c.f. <A HREF="../format.html#subframe_fixed">format specification</A>)
263  */
264 typedef struct {
265         FLAC__EntropyCodingMethod entropy_coding_method;
266         /**< The residual coding method. */
267
268         unsigned order;
269         /**< The polynomial order. */
270
271         FLAC__int32 warmup[FLAC__MAX_FIXED_ORDER];
272         /**< Warmup samples to prime the predictor, length == order. */
273
274         const FLAC__int32 *residual;
275         /**< The residual signal, length == (blocksize minus order) samples. */
276 } FLAC__Subframe_Fixed;
277
278
279 /** LPC subframe.  (c.f. <A HREF="../format.html#subframe_lpc">format specification</A>)
280  */
281 typedef struct {
282         FLAC__EntropyCodingMethod entropy_coding_method;
283         /**< The residual coding method. */
284
285         unsigned order;
286         /**< The FIR order. */
287
288         unsigned qlp_coeff_precision;
289         /**< Quantized FIR filter coefficient precision in bits. */
290
291         int quantization_level;
292         /**< The qlp coeff shift needed. */
293
294         FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER];
295         /**< FIR filter coefficients. */
296
297         FLAC__int32 warmup[FLAC__MAX_LPC_ORDER];
298         /**< Warmup samples to prime the predictor, length == order. */
299
300         const FLAC__int32 *residual;
301         /**< The residual signal, length == (blocksize minus order) samples. */
302 } FLAC__Subframe_LPC;
303
304 extern const unsigned FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN; /**< == 4 (bits) */
305 extern const unsigned FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN; /**< == 5 (bits) */
306
307
308 /** FLAC subframe structure.  (c.f. <A HREF="../format.html#subframe">format specification</A>)
309  */
310 typedef struct {
311         FLAC__SubframeType type;
312         union {
313                 FLAC__Subframe_Constant constant;
314                 FLAC__Subframe_Fixed fixed;
315                 FLAC__Subframe_LPC lpc;
316                 FLAC__Subframe_Verbatim verbatim;
317         } data;
318         unsigned wasted_bits;
319 } FLAC__Subframe;
320
321 extern const unsigned FLAC__SUBFRAME_ZERO_PAD_LEN; /**< == 1 (bit) */
322 extern const unsigned FLAC__SUBFRAME_TYPE_LEN; /**< == 6 (bits) */
323 extern const unsigned FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN; /**< == 1 (bit) */
324
325 extern const unsigned FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK; /* = 0x00 */
326 extern const unsigned FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK; /* = 0x02 */
327 extern const unsigned FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK; /* = 0x10 */
328 extern const unsigned FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK; /* = 0x40 */
329
330 /*****************************************************************************/
331
332
333 /*****************************************************************************
334  *
335  * Frame structures
336  *
337  *****************************************************************************/
338
339 /** An enumeration of the available channel assignments. */
340 typedef enum {
341         FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT = 0, /**< independent channels */
342         FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE = 1, /**< left+side stereo */
343         FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE = 2, /**< right+side stereo */
344         FLAC__CHANNEL_ASSIGNMENT_MID_SIDE = 3 /**< mid+side stereo */
345 } FLAC__ChannelAssignment;
346
347 /** Maps a FLAC__ChannelAssignment to a C string.
348  *
349  *  Using a FLAC__ChannelAssignment as the index to this array will
350  *  give the string equivalent.  The contents should not be modified.
351  */
352 extern const char * const FLAC__ChannelAssignmentString[];
353
354 /** An enumeration of the possible frame numbering methods. */
355 typedef enum {
356         FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER, /**< number contains the frame number */
357         FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER /**< number contains the sample number of first sample in frame */
358 } FLAC__FrameNumberType;
359
360 /** Maps a FLAC__FrameNumberType to a C string.
361  *
362  *  Using a FLAC__FrameNumberType as the index to this array will
363  *  give the string equivalent.  The contents should not be modified.
364  */
365 extern const char * const FLAC__FrameNumberTypeString[];
366
367
368 /** FLAC frame header structure.  (c.f. <A HREF="../format.html#frame_header">format specification</A>)
369  */
370 typedef struct {
371         unsigned blocksize;
372         /**< The number of samples per subframe. */
373
374         unsigned sample_rate;
375         /**< The sample rate in Hz. */
376
377         unsigned channels;
378         /**< The number of channels (== number of subframes). */
379
380         FLAC__ChannelAssignment channel_assignment;
381         /**< The channel assignment for the frame. */
382
383         unsigned bits_per_sample;
384         /**< The sample resolution. */
385
386         FLAC__FrameNumberType number_type;
387         /**< The numbering scheme used for the frame. */
388
389         union {
390                 FLAC__uint32 frame_number;
391                 FLAC__uint64 sample_number;
392         } number;
393         /**< The frame number or sample number of first sample in frame;
394          * use the \a number_type value to determine which to use. */
395
396         FLAC__uint8 crc;
397         /**< CRC-8 (polynomial = x^8 + x^2 + x^1 + x^0, initialized with 0)
398          * of the raw frame header bytes, meaning everything before the CRC byte
399          * including the sync code.
400          */
401 } FLAC__FrameHeader;
402
403 extern const unsigned FLAC__FRAME_HEADER_SYNC; /**< == 0x3ffe; the frame header sync code */
404 extern const unsigned FLAC__FRAME_HEADER_SYNC_LEN; /**< == 14 (bits) */
405 extern const unsigned FLAC__FRAME_HEADER_RESERVED_LEN; /**< == 2 (bits) */
406 extern const unsigned FLAC__FRAME_HEADER_BLOCK_SIZE_LEN; /**< == 4 (bits) */
407 extern const unsigned FLAC__FRAME_HEADER_SAMPLE_RATE_LEN; /**< == 4 (bits) */
408 extern const unsigned FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN; /**< == 4 (bits) */
409 extern const unsigned FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN; /**< == 3 (bits) */
410 extern const unsigned FLAC__FRAME_HEADER_ZERO_PAD_LEN; /**< == 1 (bit) */
411 extern const unsigned FLAC__FRAME_HEADER_CRC_LEN; /**< == 8 (bits) */
412
413
414 /** FLAC frame footer structure.  (c.f. <A HREF="../format.html#frame_footer">format specification</A>)
415  */
416 typedef struct {
417         FLAC__uint16 crc;
418         /**< CRC-16 (polynomial = x^16 + x^15 + x^2 + x^0, initialized with
419          * 0) of the bytes before the crc, back to and including the frame header
420          * sync code.
421          */
422 } FLAC__FrameFooter;
423
424 extern const unsigned FLAC__FRAME_FOOTER_CRC_LEN; /**< == 16 (bits) */
425
426
427 /** FLAC frame structure.  (c.f. <A HREF="../format.html#frame">format specification</A>)
428  */
429 typedef struct {
430         FLAC__FrameHeader header;
431         FLAC__Subframe subframes[FLAC__MAX_CHANNELS];
432         FLAC__FrameFooter footer;
433 } FLAC__Frame;
434
435 /*****************************************************************************/
436
437
438 /*****************************************************************************
439  *
440  * Meta-data structures
441  *
442  *****************************************************************************/
443
444 /** An enumeration of the available metadata block types. */
445 typedef enum {
446
447         FLAC__METADATA_TYPE_STREAMINFO = 0,
448         /**< <A HREF="../format.html#metadata_block_streaminfo">STREAMINFO</A> block */
449
450         FLAC__METADATA_TYPE_PADDING = 1,
451         /**< <A HREF="../format.html#metadata_block_padding"PADDING</A> block */
452
453         FLAC__METADATA_TYPE_APPLICATION = 2,
454         /**< <A HREF="../format.html#metadata_block_application"APPLICATION</A> block */
455
456         FLAC__METADATA_TYPE_SEEKTABLE = 3,
457         /**< <A HREF="../format.html#metadata_block_seektable"SEEKTABLE</A> block */
458
459         FLAC__METADATA_TYPE_VORBIS_COMMENT = 4,
460         /**< <A HREF="../format.html#metadata_block_vorbis_comment"VORBISCOMMENT</A> block */
461
462 } FLAC__MetadataType;
463
464 /** Maps a FLAC__MetadataType to a C string.
465  *
466  *  Using a FLAC__MetadataType as the index to this array will
467  *  give the string equivalent.  The contents should not be modified.
468  */
469 extern const char * const FLAC__MetadataTypeString[];
470
471
472 /** FLAC STREAMINFO structure.  (c.f. <A HREF="../format.html#metadata_block_streaminfo">format specification</A>)
473  */
474 typedef struct {
475         unsigned min_blocksize, max_blocksize;
476         unsigned min_framesize, max_framesize;
477         unsigned sample_rate;
478         unsigned channels;
479         unsigned bits_per_sample;
480         FLAC__uint64 total_samples;
481         FLAC__byte md5sum[16];
482 } FLAC__StreamMetadata_StreamInfo;
483
484 extern const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN; /**< == 16 (bits) */
485 extern const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN; /**< == 16 (bits) */
486 extern const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN; /**< == 24 (bits) */
487 extern const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN; /**< == 24 (bits) */
488 extern const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN; /**< == 20 (bits) */
489 extern const unsigned FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN; /**< == 3 (bits) */
490 extern const unsigned FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN; /**< == 5 (bits) */
491 extern const unsigned FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN; /**< == 36 (bits) */
492 extern const unsigned FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN; /**< == 128 (bits) */
493
494 /** The total stream length of the STREAMINFO block in bytes. */
495 #define FLAC__STREAM_METADATA_STREAMINFO_LENGTH (34u)
496
497 /** FLAC PADDING structure.  (c.f. <A HREF="../format.html#metadata_block_padding">format specification</A>)
498  */
499 typedef struct {
500         int dummy;
501         /**< Conceptually this is an empty struct since we don't store the
502          * padding bytes.  Empty structs are not allowed by some C compilers,
503          * hence the dummy.
504          */
505 } FLAC__StreamMetadata_Padding;
506
507
508 /** FLAC APPLICATION structure.  (c.f. <A HREF="../format.html#metadata_block_application">format specification</A>)
509  */
510 typedef struct {
511         FLAC__byte id[4];
512         FLAC__byte *data;
513 } FLAC__StreamMetadata_Application;
514
515 extern const unsigned FLAC__STREAM_METADATA_APPLICATION_ID_LEN; /**< == 32 (bits) */
516
517 /** SeekPoint structure used in SEEKTABLE blocks.  (c.f. <A HREF="../format.html#seekpoint">format specification</A>)
518  */
519 typedef struct {
520         FLAC__uint64 sample_number;
521         /**<  The sample number of the target frame. */
522
523         FLAC__uint64 stream_offset;
524         /**< The offset, in bytes, of the target frame with respect to
525          * beginning of the first frame. */
526
527         unsigned frame_samples;
528         /**< The number of samples in the target frame. */
529 } FLAC__StreamMetadata_SeekPoint;
530
531 extern const unsigned FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN; /**< == 64 (bits) */
532 extern const unsigned FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN; /**< == 64 (bits) */
533 extern const unsigned FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN; /**< == 16 (bits) */
534
535 /** The total stream length of a seek point in bytes. */
536 #define FLAC__STREAM_METADATA_SEEKPOINT_LENGTH (18u)
537
538 /** The value used in the \a sample_number field of
539  *  FLAC__StreamMetadataSeekPoint used to indicate a placeholder
540  *  point (== 0xffffffffffffffff).
541  */
542 extern const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
543
544
545 /** FLAC SEEKTABLE structure.  (c.f. <A HREF="../format.html#metadata_block_seektable">format specification</A>)
546  *
547  * \note From the format specification:
548  * - The seek points must be sorted by ascending sample number.
549  * - Each seek point's sample number must be the first sample of the
550  *   target frame.
551  * - Each seek point's sample number must be unique within the table.
552  * - Existence of a SEEKTABLE block implies a correct setting of
553  *   total_samples in the stream_info block.
554  * - Behavior is undefined when more than one SEEKTABLE block is
555  *   present in a stream.
556  */
557 typedef struct {
558         unsigned num_points;
559         FLAC__StreamMetadata_SeekPoint *points;
560 } FLAC__StreamMetadata_SeekTable;
561
562
563 /** Vorbis comment entry structure used in VORBIS_COMMENT blocks.  (c.f. <A HREF="../format.html#metadata_block_vorbis_comment">format specification</A>)
564  */
565 typedef struct {
566         FLAC__uint32 length;
567         FLAC__byte *entry;
568 } FLAC__StreamMetadata_VorbisComment_Entry;
569
570 extern const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN; /**< == 32 (bits) */
571
572
573 /** FLAC VORBIS_COMMENT structure.  (c.f. <A HREF="../format.html#metadata_block_vorbis_comment">format specification</A>)
574  */
575 typedef struct {
576         FLAC__StreamMetadata_VorbisComment_Entry vendor_string;
577         FLAC__uint32 num_comments;
578         FLAC__StreamMetadata_VorbisComment_Entry *comments;
579 } FLAC__StreamMetadata_VorbisComment;
580
581 extern const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN; /**< == 32 (bits) */
582
583
584 /** FLAC metadata block structure.  (c.f. <A HREF="../format.html#metadata_block">format specification</A>)
585  */
586 typedef struct {
587         FLAC__MetadataType type;
588         /**< The type of the metadata block; used determine which member of the
589          * \a data union to dereference. */
590
591         FLAC__bool is_last;
592         /**< \c true if this metadata block is the last, else \a false */
593
594         unsigned length;
595         /**< Length, in bytes, of the block data as it appears in the stream. */
596
597         union {
598                 FLAC__StreamMetadata_StreamInfo stream_info;
599                 FLAC__StreamMetadata_Padding padding;
600                 FLAC__StreamMetadata_Application application;
601                 FLAC__StreamMetadata_SeekTable seek_table;
602                 FLAC__StreamMetadata_VorbisComment vorbis_comment;
603         } data;
604         /**< Polymorphic block data; use the \a type value to determine which
605          * to use. */
606 } FLAC__StreamMetadata;
607
608 extern const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN; /**< == 1 (bit) */
609 extern const unsigned FLAC__STREAM_METADATA_TYPE_LEN; /**< == 7 (bits) */
610 extern const unsigned FLAC__STREAM_METADATA_LENGTH_LEN; /**< == 24 (bits) */
611
612 /** The total stream length of a metadata block header in bytes. */
613 #define FLAC__STREAM_METADATA_HEADER_LENGTH (4u)
614
615 /*****************************************************************************/
616
617
618 /*****************************************************************************
619  *
620  * Utility functions
621  *
622  *****************************************************************************/
623
624 /** Tests that a sample rate is valid for FLAC.  Since the rules for valid
625  *  sample rates are slightly complex, they are encapsulated in this function.
626  *
627  * \param sample_rate  The sample rate to test for compliance.
628  * \retval FLAC__bool
629  *    \c true if the given sample rate conforms to the specification, else
630  *    \c false.
631  */
632 FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate);
633
634 /** Check a seek table to see if it conforms to the FLAC specification.
635  *  See the format specification for limits on the contents of the
636  *  seek table.
637  *
638  * \param seek_table  A pointer to a seek table to be checked.
639  * \assert
640  *    \code seek_table != NULL \endcode
641  * \retval FLAC__bool
642  *    \c false if seek table is illegal, else \c true.
643  */
644 FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_SeekTable *seek_table);
645
646 /** Sort a seek table's seek points according to the format specification.
647  *  This includes a "unique-ification" step to remove duplicates, i.e.
648  *  seek points with identical \a sample_number values.  Duplicate seek
649  *  points are converted into placeholder points and sorted to the end of
650  *  the table.
651  *
652  * \param seek_table  A pointer to a seek table to be sorted.
653  * \assert
654  *    \code seek_table != NULL \endcode
655  * \retval unsigned
656  *    The number of duplicate seek points converted into placeholders.
657  */
658 unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table);
659
660 /* \} */
661
662 #ifdef __cplusplus
663 }
664 #endif
665
666 #endif