configure.ac: Move OggVorbis Encoder to Encoder Plugins.
[mpd-mk.git] / src / chunk.h
blob23f6321fb522d08fc6de13137546937bab6771d1
1 /*
2 * Copyright (C) 2003-2010 The Music Player Daemon Project
3 * http://www.musicpd.org
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #ifndef MPD_CHUNK_H
21 #define MPD_CHUNK_H
23 #include "replay_gain_info.h"
25 #ifndef NDEBUG
26 #include "audio_format.h"
27 #endif
29 #include <stdbool.h>
30 #include <stdint.h>
31 #include <stddef.h>
33 enum {
34 CHUNK_SIZE = 4096,
37 struct audio_format;
39 /**
40 * A chunk of music data. Its format is defined by the
41 * music_pipe_append() caller.
43 struct music_chunk {
44 /** the next chunk in a linked list */
45 struct music_chunk *next;
47 /** number of bytes stored in this chunk */
48 uint16_t length;
50 /** current bit rate of the source file */
51 uint16_t bit_rate;
53 /** the time stamp within the song */
54 float times;
56 /**
57 * An optional tag associated with this chunk (and the
58 * following chunks); appears at song boundaries. The tag
59 * object is owned by this chunk, and must be freed when this
60 * chunk is deinitialized in music_chunk_free()
62 struct tag *tag;
64 /**
65 * Replay gain information associated with this chunk.
66 * Only valid if the serial is not 0.
68 struct replay_gain_info replay_gain_info;
70 /**
71 * A serial number for checking if replay gain info has
72 * changed since the last chunk. The magic value 0 indicates
73 * that there is no replay gain info available.
75 unsigned replay_gain_serial;
77 /** the data (probably PCM) */
78 char data[CHUNK_SIZE];
80 #ifndef NDEBUG
81 struct audio_format audio_format;
82 #endif
85 void
86 music_chunk_init(struct music_chunk *chunk);
88 void
89 music_chunk_free(struct music_chunk *chunk);
91 static inline bool
92 music_chunk_is_empty(const struct music_chunk *chunk)
94 return chunk->length == 0 && chunk->tag == NULL;
97 #ifndef NDEBUG
98 /**
99 * Checks if the audio format if the chunk is equal to the specified
100 * audio_format.
102 bool
103 music_chunk_check_format(const struct music_chunk *chunk,
104 const struct audio_format *audio_format);
105 #endif
108 * Prepares appending to the music chunk. Returns a buffer where you
109 * may write into. After you are finished, call music_chunk_expand().
111 * @param chunk the music_chunk object
112 * @param audio_format the audio format for the appended data; must
113 * stay the same for the life cycle of this chunk
114 * @param data_time the time within the song
115 * @param bit_rate the current bit rate of the source file
116 * @param max_length_r the maximum write length is returned here
117 * @return a writable buffer, or NULL if the chunk is full
119 void *
120 music_chunk_write(struct music_chunk *chunk,
121 const struct audio_format *audio_format,
122 float data_time, uint16_t bit_rate,
123 size_t *max_length_r);
126 * Increases the length of the chunk after the caller has written to
127 * the buffer returned by music_chunk_write().
129 * @param chunk the music_chunk object
130 * @param audio_format the audio format for the appended data; must
131 * stay the same for the life cycle of this chunk
132 * @param length the number of bytes which were appended
133 * @return true if the chunk is full
135 bool
136 music_chunk_expand(struct music_chunk *chunk,
137 const struct audio_format *audio_format, size_t length);
139 #endif