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
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 public abstract class SurveillanceEngine : IDisposable
32 private IntPtr _handle = IntPtr.Zero;
33 private bool _disposed = false;
36 /// Initializes a new instance of the <see cref="SurveillanceEngine"/> class.
38 /// <param name="eventType">The type of the event trigger</param>
39 internal SurveillanceEngine(string eventType)
41 EventTriggerCreate(eventType, out _handle).Validate("Failed to create surveillance event trigger.");
49 internal IntPtr Handle
55 throw new ObjectDisposedException(GetType().Name);
62 /// Sets and gets ROI (Region Of Interest) to the event trigger
64 /// <exception cref="ObjectDisposedException">The <see cref="SurveillanceEngine"/> has already been disposed of.</exception>
69 IntPtr roiPtr = IntPtr.Zero;
73 GetEventTriggerRoi(Handle, out count, out roiPtr).Validate("Failed to get roi");
75 Point[] points = new Point[count];
76 IntPtr iterPtr = roiPtr;
78 for (int i = 0; i < count; i++)
80 points[i] = Marshal.PtrToStructure<Interop.MediaVision.Point>(roiPtr).ToApiStruct();
81 iterPtr = IntPtr.Add(iterPtr, Marshal.SizeOf<Interop.MediaVision.Point>());
88 Interop.Libc.Free(roiPtr);
93 int length = value == null ? 0 : value.Length;
95 var points = value == null ? null : Interop.ToMarshalable(value);
97 SetEventTriggerRoi(Handle, length, points).Validate("Failed to set roi");
101 internal abstract void OnEventDetected(IntPtr trigger, IntPtr source,
102 int streamId, IntPtr eventResult, IntPtr userData);
105 /// Subscribes trigger to process sources pushed from video identified by @a videoStreamId.
107 internal void InvokeAddSource(SurveillanceSource source, SurveillanceEngineConfiguration config)
111 throw new ArgumentNullException(nameof(source));
113 SubscribeEventTrigger(Handle, source.StreamId, EngineConfiguration.GetHandle(config),
114 OnEventDetected).Validate("Failed to subscribe trigger");
118 /// Removes the source from <see cref="SurveillanceEngine"/>.
120 /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
121 /// <exception cref="ObjectDisposedException">The <see cref="SurveillanceEngine"/> has already been disposed of.</exception>
122 /// <exception cref="ArgumentException"><paramref name="source"/> has not been added.</exception>
123 public void RemoveSource(SurveillanceSource source)
127 throw new ArgumentNullException(nameof(source));
129 UnsubscribeEventTrigger(Handle, source.StreamId).Validate("Failed to unsubscribe event trigger");
132 public void Dispose()
135 GC.SuppressFinalize(this);
138 protected virtual void Dispose(bool disposing)
145 EventTriggerDestroy(_handle);