Media Center Technical Discussion 1: Tuners and TuningSpaces

The Media Center TV experience driven by a flexible, multi-standard engine that works with any compatible tuner (including a good number of analog tuner cards and all BDA digital tuner cards) to create portable recordings viewable on any Windows XP machine.  To support “trick play” on Live TV (Pause, FFWD, etc.), the video engine is separated into two main segments: capture and playback.  The capture engine, controlled through the Media Center Receiver Service (ehrecvr.exe), is responsible for creating the actual recordings, including controlling tuners, creating a media stream, and optionally encrypting the stream before writing it to disk.  The playback engine, controlled through the Media Center Shell (ehshell.exe), processes media streams created by the capture engine and renders them for the user.  Everything else, as far as TV goes, is built on top of or leverages these two components.

The capture engine uses the Microsoft Unified Tuning Model, with TuningSpaces and TuneRequests, as a layer on top of the physical tuner, allowing Media Center to treat tuners agnostically.  To actually tune to a channel, Media Center first creates (or looks up) a tune request that corresponds to that channel, then submits it to the capture engine, which uses it to tell the tuner what to do.

A TuningSpace corresponds to code written specifically to handle a type of video broadcast, such as ATSC, NTSC, or DVB-T.  Some properties are present in all TuningSpaces, like its ID (e.g. {8A674B4D-1F63-11D3-B64C-00C04F79498E} for NTSC Analog Cable), and some are specific to an implementation.  The implementation-specific properties–like NetworkType or DefaultLocator for digital standards–let the capture engine configure the underlying BDA driver, and provide a way to tweak default values.  A TuningSpace can be considered a “template” for how Media Center will try to talk to the tuner card, depending on how you have it configured–mapping roughly to the old TV setting of “Antenna” or “Cable”.

All by itself, a TuningSpace is not enough to actually tune to a broadcast stream.  For that, Media Center creates a TuneRequest (by using the ITuningSpace object).  A TuneRequest can be thought of as “everything you need to know about tuning to a channel”; what it contains varies from TuningSpace to TuningSpace. For an NTSC tune request, you could expect it to contain a channel number and a reference to the TuningSpace; an ATSC tune request would contain a physical channel (the “major” channel) and a minor channel; a DVB-T tune request would contain the broadcast frequency, ONID, TSID, and SID.  All tune requests contain a reference back to the proper TuningSpace.

Media Center stores information about which TuningSpace(s) are configured on the system on a per-tuner basis in the Windows registry under the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Media Center\Service\Video\Tuners key.  If you open this key, you’ll see something like this:

The GUIDs correspond to “tuning categories”, which are digital ({71985F48-1CA1-11D3-9CC8-00C04F7971E0}) and analog ({A799A800-A46D-11D0-A18C-00A02401DCD4}), each containing subkeys that correspond to individual tuner devices.  Note that there can be more than one tuner device per physical tuner card or USB device–Media Center treats multi-tuner cards as separate devices.  I will use my Hauppauge WinTV PVR PCI II device’s entry as an example:

As you can see above, the tuner’s auto-generated GUID is {99F4E181-4B58-4258-8547-2CE73F3C0386}.  This key is created by the ehrecvr service automatically when it detects the tuner: for a PCI card, this happens at service startup; for a USB device, this happens either at service startup or when you plug in the device.  If you delete the key and restart the ehrecvr service–and the card is still installed–a key will be created with a new GUID.  If a USB device is detached and reattached to a different port it will also get a new key.

Examining the properties, there are a couple of interesting values:

  • ConfiguredTuningspace is a REG_MULTI_SZ that contains a list of the TuningSpace IDs for which this card has been configured in Media Center.
  • SupportedTuningspace contains a list of the TuningSpace IDs with which the tuner’s driver reports compatibility.  These lists can differ if the tuner supports more than one type of tuning, like some of the newer “hybrid” tuners–a card that supports both NTSC and PAL is an example of such a card. 
  • DevInstance, DevName, and DevPath are obtained from the tuner driver, and give Media Center “pointers” to the physical device.  If you open up Device Manager and look at the advanced properties for the matching device, you will find that the values map 1:1 to entries here.
  • PrefEncoder either points to another hardware ID (in the case of a tuner with hardware MPEG2 encoding) or a software encoder (e.g. ATI AIW cards).  This is populated after we successfully build a capture graph for the device, and points to the MPEG2 encoder that is included in the graph at that time.

