Esempio n. 1
0
 public override void RemoveMe(DataContext context, ItemManager manager)
 {
     this.Parent.CheckMediaType(MediaType.Video);
 }
Esempio n. 2
0
        public static void WriteHTMLPlayer(XmlWriter xmlWriter, ItemManager manager, string id, TimeSpan?duration, Dictionary <string, string> urlParams, string encodeParams)
        {
            string codec = null;

            if (urlParams.ContainsKey("codec"))
            {
                codec = urlParams["codec"].ToLower();
            }

            string quality = null;

            if (urlParams.ContainsKey("quality"))
            {
                quality = urlParams["quality"].ToLower();
            }

            string width = "800", height = "480";

            if (urlParams.ContainsKey("resolution"))
            {
                uint     result;
                string[] res = urlParams["resolution"].Split(new char[] { 'x' }, StringSplitOptions.RemoveEmptyEntries);
                if (res.Length == 2 && uint.TryParse(res[0], out result) && uint.TryParse(res[1], out result))
                {
                    width  = res[0];
                    height = res[1];
                }
            }
            string resolution = width + "x" + height;

            if (codec == "wmv")
            {
                string sourceUrl = string.Format("/encode/web?id={0}&codec=wmv2&width={1}&height={2}&obufsize=1024{3}", id, width, height, encodeParams);
                switch (quality)
                {
                case "low": sourceUrl += "&vidbitrate=200&audbitrate=40&quality=1&fps=25"; break;

                case "high": sourceUrl += "&vidbitrate=800&audbitrate=80&quality=51&fps=30"; break;

                default /*"medium"*/:
                    quality    = "medium";
                    sourceUrl += "&vidbitrate=400&audbitrate=40&quality=1&fps=25";
                    break;
                }

                xmlWriter.WriteRaw(@"<div>");
                xmlWriter.WriteRaw(@"<object id=""silverlightControlHost"" data=""data:application/x-silverlight-2,"" type=""application/x-silverlight-2"">");
                xmlWriter.WriteRaw(@"<param name=""source"" value=""/web/webplayer.xap"" />");
                xmlWriter.WriteRaw(@"<param name=""onError"" value=""onSilverlightError"" />");
                xmlWriter.WriteRaw(@"<param name=""background"" value=""white"" />");
                xmlWriter.WriteRaw(@"<param name=""minRuntimeVersion"" value=""4.0.60310.0"" />");
                xmlWriter.WriteRaw(@"<param name=""autoUpgrade"" value=""true"" />");
                xmlWriter.WriteRaw(@"<param name=""onLoad"" value=""silverlightControlLoaded"" />");

                xmlWriter.WriteStartElement("span");
                xmlWriter.WriteValue(LanguageResource.Install + " ");

                xmlWriter.WriteStartElement("a");
                xmlWriter.WriteAttributeString("class", "videoLink");
                xmlWriter.WriteAttributeString("href", "http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.60310.0");
                xmlWriter.WriteValue("Silverlight");
                xmlWriter.WriteEndElement();

                xmlWriter.WriteValue(string.Format(" {0} ", LanguageResource.Or));

                xmlWriter.WriteStartElement("a");
                xmlWriter.WriteAttributeString("href", sourceUrl);
                xmlWriter.WriteAttributeString("id", "videoLink");
                xmlWriter.WriteAttributeString("class", "videoLink");
                xmlWriter.WriteValue(LanguageResource.Play);
                xmlWriter.WriteEndElement();

                xmlWriter.WriteValue(" " + LanguageResource.ThroughDirectLink);
                xmlWriter.WriteEndElement();

                xmlWriter.WriteRaw(@"</object>");
                xmlWriter.WriteRaw(@"</div>");
            }
            else if (codec == "flv" || codec == "flvhd")
            {
                string sourceUrl = string.Format("/encode/web%3Fid={0}&codec={1}&width={2}&height={3}&obufsize=1024{4}",
                                                 id, (codec == "flv") ? "flv_ts" : "flv_h264_ts", width, height, encodeParams);
                switch (quality)
                {
                case "low": sourceUrl += "&vidbitrate=200&audbitrate=64&quality=1&fps=25"; break;

                case "high": sourceUrl += "&vidbitrate=1500&audbitrate=256&quality=51&fps=30"; break;

                default /*"medium"*/:
                    quality    = "medium";
                    sourceUrl += "&vidbitrate=700&audbitrate=128&quality=1&fps=25";
                    break;
                }
                sourceUrl = sourceUrl.Replace("=", "%3D").Replace("&", "%26");

                xmlWriter.WriteStartElement("a");
                xmlWriter.WriteAttributeString("id", "videoLink");
                xmlWriter.WriteAttributeString("href", sourceUrl);
                xmlWriter.WriteAttributeString("style", string.Format("display:block;margin-left:auto;margin-right:auto;width:{0}px;height:{1}px;", width, height));
                xmlWriter.WriteValue(LanguageResource.Play + " " + LanguageResource.ThroughDirectLink);
                xmlWriter.WriteEndElement();
            }
            else
            {
                codec = "html5";

                string sourceUrlQuality;
                switch (quality)
                {
                case "low": sourceUrlQuality = "&vidbitrate=200&audbitrate=64&quality=1&fps=25"; break;

                case "high": sourceUrlQuality = "&vidbitrate=1000&audbitrate=128&quality=30&fps=25"; break;

                default /*"medium"*/:
                    quality          = "medium";
                    sourceUrlQuality = "&vidbitrate=400&audbitrate=64&quality=1&fps=25";
                    break;
                }
                string sourceUrl1   = string.Format("/encode/web?id={0}&codec=webm_ts&width={1}&height={2}&obufsize=1024{3}{4}", id, width, height, sourceUrlQuality, encodeParams);
                string sourceUrl2   = string.Format("/encode/web?id={0}&codec=mp4_ts&width={1}&height={2}&obufsize=1024{3}{4}", id, width, height, sourceUrlQuality, encodeParams);
                string sourceUrlHls = string.Format("/hls/playlist.m3u8?id={0}&width={1}&height={2}&hlsSegmentTime={3}{4}{5}",
                                                    id, width, height, manager.UpnpDevice.HlsManager.DefaultSegmentTime, sourceUrlQuality, encodeParams);

                xmlWriter.WriteRaw(@"<video id=""streamVideo"" autoplay=""autoplay"" controls=""controls"" />");

                xmlWriter.WriteStartElement("source");
                xmlWriter.WriteAttributeString("src", sourceUrlHls);
                xmlWriter.WriteAttributeString("type", "application/x-mpegurl");
                xmlWriter.WriteEndElement();

                xmlWriter.WriteStartElement("source");
                xmlWriter.WriteAttributeString("src", sourceUrl1);
                xmlWriter.WriteAttributeString("type", "video/webm; codecs=\"vp8.0, vorbis\"");
                xmlWriter.WriteEndElement();

                xmlWriter.WriteStartElement("source");
                xmlWriter.WriteAttributeString("src", sourceUrl2);
                xmlWriter.WriteAttributeString("type", "video/mp4");
                xmlWriter.WriteEndElement();

                xmlWriter.WriteStartElement("span");
                xmlWriter.WriteAttributeString("id", "streamVideoSpan");

                xmlWriter.WriteStartElement("a");
                xmlWriter.WriteAttributeString("href", sourceUrl1);
                xmlWriter.WriteAttributeString("id", "videoLink");
                xmlWriter.WriteAttributeString("class", "videoLink");
                xmlWriter.WriteValue(LanguageResource.Play);
                xmlWriter.WriteEndElement();

                xmlWriter.WriteValue(" " + LanguageResource.ThroughDirectLink);
                xmlWriter.WriteEndElement();

                xmlWriter.WriteRaw(@"</video>");
            }

            xmlWriter.WriteStartElement("form");
            xmlWriter.WriteAttributeString("id", "mainForm");
            xmlWriter.WriteAttributeString("action", "/Web/player.html");
            xmlWriter.WriteAttributeString("method", "get");
            xmlWriter.WriteAttributeString("enctype", "application/x-www-form-urlencoded");

            xmlWriter.WriteRaw(string.Format(@"<input type=""hidden"" name=""id"" value=""{0}"" />", id));

            xmlWriter.WriteRaw(@"<span id=""streamPos"">0:00:00</span>");
            xmlWriter.WriteRaw(@"<div id=""seekSlider""></div>");
            xmlWriter.WriteRaw(string.Format(@"<span id=""streamLength"">{0}</span>",
                                             duration.HasValue ? duration.Value.ToString("h':'mm':'ss") : "0:00:00"));
            xmlWriter.WriteRaw(@"<div id=""volumeSlider""></div>");
            xmlWriter.WriteRaw(@"<span id=""volumeVal"">100%</span>");

            xmlWriter.WriteRaw(@"<div id=""streamToolbar"" class=""ui-widget-header ui-corner-all"">");
            xmlWriter.WriteRaw(string.Format(@"<button type=""button"" id=""playButton"">{0}</button>", LanguageResource.Play));
            xmlWriter.WriteRaw(string.Format(@"<button type=""button"" id=""pauseButton"">{0}</button>", LanguageResource.Pause));
            if (codec == "html5")
            {
                xmlWriter.WriteRaw(string.Format(@"<button type=""button"" id=""fullScreenButton"">{0}</button>", LanguageResource.Fullscreen));
            }

            xmlWriter.WriteRaw(@"<span id=""codecRadios"">");
            xmlWriter.WriteRaw(string.Format(@"<input type=""radio"" id=""html5Radio"" name=""codec"" value=""html5"" {0} /><label for=""html5Radio"">Html5</label>",
                                             codec == "html5" ? "checked=\"checked\"" : string.Empty));
            xmlWriter.WriteRaw(string.Format(@"<input type=""radio"" id=""wmvRadio"" name=""codec"" value=""wmv"" {0} /><label for=""wmvRadio"">Wmv</label>",
                                             codec == "wmv" ? "checked=\"checked\"" : string.Empty));
            xmlWriter.WriteRaw(string.Format(@"<input type=""radio"" id=""flvRadio"" name=""codec"" value=""flv"" {0} /><label for=""flvRadio"">Flash</label>",
                                             codec == "flv" ? "checked=\"checked\"" : string.Empty));
            xmlWriter.WriteRaw(string.Format(@"<input type=""radio"" id=""flvHdRadio"" name=""codec"" value=""flvhd"" {0} /><label for=""flvHdRadio"">Flash HD</label>",
                                             codec == "flvhd" ? "checked=\"checked\"" : string.Empty));
            xmlWriter.WriteRaw(@"</span>");

            bool resChecked = false;

            xmlWriter.WriteRaw(@"<span id=""resolutionRadios"">");
            foreach (string res in new[] { "1280x720", "800x480", "640x480", "320x240" })
            {
                xmlWriter.WriteRaw(string.Format(@"<input type=""radio"" id=""r{0}Radio"" name=""resolution"" value=""{0}""", res));
                if (resolution == res)
                {
                    xmlWriter.WriteRaw(@" checked=""checked""");
                    resChecked = true;
                }
                xmlWriter.WriteRaw(string.Format(@"/><label for=""r{0}Radio"">{0}</label>", res));
            }
            xmlWriter.WriteRaw(string.Format(@"<input type=""radio"" id=""r0x0Radio"" name=""resolution"" value=""0x0"" {0}/><label for=""r0x0Radio"">{1}</label>",
                                             resChecked ? string.Empty : "checked=\"checked\"", LanguageResource.Other));
            xmlWriter.WriteRaw(@"</span>");

            xmlWriter.WriteRaw(@"<span id=""qualityRadios"">");
            xmlWriter.WriteRaw(string.Format(@"<input type=""radio"" id=""lowRadio"" name=""quality"" value=""low"" {0} /><label for=""lowRadio"">{1}</label>",
                                             quality == "low" ? "checked=\"checked\"" : string.Empty, LanguageResource.Low));
            xmlWriter.WriteRaw(string.Format(@"<input type=""radio"" id=""mediumRadio"" name=""quality"" value=""medium"" {0} /><label for=""mediumRadio"">{1}</label>",
                                             quality == "medium" ? "checked=\"checked\"" : string.Empty, LanguageResource.Medium));
            xmlWriter.WriteRaw(string.Format(@"<input type=""radio"" id=""highRadio"" name=""quality"" value=""high"" {0} /><label for=""highRadio"">{1}</label>",
                                             quality == "high" ? "checked=\"checked\"" : string.Empty, LanguageResource.High));
            xmlWriter.WriteRaw(@"</span>");

            xmlWriter.WriteRaw(@"</div>");

            //Koniec form
            xmlWriter.WriteEndElement();

            xmlWriter.WriteStartElement("div");
            xmlWriter.WriteAttributeString("id", "resDlg");
            xmlWriter.WriteAttributeString("title", LanguageResource.Resolution);
            xmlWriter.WriteRaw(string.Format(@"<label for=""resDlgWidth"">{0}</label><input type=""text"" name=""resDlgWidth"" id=""resDlgWidth"" value=""{1}"" class=""text ui-widget-content ui-corner-all"">", LanguageResource.Width, width));
            xmlWriter.WriteRaw(string.Format(@"<label for=""resDlgHeight"">{0}</label><input type=""text"" name=""resDlgHeight"" id=""resDlgHeight"" value=""{1}"" class=""text ui-widget-content ui-corner-all"">", LanguageResource.Height, height));
            xmlWriter.WriteRaw(string.Format(@"<button type=""button"" id=""resDlgButton"">{0}</button>", LanguageResource.Apply));
            xmlWriter.WriteFullEndElement();
        }
