Backout bug 480521 due to build failure

This commit is contained in:
Chris Double 2009-03-30 14:11:46 +13:00
commit d79758ffa4
22 changed files with 281 additions and 633 deletions

View File

@ -5,9 +5,6 @@ Conrad Parker <conrad@metadecks.org>
Tobias Gehrig Tobias Gehrig
- FLAC support - FLAC support
Michel Salim
- libFLAC 1.1.3 support
Silvia Pfeiffer <silvia@annodex.net> Silvia Pfeiffer <silvia@annodex.net>
- MS Windows porting, general packaging. - MS Windows porting, general packaging.

View File

@ -1,11 +1,10 @@
The source from this directory was copied from the libfishsound svn The source from this directory was copied from the libfishsound-0.9.1
distribution using the update.sh script. The only changes made source distribution using the update.sh script. The only changes made
were those applied by update.sh and the addition/upate of Makefile.in were those applied by update.sh and the addition/upate of Makefile.in
files for the Mozilla build system. files for the Mozilla build system.
Some files are renamed during the copy to prevent clashes with object Some files are renamed during the copy to prevent clashes with object
file names with other Mozilla libraries. file names with other Mozilla libraries.
The svn revision number used was r3901.
endian.patch is applied to fix Bug 45269. endian.patch is applied to fix Bug 45269.
bu481601.patch is applied to fix bug 481601.

View File

@ -1,9 +1,6 @@
/* config.h. Generated from config.h.in by configure. */ /* config.h. Generated from config.h.in by configure. */
/* config.h.in. Generated from configure.ac by autoheader. */ /* config.h.in. Generated from configure.ac by autoheader. */
/* Define if building universal (internal helper macro) */
/* #undef AC_APPLE_UNIVERSAL_BUILD */
/* Do not build decoding support */ /* Do not build decoding support */
#define FS_DECODE 1 #define FS_DECODE 1
@ -19,23 +16,17 @@
/* Define to 1 if you have libFLAC */ /* Define to 1 if you have libFLAC */
#define HAVE_FLAC 0 #define HAVE_FLAC 0
/* Define to 1 if you have libFLAC 1.1.2 */
/* #undef HAVE_FLAC_1_1_2 */
/* Define to 1 if you have libFLAC 1.1.3 */
/* #undef HAVE_FLAC_1_1_3 */
/* Define to 1 if you have the <inttypes.h> header file. */ /* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H 1 #define HAVE_INTTYPES_H 1
/* Define if have libsndfile */ /* Define if have libsndfile */
#define HAVE_LIBSNDFILE1 /**/ /* #undef HAVE_LIBSNDFILE1 */
/* Define to 1 if you have the <memory.h> header file. */ /* Define to 1 if you have the <memory.h> header file. */
#define HAVE_MEMORY_H 1 #define HAVE_MEMORY_H 1
/* Define if have liboggz */ /* Define if have liboggz */
#define HAVE_OGGZ /**/ /* #undef HAVE_OGGZ */
/* Define to 1 if you have libspeex */ /* Define to 1 if you have libspeex */
#define HAVE_SPEEX 0 #define HAVE_SPEEX 0
@ -43,9 +34,6 @@
/* Define to 1 if you have libspeex 1.1.x */ /* Define to 1 if you have libspeex 1.1.x */
/* #undef HAVE_SPEEX_1_1 */ /* #undef HAVE_SPEEX_1_1 */
/* Define to 1 if speex_lib_get_mode() exists in libspeex */
/* #undef HAVE_SPEEX_LIB_GET_MODE */
/* Define to 1 if you have the <stdint.h> header file. */ /* Define to 1 if you have the <stdint.h> header file. */
#define HAVE_STDINT_H 1 #define HAVE_STDINT_H 1
@ -73,10 +61,6 @@
/* Define to 1 if you have libvorbisenc */ /* Define to 1 if you have libvorbisenc */
#define HAVE_VORBISENC 0 #define HAVE_VORBISENC 0
/* Define to the sub-directory in which libtool stores uninstalled libraries.
*/
#define LT_OBJDIR ".libs/"
/* Name of package */ /* Name of package */
#define PACKAGE "libfishsound" #define PACKAGE "libfishsound"
@ -99,19 +83,11 @@
#define STDC_HEADERS 1 #define STDC_HEADERS 1
/* Version number of package */ /* Version number of package */
#define VERSION "0.9.0" #define VERSION "0.9.1"
/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most /* Define to 1 if your processor stores words with the most significant byte
significant byte first (like Motorola and SPARC, unlike Intel). */ first (like Motorola and SPARC, unlike Intel and VAX). */
#if defined AC_APPLE_UNIVERSAL_BUILD /* #undef WORDS_BIGENDIAN */
# if defined __BIG_ENDIAN__
# define WORDS_BIGENDIAN 1
# endif
#else
# ifndef WORDS_BIGENDIAN
/* # undef WORDS_BIGENDIAN */
# endif
#endif
/* Define to empty if `const' does not conform to ANSI C. */ /* Define to empty if `const' does not conform to ANSI C. */
/* #undef const */ /* #undef const */

View File

