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.
22 #include "audio_format.h"
28 music_chunk_init(struct music_chunk
*chunk
)
32 chunk
->replay_gain_serial
= 0;
36 music_chunk_free(struct music_chunk
*chunk
)
38 if (chunk
->tag
!= NULL
)
44 music_chunk_check_format(const struct music_chunk
*chunk
,
45 const struct audio_format
*audio_format
)
47 assert(chunk
!= NULL
);
48 assert(audio_format
!= NULL
);
49 assert(audio_format_valid(audio_format
));
51 return chunk
->length
== 0 ||
52 audio_format_equals(&chunk
->audio_format
, audio_format
);
57 music_chunk_write(struct music_chunk
*chunk
,
58 const struct audio_format
*audio_format
,
59 float data_time
, uint16_t bit_rate
,
62 const size_t frame_size
= audio_format_frame_size(audio_format
);
65 assert(music_chunk_check_format(chunk
, audio_format
));
66 assert(chunk
->length
== 0 || audio_format_valid(&chunk
->audio_format
));
68 if (chunk
->length
== 0) {
69 /* if the chunk is empty, nobody has set bitRate and
72 chunk
->bit_rate
= bit_rate
;
73 chunk
->times
= data_time
;
76 num_frames
= (sizeof(chunk
->data
) - chunk
->length
) / frame_size
;
81 chunk
->audio_format
= *audio_format
;
84 *max_length_r
= num_frames
* frame_size
;
85 return chunk
->data
+ chunk
->length
;
89 music_chunk_expand(struct music_chunk
*chunk
,
90 const struct audio_format
*audio_format
, size_t length
)
92 const size_t frame_size
= audio_format_frame_size(audio_format
);
94 assert(chunk
!= NULL
);
95 assert(chunk
->length
+ length
<= sizeof(chunk
->data
));
96 assert(audio_format_equals(&chunk
->audio_format
, audio_format
));
98 chunk
->length
+= length
;
100 return chunk
->length
+ frame_size
> sizeof(chunk
->data
);