[Approved] Improve support for analog cards that use software encoders (1 Viewer)

mm1352000

Retired Team Member
  • Premium Supporter
  • September 1, 2008
    21,577
    8,224
    Home Country
    New Zealand New Zealand
    Hi all

    -----------------------------------------------------------------------------------------
    Background:
    I have four hybrid cards in my system. With recent versions of MediaPortal I have trouble listening to FM radio or watching/recording more than one analog channel at a time.

    -----------------------------------------------------------------------------------------
    Testing/diagnosis:
    I tested each tuner individually by disabling all the other cards and they all work fine by themselves. This led me to suspect that my issues were caused by attempts to share resources that should not be shared or to use resources [that can only be used once] more than once. In particular I suspected issues around the use of audio and video encoders (all four of my cards use software encoders rather than hardware encoders to support analog TV and FM).

    I have 3 pairs of software encoders installed on my system:
    1. Intervideo
    2. Cyberlink(Twinhan)
    3. PCTV Systems [formerly Pinnacle]

    As I suspected I found that one pair of encoders was being used for all four tuners. I believe some encoders may support encoding for multiple tuners simultaneously, but I suspect that some or all of mine do not for the following reasons:

    1. When tuning an FM station, all analog tuners must be tested to see if they support FM radio. This can only be determined once the tuner graph has been built. On my system this means that four graphs have to be built. All four graphs use the same audio and video encoders. Once it is determined that all four tuners support FM radio (because they do), TV Server attempts to tune and start timeshifting on the first analog tuner. Tuning is successful, however timeshifting fails. The server waits 15 seconds for audio and video to be seen but they never arrive. This pattern continues for the next two tuners; tuning succeeds but timeshifting fails to start. On the last tuner tuning succeeds as well... and timeshifting also succeeds. Note that the last tuner is also the last tuner to have had its graph built. I don't think this is a coincidence.

    2. When tuning a TV station on a second tuner a second analog graph will have to be built (assuming an FM radio station hasn't yet been tuned). The second graph is built using the same software encoder pair as the first graph. Tuning is successful, however timeshifting fails after waiting 15 seconds for audio to arrive.

    -----------------------------------------------------------------------------------------
    A solution:
    1. I have created a patch that prevents audio and video encoders from being used more than once [by MediaPortal]. Unfortunately it doesn't seem to be possible to query the filter itself to determine whether it has already been used. This means that usage outside MediaPortal cannot be taken into account. This assumption might well be wrong because I don't have a whole lot of experience with DirectShow. Anyhow the solution I have implemented adds two (one for audio compressors, one for video compressors) private static lists to the TVLibrary.Implementations.Analog.Components.Encoder class. The lists are checked and updated each time an analog graph is built, and updated each time an analog graph is disposed. I use locking to ensure that the lists are only accessed by one thread at a time.

    This change allows me to watch/record up to three analog TV/FM streams on my system successfully.

    2. In addition: I mentioned earlier that when I tune to an FM station for the first time the TVServer has to build four graphs (one for each tuner). This takes quite a long time!

    "AdvancedCardAllocation.GetAvailableCardsForChannel took 6673 msec"

    I thought it would be a good idea to swap the order of the CanTune and IsChannelMappedToCard checks in the TvService.CardManagement.CardAllocation.AdvancedCardAllocation.GetAvailableCardsForChannel() function. Checking CanTune() for an FM channel requires the full tuner graph to be built. If you can reduce the number of graphs that have to be built then you can speed up this process quite significantly. If you check IsChannelMappedToCard first and FM channels are only mapped to 1 tuner (instead of four) then you save the time that it takes to build 3 graphs. Of course this time can only be saved on the first attempt to tune an FM channel because after that the graphs would already be built, but still... Hopefully all of that makes sense.

    Better fix already in SVN...

    3. Finally, I have found that some of my tuners will not tune to FM after watching analog TV. The issue is *1 line* in the TVLibrary.Implementations.Analog.Graphs.Analog.TvCardAnalog.Tune() function:

    _encoder.UpdatePinVideo(channel.IsTv, _graphBuilder);

    The effect is to connect the video pin if changing from FM to TV and disconnect it if changing from TV to FM. Perhaps some encoders require this, however at least one of the encoders on my machine does not. In fact, it prevents the channel from successfully changing and the TV Server is forced to use a different tuner.

    Assumed hardware-specific ==> will be kept as a private fix for me...
    -----------------------------------------------------------------------------------------
    Feedback:
    I welcome any comments and feedback, particularly about detecting whether a filter is already being used.
    - I am running SVN head on my machine. The changes related to software encoder prioritisation that misterd has added (see here) work well for me. Perhaps if some encoders support simultaneous use with multiple tuners, a simultaneousUseSupported column could be added to the new softwareencoder table. Likewise, a disconnectVideoPinForRadio column could be added to indicate whether the video pin should be disconnected when changing to radio.

    Thanks for reading...

    -----------------------------------------------------------------------------------------
    Update 25 October 2010
    I discovered that the lists of encoders were not being updated properly when analog graphs were destroyed because for some reason it was not possible to get the compressor/encoder filter names in the encoder dispose function. The workaround is to store the names of the encoders as private instance variables. These variables are set when the encoders are selected and unset when the encoder instance is disposed. Sorry for any inconvenience.

    -----------------------------------------------------------------------------------------
    Update 11 January 2011
    Team member MisterD informed me that some encoders do support encoding multiple channels at once. I will be adding a setting in the encoder priority tab to support this. In the meantime, back to WIP...

    -----------------------------------------------------------------------------------------
    Update 26 January 2011
    New (and hopefully, final) patch available. I confirmed MisterD's observation that some encoders support simultaneous use with multiple tuners. On my system the ATI AVIVO encoders can be simultaneously used with all four of my analog (hybrid) tuners - it takes 80-90% of my Core2 e6600 2.4GHz CPU, but it can be done. ;)

    Changes:
    - issue 2 already committed to SVN in a separate patch
    - issue 3 *not* included (at this point I consider the fix to be hardware-specific)
    - additional "reuse" column on each of the grids on the software encoders configuration tab to indicate/control whether an encoder can be used with multiple tuners at once
    - additional "reuse cap" setting at the bottom of the software encoders configuration tab to specify the maximum number of times that each encoder can be reused
    (- extra debug included only while testing)

    -----------------------------------------------------------------------------------------
    Update 26 January 2011
    Minor changes in response to feedback from MisterD (thank you :)).
    - rows no longer resizeable and squashed a little
    - columns use total width of lists
    - a little refactoring to improve code efficiency
    - remove extra debug

    Note that versions 2 and 3 require DB structure changes.
     

    sdf

    Portal Pro
    September 29, 2006
    292
    42
    Home Country
    Italy Italy
    I think this definitely the way to go, because analog (especially fm) tuner doesn't work in MP (referring to software cards).
    Only a suggestion: do you think there's the possibility to choose the encoder and muxer (i.e. manually build the graph) for cards that use software encoders?
    This because every card works with some encoder and others not. For example my Pinnacle 3010iX works best with pinnacle encoders. I think that choosing from a combo box muxer, audio and video encoder (or give user the possibility to manually build the graph) should be the optimal solution, also because we could try with graphedit first variuos combinations. This way it could be also very easy to implement radio recording (via directshow filters). I've already tried with graphedit and it wotks perfectly (with my card).
    Bye,
    sdf
     

    mm1352000

    Retired Team Member
  • Premium Supporter
  • September 1, 2008
    21,577
    8,224
    Home Country
    New Zealand New Zealand
    Hi sdf

    Take a look at misterd's work here. He has created a patch that allows us to prioritise our software encoders. This will allow you to prioritise the use of the Pinnacle/PCTV Systems encoder. It has already been accepted by the developers and will be included in MediaPortal 1.2.0 (a good reason to upgrade!). As I said in the original post, I have patched my version already and it works really well for me. You may want to try it as well (considering that I have 2 Pinnacle 7010ix's, which are very similar to your 3010ix). Note that if you use the PCTV Systems encoders then you will have to add the encoder names to the softwareencoders table in your database (see here).

    Having said that, analog TV and FM already almost worked for me. Some steps to follow for you:
    1. I had to make this modification to get FM to work properly.
    2. Install misterd's patch.
    3. Add the PCTV Systems encoders to the database if necessary (as mentioned above).
    4. I set up my cards as hybrid cards in TV Server
    5. Also in TV Server: I set the analog cards to be stopped rather than paused. The DVB-T cards can still be paused.
    6. Apply this patch.
    After that you should be good to go!

    A few more comments:
    - Setting up the graphs for analog cards with software encoders can be quite complicated. Typically it is beyond the understanding or ability of most users. I'd consider myself to be quite an advanced user but I would struggle to do that! In my opinion MediaPortal does an *excellent* job with graphs (you should see the code!). I think it would be difficult to create a user interface to do the same job. Furthermore, analog cards are becoming less and less useful as digital TV becomes more prevalent. I think the developers would say that it is not worth their time to work on this. In fact I would be surprised if there are any improvements to analog support in MediaPortal 2. Who knows - analog support may even be dropped altogether!

    - MediaPortal stores the graphs that it uses for your tuners in the TV Server configuration directory. For me (on Windows XP) that is C:\Documents and Settings\All Users\Application Data\Team MediaPortal\MediaPortal TV Server. Look at analog.grf with either GraphEdit or GraphStudio (note: my graph with the Intervideo encoders is attached). I have never tried to modify these because I think it would be a bad idea, but if you are desperate you may want to try changing them and see what happens.

    - MediaPortal uses the Cyberlink muxer which is distributed with MediaPortal. This is not something that can be chosen.
     

    Attachments

    • Graphs.zip
      5.9 KB

    mm1352000

    Retired Team Member
  • Premium Supporter
  • September 1, 2008
    21,577
    8,224
    Home Country
    New Zealand New Zealand
    Updated version attached to the first post.
    Enjoy! :)
     

    sdf

    Portal Pro
    September 29, 2006
    292
    42
    Home Country
    Italy Italy
    mm1352000,
    thank you so much for your preciuos suggestions.
    I've already tried many of them.
    Now I know that cyberlink muxer is hard coded.
    As you already know, many encoders need that specific muxer, otherwise the graph will not be built.
    And many tuner filters need some specific software encoders.
    The patch from MisterD is sometyhing that goes in that direction, trying to make a custom graph.
    The solution could be to build only the part of the graph that puts the encoders and muxer, leaving the possibility to build the graph automatically to the not so much impaired user.
    I'm not a programmer and didn't see the MP code, but it should be three combo box and a checkbox.
    Anyway, thank you very much.
    Bye,
    sdf
     

    mm1352000

    Retired Team Member
  • Premium Supporter
  • September 1, 2008
    21,577
    8,224
    Home Country
    New Zealand New Zealand
    sdf,

    I'm sorry I just assumed you were a programmer! Can I help with more specific instructions or specific issues? Maybe I could help you build DLLs for your version of TV Server. Please - I'd be happy to help if I can :)

    My limited experience with software encoders leads me to agree with you. There are certainly incompatibilities. In fact, I can't get my 7010ix's to use the PCTV Systems/Pinnacle encoders that come with TVCenter!!! Can you provide me with a screenshot of the graph that you built that worked for you?

    The problem with the combo boxes that you talk about is that the tuner/capture filters have different outputs. Here is a comment from the code that might help to explain:

    Code:
        /// Adds the multiplexer filter to the graph.
        /// several posibilities
        ///  1. no tv multiplexer needed
        ///  2. tv multiplexer filter which is connected to a single encoder filter
        ///  3. tv multiplexer filter which is connected to two encoder filter (audio/video)
        ///  4. tv multiplexer filter which is connected to the capture filter
        /// at the end this method the graph looks like this:
        /// 
        ///  option 2: single encoder filter
        ///    [                ]----->[                ]      [             ]
        ///    [ capture filter ]      [ encoder filter ]----->[ multiplexer ]
        ///    [                ]----->[                ]      [             ]
        ///
        ///
        ///  option 3: dual encoder filters
        ///    [                ]----->[   video        ]    
        ///    [ capture filter ]      [ encoder filter ]------>[             ]
        ///    [                ]      [                ]       [             ]
        ///    [                ]                               [ multiplexer ]
        ///    [                ]----->[   audio        ]------>[             ]
        ///                            [ encoder filter ]      
        ///                            [                ]
        ///
        ///  option 4: no encoder filter
        ///    [                ]----->[             ]
        ///    [ capture filter ]      [ multiplexer ]
        ///    [                ]----->[             ]

    Not all graphs need a multiplexor. Some graphs need one encoder, others need 2, some don't need any and only require a multiplexor...

    Aside from that, I can recommend the ATI encoders that come *free* with the Avivo package. They seem to provide the best picture with no issues for my 7010ix...
     

    sdf

    Portal Pro
    September 29, 2006
    292
    42
    Home Country
    Italy Italy
    mm1352000,
    I will try ati codecs (I remember last time I tried they didn't work).
    I completely agree with you, that there are so many cards and every card has his own filter, combo encoder/filter/muxer and so on.
    In fact, I think that every one could try to build the graph with graphedit and graphstudio, and then tell Mp which filters to use.
    Another method could be to pass an .xgr file to MP and then build the graph accordingly.
    Anyway will try again and let you know.
    Sure I consider the fact that me, as a user, only want to have the software working (in my actual configuration), and you, as a programmer, want to find a solution that is generally accepted and working.
    Thank you so much for your help.
    Bye,
    sdf
     

    mm1352000

    Retired Team Member
  • Premium Supporter
  • September 1, 2008
    21,577
    8,224
    Home Country
    New Zealand New Zealand
    Hi again sdf

    Perhaps you didn't see my question: can you please post a .grf file or screenshot of the graph that worked for your 3010ix?
    Perhaps I can improve the support for the Pinnacle/PCTV Systems encoders. I couldn't get them to work myself with my Pinnacle 7010ix.

    Thank you
     

    sdf

    Portal Pro
    September 29, 2006
    292
    42
    Home Country
    Italy Italy
    Sorry, I saw it but didn't reply to it.
    I will post a .grf file working.
    Thank you,
    sdf
     

    mm1352000

    Retired Team Member
  • Premium Supporter
  • September 1, 2008
    21,577
    8,224
    Home Country
    New Zealand New Zealand
    sdf, have you had a chance to try and create the graph file for me?
     

    Users who are viewing this thread

    Top Bottom