Exemple #1
0
        private void SaveJson(String sPhysicalFilePath, string sHttpVersion, string sBuffer, ref HttpRequest req)
        {
            string resp = "";
            int ot, oid;

            int.TryParse(GetVar(sPhysicalFilePath, "oid"), out oid);
            int.TryParse(GetVar(sPhysicalFilePath, "ot"), out ot);
            bool saveObjects = true;
            try
            {
                var d = getJSONObject(sBuffer);
                if (d == null)
                    return;

                String n = d.name;
                resp = "{\"actionResult\":\"ok\"}";
                bool apply = false;
                string nl = n.ToLowerInvariant();
                switch (nl)
                {
                    default:
                    {
                        resp = "{\"error\":\"" + nl + " not recognized\"}";
                        saveObjects = false;
                    }
                        break;
                    case "liveupdate":
                    {
                        switch (ot)
                        {
                            case 1:
                            {
                                var c = MainForm.Microphones.FirstOrDefault(p => p.id == oid);
                                if (c != null)
                                {
                                    PopulateObject(d, c);
                                }
                            }
                                break;
                            case 2:
                            {
                                var c = MainForm.Cameras.FirstOrDefault(p => p.id == oid);
                                if (c != null)
                                {
                                    PopulateObject(d, c);
                                }
                            }
                                break;
                        }
                        apply = true;
                        saveObjects = false;
                    }
                        break;
                    case "editpelco":
                    {
                        var c = MainForm.Cameras.FirstOrDefault(p => p.id == oid);
                        if (c != null)
                        {
                            PopulateObject(d, c);
                        }
                    }
                        break;
                    case "settings":
                    {
                        PopulateObject(d, MainForm.Conf);
                        if (!string.IsNullOrEmpty(MainForm.Conf.Archive))
                        {
                            MainForm.Conf.Archive = MainForm.Conf.Archive.Replace("/", @"\");
                            if (!MainForm.Conf.Archive.EndsWith(@"\"))
                                MainForm.Conf.Archive += @"\";
                        }
                        ReloadAllowedIPs();
                        ReloadAllowedReferrers();
                        MainForm.SaveConfig();
                        saveObjects = false;
                    }
                        break;
                    case "editftpserver":
                    {
                        resp = "{\"actionResult\":\"reloadFTPServers\"}";
                        if (d.ident == "new")
                        {
                            d.ident = Guid.NewGuid().ToString();
                            var cfgs = new configurationServer {ident = d.ident};
                            var l = MainForm.Conf.FTPServers.ToList();
                            l.Add(cfgs);
                            MainForm.Conf.FTPServers = l.ToArray();
                        }

                        PopulateObject(d, MainForm.Conf.FTPServers.First(p => p.ident == d.ident.ToString()));
                        MainForm.SaveConfig();
                        saveObjects = false;
                    }
                        break;
                    case "editstorage":
                    {
                        resp = "{\"actionResult\":\"reloadStorage\"}";
                        if (d.ident.ToString() == "new")
                        {
                            d.ident = MainForm.Conf.MediaDirectories.Max(p => p.ID) + 1;
                        }
                        int idnew = Convert.ToInt32(d.ident);
                        d.ident = idnew;

                        var md = MainForm.Conf.MediaDirectories.FirstOrDefault(p => p.ID == idnew);
                        bool ndir = false;
                        if (md == null)
                        {
                            md = new configurationDirectory {ID = d.ident, Entry = ""};
                            ndir = true;
                        }

                        var exdir = md.Entry;
                        PopulateObject(d, md);
                        md.Entry = md.Entry.Replace("/", @"\");
                        if (!md.Entry.EndsWith(@"\"))
                            md.Entry += @"\";

                        try
                        {
                            if (!Directory.Exists(md.Entry))
                            {
                                throw new Exception("Invalid Directory");
                            }
                        }
                        catch (Exception ex)
                        {
                            if (exdir != "")
                                md.Entry = exdir;
                            resp = "{\"actionResult\":\"reloadStorage\",\"error\":\"" + ex.Message.JsonSafe() + "\"}";
                            break;
                        }

                        if (ndir)
                        {
                            var l = MainForm.Conf.MediaDirectories.ToList();
                            l.Add(md);
                            MainForm.Conf.MediaDirectories = l.ToArray();
                        }
                        else
                        {
                            var di = new DirectoryInfo(exdir);
                            var di2 = new DirectoryInfo(md.Entry);
                            if (di.ToString() != di2.ToString())
                            {
                                var t = new Thread(() => Helper.CopyFolder(exdir, md.Entry)) {IsBackground = true};
                                t.Start();
                                resp =
                                    "{\"actionResult\":\"reloadStorage\",\"message\":\"Media is being copied to the new location.\"}";
                            }
                        }

                        MainForm.SaveConfig();
                        saveObjects = false;
                    }
                        break;
                    case "editcamera":
                        {
                            var c = MainForm.Cameras.FirstOrDefault(p => p.id == oid);
                            if (c != null)
                            {
                                var olddir = c.directory;
                                PopulateObject(d, c);
                                apply = true;
                                var newdir = c.directory;
                                if (olddir.ToLowerInvariant() != newdir.ToLowerInvariant())
                                {
                                    if (!Helper.IsAlphaNumeric(newdir))
                                    {
                                        c.directory = olddir;
                                        resp = "{\"error\":\"Directory invalid. Should be alphanumeric eg: ABCD.\"}";
                                    }
                                    else
                                    {
                                        var fullolddir = Helper.GetMediaDirectory(2, c.id) + "video\\" + olddir + "\\";
                                        var fullnewdir = Helper.GetMediaDirectory(2, c.id) + "video\\" + newdir + "\\";
                                        try
                                        {
                                            Directory.Move(fullolddir, fullnewdir);
                                        }
                                        catch (Exception ex)
                                        {
                                            c.directory = olddir;
                                            resp = "{\"error\":\""+ex.Message.JsonSafe()+"\"}";
                                        }
                                    }
                                }
                                MainForm.InstanceReference.SaveObjectList(false);
                            }
                        }
                        break;
                    case "motionzones":
                    {
                        var c = MainForm.Cameras.FirstOrDefault(p => p.id == oid);
                        if (c != null)
                        {
                            var lz = new List<objectsCameraDetectorZone>();
                            if (d.zones != null)
                            {
                                foreach (var z in d.zones)
                                {
                                    var x = Convert.ToInt32(z["x"].Value);
                                    var y = Convert.ToInt32(z["y"].Value);
                                    var w = Convert.ToInt32(z["w"].Value);
                                    var h = Convert.ToInt32(z["h"].Value);
                                    lz.Add(new objectsCameraDetectorZone { height = h, left = x, top = y, width = w });
                                }
                            }
                            c.detector.motionzones = lz.ToArray();
                            var cw = MainForm.InstanceReference.GetCameraWindow(oid);
                            cw?.Camera?.SetMotionZones(lz.ToArray());
                        }
                        saveObjects = false;
                    }
                        break;
                    case "screenarea":
                        {
                            var c = MainForm.Cameras.FirstOrDefault(p => p.id == oid);
                            if (c != null)
                            {

                                if (d.zones != null)
                                {
                                    var z = d.zones[0];
                                    int si;
                                    int.TryParse(c.settings.videosourcestring, out si);
                                    if (Screen.AllScreens.Length <= si)
                                        si = 0;
                                    var s = Screen.AllScreens[si];
                                    var x = Convert.ToInt32((Convert.ToDecimal(z["x"].Value) / 100) * s.WorkingArea.Width);
                                    var y = Convert.ToInt32((Convert.ToDecimal(z["y"].Value) / 100) * s.WorkingArea.Height);
                                    var w = Convert.ToInt32((Convert.ToDecimal(z["w"].Value) / 100) * s.WorkingArea.Width);
                                    var h = Convert.ToInt32((Convert.ToDecimal(z["h"].Value) / 100) * s.WorkingArea.Height);
                                    //even height and width
                                    if (w % 2 != 0)
                                        w -= 1;
                                    if (h % 2 != 0)
                                        h -= 1;

                                    c.settings.desktoparea = x + "," + y + "," + w + "," + h;
                                }
                                else
                                    c.settings.desktoparea = "";
                            }
                            saveObjects = false;
                        }
                        
                        break;
                    case "pip":
                        {
                            var c = MainForm.Cameras.FirstOrDefault(p => p.id == oid);
                            if (c != null)
                            {
                                string cfg = "";
                                if (d.zones != null)
                                {
                                    foreach (var z in d.zones)
                                    {
                                        var id = Convert.ToInt32(z["id"].Value);
                                        var x = Convert.ToInt32(z["x"].Value);
                                        var y = Convert.ToInt32(z["y"].Value);
                                        var w = Convert.ToInt32(z["w"].Value);
                                        var h = Convert.ToInt32(z["h"].Value);
                                        cfg += id + "," + x + "," + y + "," + w + "," + h + "|";
                                    }
                                }
                                c.settings.pip.config = cfg.Trim('|');
                                
                                var cw = MainForm.InstanceReference.GetCameraWindow(oid);
                                if (cw?.Camera != null)
                                {
                                    cw.Camera.PiPConfig = c.settings.pip.config;
                                }

                            }
                            saveObjects = false;
                        }
                        
                        break;
                    case "editmicrophone":
                        {
                            var c = MainForm.Microphones.FirstOrDefault(p => p.id == oid);
                            if (c != null)
                            {
                                var olddir = c.directory;
                                PopulateObject(d, c);
                                apply = true;
                                var newdir = c.directory;
                                if (olddir.ToLowerInvariant() != newdir.ToLowerInvariant())
                                {
                                    if (!Helper.IsAlphaNumeric(newdir))
                                    {
                                        c.directory = olddir;
                                        resp = "{\"error\":\"Directory invalid. Should be alphanumeric eg: ABCD.\"}";
                                    }
                                    else
                                    {
                                        var fullolddir = Helper.GetMediaDirectory(2, c.id) + "video\\" + olddir + "\\";
                                        var fullnewdir = Helper.GetMediaDirectory(2, c.id) + "video\\" + newdir + "\\";
                                        try
                                        {
                                            Directory.Move(fullolddir, fullnewdir);
                                        }
                                        catch (Exception ex)
                                        {
                                            c.directory = olddir;
                                            resp = "{\"error\":\"" + ex.Message.JsonSafe() + "\"}";
                                        }
                                    }
                                } 
                                MainForm.InstanceReference.SaveObjectList(false);
                            }
                        }
                        break;
                    case "editschedule":
                        {
                            resp = "{\"actionResult\":\"reloadSchedule\"}";
                            objectsScheduleEntry s = null;
                            if (d.ident.ToString() == "new")
                            {
                                s = new objectsScheduleEntry
                                {
                                    active = true,
                                    time = 0,
                                    daysofweek = "",
                                    objectid = oid,
                                    objecttypeid = ot,
                                    parameter = "",
                                    typeid = 0
                                };
                                MainForm.Schedule.Add(s);
                            }
                            else
                            {
                                var l = MainForm.Schedule.Where(p => p.objectid == oid && p.objecttypeid == ot).ToList();
                                int i = Convert.ToInt32(d.ident);

                                if (i < l.Count)
                                {
                                    s = l[i];
                                }
                            }
                            if (s != null)
                            {
                                PopulateObject(d, s);
                            }
                        }
                        break;
                    case "editptzschedule":
                        {
                            resp = "{\"actionResult\":\"reloadPTZSchedule\"}";
                            var oc = MainForm.Cameras.First(p => p.id == oid);
                            objectsCameraPtzscheduleEntry pe;
                            if (d.ident.ToString() == "new")
                            {
                                pe = new objectsCameraPtzscheduleEntry
                                {
                                    command = "",
                                    time = new DateTime()
                                };

                                PopulateObject(d, pe);
                                var l = oc.ptzschedule.entries.ToList();
                                l.Add(pe);
                                oc.ptzschedule.entries = l.ToArray();
                            }
                            else
                            {
                                int i = Convert.ToInt32(d.ident);
                                var l = oc.ptzschedule.entries.ToList();
                                if (i < l.Count)
                                {
                                    pe = l[i];
                                    PopulateObject(d, pe);

                                }
                            }
                        }
                        break;
                    case "editaction":
                        resp = "{\"actionResult\":\"reloadActions\"}";
                        objectsActionsEntry a;
                        if (d.ident.ToString() == "new")
                        {
                            a = new objectsActionsEntry
                            {
                                type = "",
                                mode = "",
                                active = true,
                                objectid = oid,
                                objecttypeid = ot,
                                ident = Guid.NewGuid().ToString()
                            };
                            MainForm.Actions.Add(a);
                            resp = resp.Replace("PARAMS", "");
                        }
                        else
                        {
                            a = MainForm.Actions.FirstOrDefault(p => p.ident == d.ident.ToString());
                        }
                        if (a != null)
                        {
                            var p1 = a.param1;
                            PopulateObject(d, a);
                            if (Helper.WebRestrictedAlertTypes.Contains(a.type))
                            {
                                a.param1 = a.param1.Replace("/", "\\");
                                if (a.param1.IndexOf("\\", StringComparison.Ordinal)!=-1)
                                {
                                    resp = "{\"error\":\"Only filenames (not paths) are allowed in actions via the website\"}";
                                    a.param1 = p1;
                                }
                            }
                            
                            MainForm.InstanceReference.SaveObjectList(false);
                        }
                        break;
                    case "editaudiosource":
                    {
                        var c = MainForm.Microphones.FirstOrDefault(p => p.id == oid);
                        if (c != null)
                        {
                            PopulateObject(d, c);
                            
                            var vl = MainForm.InstanceReference.GetVolumeLevel(c.id);
                            if (vl != null)
                            {
                                vl.Disable();
                                vl.Enable();
                            }
                            
                        }
                        resp = "{\"actionResult\":\"waiteditobject\"}";
                    }
                        break;
                    case "editvideosource":
                        {
                            var c = MainForm.Cameras.FirstOrDefault(p => p.id == oid);
                            if (c != null)
                            {
                                PopulateObject(d, c);

                                if (c.settings.sourceindex == 9)
                                {
                                    string url = c.settings.onvifident;

                                    Uri u;
                                    if (!Uri.TryCreate(url, UriKind.Absolute, out u))
                                    {
                                        resp = "{\"error\":\"URI invalid\"}";
                                        break;
                                    }
                                    string addr = u.DnsSafeHost;
                                    var dev = MainForm.ONVIFDevices.FirstOrDefault(p => p.Address == addr);
                                    if (dev == null)
                                    {
                                        if (NV(c.settings.namevaluesettings, "profileid") == "")
                                            c.settings.namevaluesettings = NVSet(c.settings.namevaluesettings, "profileid", "0");
                                    }
                                    else
                                    {
                                        TransportProtocol tp;
                                        if (!Enum.TryParse(NV(c.settings.namevaluesettings, "transport"), true, out tp))
                                            tp = TransportProtocol.rtsp;

                                        dev.Account = new NetworkCredential
                                        {
                                            UserName = c.settings.login,
                                            Password = c.settings.password
                                        };
                                        var sessionFactory = new NvtSessionFactory(dev.Account);
                                        var profilename = NV(c.settings.namevaluesettings, "profilename");

                                        foreach (var uri in dev.Uris)
                                        {
                                            var f = sessionFactory.CreateSession(uri);
                                            dev.URL = uri.ToString();
                                            Profile[] profiles;
                                            try
                                            {
                                                profiles = f.GetProfiles().RunSynchronously();
                                            }
                                            catch (Exception ex)
                                            {
                                                Logger.LogExceptionToFile(ex, "ONVIF");
                                                continue;
                                            }

                                            dev.Profiles = profiles;
                                            var strSetup = new StreamSetup { transport = new Transport() };
                                            strSetup.transport.protocol = tp;
                                            int i = 0;
                                            foreach (var p in profiles)
                                            {
                                                try
                                                {
                                                    if (p.token == profilename)
                                                    {
                                                        var strUri = f.GetStreamUri(strSetup, p.token).RunSynchronously();
                                                        string urlAuth = strUri.uri.Replace("://", "://[USERNAME]:[PASSWORD]@");
                                                        string streamSize = p.videoEncoderConfiguration.resolution.width + "x" + p.videoEncoderConfiguration.resolution.height;

                                                        c.settings.videosourcestring = urlAuth;
                                                        c.settings.namevaluesettings = NVSet(c.settings.namevaluesettings, "profileid", i.ToString(CultureInfo.InvariantCulture));
                                                        c.settings.namevaluesettings = NVSet(c.settings.namevaluesettings, "streamsize", streamSize);

                                                        string[] sz = streamSize.Split('x');
                                                        c.settings.desktopresizewidth = Convert.ToInt32(sz[0]);
                                                        c.settings.desktopresizeheight = Convert.ToInt32(sz[1]);

                                                        break;
                                                    }
                                                    i++;
                                                }
                                                catch (Exception ex)
                                                {
                                                    Logger.LogExceptionToFile(ex, "ONVIF");
                                                }

                                            }
                                        }
                                    }
                                    c.ptz = -5;
                                }
                                
                                var cw = MainForm.InstanceReference.GetCameraWindow(c.id);
                                if (cw != null)
                                {
                                    cw.Disable();
                                    cw.Enable();
                                }
                                resp = "{\"actionResult\":\"waiteditobject\"}";
                            }

                        }
                        break;
                }
                if (apply)
                {
                    var io = MainForm.InstanceReference.GetISpyControl(ot, oid);
                    io?.Apply();
                }
            }
            catch (Exception ex)
            {
                Logger.LogExceptionToFile(ex, "JSON Parser");
            }
            if (saveObjects)
            {
                try
                {
                    MainForm.InstanceReference.SaveObjectList(false);
                }
                catch (Exception ex)
                {
                    Logger.LogExceptionToFile(ex, "JSON Parser");
                }
            }

            SendHeader(sHttpVersion, "application/json", resp.Length, " 200 OK", 0, ref req);
            SendToBrowser(resp, req);
        }
Exemple #2
0
        private void lbONVIFDevices_Click(object sender, EventArgs e)
        {
            lbONVIFURLs.Items.Clear();
            _onvifurl = "";

            if (lbONVIFDevices.SelectedIndex > -1)
            {
                lbONVIFDevices.Enabled = false;
                lbONVIFURLs.Items.Add("loading...");

                DeviceDescriptionHolder ddh = MainForm.ONVIFDevices[lbONVIFDevices.SelectedIndex];
                ddh.Account = new NetworkCredential { UserName = txtOnvifUsername.Text, Password = txtOnvifPassword.Text };
                var sessionFactory = new NvtSessionFactory(ddh.Account);

                var urls = new List<object>();

                foreach (var uri in ddh.Uris)
                {
                    var f = sessionFactory.CreateSession(uri);
                    ddh.URL = uri.ToString();
                    Profile[] profiles;
                    try
                    {
                        profiles = f.GetProfiles().RunSynchronously();
                    }
                    catch (Exception ex)
                    {
                        Logger.LogExceptionToFile(ex);
                        urls.Add("Ensure your login information is correct.");
                        continue;
                    }

                    ddh.Profiles = profiles;
                    var strSetup = new StreamSetup { transport = new Transport() };
                    TransportProtocol tp;
                    strSetup.transport.protocol = Enum.TryParse(_transports[ddlTransport.SelectedIndex].ToString(), true, out tp) ? tp : TransportProtocol.rtsp;
                    int i = 0;
                    foreach (var p in profiles)
                    {
                        var strUri = f.GetStreamUri(strSetup, p.token).RunSynchronously();
                        string urlAuth = strUri.uri.Replace("://",
                                                        "://[USERNAME]:[PASSWORD]@");
                        string uriDisp = strUri.uri;
                        string streamSize = p.videoEncoderConfiguration.resolution.width + "x" + p.videoEncoderConfiguration.resolution.height;
                        uriDisp += " (" + streamSize + ")";

                        urls.Add(new MainForm.ListItem(uriDisp, new[] { urlAuth, streamSize, ddh.Account.UserName, ddh.Account.Password, ddh.Name,i.ToString(CultureInfo.InvariantCulture)}));
                        i++;

                    }

                }
                lbONVIFURLs.Items.Clear();
                lbONVIFURLs.Items.AddRange(urls.ToArray());
                lbONVIFDevices.Enabled = true;
                _onvifurl = ddh.URL;

            }
        }
		//public ObservableCollection<MetadataUnit> MetaData { get; set; }

		void Reload(INvtSession session) {
			var vs = AppDefaults.visualSettings;

			StreamSetup strSetup = new StreamSetup() {
				stream = StreamType.rtpUnicast,
				transport = new Transport(){
					protocol = vs.Transport_Type,
					tunnel = null
				}
			};

			//TODO: provide a way of cancelation
			//try {
			//	var streamInfo = await session.GetStreamUri(strSetup, profile.token);
			//	VideoInfo.MediaUri = streamInfo.uri;
			//	VideoStartup(VideoInfo);
			//} catch (Exception err) {
			//	dbg.Error(err);
			//	throw;
			//}

			subscription.Add(
				session.GetStreamUri(strSetup, profile.token)
				.ObserveOnCurrentDispatcher()
				.Subscribe(
					uri => {
						VideoInfo.MediaUri = uri.uri;
						VideoStartup(VideoInfo);
					}, 
					err => {
					}
				)
			);
		}
		IEnumerable<FSharpAsync<Unit>> LoadStreamInfoNVT(ChannelLinkEventArgs args, StreamInfoHelper parent) {
			StreamInfoArgs strInfoArgs = new StreamInfoArgs(args.session);
			strInfoArgs.encoderResolution = new Size(args.profile.videoEncoderConfiguration.resolution.width, args.profile.videoEncoderConfiguration.resolution.height);

			var strsetup = new StreamSetup() {
				stream = StreamType.rtpUnicast,
				transport = new Transport() {
					protocol = AppDefaults.visualSettings.Transport_Type
				}
			};

			strInfoArgs.streamSetup = strsetup;

			yield return args.session.GetStreamUri(strsetup, args.profile.token).Select(muri => {
				strInfoArgs.streamUri = muri.uri;

				parent.args = strInfoArgs;
				return (Unit)null;
			});

			yield return args.session.GetVideoSourceConfiguration(args.profile.videoSourceConfiguration.token).Select(conf => {
				if (conf != null && conf.bounds != null)
					strInfoArgs.sourceResolution = new Size(conf.bounds.width, conf.bounds.height);
				else {
					strInfoArgs.sourceResolution = new Size(720, 576);
				}
				return (Unit)null;
			});
		}
		void Reload(INvtSession session) {
			var vs = AppDefaults.visualSettings;

			//vidBuff = new VideoBuffer(resolution.Width, resolution.Height);

			var streamSetup = new StreamSetup() {
				transport = new Transport() {
					protocol = AppDefaults.visualSettings.Transport_Type
				}
			};

			//TODO: provide a way of cancelation
			//VideoInfo.MediaUri = model.uri;
			//VideoStartup(VideoInfo);
			VideoStartup();

			//subscription.Add(session.GetStreamUri(strSetup, profile.token)
			//	.ObserveOnCurrentDispatcher()
			//	.Subscribe(uri => {
			//		VideoInfo.MediaUri = uri.Uri;
			//		VideoStartup(VideoInfo);
			//	}, err => {
			//	}));
		}
		void NVAMetadataClick(NVALinkEventArgs evarg) {
			ReleaseViewModels(RegionNames.reg_property);

			ContentColumn column = new ContentColumn();
			ShowView(column, "MetadataClick", RegionNames.reg_property);
			column.CreateBinding(ContentColumn.TitleProperty, LinkButtonsStrings.instance, x => x.nvaMetadata);
			var ctx = CreateActivityContext(RegionNames.reg_property, evarg.session, column);

			StreamInfoHelper strinfo = new StreamInfoHelper();
			strinfo.streamInfo = () => {
				return Apm.Iterate(LoadStreamInfoNVA(evarg, strinfo));
			};
			ctx.RegisterInstance<IStreamInfoHelper>(strinfo);

			Ctxdisp = ctx;

			StreamSetup ssetup = new StreamSetup() {
				transport = new Transport() {
					protocol = AppDefaults.visualSettings.Transport_Type
				}
			};

			//EngineControlsView.Start(new EngineControlsView.Model(null, null), container, column);
			UIdisp = NvaMetadataSettingsActivity
				 .Run(ctx, evarg.control.token, evarg.control.engineConfigToken, ssetup)
				 .ObserveOnCurrentDispatcher()
				 .Subscribe(x => {
				 }, err => {
					 dbg.Error(err);
				 });
		}
		IEnumerable<FSharpAsync<Unit>> LoadStreamInfoNVA(NVALinkEventArgs args, StreamInfoHelper parent) {
			StreamInfoArgs strInfoArgs = new StreamInfoArgs(args.session);
			//strInfoArgs.encoderResolution = new Size(args.profile.VideoEncoderConfiguration.Resolution.Width, args.profile.VideoEncoderConfiguration.Resolution.Height);

			StreamSetup strsetup = new StreamSetup() {
				stream = StreamType.rtpUnicast,
				transport = new Transport() {
					protocol = AppDefaults.visualSettings.Transport_Type
				},
			};

			strInfoArgs.streamSetup = strsetup;

			yield return args.session.GetAnalyticsDeviceStreamUri(strsetup, args.control.token).Select(muri => {
				strInfoArgs.streamUri = muri;

				parent.args = strInfoArgs;
				return (Unit)null;
			});
			var inputtoken = "";
			try {
				inputtoken = args.control.inputToken.First();
			} catch (Exception err) {
				dbg.Error(err);
			}

			yield return args.session.GetAnalyticsEngineInput(inputtoken).Select(inp => {
				strInfoArgs.encoderResolution = new Size(inp.videoInput.resolution.width, inp.videoInput.resolution.height);
				strInfoArgs.sourceResolution = new Size(inp.videoInput.resolution.width, inp.videoInput.resolution.height);
				return (Unit)null;
			});
		}
		public VideoPlayerActivityModel(StreamSetup streamSetup, Profile profile, bool showStreamUrl) {
			this.profile = profile;
			this.profileToken = profile.token;
			this.streamSetup = streamSetup;
			this.showStreamUrl = showStreamUrl;
			this.metadataReceiver = null;
		}
		public VideoPlayerActivityModel(StreamSetup streamSetup, string profileToken, bool showStreamUrl, IMetadataReceiver metadataReceiver) {
			this.profile = null;
			this.profileToken = profileToken;
			this.streamSetup = streamSetup;
			this.showStreamUrl = showStreamUrl;
			this.metadataReceiver = metadataReceiver;
		}
		void VideoStartup(Model model, VideoResolution resolution) {

			//subscribe to metadata
			IMetadataReceiver metadataReceiver = null;
			if (AppDefaults.visualSettings.EnableGraphicAnnotation) {
				string vaConfToken = model.engineConfToken;
				var eventMetadataProcessor = new EventMetadataProcessor();
				//eventMetadataProcessor.Processors.Add(new ObjectMotionMetadataProcessor(null, vaConfToken, movingObjectsHolder.EntityInitialized, movingObjectsHolder.EntityChanged, movingObjectsHolder.EntityDeleted));
				eventMetadataProcessor.Processors.Add(new MotionAlarmMetadataProcessor(null, vaConfToken, alarmsHolder.EntityInitialized, alarmsHolder.EntityChanged, alarmsHolder.EntityDeleted));
				eventMetadataProcessor.Processors.Add(new RegionMotionAlarmMetadataProcessor(null, vaConfToken, alarmsHolder.EntityInitialized, alarmsHolder.EntityChanged, alarmsHolder.EntityDeleted));
				eventMetadataProcessor.Processors.Add(new LoiteringAlarmMetadataProcessor(null, vaConfToken, alarmsHolder.EntityInitialized, alarmsHolder.EntityChanged, alarmsHolder.EntityDeleted));
				eventMetadataProcessor.Processors.Add(new AbandonedItemAlarmMetadataProcessor(null, vaConfToken, alarmsHolder.EntityInitialized, alarmsHolder.EntityChanged, alarmsHolder.EntityDeleted));
				eventMetadataProcessor.Processors.Add(new TripwireAlarmMetadataProcessor(null, vaConfToken, alarmsHolder.EntityInitialized, alarmsHolder.EntityChanged, alarmsHolder.EntityDeleted));
				eventMetadataProcessor.Processors.Add(new TamperingDetectorAlarmMetadataProcessor(null, vaConfToken, alarmsHolder.EntityInitialized, alarmsHolder.EntityChanged, alarmsHolder.EntityDeleted));
				var sceneMetadataProcessor = new SceneMetadataProcessor(movingObjectsHolder.EntityInitialized, movingObjectsHolder.EntityChanged, movingObjectsHolder.EntityDeleted);
				var metadataProcessor = new MetadataProcessor(eventMetadataProcessor, sceneMetadataProcessor);
				metadataReceiver = new MetadataFramer(metadataProcessor.Process);
			}

			vidBuff = new VideoBuffer(resolution.width, resolution.height);

			var streamSetup = new StreamSetup() {
				transport = new Transport() {
					protocol = AppDefaults.visualSettings.Transport_Type
				}
			};

			VideoPlayerView playview = new VideoPlayerView();
			disposables.Add(playview);

			player.Child = playview;

			playview.Init(new VideoPlayerView.Model(
				streamSetup: streamSetup,
				mediaUri: new MediaUri() { 
					uri = model.uri 
				},
				encoderResolution: new VideoResolution() {
					height = resolution.height,
					width = resolution.width
				},
				isUriEnabled: false, //TODO if true then annotation is not positioned correctly
				metadataReceiver: metadataReceiver
			));

			uriString.Visibility = System.Windows.Visibility.Visible;
			uriString.Text = model.uri;
		}