tweaks to the MD5 routines; they need to be exported when building a windows DLL...
authorJosh Coalson <jcoalson@users.sourceforce.net>
Fri, 23 Jul 2004 05:18:22 +0000 (05:18 +0000)
committerJosh Coalson <jcoalson@users.sourceforce.net>
Fri, 23 Jul 2004 05:18:22 +0000 (05:18 +0000)
src/libFLAC/include/private/md5.h
src/libFLAC/md5.c
src/libFLAC/seekable_stream_decoder.c
src/libFLAC/stream_encoder.c
src/libOggFLAC/seekable_stream_decoder.c

index 5215c9a..e853260 100644 (file)
 
 #define md5byte unsigned char
 
+/*
+ * Due to an unholy abomination in libOggFLAC (it requires access to
+ * these internal MD5 functions) we have to #include "FLAC/export.h"
+ * and export them when building a DLL
+ */
+#include "FLAC/export.h"
 #include "FLAC/ordinals.h"
 
-struct MD5Context {
+struct FLAC__MD5Context {
        FLAC__uint32 buf[4];
        FLAC__uint32 bytes[2];
        FLAC__uint32 in[16];
@@ -38,11 +44,11 @@ struct MD5Context {
        unsigned capacity;
 };
 
-void MD5Init(struct MD5Context *context);
-void MD5Update(struct MD5Context *context, md5byte const *buf, unsigned len);
-void MD5Final(md5byte digest[16], struct MD5Context *context);
-void MD5Transform(FLAC__uint32 buf[4], FLAC__uint32 const in[16]);
+FLAC_API void FLAC__MD5Init(struct FLAC__MD5Context *context);
+FLAC_API void FLAC__MD5Update(struct FLAC__MD5Context *context, md5byte const *buf, unsigned len);
+FLAC_API void FLAC__MD5Final(md5byte digest[16], struct FLAC__MD5Context *context);
+void FLAC__MD5Transform(FLAC__uint32 buf[4], FLAC__uint32 const in[16]);
 
-FLAC__bool FLAC__MD5Accumulate(struct MD5Context *ctx, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample);
+FLAC_API FLAC__bool FLAC__MD5Accumulate(struct FLAC__MD5Context *ctx, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample);
 
 #endif /* !MD5_H */
index 70fdedb..9679387 100644 (file)
@@ -59,7 +59,7 @@ static FLAC__bool is_big_endian_host_;
  */
 FLaC__INLINE
 void
-MD5Transform(FLAC__uint32 buf[4], FLAC__uint32 const in[16])
+FLAC__MD5Transform(FLAC__uint32 buf[4], FLAC__uint32 const in[16])
 {
        register FLAC__uint32 a, b, c, d;
 
@@ -163,7 +163,7 @@ byteSwap(FLAC__uint32 *buf, unsigned words)
  * initialization constants.
  */
 void
-MD5Init(struct MD5Context *ctx)
+FLAC__MD5Init(struct FLAC__MD5Context *ctx)
 {
        FLAC__uint32 test = 1;
 
@@ -186,7 +186,7 @@ MD5Init(struct MD5Context *ctx)
  * of bytes.
  */
 void
-MD5Update(struct MD5Context *ctx, md5byte const *buf, unsigned len)
+FLAC__MD5Update(struct FLAC__MD5Context *ctx, md5byte const *buf, unsigned len)
 {
        FLAC__uint32 t;
 
@@ -204,7 +204,7 @@ MD5Update(struct MD5Context *ctx, md5byte const *buf, unsigned len)
        /* First chunk is an odd size */
        memcpy((md5byte *)ctx->in + 64 - t, buf, t);
        byteSwap(ctx->in, 16);
-       MD5Transform(ctx->buf, ctx->in);
+       FLAC__MD5Transform(ctx->buf, ctx->in);
        buf += t;
        len -= t;
 
@@ -212,7 +212,7 @@ MD5Update(struct MD5Context *ctx, md5byte const *buf, unsigned len)
        while (len >= 64) {
                memcpy(ctx->in, buf, 64);
                byteSwap(ctx->in, 16);
-               MD5Transform(ctx->buf, ctx->in);
+               FLAC__MD5Transform(ctx->buf, ctx->in);
                buf += 64;
                len -= 64;
        }
@@ -222,10 +222,10 @@ MD5Update(struct MD5Context *ctx, md5byte const *buf, unsigned len)
 }
 
 /*
- * Convert the incoming audio signal to a byte stream and MD5Update it.
+ * Convert the incoming audio signal to a byte stream and FLAC__MD5Update it.
  */
 FLAC__bool
-FLAC__MD5Accumulate(struct MD5Context *ctx, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample)
+FLAC__MD5Accumulate(struct FLAC__MD5Context *ctx, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample)
 {
        unsigned channel, sample, a_byte;
        FLAC__int32 a_word;
@@ -268,7 +268,7 @@ FLAC__MD5Accumulate(struct MD5Context *ctx, const FLAC__int32 * const signal[],
                }
        }
 
-       MD5Update(ctx, ctx->internal_buf, bytes_needed);
+       FLAC__MD5Update(ctx, ctx->internal_buf, bytes_needed);
 
        return true;
 }
@@ -278,7 +278,7 @@ FLAC__MD5Accumulate(struct MD5Context *ctx, const FLAC__int32 * const signal[],
  * 1 0* (64-bit count of bits processed, MSB-first)
  */
 void
-MD5Final(md5byte digest[16], struct MD5Context *ctx)
+FLAC__MD5Final(md5byte digest[16], struct FLAC__MD5Context *ctx)
 {
        int count = ctx->bytes[0] & 0x3f;       /* Number of bytes in ctx->in */
        md5byte *p = (md5byte *)ctx->in + count;
@@ -292,7 +292,7 @@ MD5Final(md5byte digest[16], struct MD5Context *ctx)
        if (count < 0) {        /* Padding forces an extra block */
                memset(p, 0, count + 8);
                byteSwap(ctx->in, 16);
-               MD5Transform(ctx->buf, ctx->in);
+               FLAC__MD5Transform(ctx->buf, ctx->in);
                p = (md5byte *)ctx->in;
                count = 56;
        }
@@ -302,7 +302,7 @@ MD5Final(md5byte digest[16], struct MD5Context *ctx)
        /* Append length in bits and transform */
        ctx->in[14] = ctx->bytes[0] << 3;
        ctx->in[15] = ctx->bytes[1] << 3 | ctx->bytes[0] >> 29;
-       MD5Transform(ctx->buf, ctx->in);
+       FLAC__MD5Transform(ctx->buf, ctx->in);
 
        byteSwap(ctx->buf, 4);
        memcpy(digest, ctx->buf, 16);
index ede2312..c142c26 100644 (file)
@@ -68,7 +68,7 @@ typedef struct FLAC__SeekableStreamDecoderPrivate {
        void *client_data;
        FLAC__StreamDecoder *stream_decoder;
        FLAC__bool do_md5_checking; /* initially gets protected_->md5_checking but is turned off after a seek */
-       struct MD5Context md5context;
+       struct FLAC__MD5Context md5context;
        FLAC__byte stored_md5sum[16]; /* this is what is stored in the metadata */
        FLAC__byte computed_md5sum[16]; /* this is the sum we computed from the decoded data */
        /* the rest of these are only used for seeking: */
@@ -205,13 +205,13 @@ FLAC_API FLAC__SeekableStreamDecoderState FLAC__seekable_stream_decoder_init(FLA
 
        decoder->private_->do_md5_checking = decoder->protected_->md5_checking;
 
-       /* We initialize the MD5Context even though we may never use it.  This is
-        * because md5 checking may be turned on to start and then turned off if a
-        * seek occurs.  So we always init the context here and finalize it in
+       /* We initialize the FLAC__MD5Context even though we may never use it.  This
+        * is because md5 checking may be turned on to start and then turned off if
+        * seek occurs.  So we always init the context here and finalize it in
         * FLAC__seekable_stream_decoder_finish() to make sure things are always
         * cleaned up properly.
         */
-       MD5Init(&decoder->private_->md5context);
+       FLAC__MD5Init(&decoder->private_->md5context);
 
        FLAC__stream_decoder_set_read_callback(decoder->private_->stream_decoder, read_callback_);
        FLAC__stream_decoder_set_write_callback(decoder->private_->stream_decoder, write_callback_);
@@ -246,9 +246,9 @@ FLAC_API FLAC__bool FLAC__seekable_stream_decoder_finish(FLAC__SeekableStreamDec
        FLAC__ASSERT(0 != decoder->private_->stream_decoder);
 
        /* see the comment in FLAC__seekable_stream_decoder_init() as to why we
-        * always call MD5Final()
+        * always call FLAC__MD5Final()
         */
-       MD5Final(decoder->private_->computed_md5sum, &decoder->private_->md5context);
+       FLAC__MD5Final(decoder->private_->computed_md5sum, &decoder->private_->md5context);
 
        FLAC__stream_decoder_finish(decoder->private_->stream_decoder);
 
@@ -574,13 +574,13 @@ FLAC_API FLAC__bool FLAC__seekable_stream_decoder_reset(FLAC__SeekableStreamDeco
 
        decoder->private_->do_md5_checking = decoder->protected_->md5_checking;
 
-       /* We initialize the MD5Context even though we may never use it.  This is
-        * because md5 checking may be turned on to start and then turned off if a
-        * seek occurs.  So we always init the context here and finalize it in
+       /* We initialize the FLAC__MD5Context even though we may never use it.  This
+        * is because md5 checking may be turned on to start and then turned off if
+        * seek occurs.  So we always init the context here and finalize it in
         * FLAC__seekable_stream_decoder_finish() to make sure things are always
         * cleaned up properly.
         */
-       MD5Init(&decoder->private_->md5context);
+       FLAC__MD5Init(&decoder->private_->md5context);
 
        decoder->protected_->state = FLAC__SEEKABLE_STREAM_DECODER_OK;
 
index 75d22fb..1049414 100644 (file)
@@ -344,7 +344,7 @@ typedef struct FLAC__StreamEncoderPrivate {
        FLAC__StreamMetadata metadata;
        unsigned current_sample_number;
        unsigned current_frame_number;
-       struct MD5Context md5context;
+       struct FLAC__MD5Context md5context;
        FLAC__CPUInfo cpuinfo;
        unsigned (*local_fixed_compute_best_predictor)(const FLAC__int32 data[], unsigned data_len, FLAC__real residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
        void (*local_lpc_compute_autocorrelation)(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
@@ -858,7 +858,7 @@ FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_init(FLAC__StreamEncoder
        encoder->private_->metadata.data.stream_info.bits_per_sample = encoder->protected_->bits_per_sample;
        encoder->private_->metadata.data.stream_info.total_samples = encoder->protected_->total_samples_estimate; /* we will replace this later with the real total */
        memset(encoder->private_->metadata.data.stream_info.md5sum, 0, 16); /* we don't know this yet; have to fill it in later */
-       MD5Init(&encoder->private_->md5context);
+       FLAC__MD5Init(&encoder->private_->md5context);
        if(!FLAC__bitbuffer_clear(encoder->private_->frame))
                return encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
        if(!FLAC__add_metadata_block(&encoder->private_->metadata, encoder->private_->frame))
@@ -935,7 +935,7 @@ FLAC_API void FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder)
                }
        }
 
-       MD5Final(encoder->private_->metadata.data.stream_info.md5sum, &encoder->private_->md5context);
+       FLAC__MD5Final(encoder->private_->metadata.data.stream_info.md5sum, &encoder->private_->md5context);
 
        if(encoder->protected_->state == FLAC__STREAM_ENCODER_OK && !encoder->private_->is_being_deleted) {
                encoder->private_->metadata_callback(encoder, &encoder->private_->metadata, encoder->private_->client_data);
@@ -1867,7 +1867,7 @@ FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_last_f
 
                frame_header.channel_assignment = channel_assignment;
 
-               if(!FLAC__frame_add_header(&frame_header, encoder->protected_->streamable_subset, is_last_frame, encoder->private_->frame)) {
+               if(!FLAC__frame_add_header(&frame_header, encoder->protected_->streamable_subset, encoder->private_->frame)) {
                        encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
                        return false;
                }
@@ -1921,7 +1921,7 @@ FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_last_f
                        return false;
        }
        else {
-               if(!FLAC__frame_add_header(&frame_header, encoder->protected_->streamable_subset, is_last_frame, encoder->private_->frame)) {
+               if(!FLAC__frame_add_header(&frame_header, encoder->protected_->streamable_subset, encoder->private_->frame)) {
                        encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
                        return false;
                }
index 8dd3d16..6e7272c 100644 (file)
@@ -68,7 +68,7 @@ typedef struct OggFLAC__SeekableStreamDecoderPrivate {
        void *client_data;
        OggFLAC__StreamDecoder *stream_decoder;
        FLAC__bool do_md5_checking; /* initially gets protected_->md5_checking but is turned off after a seek */
-       struct MD5Context md5context;
+       struct FLAC__MD5Context md5context;
        FLAC__byte stored_md5sum[16]; /* this is what is stored in the metadata */
        FLAC__byte computed_md5sum[16]; /* this is the sum we computed from the decoded data */
        /* the rest of these are only used for seeking: */
@@ -205,13 +205,13 @@ OggFLAC_API OggFLAC__SeekableStreamDecoderState OggFLAC__seekable_stream_decoder
 
        decoder->private_->do_md5_checking = decoder->protected_->md5_checking;
 
-       /* We initialize the MD5Context even though we may never use it.  This is
-        * because md5 checking may be turned on to start and then turned off if a
-        * seek occurs.  So we always init the context here and finalize it in
+       /* We initialize the FLAC__MD5Context even though we may never use it.  This
+        * is because md5 checking may be turned on to start and then turned off if
+        * seek occurs.  So we always init the context here and finalize it in
         * OggFLAC__seekable_stream_decoder_finish() to make sure things are always
         * cleaned up properly.
         */
-       MD5Init(&decoder->private_->md5context);
+       FLAC__MD5Init(&decoder->private_->md5context);
 
        OggFLAC__stream_decoder_set_read_callback(decoder->private_->stream_decoder, read_callback_);
        OggFLAC__stream_decoder_set_write_callback(decoder->private_->stream_decoder, write_callback_);
@@ -246,9 +246,9 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_decoder_finish(OggFLAC__Seekable
        FLAC__ASSERT(0 != decoder->private_->stream_decoder);
 
        /* see the comment in OggFLAC__seekable_stream_decoder_init() as to why we
-        * always call MD5Final()
+        * always call FLAC__MD5Final()
         */
-       MD5Final(decoder->private_->computed_md5sum, &decoder->private_->md5context);
+       FLAC__MD5Final(decoder->private_->computed_md5sum, &decoder->private_->md5context);
 
        OggFLAC__stream_decoder_finish(decoder->private_->stream_decoder);
 
@@ -579,13 +579,13 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_decoder_reset(OggFLAC__SeekableS
 
        decoder->private_->do_md5_checking = decoder->protected_->md5_checking;
 
-       /* We initialize the MD5Context even though we may never use it.  This is
-        * because md5 checking may be turned on to start and then turned off if a
-        * seek occurs.  So we always init the context here and finalize it in
+       /* We initialize the FLAC__MD5Context even though we may never use it.  This
+        * is because md5 checking may be turned on to start and then turned off if
+        * seek occurs.  So we always init the context here and finalize it in
         * OggFLAC__seekable_stream_decoder_finish() to make sure things are always
         * cleaned up properly.
         */
-       MD5Init(&decoder->private_->md5context);
+       FLAC__MD5Init(&decoder->private_->md5context);
 
        decoder->protected_->state = OggFLAC__SEEKABLE_STREAM_DECODER_OK;
 
@@ -877,7 +877,12 @@ FLAC__bool seek_to_absolute_sample_(OggFLAC__SeekableStreamDecoder *decoder, FLA
                                if (iteration >= BINARY_SEARCH_AFTER_ITERATION)
                                        pos = (right_pos + left_pos) / 2;
                                else
+#if defined _MSC_VER || defined __MINGW32__
+                                       /* with VC++ you have to spoon feed it the casting */
+                                       pos = (FLAC__uint64)((double)(FLAC__int64)(target_sample - left_sample) / (double)(FLAC__int64)(right_pos - left_pos));
+#else
                                        pos = (FLAC__uint64)((double)(target_sample - left_sample) / (double)(right_pos - left_pos));
+#endif
 
                                if (this_frame_sample <= target_sample) {
                                        /* The 'equal' case should not happen, since