It’s important to note that ehrecvr will create a key for every tuner device detected, whether or not it is configured in Media Center or not.  Whether it is available for tuning in Media Center is just a matter of whether the registry keys says it is.  For example, you can easily get more than 2 tuners working for scheduling, recording and Live TV viewing by editing the registry entries for the tuners to enable them.  The reason that you cannot do this through the UI is simply because there is not a good graphical way to resolve recording/viewing conflicts amongst more than 2 tuners for a given TuningSpace.  Instead of being able to choose which of the 4 tuners to “steal”, you can only choose from 2 of them.  However, with 4 tuners you’re much less likely to actually need conflict resolution, so IMHO it’s acceptable.

To actually get the n-tuner scenario working properly, every tuner must be in the same TuningSpace, and change channels the same way.  So you cannot mix STB with non-STB, Satellite with Cable, etc. This is due to limitations in the Guide and PVR engine, not in the capture or playback engines.  STB tuners are somewhat of a pain, so I recommend using Method 2 (below) if you are going to go with n-tuners on STBs.  Also, you must have an STB for each and every tuner… not a fun scenario if you have to pay for each one. 

This week’s Media Center tweak is getting N tuners working in Media Center.  There are various versions floating around out there on the internet, most of which include extra, unnecessary steps, likely because the authors figured out this stuff without the benefit of internal knowledge of the codebase, so they included everything they did to get it all working.  The version of this tweak posted on The Green Button works just like Method 2 below, but requires a reboot between each configuration run.

If you have NTSC + ATSC, you can use this method for the ATSC tuners, the NTSC tuners, or both!  The only limitations are your hard drive’s bandwidth, your system bus bandwidth, CPU time, and the number of tuners you can attach to the machine.  For NTSC that means a practical limit of about 10 tuners, if they are all recording non-DRM content.  For High Definition ATSC and DVB it’s a little more intensive, but since there’s no encoding going on (digital broadcasts are already encoded!), it actually balances out a little, with a top limit of around 7-8 tuners.  I have personally run 3 ATSC + 6 NTSC on my home system (through dual-tuner USB devices like the Adaptec AVC-3610), and it hummed right along (1 GB DDR Dual-Channel DDR 3200 RAM, Pentium 4 2.8 GHz (HT), 2x 7200 RPM 500GB Hitachi SATA drives in RAID-0 with the system/boot drive on a 40 GB PATA drive).  That’s a bit more than I need, so I backed off to only 3 NTSC (2 USB + 1 PCI) and 2 ATSC (both PCI).

Step-by-step, here’s how to get n-tuner going.  Both methods assume you’ve already installed the tuners and have the drivers installed. 

N Tuners in MCE, Method 1 (only registry editing):

  1. Stop the Media Center Receiver Service (net stop ehrecvr)
  2. Open Registry Editor (regedit.exe) and open this key:
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Media Center\Service\Video\Tuners\{GUID}
    where {GUID} is either {71985F48-1CA1-11D3-9CC8-00C04F7971E0} for Digital (ATSC or DVB-T) or {A799A800-A46D-11D0-A18C-00A02401DCD4} for Analog (NTSC or PAL).
  3. Under the {GUID} key, there will be one key per tuner device.
  4. Select the first tuner’s key.
  5. Select the UserSettings key.
  6. Set these DWORD values as follows (case sensitive, all values in hexadecimal), creating them if they do not exist:
    EnabledForMCE = 0xffffffff
    UseSTB = 0
  7. Create a REG_SZ value named UserDefName and set its value to “Tuner X”, where X is the tuner number (1 for the first tuner, 2 for the 2nd, etc.)
  8. If this is the FIRST tuner:
    RecordOrder = 0
    RecordPrefered = 0xffffffff
    WatchOrder = number of tuners – 1, e.g. for 4 tuners set this to 3
    WatchPrefered = 0

    If this is the LAST tuner:
    RecordOrder = number of tuners – 1, e.g. for 4 tuners set this to 3
    RecordPrefered = 0
    WatchOrder = 0
    WatchPrefered = 0xffffffff

    If this is a tuner somewhere in the middle:
    RecordOrder = whatever you put for the last tuner + 1
    RecordPrefered = 0
    WatchOrder = whatever you put for the last tuner – 1
    WatchPrefered = 0

    The idea here is that you increment the RecordOrder by 1 for each tuner, and decrement the WatchOrder by 1.  RecordOrder starts at 0 on the first tuner and goes up to #Tuners – 1; WatchOrder starts at #Tuners – 1 and ends at 0 on the last tuner.  RecordPrefered is true (0xffffffff) on the first tuner, false (0x00000000) everywhere else; WatchPrefered is true on the last tuner, false everywhere else.
  9. Repeat steps 7 – 10 for each tuner, adjusting the values of RecordOrder, RecordPrefered, WatchOrder and WatchPrefered as appropriate.
  10. Close Registry Editor.
  11. Start Media Center. Voila!

