Friday, July 22, 2011

Ceton InifiniTV 4 in MythTV 0.24 - Part 3 (Mythbuntu)

In Part 2 of this article, I provided all of the instructions for setting up MythTV 0.24 to use a Ceton InfiniTV 4 cablecard tuner. Today, I'm going to provide a simple step by step that should get a Mythbuntu 11.04 user up and running with Ceton support. However, before continuing, please first read Part 2 to see all of the disclaimers and important info. I'm going to assume you've read it, and thus won't be repeating all of the important details here.

Instructions

mkdir /usr/src/mythtv
cd /usr/src/mythtv

apt-get build-dep mythtv
apt-get source mythtv
apt-get install devscripts

cd mythtv-0.24.0+fixes.20110416.9ba3ece

dch -i

This will take you to edit a file containing a changelog. At the top of the file, it will have already filled in the framework for you to enter your change info. There will be a line with a single asterisk * about 3-4 lines down. Next to the asterisk, just put a brief summery like "applying ron's ceton patch"

For the following, I'm going to assume you've put the patch file (which you can get here) in your home directory. Also, substitute the XXX in the filename with the appropriate version you've downloaded.

cp ~/ceton_mythbuntu_verXXX.patch debian/patches/
patch --dry-run -p1 < debian/patches/ceton_mythbuntu_verXXX.patch

Make sure you got no error from the above. Also please double check the output to make sure it doesn't say anything about applying the patch with fuzz. Although patching with fuzz will work at this step, when you go to rebuild the package, it won't allow fuzz.

pico debian/patches/series

Add ceton_mythbuntu_verXXX.patch at the end of the mythtv section.

debuild -us -uc -iFFmpeg

In the above command -us and -uc are necessary so that we can build the packages even though we aren't setup to sign them. The -iFFmpeg is to tell the packager not to include the FFmpeg stuff in the package. I had to do this because the build process started complaining about the binary file being different. I couldn't find any good explanations on google, but since I didn't modify anything in ffmpeg, we can just leave it out and it will use the old version.


Now at this step you are going to need to install the packages to replace the binary files with your new version. First, I want you to run the following command and make note of the timestamps on the existing files (copy the output to a text editor and hold onto it for a few moments).

ls -l /usr/bin/mythbackend /usr/bin/mythfrontend* /usr/lib/libmythtv-0.24.so* /usr/bin/mythtv-setup*

Now lets install the packages. There are a ton of packages here, and you can try to install them all if you like. However, I only bothered with the following, and everything seemed to work

cd ..
dpkg -i mythtv_0.24.0+fixes.20110416.9ba3ece-0ubuntu2_all.deb
dpkg -i mythtv-common_0.24.0+fixes.20110416.9ba3ece-0ubuntu2_i386.deb
dpkg -i libmyth-0.24-0_0.24.0+fixes.20110416.9ba3ece-0ubuntu2_i386.deb
dpkg -i mythtv-backend_0.24.0+fixes.20110416.9ba3ece-0ubuntu2_i386.deb
dpkg -i mythtv-frontend_0.24.0+fixes.20110416.9ba3ece-0ubuntu2_i386.deb


Now, let's once again look at the timestamps on the files:

ls -l /usr/bin/mythbackend /usr/bin/mythfrontend* /usr/lib/libmythtv-0.24.so* /usr/bin/mythtv-setup*

Everything should have a new timestamp on it


At this point, all of the Mythbuntu specific stuff should be setup. Now go to Part 2 of this article and continue on from step 8.


...click here to read more!

Thursday, July 21, 2011

Ceton InifiniTV 4 in MythTV 0.24 - Part 2

In Part 1 of this article, I discussed my decision to get a Ceton InfiniTV 4 card instead of a HD Homerun Prime, how it didn't initially go as planned, and how I eventually went through the process to write my own code to utilize the card in MythTV 0.24. Now I'd like to share the fruits of my labor...the necessary code which you can compile into MythTV 0.24-fixes to get Ceton support for yourself. In the upcomming Part 3 (hopefully posted tomorrow), I'll post a patch and instructions for Mythbuntu 11.04 users


Standard disclaimers

