[xiph-commits] r3327 -
libfishsound/branches/1.0-stable-flac/src/libfishsound
conrad at svn.annodex.net
conrad at svn.annodex.net
Thu Jan 10 00:03:33 PST 2008
Author: conrad
Date: 2008-01-10 00:03:33 -0800 (Thu, 10 Jan 2008)
New Revision: 3327
Modified:
libfishsound/branches/1.0-stable-flac/src/libfishsound/flac.c
Log:
add license and comments to flac.c
Modified: libfishsound/branches/1.0-stable-flac/src/libfishsound/flac.c
===================================================================
--- libfishsound/branches/1.0-stable-flac/src/libfishsound/flac.c 2008-01-10 06:29:24 UTC (rev 3326)
+++ libfishsound/branches/1.0-stable-flac/src/libfishsound/flac.c 2008-01-10 08:03:33 UTC (rev 3327)
@@ -1,11 +1,50 @@
-#define DEBUG
-#include <stdio.h>
+/*
+ Copyright (C) 2007 Annodex Association
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ - Neither the name of the Annodex Association nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ASSOCIATION OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* Original patches by Tobias Gehrig, 2005
+ * http://www.annodex.net/software/libfishsound/libfishsound-flac/
+ *
+ * The Ogg FLAC mapping is documented in:
+ * http://flac.sourceforge.net/ogg_mapping.html
+ */
+
#include "config.h"
+#include <stdio.h>
+
#include "private.h"
#include "convert.h"
+#define DEBUG
+
#if HAVE_FLAC
#include "FLAC/all.h"
@@ -119,33 +158,47 @@
#endif
#ifdef FS_ENCODE
-FLAC__StreamEncoderWriteStatus fs_flac_enc_write_callback(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data)
+FLAC__StreamEncoderWriteStatus
+fs_flac_enc_write_callback(const FLAC__StreamEncoder *encoder,
+ const FLAC__byte buffer[], unsigned bytes,
+ unsigned samples, unsigned current_frame,
+ void *client_data)
{
FishSound* fsound = (FishSound*)client_data;
FishSoundFlacInfo *fi = fsound->codec_data;
#ifdef DEBUG
fprintf(stderr, "fs_flac_enc_write_callback\n");
printf("bytes: %d, samples: %d\n", bytes, samples);
-#endif DEBUG
+#endif
if (fsound->callback.encoded) {
FishSoundEncoded encoded = (FishSoundEncoded)fsound->callback.encoded;
if (fi->packetno == 0 && fi->header <= 1) {
- printf("first: %x\n", buffer[0]);
if (fi->header == 0) {
+ /* libFLAC has called us with data containing the normal fLaC header
+ * and a STREAMINFO block. Prepend the FLAC Ogg mapping header,
+ * as described in http://flac.sourceforge.net/ogg_mapping.html.
+ */
+#ifdef DEBUG
+ printf("fs_flac_enc_write_callback: generating FLAC header packet: %x\n",
+ buffer[0]);
+#endif
fi->buffer = (unsigned char*)malloc(sizeof(unsigned char)*(bytes+9));
fi->buffer[0] = 0x7f;
- fi->buffer[1] = 0x46;
- fi->buffer[2] = 0x4c;
- fi->buffer[3] = 0x41;
- fi->buffer[4] = 0x43;
- fi->buffer[5] = 1;
- fi->buffer[6] = 0;
- fi->buffer[7] = 0;
- fi->buffer[8] = 2;
- memcpy (fi->buffer+9, buffer, bytes);
+ fi->buffer[1] = 0x46; /* 'F' */
+ fi->buffer[2] = 0x4c; /* 'L' */
+ fi->buffer[3] = 0x41; /* 'A' */
+ fi->buffer[4] = 0x43; /* 'C' */
+ fi->buffer[5] = 1; /* Version major generated by this file */
+ fi->buffer[6] = 0; /* Version minor generated by this file */
+ fi->buffer[7] = 0; /* MSB(be): Nr. non-audio header packets */
+ fi->buffer[8] = 2; /* LSB(be): Nr. non-audio header packets */
+ memcpy (fi->buffer+9, buffer, bytes); /* fLaC header ++ STREAMINFO */
fi->bufferlength = bytes+9;
fi->header++;
} else {
+ /* Make a temporary copy of the metadata header to pass to the user
+ * callback.
+ */
unsigned char* tmp = (unsigned char*)malloc(sizeof(unsigned char)*(bytes+fi->bufferlength));
memcpy (tmp, fi->buffer, fi->bufferlength);
memcpy (tmp+fi->bufferlength, buffer, bytes);
@@ -192,8 +245,8 @@
int
fish_sound_flac_identify (unsigned char * buf, long bytes)
{
+ if (bytes < 8) return FISH_SOUND_UNKNOWN;
if (buf[0] != 0x7f) return FISH_SOUND_UNKNOWN;
- if (bytes < 8) return FISH_SOUND_UNKNOWN;
if (!strncmp ((char *)buf+1, "FLAC", 4)) {
#ifdef DEBUG
fprintf(stderr, "flac found\n");
@@ -201,8 +254,7 @@
/* if only a short buffer was passed, do a weak identify */
if (bytes == 8) return FISH_SOUND_FLAC;
- /* otherwise, assume the buffer is an entire initial header and
- * feed it to vorbis_synthesis_headerin() */
+ /* otherwise, look for the fLaC header preceding STREAMINFO */
if (!strncmp ((char *)buf+9, "fLaC", 4)) {
return FISH_SOUND_FLAC;
}
@@ -239,7 +291,9 @@
{
FishSoundFlacInfo *fi = fsound->codec_data;
int i, *p = (int *)pcm;
+#ifdef DEBUG
printf("frames: %ld\n", frames);
+#endif
if (fi->packetno == 0)
fs_flac_enc_headers (fsound);
// FLAC__stream_encoder_process_interleaved(fi->fse, pcm, frames);
@@ -281,7 +335,8 @@
fi->version.major = buf[5];
fi->version.minor = buf[6];
#ifdef DEBUG
- printf("Flac Version: %d.%d\n", fi->version.major, fi->version.minor);
+ printf("Flac Ogg Mapping Version: %d.%d\n",
+ fi->version.major, fi->version.minor);
#endif
fi->header_packets = buf[7] << 8 | buf[8];
#ifdef DEBUG
@@ -305,11 +360,13 @@
{
FishSoundFlacInfo *fi = fsound->codec_data;
#ifdef DEBUG
- fprintf(stderr, "fs_flac_decode\n");
+ printf("fs_flac_decode: IN\n");
#endif
if (fi->packetno == 0) {
if (process_header(fsound, buf, bytes) == NULL) {
- fprintf(stderr, "EROROROROR\n");
+#ifdef DEBUG
+ printf("fs_flac_decode: Error reading header\n");
+#endif
return -1;
}
fi->buffer = fs_malloc(sizeof(unsigned char)*bytes);
@@ -318,7 +375,9 @@
}
else if (fi->packetno <= fi->header_packets){
unsigned char* tmp = fs_malloc(sizeof(unsigned char)*(fi->bufferlength+bytes));
- /* if (fi->packetno == 1) fish_sound_comments_decode (fsound, buf, bytes); */
+#if 0
+ if (fi->packetno == 1) fish_sound_comments_decode (fsound, buf, bytes);
+#endif
memcpy(tmp, fi->buffer, fi->bufferlength);
memcpy(tmp+fi->bufferlength, buf, bytes);
fi->bufferlength += bytes;
More information about the commits
mailing list