Yes, “Prefered” is misspelled.  We caught that after we shipped, and it’s a little late to change now…

N Tuners in MCE Method 2 (a little registry stuff, no manual editing though):

  1. Start the Media Center shell (Green Button)
  2. Go to Settings–>TV–>Set Up TV Signal
  3. Choose the 2 tuners from the list of tuners that you will configure this time (first time through, just the first 2)
  4. Close the Media Center shell.
  5. Stop the Media Center Receiver service (net stop ehrecvr or stop the service from Control Panel–>Administrative Tools–>Services)
  6. Open Registry Editor (regedit.exe) and open this key:
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Media Center\Service\Video\Tuners\{GUID}
    where {GUID} is either {71985F48-1CA1-11D3-9CC8-00C04F7971E0} for Digital (ATSC or DVB-T) or {A799A800-A46D-11D0-A18C-00A02401DCD4} for Analog (NTSC or PAL).
  7. Under the {GUID} key, there will be one key per tuner device.
  8. Find the 2 keys that were just configured by Media Center.  You can tell which ones they are by looking for the “EnabledForMCE” value under the UserSettings key.  If it is set to 0xffffffff, it was configured–otherwise it will be 0x00000000 (0).
  9. Export the 2 keys to .reg files on your hard disk. (right-click on the {GUID} key and choose Export [selected branch only]).  Make a note of where you save those files… you’re going to need them!  Name each one differently (e.g. Tuner1.reg, Tuner2.reg).
  10. Repeat steps 1 – 8 for each set of 2 tuners (if you have 3, then just then 3rd, etc.), selecting different tuners each time.
  11. Repeat steps 4 and 5.
  12. Double-click on each of the .reg files you created in step 9 to import them into the registry.
  13. Close Registry Editor.
  14. Start Media Center. Voila!

Next week we’ll talk about the PVR engine and recording management.

This posting is provided AS-IS with no warranties.  The views expressed above do not represent those of Microsoft Corporation.