I'd be absolutely thrilled if you wanted to use my code to get your Ceton card working in MythTV. However, before I unleash all of this on you, I need to be clear about a number of things. I wouldn't want you to not realize what you are getting into and get mad at me if something goes terribly wrong (like you miss a bunch of recordings). So here are a few things you'll need to know before getting started

1) This isn't just a distribution you can download and install, or run apt-get on. We are talking about custom compiled code. You will be downloading the mythtv source code from the git tree, applying some patches, and custom compiling it on your own. If you've never done this before, then I'd prefer that you get comfortable with that process before trying to add in my code. So I'd suggest downloading 0.24-fixes from git (see the instructions at code.mythtv.org), compiling it, installing it, and making sure everything works. If that all works fine, only then should you think about proceeding

2) This isn't official code by any means. This is something I put together by myself, as a stopgap measure until 0.25 is eventually released with real Ceton support. So far, the only person to test this code is me. If you run into problems, the folks on the MythTV forums aren't gonna help you with this one. You'll be depending on me for help.

3) If you have problems with the code, I'll try to help. I take pride in what I do, and I'll be willing to work with you as much as I can to figure out your problems. That said, I've got a full time job and a 1 year old daughter, so don't expect 24 hour support and quick turnaround time. It may take me a while to figure out and get to the bottom of it, but I'll try my best.

4) If you do need help from me, then I'm gonna need help from you. I'm gonna ask you for logs, I'll probably send you some custom code, ask you to run it, and send me back the results. I may do this a number of times.

5) Realizing that this isn't the official software for running the Ceton card in MythTV (nor will it be the official code in 0.25 or ever), you are going to have to expect things to break when you eventually upgrade to 0.25. You're going to have to delete your tuners and repeat the setup process in 0.25 using the officially supported mechanism.

6) When 0.25 comes out, if by some chance it does NOT contain the official support for this card as expected, then this code won't work on 0.25. I may be a bit delayed in upgrading my systems to 0.25, so it may be a little while before I can update the code. That said, I should be able to do it relatively easily, as I already did some preliminary work at getting this working in 0.25 (and had it working in a limited capacity), so I've got a decent part of the code written. And some of the biggest parts (that deal with tuning and getting status info) are actually not tied to myth directly, so I should be able to port them with no problems.


Other important information

If the disclaimers didn't scare you off, then here are few of the little quirks you need to know about:

Importing QAM channels - I haven't written a channel scanner for this card, so if you want to run it in QAM mode without a cablecard installed, you are going to have to do some work to get your channel data setup properly. I can work with you to get this setup if necessary, and I can probably write some perl scripts to help you with the process. However, hopefully nobody is buying this card just for it's QAM support, so hopefully this won't be such an issue. But if you maybe want to test it in QAM mode before upgrading your cable service and ordering a cable card, then we'll have to setup some channels for you

Importing cable card channels - For cable card support, we just use myth's download option and let mythfilldatabase download the data from schedules direct and create the channels. This sets up the channels for the most part, but they are not yet usable by this code. You'll need to run an SQL query to update one of the fields in the database. I'll provide you with instructions below. Also, in the future, if new channels get added to your lineup automatically, they are going to need to be tweaked before they are usable, so you'll need to rerun that query whenever your lineup changes. In the future, I'll try to figure out the most appropriate way to automate this so you don't have to worry about it, but for now it's something you'll need to be aware of

Live TV channel changing - Typically this works very well...about 3 to 4 seconds per channel change. However, occasionally a tuning request may fail and the Ceton doesn't properly tune the channel. The good news is that I've got code to detect this condition (as least for every way I've experienced this or I anticipate it could happen) and re-initiate the channel change request automatically. However, when it does happen, it will take 5 seconds for the code to kick in, and then another few seconds for the channel change to occur. When this happens, you'll be staring at a black screen for several seconds. Back on the good news side, I've only had this happen to me once in my testing, so I don't expect it will be very common).

