| OLD | NEW |
| 1 /* libFLAC - Free Lossless Audio Codec library | 1 /* libFLAC - Free Lossless Audio Codec library |
| 2 * Copyright (C) 2000,2001,2002,2003,2004,2005,2006,2007 Josh Coalson | 2 * Copyright (C) 2000-2009 Josh Coalson |
| 3 * Copyright (C) 2011-2014 Xiph.Org Foundation |
| 3 * | 4 * |
| 4 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 6 * are met: | 7 * are met: |
| 7 * | 8 * |
| 8 * - Redistributions of source code must retain the above copyright | 9 * - Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| 10 * | 11 * |
| 11 * - Redistributions in binary form must reproduce the above copyright | 12 * - Redistributions in binary form must reproduce the above copyright |
| 12 * notice, this list of conditions and the following disclaimer in the | 13 * notice, this list of conditions and the following disclaimer in the |
| 13 * documentation and/or other materials provided with the distribution. | 14 * documentation and/or other materials provided with the distribution. |
| 14 * | 15 * |
| 15 * - Neither the name of the Xiph.org Foundation nor the names of its | 16 * - Neither the name of the Xiph.org Foundation nor the names of its |
| 16 * contributors may be used to endorse or promote products derived from | 17 * contributors may be used to endorse or promote products derived from |
| 17 * this software without specific prior written permission. | 18 * this software without specific prior written permission. |
| 18 * | 19 * |
| 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR | 23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR |
| 23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 26 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | 27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 27 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | 28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 28 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 */ | 31 */ |
| 31 | 32 |
| 32 #if HAVE_CONFIG_H | 33 #ifdef HAVE_CONFIG_H |
| 33 # include <config.h> | 34 # include <config.h> |
| 34 #endif | 35 #endif |
| 35 | 36 |
| 36 #include <stdio.h> | 37 #include <stdio.h> |
| 37 #include <string.h> /* for strlen() */ | 38 #include <string.h> /* for strlen() */ |
| 38 #include "private/stream_encoder_framing.h" | 39 #include "private/stream_encoder_framing.h" |
| 39 #include "private/crc.h" | 40 #include "private/crc.h" |
| 40 #include "FLAC/assert.h" | 41 #include "FLAC/assert.h" |
| 41 | 42 |
| 42 #ifdef max | |
| 43 #undef max | |
| 44 #endif | |
| 45 #define max(x,y) ((x)>(y)?(x):(y)) | |
| 46 | |
| 47 static FLAC__bool add_entropy_coding_method_(FLAC__BitWriter *bw, const FLAC__En
tropyCodingMethod *method); | 43 static FLAC__bool add_entropy_coding_method_(FLAC__BitWriter *bw, const FLAC__En
tropyCodingMethod *method); |
| 48 static FLAC__bool add_residual_partitioned_rice_(FLAC__BitWriter *bw, const FLAC
__int32 residual[], const unsigned residual_samples, const unsigned predictor_or
der, const unsigned rice_parameters[], const unsigned raw_bits[], const unsigned
partition_order, const FLAC__bool is_extended); | 44 static FLAC__bool add_residual_partitioned_rice_(FLAC__BitWriter *bw, const FLAC
__int32 residual[], const unsigned residual_samples, const unsigned predictor_or
der, const unsigned rice_parameters[], const unsigned raw_bits[], const unsigned
partition_order, const FLAC__bool is_extended); |
| 49 | 45 |
| 50 FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__
BitWriter *bw) | 46 FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__
BitWriter *bw) |
| 51 { | 47 { |
| 52 unsigned i, j; | 48 unsigned i, j; |
| 53 const unsigned vendor_string_length = (unsigned)strlen(FLAC__VENDOR_STRI
NG); | 49 const unsigned vendor_string_length = (unsigned)strlen(FLAC__VENDOR_STRI
NG); |
| 54 | 50 |
| 55 if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->is_last, FLAC__STREAM
_METADATA_IS_LAST_LEN)) | 51 if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->is_last, FLAC__STREAM
_METADATA_IS_LAST_LEN)) |
| 56 return false; | 52 return false; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 return false; | 155 return false; |
| 160 if(!FLAC__bitwriter_write_raw_uint32(bw, track->
type, FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN)) | 156 if(!FLAC__bitwriter_write_raw_uint32(bw, track->
type, FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN)) |
| 161 return false; | 157 return false; |
| 162 if(!FLAC__bitwriter_write_raw_uint32(bw, track->
pre_emphasis, FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN)) | 158 if(!FLAC__bitwriter_write_raw_uint32(bw, track->
pre_emphasis, FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN)) |
| 163 return false; | 159 return false; |
| 164 if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREA
M_METADATA_CUESHEET_TRACK_RESERVED_LEN)) | 160 if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREA
M_METADATA_CUESHEET_TRACK_RESERVED_LEN)) |
| 165 return false; | 161 return false; |
| 166 if(!FLAC__bitwriter_write_raw_uint32(bw, track->
num_indices, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN)) | 162 if(!FLAC__bitwriter_write_raw_uint32(bw, track->
num_indices, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN)) |
| 167 return false; | 163 return false; |
| 168 for(j = 0; j < track->num_indices; j++) { | 164 for(j = 0; j < track->num_indices; j++) { |
| 169 » » » » » const FLAC__StreamMetadata_CueSheet_Inde
x *index = track->indices + j; | 165 » » » » » const FLAC__StreamMetadata_CueSheet_Inde
x *indx = track->indices + j; |
| 170 | 166 |
| 171 » » » » » if(!FLAC__bitwriter_write_raw_uint64(bw,
index->offset, FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN)) | 167 » » » » » if(!FLAC__bitwriter_write_raw_uint64(bw,
indx->offset, FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN)) |
| 172 return false; | 168 return false; |
| 173 » » » » » if(!FLAC__bitwriter_write_raw_uint32(bw,
index->number, FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN)) | 169 » » » » » if(!FLAC__bitwriter_write_raw_uint32(bw,
indx->number, FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN)) |
| 174 return false; | 170 return false; |
| 175 if(!FLAC__bitwriter_write_zeroes(bw, FLA
C__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN)) | 171 if(!FLAC__bitwriter_write_zeroes(bw, FLA
C__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN)) |
| 176 return false; | 172 return false; |
| 177 } | 173 } |
| 178 } | 174 } |
| 179 break; | 175 break; |
| 180 case FLAC__METADATA_TYPE_PICTURE: | 176 case FLAC__METADATA_TYPE_PICTURE: |
| 181 { | 177 { |
| 182 » » » » unsigned len; | 178 » » » » size_t len; |
| 183 if(!FLAC__bitwriter_write_raw_uint32(bw, metadat
a->data.picture.type, FLAC__STREAM_METADATA_PICTURE_TYPE_LEN)) | 179 if(!FLAC__bitwriter_write_raw_uint32(bw, metadat
a->data.picture.type, FLAC__STREAM_METADATA_PICTURE_TYPE_LEN)) |
| 184 return false; | 180 return false; |
| 185 » » » » len = (unsigned)strlen(metadata->data.picture.mi
me_type); | 181 » » » » len = strlen(metadata->data.picture.mime_type); |
| 186 if(!FLAC__bitwriter_write_raw_uint32(bw, len, FL
AC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN)) | 182 if(!FLAC__bitwriter_write_raw_uint32(bw, len, FL
AC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN)) |
| 187 return false; | 183 return false; |
| 188 if(!FLAC__bitwriter_write_byte_block(bw, (const
FLAC__byte*)metadata->data.picture.mime_type, len)) | 184 if(!FLAC__bitwriter_write_byte_block(bw, (const
FLAC__byte*)metadata->data.picture.mime_type, len)) |
| 189 return false; | 185 return false; |
| 190 » » » » len = (unsigned)strlen((const char *)metadata->d
ata.picture.description); | 186 » » » » len = strlen((const char *)metadata->data.pictur
e.description); |
| 191 if(!FLAC__bitwriter_write_raw_uint32(bw, len, FL
AC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN)) | 187 if(!FLAC__bitwriter_write_raw_uint32(bw, len, FL
AC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN)) |
| 192 return false; | 188 return false; |
| 193 if(!FLAC__bitwriter_write_byte_block(bw, metadat
a->data.picture.description, len)) | 189 if(!FLAC__bitwriter_write_byte_block(bw, metadat
a->data.picture.description, len)) |
| 194 return false; | 190 return false; |
| 195 if(!FLAC__bitwriter_write_raw_uint32(bw, metadat
a->data.picture.width, FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN)) | 191 if(!FLAC__bitwriter_write_raw_uint32(bw, metadat
a->data.picture.width, FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN)) |
| 196 return false; | 192 return false; |
| 197 if(!FLAC__bitwriter_write_raw_uint32(bw, metadat
a->data.picture.height, FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN)) | 193 if(!FLAC__bitwriter_write_raw_uint32(bw, metadat
a->data.picture.height, FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN)) |
| 198 return false; | 194 return false; |
| 199 if(!FLAC__bitwriter_write_raw_uint32(bw, metadat
a->data.picture.depth, FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN)) | 195 if(!FLAC__bitwriter_write_raw_uint32(bw, metadat
a->data.picture.depth, FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN)) |
| 200 return false; | 196 return false; |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 for(j = k_last; j < k; j++) { | 540 for(j = k_last; j < k; j++) { |
| 545 if(!FLAC__bitwriter_write_raw_int32(bw,
residual[j], raw_bits[i])) | 541 if(!FLAC__bitwriter_write_raw_int32(bw,
residual[j], raw_bits[i])) |
| 546 return false; | 542 return false; |
| 547 } | 543 } |
| 548 } | 544 } |
| 549 k_last = k; | 545 k_last = k; |
| 550 } | 546 } |
| 551 return true; | 547 return true; |
| 552 } | 548 } |
| 553 } | 549 } |
| OLD | NEW |