Plex Blog

Much progress on video

Jan
21
2008
January 21, 2008 24 Comments

Changes in this version:

  • Videos play at the right speed, and don’t lock up. Even seeking works.
  • Audio now works during video playback, including DTS and AC3 passthrough!!
  • SDL’s OpenGL vertical sync support is enabled, to avoid tearing.
  • If we can’t open the selected audio device, try opening the default device. Might prevent some crashes.
  • Integrated fix for Mac Mini OpenGL issue, it *should* run there too (but I haven’t tested it).

The hardest piece of work for this release was tracking down a nefarious deadlock in CSharedSection. Deadlocks are a pain in the ass to track down, and the method I’ve always used is quite simple: printf. I run the program inside gdb, wait for it to deadlock, and then backtrack with the printf output to see what went wrong (looking at thread stack traces to see where the threads blocked). Tracking down this particular problem took me about four hours, which is about par for the course. I would have bet money that it was a bug in my code, since I’ve rewritten the critical section and event code (both of which CSharedSection relies upon heavily), but it turned out to be a bug in the class itself.

deadlock.jpg

Once I fixed the problem the movie 187 (my test video, for whatever reason), played through until the end, at turbo speed. I watched it for a few minutes, left the house, and when I returned I had a glorious kernel panic staring at me (although I could see that the movie had ended, at least). I haven’t seen any panics since, perhaps something to do with the fact that playing it so fast taxed the system much harder than usual. Plus it turns out the debug line on the screen (showing memory, CPU, etc.) isn’t thread safe with the video rendering code so that could have had something to do with it too (although it should never kernel panic, of course).

Once I got the audio working (through Portaudio), the video played at normal speed. This was so exhilarating that I started watching Along Came Polly and my wife came and sat with me and we watched the whole thing. (I have to admit, I was half expecting it to crash halfway through, but it didn’t.)

It was about this time when I realized that the mix-down code was ALSA dependent, so my only hope for multi-channel audio was through my surround receiver. I crossed my fingers, redirected the audio to Digital Output, and selected a video with AC3. It worked!!! DTS worked as well, which was incredibly exciting, because I’ve never found another application on OS X which could do DTS passthrough. No speaker-abusing audio glitches, either, like those that happen with some of the applications that try to feign passthrough with QuickTime. The way I’ve coded it is that if encoded digital audio is to be played, it looks for an output with “Digital” in it (thanks to the people who contributed data on this!). Otherwise it plays to the selected output in Audio Hardware. This isn’t perfect, but it’s probably a decent first take.

After fixing a few more bugs (seeking, OpenGL threading weirdness), and just for giggles, we decided to try to watch our nightly Six Feet Under on our Sony TV, which is connected to the second DVI port on my Mac. I changed the XBMC resolution to 1080i (and had to change it in the video settings as well), and moved the window over to the second display (with Anna yelling from around the corner “right…up…a bit more….stop!”) and we watched S03E03. Worked perfectly. One interesting note: Since it wasn’t officially full-screen, the first display wasn’t black, so it would have been possible to check email or do something else while the other person was using XBMC. This is an advantage over Front Row, which takes over your entire display.

IMG_1400.jpg

Next up:

  • Use an optimized, assembly-enabled (and non-buggy) ffmpeg.
  • Get full-screen display working.
  • Lots of other bugs…

At that point, it should be possible to actually to use XBMC on a TV with a halfway decent experience, and certainly better than that which Front Row offers.

I uploaded the new binary (why bother uploading an entire new package, right?) here. Enjoy!

Categories: