xine-lib  1.2.10
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 
25 typedef struct {
26  off_t offset;
27  int64_t sample_number;
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 
36 enum {
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 
54 typedef struct {
55  uint8_t last;
56  uint8_t blocktype;
57  uint32_t length;
59 
60 typedef 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;
67  uint8_t bits_per_sample;
68  uint64_t total_samples;
69  uint8_t md5[16];
71 
72 static 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 
79 static 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
FLAC_BLOCKTYPE_VORBIS_COMMENT
@ FLAC_BLOCKTYPE_VORBIS_COMMENT
Definition: flacutils.h:41
FLAC_BLOCKTYPE_APPLICATION
@ FLAC_BLOCKTYPE_APPLICATION
Definition: flacutils.h:39
xine_flac_metadata_header::blocktype
uint8_t blocktype
Definition: flacutils.h:56
xine_flac_streaminfo_block::blocksize_max
uint16_t blocksize_max
Definition: flacutils.h:62
_x_parse_flac_metadata_header
static void _x_parse_flac_metadata_header(uint8_t *buffer, xine_flac_metadata_header *parsed)
Definition: flacutils.h:72
FLAC_BLOCKTYPE_PADDING
@ FLAC_BLOCKTYPE_PADDING
Definition: flacutils.h:38
xine_flac_streaminfo_block
Definition: flacutils.h:60
xine_flac_streaminfo_block::bits_per_sample
uint8_t bits_per_sample
Definition: flacutils.h:67
FLAC_BLOCKTYPE_INVALID
@ FLAC_BLOCKTYPE_INVALID
Definition: flacutils.h:43
xine_flac_streaminfo_block::blocksize_min
uint16_t blocksize_min
Definition: flacutils.h:61
flac_seekpoint_t
Definition: flacutils.h:25
xine_flac_streaminfo_block::samplerate
uint32_t samplerate
Definition: flacutils.h:65
flac_seekpoint_t::pts
int64_t pts
Definition: flacutils.h:28
xine_flac_metadata_header::length
uint32_t length
Definition: flacutils.h:57
xine_flac_streaminfo_block::framesize_max
uint32_t framesize_max
Definition: flacutils.h:64
_X_BE_16
#define _X_BE_16(x)
Definition: bswap.h:40
xine_flac_streaminfo_block::total_samples
uint64_t total_samples
Definition: flacutils.h:68
FLAC_BLOCKTYPE_CUESHEET
@ FLAC_BLOCKTYPE_CUESHEET
Definition: flacutils.h:42
flac_seekpoint_t::size
int size
Definition: flacutils.h:29
xine_flac_metadata_header
Definition: flacutils.h:54
xine_flac_streaminfo_block::framesize_min
uint32_t framesize_min
Definition: flacutils.h:63
flac_seekpoint_t::offset
off_t offset
Definition: flacutils.h:26
_x_parse_flac_streaminfo_block
static void _x_parse_flac_streaminfo_block(uint8_t *buffer, xine_flac_streaminfo_block *parsed)
Definition: flacutils.h:79
flac_seekpoint_t::sample_number
int64_t sample_number
Definition: flacutils.h:27
xine_flac_streaminfo_block::channels
uint8_t channels
Definition: flacutils.h:66
_X_BE_64
#define _X_BE_64(x)
Definition: bswap.h:49
FLAC_BLOCKTYPE_STREAMINFO
@ FLAC_BLOCKTYPE_STREAMINFO
Definition: flacutils.h:37
_X_BE_32
#define _X_BE_32(x)
Definition: bswap.h:45
_X_BE_24
#define _X_BE_24(x)
Definition: bswap.h:42
xine_flac_metadata_header::last
uint8_t last
Definition: flacutils.h:55
FLAC_BLOCKTYPE_SEEKTABLE
@ FLAC_BLOCKTYPE_SEEKTABLE
Definition: flacutils.h:40