Tuesday, July 19, 2011

Ceton InifiniTV 4 in MythTV 0.24 - Part 1

With the pending release of the SiliconDust HD Homerun Prime, I was getting pretty excited about getting a cablecard tuner for MythTV. However, then something wonderful happened...Ceton decided to drop the price of the InfiniTV 4 card to $300. I hadn't been very interested in the card before simply because it was a bit out of my desired price range. However, at the new price, it was barely more expensive than the Prime, and it gave you a 4th tuner to run off the same cablecard. After thinking about it for a few weeks, I decided to cancel my HDHR Prime preorder and take a chance on the Ceton card.

I said take a chance, because I knew that the Ceton card wasn't yet supported in MythTV. However, I had some ideas how I could hack support into myth 0.24, and failing that, I was under the impression that the trunk code of mythtv (which will eventually be 0.25) already had the code necessary to work with the Ceton. So I figured one way or another, I was covered with the caveat that I wouldn't be working with a proven, tested system.

It turns out I was wrong on both counts. My plans for hacking support into 0.24 (using the Demo Recorder or Import Recorder) didn't pan out. So I tried the trunk support and couldn't get it working. After a post on the MythTV user forums, I learned that I was mistaken...that the trunk code only contained bits of the needed code, and wasn't at all functional. Oops. Big oops.

So here I was with a $300 capture card that didn't work in myth, and a wife who had been anxiously anticipating an upgrade to HD channels. What do I do? Tell her "sorry...you'll have to wait a while...maybe another 6 months"? Or do I sell the Ceton card and buy the Prime? Or is there a 3rd option....can I write my own code to get it working in MythTV 0.24?


Writing the code

When I first looked into the code, it was a huge mess of very mysterious things I didn't understand. There was a part of me that said I'd probably never get this all to work. But then I did what I always do...just try to break it down into chunks. I started looking at bits and pieces, figuring out what I did and didn't need. This allowed me to discard large sections of code and focus on a much smaller core set of functionality.

It took me only a few days to figure out enough to hack my way through it and get my very first output...video from the Ceton on my TV screen. It was very basic..it didn't include things like channel changing yet, but it was a start. Then I discovered that a whole bunch of stuff wasn't working...seeking, commercial flagging, channel changing was incredibly slow, etc.

After looking into it, it turns out that a lot of that "unimportant" code I discarded early actually had important functionality that I didn't yet understand. Yet stripping it out still had value...it allowed me to focus on a smaller bit of functionality and become more familiar with it. I now understood a lot of code, and as I started to work back in those pieces I ripped out, one by one they were making sense, too.

Over the next few weeks, I got everything put back in and reworked it. I hit some snags along the way...a bug in the existing myth code, a VDPAU bug in an early release of Debian squeeze, and some peculiar mpeg data streams from my cable provider all simultaneously threw up obstacles and mislead me about why things weren't working. One by one I figured it out, and eventually I ended up with a fully functional recorder for the Ceton card. It could record, flag commercials, do the channel changing on it's own, etc.

However, I had a few issues with channel changing. I was changing channels through the Ceton's built in web interface (rather than the DRI UPnP interface), and apparently that isn't the most rock solid way to change channels. I thought I had dealt with the issue and everything seemed fine, so I set up my first big test...recording a dozen programs overnight. When I woke up in the morning, I found that a few of the recordings failed. However, that turned out to be my fault...I had setup the channel data with a channel I didn't actually subscribe to.

After fixing that, I ran a bigger test the next night....about 30 programs, using all 4 tuners at a time. When I woke up the next day, I found that several of those didn't record. Looking at my logs, the problem appeared to be that when multiple tuners tried to change the channel in rapid succession, not all of the requests would always succeed. So I spent a few days writing an entire new set of channel changing code, which would do 2 things...first, it would space out the request to ensure too many don't occur at once. Second, it would monitor the change until it saw that it was complete and successful, and if necessary, it would re-initiate the channel change until it finally succeeds.

With my new changes in place, I setup my box to run for 12 hours, recording 80 programs, all back to back, and often with 4 new program starting simultaneously. End result...everything worked perfectly.

With that final test completely successful, I put it all on the line. I took the Ceton card out of my dev box, put it in my newly-rebuilt production myth server, and set it up as the 4 highest priority tuners. It's been working great for a few days now.

I still have some more tweaks I want to make, but it's going to be a little while (I'm getting prepared for my daughters 1st birthday this weekend). However, everything is working well enough now, so I'll be posting my existing code very soon.


4 comments:

Tom said...

I'm looking forward to part 2 =). I plan to take the infinitv 4 plunge (hopefully this summer) but I'm waiting to make the purchase till I know it will run on mythtv.

Anonymous said...

Looking forward to part 2, I just got my Ceton on Tuesday, got my Cable Card Wednesday, and am ready to go. My experience with WOW was much better than yours - 1st level support asked me if I wanted to pick it up, or have a tech deliver it. Based on your earlier results, I picked it up, installed it in Windows to get it authorized, and my call for authorization was under 15 minutes. Most of that was rebooting after the card was authorized. The "digital transition" just came to my area on Monday, which encouraged me to look for Myth options.

ken said...

Ron, my Ceton arrived today. I've got Mythbuntu so your post on myth-users that you got it working on Mythbuntu is very good news. I'm looking forward to trying it out.

whoami said...

I found a possible bug in the perl script you wrote for the QAM channel map utility. The program wasn't finding any programs when tuning.
I changed the 1st line getPrograms Sub from :
my ($line) = .....
to
my $line = .....

I upgraded the firmware for my ceton infinitv card and I think it modifed the output of the scripts ..

thx

im