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 functionality 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.");
50 internal IntPtr Handle
56 throw new ObjectDisposedException(GetType().Name);
63 /// Sets and gets ROI (Region Of Interest).
65 /// <exception cref="ObjectDisposedException">The <see cref="SurveillanceEngine"/> has already been disposed of.</exception>
66 /// <since_tizen> 3</since_tizen>
71 IntPtr roiPtr = IntPtr.Zero;
75 GetEventTriggerRoi(Handle, out count, out roiPtr).Validate("Failed to get roi");
77 Point[] points = new Point[count];
78 IntPtr iterPtr = roiPtr;
80 for (int i = 0; i < count; i++)
82 points[i] = Marshal.PtrToStructure<global::Interop.MediaVision.Point>(iterPtr).ToApiStruct();
83 iterPtr = IntPtr.Add(iterPtr, Marshal.SizeOf<global::Interop.MediaVision.Point>());
90 LibcSupport.Free(roiPtr);
95 int length = value == null ? 0 : value.Length;
97 var points = value == null ? null : global::Interop.ToMarshalable(value);
99 SetEventTriggerRoi(Handle, length, points).Validate("Failed to set roi");
103 internal abstract void OnEventDetected(IntPtr trigger, IntPtr source,
104 int streamId, IntPtr eventResult, IntPtr userData);
106 internal void InvokeAddSource(SurveillanceSource source, SurveillanceEngineConfiguration config)
110 throw new ArgumentNullException(nameof(source));
112 SubscribeEventTrigger(Handle, source.StreamId, EngineConfiguration.GetHandle(config),
113 OnEventDetected).Validate("Failed to subscribe trigger");
117 /// Removes the source from <see cref="SurveillanceEngine"/>.
119 /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
120 /// <exception cref="ObjectDisposedException">The <see cref="SurveillanceEngine"/> has already been disposed of.</exception>
121 /// <exception cref="ArgumentException"><paramref name="source"/> has not been added.</exception>
122 /// <since_tizen> 3</since_tizen>
123 public void RemoveSource(SurveillanceSource source)
127 throw new ArgumentNullException(nameof(source));
129 UnsubscribeEventTrigger(Handle, source.StreamId).Validate("Failed to unsubscribe event trigger");
134 /// Releases all resources used by the <see cref="SurveillanceEngine"/> object.
136 public void Dispose()
139 GC.SuppressFinalize(this);
143 /// Releases the resources used by the <see cref="SurveillanceEngine"/> object.
145 /// <param name="disposing">
146 /// true to release both managed and unmanaged resources; false to release only unmanaged resources.
148 protected virtual void Dispose(bool disposing)
155 EventTriggerDestroy(_handle);