Hi,
I've been playing with a little player, and it seems I can't ov_open a
file
twice?
heres a snipit...
<p>#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <vorbis/vorbisfile.h>
OggVorbis_File vf;
FILE *f = NULL;
int main(int argc, char **argv)
{
char *file = NULL;
int err = 0;
if(argc < 2) {
fprintf(stderr, "usage: %s <file.ogg>\n",
argv[0]);
return -1;
}
file = argv[2];
f = fopen(argv[1], "rb");
if(!f) {
fprintf(stderr, "fopen for '%s' failed: %s",
file, strerror(errno));
return -1;
}
err = ov_test(f, &vf, NULL, 0);
if(err < 0) {
char *tmp = "What?";
switch(err) {
case OV_EREAD: tmp = "A read from media returned an
error."; break;
case OV_ENOTVORBIS: tmp = "Bitstream is not Vorbis
data."; break;
case OV_EVERSION: tmp = "Vorbis version
mismatch."; break;
case OV_EBADHEADER: tmp = "Invalid Vorbis bitstream
header."; break;
case OV_EFAULT: tmp = "Internal logic fault;
indicates a bug or heap/stack
corruption."; break;
default: tmp = "Unknown error"; break;
}
fprintf(stderr, "error: %s\n", tmp);
return -1;
}
ov_clear(&vf);
fclose(f);
fprintf(stderr, "Ok1\n");
f = fopen(argv[1], "rb");
if(!f) {
fprintf(stderr, "fopen for '%s' failed: %s",
file, strerror(errno));
return -1;
}
err = ov_open(f, &vf, NULL, 0);
if(err < 0) {
char *tmp = "What?";
switch(err) {
case OV_EREAD: tmp = "A read from media returned an
error."; break;
case OV_ENOTVORBIS: tmp = "Bitstream is not Vorbis
data."; break;
case OV_EVERSION: tmp = "Vorbis version
mismatch."; break;
case OV_EBADHEADER: tmp = "Invalid Vorbis bitstream
header."; break;
case OV_EFAULT: tmp = "Internal logic fault;
indicates a bug or heap/stack
corruption."; break;
default: tmp = "Unknown error"; break;
}
fprintf(stderr, "error: %s\n", tmp);
return -1;
}
ov_clear(&vf);
fclose(f);
fprintf(stderr, "Ok2\n");
return 0;
}
it just doesn't work. Ok1 is printed. But I get OV_ENOTVORBIS the second
time,
everytime. Even if I use ov_test the first time.. Oh and ov_test acts the
same as ov_open, I don't have to call ov_test_open (in fact ov_test_open
fails...)
Also I've tried using 2 different OggVorbis_File structs for the two tries,
but that doesn't help either.
ystem specs:
Debian Cid, Linux/AMD k7
libvorbisfile 1.0
libogg 1.0
libvorbis 1.0
--
Thomas Fjellstrom
tfjellstrom@telusplanet.net
http://strangesoft.net
--- >8 ----
List archives: http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to
'vorbis-request@xiph.org'
containing only the word 'unsubscribe' in the body. No subject is
needed.
Unsubscribe messages sent to the list will be ignored/filtered.
On Mon, Dec 09, 2002 at 06:55:01AM -0700, Thomas Fjellstrom wrote:> Hi, > > I've been playing with a little player, and it seems I can't ov_open a file > twice?I apologize for the incompleteness of the main doc on the following point: Like with ov_open(), if ov_test() succeeds, it takes complete ownership of the passed in FILE *. Do not fclose() it later as you do below. Your trouble is most likely a heap corruption in stdio. Any successful lib call that takes a FILE * takes ownership of that FILE *; the close is carried out in the ov_clear(). Monty --- >8 ---- List archives: http://www.xiph.org/archives/ Ogg project homepage: http://www.xiph.org/ogg/ To unsubscribe from this list, send a message to 'vorbis-request@xiph.org' containing only the word 'unsubscribe' in the body. No subject is needed. Unsubscribe messages sent to the list will be ignored/filtered.
> file = argv[2];Well, let's make that argv[1] to avoid other problems, and wrong error messages...> ov_clear(&vf); > > fclose(f);Don't do that. As documented, ov_clear() will close the file for you. <p>> ov_clear(&vf);> > fclose(f);As above.> it just doesn't work. Ok1 is printed. But I get OV_ENOTVORBIS the second time, > everytime. Even if I use ov_test the first time.. Oh and ov_test acts the > same as ov_open, I don't have to call ov_test_open (in fact ov_test_open > fails...)Not sure what the problem is - whilst you have a series of obvious errors, none of them look like they should cause this sort of failure. Anyway, the first stage is to fix the errors. Failure of ov_test_open() is rather strange. ov_test() also will NEVER (it cannot) leave the OggVorbis_File struct in a state where it's usable (i.e. you can do decode). Michael --- >8 ---- List archives: http://www.xiph.org/archives/ Ogg project homepage: http://www.xiph.org/ogg/ To unsubscribe from this list, send a message to 'vorbis-request@xiph.org' containing only the word 'unsubscribe' in the body. No subject is needed. Unsubscribe messages sent to the list will be ignored/filtered.