Live Stream Operations: Add StartLiveStream to CJMS11 camera
This commit is contained in:
parent
8301971906
commit
e7d04b55b3
@ -2337,6 +2337,49 @@ namespace TBF.Rig.Network.Camera.CJMS11
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// pouziva LiveStreamOp - pre nahlad
|
||||
/// </summary>
|
||||
/// <param name="hiResolution"></param>
|
||||
public void StartLiveStream(bool hiResolution)
|
||||
{
|
||||
if (CameraCfg.DebugLevel == DebugMode.Simulate)
|
||||
return;
|
||||
|
||||
StartLiveStreamListener();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// pouziva LiveStreamOp - pre ukoncenie nahladu
|
||||
/// </summary>
|
||||
public void StopLiveStream()
|
||||
{
|
||||
if (CameraCfg.DebugLevel == DebugMode.Simulate)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
liveCts?.Cancel();
|
||||
|
||||
if (liveStreamTask != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
liveStreamTask.Wait(1000);
|
||||
}
|
||||
catch (AggregateException)
|
||||
{
|
||||
// expected after cancellation
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.Error($"{Name}: StopLiveStream failed.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// listener for multiple - repetetive image receiving
|
||||
/// </summary>
|
||||
@ -2345,12 +2388,7 @@ namespace TBF.Rig.Network.Camera.CJMS11
|
||||
/// </detail>
|
||||
/// <param name="localIP"></param>
|
||||
/// <param name="localPort"></param>
|
||||
|
||||
// private void StartLiveStreamListener(IPAddress localIP, int localPort)
|
||||
// {
|
||||
// liveStreamListenerThread = new Thread(new ThreadStart(LiveStreamListener));
|
||||
// liveStreamListenerThread.Start();
|
||||
// }
|
||||
|
||||
|
||||
private CancellationTokenSource liveCts;
|
||||
private Task liveStreamTask;
|
||||
@ -2662,7 +2700,7 @@ namespace TBF.Rig.Network.Camera.CJMS11
|
||||
//string command = string.Format("~/userland/build/bin/raspivid -t 0 -cd MJPEG -w {0} -h {1} -fps 30 -b 8000000 -o - | gst-launch-1.0 fdsrc ! \"image/jpeg,framerate=30/1\" ! jpegparse ! rtpjpegpay ! udpsink host={2} port={3}",
|
||||
// wid, hgh, NetAdapter.IPAddress, rtpUdpLocalPort);
|
||||
|
||||
return new LiveStreamOp(this, command);
|
||||
return new LiveStreamOp(this, hiRes);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -10,58 +10,72 @@ namespace TBF.Rig.Network.Camera.CJMS11
|
||||
{
|
||||
private static readonly ILog log = LogManager.GetLogger(typeof(LiveStreamOp));
|
||||
|
||||
readonly Camera camera;
|
||||
readonly Telnet.TelnetClient telnet;
|
||||
readonly string command;
|
||||
private readonly Camera camera;
|
||||
private readonly bool hiResolution;
|
||||
|
||||
private bool started;
|
||||
private Exception startException;
|
||||
|
||||
|
||||
bool liveStreamCommandSent;
|
||||
|
||||
/// <summary>
|
||||
/// Events: Event.None or Event.Error
|
||||
/// </summary>
|
||||
/// <param name="camera">CLP1611.Camera reference</param>
|
||||
public LiveStreamOp(Camera camera, string command)
|
||||
public LiveStreamOp(Camera camera, bool hiResolution)
|
||||
{
|
||||
this.camera = camera;
|
||||
this.command = command;
|
||||
this.hiResolution = hiResolution;
|
||||
}
|
||||
|
||||
|
||||
public void Start()
|
||||
{
|
||||
liveStreamCommandSent = false;
|
||||
started = false;
|
||||
startException = null;
|
||||
|
||||
try
|
||||
{
|
||||
camera.StartLiveStream(hiResolution);
|
||||
started = true;
|
||||
|
||||
log.InfoFormat("{0} Live stream started",
|
||||
camera.Name);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
startException = ex;
|
||||
log.Error("Unable to start live stream.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public Event Run()
|
||||
{
|
||||
if (camera.CameraCfg.DebugLevel == DebugMode.Simulate) return Event.None;
|
||||
if (camera.CameraCfg.DebugLevel == DebugMode.Simulate)
|
||||
return Event.None;
|
||||
|
||||
log.DebugFormat("Run(): telnet.State = {0}, liveStreamCommandSent = {1}", telnet.State, liveStreamCommandSent);
|
||||
|
||||
if (!liveStreamCommandSent)
|
||||
{
|
||||
if (camera.Running && (telnet.State == TelnetClient.TelnetState.Inactive))
|
||||
{
|
||||
telnet.Enqueue(new Telnet.Command(Telnet.CmdAction.SEND_STRING, command));
|
||||
liveStreamCommandSent = true;
|
||||
log.WarnFormat("{0} IP={1} command={2}", camera.Name, camera.IPAddress, command);
|
||||
}
|
||||
}
|
||||
if (startException != null)
|
||||
return Event.Error;
|
||||
|
||||
return Event.None;
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
if (camera.CameraCfg.DebugLevel == DebugMode.Simulate) return;
|
||||
if (camera.CameraCfg.DebugLevel == DebugMode.Simulate)
|
||||
return;
|
||||
|
||||
log.DebugFormat("Stop(): telnet.State = {0}, liveStreamCommandSent = {1}", telnet.State, liveStreamCommandSent);
|
||||
|
||||
if (liveStreamCommandSent)
|
||||
try
|
||||
{
|
||||
telnet.Enqueue(new Telnet.Command(Telnet.CmdAction.SEND_COMMAND, Telnet.TelnetClient.CtrlCCommand));
|
||||
log.WarnFormat("{0} IP={1} command=CTRL-C", camera.Name, camera.IPAddress);
|
||||
}
|
||||
camera.StopLiveStream();
|
||||
|
||||
log.InfoFormat("{0} Live stream stopped",
|
||||
camera.Name);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.Error("Unable to stop live stream.", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user