Esempio n. 3
0
 public override void GetWebPlayer(XmlWriter xmlWriter, ItemManager manager, Dictionary <string, string> urlParams)
 {
     WriteHTMLPlayer(xmlWriter, manager, this.Id.ToString(), this.GetDuration(), urlParams, this.Path);
 }
Esempio n. 4
0
 public override void RefreshMetadata(DataContext context, ItemManager manager, bool recursive)
 {
 }
Esempio n. 5
0
 public override string GetThumbnailPath(ItemManager manager)
 {
     return(GetPath());
 }
Esempio n. 6
0
        public MediaServerDevice(string dataDirectory)
        {
            this.dataDirectory  = dataDirectory;
            this.settingsPath   = Path.Combine(dataDirectory, "settings.xml");
            this.databasePath   = Path.Combine(dataDirectory, "database.db");
            this.thumbnailsPath = Path.Combine(dataDirectory, "thumbnails");

            this.prefDsDemux = new List <Guid>()
            {
                new Guid(0x171252A0, 0x8820, 0x4AFE, 0x9D, 0xF8, 0x5C, 0x92, 0xB2, 0xD6, 0x6B, 0x04) //LAV Splitter
            };

            this.itemManager  = new ItemManager(this);
            this.controlPoint = new UpnpControlPoint(this);
            Version ver = Assembly.GetExecutingAssembly().GetName().Version;

            this.udn          = Guid.NewGuid();
            this.friendlyName = "Home Media Center";
            this.deviceType   = "urn:schemas-upnp-org:device:MediaServer:1";
            this.manufacturer = "Tomáš Pšenák";
            this.modelName    = "Home Media Center Server";
            this.modelNumber  = ver.Major + "." + ver.Minor;
            this.serialNumber = this.udn.ToString();
            this.modelUrl     = "http://hmc.codeplex.com";

            this.services.Add(new ConnectionManagerService(this, this.server));
            this.services.Add(new ContentDirectoryService(this, this.server));
            this.services.Add(new MediaReceiverRegistrarService(this, this.server));

            this.server.HttpServer.AddRoute("HEAD", "/Files/*", new HttpRouteDelegate(GetLibraryFile));
            this.server.HttpServer.AddRoute("GET", "/Files/*", new HttpRouteDelegate(GetLibraryFile));
            this.server.HttpServer.AddRoute("HEAD", "/Encode/*", new HttpRouteDelegate(GetLibraryEncode));
            this.server.HttpServer.AddRoute("GET", "/Encode/*", new HttpRouteDelegate(GetLibraryEncode));
            this.server.HttpServer.AddRoute("HEAD", "/Thumbnail/*", new HttpRouteDelegate(GetThumbnailFile));
            this.server.HttpServer.AddRoute("GET", "/Thumbnail/*", new HttpRouteDelegate(GetThumbnailFile));
            this.server.HttpServer.AddRoute("HEAD", "/Subtitle/*", new HttpRouteDelegate(GetSubtitleFile));
            this.server.HttpServer.AddRoute("GET", "/Subtitle/*", new HttpRouteDelegate(GetSubtitleFile));

            this.server.HttpServer.AddRoute("GET", "/", new HttpRouteDelegate(GetWeb));
            this.server.HttpServer.AddRoute("GET", "/Web/*", new HttpRouteDelegate(GetWeb));
            this.server.HttpServer.AddRoute("GET", "/favicon.ico", new HttpRouteDelegate(GetWebIco));
            this.server.HttpServer.AddRoute("GET", "/Web/player.html", new HttpRouteDelegate(GetWebPlayer));
            this.server.HttpServer.AddRoute("HEAD", "/Web/WebPlayer.xap", new HttpRouteDelegate(GetWebSilverlight));
            this.server.HttpServer.AddRoute("GET", "/Web/WebPlayer.xap", new HttpRouteDelegate(GetWebSilverlight));
            this.server.HttpServer.AddRoute("GET", "/Web/htmlstyle.css", new HttpRouteDelegate(GetWebStyle));
            this.server.HttpServer.AddRoute("GET", "/Web/jquery.lightbox-0.5.css", new HttpRouteDelegate(GetWebStyle));
            this.server.HttpServer.AddRoute("GET", "/Web/jquery-ui-1.11.1.custom.min.css", new HttpRouteDelegate(GetWebStyle));
            this.server.HttpServer.AddRoute("GET", "/Web/control.js", new HttpRouteDelegate(GetWebJavascript));
            this.server.HttpServer.AddRoute("GET", "/Web/player.js", new HttpRouteDelegate(GetWebJavascript));
            this.server.HttpServer.AddRoute("GET", "/Web/jquery-1.11.1.min.js", new HttpRouteDelegate(GetWebJavascript));
            this.server.HttpServer.AddRoute("GET", "/Web/jquery.lightbox-0.5.min.js", new HttpRouteDelegate(GetWebJavascript));
            this.server.HttpServer.AddRoute("GET", "/Web/jquery-ui-1.11.1.custom.min.js", new HttpRouteDelegate(GetWebJavascript));
            this.server.HttpServer.AddRoute("GET", "/Web/jquery.ui.touch-punch.min.js", new HttpRouteDelegate(GetWebJavascript));
            this.server.HttpServer.AddRoute("GET", "/Web/Images/folder.png", new HttpRouteDelegate(GetWebPng));
            this.server.HttpServer.AddRoute("GET", "/Web/Images/folderback.png", new HttpRouteDelegate(GetWebPng));
            this.server.HttpServer.AddRoute("GET", "/Web/Images/htmllogo.png", new HttpRouteDelegate(GetWebPng));
            this.server.HttpServer.AddRoute("GET", "/Web/Images/ui-icons_222222_256x240.png", new HttpRouteDelegate(GetWebPng));
            this.server.HttpServer.AddRoute("GET", "/Web/Images/ui-icons_454545_256x240.png", new HttpRouteDelegate(GetWebPng));
            this.server.HttpServer.AddRoute("GET", "/Web/Images/ui-icons_888888_256x240.png", new HttpRouteDelegate(GetWebPng));
            this.server.HttpServer.AddRoute("GET", "/Web/Images/htmlarrow.gif", new HttpRouteDelegate(GetWebGif));
            this.server.HttpServer.AddRoute("GET", "/Web/Images/htmlorangearrow.gif", new HttpRouteDelegate(GetWebGif));
            this.server.HttpServer.AddRoute("GET", "/Web/Images/htmlleftcontent.gif", new HttpRouteDelegate(GetWebGif));
            this.server.HttpServer.AddRoute("GET", "/Web/Images/htmlgreenbox.gif", new HttpRouteDelegate(GetWebGif));
            this.server.HttpServer.AddRoute("GET", "/Web/Images/htmlrightnav.gif", new HttpRouteDelegate(GetWebGif));
            this.server.HttpServer.AddRoute("GET", "/Web/Images/lightbox-blank.gif", new HttpRouteDelegate(GetWebGif));
            this.server.HttpServer.AddRoute("GET", "/Web/Images/lightbox-btn-close.gif", new HttpRouteDelegate(GetWebGif));
            this.server.HttpServer.AddRoute("GET", "/Web/Images/lightbox-btn-next.gif", new HttpRouteDelegate(GetWebGif));
            this.server.HttpServer.AddRoute("GET", "/Web/Images/lightbox-btn-prev.gif", new HttpRouteDelegate(GetWebGif));
            this.server.HttpServer.AddRoute("GET", "/Web/Images/lightbox-ico-loading.gif", new HttpRouteDelegate(GetWebGif));
            this.server.HttpServer.AddRoute("GET", "/Web/flowplayer.min.js", new HttpRouteDelegate(GetWebJavascript));
            this.server.HttpServer.AddRoute("HEAD", "/Web/flowplayer.swf", new HttpRouteDelegate(GetWebShockwave));
            this.server.HttpServer.AddRoute("GET", "/Web/flowplayer.swf", new HttpRouteDelegate(GetWebShockwave));
            this.server.HttpServer.AddRoute("HEAD", "/Web/flowplayer.controls.swf", new HttpRouteDelegate(GetWebShockwave));
            this.server.HttpServer.AddRoute("GET", "/Web/flowplayer.controls.swf", new HttpRouteDelegate(GetWebShockwave));
            this.server.HttpServer.AddRoute("POST", "/Web/devices.xml", new HttpRouteDelegate(GetWebDevices));

            this.hlsManager = new HlsManager(this);
        }