PDA

View Full Version : ov_open_callbacks() question


Dogness
12-20-2005, 11:21 AM
I am relatively new at this and I am working on someone else's code, so please be patient with me. :)

Here's the deal:

This program is using OggVorbis and OpenAL. I think I have a pretty good handle on how it all works together.

We were having a timing issue. As I was stepping through the code, I came to the ov_open_callbacks() call. I put a breakpoint in the callback read_func and immediately after the ov_open_callbacks() call. When I let the code run, I hit enter the read_func callback 8 to 11 times before I hit the breakpoint that was after the ov_open_callbacks() call.

Now, the code works and my .ogg file gets loaded. However, the multiple calls to the read_func seem unnecessary and waste a lot of CPU cycles.

Maybe there is something I don't understand, but I would think that the callback would only be invoked once.

Can anyone explain to me why I am getting so many callbacks?

Thanks in advance.

SpreeTree
12-20-2005, 02:33 PM
Am I right in thinking that when you call ov_open_callbacks, it starts to instantly call the vorbis read function?

When you call the ov_open_callbacks function, it probably (now this is a guess, but it might be a good one!) parses the ogg file header to both check the data is ogg data, and to allows the functions like ov_info and ov_comment to be used.

It probably needs to make multiple calls to allow it to parse the various header sections and information contained within the file.

Is your application so time critical that a few calls to a (what should be) very quick function - granted probably called at run time - is causing you serious problems?

Hope that helps
Spree

Dogness
12-21-2005, 11:20 AM
Am I right in thinking that when you call ov_open_callbacks, it starts to instantly call the vorbis read function?


That is what I am trying to figure out. How do I get from the ov_open_callbacks() call to the read function? What triggers that callback?


When you call the ov_open_callbacks function, it probably (now this is a guess, but it might be a good one!) parses the ogg file header to both check the data is ogg data, and to allows the functions like ov_info and ov_comment to be used.

It probably needs to make multiple calls to allow it to parse the various header sections and information contained within the file.


Is this true? It seems to me that the read callback function simply copies my input data array into the OggVorbis_File for the call to ov_read.

From my debugging info, that callback is basically performing a memcpy of the same data into the same destination over and over again. This can't be on purpose, can it?


Is your application so time critical that a few calls to a (what should be) very quick function - granted probably called at run time - is causing you serious problems?


The problem is that each call to ov_open_callbacks() generates 8-11 "calls" to the callback function. So, when the program attempts to open 40 OGG files in a short period of time, it ends up generating a minumum of (40*8=)320 callbacks. This is not good.


Hope that helps
Spree

I appreciate the feedback. At this point, we have a workaround. I just want to see if I can figure out what the heck is goign on.

SpreeTree
12-23-2005, 12:34 AM
Sorry for the delay in reply, I havn't had time to look into my code until now.


From my debugging info, that callback is basically performing a memcpy of the same data into the same destination over and over again. This can't be on purpose, can it?


If I step through my ogg vorbis code, it calls the red callback 4-5 times (depending on the file, but the same file always has the same number of reads), and each time it is definatly reading different data to the same destination.

The same destination is obviously ok (it is probably some kind on internal buffer), but I would be worried about it reading the same data again and again in your code - Are you incrementing your file buffer so it takes into account how much has been read so far?


The problem is that each call to ov_open_callbacks() generates 8-11 "calls" to the callback function.

Having stepped through all my code, I can happily say I have no idea what it is reading when it does these initial calls. But it does seem to just move around the file, rather than reading it sequentially.

I think it intially reads the header, and then the footer of the file format. Maybe it needs this data to correctly decompress the content?


So, when the program attempts to open 40 OGG files in a short period of time, it ends up generating a minumum of (40*8=)320 callbacks. This is not good.

As I said before, if this is in your set-up routine, don't worry about it. 320 calls to a callback it not ideal, but if its not effecting the running of the application it's fine.

Of course, if you are doing this at runtime, it may be a problem. But what are you using 40 ogg files for? It seems like a large number to be loading all within a short space of time, in fact it seems like a large number to be loading at all!


At this point, we have a workaround.

What is your work around? Do this stop the 8-10 calls to the callback? If so, does everything still stream smoothly, and do the ov_comment and ov_info functions still work?

Spree