xine-lib 1.2.11
flacutils.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2006-2007 the xine project
3 * Based on the FLAC File Demuxer by Mike Melanson
4 *
5 * This file is part of xine, a free video player.
6 *
7 * xine is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * xine is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
20 */
21
22#ifndef __FLACUTILS_H__
23#define __FLACUTILS_H__
24
25typedef struct {
26 off_t offset;
28 int64_t pts;
29 int size;
31
32#define FLAC_SIGNATURE_SIZE 4
33#define FLAC_STREAMINFO_SIZE 34
34#define FLAC_SEEKPOINT_SIZE 18
35
36enum {
44};
45
46/*
47 * WARNING: These structures are *not* using the same format
48 * used by FLAC files, bitwise.
49 *
50 * Using bitfields to read the whole data is unfeasible because
51 * of endianness problems with non-byte-aligned values.
52 */
53
54typedef struct {
55 uint8_t last;
56 uint8_t blocktype;
57 uint32_t length;
59
60typedef struct {
61 uint16_t blocksize_min;
62 uint16_t blocksize_max;
63 uint32_t framesize_min;
64 uint32_t framesize_max;
65 uint32_t samplerate;
66 uint8_t channels;
68 uint64_t total_samples;
69 uint8_t md5[16];
71
72static inline void _x_parse_flac_metadata_header(uint8_t *buffer, xine_flac_metadata_header *parsed) {
73 parsed->last = buffer[0] & 0x80 ? 1 : 0;
74 parsed->blocktype = buffer[0] & 0x7f;
75
76 parsed->length = _X_BE_24(&buffer[1]);
77}
78
79static inline void _x_parse_flac_streaminfo_block(uint8_t *buffer, xine_flac_streaminfo_block *parsed) {
80 parsed->blocksize_min = _X_BE_16(&buffer[0]);
81 parsed->blocksize_max = _X_BE_16(&buffer[2]);
82 parsed->framesize_min = _X_BE_24(&buffer[4]);
83 parsed->framesize_max = _X_BE_24(&buffer[7]);
84 parsed->samplerate = _X_BE_32(&buffer[10]);
85 parsed->channels = ((parsed->samplerate >> 9) & 0x07) + 1;
86 parsed->bits_per_sample = ((parsed->samplerate >> 4) & 0x1F) + 1;
87 parsed->samplerate >>= 12;
88 parsed->total_samples = _X_BE_64(&buffer[10]) & UINT64_C(0x0FFFFFFFFF); /* 36 bits */
89}
90
91#endif
#define _X_BE_16(x)
Definition: bswap.h:40
#define _X_BE_32(x)
Definition: bswap.h:45
#define _X_BE_64(x)
Definition: bswap.h:49
#define _X_BE_24(x)
Definition: bswap.h:42
static void _x_parse_flac_metadata_header(uint8_t *buffer, xine_flac_metadata_header *parsed)
Definition: flacutils.h:72
static void _x_parse_flac_streaminfo_block(uint8_t *buffer, xine_flac_streaminfo_block *parsed)
Definition: flacutils.h:79
@ FLAC_BLOCKTYPE_CUESHEET
Definition: flacutils.h:42
@ FLAC_BLOCKTYPE_APPLICATION
Definition: flacutils.h:39
@ FLAC_BLOCKTYPE_INVALID
Definition: flacutils.h:43
@ FLAC_BLOCKTYPE_PADDING
Definition: flacutils.h:38
@ FLAC_BLOCKTYPE_SEEKTABLE
Definition: flacutils.h:40
@ FLAC_BLOCKTYPE_VORBIS_COMMENT
Definition: flacutils.h:41
@ FLAC_BLOCKTYPE_STREAMINFO
Definition: flacutils.h:37
Definition: flacutils.h:25
off_t offset
Definition: flacutils.h:26
int size
Definition: flacutils.h:29
int64_t sample_number
Definition: flacutils.h:27
int64_t pts
Definition: flacutils.h:28
Definition: flacutils.h:54
uint8_t last
Definition: flacutils.h:55
uint8_t blocktype
Definition: flacutils.h:56
uint32_t length
Definition: flacutils.h:57
Definition: flacutils.h:60
uint32_t samplerate
Definition: flacutils.h:65
uint32_t framesize_min
Definition: flacutils.h:63
uint8_t channels
Definition: flacutils.h:66
uint64_t total_samples
Definition: flacutils.h:68
uint16_t blocksize_min
Definition: flacutils.h:61
uint16_t blocksize_max
Definition: flacutils.h:62
uint8_t bits_per_sample
Definition: flacutils.h:67
uint32_t framesize_max
Definition: flacutils.h:64