public void Initialise()
        {
            DlnaMediaItem dlnaItem = Client.GetLiveDlnaItem(ChannelId);
            var           url      = DlnaResourceAccessUtils.GetBaseResourceURL() + DlnaResourceAccessUtils.GetResourceUrl(Key + (dlnaItem.IsSegmented ? "/playlist.m3u8" : ""), Client.ClientId);

            BitRate               = null;
            SampleFrequency       = null;
            NumberOfAudioChannels = null;
            Size          = null;
            BitsPerSample = null;
            ColorDepth    = null;
            Duration      = null;
            var dlnaProtocolInfo = DlnaProtocolInfoFactory.GetProfileInfo(dlnaItem, Client.Profile.ProtocolInfo);

            if (dlnaProtocolInfo != null)
            {
                ProtocolInfo = dlnaProtocolInfo.ToString();
            }
            if (dlnaItem.Metadata == null)
            {
                throw new DlnaAspectMissingException("No DLNA metadata found for MediaItem " + dlnaItem.MediaItemId);
            }
            if (dlnaItem.IsImage == false)
            {
                if (dlnaItem.Metadata.Bitrate > 0)
                {
                    BitRate = Convert.ToUInt32((double)dlnaItem.Metadata.Bitrate / 8.0);
                }
                if (dlnaItem.Audio[0].Frequency > 0)
                {
                    SampleFrequency = Convert.ToUInt32(dlnaItem.Audio[0].Frequency);
                }
                if (dlnaItem.Audio[0].Channels > 0)
                {
                    NumberOfAudioChannels = Convert.ToUInt32(dlnaItem.Audio[0].Channels);
                }
            }
            if (dlnaItem.IsVideo == true)
            {
                Resolution = dlnaItem.Video.Width + "x" + dlnaItem.Video.Height;
            }
            else if (dlnaItem.IsImage == true)
            {
                Resolution = dlnaItem.Image.Width + "x" + dlnaItem.Image.Height;
            }

            Uri = url;
        }
Esempio n. 2
0
        /// <summary>
        /// Returns a DLNA media item based on the given client and request
        /// </summary>
        /// <returns>Returns the requested DLNA media item otherwise null</returns>
        internal static StreamItem GetNewStreamItem(EndPointSettings client, Uri uri)
        {
            if (STREAM_ITEMS.TryGetValue(client.ClientId, out var currentStreamItem))
            {
                return(currentStreamItem);
            }

            currentStreamItem = new StreamItem(uri.Host);

            Guid          mediaItemGuid = Guid.Empty;
            DlnaMediaItem dlnaItem      = null;
            int           channel       = 0;

            if (DlnaResourceAccessUtils.ParseMediaItem(uri, out mediaItemGuid))
            {
                if (mediaItemGuid == Guid.Empty)
                {
                    throw new InvalidOperationException(string.Format("Illegal request syntax. Correct syntax is '{0}'", DlnaResourceAccessUtils.SYNTAX));
                }

                if (!client.DlnaMediaItems.TryGetValue(mediaItemGuid, out dlnaItem))
                {
                    // Attempt to grab the media item from the database.
                    MediaItem item = MediaLibraryHelper.GetMediaItem(mediaItemGuid);
                    if (item == null)
                    {
                        throw new Exception(string.Format("Media item '{0}' not found.", mediaItemGuid));
                    }

                    dlnaItem = client.GetDlnaItem(item);
                }

                if (dlnaItem == null)
                {
                    throw new Exception(string.Format("DLNA media item '{0}' not found.", mediaItemGuid));
                }
            }
            else if (DlnaResourceAccessUtils.ParseTVChannel(uri, out channel))
            {
                dlnaItem = client.GetLiveDlnaItem(channel);

                if (dlnaItem == null)
                {
                    throw new Exception(string.Format("DLNA TV channel '{0}' was never tuned.", channel));
                }
            }
            else if (DlnaResourceAccessUtils.ParseRadioChannel(uri, out channel))
            {
                dlnaItem = client.GetLiveDlnaItem(channel);

                if (dlnaItem == null)
                {
                    throw new Exception(string.Format("DLNA radio channel '{0}' was never tuned.", channel));
                }
            }

            currentStreamItem.RequestedMediaItem = mediaItemGuid;
            currentStreamItem.TranscoderObject   = dlnaItem;
            currentStreamItem.Title         = dlnaItem?.MediaItemTitle;
            currentStreamItem.LiveChannelId = channel > 0 ? channel : 0;

            return(currentStreamItem);
        }