111 lines
3.6 KiB
C#
111 lines
3.6 KiB
C#
using LibVLCSharp.Shared;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.DirectoryServices.ActiveDirectory;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace robospot_camera_finder
|
|
{
|
|
public partial class StreamViewer : Form
|
|
{
|
|
public LibVLC _libVLC;
|
|
public MediaPlayer _mp;
|
|
|
|
string username = "admin";
|
|
string password = "RoboSpot10";
|
|
string cam_ip = "";
|
|
|
|
int max_zoom_pulse = 9999;
|
|
int min_zoom_pulse = 10;
|
|
|
|
public StreamViewer(string name, string ip)
|
|
{
|
|
InitializeComponent();
|
|
_libVLC = new LibVLC();
|
|
_mp = new MediaPlayer(_libVLC);
|
|
cam_ip = ip;
|
|
|
|
timerUpdateZoom.Start();
|
|
updateZoomSlider();
|
|
|
|
videoView.MediaPlayer = _mp;
|
|
var media = new Media(_libVLC, new Uri("rtsp://" + ip + "/profile2/media.smp"));
|
|
media.AddOption(":network-caching=25");
|
|
_mp.Play(media);
|
|
media.Dispose();
|
|
this.Text = name;
|
|
}
|
|
|
|
private void updateZoomSlider()
|
|
{
|
|
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://" + cam_ip + "/stw-cgi/ptzcontrol.cgi?msubmenu=query&action=view&Query=Zoom");
|
|
request.Credentials = new NetworkCredential(username, password);
|
|
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
|
string text;
|
|
using (var sr = new StreamReader(response.GetResponseStream())) { text = sr.ReadToEnd(); }
|
|
string[] resp_lines = text.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
|
|
string zoom_value = resp_lines[1].Substring(resp_lines[1].LastIndexOf('=') + 1);
|
|
tbZoom.Value = int.Parse(zoom_value);
|
|
|
|
}
|
|
|
|
private void sendZoomValue(string zoom_pulse)
|
|
{
|
|
// clamp values to allowed range
|
|
if (int.Parse(zoom_pulse) < min_zoom_pulse)
|
|
{
|
|
zoom_pulse = min_zoom_pulse.ToString();
|
|
}
|
|
if (int.Parse(zoom_pulse) > max_zoom_pulse)
|
|
{
|
|
zoom_pulse = max_zoom_pulse.ToString();
|
|
}
|
|
|
|
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://" + cam_ip + "/stw-cgi/ptzcontrol.cgi?msubmenu=absolute&action=control&ZoomPulse=" + zoom_pulse);
|
|
request.Credentials = new NetworkCredential(username, password);
|
|
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
|
}
|
|
|
|
private void StreamViewer_FormClosed(object sender, FormClosedEventArgs e)
|
|
{
|
|
_mp.Stop();
|
|
_mp.Dispose();
|
|
_libVLC.Dispose();
|
|
}
|
|
|
|
private void tbZoom_KeyUp(object sender, KeyEventArgs e)
|
|
{
|
|
sendZoomValue(tbZoom.Value.ToString());
|
|
}
|
|
|
|
private void tbZoom_MouseUp(object sender, MouseEventArgs e)
|
|
{
|
|
sendZoomValue(tbZoom.Value.ToString());
|
|
}
|
|
|
|
private void timerUpdateZoom_Tick(object sender, EventArgs e)
|
|
{
|
|
updateZoomSlider();
|
|
}
|
|
|
|
private void btnZoomMax_Click(object sender, EventArgs e)
|
|
{
|
|
tbZoom.Value = max_zoom_pulse;
|
|
sendZoomValue(tbZoom.Value.ToString());
|
|
}
|
|
|
|
private void btnZoomMin_Click(object sender, EventArgs e)
|
|
{
|
|
tbZoom.Value = min_zoom_pulse;
|
|
sendZoomValue(tbZoom.Value.ToString());
|
|
}
|
|
}
|
|
}
|