Archive for June, 2009
Movie Module Progress: Week 4
This week was a bit of varied work.
I did this week:
- Cleaned up, refactored, and commented code. This took a day
- Hunting down a memory leak. This took two days. It ended up being leaving opening a video stream without closing it before looping.
- Worked on getting loops to work properly. This took the better part of a day, as there’s various things that need to be manipulated in between loops for proper playback.
- Did various experiments with sound. My current attempt has been disastrous.
What I’m trying to do right now, is work with SDL_mixer. This goes on behind another file, lowering the dependency between SDL_mixer and my module, to make it easier and more portable to other sound systems in the future. One method I tried is to give the sdl_mixer adapter code a reference to a Condition variable, and to send a signal through the Condition variable when it needs more samples to play, whereupon my audio thread would pass it an already allocated buffer, which would then be added into a Mix_Chunk struct, and played via the SDL_mixer api. After doing this, my audio_thread would work on allocating another bunch of samples to pass it when necessary. This… didn’t work. Mainly because the sdl_mixer adapter code would send a signal back to the audio thread, but the audio thread wouldn’t catch the signal(I was using SDL_cond and associated functions to do this) for some reason. Add in as well the issues of deadlocking, which were quite literally textbook, where thread A grabs the GIL and tries to grab a mutex, while thread B grabs the mutex, and tries to grab the GIL. I fixed that.
I’ve also tried building a queue of buffers, which the adapter code will pull out and play when the current buffer is finished. Whenever the audio thread calls playBuffer, it copies that buffer to a newly allocated buffer of the same length, and then that new buffer is stored on the queue. This isn’t really quite debugged as apparently I need to brush up on pointer manipulation and memory allocation. I think I’m on the right path, by building a queue of buffers, I just need to do it right.
If anyone has any suggestions on how to do this, I will gladly welcome any help!
At the moment, the module will load pretty much any type of movie that ffmpeg supports, play it(infinite amount of times, or a specified amount of times), with pause, and stop working. Seeking does not work yet. Only video works. I’ve also added a few basic parameters to get, like the width and height of the movie itself. Next week, I will work on adding the ability to specify the height and width of the video file. As well, I think I could probably alter the repr a bit to get the current time-stamp. In fact I’ll do that right now. I should also add docs like the other pygame modules.
Comments are off for this postMovie Module Progress: Week 3
So some really good news today! I finally got video working this week, along with proper video synchronization, all without audio information. This bodes well for the rest of the module. I discovered I can’t use SDL audio, as SDL spawns a thread I have no control over, with only occassional callbacks. This does not work in Python, as it is not threadsafe to access Python objects or methods without proper synchronization primitives.
Rene suggested I pass back a buffer of the sound data, to be passed to say a pygame.mixer.Sound or pygame.mixer.Channel object. However, that doesn’t quite work as the Sound object copies the buffer passed into it, and shares no data with the buffer. The issue is that I’m trying to keep the threading as small as possible, so if anyone has any good suggestions for doing sound, I’d love to hear them!
Comments are off for this post