[cvs-annodex] commit (/annodex):
libfishsound/branches/1.0-stable/src/libfishsound/vorbis.c
conrad
nobody at lists.annodex.net
Wed Aug 10 21:21:55 EST 2005
Update of /annodex (new revision 1426)
Modified files:
libfishsound/branches/1.0-stable/src/libfishsound/vorbis.c
Log Message:
libfishsound-stable: add internal fs_vorbis_finish() function to ensure
that vorbis_analysis_wrote(vd, 0) is only ever called once. This is to
be done at the end of stream, but doing it multiple times leads to a
corrupted file. Don't allow the user to make that mistake :)
Modified: libfishsound/branches/1.0-stable/src/libfishsound/vorbis.c
===================================================================
--- libfishsound/branches/1.0-stable/src/libfishsound/vorbis.c 2005-08-09 05:46:13 UTC (rev 1425)
+++ libfishsound/branches/1.0-stable/src/libfishsound/vorbis.c 2005-08-10 11:21:52 UTC (rev 1426)
@@ -50,6 +50,7 @@
typedef struct _FishSoundVorbisInfo {
int packetno;
+ int finished;
vorbis_info vi;
vorbis_comment vc;
vorbis_dsp_state vd; /** central working state for the PCM->packet encoder */
@@ -267,7 +268,6 @@
#endif
-
#if FS_ENCODE && HAVE_VORBISENC
static FishSound *
@@ -344,6 +344,21 @@
return len;
}
+static int
+fs_vorbis_finish (FishSound * fsound)
+{
+ FishSoundVorbisInfo * fsv = (FishSoundVorbisInfo *)fsound->codec_data;
+
+ if (!fsv->finished) {
+ if (fsound->mode == FISH_SOUND_ENCODE) {
+ fs_vorbis_encode_write (fsound, 0);
+ }
+ fsv->finished = 1;
+ }
+
+ return 0;
+}
+
static long
fs_vorbis_encode_f_ilv (FishSound * fsound, float ** pcm, long frames)
{
@@ -356,6 +371,11 @@
fs_vorbis_enc_headers (fsound);
}
+ if (frames == 0) {
+ fs_vorbis_finish (fsound);
+ return 0;
+ }
+
while (remaining > 0) {
len = MIN (1024, remaining);
@@ -376,7 +396,7 @@
* handle the last frame and mark the end of stream in the output properly.
*/
if (fsound->next_eos)
- fs_vorbis_encode_write (fsound, 0);
+ fs_vorbis_finish (fsound);
return 0;
}
@@ -394,6 +414,11 @@
fs_vorbis_enc_headers (fsound);
}
+ if (frames == 0) {
+ fs_vorbis_finish (fsound);
+ return 0;
+ }
+
for (i = 0; i < fsound->info.channels; i++) {
ppcm[i] = pcm[i];
}
@@ -422,7 +447,7 @@
* handle the last frame and mark the end of stream in the output properly.
*/
if (fsound->next_eos)
- fs_vorbis_encode_write (fsound, 0);
+ fs_vorbis_finish (fsound);
return 0;
}
@@ -452,6 +477,7 @@
#define fs_vorbis_encode_f NULL
#define fs_vorbis_encode_f_ilv NULL
+#define fs_vorbis_finish NULL
#endif /* ! FS_ENCODE && HAVE_VORBISENC */
@@ -474,6 +500,7 @@
if (fsv == NULL) return NULL;
fsv->packetno = 0;
+ fsv->finished = 0;
vorbis_info_init (&fsv->vi);
vorbis_comment_init (&fsv->vc);
fsv->ipcm = NULL;
@@ -497,6 +524,8 @@
{
FishSoundVorbisInfo * fsv = (FishSoundVorbisInfo *)fsound->codec_data;
+ fs_vorbis_finish (fsound);
+
if (fsv->ipcm) fs_free (fsv->ipcm);
vorbis_block_clear (&fsv->vb);
--
conrad
More information about the cvs-annodex
mailing list