Beispiel #1
0
 public ItemVideoStream(ItemContainer parent, string path, string title, EncoderBuilder settings)
     : base(string.Format("{0} {1} {2}kBps {3}", title, settings.Resolution, settings.VidBitrate, settings.Audio), parent)
 {
     this.path        = path;
     this.mime        = settings.GetMime();
     this.date        = DateTime.Now;
     this.bitrate     = settings.VidBitrate;
     this.resolution  = settings.Resolution;
     this.queryString = settings.GetParamString();
     this.dlnaType    = settings.GetDlnaType();
 }
Beispiel #2
0
        public ItemStream(string title, ItemContainer parent, EncoderBuilder encBuilder)
            : base(GetTitle(title, encBuilder.Resolution, encBuilder.Video ? encBuilder.VidBitrate : encBuilder.AudBitrate, encBuilder.Audio), null, parent)
        {
            this.Mime          = encBuilder.GetMime();
            this.Date          = DateTime.Now;
            this.Resolution    = encBuilder.Resolution;
            this.SubtitlesPath = encBuilder.GetParamString();
            this.Audio         = encBuilder.Audio && !encBuilder.Video;
            this.Video         = encBuilder.Video;

            parent.SetMediaType(this.Audio ? MediaType.Audio : MediaType.Video);
        }
Beispiel #3
0
        private void SendResource(HttpRequest request, string mime, bool encode = false)
        {
            HttpResponse response = request.GetResponse();

            string name = request.Url.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries).Last();

            using (Stream resourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("HomeMediaCenter.Resources." + name))
            {
                if (encode)
                {
                    EncoderBuilder builder = EncoderBuilder.GetEncoder(request.UrlParams);

                    using (MemoryStream memStream = new MemoryStream())
                    {
                        builder.StartEncode(resourceStream, memStream);

                        response.AddHreader(HttpHeader.ContentLength, memStream.Length.ToString());
                        response.AddHreader(HttpHeader.ContentType, builder.GetMime());
                        response.SendHeaders();

                        if (request.Method == "GET")
                        {
                            memStream.Position = 0;
                            memStream.CopyTo(response.GetStream());
                        }
                    }
                }
                else
                {
                    response.AddHreader(HttpHeader.ContentLength, resourceStream.Length.ToString());
                    response.AddHreader(HttpHeader.ContentType, mime);
                    response.SendHeaders();

                    if (request.Method == "GET")
                    {
                        resourceStream.CopyTo(response.GetStream());
                    }
                }
            }
        }
Beispiel #4
0
        private void GetEncode(HttpRequest request, string path, string subtitlesPath, string encodeFeature, TimeSpan?duration)
        {
            HttpResponse response = request.GetResponse();

            request.UrlParams["source"] = path;
            if (subtitlesPath != null)
            {
                request.UrlParams["subtitles"] = subtitlesPath;
            }
            if (encodeFeature != null)
            {
                response.AddHreader("ContentFeatures.dlna.org", encodeFeature);
            }

            if (duration.HasValue)
            {
                //Je mozne seekovanie pomocou casu

                double startTimeParam = 0;
                if (request.UrlParams.ContainsKey("starttime") && double.TryParse(request.UrlParams["starttime"],
                                                                                  System.Globalization.NumberStyles.Float | System.Globalization.NumberStyles.AllowThousands,
                                                                                  System.Globalization.CultureInfo.InvariantCulture, out startTimeParam))
                {
                    //Ak je nastaveny url parameter pozicie - treba upravit dlzku
                    duration -= TimeSpan.FromSeconds(startTimeParam);
                }

                response.AddHreader("X-AvailableSeekRange", string.Format(System.Globalization.CultureInfo.InvariantCulture,
                                                                          "1 npt=0.0-{0:0.000}", duration.Value.TotalSeconds));

                if (request.Headers.ContainsKey("TimeSeekRange.dlna.org"))
                {
                    //Zistenie a nastavenie pozicie
                    string[] range = request.Headers["TimeSeekRange.dlna.org"].Split('=').Last().Split('-').Select(a => a.Trim()).ToArray();
                    double   end, start;

                    //Cas moze byt vo formate 0.000 sekundy alebo 0:00:00.0
                    if (!double.TryParse(range[0], System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out start))
                    {
                        start = TimeSpan.Parse(range[0]).TotalSeconds;
                    }
                    if (start < 0)
                    {
                        start += duration.Value.TotalSeconds;
                    }

                    if (range.Length < 2)
                    {
                        end = duration.Value.TotalSeconds;
                    }
                    else
                    {
                        TimeSpan endSpan;
                        if (double.TryParse(range[1], System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out end))
                        {
                            request.UrlParams["endtime"] = end.ToString(System.Globalization.CultureInfo.InvariantCulture);
                        }
                        else if (TimeSpan.TryParse(range[1], out endSpan))
                        {
                            request.UrlParams["endtime"] = endSpan.TotalSeconds.ToString(System.Globalization.CultureInfo.InvariantCulture);
                        }
                        else
                        {
                            end = duration.Value.TotalSeconds;
                        }
                    }

                    request.UrlParams["starttime"] = (start + startTimeParam).ToString(System.Globalization.CultureInfo.InvariantCulture);

                    response.AddHreader("Vary", "TimeSeekRange.dlna.org");
                    response.AddHreader("TimeSeekRange.dlna.org", string.Format(System.Globalization.CultureInfo.InvariantCulture,
                                                                                "npt={0:0.000}-{1:0.000}/{2:0.000}", start, end, duration.Value.TotalSeconds));
                }
            }

            string prefDsDemuxStr = GetPrefDsDemux();

            if (prefDsDemuxStr != null)
            {
                request.UrlParams["prefDsDemux"] = prefDsDemuxStr;
            }

            EncoderBuilder builder = EncoderBuilder.GetEncoder(request.UrlParams);

            response.AddHreader(HttpHeader.ContentType, builder.GetMime());
            response.AddHreader(HttpHeader.AcceptRanges, "none");
            response.AddHreader("TransferMode.dlna.org", "Streaming");
            response.SendHeaders();

            if (request.Method == "GET")
            {
                OnLogEvent(string.Format("Starting encode {0} as {1}", request.UrlParams["source"], builder.GetMime()));
                builder.StartEncode(response.GetStream());
            }
        }