@ -106,9 +106,6 @@ typedef enum _FishSoundError {
/** The requested operation is not suitable for this FishSound* handle */ /** The requested operation is not suitable for this FishSound* handle */
FISH_SOUND_ERR_INVALID = -3, FISH_SOUND_ERR_INVALID = -3,
/** Out of memory */
FISH_SOUND_ERR_OUT_OF_MEMORY = -4,
/** Functionality disabled at build time */ /** Functionality disabled at build time */
FISH_SOUND_ERR_DISABLED = -10, FISH_SOUND_ERR_DISABLED = -10,

View File

@ -79,9 +79,7 @@ typedef int (*FishSoundDecoded_FloatIlv) (FishSound * fsound, float ** pcm,
* \param fsound A FishSound* handle (created with mode FISH_SOUND_DECODE) * \param fsound A FishSound* handle (created with mode FISH_SOUND_DECODE)
* \param decoded The callback to call * \param decoded The callback to call
* \param user_data Arbitrary user data to pass to the callback * \param user_data Arbitrary user data to pass to the callback
* \retval 0 Success * \returns 0 on success, -1 on failure
* \retval FISH_SOUND_ERR_BAD Not a valid FishSound* handle
* \retval FISH_SOUND_ERR_OUT_OF_MEMORY Out of memory
*/ */
int fish_sound_set_decoded_float (FishSound * fsound, int fish_sound_set_decoded_float (FishSound * fsound,
FishSoundDecoded_Float decoded, FishSoundDecoded_Float decoded,
@ -93,9 +91,7 @@ int fish_sound_set_decoded_float (FishSound * fsound,
* \param fsound A FishSound* handle (created with mode FISH_SOUND_DECODE) * \param fsound A FishSound* handle (created with mode FISH_SOUND_DECODE)
* \param decoded The callback to call * \param decoded The callback to call
* \param user_data Arbitrary user data to pass to the callback * \param user_data Arbitrary user data to pass to the callback
* \retval 0 Success * \returns 0 on success, -1 on failure
* \retval FISH_SOUND_ERR_BAD Not a valid FishSound* handle
* \retval FISH_SOUND_ERR_OUT_OF_MEMORY Out of memory
*/ */
int fish_sound_set_decoded_float_ilv (FishSound * fsound, int fish_sound_set_decoded_float_ilv (FishSound * fsound,
FishSoundDecoded_FloatIlv decoded, FishSoundDecoded_FloatIlv decoded,
@ -117,8 +113,6 @@ int fish_sound_set_decoded_float_ilv (FishSound * fsound,
* callback returning FISH_SOUND_STOP_ERR before any input bytes were consumed. * callback returning FISH_SOUND_STOP_ERR before any input bytes were consumed.
* This will occur when PCM is decoded from previously buffered input, and * This will occur when PCM is decoded from previously buffered input, and
* stopping is immediately requested. * stopping is immediately requested.
* \retval FISH_SOUND_ERR_BAD Not a valid FishSound* handle
* \retval FISH_SOUND_ERR_OUT_OF_MEMORY Out of memory
*/ */
long fish_sound_decode (FishSound * fsound, unsigned char * buf, long bytes); long fish_sound_decode (FishSound * fsound, unsigned char * buf, long bytes);

View File

@ -41,6 +41,27 @@
extern "C" { extern "C" {
#endif #endif
/**
* DEPRECATED FUNCTION.
* Set the PCM format used by a FishSound object. The default value is
* non-interleaved.
* Prior to libfishsound 0.7.0, you would (optionally) specify whether you
* wanted to receive interleaved or per-channel PCM data using
* fish_sound_set_interleave(), the default being per-channel
* (non-interleaved) PCM.
* Whether or not your decoded callback expects interleaved or
* non-interleaved data is now implied by the particular
* fish_sound_set_decoded_TYPE() method you use to set it, such as
* fish_sound_set_decoded_float() or fish_sound_set_decode_float_ilv().
*
* \param fsound A FishSound* handle
* \param interleave Whether to use interleaved PCM or not. Valid values are
* 0 for non-interleaved, and 1 for interleaved.
* \retval 0 Success
* \retval -1 Invalid \a fsound
*/
int fish_sound_set_interleave (FishSound * fsound, int interleave);
/** /**
* DEPRECATED TYPE. * DEPRECATED TYPE.
* Signature of a callback for libfishsound to call when it has decoded * Signature of a callback for libfishsound to call when it has decoded
@ -78,7 +99,7 @@ int fish_sound_set_decoded_callback (FishSound * fsound,
* Whether or not your decoded callback expects interleaved or * Whether or not your decoded callback expects interleaved or
* non-interleaved data is now implied by the particular * non-interleaved data is now implied by the particular
* fish_sound_set_decoded_TYPE() method you use to set it, such as * fish_sound_set_decoded_TYPE() method you use to set it, such as
* fish_sound_set_decoded_float() or fish_sound_set_decoded_float_ilv(). * fish_sound_set_decoded_float() or fish_sound_set_decode_float_ilv().
* *
* \param fsound A FishSound* handle * \param fsound A FishSound* handle
* \param interleave Whether to use interleaved PCM or not. Valid values are * \param interleave Whether to use interleaved PCM or not. Valid values are

View File

@ -505,7 +505,7 @@ int fish_sound_command (FishSound * fsound, int command, void * data,
* \param fsound A FishSound* handle * \param fsound A FishSound* handle
* \retval 0 \a fsound uses non-interleaved PCM * \retval 0 \a fsound uses non-interleaved PCM
* \retval 1 \a fsound uses interleaved PCM * \retval 1 \a fsound uses interleaved PCM
* \retval -1 Invalid \a fsound, or out of memory. * \retval -1 Invalid \a fsound
*/ */
int fish_sound_get_interleave (FishSound * fsound); int fish_sound_get_interleave (FishSound * fsound);

View File

@ -1,9 +1,6 @@
/* config.h. Generated from config.h.in by configure. */ /* config.h. Generated from config.h.in by configure. */
/* config.h.in. Generated from configure.ac by autoheader. */ /* config.h.in. Generated from configure.ac by autoheader. */
/* Define if building universal (internal helper macro) */
/* #undef AC_APPLE_UNIVERSAL_BUILD */
/* Do not build decoding support */ /* Do not build decoding support */
#define FS_DECODE 1 #define FS_DECODE 1
@ -19,23 +16,17 @@
/* Define to 1 if you have libFLAC */ /* Define to 1 if you have libFLAC */
#define HAVE_FLAC 0 #define HAVE_FLAC 0
/* Define to 1 if you have libFLAC 1.1.2 */
/* #undef HAVE_FLAC_1_1_2 */
/* Define to 1 if you have libFLAC 1.1.3 */
/* #undef HAVE_FLAC_1_1_3 */
/* Define to 1 if you have the <inttypes.h> header file. */ /* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H 1 #define HAVE_INTTYPES_H 1
/* Define if have libsndfile */ /* Define if have libsndfile */
#define HAVE_LIBSNDFILE1 /**/ /* #undef HAVE_LIBSNDFILE1 */
/* Define to 1 if you have the <memory.h> header file. */ /* Define to 1 if you have the <memory.h> header file. */
#define HAVE_MEMORY_H 1 #define HAVE_MEMORY_H 1
/* Define if have liboggz */ /* Define if have liboggz */
#define HAVE_OGGZ /**/ /* #undef HAVE_OGGZ */
/* Define to 1 if you have libspeex */ /* Define to 1 if you have libspeex */
#define HAVE_SPEEX 0 #define HAVE_SPEEX 0
@ -43,9 +34,6 @@
/* Define to 1 if you have libspeex 1.1.x */ /* Define to 1 if you have libspeex 1.1.x */
/* #undef HAVE_SPEEX_1_1 */ /* #undef HAVE_SPEEX_1_1 */
/* Define to 1 if speex_lib_get_mode() exists in libspeex */
/* #undef HAVE_SPEEX_LIB_GET_MODE */
/* Define to 1 if you have the <stdint.h> header file. */ /* Define to 1 if you have the <stdint.h> header file. */
#define HAVE_STDINT_H 1 #define HAVE_STDINT_H 1
@ -73,10 +61,6 @@
/* Define to 1 if you have libvorbisenc */ /* Define to 1 if you have libvorbisenc */
#define HAVE_VORBISENC 0 #define HAVE_VORBISENC 0
/* Define to the sub-directory in which libtool stores uninstalled libraries.
*/
#define LT_OBJDIR ".libs/"
/* Name of package */ /* Name of package */
#define PACKAGE "libfishsound" #define PACKAGE "libfishsound"
@ -99,19 +83,11 @@
#define STDC_HEADERS 1 #define STDC_HEADERS 1
/* Version number of package */ /* Version number of package */
#define VERSION "0.9.0" #define VERSION "0.9.1"
/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most /* Define to 1 if your processor stores words with the most significant byte
significant byte first (like Motorola and SPARC, unlike Intel). */ first (like Motorola and SPARC, unlike Intel and VAX). */
#if defined AC_APPLE_UNIVERSAL_BUILD /* #undef WORDS_BIGENDIAN */
# if defined __BIG_ENDIAN__
# define WORDS_BIGENDIAN 1
# endif
#else
# ifndef WORDS_BIGENDIAN
/* # undef WORDS_BIGENDIAN */
# endif
#endif
/* Define to empty if `const' does not conform to ANSI C. */ /* Define to empty if `const' does not conform to ANSI C. */
/* #undef const */ /* #undef const */

View File

@ -70,7 +70,7 @@ fish_sound_set_format (FishSound * fsound, int format)
} }
if (fsound->codec && fsound->codec->init) if (fsound->codec && fsound->codec->init)
if (fsound->codec->init (fsound) == NULL) return -1; fsound->codec->init (fsound);
fsound->info.format = format; fsound->info.format = format;
@ -105,7 +105,6 @@ fish_sound_new (int mode, FishSoundInfo * fsinfo)
} }
fsound = fs_malloc (sizeof (FishSound)); fsound = fs_malloc (sizeof (FishSound));
if (fsound == NULL) return NULL;
fsound->mode = mode; fsound->mode = mode;
fsound->interleave = 0; fsound->interleave = 0;

View File

@ -35,50 +35,27 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <limits.h> /* ULONG_MAX */
#ifndef WIN32
#include <strings.h>
#endif
#include "private.h" #include "private.h"
/*#define DEBUG*/ /*#define DEBUG*/
/* Ensure comment vector length can be expressed in 32 bits
* including space for the trailing NUL */
#define MAX_COMMENT_LENGTH 0xFFFFFFFE
#define fs_comment_clamp(c) MIN((c),MAX_COMMENT_LENGTH)
static size_t
fs_comment_len (const char * s)
{
size_t len;
if (s == NULL) return 0;
len = strlen (s);
return fs_comment_clamp(len);
}
static char * static char *
fs_strdup (const char * s) fs_strdup (const char * s)
{ {
char * ret; char * ret;
if (s == NULL) return NULL; if (s == NULL) return NULL;
ret = fs_malloc (fs_comment_len(s) + 1); ret = fs_malloc (strlen(s) + 1);
if (ret == NULL) return NULL;
return strcpy (ret, s); return strcpy (ret, s);
} }
static char * static char *
fs_strdup_len (const char * s, size_t len) fs_strdup_len (const char * s, int len)
{ {
char * ret; char * ret;
if (s == NULL) return NULL; if (s == NULL) return NULL;
if (len == 0) return NULL; if (len == 0) return NULL;
len = fs_comment_clamp(len);
ret = fs_malloc (len + 1); ret = fs_malloc (len + 1);
if (ret == NULL) return NULL;
if (strncpy (ret, s, len) == NULL) { if (strncpy (ret, s, len) == NULL) {
fs_free (ret); fs_free (ret);
return NULL; return NULL;
@ -102,6 +79,11 @@ fs_index_len (const char * s, char c, int len)
return NULL; return NULL;
} }
#if 0
static void comment_init(char **comments, int* length, char *vendor_string);
static void comment_add(char **comments, int* length, char *tag, char *val);
#endif
/* /*
Comments will be stored in the Vorbis style. Comments will be stored in the Vorbis style.
It is describled in the "Structure" section of It is describled in the "Structure" section of
@ -132,6 +114,47 @@ The comment header is decoded as follows:
buf[base]=(val)&0xff; \ buf[base]=(val)&0xff; \
}while(0) }while(0)
#if 0
static void
comment_init(char **comments, int* length, char *vendor_string)
{
int vendor_length=strlen(vendor_string);
int user_comment_list_length=0;
int len=4+vendor_length+4;
char *p=(char*)fs_malloc(len);
if(p==NULL){
}
writeint(p, 0, vendor_length);
memcpy(p+4, vendor_string, vendor_length);
writeint(p, 4+vendor_length, user_comment_list_length);
*length=len;
*comments=p;
}
static void
comment_add(char **comments, int* length, char *tag, char *val)
{
char* p=*comments;
int vendor_length=readint(p, 0);
int user_comment_list_length=readint(p, 4+vendor_length);
int tag_len=(tag?strlen(tag):0);
int val_len=strlen(val);
int len=(*length)+4+tag_len+val_len;
p=(char*)fs_realloc(p, len);
if(p==NULL){
}
writeint(p, *length, tag_len+val_len); /* length of comment */
if(tag) memcpy(p+*length+4, tag, tag_len); /* comment */
memcpy(p+*length+4+tag_len, val, val_len); /* comment */
writeint(p, 4+vendor_length, user_comment_list_length+1);
*comments=p;
*length=len;
}
#endif
static int static int
fs_comment_validate_byname (const char * name, const char * value) fs_comment_validate_byname (const char * name, const char * value)
{ {
@ -159,23 +182,10 @@ fs_comment_new (const char * name, const char * value)
FishSoundComment * comment; FishSoundComment * comment;
if (!fs_comment_validate_byname (name, value)) return NULL; if (!fs_comment_validate_byname (name, value)) return NULL;
/* Ensures that name != NULL, value != NULL, and validates strings */
comment = fs_malloc (sizeof (FishSoundComment)); comment = fs_malloc (sizeof (FishSoundComment));
if (comment == NULL) return NULL;
comment->name = fs_strdup (name); comment->name = fs_strdup (name);
if (comment->name == NULL) {
fs_free (comment);
return NULL;
}
comment->value = fs_strdup (value); comment->value = fs_strdup (value);
if (comment->value == NULL) {
fs_free (comment->name);
fs_free (comment);
return NULL;
}
return comment; return comment;
} }
@ -201,19 +211,6 @@ fs_comment_cmp (const FishSoundComment * comment1, const FishSoundComment * comm
return 1; return 1;
} }
int
fish_sound_comment_set_vendor (FishSound * fsound, const char * vendor_string)
{
if (fsound == NULL) return FISH_SOUND_ERR_BAD;
if (fsound->vendor) fs_free (fsound->vendor);
if ((fsound->vendor = fs_strdup (vendor_string)) == NULL)
return FISH_SOUND_ERR_OUT_OF_MEMORY;
return 0;
}
/* Public API */ /* Public API */
const char * const char *
@ -224,6 +221,18 @@ fish_sound_comment_get_vendor (FishSound * fsound)
return fsound->vendor; return fsound->vendor;
} }
int
fish_sound_comment_set_vendor (FishSound * fsound, const char * vendor_string)
{
if (fsound == NULL) return FISH_SOUND_ERR_BAD;
if (fsound->vendor) fs_free (fsound->vendor);
fsound->vendor = fs_strdup (vendor_string);
return 0;
}
const FishSoundComment * const FishSoundComment *
fish_sound_comment_first (FishSound * fsound) fish_sound_comment_first (FishSound * fsound)
{ {
@ -302,13 +311,11 @@ fish_sound_comment_add (FishSound * fsound, FishSoundComment * comment)
if (!fs_comment_validate_byname (comment->name, comment->value)) if (!fs_comment_validate_byname (comment->name, comment->value))
return FISH_SOUND_ERR_COMMENT_INVALID; return FISH_SOUND_ERR_COMMENT_INVALID;
if ((new_comment = fs_comment_new (comment->name, comment->value)) == NULL) new_comment = fs_comment_new (comment->name, comment->value);
return FISH_SOUND_ERR_OUT_OF_MEMORY;
if (_fs_comment_add (fsound, new_comment) == NULL) _fs_comment_add (fsound, new_comment);
return FISH_SOUND_ERR_OUT_OF_MEMORY;
return FISH_SOUND_OK; return 0;
#else #else
return FISH_SOUND_ERR_DISABLED; return FISH_SOUND_ERR_DISABLED;
#endif #endif
@ -329,13 +336,9 @@ fish_sound_comment_add_byname (FishSound * fsound, const char * name,
if (!fs_comment_validate_byname (name, value)) if (!fs_comment_validate_byname (name, value))
return FISH_SOUND_ERR_COMMENT_INVALID; return FISH_SOUND_ERR_COMMENT_INVALID;
if ((comment = fs_comment_new (name, value)) == NULL) comment = fs_comment_new (name, value);
return FISH_SOUND_ERR_OUT_OF_MEMORY;
if (_fs_comment_add (fsound, comment) == NULL) _fs_comment_add (fsound, comment);
return FISH_SOUND_ERR_OUT_OF_MEMORY;
return FISH_SOUND_OK;
return 0; return 0;
@ -426,8 +429,7 @@ fish_sound_comments_decode (FishSound * fsound, unsigned char * comments,
long length) long length)
{ {
char *c= (char *)comments; char *c= (char *)comments;
int i, nb_fields, n; int len, i, nb_fields, n;
size_t len;
char *end; char *end;
char * name, * value, * nvalue = NULL; char * name, * value, * nvalue = NULL;
FishSoundComment * comment; FishSoundComment * comment;
@ -437,20 +439,14 @@ fish_sound_comments_decode (FishSound * fsound, unsigned char * comments,
end = c+length; end = c+length;
len=readint(c, 0); len=readint(c, 0);
if (len<0) return -1;
c+=4; c+=4;
if (len>end-c) return -1; if (c+len>end) return -1;
/* Vendor */ /* Vendor */
if (len > 0) { nvalue = fs_strdup_len (c, len);
if ((nvalue = fs_strdup_len (c, len)) == NULL) fish_sound_comment_set_vendor (fsound, nvalue);
return FISH_SOUND_ERR_OUT_OF_MEMORY; if (nvalue) fs_free (nvalue);
if (fish_sound_comment_set_vendor (fsound, nvalue) == FISH_SOUND_ERR_OUT_OF_MEMORY)
return FISH_SOUND_ERR_OUT_OF_MEMORY;
fs_free (nvalue);
}
#ifdef DEBUG #ifdef DEBUG
fwrite(c, 1, len, stderr); fputc ('\n', stderr); fwrite(c, 1, len, stderr); fputc ('\n', stderr);
#endif #endif
@ -458,8 +454,6 @@ fish_sound_comments_decode (FishSound * fsound, unsigned char * comments,
if (c+4>end) return -1; if (c+4>end) return -1;
/* This value gets checked effectively by the 'for' condition
and the checks within the loop for c running off the end. */
nb_fields=readint(c, 0); nb_fields=readint(c, 0);
#ifdef DEBUG #ifdef DEBUG
printf ("fish_sound_comments_decode: %d comments\n", nb_fields); printf ("fish_sound_comments_decode: %d comments\n", nb_fields);
@ -474,10 +468,9 @@ fish_sound_comments_decode (FishSound * fsound, unsigned char * comments,
#ifdef DEBUG #ifdef DEBUG
printf ("fish_sound_comments_decode: [%d] len %d\n", i, len); printf ("fish_sound_comments_decode: [%d] len %d\n", i, len);
#endif #endif
if (len<0) return -1;
c+=4; c+=4;
if (len>end-c) return -1; if (c+len>end) return -1;
name = c; name = c;
value = fs_index_len (c, '=', len); value = fs_index_len (c, '=', len);
@ -486,33 +479,22 @@ fish_sound_comments_decode (FishSound * fsound, unsigned char * comments,
value++; value++;
n = c+len - value; n = c+len - value;
if ((nvalue = fs_strdup_len (value, n)) == NULL) nvalue = fs_strdup_len (value, n);
return FISH_SOUND_ERR_OUT_OF_MEMORY;
#ifdef DEBUG #ifdef DEBUG
printf ("fish_sound_comments_decode: %s -> %s (length %d)\n", printf ("fish_sound_comments_decode: %s -> %s (length %d)\n",
name, nvalue, n); name, nvalue, n);
#endif #endif
if ((comment = fs_comment_new (name, nvalue)) == NULL) comment = fs_comment_new (name, nvalue);
return FISH_SOUND_ERR_OUT_OF_MEMORY; _fs_comment_add (fsound, comment);
if (_fs_comment_add (fsound, comment) == NULL)
return FISH_SOUND_ERR_OUT_OF_MEMORY;
fs_free (nvalue); fs_free (nvalue);
} else { } else {
#ifdef DEBUG #ifdef DEBUG
printf ("fish_sound_comments_decode: [%d] %s (no value)\n", printf ("fish_sound_comments_decode: [%d] %s (no value)\n",
i, name, len); i, name, len);
#endif #endif
if ((nvalue = fs_strdup_len (name, len)) == NULL) nvalue = fs_strdup_len (name, len);
return FISH_SOUND_ERR_OUT_OF_MEMORY; comment = fs_comment_new (nvalue, NULL);
_fs_comment_add (fsound, comment);
if ((comment = fs_comment_new (nvalue, NULL)) == NULL)
return FISH_SOUND_ERR_OUT_OF_MEMORY;
if (_fs_comment_add (fsound, comment) == NULL)
return FISH_SOUND_ERR_OUT_OF_MEMORY;
fs_free (nvalue); fs_free (nvalue);
} }
@ -523,28 +505,7 @@ fish_sound_comments_decode (FishSound * fsound, unsigned char * comments,
printf ("fish_sound_comments_decode: done\n"); printf ("fish_sound_comments_decode: done\n");
#endif #endif
return FISH_SOUND_OK;
}
/*
* Pre-condition: at least one of accum, delta are non-zero,
* ie. don't call accum_length (0, 0);
* \retval 0 Failure: integer overflow
*/
static unsigned long
accum_length (unsigned long * accum, unsigned long delta)
{
/* Pre-condition: don't call accum_length (0, 0) */
if (*accum == 0 && delta == 0)
return 0; return 0;
/* Check for integer overflow */
if (delta > ULONG_MAX - (*accum))
return 0;
*accum += delta;
return *accum;
} }
long long
@ -553,29 +514,21 @@ fish_sound_comments_encode (FishSound * fsound, unsigned char * buf,
{ {
char * c = (char *)buf; char * c = (char *)buf;
const FishSoundComment * comment; const FishSoundComment * comment;
int nb_fields = 0, vendor_length = 0; int nb_fields = 0, vendor_length, field_length;
unsigned long actual_length = 0, remaining = length, field_length; long actual_length, remaining = length;
/* Vendor string */ /* Vendor string */
if (fsound->vendor) vendor_length = strlen (fsound->vendor);
vendor_length = fs_comment_len (fsound->vendor); actual_length = 4 + vendor_length;
if (accum_length (&actual_length, 4 + vendor_length) == 0)
return 0;
/* user comment list length */ /* user comment list length */
if (accum_length (&actual_length, 4) == 0) actual_length += 4;
return 0;
for (comment = fish_sound_comment_first (fsound); comment; for (comment = fish_sound_comment_first (fsound); comment;
comment = fish_sound_comment_next (fsound, comment)) { comment = fish_sound_comment_next (fsound, comment)) {
/* [size]"name" */ actual_length += 4 + strlen (comment->name); /* [size]"name" */
if (accum_length (&actual_length, 4 + fs_comment_len (comment->name)) == 0) if (comment->value)
return 0; actual_length += 1 + strlen (comment->value); /* "=value" */
if (comment->value) {
/* "=value" */
if (accum_length (&actual_length, 1 + fs_comment_len (comment->value)) == 0)
return 0;
}
#ifdef DEBUG #ifdef DEBUG
printf ("fish_sound_comments_encode: %s = %s\n", printf ("fish_sound_comments_encode: %s = %s\n",
@ -585,11 +538,7 @@ fish_sound_comments_encode (FishSound * fsound, unsigned char * buf,
nb_fields++; nb_fields++;
} }
/* framing bit */ actual_length++; /* framing bit */
if (accum_length (&actual_length, 1) == 0)
return 0;
/* NB. actual_length is not modified from here onwards */
if (buf == NULL) return actual_length; if (buf == NULL) return actual_length;
@ -598,12 +547,10 @@ fish_sound_comments_encode (FishSound * fsound, unsigned char * buf,
writeint (c, 0, vendor_length); writeint (c, 0, vendor_length);
c += 4; c += 4;
if (fsound->vendor) { field_length = strlen (fsound->vendor);
field_length = fs_comment_len (fsound->vendor);
memcpy (c, fsound->vendor, MIN (field_length, remaining)); memcpy (c, fsound->vendor, MIN (field_length, remaining));
c += field_length; remaining -= field_length; c += field_length; remaining -= field_length;
if (remaining <= 0) return actual_length; if (remaining <= 0 ) return actual_length;
}
remaining -= 4; remaining -= 4;
if (remaining <= 0) return actual_length; if (remaining <= 0) return actual_length;
@ -613,16 +560,16 @@ fish_sound_comments_encode (FishSound * fsound, unsigned char * buf,
for (comment = fish_sound_comment_first (fsound); comment; for (comment = fish_sound_comment_first (fsound); comment;
comment = fish_sound_comment_next (fsound, comment)) { comment = fish_sound_comment_next (fsound, comment)) {
field_length = fs_comment_len (comment->name); /* [size]"name" */ field_length = strlen (comment->name); /* [size]"name" */
if (comment->value) if (comment->value)
field_length += 1 + fs_comment_len (comment->value); /* "=value" */ field_length += 1 + strlen (comment->value); /* "=value" */
remaining -= 4; remaining -= 4;
if (remaining <= 0) return actual_length; if (remaining <= 0) return actual_length;
writeint (c, 0, field_length); writeint (c, 0, field_length);
c += 4; c += 4;
field_length = fs_comment_len (comment->name); field_length = strlen (comment->name);
memcpy (c, comment->name, MIN (field_length, remaining)); memcpy (c, comment->name, MIN (field_length, remaining));
c += field_length; remaining -= field_length; c += field_length; remaining -= field_length;
if (remaining <= 0) return actual_length; if (remaining <= 0) return actual_length;
@ -633,7 +580,7 @@ fish_sound_comments_encode (FishSound * fsound, unsigned char * buf,
*c = '='; *c = '=';
c++; c++;
field_length = fs_comment_len (comment->value); field_length = strlen (comment->value);
memcpy (c, comment->value, MIN (field_length, remaining)); memcpy (c, comment->value, MIN (field_length, remaining));
c += field_length; remaining -= field_length; c += field_length; remaining -= field_length;
if (remaining <= 0) return actual_length; if (remaining <= 0) return actual_length;

View File

@ -58,7 +58,7 @@ int fish_sound_set_decoded_float (FishSound * fsound,
{ {
int ret = 0; int ret = 0;
if (fsound == NULL) return FISH_SOUND_ERR_BAD; if (fsound == NULL) return -1;
#if FS_DECODE #if FS_DECODE
ret = fs_decode_update (fsound, 0); ret = fs_decode_update (fsound, 0);
@ -80,7 +80,7 @@ int fish_sound_set_decoded_float_ilv (FishSound * fsound,
{ {
int ret = 0; int ret = 0;
if (fsound == NULL) return FISH_SOUND_ERR_BAD; if (fsound == NULL) return -1;
#if FS_DECODE #if FS_DECODE
ret = fs_decode_update (fsound, 1); ret = fs_decode_update (fsound, 1);
@ -101,7 +101,7 @@ fish_sound_decode (FishSound * fsound, unsigned char * buf, long bytes)
{ {
int format; int format;
if (fsound == NULL) return FISH_SOUND_ERR_BAD; if (fsound == NULL) return -1;
#if FS_DECODE #if FS_DECODE
if (fsound->info.format == FISH_SOUND_UNKNOWN) { if (fsound->info.format == FISH_SOUND_UNKNOWN) {

View File

@ -141,7 +141,6 @@ fs_flac_write_callback(const FLAC__StreamDecoder *decoder,
FishSound* fsound = (FishSound*)client_data; FishSound* fsound = (FishSound*)client_data;
FishSoundFlacInfo* fi = (FishSoundFlacInfo *)fsound->codec_data; FishSoundFlacInfo* fi = (FishSoundFlacInfo *)fsound->codec_data;
int i, j, channels, blocksize, offset; int i, j, channels, blocksize, offset;
float * ipcm;
channels = frame->header.channels; channels = frame->header.channels;
blocksize = frame->header.blocksize; blocksize = frame->header.blocksize;
@ -159,10 +158,7 @@ fs_flac_write_callback(const FLAC__StreamDecoder *decoder,
FishSoundDecoded_FloatIlv dfi; FishSoundDecoded_FloatIlv dfi;
float* retpcm; float* retpcm;
if ((ipcm = realloc(fi->ipcm, sizeof(float) * channels * blocksize)) == NULL) fi->ipcm = realloc(fi->ipcm, sizeof(float) * channels * blocksize);
return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
fi->ipcm = ipcm;
retpcm = (float*) fi->ipcm; retpcm = (float*) fi->ipcm;
for (i = 0; i < blocksize; i++) { for (i = 0; i < blocksize; i++) {
offset = i * channels; offset = i * channels;
@ -177,9 +173,7 @@ fs_flac_write_callback(const FLAC__StreamDecoder *decoder,
float *d; /* de-interleave dest */ float *d; /* de-interleave dest */
for (j = 0; j < channels; j++) { for (j = 0; j < channels; j++) {
if ((ipcm = realloc(fi->pcm_out[j], sizeof(float) * blocksize)) == NULL) fi->pcm_out[j] = realloc(fi->pcm_out[j], sizeof(float) * blocksize);
return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
fi->pcm_out[j] = ipcm;
} }
for (i = 0; i < blocksize; i++) for (i = 0; i < blocksize; i++)
for (j = 0; j < channels; j++) { for (j = 0; j < channels; j++) {
@ -237,8 +231,6 @@ static void*
fs_flac_decode_header (FishSound * fsound, unsigned char *buf, long bytes) fs_flac_decode_header (FishSound * fsound, unsigned char *buf, long bytes)
{ {
FishSoundFlacInfo *fi = fsound->codec_data; FishSoundFlacInfo *fi = fsound->codec_data;
if (bytes < 9) return NULL;
if (buf[0] != 0x7f) return NULL; if (buf[0] != 0x7f) return NULL;
if (strncmp((char *)buf+1, "FLAC", 4) != 0) return NULL; if (strncmp((char *)buf+1, "FLAC", 4) != 0) return NULL;
fi->version.major = buf[5]; fi->version.major = buf[5];
@ -260,7 +252,6 @@ fs_flac_decode_header (FishSound * fsound, unsigned char *buf, long bytes)
return NULL; return NULL;
} }
#if defined (HAVE_FLAC_1_1_2)
FLAC__stream_decoder_set_read_callback(fi->fsd, fs_flac_read_callback); FLAC__stream_decoder_set_read_callback(fi->fsd, fs_flac_read_callback);
FLAC__stream_decoder_set_write_callback(fi->fsd, fs_flac_write_callback); FLAC__stream_decoder_set_write_callback(fi->fsd, fs_flac_write_callback);
FLAC__stream_decoder_set_metadata_callback(fi->fsd, fs_flac_meta_callback); FLAC__stream_decoder_set_metadata_callback(fi->fsd, fs_flac_meta_callback);
@ -269,21 +260,6 @@ fs_flac_decode_header (FishSound * fsound, unsigned char *buf, long bytes)
if (FLAC__stream_decoder_init(fi->fsd) != FLAC__STREAM_DECODER_SEARCH_FOR_METADATA) if (FLAC__stream_decoder_init(fi->fsd) != FLAC__STREAM_DECODER_SEARCH_FOR_METADATA)
return NULL; return NULL;
#elif defined (HAVE_FLAC_1_1_3)
if (FLAC__stream_decoder_init_stream
(fi->fsd,
fs_flac_read_callback,
NULL, /* seek callback */
NULL, /* tell callback */
NULL, /* length callback */
NULL, /* EOF callback */
fs_flac_write_callback,
fs_flac_meta_callback,
fs_flac_error_callback,
fsound
) != FLAC__STREAM_DECODER_SEARCH_FOR_METADATA)
return NULL;
#endif
return fi->fsd; return fi->fsd;
} }
@ -304,14 +280,12 @@ fs_flac_decode (FishSound * fsound, unsigned char * buf, long bytes)
#endif #endif
return -1; return -1;
} }
if ((fi->buffer = fs_malloc(sizeof(unsigned char)*bytes)) == NULL) fi->buffer = fs_malloc(sizeof(unsigned char)*bytes);
return FISH_SOUND_ERR_OUT_OF_MEMORY;
memcpy(fi->buffer, buf+9, bytes-9); memcpy(fi->buffer, buf+9, bytes-9);
fi->bufferlength = bytes-9; fi->bufferlength = bytes-9;
} }
else if (fi->packetno <= fi->header_packets){ else if (fi->packetno <= fi->header_packets){
unsigned char* tmp; unsigned char* tmp = fs_malloc(sizeof(unsigned char)*(fi->bufferlength+bytes));
#ifdef DEBUG #ifdef DEBUG
printf("fs_flac_decode: handling header (fi->header_packets = %d)\n", printf("fs_flac_decode: handling header (fi->header_packets = %d)\n",
fi->header_packets); fi->header_packets);
@ -326,14 +300,8 @@ fs_flac_decode (FishSound * fsound, unsigned char * buf, long bytes)
#ifdef DEBUG #ifdef DEBUG
printf ("fs_flac_decode: got vorbiscomments len %d\n", len); printf ("fs_flac_decode: got vorbiscomments len %d\n", len);
#endif #endif
if (fish_sound_comments_decode (fsound, buf+4, len) == FISH_SOUND_ERR_OUT_OF_MEMORY) { fish_sound_comments_decode (fsound, buf+4, len);
fi->packetno++;
return FISH_SOUND_ERR_OUT_OF_MEMORY;
} }
}
if ((tmp = fs_malloc(sizeof(unsigned char)*(fi->bufferlength+bytes))) == NULL)
return FISH_SOUND_ERR_OUT_OF_MEMORY;
memcpy(tmp, fi->buffer, fi->bufferlength); memcpy(tmp, fi->buffer, fi->bufferlength);
memcpy(tmp+fi->bufferlength, buf, bytes); memcpy(tmp+fi->bufferlength, buf, bytes);
@ -341,29 +309,17 @@ fs_flac_decode (FishSound * fsound, unsigned char * buf, long bytes)
fs_free(fi->buffer); fs_free(fi->buffer);
fi->buffer = tmp; fi->buffer = tmp;
if (fi->packetno == fi->header_packets) { if (fi->packetno == fi->header_packets) {
if (FLAC__stream_decoder_process_until_end_of_metadata(fi->fsd) == false) { FLAC__stream_decoder_process_until_end_of_metadata(fi->fsd);
goto dec_err;
}
fs_free(fi->buffer); fs_free(fi->buffer);
} }
} else { } else {
fi->buffer = buf; fi->buffer = buf;
fi->bufferlength = bytes; fi->bufferlength = bytes;
if (FLAC__stream_decoder_process_single(fi->fsd) == false) { FLAC__stream_decoder_process_single(fi->fsd);
goto dec_err;
}
} }
fi->packetno++; fi->packetno++;
return 0; return 0;
dec_err:
switch (FLAC__stream_decoder_get_state(fi->fsd)) {
case FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR:
return FISH_SOUND_ERR_OUT_OF_MEMORY;
default:
return FISH_SOUND_ERR_GENERIC;
}
} }
#else /* !FS_DECODE */ #else /* !FS_DECODE */
@ -397,9 +353,7 @@ fs_flac_enc_write_callback(const FLAC__StreamEncoder *encoder,
printf("fs_flac_enc_write_callback: generating FLAC header packet: " printf("fs_flac_enc_write_callback: generating FLAC header packet: "
"%c%c%c%c\n", buffer[0], buffer[1], buffer[2], buffer[3]); "%c%c%c%c\n", buffer[0], buffer[1], buffer[2], buffer[3]);
#endif #endif
if ((fi->buffer = (unsigned char*)fs_malloc(sizeof(unsigned char)*(bytes+9))) == NULL) fi->buffer = (unsigned char*)malloc(sizeof(unsigned char)*(bytes+9));
return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
fi->buffer[0] = 0x7f; fi->buffer[0] = 0x7f;
fi->buffer[1] = 0x46; /* 'F' */ fi->buffer[1] = 0x46; /* 'F' */
fi->buffer[2] = 0x4c; /* 'L' */ fi->buffer[2] = 0x4c; /* 'L' */
@ -417,11 +371,7 @@ fs_flac_enc_write_callback(const FLAC__StreamEncoder *encoder,
/* Make a temporary copy of the metadata header to pass to the user /* Make a temporary copy of the metadata header to pass to the user
* callback. * callback.
*/ */
unsigned char* tmp; unsigned char* tmp = (unsigned char*)malloc(sizeof(unsigned char)*(bytes+fi->bufferlength));
if ((tmp = (unsigned char*)fs_malloc(sizeof(unsigned char)*(bytes+fi->bufferlength))) == NULL)
return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
memcpy (tmp, fi->buffer, fi->bufferlength); memcpy (tmp, fi->buffer, fi->bufferlength);
memcpy (tmp+fi->bufferlength, buffer, bytes); memcpy (tmp+fi->bufferlength, buffer, bytes);
fs_free(fi->buffer); fs_free(fi->buffer);
@ -512,8 +462,7 @@ fs_flac_encode_vcentry (const FishSoundComment * comment)
length += value_len + 1; length += value_len + 1;
} }
if ((entry = fs_malloc (length)) == NULL) entry = fs_malloc (length);
return NULL;
/* We assume that comment->name, value are NUL terminated, as they were /* We assume that comment->name, value are NUL terminated, as they were
* produced by our own comments.c */ * produced by our own comments.c */
@ -533,7 +482,7 @@ static FLAC__StreamMetadata *
fs_flac_encode_vorbiscomments (FishSound * fsound) fs_flac_encode_vorbiscomments (FishSound * fsound)
{ {
FishSoundFlacInfo * fi = fsound->codec_data; FishSoundFlacInfo * fi = fsound->codec_data;
FLAC__StreamMetadata * metadata = NULL; FLAC__StreamMetadata * metadata;
const FishSoundComment * comment; const FishSoundComment * comment;
unsigned int i=0, length=0, total_length; unsigned int i=0, length=0, total_length;
FLAC__VCEntry * comments; FLAC__VCEntry * comments;
@ -553,13 +502,11 @@ fs_flac_encode_vorbiscomments (FishSound * fsound)
if (length == 0) return NULL; if (length == 0) return NULL;
if ((comments = (FLAC__VCEntry *)fs_malloc (sizeof(FLAC__VCEntry) * length)) == NULL) comments = (FLAC__VCEntry *)fs_malloc (sizeof(FLAC__VCEntry) * length);
goto encode_vc_oom;
for (comment = fish_sound_comment_first (fsound); comment; for (comment = fish_sound_comment_first (fsound); comment;
comment = fish_sound_comment_next (fsound, comment)) { comment = fish_sound_comment_next (fsound, comment)) {
if ((comments[i].entry = fs_flac_encode_vcentry (comment)) == NULL) { comments[i].entry = fs_flac_encode_vcentry (comment);
}
comments[i].length = strlen((char *)comments[i].entry); comments[i].length = strlen((char *)comments[i].entry);
/* In the generated vorbiscomment data, each entry is preceded by a /* In the generated vorbiscomment data, each entry is preceded by a
@ -568,9 +515,7 @@ fs_flac_encode_vorbiscomments (FishSound * fsound)
i++; i++;
} }
if ((metadata = (FLAC__StreamMetadata *) fs_malloc (sizeof (*metadata))) == NULL) metadata = (FLAC__StreamMetadata *) fs_malloc (sizeof (*metadata));
goto encode_vc_oom;
metadata->type = FLAC__METADATA_TYPE_VORBIS_COMMENT; metadata->type = FLAC__METADATA_TYPE_VORBIS_COMMENT;
metadata->is_last = true; metadata->is_last = true;
metadata->length = total_length; metadata->length = total_length;
@ -582,21 +527,6 @@ fs_flac_encode_vorbiscomments (FishSound * fsound)
fi->enc_vc_metadata = metadata; fi->enc_vc_metadata = metadata;
return metadata; return metadata;
encode_vc_oom:
if (metadata != NULL)
fs_free (metadata);
/* Unwind allocated comment entries */
for (i--; i >= 0; i--) {
if (comments[i].entry != NULL)
fs_free (comments[i].entry);
}
if (comments != NULL)
fs_free (comments);
return NULL;
} }
static FishSound * static FishSound *
@ -609,51 +539,26 @@ fs_flac_enc_headers (FishSound * fsound)
FLAC__stream_encoder_set_channels(fi->fse, fsound->info.channels); FLAC__stream_encoder_set_channels(fi->fse, fsound->info.channels);
FLAC__stream_encoder_set_sample_rate(fi->fse, fsound->info.samplerate); FLAC__stream_encoder_set_sample_rate(fi->fse, fsound->info.samplerate);
FLAC__stream_encoder_set_bits_per_sample(fi->fse, BITS_PER_SAMPLE); FLAC__stream_encoder_set_bits_per_sample(fi->fse, BITS_PER_SAMPLE);
#if defined (HAVE_FLAC_1_1_2)
FLAC__stream_encoder_set_write_callback(fi->fse, fs_flac_enc_write_callback); FLAC__stream_encoder_set_write_callback(fi->fse, fs_flac_enc_write_callback);
FLAC__stream_encoder_set_metadata_callback(fi->fse, fs_flac_enc_meta_callback); FLAC__stream_encoder_set_metadata_callback(fi->fse, fs_flac_enc_meta_callback);
FLAC__stream_encoder_set_client_data(fi->fse, fsound); FLAC__stream_encoder_set_client_data(fi->fse, fsound);
#endif
metadata = fs_flac_encode_vorbiscomments (fsound); metadata = fs_flac_encode_vorbiscomments (fsound);
if (metadata != NULL) if (metadata != NULL)
FLAC__stream_encoder_set_metadata (fi->fse, &metadata, 1); FLAC__stream_encoder_set_metadata (fi->fse, &metadata, 1);
/* FLAC__stream_encoder_set_total_samples_estimate(fi->fse, ...);*/ /* FLAC__stream_encoder_set_total_samples_estimate(fi->fse, ...);*/
#if defined (HAVE_FLAC_1_1_2)
if (FLAC__stream_encoder_init(fi->fse) != FLAC__STREAM_ENCODER_OK) if (FLAC__stream_encoder_init(fi->fse) != FLAC__STREAM_ENCODER_OK)
return NULL; return NULL;
#elif defined (HAVE_FLAC_1_1_3)
if (FLAC__stream_encoder_init_stream
(fi->fse,
fs_flac_enc_write_callback,
NULL, /* seek callback */
NULL, /* tell callback */
fs_flac_enc_meta_callback,
fsound
) != FLAC__STREAM_ENCODER_OK)
return NULL;
#endif
return fsound; return fsound;
} }
static long
fs_flac_encode_fatal (FishSoundFlacInfo *fi, long err)
{
FLAC__stream_encoder_delete (fi->fse);
fi->fse = NULL;
return err;
}
static long static long
fs_flac_encode_f (FishSound * fsound, float * pcm[], long frames) fs_flac_encode_f (FishSound * fsound, float * pcm[], long frames)
{ {
FishSoundFlacInfo *fi = fsound->codec_data; FishSoundFlacInfo *fi = fsound->codec_data;
FLAC__int32 *buffer, *ipcm; FLAC__int32 *buffer;
float * p, norm = (1 << (BITS_PER_SAMPLE - 1)); float * p, norm = (1 << (BITS_PER_SAMPLE - 1));
long i; long i;
int j, channels = fsound->info.channels; int j, channels = fsound->info.channels;
@ -662,10 +567,7 @@ fs_flac_encode_f (FishSound * fsound, float * pcm[], long frames)
printf("fs_flac_encode_f: IN, frames = %ld\n", frames); printf("fs_flac_encode_f: IN, frames = %ld\n", frames);
#endif #endif
if ((ipcm = realloc(fi->ipcm, sizeof(FLAC__int32) * channels * frames)) == NULL) fi->ipcm = realloc(fi->ipcm, sizeof(FLAC__int32) * channels * frames);
return FISH_SOUND_ERR_OUT_OF_MEMORY;
fi->ipcm = ipcm;
buffer = (FLAC__int32*) fi->ipcm; buffer = (FLAC__int32*) fi->ipcm;
for (i = 0; i < frames; i++) { for (i = 0; i < frames; i++) {
for (j = 0; j < channels; j++) { for (j = 0; j < channels; j++) {
@ -679,17 +581,7 @@ fs_flac_encode_f (FishSound * fsound, float * pcm[], long frames)
/* We could have used FLAC__stream_encoder_process() and a more direct /* We could have used FLAC__stream_encoder_process() and a more direct
* conversion loop above, rather than converting and interleaving. */ * conversion loop above, rather than converting and interleaving. */
if (FLAC__stream_encoder_process_interleaved(fi->fse, buffer, frames) == false) { FLAC__stream_encoder_process_interleaved(fi->fse, buffer, frames);
switch (FLAC__stream_encoder_get_state (fi->fse)) {
case FLAC__STREAM_ENCODER_OK:
case FLAC__STREAM_ENCODER_UNINITIALIZED:
break;
case FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR:
return fs_flac_encode_fatal (fi, FISH_SOUND_ERR_OUT_OF_MEMORY);
default:
return fs_flac_encode_fatal (fi, FISH_SOUND_ERR_GENERIC);
}
}
fi->packetno++; fi->packetno++;
@ -700,7 +592,7 @@ static long
fs_flac_encode_f_ilv (FishSound * fsound, float ** pcm, long frames) fs_flac_encode_f_ilv (FishSound * fsound, float ** pcm, long frames)
{ {
FishSoundFlacInfo *fi = fsound->codec_data; FishSoundFlacInfo *fi = fsound->codec_data;
FLAC__int32 *buffer, *ipcm; FLAC__int32 *buffer;
float * p = (float*)pcm, norm = (1 << (BITS_PER_SAMPLE - 1)); float * p = (float*)pcm, norm = (1 << (BITS_PER_SAMPLE - 1));
long i, length = frames * fsound->info.channels; long i, length = frames * fsound->info.channels;
@ -708,10 +600,7 @@ fs_flac_encode_f_ilv (FishSound * fsound, float ** pcm, long frames)
printf("fs_flac_encode_f_ilv: IN, frames = %ld\n", frames); printf("fs_flac_encode_f_ilv: IN, frames = %ld\n", frames);
#endif #endif
if ((ipcm = realloc(fi->ipcm, sizeof(FLAC__int32)*fsound->info.channels*frames)) == NULL) fi->ipcm = realloc(fi->ipcm, sizeof(FLAC__int32)*fsound->info.channels*frames);
return FISH_SOUND_ERR_OUT_OF_MEMORY;
fi->ipcm = ipcm;
buffer = (FLAC__int32*) fi->ipcm; buffer = (FLAC__int32*) fi->ipcm;
for (i=0; i<length; i++) for (i=0; i<length; i++)
buffer[i] = p[i] * norm; buffer[i] = p[i] * norm;
@ -719,17 +608,7 @@ fs_flac_encode_f_ilv (FishSound * fsound, float ** pcm, long frames)
if (fi->packetno == 0) if (fi->packetno == 0)
fs_flac_enc_headers (fsound); fs_flac_enc_headers (fsound);
if (FLAC__stream_encoder_process_interleaved(fi->fse, buffer, frames) == false) { FLAC__stream_encoder_process_interleaved(fi->fse, buffer, frames);
switch (FLAC__stream_encoder_get_state (fi->fse)) {
case FLAC__STREAM_ENCODER_OK:
case FLAC__STREAM_ENCODER_UNINITIALIZED:
break;
case FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR:
return fs_flac_encode_fatal (fi, FISH_SOUND_ERR_OUT_OF_MEMORY);
default:
return fs_flac_encode_fatal (fi, FISH_SOUND_ERR_GENERIC);
}
}
fi->packetno++; fi->packetno++;
@ -859,7 +738,6 @@ fish_sound_flac_codec (void)
FishSoundCodec * codec; FishSoundCodec * codec;
codec = (FishSoundCodec *) fs_malloc (sizeof (FishSoundCodec)); codec = (FishSoundCodec *) fs_malloc (sizeof (FishSoundCodec));
if (codec == NULL) return NULL;
codec->format.format = FISH_SOUND_FLAC; codec->format.format = FISH_SOUND_FLAC;
codec->format.name = "Flac (Xiph.Org)"; codec->format.name = "Flac (Xiph.Org)";

View File

@ -36,10 +36,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#if HAVE_STDINT_H
#include <stdint.h>
#endif
#include <ctype.h> #include <ctype.h>
#include "private.h" #include "private.h"
@ -136,46 +132,59 @@ process_header(unsigned char * buf, long bytes, int enh_enabled,
header = speex_packet_to_header((char*)buf, (int)bytes); header = speex_packet_to_header((char*)buf, (int)bytes);
if (!header) { if (!header) {
/* cannot read header */ /*info_dialog_new ("Speex error", NULL, "Speex: cannot read header");*/
return NULL; return NULL;
} }
if (header->mode >= SPEEX_NB_MODES || header->mode < 0) { if (header->mode >= SPEEX_NB_MODES || header->mode < 0) {
/* Mode number does not (any longer) exist in this version */ /*
info_dialog_new ("Speex error", NULL,
"Mode number %d does not (any longer) exist in this version\n",
header->mode);
*/
return NULL; return NULL;
} }
modeID = header->mode; modeID = header->mode;
if (forceMode!=-1) if (forceMode!=-1)
modeID = forceMode; modeID = forceMode;
#if HAVE_SPEEX_LIB_GET_MODE
mode = (SpeexMode *) speex_lib_get_mode (modeID);
#else
/* speex_mode_list[] is declared const in speex 1.1.x, hence the cast */ /* speex_mode_list[] is declared const in speex 1.1.x, hence the cast */
mode = (SpeexMode *)speex_mode_list[modeID]; mode = (SpeexMode *)speex_mode_list[modeID];
#endif
if (header->speex_version_id > 1) { if (header->speex_version_id > 1) {
/* Unknown bitstream version */ /*
info_dialog_new ("Speex error", NULL,
"This file was encoded with Speex bit-stream version %d, "
"which I don't know how to decode\n",
header->speex_version_id);
*/
return NULL; return NULL;
} }
if (mode->bitstream_version < header->mode_bitstream_version) { if (mode->bitstream_version < header->mode_bitstream_version) {
/* The file was encoded with a newer version of Speex, /*
* need to upgrade in order to play it */ info_dialog_new ("Speex error", NULL,
"The file was encoded with a newer version of Speex. "
"You need to upgrade in order to play it.\n");
*/
return NULL; return NULL;
} }
if (mode->bitstream_version > header->mode_bitstream_version) { if (mode->bitstream_version > header->mode_bitstream_version) {
/* The file was encoded with an older version of Speex. /*
* You would need to downgrade the version in order to play it */ info_dialog_new ("Speex error", NULL,
"The file was encoded with an older version of Speex. "
"You would need to downgrade the version in order to play it.\n");
*/
return NULL; return NULL;
} }
st = speex_decoder_init(mode); st = speex_decoder_init(mode);
if (!st) { if (!st) {
/* Decoder initialization failed */ /*
info_dialog_new ("Speex error", NULL,
"Decoder initialization failed.\n");
*/
return NULL; return NULL;
} }
@ -283,8 +292,7 @@ fs_speex_decode (FishSound * fsound, unsigned char * buf, long bytes)
&fss->extra_headers); &fss->extra_headers);
if (fss->st == NULL) { if (fss->st == NULL) {
/* TODO: Return more specific error identifiers for invalid header fields */ /* XXX: error */
return FISH_SOUND_ERR_GENERIC;
} }
#ifdef DEBUG #ifdef DEBUG
@ -294,50 +302,20 @@ fs_speex_decode (FishSound * fsound, unsigned char * buf, long bytes)
fsound->info.samplerate = rate; fsound->info.samplerate = rate;
fsound->info.channels = channels; fsound->info.channels = channels;
/* Sanity check the channels value, as we will use it to determine buffer
sizes below.
*/
if (channels < 1 || channels > 2)
return FISH_SOUND_ERR_GENERIC;
#if HAVE_UINTPTR_T
/* Sanity check: frame_size is not so large that the buffer size calculations
* would wrap. In reality, frame_size is set by libspeex according to the
* mode index specified in the file header, and is usually equal to 320.
*/
if (fss->frame_size > UINTPTR_MAX / (sizeof(float) * channels))
return FISH_SOUND_ERR_GENERIC;
#endif
fss->ipcm = fs_malloc (sizeof (float) * fss->frame_size * channels); fss->ipcm = fs_malloc (sizeof (float) * fss->frame_size * channels);
if (fss->ipcm == NULL) {
return FISH_SOUND_ERR_OUT_OF_MEMORY;
}
if (channels == 1) { if (channels == 1) {
fss->pcm[0] = fss->ipcm; fss->pcm[0] = fss->ipcm;
} else if (channels == 2) { } else if (channels == 2) {
fss->pcm[0] = fs_malloc (sizeof (float) * fss->frame_size); fss->pcm[0] = fs_malloc (sizeof (float) * fss->frame_size);
if (fss->pcm[0] == NULL) {
fs_free (fss->ipcm);
return FISH_SOUND_ERR_OUT_OF_MEMORY;
}
fss->pcm[1] = fs_malloc (sizeof (float) * fss->frame_size); fss->pcm[1] = fs_malloc (sizeof (float) * fss->frame_size);
if (fss->pcm[1] == NULL) {
fs_free (fss->pcm[0]);
fs_free (fss->ipcm);
return FISH_SOUND_ERR_OUT_OF_MEMORY;
}
} }
if (fss->nframes == 0) fss->nframes = 1; if (fss->nframes == 0) fss->nframes = 1;
} else if (fss->packetno == 1) { } else if (fss->packetno == 1) {
/* Comments */ /* Comments */
if (fish_sound_comments_decode (fsound, buf, bytes) == FISH_SOUND_ERR_OUT_OF_MEMORY) { fish_sound_comments_decode (fsound, buf, bytes);
fss->packetno++;
return FISH_SOUND_ERR_OUT_OF_MEMORY;
}
} else if (fss->packetno <= 1+fss->extra_headers) { } else if (fss->packetno <= 1+fss->extra_headers) {
/* Unknown extra headers */ /* Unknown extra headers */
} else { } else {
@ -385,21 +363,15 @@ static FishSound *
fs_speex_enc_headers (FishSound * fsound) fs_speex_enc_headers (FishSound * fsound)
{ {
FishSoundSpeexInfo * fss = (FishSoundSpeexInfo *)fsound->codec_data; FishSoundSpeexInfo * fss = (FishSoundSpeexInfo *)fsound->codec_data;
int modeID;
SpeexMode * mode = NULL; SpeexMode * mode = NULL;
SpeexHeader header; SpeexHeader header;
unsigned char * header_buf = NULL, * comments_buf = NULL; unsigned char * buf;
int header_bytes, comments_bytes; int bytes;
size_t buflen; size_t buflen;
modeID = 1; /* XXX: set wb, nb, uwb modes */
/* These modes are declared const in speex 1.1.x, hence the explicit cast */
#if HAVE_SPEEX_LIB_GET_MODE mode = (SpeexMode *)&speex_wb_mode;
mode = (SpeexMode *) speex_lib_get_mode (modeID);
#else
/* speex_mode_list[] is declared const in speex 1.1.x, hence the cast */
mode = (SpeexMode *)speex_mode_list[modeID];
#endif
speex_init_header (&header, fsound->info.samplerate, 1, mode); speex_init_header (&header, fsound->info.samplerate, 1, mode);
header.frames_per_packet = fss->nframes; /* XXX: frames per packet */ header.frames_per_packet = fss->nframes; /* XXX: frames per packet */
@ -409,26 +381,24 @@ fs_speex_enc_headers (FishSound * fsound)
fss->st = speex_encoder_init (mode); fss->st = speex_encoder_init (mode);
if (fsound->callback.encoded) { if (fsound->callback.encoded) {
FishSoundEncoded encoded = (FishSoundEncoded)fsound->callback.encoded;
char vendor_string[128]; char vendor_string[128];
/* Allocate and create header */ /* header */
header_buf = (unsigned char *) speex_header_to_packet (&header, &header_bytes); buf = (unsigned char *) speex_header_to_packet (&header, &bytes);
if (header_buf == NULL) { encoded (fsound, buf, (long)bytes, fsound->user_data);
return NULL; fss->packetno++;
} fs_free (buf);
/* Allocate and create comments */ /* comments */
snprintf (vendor_string, 128, VENDOR_FORMAT, header.speex_version); snprintf (vendor_string, 128, VENDOR_FORMAT, header.speex_version);
if (fish_sound_comment_set_vendor (fsound, vendor_string) == FISH_SOUND_ERR_OUT_OF_MEMORY) { fish_sound_comment_set_vendor (fsound, vendor_string);
fs_free (header_buf); bytes = fish_sound_comments_encode (fsound, NULL, 0);
return NULL; buf = fs_malloc (bytes);
} bytes = fish_sound_comments_encode (fsound, buf, bytes);
comments_bytes = fish_sound_comments_encode (fsound, NULL, 0); encoded (fsound, buf, (long)bytes, fsound->user_data);
comments_buf = fs_malloc (comments_bytes); fss->packetno++;
if (comments_buf == NULL) { fs_free (buf);
fs_free (header_buf);
return NULL;
}
} }
speex_encoder_ctl (fss->st, SPEEX_SET_SAMPLING_RATE, speex_encoder_ctl (fss->st, SPEEX_SET_SAMPLING_RATE,
@ -440,33 +410,12 @@ fs_speex_enc_headers (FishSound * fsound)
printf ("got frame size %d\n", fss->frame_size); printf ("got frame size %d\n", fss->frame_size);
#endif #endif
/* XXX: set VBR etc. */ /* XXX: blah blah blah ... set VBR etc. */
buflen = fss->frame_size * fsound->info.channels * sizeof (float); buflen = fss->frame_size * fsound->info.channels * sizeof (float);
fss->ipcm = fs_malloc (buflen); fss->ipcm = fs_malloc (buflen);
if (fss->ipcm == NULL) {
if (comments_buf) fs_free (comments_buf);
if (header_buf) fs_free (header_buf);
return NULL;
}
memset (fss->ipcm, 0, buflen); memset (fss->ipcm, 0, buflen);
/* Allocations succeeded, actually call encoded callback for headers */
if (fsound->callback.encoded) {
FishSoundEncoded encoded = (FishSoundEncoded)fsound->callback.encoded;
/* header */
encoded (fsound, header_buf, (long)header_bytes, fsound->user_data);
fss->packetno++;
fs_free (header_buf);
/* comments */
comments_bytes = fish_sound_comments_encode (fsound, comments_buf, comments_bytes);
encoded (fsound, comments_buf, (long)comments_bytes, fsound->user_data);
fss->packetno++;
fs_free (comments_buf);
}
return fsound; return fsound;
} }
@ -644,13 +593,10 @@ fs_speex_update (FishSound * fsound, int interleave)
{ {
FishSoundSpeexInfo * fss = (FishSoundSpeexInfo *)fsound->codec_data; FishSoundSpeexInfo * fss = (FishSoundSpeexInfo *)fsound->codec_data;
size_t pcm_size = sizeof (float); size_t pcm_size = sizeof (float);
float *ipcm_new, *pcm0, *pcm1;
ipcm_new = (float *)fs_realloc (fss->ipcm, fss->ipcm = (float *)
fs_realloc (fss->ipcm,
pcm_size * fss->frame_size * fsound->info.channels); pcm_size * fss->frame_size * fsound->info.channels);
if (ipcm_new == NULL) return FISH_SOUND_ERR_OUT_OF_MEMORY;
fss->ipcm = ipcm_new;
if (interleave) { if (interleave) {
/* if transitioning from non-interleave to interleave, /* if transitioning from non-interleave to interleave,
@ -665,28 +611,8 @@ fs_speex_update (FishSound * fsound, int interleave)
if (fsound->info.channels == 1) { if (fsound->info.channels == 1) {
fss->pcm[0] = (float *) fss->ipcm; fss->pcm[0] = (float *) fss->ipcm;
} else if (fsound->info.channels == 2) { } else if (fsound->info.channels == 2) {
#if HAVE_UINTPTR_T fss->pcm[0] = fs_realloc (fss->pcm[0], pcm_size * fss->frame_size);
/* Sanity check: frame_size is not so large that the buffer size calculations fss->pcm[1] = fs_realloc (fss->pcm[1], pcm_size * fss->frame_size);
* would wrap. In reality, frame_size is set by libspeex according to the
* mode index specified in the file header, and is usually equal to 320.
*/
if (fss->frame_size > UINTPTR_MAX / pcm_size)
return FISH_SOUND_ERR_GENERIC;
#endif
pcm0 = fs_realloc (fss->pcm[0], pcm_size * fss->frame_size);
if (pcm0 == NULL) {
return FISH_SOUND_ERR_OUT_OF_MEMORY;
}
pcm1 = fs_realloc (fss->pcm[1], pcm_size * fss->frame_size);
if (pcm1 == NULL) {
fs_free (pcm0);
return FISH_SOUND_ERR_OUT_OF_MEMORY;
}
fss->pcm[0] = pcm0;
fss->pcm[1] = pcm1;
} }
} }
@ -768,7 +694,6 @@ fish_sound_speex_codec (void)
FishSoundCodec * codec; FishSoundCodec * codec;
codec = (FishSoundCodec *) fs_malloc (sizeof (FishSoundCodec)); codec = (FishSoundCodec *) fs_malloc (sizeof (FishSoundCodec));
if (codec == NULL) return NULL;
codec->format.format = FISH_SOUND_SPEEX; codec->format.format = FISH_SOUND_SPEEX;
codec->format.name = "Speex (Xiph.Org)"; codec->format.name = "Speex (Xiph.Org)";

View File

@ -115,7 +115,6 @@ fs_vorbis_decode (FishSound * fsound, unsigned char * buf, long bytes)
FishSoundVorbisInfo * fsv = (FishSoundVorbisInfo *)fsound->codec_data; FishSoundVorbisInfo * fsv = (FishSoundVorbisInfo *)fsound->codec_data;
ogg_packet op; ogg_packet op;
long samples; long samples;
float * pcm_new;
int ret; int ret;
/* Make an ogg_packet structure to pass the data to libvorbis */ /* Make an ogg_packet structure to pass the data to libvorbis */
@ -143,10 +142,7 @@ fs_vorbis_decode (FishSound * fsound, unsigned char * buf, long bytes)
* start of vorbiscomment packet. */ * start of vorbiscomment packet. */
if (fsv->packetno == 1 && bytes > 7 && buf[0] == 0x03 && if (fsv->packetno == 1 && bytes > 7 && buf[0] == 0x03 &&
!strncmp ((char *)&buf[1], "vorbis", 6)) { !strncmp ((char *)&buf[1], "vorbis", 6)) {
if (fish_sound_comments_decode (fsound, buf+7, bytes-7) == FISH_SOUND_ERR_OUT_OF_MEMORY) { fish_sound_comments_decode (fsound, buf+7, bytes-7);
fsv->packetno++;
return FISH_SOUND_ERR_OUT_OF_MEMORY;
}
} else if (fsv->packetno == 2) { } else if (fsv->packetno == 2) {
vorbis_synthesis_init (&fsv->vd, &fsv->vi); vorbis_synthesis_init (&fsv->vd, &fsv->vi);
vorbis_block_init (&fsv->vd, &fsv->vb); vorbis_block_init (&fsv->vd, &fsv->vb);
@ -166,16 +162,10 @@ fs_vorbis_decode (FishSound * fsound, unsigned char * buf, long bytes)
if (fsound->interleave) { if (fsound->interleave) {
if (samples > fsv->max_pcm) { if (samples > fsv->max_pcm) {
pcm_new = realloc (fsv->ipcm, sizeof(float) * samples * fsv->ipcm = realloc (fsv->ipcm, sizeof(float) * samples *
fsound->info.channels); fsound->info.channels);
if (pcm_new == NULL) {
/* Allocation failure; just truncate here, fail gracefully elsewhere */
samples = fsv->max_pcm;
} else {
fsv->ipcm = pcm_new;
fsv->max_pcm = samples; fsv->max_pcm = samples;
} }
}
_fs_interleave (fsv->pcm, (float **)fsv->ipcm, samples, _fs_interleave (fsv->pcm, (float **)fsv->ipcm, samples,
fsound->info.channels, 1.0); fsound->info.channels, 1.0);
@ -214,14 +204,12 @@ fs_vorbis_enc_headers (FishSound * fsound)
ogg_packet header_comm; ogg_packet header_comm;
ogg_packet header_code; ogg_packet header_code;
/* Vorbis streams begin with three headers: /* Vorbis streams begin with three headers; the initial header (with
* 1. The initial header (with most of the codec setup parameters), most of the codec setup parameters) which is mandated by the Ogg
* which is mandated by the Ogg bitstream spec, bitstream spec. The second header holds any comment fields. The
* 2. The second header which holds any comment fields, third header holds the bitstream codebook. We merely need to
* 3. The third header which contains the bitstream codebook. make the headers, then pass them to libvorbis one at a time;
* We merely need to make the headers, then pass them to libvorbis one at libvorbis handles the additional Ogg bitstream constraints */
* a time; libvorbis handles the additional Ogg bitstream constraints.
*/
/* Update the comments */ /* Update the comments */
for (comment = fish_sound_comment_first (fsound); comment; for (comment = fish_sound_comment_first (fsound); comment;
@ -345,6 +333,7 @@ fs_vorbis_encode_f (FishSound * fsound, float * pcm[], long frames)
float ** vpcm; float ** vpcm;
long len, remaining = frames; long len, remaining = frames;
int i; int i;
float ** ppcm = alloca (sizeof (float *) * fsound->info.channels);
if (fsv->packetno == 0) { if (fsv->packetno == 0) {
fs_vorbis_enc_headers (fsound); fs_vorbis_enc_headers (fsound);
@ -355,6 +344,10 @@ fs_vorbis_encode_f (FishSound * fsound, float * pcm[], long frames)
return 0; return 0;
} }
for (i = 0; i < fsound->info.channels; i++) {
ppcm[i] = pcm[i];
}
while (remaining > 0) { while (remaining > 0) {
len = MIN (1024, remaining); len = MIN (1024, remaining);
@ -366,7 +359,7 @@ fs_vorbis_encode_f (FishSound * fsound, float * pcm[], long frames)
vpcm = vorbis_analysis_buffer (&fsv->vd, 1024); vpcm = vorbis_analysis_buffer (&fsv->vd, 1024);
for (i = 0; i < fsound->info.channels; i++) { for (i = 0; i < fsound->info.channels; i++) {
memcpy (vpcm[i], pcm[i], sizeof (float) * len); memcpy (vpcm[i], ppcm[i], sizeof (float) * len);
} }
fs_vorbis_encode_write (fsound, len); fs_vorbis_encode_write (fsound, len);
@ -435,7 +428,7 @@ fs_vorbis_init (FishSound * fsound)
fsv->finished = 0; fsv->finished = 0;
vorbis_info_init (&fsv->vi); vorbis_info_init (&fsv->vi);
vorbis_comment_init (&fsv->vc); vorbis_comment_init (&fsv->vc);
memset(&fsv->vd, 0, sizeof(fsv->vd)); vorbis_dsp_init (&fsv->vd);
vorbis_block_init (&fsv->vd, &fsv->vb); vorbis_block_init (&fsv->vd, &fsv->vb);
fsv->pcm = NULL; fsv->pcm = NULL;
fsv->ipcm = NULL; fsv->ipcm = NULL;
@ -482,7 +475,6 @@ fish_sound_vorbis_codec (void)
FishSoundCodec * codec; FishSoundCodec * codec;
codec = (FishSoundCodec *) fs_malloc (sizeof (FishSoundCodec)); codec = (FishSoundCodec *) fs_malloc (sizeof (FishSoundCodec));
if (codec == NULL) return NULL;
codec->format.format = FISH_SOUND_VORBIS; codec->format.format = FISH_SOUND_VORBIS;
codec->format.name = "Vorbis (Xiph.Org)"; codec->format.name = "Vorbis (Xiph.Org)";

View File

@ -58,7 +58,6 @@ fs_vector_new (FishSoundCmpFunc cmp)
FishSoundVector * vector; FishSoundVector * vector;
vector = fs_malloc (sizeof (FishSoundVector)); vector = fs_malloc (sizeof (FishSoundVector));
if (vector == NULL) return NULL;
vector->max_elements = 0; vector->max_elements = 0;
vector->nr_elements = 0; vector->nr_elements = 0;
@ -177,8 +176,6 @@ fs_vector_grow (FishSoundVector * vector)
void * void *
fs_vector_insert (FishSoundVector * vector, void * data) fs_vector_insert (FishSoundVector * vector, void * data)
{ {
if (vector == NULL) return NULL;
if (fs_vector_grow (vector) == NULL) if (fs_vector_grow (vector) == NULL)
return NULL; return NULL;

View File

@ -38,4 +38,5 @@ cp $1/src/libfishsound/fs_vector.h ./src/libfishsound/fs_vector.h
cp $1/src/libfishsound/fs_vector.c ./src/libfishsound/fs_vector.c cp $1/src/libfishsound/fs_vector.c ./src/libfishsound/fs_vector.c
cp $1/src/libfishsound/convert.h ./src/libfishsound/convert.h cp $1/src/libfishsound/convert.h ./src/libfishsound/convert.h
cp $1/AUTHORS ./AUTHORS cp $1/AUTHORS ./AUTHORS
patch -p3 <endian.patch patch -p4 <endian.patch
patch -p3 <bug481601.patch

View File

@ -104,41 +104,36 @@ and mux and demux examples can be read online at:
http://www.annodex.net/software/liboggz/html/ http://www.annodex.net/software/liboggz/html/
oggz tool Tools
--------- -----
Usage: oggz <subcommand> [options] filename ... The Oggz source tarball also contains the following command-line tools,
which are useful for debugging and testing Ogg bitstreams:
oggz is a commandline tool for manipulating Ogg files. It supports * oggz-chop: Extract the part of an Ogg file between given start
multiplexed files conformant with RFC3533. Oggz can parse headers for and/or end times.
CELT, CMML, FLAC, Kate, PCM, Speex, Theora and Vorbis, and can read and write
Ogg Skeleton logical bitstreams.
Commands: * oggz-comment: List or edit comments in an Ogg file.
help Display help for a specific subcommand (eg. "oggz help chop")
Reporting: * oggz-diff: Hexdump the packets of two Ogg files and output
diff Hexdump the packets of two Ogg files and output differences. differences.
dump Hexdump packets of an Ogg file, or revert an Ogg file from
such a hexdump.
info Display information about one or more Ogg files and their
bitstreams.
scan Scan an Ogg file and output characteristic landmarks.
validate Validate the Ogg framing of one or more files.
Extraction: * oggz-dump: Hexdump packets of an Ogg file, or revert an Ogg file
rip Extract one or more logical bitstreams from an Ogg file. from such a hexdump.
Editing: * oggz-info: Display information about one or more Ogg files and
chop Extract the part of an Ogg file between given start and/or their bitstreams.
end times.
comment List or edit comments in an Ogg file.
merge Merge Ogg files together, interleaving pages in order of
presentation time.
sort Sort the pages of an Ogg file in order of presentation time.
Miscellaneous: * oggz-merge: Merge Ogg files together, interleaving pages in order
known-codecs List codecs known by this version of oggz of presentation time.
* oggz-rip: Extract one or more logical bitstreams from an Ogg file.
* oggz-scan: Scan an Ogg file and output characteristic landmarks.
* oggz-sort: Sort the pages of an Ogg file in order of presentation time.
* oggz-validate: Validate the Ogg framing of one or more files.
The script bash-completion/oggz enables completion of tool options and codec The script bash-completion/oggz enables completion of tool options and codec
names when using the bash shell. Source it from your .profile, or install it names when using the bash shell. Source it from your .profile, or install it

View File

@ -4,7 +4,7 @@ were those applied by update.sh, which applies patches described
below, and the addition/upate of Makefile.in files for the below, and the addition/upate of Makefile.in files for the
Mozilla build system. Mozilla build system.
The svn revision number used was r3902. The svn revision number used was r3867.
The wince.patch addresses the lack of posix file IO support on windows ce, The wince.patch addresses the lack of posix file IO support on windows ce,
see bug 461844 for details. see bug 461844 for details.

View File

@ -158,7 +158,6 @@ int oggz_set_read_page (OGGZ * oggz, long serialno,
* returning OGGZ_STOP_OK * returning OGGZ_STOP_OK
* \retval OGGZ_ERR_STOP_ERR Reading was stopped by a user callback * \retval OGGZ_ERR_STOP_ERR Reading was stopped by a user callback
* returning OGGZ_STOP_ERR * returning OGGZ_STOP_ERR
* \retval OGGZ_ERR_HOLE_IN_DATA Hole (sequence number gap) detected in input data
* \retval OGGZ_ERR_OUT_OF_MEMORY Out of memory * \retval OGGZ_ERR_OUT_OF_MEMORY Out of memory
*/ */
long oggz_read (OGGZ * oggz, long n); long oggz_read (OGGZ * oggz, long n);
@ -175,8 +174,6 @@ long oggz_read (OGGZ * oggz, long n);
* returning OGGZ_STOP_OK * returning OGGZ_STOP_OK
* \retval OGGZ_ERR_STOP_ERR Reading was stopped by a user callback * \retval OGGZ_ERR_STOP_ERR Reading was stopped by a user callback
* returning OGGZ_STOP_ERR * returning OGGZ_STOP_ERR
* \retval OGGZ_ERR_HOLE_IN_DATA Hole (sequence number gap) detected in input data
* \retval OGGZ_ERR_OUT_OF_MEMORY Out of memory
*/ */
long oggz_read_input (OGGZ * oggz, unsigned char * buf, long n); long oggz_read_input (OGGZ * oggz, unsigned char * buf, long n);

View File

@ -638,7 +638,7 @@ oggz_map_return_value_to_error (int cb_ret)
case OGGZ_STOP_ERR: case OGGZ_STOP_ERR:
return OGGZ_ERR_STOP_ERR; return OGGZ_ERR_STOP_ERR;
default: default:
return cb_ret; return OGGZ_ERR_STOP_ERR;
} }
} }

View File

@ -57,12 +57,9 @@
#define strcasecmp _stricmp #define strcasecmp _stricmp
#endif #endif
/* Ensure comment vector length can be expressed in 32 bits
* including space for the trailing NUL */
#define MAX_COMMENT_LENGTH 0xFFFFFFFE
#define oggz_comment_clamp(c) MIN((c),MAX_COMMENT_LENGTH)
static size_t /* Ensure comment vector length can be expressed in 32 bits */
static unsigned long
oggz_comment_len (const char * s) oggz_comment_len (const char * s)
{ {
size_t len; size_t len;
@ -70,7 +67,7 @@ oggz_comment_len (const char * s)
if (s == NULL) return 0; if (s == NULL) return 0;
len = strlen (s); len = strlen (s);
return oggz_comment_clamp(len); return (unsigned long) MIN(len, 0xFFFFFFFF);
} }
static char * static char *
@ -85,12 +82,11 @@ oggz_strdup (const char * s)
} }
static char * static char *
oggz_strdup_len (const char * s, size_t len) oggz_strdup_len (const char * s, int len)
{ {
char * ret; char * ret;
if (s == NULL) return NULL; if (s == NULL) return NULL;
if (len == 0) return NULL; if (len == 0) return NULL;
len = oggz_comment_clamp(len);
ret = oggz_malloc (len + 1); ret = oggz_malloc (len + 1);
if (!ret) return NULL; if (!ret) return NULL;
if (strncpy (ret, s, len) == NULL) { if (strncpy (ret, s, len) == NULL) {
@ -177,23 +173,12 @@ oggz_comment_new (const char * name, const char * value)
OggzComment * comment; OggzComment * comment;
if (!oggz_comment_validate_byname (name, value)) return NULL; if (!oggz_comment_validate_byname (name, value)) return NULL;
/* Ensures that name != NULL, value != NULL, and validates strings */
comment = oggz_malloc (sizeof (OggzComment)); comment = oggz_malloc (sizeof (OggzComment));
if (comment == NULL) return NULL; if (comment == NULL) return NULL;
comment->name = oggz_strdup (name); comment->name = oggz_strdup (name);
if (comment->name == NULL) {
oggz_free (comment);
return NULL;
}
comment->value = oggz_strdup (value); comment->value = oggz_strdup (value);
if (comment->value == NULL) {
oggz_free (comment->name);
oggz_free (comment);
return NULL;
}
return comment; return comment;
} }
@ -232,8 +217,7 @@ _oggz_comment_set_vendor (OGGZ * oggz, long serialno,
if (stream->vendor) oggz_free (stream->vendor); if (stream->vendor) oggz_free (stream->vendor);
if ((stream->vendor = oggz_strdup (vendor_string)) == NULL) stream->vendor = oggz_strdup (vendor_string);
return OGGZ_ERR_OUT_OF_MEMORY;
return 0; return 0;
} }
@ -380,11 +364,9 @@ oggz_comment_add (OGGZ * oggz, long serialno, const OggzComment * comment)
if (!oggz_comment_validate_byname (comment->name, comment->value)) if (!oggz_comment_validate_byname (comment->name, comment->value))
return OGGZ_ERR_COMMENT_INVALID; return OGGZ_ERR_COMMENT_INVALID;
if ((new_comment = oggz_comment_new (comment->name, comment->value)) == NULL) new_comment = oggz_comment_new (comment->name, comment->value);
return OGGZ_ERR_OUT_OF_MEMORY;
if (_oggz_comment_add (stream, new_comment) == NULL) _oggz_comment_add (stream, new_comment);
return OGGZ_ERR_OUT_OF_MEMORY;
return 0; return 0;
} else { } else {
@ -416,11 +398,9 @@ oggz_comment_add_byname (OGGZ * oggz, long serialno,
if (!oggz_comment_validate_byname (name, value)) if (!oggz_comment_validate_byname (name, value))
return OGGZ_ERR_COMMENT_INVALID; return OGGZ_ERR_COMMENT_INVALID;
if ((new_comment = oggz_comment_new (name, value)) == NULL) new_comment = oggz_comment_new (name, value);
return OGGZ_ERR_OUT_OF_MEMORY;
if (_oggz_comment_add (stream, new_comment) == NULL) _oggz_comment_add (stream, new_comment);
return OGGZ_ERR_OUT_OF_MEMORY;
return 0; return 0;
} else { } else {
@ -551,8 +531,7 @@ oggz_comments_decode (OGGZ * oggz, long serialno,
{ {
oggz_stream_t * stream; oggz_stream_t * stream;
char *c= (char *)comments; char *c= (char *)comments;
int i, nb_fields, n; int len, i, nb_fields, n;
size_t len;
char *end; char *end;
char * name, * value, * nvalue = NULL; char * name, * value, * nvalue = NULL;
OggzComment * comment; OggzComment * comment;
@ -564,22 +543,16 @@ oggz_comments_decode (OGGZ * oggz, long serialno,
len=readint(c, 0); len=readint(c, 0);
c+=4; c+=4;
if (len>(size_t)(end-c)) return -1; if (c+len>end) return -1;
stream = oggz_get_stream (oggz, serialno); stream = oggz_get_stream (oggz, serialno);
if (stream == NULL) return OGGZ_ERR_BAD_SERIALNO; if (stream == NULL) return OGGZ_ERR_BAD_SERIALNO;
/* Vendor */ /* Vendor */
if (len > 0) { nvalue = oggz_strdup_len (c, len);
if ((nvalue = oggz_strdup_len (c, len)) == NULL) if (!nvalue) return -1;
return OGGZ_ERR_OUT_OF_MEMORY; _oggz_comment_set_vendor (oggz, serialno, nvalue);
if (nvalue) oggz_free (nvalue);
if (_oggz_comment_set_vendor (oggz, serialno, nvalue) == OGGZ_ERR_OUT_OF_MEMORY)
return OGGZ_ERR_OUT_OF_MEMORY;
oggz_free (nvalue);
}
#ifdef DEBUG #ifdef DEBUG
fwrite(c, 1, len, stderr); fputc ('\n', stderr); fwrite(c, 1, len, stderr); fputc ('\n', stderr);
#endif #endif
@ -587,8 +560,6 @@ oggz_comments_decode (OGGZ * oggz, long serialno,
if (c+4>end) return -1; if (c+4>end) return -1;
/* This value gets checked effectively by the 'for' condition
and the checks within the loop for c running off the end. */
nb_fields=readint(c, 0); nb_fields=readint(c, 0);
c+=4; c+=4;
for (i=0;i<nb_fields;i++) { for (i=0;i<nb_fields;i++) {
@ -597,7 +568,7 @@ oggz_comments_decode (OGGZ * oggz, long serialno,
len=readint(c, 0); len=readint(c, 0);
c+=4; c+=4;
if (len>(size_t)(end-c)) return -1; if (c+len>end) return -1;
name = c; name = c;
value = oggz_index_len (c, '=', len); value = oggz_index_len (c, '=', len);
@ -606,30 +577,18 @@ oggz_comments_decode (OGGZ * oggz, long serialno,
value++; value++;
n = c+len - value; n = c+len - value;
if ((nvalue = oggz_strdup_len (value, n)) == NULL) nvalue = oggz_strdup_len (value, n);
return OGGZ_ERR_OUT_OF_MEMORY;
#ifdef DEBUG #ifdef DEBUG
printf ("oggz_comments_decode: %s -> %s (length %d)\n", printf ("oggz_comments_decode: %s -> %s (length %d)\n",
name, nvalue, n); name, nvalue, n);
#endif #endif
if ((comment = oggz_comment_new (name, nvalue)) == NULL) comment = oggz_comment_new (name, nvalue);
return OGGZ_ERR_OUT_OF_MEMORY; _oggz_comment_add (stream, comment);
if (_oggz_comment_add (stream, comment) == NULL)
return OGGZ_ERR_OUT_OF_MEMORY;
oggz_free (nvalue); oggz_free (nvalue);
} else { } else {
if ((nvalue = oggz_strdup_len (name, len)) == NULL) nvalue = oggz_strdup_len (name, len);
return OGGZ_ERR_OUT_OF_MEMORY; comment = oggz_comment_new (nvalue, NULL);
_oggz_comment_add (stream, comment);
if ((comment = oggz_comment_new (nvalue, NULL)) == NULL)
return OGGZ_ERR_OUT_OF_MEMORY;
if (_oggz_comment_add (stream, comment) == NULL)
return OGGZ_ERR_OUT_OF_MEMORY;
oggz_free (nvalue); oggz_free (nvalue);
} }
@ -689,9 +648,7 @@ oggz_comments_encode (OGGZ * oggz, long serialno,
#endif #endif
/* user comment list length */ /* user comment list length */
if (accum_length (&actual_length, 4) == 0) actual_length += 4;
return 0;
for (comment = oggz_comment_first (oggz, serialno); comment; for (comment = oggz_comment_first (oggz, serialno); comment;
comment = oggz_comment_next (oggz, serialno, comment)) { comment = oggz_comment_next (oggz, serialno, comment)) {
@ -729,7 +686,7 @@ oggz_comments_encode (OGGZ * oggz, long serialno,
field_length = oggz_comment_len (stream->vendor); field_length = oggz_comment_len (stream->vendor);
memcpy (c, stream->vendor, MIN (field_length, remaining)); memcpy (c, stream->vendor, MIN (field_length, remaining));
c += field_length; remaining -= field_length; c += field_length; remaining -= field_length;
if (remaining <= 0) return actual_length; if (remaining <= 0 ) return actual_length;
} }
remaining -= 4; remaining -= 4;

View File

@ -722,7 +722,7 @@ oggz_seek_set (OGGZ * oggz, ogg_int64_t unit_target)
printf ("oggz_seek_set: [c] u%lld\n", printf ("oggz_seek_set: [c] u%lld\n",
oggz_get_unit (oggz, serialno, granule_at)); oggz_get_unit (oggz, serialno, granule_at));
#endif #endif
} else if (offset_next >= 0) { } else {
serialno = ogg_page_serialno (og); serialno = ogg_page_serialno (og);
granule_at = ogg_page_granulepos (og); granule_at = ogg_page_granulepos (og);
} }