Skip to content

Commit

Permalink
add libFLAC 1.1.3 support. Adapted from patch by Michel Salim
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.annodex.net/libfishsound/branches/1.0-stable@3372 8158c8cd-e7e1-0310-9fa4-c5954c97daef
  • Loading branch information
conrad committed Jan 21, 2008
1 parent 4c5a3eb commit 75e07df
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 6 deletions.
3 changes: 3 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Conrad Parker <conrad@metadecks.org>

Tobias Gehrig
- FLAC support

Michel Salim
- libFLAC 1.1.3 support

Silvia Pfeiffer <silvia@annodex.net>
- MS Windows porting, general packaging.
Expand Down
3 changes: 3 additions & 0 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
/* 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. */
#undef HAVE_INTTYPES_H

Expand Down
21 changes: 15 additions & 6 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ dnl

HAVE_FLAC=no
HAVE_FLAC_1_1_2=no
HAVE_FLAC_1_1_3=no
FLAC_SUPPORT=no

ac_enable_flac=yes
Expand All @@ -274,12 +275,20 @@ if test "x${ac_enable_flac}" = xyes ; then
saved_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS $FLAC_CFLAGS"

dnl Test for libFLAC 1.1.2
AC_CHECK_LIB(FLAC, FLAC__stream_decoder_init, HAVE_FLAC_1_1_2="yes",
HAVE_FLAC_1_1_2="no", [$FLAC_LIBS])
if test "x$HAVE_FLAC_1_1_2" = xyes ; then
AC_DEFINE(HAVE_FLAC_1_1_2, [1], [Define to 1 if you have libFLAC 1.1.2])
FLAC_SUPPORT="yes (1.1.2)"
dnl Test for libFLAC 1.1.3
AC_CHECK_LIB(FLAC, FLAC__stream_decoder_init_stream, HAVE_FLAC_1_1_3="yes",
HAVE_FLAC_1_1_3="no", [$FLAC_LIBS])
if test "x$HAVE_FLAC_1_1_3" = xyes ; then
AC_DEFINE(HAVE_FLAC_1_1_3, [1], [Define to 1 if you have libFLAC 1.1.3])
FLAC_SUPPORT="yes (1.1.3)"
else
dnl Test for libFLAC 1.1.2
AC_CHECK_LIB(FLAC, FLAC__stream_decoder_init, HAVE_FLAC_1_1_2="yes",
HAVE_FLAC_1_1_2="no", [$FLAC_LIBS])
if test "x$HAVE_FLAC_1_1_2" = xyes ; then
AC_DEFINE(HAVE_FLAC_1_1_2, [1], [Define to 1 if you have libFLAC 1.1.2])
FLAC_SUPPORT="yes (1.1.2)"
fi
fi

CFLAGS="$saved_CFLAGS"
Expand Down
33 changes: 33 additions & 0 deletions src/libfishsound/flac.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ fs_flac_decode_header (FishSound * fsound, unsigned char *buf, long bytes)
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_write_callback(fi->fsd, fs_flac_write_callback);
FLAC__stream_decoder_set_metadata_callback(fi->fsd, fs_flac_meta_callback);
Expand All @@ -260,6 +261,21 @@ fs_flac_decode_header (FishSound * fsound, unsigned char *buf, long bytes)

if (FLAC__stream_decoder_init(fi->fsd) != FLAC__STREAM_DECODER_SEARCH_FOR_METADATA)
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;
}
Expand Down Expand Up @@ -539,17 +555,34 @@ fs_flac_enc_headers (FishSound * fsound)
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_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_metadata_callback(fi->fse, fs_flac_enc_meta_callback);
FLAC__stream_encoder_set_client_data(fi->fse, fsound);
#endif

metadata = fs_flac_encode_vorbiscomments (fsound);
if (metadata != NULL)
FLAC__stream_encoder_set_metadata (fi->fse, &metadata, 1);

/* 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)
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;
}
Expand Down

0 comments on commit 75e07df

Please sign in to comment.