2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System.Runtime.InteropServices;
19 using static Interop.MediaVision.Surveillance;
21 namespace Tizen.Multimedia.Vision
24 /// SurveillanceEngine is a base class for surveillance event triggers.
25 /// Media Vision Surveillance provides the functionality which can be utilized for creation of video surveillance systems.
27 /// <seealso cref="MovementDetector"/>
28 /// <seealso cref="PersonAppearanceDetector"/>
29 /// <seealso cref="PersonRecognizer"/>
30 /// <since_tizen> 3 </since_tizen>
31 public abstract class SurveillanceEngine : IDisposable
33 private IntPtr _handle = IntPtr.Zero;
34 private bool _disposed = false;
37 /// Initializes a new instance of the <see cref="SurveillanceEngine"/> class.
39 /// <param name="eventType">The type of the event trigger.</param>
40 internal SurveillanceEngine(string eventType)
42 EventTriggerCreate(eventType, out _handle).Validate("Failed to create surveillance event trigger.");
46 /// Finalizes an instance of the SurveillanceEngine class.
53 internal IntPtr Handle
59 throw new ObjectDisposedException(GetType().Name);
66 /// Sets and gets the ROI (Region Of Interest).
68 /// <exception cref="ObjectDisposedException">The <see cref="SurveillanceEngine"/> has already been disposed of.</exception>
69 /// <since_tizen> 3 </since_tizen>
74 IntPtr roiPtr = IntPtr.Zero;
78 GetEventTriggerRoi(Handle, out count, out roiPtr).Validate("Failed to get roi");
80 Point[] points = new Point[count];
81 IntPtr iterPtr = roiPtr;
83 for (int i = 0; i < count; i++)
85 points[i] = Marshal.PtrToStructure<global::Interop.MediaVision.Point>(iterPtr).ToApiStruct();
86 iterPtr = IntPtr.Add(iterPtr, Marshal.SizeOf<global::Interop.MediaVision.Point>());
93 LibcSupport.Free(roiPtr);
98 int length = value == null ? 0 : value.Length;
100 var points = value == null ? null : global::Interop.ToMarshalable(value);
102 SetEventTriggerRoi(Handle, length, points).Validate("Failed to set roi");
106 internal abstract void OnEventDetected(IntPtr trigger, IntPtr source,
107 int streamId, IntPtr eventResult, IntPtr userData);
109 internal void InvokeAddSource(SurveillanceSource source, SurveillanceEngineConfiguration config)
113 throw new ArgumentNullException(nameof(source));
115 SubscribeEventTrigger(Handle, source.StreamId, EngineConfiguration.GetHandle(config),
116 OnEventDetected).Validate("Failed to subscribe trigger");
120 /// Removes the source from <see cref="SurveillanceEngine"/>.
122 /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
123 /// <exception cref="ObjectDisposedException">The <see cref="SurveillanceEngine"/> has already been disposed of.</exception>
124 /// <exception cref="ArgumentException"><paramref name="source"/> has not been added.</exception>
125 /// <since_tizen> 3 </since_tizen>
126 public void RemoveSource(SurveillanceSource source)
130 throw new ArgumentNullException(nameof(source));
132 UnsubscribeEventTrigger(Handle, source.StreamId).Validate("Failed to unsubscribe event trigger");
137 /// Releases all the resources used by the <see cref="SurveillanceEngine"/> object.
139 public void Dispose()
142 GC.SuppressFinalize(this);
146 /// Releases the resources used by the <see cref="SurveillanceEngine"/> object.
148 /// <param name="disposing">
149 /// true to release both managed and unmanaged resources; otherwise false to release only unmanaged resources.
151 protected virtual void Dispose(bool disposing)
158 EventTriggerDestroy(_handle);