Comments (28)

  1. Shahn Hogan says:

    You are the man! Thanks for the insight into how MCE works and the great tips!

  2. Jan Tielens says:

    Thanks for the tip! Do you have any idea if Vista will support more than 2 PAL tuners for example?

  3. PeterRosser says:

    Jan: MCE 2005 supports more than 2 by doing what I said above, and Vista has certainly not disabled any of that functionality. I’m afraid we don’t have any announced plans to support more tuners in the conflict resolution UI than you can currently see in the Windows Vista CTP.

  4. Jan says:

    I haven’t installed the CTP of Vista yet, so I don’t know how many tuners will be available out-of-the-box. Is it also 2 (upgradable to 4 via this "hack")? Thanks!

  5. Mike Garcen (ShadyMG) says:

    Hey peter, great writeup.

    One thing i’ve noticed, that comes & goes, is that sometimes when there’s a conflict, it doesn’t take me to the resolve conflict window to select which tuner to use. Sometimes it works though.

    I’m using 3 analog tuners (all Hauppauge PVR-150’s)

  6. Alistair says:

    Good read. Are there plans to improve the Guide and PVR engine to support different Tuning Spaces? I live in the UK and pay for satellite TV (SKY) and in order to support recording and watching simultaneously have to pay an extra monthly fee for an additional STB. I only really need 1 STB and if I could add a couple of "Freeview" DVB-T tuners in conjunction this would be perfect.

  7. psallo-repeto says:

    Actually this line is not entirely correct:

    PrefEncoder either points to another hardware ID (in the case of a tuner with hardware MPEG2 encoding) or a software encoder (e.g. ATI AIW cards).  This is auto-magically populated by examining the tuner device and whether it has an associated MPEG2 encoder onboard.

    PrefEncoder does point to a hardware or software encoder, but it is not "auto-magically populated". Instead it is populated only after we have actually successfully built the capture graph using that encoder. I wish we could fill it in "auto-magically", but our psychic powers are not that good (and there are not API’s for hardware and software encoder for association with a specific tuner)

  8. PeterRosser says:

    Thanks psallo-repeto, I’ll correct the entry 🙂  By "magic" I meant the standard geek definition: "it’s either too complicated to describe or I’m too lazy to do so right now".

  9. Roger Wicks says:

    Peter, lets say that two physical cards are placed in a MCE machine, those cards would reside in a different tuning spaces, right?  If that is the case couldn’t one of those card be configured for a composite or svideo connection?

  10. PeterRosser says:

    Roger: A tuning space corresponds to how you tune, not what you’re tuning on, but you’re still right about configuration–cards can be configured to a different tuning space depending on your setup.  Most times they are NOT configured differently, though, since Media Center does not support truly heterogeneous tuning because of Guide (and to a lesser extent PVR) design limitations.  With the exception of ATSC (see my prior posting on the details about that).

    Media Center cannot use disparate inputs, though, so if you configure one tuner to be able to directly tune to cable channels, the other tuners must also be configured in the same way (as opposed to tuning via an IR blaster and getting their data through S-Video or composite).  Media Center does not support AUX-In recording at all, at present.

  11. Shane (scrytch at gmail dot com) says:


    Thanks for the step-by-step guide.

    Just FYI, I tried Option 1 above, and whilst each of my three DVB-T tuners work fine when any combination of two are installed, when I follow your guide to get all three working together I always get one reporting that the tuner is not installed, restart the pc and try again.

    I did notice that the default UserDefName for the tuners that are setup with MCE (when I have just two going) are "Digital TV Antenna A" and "Digital TV Antenna B". Also the RecordOrder and WatchOrder do not start/end (where applicable) with a "0", they are 1 & 2 only. Not sure if this makes a difference or not.

    Any ideas?



  12. Shane (scrytch at gmail dot com) says:

    OK – just tried Method 2, and all is now working.

    Strangely, the registry entries seem to clash, but all works fine.

    I have sent you the relevant registry tree to your hotmail account just in case it helps.



  13. PeterRosser says:

    Thanks, Shane!  I’ll take a look at that and fix my lousy instructions. ^_^

  14. Shane (scrytch at gmail dot com) says:


    They’re not lousy by any stretch of the imagination! In fact they are pretty simple to follow and are far better than any other instructions available elsewhere. Just make them work for me and they’ll be perfect 🙂

    I just wish there was a tool in Media Center that could test the specs/bandwidth of the machine and allow it to work with as many tuners as it in theory can support. Artificially limiting the machine to two DVB-T tuners seems silly if it can technically support more.

    If MS "Powertoys division" can’t do it, the fact that the keys are there and can be adjusted this easily begs for someone to create a tool that can do this.




  15. Scuffs says:

    "Media Center cannot use disparate inputs, though, so if you configure one tuner to be able to directly tune to cable channels, the other tuners must also be configured in the same way (as opposed to tuning via an IR blaster and getting their data through S-Video or composite)."

    Actually this is incorrect.  The post on how to do it is located here

    It does cause a couple of problems with the guide, but those could be fixed if you guys would add recording by tuner options.

    History shows which tuner recorded which show so MCE can track which tuner is which.

    If MCE tries to record a show on the first tuner but cant tune to channel 160 it will try the second tuner, then the third, then the fourth.  If you have a STB hooked to the tuner via the svideo input on a dual card,(the other tuner uses coax) and set the tuner to be watch/record 2 (anything but 0 or 1 since MCE doesnt seem to keep track of them after that, it just uses them randomly) it will eventually find it and use it.  One problem is that if another show starts right after that show finishes with a high priority, MCE will sometimes use the same tuner which can cause another show with a lower priorty to not record on a digital channel.

    Being able to set a channel by tuner priority would solve this, even being able to set a record with tuner would work.  I know this would take a little work, but from everything I have seen it should be possible.  That is it should be possible for someone at Microsoft who has access to the code.

  16. Scuffs says:

    Perhaps you can answer this.

    Why are recordings in progress locked to viewing outside MCE until the recording is complete?

    It cant be a DRM issue since DRM content is checked througout the playback, so I ssume its placed in during recording.

  17. PeterRosser says:

    The reason recordings are locked outside MCE is because of the way that the Stream Buffer Engine (SBE, see sbe.dll and sbeio.dll) writes to the recordings.  SBE throws an exclusive lock on the file, since we resize by chunk instead of by byte.  If we did not lock the file, programs that tried to read the file while we are writing it would probably choke, since at some point they would encounter a) garbage data (random from whatever was on the disk previously at that point) or b) all zeroes.  We cannot guarantee one or the other, though on FAT drives it’s likely to be (a) and on NTFS drives it’s likely to be (b).

    We increase the file size by chunks to decrease fragmentation and increase performance.

  18. Scuffs says:

    Wholly shit.  Thank you I think you answered everything I have been trying to figure out.

    Dude this is so fucking hot.

  19. db23 says:

    Your instructions seem to be for a non STB configuration. How would one go about configuring the IR control for the N STBs? Say I wanted 4 total, I can configure the first two with the MCE wizard, how do I configure the second two? If it helps they are all the same model so should all use the same IR code set.

  20. Scuffs says:

    Accident went over this on TGB.  Right now you cant use more than 2 STBs because MCE will only support 1 USB IR reciever (whatever its really called) The reciever only has 2 IR outputs.  He used an IR blaster cable from another device that had 2 outputs on 1 cable to control 2 different devices.  

  21. Warren says:

    Ok, maybe this is a dumb question, I don’t have an ATSC tuner for testing how this shows up, so bear with me.

    If you’re not using an ATSC tuner, is it possible to hack MCE into using the EPG for a STB, thus allowing disparate program guides?

    I did a test and set up my HD-DVR to be tuned through the Svideo input on my NVTV card controlled via the IR blaster. This seemed to work fine, but I obviously had the issue that the coax tuner on the board didn’t have the full range of channels available to it.

    It seems that the code already exists to do this via the ATSC setup, or do i not understand how the ATSC tuners work with the program guide?

  22. PeterRosser says:

    db23: I bet you can use more than 2 STBs, but you would almost have to use timmmoore’s Firewire tuning hack to get them all going, what with that IR blaster limitation and all.

    warren: first off, you can hack anything to do anything, given sufficient motivation, skill and time… but in this case the cost would be pretty high.  The problem is that the EPG had to be "one-off" modified to support ATSC guide data as it is, and so it’s strongly tied to the ATSC tuning space and ATSC-specific tuning characteristics like minor channel, etc.  So, without large modifications to the EPG, it is just not in the cards to enable heterogeneous EPG scenarios.  We have no announced plans to include that for Media Center 2005. >_<

  23. sanderton says:

    Shame you can’t get the multiple sources sorted. My TiVo dates from the last century and it can handle having DVB-T and satellite connected to it at the same time with a merged EPG. Six years on and MS can’t manage it? I suspect it’s because it’s not a big issue in the US and it is way over here in Europe…

  24. Scuffs says:

    Actually it is a big issue.  First there are a lot of people with both cable and satallite.  There are complaints about 3 times a week on TGB about it.  But there are a lot more people who have a 2, 3, or 4 tuner setup with a single cable box.  These people are stuck not using the cable box, or hacking MCE to allow it, and direct cable connections.

    The UK has it worse, although I dont really understand how yours works.  But its still a huge pain in the ass over here.

  25. Bryan Zouiden says:

    Any suggestions on a particular mix of ATSC cards.  I currently have 2 avermedia HDTV cards.  Can I add another follow these great instructions and get 3 ATSC tuners to work inside MCE?  I only ask because I know when I went from 1 to 2 I had to get a different driver from avermedia.

    thanks for the guide this is going to be great.


  26. Nick says:

    Well, I have had two tuners up and running for the past 10 months and they were working well. My raid 0 config with 2 300gb drives failed,DOH! So I upgraded a bit and went to 4 300gb drives in a raid 5, NICE! Here’s the issue, I originally had used the import export method to install the 6 tuners I have and they worked GREAT! On the rare occasion I would get a 0 (zero) minute recording no big deal about rwice a month I was OK with that. Now with the same method and the regisrtry edit to # the tuners I get 0 (zero) minute recordings everyday!? I have also noticed I am also not getting all the recordings I have scheduled!? And yes there are no confilicts I should be getting all the recordings.

    Any ideas???



  27. mosquito says:

    I successfully used method #1 to get a Fusion 5, Avermedia, and ATI HD all working together without any issues for the past 2 days. I have 1 more Fusion 3 that I might try to include just for fun, although I don’t think I’ve ever run into a case where I needed 4 OTA tuners at once. Anyway, thanks for the detailed instructions….It made it very easy!