|Problems? Is your data what you think it is?|
How Perl Saved BayCon TVby stephen (Priest)
|on Feb 20, 2007 at 02:34 UTC||Need Help??|
This is the story of how I used Perl, POE, and a Linux box to turn an annual event of terror, boredom, and insomnia into an enjoyable experience.
Every year in the San Francisco Bay Area there’s a science fiction convention called BayCon. During the con, we take over one of the channels on the hotel's televisions to run a TV station called BayCon TV, or BCTV for short. We play interviews with our guests of honor, fan videos, old movies, and pictures of people at the convention.
When I first came aboard with BCTV, everything was done with tape. The crew had to build huge videotapes and play them one after the other. If they missed a tape change, or if a movie was shorter than expected, the entire schedule got thrown off. We had to build the tapes during the convention, which kept us locked in our rooms and awake all night, frantically editing the next tape together.
There had to be a better way. I found one... using Perl.
The first problem was how to play the movies. I found that the most complete video player which had a documented library interface was Xine. (This was in 2003.) I wrote a Perl library to handle at least the basics of accessing it. This module became Video::Xine.
Next, I needed something to tell the Xine module when to play the movies. I drew up baroque plans involving threads, forking, and alarm calls... then used POE instead. With POE, I could create a daemon that called my movie-player object at the scheduled time. Whenever Xine was finished playing a movie, it would tell POE about it via Xine's built-in event system, and it would show slides with Image::Imlib2 and play music, again using Xine.
Overlapping movies proved to be a big problem. The listed running time for a movie can be inaccurate (or, in the throes of con confusion, miscommunicated), and it can be easy to schedule one movie to start before another is finished. I attacked this problem in a couple of ways.
First, I stored the schedule in a PostgreSQL database. This allowed me to prevent careless errors by defining database triggers that calculated the start time and end time for a particular run of a film and would not allow me to add a new schedule entry that conflicted with a previous one. Second, I kept the lengths of all the movies in the Postgres database as well, and automatically calculated them using my Xine module. Finally, POE's event-based programming environment let me program the system flexibly enough to simply skip any conflicting movie.
Since the theme of the convention for which I wrote this system was time travel, I called it the Playback Machine. You can find it on CPAN as Video::PlaybackMachine.
These days, the Playback Machine is stable enough to do its work without interference from me. I can, in theory, hook it up to the hotel's TV system, walk out of the room, and spend the rest of the weekend mingling with my fellow deranged geeks. (It hasn't always been perfect. A tip-- always turn off your screen saver.) I run around taking pictures, then upload them to the system so that my fellow fans can turn on their television sets and say, "Hey! That's me!"
So if you're a science fiction fan in the San Francisco Bay Area, and feel like stopping by a convention on Memorial Day weekend, see if you can find a television set tuned to BCTV. And as you watch Godzilla destroy Tokyo, or see images of people dressed in very strange costumes, just remember-- it's powered by Perl.