Startup error condition - I've started and stopped the mythtv-backend service hundreds of times almost entirely without issue. Once it's running, the code works great. However, one time I rebooted my computer and when it came up, it didn't initialize properly. As a result, the card wasn't usable for recording until I stopped and restarted mythtv-backend. When it happened, it was logging very obvious info to the log file, so this will be easy for you to detect. Sometime next week (after my daughter's 1st birthday party) I intend to take a better look at this, rebooting my system several times to see if I can recreate it. I'm pretty sure it was just a matter of mythtv-backend starting up before the Ceton card was ready. I've modified my card to get its IP through DHCP instead of using the static 192.168.200.1 that it has by default, so this may have been the cause of the problem.


One final disclaimer

It's important to know that cablecard support is going to depend on your cable provider. Unfortunately, cable labs has only certified Windows Media Center to support certain modes of DRM. This means in MythTV, you can only watch channels that are marked as Copy Freely, and it's up to your cable provider to decide this. If they mark a channel as Copy Once or Copy Never, you are out of luck and the only thing you can possibly do is complain to them (for all the good it will probably do). You can probably check with others on the MythTV forum to try and figure out what channels are marked Copy Freely for you (either someone that lives in your area may know, or someone may be able to show you how to retrieve that info from your cable box).

In general, WOW (wide open west) has said that they mark everything except premium channels (HBO, showtime, etc) and PPV as Copy Freely. This should hold true in all WOW markets. Comcast has the exact same arrangement in most of their markets, but I believe there are some places here and there that are configured differently. With other cable providers, results may vary.


Are you still here? OK, let's get this going

If I haven't scared you off with the disclaimers and quirks, then I guess you are serious about this and it's time to get to work. So here's what you need to do

1) Download myth 0.24-fixes and make sure you can compile it all fine.

2) Download my ceton patch for 0.24-fixes.

3) cd to the mythtv/mythtv folder of the source code. This is the folder that contains the ./configure script

4) Clean up any previously compiled code by running:
make dist-clean

5) Test the patch first by running the following command:
patch --dry-run -p2 < /path/to/ceton_verXXX.patch

6) If the above test was successful and no failures occurred, then apply the patches by running:
patch -p2 < /path/to/ceton_verXXX.patch

7) Run ./configure, compile everything, and install it

8) Start mythtv-setup and add a Ceton tuner. The default IP address (if you haven't changed it) is 192.168.200.1, and the tuners are numbered 1 to 4. Repeat this process for all 4 tuners (or as many as you want to setup).

9) Create a brand new data source exclusively for the Ceton tuners (and don't let any other non-ceton tuners use it).

10) Click the button to fetch channel info (I don't recall the exact wording, but it's the next to the scan button in the Input Connections page

11) If you have a cablecard installed in your Ceton InfiniTV, perform step 11-A and then go to step 12. If you DO NOT have a cablecard installed (ie: you want to operate the card in QAM mode) perform step 11-B and then go to step 12.

11-A) Note: this step is no longer needed as of patch ver 008 (1/7/2012) Do this step ONLY if you are running the Ceton in CableCard mode (ie: you have a cablecard installed):
Download the channel mapping utility. Unzip/untar it and edit the perl script to adjust the config settings at the top of the file. You'll want to verify (and change when necessary) the path to wget, the ip address of your Ceton InfiniTV 4 card, and the mysql info (host/db/user/password). Then simply run the perl script to have it update the channel config.


11-B) Do this step ONLY if you are running the Ceton in QAM mode (ie: you do NOT have a cablecard installed):
Download the QAM channel mapping utility. Unzip/untar it and edit the perl script to adjust the config settings at the top of the file. You'll want to verify (and change when necessary) the path to wget, the ip address of your Ceton InfiniTV 4 card, and the mysql info (host/db/user/password). Then run the perl script to have it update the channel config.

Note: One limitation of this script is that it cannot determine which channels are available in unencrypted QAM. It will simply look at every channel in the videosource that you've assigned to the card in mythtv-setup, and then update the configuration of that channel accordingly. Therefore, in order to eliminate the encrypted channels so that myth doesn't have to tune them, you will need to delete those extra channels or mark them as not visible (either in mythtv-setup or using mythweb).

12) Startup the backend and the front end, and you should be good to go if I haven't forgot anything.


...click here to read more!

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.
...click here to read more!