/// <summary> /// Allows a programmet to set the "protocolInfo" string. /// </summary> /// <param name="protocolInfo"> /// A valid protocolInfo string must have the format /// "[protocol]:[network]:[mime type]:[info]". /// </param> /// <exception cref="Error_CannotSetProtocolInfo"> /// Thrown if the protocolInfo string is not "http-get", when the contentUri /// starts with /// <see cref="OpenSource.UPnP.AV.CdsMetadata.MediaResource.AUTOMAPFILE"/>. /// </exception> public void SetProtocolInfo(ProtocolInfoString protocolInfo) { if (this.ContentUri.StartsWith(AUTOMAPFILE)) { if (string.Compare(protocolInfo.Protocol, "http-get") != 0) { throw new Error_CannotSetProtocolInfo(this.ContentUri, protocolInfo); } } this.m_ProtocolInfo = protocolInfo; }
/// <summary> /// This is used to determine if the renderer supports a given protocol type. /// </summary> /// <param name="ProtocolInfo">The ProtocolInfo you wish to check</param> /// <returns>true if supported</returns> public bool SupportsProtocolInfo(ProtocolInfoString ProtocolInfo) { bool RetVal = false; foreach (ProtocolInfoString pis in ProtocolInfoList) { if (pis.Matches(ProtocolInfo)) { RetVal = true; break; } } return(RetVal); }
public AVConnection(AVRenderer _parent, System.String RemoteProtocolInfo, System.String PeerConnectionManager, int PeerConnectionID, DvConnectionManager.Enum_A_ARG_TYPE_Direction Direction, System.Int32 ConnectionID, System.Int32 AVTransportID, System.Int32 RcsID) { Parent = _parent; foreach (string V in DvRenderingControl.Values_A_ARG_TYPE_Channel) { MuteChannelTable[V] = false; VolumeChannelTable[V] = (UInt16)0; } _InfoString = new ProtocolInfoString(RemoteProtocolInfo); _PeerManager = PeerConnectionManager; _PeerManagerID = PeerConnectionID; Connection_ID = ConnectionID; AVTransport_ID = AVTransportID; RenderingControl_ID = RcsID; _Direction = Direction; }
protected MediaResource[] BuildResources(string Interface, IDictionaryEnumerator en) { ArrayList a = new ArrayList(); while (en.MoveNext()) { FileInfo f = (FileInfo)en.Value; MediaResource mr; ResourceBuilder.ResourceAttributes resInfo = new ResourceBuilder.ResourceAttributes(); resInfo.contentUri = "file://" + f.FullName; resInfo.protocolInfo = ProtocolInfoString.CreateHttpGetProtocolInfoString(f); mr = ResourceBuilder.CreateResource(resInfo); OpenSource.UPnP.AV.Extensions.MetaData.Finder.PopulateMetaData(mr, f); a.Add(mr); } return((MediaResource[])a.ToArray(typeof(MediaResource))); }
/// <summary> /// This method is called when an AsyncCall to GetProtocolInfo completes /// </summary> /// <param name="sender"></param> /// <param name="Source"></param> /// <param name="Sink"></param> /// <param name="e"></param> /// <param name="Handle"></param> protected void GetProtocolInfoSink(CpConnectionManager sender, System.String Source, System.String Sink, UPnPInvokeException e, object Handle) { if (e != null) { return; } if (Sink == "") { return; } // This is a temp parser to parse the supported ProtocolInfo values DText p = new DText(); p.ATTRMARK = ","; p[0] = Sink; int len = p.DCOUNT(); ProtocolInfoString istring; for (int i = 1; i <= len; ++i) { istring = new ProtocolInfoString(p[i]); // Add each individual entry ProtocolInfoList.Add(istring); } if (!this.__Init) { this.__Init = true; // Upon discovery of a renderer, we can't return the renderer to the user // until we at least parsed the supported ProtocolInfo values, otherwise // the user will experience incorrect behavior. Since we have just parsed // these values, we can fire this event. if (this.OnInitialized != null) { OnInitialized(this); } } }
/// <summary> /// Creates a media object. /// </summary> /// <param name="title">The title of the object.</param> /// <param name="file">The full path to the file.</param> /// <returns>Media object.</returns> private static IDvMedia CreateObject(string title, string file) { var fi = new FileInfo(file); var media = DvMediaBuilder.CreateItem(new MediaBuilder.item(title)); string mime, mediaClass; MimeTypes.ExtensionToMimeType(fi.Extension, out mime, out mediaClass); var resInfo = new ResourceBuilder.VideoItem { contentUri = MediaResource.AUTOMAPFILE + fi.FullName, protocolInfo = new ProtocolInfoString("http-get:*:" + mime + ":*"), size = new _ULong((ulong)fi.Length) }; var res = DvResourceBuilder.CreateResource(resInfo, true); res.Tag = fi; media.AddResource(res); if (_mimes.Contains(mime) == false) { _mimes.Add(mime); var ps = new ProtocolInfoString[_mimes.Count]; var i = 0; foreach (var mime2 in _mimes) { ps[i++] = new ProtocolInfoString("http-get:*:" + mime2 + ":*"); } _ms.SourceProtocolInfoSet = ps; } return(media); }
/// <summary> /// This method gets called when a new Request is received /// </summary> /// <param name="request"></param> /// <param name="WebSession"></param> protected void ReceiveSink(HTTPMessage request, HTTPSession WebSession) { HTTPMessage rsp = new HTTPMessage(); UTF8Encoding U = new UTF8Encoding(); if ((request.Directive == "HEAD") || (request.Directive == "GET")) { if (request.DirectiveObj == "/item.m3u") {/* * rsp.StatusCode = 200; * rsp.StatusData = "OK"; * rsp.ContentType = "audio/mpegurl"; * rsp.StringBuffer = M3UString; */ string r = request.GetTag("Range"); if (r == "") { rsp.StatusCode = 200; rsp.StatusData = "OK"; rsp.ContentType = "audio/mpegurl"; rsp.StringBuffer = M3UString; } else { rsp.StatusCode = 206; rsp.StatusData = "Partial Content"; rsp.ContentType = "audio/mpegurl"; DText rp0 = new DText(); rp0.ATTRMARK = "="; rp0[0] = r; DText rp = new DText(); rp.ATTRMARK = "-"; rp[0] = rp0[2].Trim(); if (rp[1] == "") { // LastBytes try { if (int.Parse(rp[2]) > M3UString.Length) { rsp.AddTag("Content-Range", "bytes 0-" + M3UString.Length.ToString() + "/" + M3UString.Length.ToString()); rsp.StringBuffer = M3UString; } else { rsp.AddTag("Content-Range", "bytes " + (M3UString.Length - int.Parse(rp[2])).ToString() + "-" + M3UString.Length.ToString() + "/" + M3UString.Length.ToString()); rsp.StringBuffer = M3UString.Substring(M3UString.Length - int.Parse(rp[2])); } } catch (Exception) { rsp = new HTTPMessage(); rsp.StatusCode = 400; rsp.StatusData = "Bad Request"; } } else if (rp[2] == "") { // Offset till end try { rsp.AddTag("Content-Range", "bytes " + rp[1] + "-" + M3UString.Length.ToString() + "/" + M3UString.Length.ToString()); rsp.StringBuffer = M3UString.Substring(int.Parse(rp[1])); } catch (Exception) { rsp = new HTTPMessage(); rsp.StatusCode = 400; rsp.StatusData = "Bad Request"; } } else { // Range try { if (int.Parse(rp[2]) > M3UString.Length + 1) { rsp.AddTag("Content-Range", "bytes " + rp[1] + "-" + (M3UString.Length - 1).ToString() + "/" + M3UString.Length.ToString()); rsp.StringBuffer = M3UString.Substring(int.Parse(rp[1])); } else { rsp.AddTag("Content-Range", "bytes " + rp[1] + "-" + rp[2] + "/" + M3UString.Length.ToString()); rsp.StringBuffer = M3UString.Substring(int.Parse(rp[1]), 1 + int.Parse(rp[2]) - int.Parse(rp[1])); } } catch (Exception) { rsp = new HTTPMessage(); rsp.StatusCode = 400; rsp.StatusData = "Bad Request"; } } } } else { try { int i = request.DirectiveObj.LastIndexOf("/"); string tmp = request.DirectiveObj.Substring(1, i - 1); bool hasRange = true; if (tmp.IndexOf("/") != -1) { tmp = tmp.Substring(0, tmp.IndexOf("/")); } if (FileInfoTable.ContainsKey(tmp)) { FileInfo f; if (FileInfoTable[tmp].GetType() == typeof(string)) { f = new FileInfo((string)FileInfoTable[tmp]); FileInfoTable[tmp] = f; } else { f = (FileInfo)FileInfoTable[tmp]; } ProtocolInfoString pis = ProtocolInfoString.CreateHttpGetProtocolInfoString(f); rsp.StatusCode = 200; rsp.StatusData = "OK"; rsp.ContentType = pis.MimeType; if (request.Directive == "HEAD") { rsp.AddTag("Content-Length", f.Length.ToString()); rsp.OverrideContentLength = true; } else { HTTPSession.Range[] RNG = null; if (request.GetTag("Range") != "") { long x, y; ArrayList RList = new ArrayList(); DText rp = new DText(); rp.ATTRMARK = "="; rp.MULTMARK = ","; rp.SUBVMARK = "-"; rp[0] = request.GetTag("Range"); for (int I = 1; I <= rp.DCOUNT(2); ++I) { if (rp[2, I, 1] == "") { // Final Bytes y = long.Parse(rp[2, I, 2].Trim()); x = f.Length - y; y = x + y; } else if (rp[2, I, 2] == "") { // Offset till end x = long.Parse(rp[2, I, 1].Trim()); y = f.Length - x; } else { // Full Range x = long.Parse(rp[2, I, 1].Trim()); y = long.Parse(rp[2, I, 2].Trim()); } RList.Add(new HTTPSession.Range(x, 1 + y - x)); } RNG = (HTTPSession.Range[])RList.ToArray(typeof(HTTPSession.Range)); } else { hasRange = false; } if (request.Version == "1.0") { WebSession.OnStreamDone += new HTTPSession.StreamDoneHandler(DoneSink); } // ((HTTPMessage)(new UPnPDebugObject(WebSession)).GetField("Headers")).Version = "1.0"; if (hasRange) { WebSession.SendStreamObject(f.OpenRead(), RNG, pis.MimeType); } else { FileStream fs = f.OpenRead(); long length = fs.Length; WebSession.SendStreamObject(fs, length, pis.MimeType); } return; } } else { rsp.StatusCode = 404; rsp.StatusData = "Not Found"; } } catch (Exception) { rsp.StatusCode = 404; rsp.StatusData = "Not Found"; } } WebSession.Send(rsp); return; } rsp.StatusCode = 500; rsp.StatusData = "Not implemented"; WebSession.Send(rsp); }
private void startMenuItem_Click(object sender, System.EventArgs e) { startMenuItem.Enabled = false; foreach (MenuItem i in pfcMenuItem.MenuItems) { i.Enabled = false; } foreach (MenuItem i in menuItem3.MenuItems) { i.Enabled = false; } InfoStringBox.Enabled = false; device = UPnPDevice.CreateRootDevice(900, 1, ""); device.UniqueDeviceName = Guid.NewGuid().ToString(); device.StandardDeviceType = "MediaRenderer"; device.FriendlyName = "Media Renderer (" + System.Net.Dns.GetHostName() + ")"; device.HasPresentation = false; device.Manufacturer = "OpenSource"; device.ManufacturerURL = "http://opentools.homeip.net/"; device.PresentationURL = "/"; device.HasPresentation = true; device.ModelName = "AV Renderer"; device.ModelDescription = "Media Renderer Device"; device.ModelURL = new Uri("http://opentools.homeip.net/"); UPnPService ts = new UPnPService(1, "EmptyService", "EmptyService", true, this); ts.AddMethod("NullMethod"); //device.AddService(ts); DText p = new DText(); p.ATTRMARK = "\r\n"; p[0] = this.InfoStringBox.Text; int len = p.DCOUNT(); ProtocolInfoString[] istring = new ProtocolInfoString[len]; for (int i = 1; i <= len; ++i) { istring[i - 1] = new ProtocolInfoString(p[i]); } r = new AVRenderer(MaxConnections, istring, new AVRenderer.ConnectionHandler(NewConnectionSink)); r.OnClosedConnection += new AVRenderer.ConnectionHandler(ClosedConnectionSink); if (supportRecordMenuItem.Checked == false) { r.AVT.RemoveAction_Record(); } if (supportRecordQualityMenuItem.Checked == false) { r.AVT.RemoveAction_SetRecordQualityMode(); } if (supportNextContentUriMenuItem.Checked == false) { r.AVT.RemoveAction_SetNextAVTransportURI(); } if (MaxConnections == 0) { r.Manager.RemoveAction_PrepareForConnection(); r.Manager.RemoveAction_ConnectionComplete(); } r.AVT.GetUPnPService().GetStateVariableObject("CurrentPlayMode").AllowedStringValues = new String[3] { "NORMAL", "REPEAT_ALL", "INTRO" }; r.Control.GetUPnPService().GetStateVariableObject("A_ARG_TYPE_Channel").AllowedStringValues = new String[3] { "Master", "LF", "RF" }; r.Control.GetUPnPService().GetStateVariableObject("RedVideoBlackLevel").SetRange((ushort)0, (ushort)100, (ushort)1); r.Control.GetUPnPService().GetStateVariableObject("GreenVideoBlackLevel").SetRange((ushort)0, (ushort)100, (ushort)1); r.Control.GetUPnPService().GetStateVariableObject("BlueVideoBlackLevel").SetRange((ushort)0, (ushort)100, (ushort)1); r.Control.GetUPnPService().GetStateVariableObject("RedVideoGain").SetRange((ushort)0, (ushort)100, (ushort)1); r.Control.GetUPnPService().GetStateVariableObject("GreenVideoGain").SetRange((ushort)0, (ushort)100, (ushort)1); r.Control.GetUPnPService().GetStateVariableObject("BlueVideoGain").SetRange((ushort)0, (ushort)100, (ushort)1); r.Control.GetUPnPService().GetStateVariableObject("Brightness").SetRange((ushort)0, (ushort)100, (ushort)1); r.Control.GetUPnPService().GetStateVariableObject("Contrast").SetRange((ushort)0, (ushort)100, (ushort)1); r.Control.GetUPnPService().GetStateVariableObject("Sharpness").SetRange((ushort)0, (ushort)100, (ushort)1); r.Control.GetUPnPService().GetStateVariableObject("Volume").SetRange((UInt16)0, (UInt16)100, (ushort)1); device.AddService(r.Control); device.AddService(r.AVT); device.AddService(r.Manager); //device.AddDevice(r); device.StartDevice(); //r.Start(); }
/// <summary> /// Indicates vendor specific UPNP error code of 877. /// </summary> public Error_CannotSetContentUri(ProtocolInfoString protocolInfo, string contentUri) : base(877, "Cannot set the contentUri (" + contentUri + ") to a string beginning with (" + MediaResource.AUTOMAPFILE + ") if the protocolInfo (" + protocolInfo.ToString() + ") does not indicate a protocol of \"http-get\"") { this.ContentUri = contentUri; this.ProtocolInfo = protocolInfo; }
/// <summary> /// Indicates vendor specific UPNP error code of 876. /// </summary> /// <param name="contentUri">The contentUri value of the MediaResource when the protocolInfo modification was attempted.</param> /// <param name="protocolInfo">The value of the intended protocolInfo string.</param> public Error_CannotSetProtocolInfo(string contentUri, ProtocolInfoString protocolInfo) : base(876, "Cannot set the protocolInfo string (" + protocolInfo.ToString() + ") to something other than \"http-get\", if the contentUri value starts with (" + MediaResource.AUTOMAPFILE + ").") { this.ContentUri = contentUri; this.ProtocolInfo = protocolInfo; }