Friday, July 23, 2010

Finding missing ClearQAM streams


Often, after installing a new Digital TV Tuner into your system Media Center will not detect any channels on it. You run 100's of  'Scan for more Channels' and just end up with 'No Channels Found. To add insult to injury you attempt to add the channels manually but you have absolutely no luck as guessing the channel numbers and sub numbers is just that - a guess.

Figure 1 The Dreaded - No channels found - screen
Well I had enough of that and I decided to write a small utility to scan every channel that media center scans and display the information in the hopes that someone else can find it useful - I know I did.
To understand why your channels are not detected you need to understand how Media Center 'detects' a unique channel. The first step is of course scanning for channels usually this starts by setting the digital tuner to channel 55.25 MHz (if you live in the USA) Media Center uses frequencies for BDA tuners to set the channel. It then jumps in increments of roughly 6 Mhz searching for a digital signal - there are some places where it jumps a different amount but this is outside the scope of this discussion.
Every time the tuner locks onto a signal the transport stream is scanned for a Program Association Table (PAT) table - the PAT table contains each program number and the PID associated with that program. After the PAT table is detected the Program Map Table (PMT) needs to be found. The PMT contains the information (PID and type) of each elementary stream i.e. video, audio, etc.
Now you are wondering what is he talking about what's all this talk about programs when we are talking transport streams…well a transport stream can carry many different streams that are multiplexed, each stream is identified by a PID which is contained in the PAT.

Now Media Center has determined that this is a digital stream and it wants to get 'Digital' information. The stream is now scanned for PSIP (Program and System Information Protocol) information. This starts off with the Master Guide Table (MGT) – this table, similar to how PAT contains information about the streams, contains information about PSIP tables. Most PSIP packets have a PID of 0x1ffb (8187) so detecting the correct table is just a matter of detecting the table field. The MGT will define if a stream contains a Terrestrial Virtual Channel Table (TVCT) used by ATSC transmissions or a Cable VCT (CVCT) which is obviously used by Cable transmissions. These two VCT tables along with the MGT are all that is used for channel detection. There are other tables – the Event Information Table (EIT) is used for guide information if a channel match cannot be found, the Extended Text Table (ETT), etc.
If everything panned out MCE would have detected your channels and you would not be reading this postJ. However there is one caveat occasionally program with duplicate program numbers may be overwritten. I have tested and verified this in a couple of times.

Figure 2 Channel information returned
As you can see in Figure 2 channel 72 two channels with PSIP information were detected and 3 without – the Call Signs are displayed along with the channel numbers that Media Center will present the channel as on the guide the other may be displayed as C72.97, C72.20 and of course C72.235. This of just depends of course on no other channels show up with the same program number and overwrite them.

Figure 3 Media Center Channel edit
As you can see in Figure 3 the information detected on the utility is reflected in Media Center. The pad-lock on the right shows that the channels are encrypted if there is no padlock you can check the box and the channel will show up on your guide without any information. You can then watch it for a while to determine what channel it is and change the listing manually.
If you do not see your program and you know more or less what channel it is you will be able to add it manually. Select Add a QAM channel enter the missing channel number which is either the PSIP number or the "channe .program number". You can select QAM256 by default it does not really make a difference as he tuner handles the demodulation not Media Center.

Figure 4 Adding Channel manually
Unfortunately Media Center will never map a xx.yy channel that it detected via a scan to a xx channel that you will see if you are using a cable card or a STB. This is because Media Center is treating every program as if is a ATSC program – scanning the internals of Media Center also reflects this.
The utility I wrote just scans the channels for now – I am busy porting some of this code to C# so that I can combine it with the code in my previous article to allow editing of the Media Center Guide listings directly. This will also give the ability to select a full channel number as opposed to a x.y number.

Here are the links to the files:
32bit ClearQAM Scanner.
64bit ClearQAM Scanner.

This files are offered without warranty, however they are not public domain please leave any comments re bugs etc. here.

To install run the registerdll.bat file then run the exe file - it will grab the first QAM capable tuner that Media Center is aware of i.e. you must have set up Media Center to use the Digital Cable Tuner before running this utility.

Friday, July 16, 2010

Detecting and fixing Channels in Media Center 7

One of the to-do's I have on my Streaming Tuner is to detect the channel call signs on the client computer for the encoded analog channels that are now digital. The second to-do was to get the channels to match up with guide information.

I managed to get the channels detected by scrubbing the transport stream (TS) created by the mpeg-2 encoder in the graph. I needed to edit the PAT and PMT - to change the program number of the stream and add additional streams (MCE does not like duplicate program numbers - I discovered after many hours of head banging). Then I needed to inject PSIP packets (namely MGT, CVCT and EIT) which would enable MCE to detect the callsigns of the channels. Needless to say I now consider myself to be somewhat of an expert in PSIP having thoroughly read the specifications and the book PSIP: Program And System Information Protocol: Naming, Numbering, and Navigation for Digital Television from cover to cover.

