UPnP / DLNA Media Server for MediaPortal 2 (3 Viewers)

mrj

Portal Pro
January 27, 2012
252
100
Hi
You can replace many if/else statement testing enums with dictionaries to reduce the number of lines.
or directly "enum.tostring().tolower()"
mrj
//Edit
I just saw this.
If you apply this to the other arguments as well, the number of code lines will be significantly reduced.
morpheus_xx already mentioned it
 
Last edited:

morpheus_xx

Retired Team Member
  • Team MediaPortal
  • March 24, 2007
    12,073
    7,459
    Home Country
    Germany Germany

    FreakyJ

    Retired Team Member
  • Premium Supporter
  • July 25, 2010
    4,024
    1,420
    Home Country
    Germany Germany
    @henso
    we just did both the same work :D But you were 3 mins faster :ROFLMAO:
    But I am still happy, so no worries^^

    At least thank you all for the suggestions!
     

    henso

    Development Group
  • Team MediaPortal
  • February 16, 2012
    2,341
    829
    Home Country
    Denmark Denmark
    But I think we agree that it would still be nice to have support for different encoders
    Agree.

    I limited the video bitrate in the default profile
    It would be better to limit the quality factor. I pushed some changes that will create smaller files.

    While ffmpeg is still transcoding you can't seek
    This is a problem with WMP AFAIK. It sends no range requests to the server. In other DLNA clients it works as expected.

    You start to transfer a file and than send another request and see if you get an answer
    I tried that. I added 5 threads that constantly download a 70 MB file in parallel while still doing the requests like before. After a few seconds the average response time is 500 ms and 100 requests/second, The file downloads average at 4-5 seconds per file. Anything more I can try? Maybe the problem is somewhere else?

    we just did both the same work
    Sorry about that. :( I thought you would look at it next week. ;)
     

    morpheus_xx

    Retired Team Member
  • Team MediaPortal
  • March 24, 2007
    12,073
    7,459
    Home Country
    Germany Germany
    @henso would you mind to make some more changes to classes?

    For codec settings lookup I suggest such kind of structure:
    C#:
        public class EncodingConfig
        {
          public Dictionary<EncodingProfile, string> Profiles { get; set; }
          public Dictionary<EncodingPreset, string> Presets { get; set; }
    
          public EncodingConfig()
          {
            Profiles = new Dictionary<EncodingProfile, string>();
            Presets = new Dictionary<EncodingPreset, string>();
          }
        }
    
        public class VideoEncodingConfig : Dictionary<VideoCodec, EncodingConfig> { }
    
        private readonly VideoEncodingConfig IntelCodecConfig = new VideoEncodingConfig
        {
          {
            VideoCodec.Mpeg2,
            new EncodingConfig
            {
              Profiles = new Dictionary<EncodingProfile, string>
              {
                { EncodingProfile.Simple, "-profile:v simple" },
                { EncodingProfile.Main, "-profile:v main" },
                { EncodingProfile.High, "-profile:v high" }
              },
              Presets = new Dictionary<EncodingPreset, string>
              {
                { EncodingPreset.Default, "-preset fast" },
                { EncodingPreset.Ultrafast, "-preset fast" },
                { EncodingPreset.Superfast, "-preset fast" },
                { EncodingPreset.Veryfast, "-preset fast" },
                { EncodingPreset.Faster, "-preset fast" },
                { EncodingPreset.Fast, "-preset fast" },
                { EncodingPreset.Medium, "-preset medium" },
                { EncodingPreset.Slow, "-preset slow" },
                { EncodingPreset.Slower, "-preset slow" },
                { EncodingPreset.Veryslow, "-preset slow" }
              }
            }
          },
          {
            VideoCodec.H264,
            new EncodingConfig
            {
              Profiles = new Dictionary<EncodingProfile, string>
              {
                { EncodingProfile.Baseline, "-profile:v baseline" },
                { EncodingProfile.Main, "-profile:v main" },
                { EncodingProfile.High, "-profile:v high" },
                { EncodingProfile.High422, "-profile:v high" },
                { EncodingProfile.High444, "-profile:v high" }
              },
             Presets = new Dictionary<EncodingPreset, string>
              {
                { EncodingPreset.Default, "-preset veryfast" },
                { EncodingPreset.Ultrafast, "-preset veryfast" },
                { EncodingPreset.Superfast, "-preset veryfast" },
                { EncodingPreset.Veryfast, "-preset veryfast" },
                { EncodingPreset.Faster, "-preset faster" },
                { EncodingPreset.Fast, "-preset fast" },
                { EncodingPreset.Medium, "-preset medium" },
                { EncodingPreset.Slow, "-preset slow" },
                { EncodingPreset.Slower, "-preset slower" },
                { EncodingPreset.Veryslow, "-preset veryslow" }
              }
            }
          }
        };
    // TODO: NVidia, SW

    The main difference to current situation is to have on single object for each encoder (SW, Intel, NVidia).

    This makes the later lookup even simpler, like:
    C#:
            VideoEncodingConfig selectedConfig;
            if (isIntel)
              selectedConfig = IntelCodecConfig;
            else if (isNvidia)
              selectedConfig = NVidiaCodecConfig;
            else
              selectedConfig = SWCodecConfig;
    
            EncodingConfig encodingConfig;
            if (selectedConfig.TryGetValue(video.TargetVideoCodec, out encodingConfig))
            {
              string profile;
              if (encodingConfig.Profiles.TryGetValue(video.TargetProfile, out profile) && !string.IsNullOrEmpty(profile))
                data.OutputArguments.Add(profile);
    
              string preset;
              if (encodingConfig.Presets.TryGetValue(video.TargetPreset, out preset) && !string.IsNullOrEmpty(preset))
                data.OutputArguments.Add(profile);
            }
     

    morpheus_xx

    Retired Team Member
  • Team MediaPortal
  • March 24, 2007
    12,073
    7,459
    Home Country
    Germany Germany
    Yesterday I tried the plugin. Unfortunately with no so good results here.

    First I tried the plugin with my existing MediaLibrary. This means, the DlnaAspect is not yet filled. Then I've started BubbleUPnP and tried to browse MP2. As result there is a huge list of:
    Code:
    [2015-10-01 20:17:43,346] [91033  ] [44       ] [ERROR] - Search failed, Key: VSS:d4b7fbb0-65eb-45f8-b4c6-c24f02dceb86, Frame: Initialise at offset 100 in file:line:column d:\Coding\MP\MP2\MP2_git\MediaPortal-2-SR15\MediaPortal\Incubator\MediaServer\Objects\MediaLibrary\MediaLibraryResource.cs:51:7
    , Line: 51
    System.InvalidOperationException: Mediaitem 86f64363-4962-4c21-a196-46bbe5e87de4 contains no DLNA video information
       bei MediaPortal.Extensions.MediaServer.DLNA.DlnaMediaItem..ctor(MediaItem item, EndPointSettings client) in d:\Coding\MP\MP2\MP2_git\MediaPortal-2-SR15\MediaPortal\Incubator\MediaServer\DLNA\DlnaMediaItem.cs:Zeile 74.
       bei MediaPortal.Extensions.MediaServer.Profiles.EndPointSettings.GetDlnaItem(MediaItem item) in d:\Coding\MP\MP2\MP2_git\MediaPortal-2-SR15\MediaPortal\Incubator\MediaServer\Profiles\ProfileObjects.cs:Zeile 431.
       bei MediaPortal.Extensions.MediaServer.Objects.MediaLibrary.MediaLibraryResource.Initialise() in d:\Coding\MP\MP2\MP2_git\MediaPortal-2-SR15\MediaPortal\Incubator\MediaServer\Objects\MediaLibrary\MediaLibraryResource.cs:Zeile 51.
       bei MediaPortal.Extensions.MediaServer.Objects.MediaLibrary.MediaLibraryVideoItem..ctor(String baseKey, MediaItem item, EndPointSettings client) in d:\Coding\MP\MP2\MP2_git\MediaPortal-2-SR15\MediaPortal\Incubator\MediaServer\Objects\MediaLibrary\MediaLibraryVideoItem.cs:Zeile 97.
       bei MediaPortal.Extensions.MediaServer.Objects.MediaLibrary.MediaLibraryHelper.InstansiateMediaLibraryObject(MediaItem item, String baseKey, BasicContainer parent, String title) in d:\Coding\MP\MP2\MP2_git\MediaPortal-2-SR15\MediaPortal\Incubator\MediaServer\Objects\MediaLibrary\MediaLibraryHelper.cs:Zeile 109.
       bei MediaPortal.Extensions.MediaServer.Objects.MediaLibrary.MediaLibraryHelper.InstansiateMediaLibraryObject(MediaItem item, String baseKey, BasicContainer parent) in d:\Coding\MP\MP2\MP2_git\MediaPortal-2-SR15\MediaPortal\Incubator\MediaServer\Objects\MediaLibrary\MediaLibraryHelper.cs:Zeile 84.
       bei MediaPortal.Extensions.MediaServer.Objects.MediaLibrary.MediaLibraryContainer.Search(String filter, String sortCriteria) in d:\Coding\MP\MP2\MP2_git\MediaPortal-2-SR15\MediaPortal\Incubator\MediaServer\Objects\MediaLibrary\MediaLibraryContainer.cs:Zeile 86.
    I think if an Item doesn't have a DlnaAspect it should be excluded before and the exceptions should be avoided. This could be achieved by adding the DlnaAspect-ID as a required MIA, then only MIs are returned that have it.

    Next try: I removed my shares and tried to let the MIs imported to fill the DlnaAspect. I've run the MP2-Server in console mode (-c as argument), not as service. My sources are network shares. During this import the log is flooded by:
    Code:
    [2015-10-01 20:24:34,953] [502639 ] [14       ] [ERROR] - MediaAnalyzer: Failed to extract media type information for resource '\\LS-WXLD09\Media\Musik\Alben\Anastacia - Anastacia\Anastacia - Anastacia - 06 - I Do (feat. Sonny of P.O.D.).mp3', Result: , ExitCode: -2147483648, Success: False
    [2015-10-01 20:24:35,480] [503167 ] [85       ] [ERROR] - MediaAnalyzer: Failed to extract media type information for resource '\\LS-WXLD09\Media\Musik\Alben\Anastacia - Anastacia\Anastacia - Anastacia - 08 - [2015-10-01 20:24:36,577] [504264 ] [95       ] [INFO ] - DlnaMediaServer: Exception reading resource '{03dd2da6-4da8-4d3e-9e55-80e3165729a3}:////LS-WXLD09/Media/Musik/Alben/Anastacia - Anastacia/Anastacia - Anastacia - 09 - Sexy Single.mp3' (Text: 'Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.')
    This looks like no process is able to access the resources on UNC share. I'm not sure if this isn't a problem of our impersonation handling? @MJGraf what do you think? I will test this build as Service as next to check if it works with System account.
     

    henso

    Development Group
  • Team MediaPortal
  • February 16, 2012
    2,341
    829
    Home Country
    Denmark Denmark
    This could be achieved by adding the DlnaAspect-ID as a required MIA, then only MIs are returned that have it.
    The problem with that approach is that I'm not only searching for one type of MIA but multiple. When I want to search for all media of type Image, Video or Audio, I can't put the DLNA MIA's as required, because Images don't have DLNA aspect for audio and so on. I will catch the exception instead and write a warning in the logs or should it be a debug message?
     

    FreakyJ

    Retired Team Member
  • Premium Supporter
  • July 25, 2010
    4,024
    1,420
    Home Country
    Germany Germany
    I would say warning :)
    Because there is something wrong if you don't have these aspects xD
     

    Users who are viewing this thread

    Top Bottom