Wednesday, September 17, 2008

A bug hard to find...

During the last evenings, I have been coding a little tool to convert Avi files to 4:2:0 Yuv files. I just wanted it to have more videos to test with my H.264 encoder I work with in my diploma thesis. Well, it was no big deal programming it, just diving into the Video for Windows Api on MSDN to get familar with its interface so it didn't take long till I finished it. It's a console application and I always tested inside Visual Studio, passing the commandline parameters in the project settings. So everything worked fine till I tested it inside a cmd window outside Visual Studio. The converting loop was successful but it freezed after printing "Done!". Looking at the code I was surprised cause that printf("Done!\n") is the very last command!
That's the pseudocode:

for all frames
   pData = (BYTE*)AVIStreamGetFrame(pFrame, i-1);
   CreateYuvfromFrame(pData);
CloseAviFunctions();
printf("Done\n");
return;

Inside Visual Studio, I found at first no hint what was wrong, even tracing it showed no problem. Than I noticed that it does not freeze when the for-loop is not entered. Again reading in msdn, more specific AviStreamGetFrame, I read following:

Remarks:

The returned frame is valid only until the next call to this function or the AVIStreamGetFrameClose function.

Then I suddenly noticed, I called every necessary Avi-release and Avi-close function except the AviStreamGetFrameClose one. Inserting it just before my program ends and the bug was gone... and I was happy!

So what we learn from this: when using the Video for Windows Api, make sure to call the corresponding close-function for every Avifunction you use, although MSDN does not explicitly state that you have to before your program finishes!

But the open question remains: how to find this bug in a structured straightforward way? Normal debugging did not help and I was not willing the spend all my time to debug internal system calls within Ollydbg.
So if you know a way or you have just a suggestion, feel free to tell it me!


Friday, September 05, 2008

Still there

Hi,
currently I'm very busy with my diploma thesis - I just finished a big part concerning mode decision inside the encoder, now I have to implement some algortihms in VHDL and after that I will start with the actual Rate Controller. Things are getting more complicated and I also have to read some papers and books to build a mathematical theoretical background for my model. Well, nearly half of the time is already gone, so only 3 months left = stress.
That's why there is also no real update on my website. Ok I improved my layout as you can see which took already some time - did I ever mentioned that I'm no friend of html/css/all other web scripting languages - they just look ugly compared to a real programming language!
But I have already two cool tools coded concerning planar 4:2:0 yuv-files which just need some commenting and bugfixing before going to be available on my site - so stay tuned.

(Caution: Advertisment) I came across two cool free downloads - maybe you are also interested:
First of all, google published their own browser chrome for free download. My first impression is pretty positive - it's fast, small and easy to use - most of the screen is used for the displayed website, there is no over-blown gui with thousands of menus and statusbars. I like it but I stick to my lovely firefox - I am used to it and the bookmark bar is better and more comfortable to use in my opinion. But you should give chrome a try!
Second, after releasing Command & Conquer 1 as freeware, C&C - Red Alert is now also freely available as download. It's even better than part 1, in fact it is my all-time favourite realtime strategy game ever. I loved it. So go and download the iso images and start playing. For playing it under Windows XP/Vista, choose compatibility mode 'Windows 95' for both, the setup exe file and game exe file, and install also the provided patch - then you have no trouble.