To get the callsigns turned out to be a much more complex the MCE 6 SDK has a few annoying features - one of which is the inability to provide channel names in cases where there are multiple sub-channels on the same channel number. As can be seen in the first image. Using the GetCallSigns method returns a serviceID and a callsign then by using the GetServiceIds method, which returns serviceID and channel number, one should theoretically be able to map the callsign to the channel number by using the serviceID and a common variable.


Figure 1 Channel 5.x on server

However as I mentioned earlier this does not work because for channel 5 only the serviceID of WPTVDT2 is returned with a channel number of 5.

I then shifted my focus to using XMLTV but that now requires a subscription for US guide data and the used would have to configure XMLTV as well as Media Center which would leave way to much space for mistakes. In addition to that I had not found a way for the client to match callsign to guide data yet.


Figure 2 Channel detection on client

Finally I decided to revisit getting the information from the media center database. I imported mcepg.dll into a project and voila I saw almost everything I needed. After a few hours I was able to pull the scanned analog lineup out of the database into an XML file.

 
 


Figure 3 Part of channel configuration file


Now all that was needed was to get the client side to edit the guide listing programmatically. I knew this was possible because you can import MXF formatted XML into media center. I had a look at that but it seemed more effort than it was worth. I decided to use the mcepg.dll again to edit the guide on the client side. This was also a pretty simple task except for the fact that I was getting exceptions every time I called the
Microsoft.MediaCenter.Guide.MergedChannel.AddChannelListings(Channel) method. I wrapped this in try catch and it worked fine - but I don't like hiding problems in code so I spent about a day finding out what was causing the exception (luckily I learnt to program in the days when asm was needed) - I narrowed it down to a inactive DeviceGroup. I tried a number of workarounds and finally managed to find one that would allow me to make my changes without corrupting the database of causing exceptions.


Figure 4 Client guide after channel scanning

Not only have I managed to programmatically remap scanned channels to a legitimate guide channel I have also managed to change a channel.subchannel into a channel number without any sub channels. The last image shows the guide after I did the first 2 channels 1.2 and 1.3. I know no one uses channel 1.x for anything so I just sent the channel on PSIP and major=1 and subchannel=analog channel number.


Figure 5 First 2 channels fixed

Next week I will finish up the installer and clean up a couple of issues so that I can make an alpha build and send it off to everyone that requested it. I think I might just also create a GUI for people to change their Guide information as well. I know I hate going through the "edit listing" menu and searching for a matching listing to map my clearQAM to my cablecard channels.

Thursday, July 1, 2010

Forget the MCE Extender - just stream the tuner output - phase 2

It has been a very busy few weeks, I have learned way more about AVStream and BDA than I even wanted to know :). I have finally reached a point in the development cycle where I can release an alpha version of the code. The current implementation of my tuner driver currently supports ATSC and Digital/Analog Cable (clear QAM and analog cable). The Device managed capture shows the 2 drivers installed the first one handles ATSC and the second handles QAM. I found it easier on Windows Media Center (WMC) to have 2 instances of the driver each supporting its own tuning space as opposed to one instance supporting both.
I have not managed to have WMC detect the analog portion of Cable on the QAM tuner, I know it is scanning for the channels and the signal is strong and locked. I think this may be due to the fact that the mpeg-2 encoder is not inserting any EIT/ETT information WMC may be searching for the channel identification information in the stream. I have a strong belief that if I inject this information into the transport stream (TS), WMC will detect the analog channels. These are all the channels below channel 69 on Comcast in my area. The QAM tuner will then present itself more like a Digital Cable tuner.
Support for DVB-C should not be too difficult to implement - I just need to find someone with a compatible tuner to test it for me.

What I currently have working:
A user can install one or more tuner servers with as many tuners as they want irrespective of the technology i.e. Analog (Cable only in USA), ATSC and Clear QAM.
A client system will install 1 or more tuners depending on the tuners installed on the servers one tuner is used for each technology i.e. if you only have ATSC then install 1 tuner. If ATSC and Analog/QAM is present install 2 tuners. The system is totally fault tolerant if a tuner server goes off-line the clients will immediately start polling until the server re-appears or connect to another server if one has tuners available. The state is restored with the viewer only noticing a few seconds of missing video (if switching to a new server) or a delay as long as it takes the original server to come back on-line.

What I am working on:
  • Injecting EIT/ETT into Analog stream for WMC. Done
  • Support for DVB-C.
  • Support for Set top boxes with IEEE interfaces.
  • Support for CableCard (unprotected content for now).
  • Interfacing with WMC to propogate recording requests
  • Priority handling of tuners and concurrent access for shared content.
  • etc.
I have a link here for anyone that is interested in testing the alpha when it becomes available. Register for Alpha.