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.Collections.Generic;
19 using System.Runtime.InteropServices;
20 using Tizen.Internals.Errors;
22 namespace Tizen.Multimedia
24 static internal class RecorderLog
26 internal const string Tag = "Tizen.Multimedia.Recorder";
30 /// The recorder class provides methods to create audio/video recorder,
31 /// to start, stop and save the recorded content. It also provides methods
32 /// to get/set various attributes and capabilities of recorder.
35 /// http://tizen.org/privilege/recorder
37 public class Recorder : IDisposable
39 private IntPtr _handle;
40 private bool _disposed = false;
41 private EventHandler<RecorderStateChangedEventArgs> _recorderStateChanged;
42 private Interop.Recorder.StatechangedCallback _recorderStateChangedCallback;
43 private EventHandler<RecordingStatusChangedEventArgs> _recordingStatusChanged;
44 private Interop.Recorder.RecordingStatusCallback _recordingStatusCallback;
45 private EventHandler<RecordingLimitReachedEventArgs> _recordingLimitReached;
46 private Interop.Recorder.RecordingLimitReachedCallback _recordingLimitReachedCallback;
47 private EventHandler<AudioStreamDeliveredEventArgs> _audioStreamDelivered;
48 private Interop.Recorder.AudioStreamCallback _audioStreamCallback;
49 private EventHandler<RecorderInterruptedEventArgs> _recorderInterrupted;
50 private Interop.Recorder.InterruptedCallback _interruptedCallback;
51 private EventHandler<RecordingErrorOccurredEventArgs> _recordingErrorOccured;
52 private Interop.Recorder.RecorderErrorCallback _recorderErrorCallback;
53 private List<RecorderFileFormat> _formats;
54 private List<RecorderAudioCodec> _audioCodec;
55 private List<RecorderVideoCodec> _videoCodec;
56 private List<RecorderVideoResolution> _resolutions;
57 RecorderVideoResolution _videoResolution = null;
60 /// Audio recorder constructor.
64 int ret = Interop.Recorder.Create (out _handle);
65 if (ret != (int)RecorderError.None)
67 RecorderErrorFactory.ThrowException (ret, "Failed to create Audio recorder");
69 _formats = new List<RecorderFileFormat>();
70 _audioCodec = new List<RecorderAudioCodec>();
71 _videoCodec = new List<RecorderVideoCodec> ();
72 _resolutions = new List<RecorderVideoResolution> ();
73 _videoResolution = new RecorderVideoResolution (_handle);
77 /// Video recorder constructor.
79 /// <param name="camera">
80 /// The camera object.
82 public Recorder(Camera camera)
84 int ret = Interop.Recorder.CreateVideo (camera.GetHandle(), out _handle);
85 if (ret != (int)RecorderError.None)
87 RecorderErrorFactory.ThrowException (ret, "Failed to create Video recorder");
89 _formats = new List<RecorderFileFormat>();
90 _audioCodec = new List<RecorderAudioCodec>();
91 _videoCodec = new List<RecorderVideoCodec> ();
92 _resolutions = new List<RecorderVideoResolution> ();
93 _videoResolution = new RecorderVideoResolution (_handle);
97 /// Recorder destructor.
105 /// Event that occurs when recorder is interrupted.
107 public event EventHandler<RecorderInterruptedEventArgs> RecorderInterrupted
111 if (_recorderInterrupted == null)
113 RegisterRecorderInterruptedEvent();
115 _recorderInterrupted += value;
119 _recorderInterrupted -= value;
120 if (_recorderInterrupted == null)
122 UnregisterRecorderInterruptedEvent ();
128 /// Event that occurs when audio stream data is being delivered.
130 public event EventHandler<AudioStreamDeliveredEventArgs> AudioStreamDelivered
134 if (_audioStreamDelivered == null)
136 RegisterAudioStreamDeliveredEvent();
138 _audioStreamDelivered += value;
142 _audioStreamDelivered -= value;
143 if (_audioStreamDelivered == null)
145 UnregisterAudioStreamDeliveredEvent ();
151 /// This event occurs when recorder state is changed.
153 public event EventHandler<RecorderStateChangedEventArgs> RecorderStateChanged
157 if (_recorderStateChanged == null)
159 RegisterStateChangedEvent();
161 _recorderStateChanged += value;
165 _recorderStateChanged -= value;
166 if (_recorderStateChanged == null)
168 UnregisterStateChangedEvent ();
174 /// Event that occurs when recording information changes.
176 public event EventHandler<RecordingStatusChangedEventArgs> RecordingStatusChanged
180 if (_recordingStatusChanged == null)
182 RegisterRecordingStatusChangedEvent();
184 _recordingStatusChanged += value;
188 _recordingStatusChanged -= value;
189 if (_recordingStatusChanged == null)
191 UnregisterRecordingStatusChangedEvent ();
197 /// Event that occurs when recording limit is reached.
199 public event EventHandler<RecordingLimitReachedEventArgs> RecordingLimitReached
203 if (_recordingLimitReached == null)
205 RegisterRecordingLimitReachedEvent();
207 _recordingLimitReached += value;
211 _recordingLimitReached -= value;
212 if (_recordingLimitReached == null)
214 UnregisterRecordingLimitReachedEvent ();
220 /// Event that occurs when an error occurs during recorder operation.
222 public event EventHandler<RecordingErrorOccurredEventArgs> RecordingErrorOccurred
226 if (_recordingErrorOccured == null)
228 RegisterRecordingErrorOccuredEvent();
230 _recordingErrorOccured += value;
234 _recordingErrorOccured -= value;
235 if (_recordingErrorOccured == null)
237 UnregisterRecordingErrorOccuredEvent ();
243 /// The file path to record.
246 /// If the same file already exists in the file system, then old file
247 /// will be overwritten.
249 public string FilePath
254 int ret = Interop.Recorder.GetFileName (_handle, out val);
255 if ((RecorderError)ret != RecorderError.None)
257 Log.Error (RecorderLog.Tag, "Failed to get filepath, " + (RecorderError)ret);
259 string result = Marshal.PtrToStringAnsi (val);
260 Interop.Libc.Free (val);
265 int ret = Interop.Recorder.SetFileName (_handle, value);
266 if ((RecorderError)ret != RecorderError.None)
268 Log.Error (RecorderLog.Tag, "Failed to set filepath, " + (RecorderError)ret);
269 RecorderErrorFactory.ThrowException (ret, "Failed to set filepath");
275 /// Get the peak audio input level in dB
278 /// 0dB indicates maximum input level, -300dB indicates minimum input level.
280 public double AudioLevel
286 int ret = Interop.Recorder.GetAudioLevel (_handle, out level);
287 if ((RecorderError)ret != RecorderError.None)
289 Log.Error (RecorderLog.Tag, "Failed to get Audio level, " + (RecorderError)ret);
296 /// The current state of the recorder.
298 public RecorderState State
304 int ret = Interop.Recorder.GetState (_handle, out val);
305 if ((RecorderError)ret != RecorderError.None)
307 Log.Error (RecorderLog.Tag, "Failed to get recorder state, " + (RecorderError)ret);
309 return (RecorderState)val;
314 /// The file format for recording media stream.
316 public RecorderFileFormat FileFormat
322 int ret = Interop.Recorder.GetFileFormat (_handle, out val);
323 if ((RecorderError)ret != RecorderError.None)
325 Log.Error (RecorderLog.Tag, "Failed to get file format, " + (RecorderError)ret);
327 return (RecorderFileFormat)val;
331 int ret = Interop.Recorder.SetFileFormat (_handle, (int)value);
332 if ((RecorderError)ret != RecorderError.None)
334 Log.Error (RecorderLog.Tag, "Failed to set file format, " + (RecorderError)ret);
335 RecorderErrorFactory.ThrowException (ret);
341 /// The audio codec for encoding an audio stream.
343 public RecorderAudioCodec AudioCodec
349 int ret = Interop.Recorder.GetAudioEncoder (_handle, out val);
350 if ((RecorderError)ret != RecorderError.None)
352 Log.Error (RecorderLog.Tag, "Failed to get audio codec, " + (RecorderError)ret);
354 return (RecorderAudioCodec)val;
358 int ret = Interop.Recorder.SetAudioEncoder (_handle, (int)value);
359 if ((RecorderError)ret != RecorderError.None)
361 Log.Error (RecorderLog.Tag, "Failed to set audio codec, " + (RecorderError)ret);
362 RecorderErrorFactory.ThrowException (ret);
368 /// The video codec for encoding video stream.
370 public RecorderVideoCodec VideoCodec
376 int ret = Interop.Recorder.GetVideoEncoder (_handle, out val);
377 if ((RecorderError)ret != RecorderError.None)
379 Log.Error( RecorderLog.Tag, "Failed to get video codec, " + (RecorderError)ret);
381 return (RecorderVideoCodec)val;
385 int ret = Interop.Recorder.SetVideoEncoder (_handle, (int)value);
387 if ((RecorderError)ret != RecorderError.None)
389 Log.Error(RecorderLog.Tag, "Failed to set video codec, " + (RecorderError)ret);
390 RecorderErrorFactory.ThrowException(ret);
396 /// The maximum size of a recording file in KB(kilobytes). If 0, means
397 /// unlimited recording size.
400 /// After reaching the limitation, the data which is being recorded will
401 /// be discarded and not written to the file.
402 /// The recorder state must be in 'Ready' or 'Created' state.
411 int ret = Interop.RecorderAttribute.GetSizeLimit (_handle, out val);
412 if ((RecorderError)ret != RecorderError.None)
414 Log.Error (RecorderLog.Tag, "Failed to get sizelimit, " + (RecorderError)ret);
420 int ret = Interop.RecorderAttribute.SetSizeLimit (_handle, value);
421 if ((RecorderError)ret != RecorderError.None)
423 Log.Error (RecorderLog.Tag, "Failed to set sizelimit, " + (RecorderError)ret);
424 RecorderErrorFactory.ThrowException (ret, "Failed to set sizelimit");
430 /// The time limit of a recording file in Seconds. If 0, means unlimited recording
434 /// After reaching the limitation, the data which is being recorded will
435 /// be discarded and not written to the file.
436 /// The recorder state must be in 'Ready' or 'Created' state.
444 int ret = Interop.RecorderAttribute.GetTimeLimit (_handle, out val);
445 if ((RecorderError)ret != RecorderError.None)
447 Log.Error (RecorderLog.Tag, "Failed to get timelimit, " + (RecorderError)ret);
453 int ret = Interop.RecorderAttribute.SetTimeLimit (_handle, value);
454 if ((RecorderError)ret != RecorderError.None)
456 Log.Error (RecorderLog.Tag, "Failed to set timelimit, " + (RecorderError)ret);
457 RecorderErrorFactory.ThrowException (ret, "Failed to set timelimit");
463 /// The sampling rate of an audio stream in hertz.
465 public int AudioSampleRate
471 int ret = Interop.RecorderAttribute.GetAudioSampleRate (_handle, out val);
472 if ((RecorderError)ret != RecorderError.None)
474 Log.Error (RecorderLog.Tag, "Failed to get audio samplerate, " + (RecorderError)ret);
480 int ret = Interop.RecorderAttribute.SetAudioSampleRate (_handle, value);
481 if ((RecorderError)ret != RecorderError.None)
483 Log.Error (RecorderLog.Tag, "Failed to set audio samplerate, " + (RecorderError)ret);
484 RecorderErrorFactory.ThrowException (ret, "Failed to set audio samplerate");
490 /// The bitrate of an audio encoder in bits per second.
492 public int AudioBitRate
498 int ret = Interop.RecorderAttribute.GetAudioEncoderBitrate (_handle, out val);
499 if ((RecorderError)ret != RecorderError.None)
501 Log.Error (RecorderLog.Tag, "Failed to get audio bitrate, " + (RecorderError)ret);
507 int ret = Interop.RecorderAttribute.SetAudioEncoderBitrate (_handle, value);
508 if ((RecorderError)ret != RecorderError.None)
510 Log.Error (RecorderLog.Tag, "Failed to set audio bitrate, " + (RecorderError)ret);
511 RecorderErrorFactory.ThrowException (ret, "Failed to set audio bitrate");
517 /// The bitrate of an video encoder in bits per second.
519 public int VideoBitRate
525 int ret = Interop.RecorderAttribute.GetVideoEncoderBitrate (_handle, out val);
526 if ((RecorderError)ret != RecorderError.None)
528 Log.Error (RecorderLog.Tag, "Failed to get video bitrate, " + (RecorderError)ret);
534 int ret = Interop.RecorderAttribute.SetVideoEncoderBitrate (_handle, value);
535 if ((RecorderError)ret != RecorderError.None)
537 Log.Error (RecorderLog.Tag, "Failed to set video bitrate, " + (RecorderError)ret);
538 RecorderErrorFactory.ThrowException (ret, "Failed to set video bitrate");
544 /// The mute state of a recorder.
552 val = Interop.RecorderAttribute.GetMute (_handle);
553 int ret = ErrorFacts.GetLastResult ();
554 if ((RecorderError)ret != RecorderError.None)
557 err = (RecorderError) ret;
558 Log.Error (RecorderLog.Tag, "Failed to get the mute state of recorder, return " + err.ToString());
564 int ret = Interop.RecorderAttribute.SetMute (_handle, value);
565 if ((RecorderError)ret != RecorderError.None)
567 Log.Error (RecorderLog.Tag, "Failed to set mute, " + (RecorderError)ret);
568 RecorderErrorFactory.ThrowException (ret, "Failed to set mute");
574 /// The video recording motion rate
577 /// The attribute is valid only in a video recorder.
578 /// If the rate is in range of 0-1, video is recorded in a slow motion mode.
579 /// If the rate is bigger than 1, video is recorded in a fast motion mode.
581 public double MotionRate
587 int ret = Interop.RecorderAttribute.GetMotionRate (_handle, out val);
588 if ((RecorderError)ret != RecorderError.None)
590 Log.Error (RecorderLog.Tag, "Failed to get video motionrate, " + (RecorderError)ret);
596 int ret = Interop.RecorderAttribute.SetMotionRate (_handle, (double)value);
597 if ((RecorderError)ret != RecorderError.None)
599 Log.Error (RecorderLog.Tag, "Failed to set video motionrate, " + (RecorderError)ret);
600 RecorderErrorFactory.ThrowException (ret, "Failed to set video motionrate");
606 /// The number of audio channel.
609 /// The attribute is applied only in Created state.
610 /// For mono recording, set channel to 1.
611 /// For stereo recording, set channel to 2.
613 public int AudioChannel
619 int ret = Interop.RecorderAttribute.GetAudioChannel (_handle, out val);
620 if ((RecorderError)ret != RecorderError.None)
622 Log.Error (RecorderLog.Tag, "Failed to get audio channel, " + (RecorderError)ret);
628 int ret = Interop.RecorderAttribute.SetAudioChannel (_handle, value);
629 if ((RecorderError)ret != RecorderError.None)
631 Log.Error (RecorderLog.Tag, "Failed to set audio channel, " + (RecorderError)ret);
632 RecorderErrorFactory.ThrowException (ret, "Failed to set audio channel");
638 /// The audio device for recording.
640 public RecorderAudioDevice AudioDevice
646 int ret = Interop.RecorderAttribute.GetAudioDevice (_handle, out val);
647 if ((RecorderError)ret != RecorderError.None)
649 Log.Error (RecorderLog.Tag, "Failed to get audio device, " + (RecorderError)ret);
651 return (RecorderAudioDevice)val;
655 int ret = Interop.RecorderAttribute.SetAudioDevice (_handle, (int)value);
656 if ((RecorderError)ret != RecorderError.None)
658 Log.Error (RecorderLog.Tag, "Failed to set audio device, " + (RecorderError)ret);
659 RecorderErrorFactory.ThrowException (ret, "Failed to set audio device");
665 /// The orientation in a video metadata tag.
667 public RecorderOrientation OrientationTag
673 int ret = Interop.RecorderAttribute.GetOrientationTag (_handle, out val);
674 if ((RecorderError)ret != RecorderError.None)
676 Log.Error (RecorderLog.Tag, "Failed to get recorder orientation, " + (RecorderError)ret);
678 return (RecorderOrientation)val;
682 int ret = Interop.RecorderAttribute.SetOrientationTag (_handle, (int)value);
683 if ((RecorderError)ret != RecorderError.None)
685 Log.Error (RecorderLog.Tag, "Failed to set recorder orientation, " + (RecorderError)ret);
686 RecorderErrorFactory.ThrowException (ret, "Failed to set audio orientation");
692 /// Video resolution of the video recording.
694 public RecorderVideoResolution Resolution
698 return _videoResolution;
703 /// Retrieves all the file formats supported by the recorder.
706 /// It returns a list containing all the supported file
707 /// formats by recorder.
709 public IEnumerable<RecorderFileFormat> SupportedFileFormats
713 if (_formats.Count == 0)
715 Interop.RecorderCapablity.FileFormatCallback callback = (RecorderFileFormat format, IntPtr userData) =>
717 _formats.Add (format);
720 int ret = Interop.RecorderCapablity.FileFormats (_handle, callback, IntPtr.Zero);
721 if (ret != (int)RecorderError.None)
723 RecorderErrorFactory.ThrowException (ret, "Failed to get the supported fileformats");
731 /// Retrieves all the audio encoders supported by the recorder.
734 /// It returns a list containing all the supported audio encoders
737 public IEnumerable<RecorderAudioCodec> SupportedAudioEncodings
741 if (_audioCodec.Count == 0)
743 Interop.RecorderCapablity.AudioEncoderCallback callback = (RecorderAudioCodec codec, IntPtr userData) =>
745 _audioCodec.Add(codec);
748 int ret = Interop.RecorderCapablity.AudioEncoders (_handle, callback, IntPtr.Zero);
749 if (ret != (int)RecorderError.None)
751 RecorderErrorFactory.ThrowException (ret, "Failed to get the supported audio encoders");
759 /// Retrieves all the video encoders supported by the recorder.
762 /// It returns a list containing all the supported video encoders
765 public IEnumerable<RecorderVideoCodec> SupportedVideoEncodings
769 if (_videoCodec.Count == 0)
771 Interop.RecorderCapablity.VideoEncoderCallback callback = (RecorderVideoCodec codec, IntPtr userData) =>
773 _videoCodec.Add(codec);
776 int ret = Interop.RecorderCapablity.VideoEncoders (_handle, callback, IntPtr.Zero);
777 if (ret != (int)RecorderError.None)
779 RecorderErrorFactory.ThrowException (ret, "Failed to get the supported video encoders");
787 /// Retrieves all the video resolutions supported by the recorder.
790 /// It returns videoresolution list containing the width and height of
791 /// different resolutions supported by recorder.
793 public IEnumerable<RecorderVideoResolution> SupportedVideoResolutions
797 if (_resolutions.Count == 0)
799 Interop.RecorderCapablity.VideoResolutionCallback callback = (int width, int height, IntPtr userData) =>
801 RecorderVideoResolution temp = new RecorderVideoResolution(width, height);
802 _resolutions.Add(temp);
805 int ret = Interop.RecorderCapablity.VideoResolution (_handle, callback, IntPtr.Zero);
806 if (ret != (int)RecorderError.None)
808 RecorderErrorFactory.ThrowException (ret, "Failed to get the supported video resolutions");
816 /// Prepare the media recorder for recording.
819 /// Before calling the function, it is required to set AudioEncoder,
820 /// videoencoder and fileformat properties of recorder.
823 /// http://tizen.org/privilege/recorder
825 public void Prepare()
827 int ret = Interop.Recorder.Prepare (_handle);
828 if (ret != (int)RecorderError.None)
830 RecorderErrorFactory.ThrowException (ret, "Failed to prepare media recorder for recording");
835 /// Resets the media recorder.
838 /// http://tizen.org/privilege/recorder
840 public void Unprepare()
842 int ret = Interop.Recorder.Unprepare (_handle);
843 if (ret != (int)RecorderError.None)
845 RecorderErrorFactory.ThrowException (ret, "Failed to reset the media recorder");
850 /// Starts the recording.
853 /// If file path has been set to an existing file, this file is removed automatically and updated by new one.
854 /// In the video recorder, some preview format does not support record mode. It will return InvalidOperation error.
855 /// You should use default preview format or CameraPixelFormatNv12 in the record mode.
856 /// The filename should be set before this function is invoked.
859 /// http://tizen.org/privilege/recorder
863 int ret = Interop.Recorder.Start (_handle);
864 if (ret != (int)RecorderError.None)
866 RecorderErrorFactory.ThrowException (ret, "Failed to start the media recorder");
871 /// Pause the recording.
874 /// Recording can be resumed with Start().
877 /// http://tizen.org/privilege/recorder
881 int ret = Interop.Recorder.Pause (_handle);
882 if (ret != (int)RecorderError.None)
884 RecorderErrorFactory.ThrowException (ret, "Failed to pause the media recorder");
889 /// Stops recording and saves the result.
892 /// http://tizen.org/privilege/recorder
896 int ret = Interop.Recorder.Commit (_handle);
897 if (ret != (int)RecorderError.None)
899 RecorderErrorFactory.ThrowException (ret, "Failed to save the recorded content");
904 /// Cancels the recording.
905 /// The recording data is discarded and not written in the recording file.
908 /// http://tizen.org/privilege/recorder
912 int ret = Interop.Recorder.Cancel (_handle);
913 if (ret != (int)RecorderError.None)
915 RecorderErrorFactory.ThrowException (ret, "Failed to cancel the recording");
920 /// Sets the audio stream policy.
922 /// <param name="policy">Policy.</param>
923 public void SetAudioStreamPolicy(AudioStreamPolicy policy)
925 int ret = Interop.Recorder.SetAudioStreamPolicy (_handle, policy.Handle);
927 if (ret != (int)RecorderError.None)
929 RecorderErrorFactory.ThrowException (ret, "Failed to set audio stream policy");
934 /// Release any unmanaged resources used by this object.
936 public void Dispose()
939 GC.SuppressFinalize(this);
942 protected virtual void Dispose(bool disposing)
948 // to be used if there are any other disposable objects
950 if (_handle != IntPtr.Zero)
952 Interop.Recorder.Destroy (_handle);
953 _handle = IntPtr.Zero;
959 private void RegisterRecorderInterruptedEvent()
961 _interruptedCallback = (RecorderPolicy policy, RecorderState previous, RecorderState current, IntPtr userData) =>
963 RecorderInterruptedEventArgs eventArgs = new RecorderInterruptedEventArgs(policy, previous, current);
964 _recorderInterrupted?.Invoke(this, eventArgs);
966 int ret = Interop.Recorder.SetInterruptedCallback (_handle, _interruptedCallback, IntPtr.Zero);
967 if (ret != (int)RecorderError.None)
969 RecorderErrorFactory.ThrowException (ret, "Setting Interrupted callback failed");
973 private void UnregisterRecorderInterruptedEvent()
975 int ret = Interop.Recorder.UnsetInterruptedCallback (_handle);
976 if (ret != (int)RecorderError.None)
978 RecorderErrorFactory.ThrowException (ret, "Unsetting Interrupted callback failed");
982 private void RegisterAudioStreamDeliveredEvent()
984 _audioStreamCallback = (IntPtr stream, int size, AudioSampleType type, int channel, uint recordingTime, IntPtr userData) =>
986 byte[] streamArray = new byte[size];
987 Marshal.Copy(stream, streamArray, 0, size);
988 AudioStreamDeliveredEventArgs eventArgs = new AudioStreamDeliveredEventArgs(streamArray, type, channel, recordingTime);
989 _audioStreamDelivered?.Invoke(this, eventArgs);
991 int ret = Interop.Recorder.SetAudioStreamCallback (_handle, _audioStreamCallback, IntPtr.Zero);
992 if (ret != (int)RecorderError.None)
994 RecorderErrorFactory.ThrowException (ret, "Setting audiostream callback failed");
998 private void UnregisterAudioStreamDeliveredEvent()
1000 int ret = Interop.Recorder.UnsetAudioStreamCallback (_handle);
1001 if (ret != (int)RecorderError.None)
1003 RecorderErrorFactory.ThrowException (ret, "Unsetting audiostream callback failed");
1007 private void RegisterStateChangedEvent()
1009 _recorderStateChangedCallback = (RecorderState previous, RecorderState current, bool byPolicy, IntPtr userData) =>
1011 RecorderStateChangedEventArgs eventArgs = new RecorderStateChangedEventArgs(previous, current, byPolicy);
1012 _recorderStateChanged?.Invoke(this, eventArgs);
1014 int ret = Interop.Recorder.SetStateChangedCallback (_handle, _recorderStateChangedCallback , IntPtr.Zero);
1015 if (ret != (int)RecorderError.None)
1017 RecorderErrorFactory.ThrowException (ret, "Setting state changed callback failed");
1021 private void UnregisterStateChangedEvent()
1023 int ret = Interop.Recorder.UnsetStateChangedCallback (_handle);
1024 if (ret != (int)RecorderError.None)
1026 RecorderErrorFactory.ThrowException (ret, "Unsetting state changed callback failed");
1030 private void RegisterRecordingStatusChangedEvent()
1032 _recordingStatusCallback = (ulong elapsedTime, ulong fileSize, IntPtr userData) =>
1034 RecordingStatusChangedEventArgs eventArgs = new RecordingStatusChangedEventArgs(elapsedTime, fileSize);
1035 _recordingStatusChanged?.Invoke(this, eventArgs);
1037 int ret = Interop.Recorder.SetStatusChangedCallback (_handle, _recordingStatusCallback, IntPtr.Zero);
1038 if (ret != (int)RecorderError.None)
1040 RecorderErrorFactory.ThrowException (ret, "Setting status changed callback failed");
1044 private void UnregisterRecordingStatusChangedEvent()
1046 int ret = Interop.Recorder.UnsetStatusChangedCallback (_handle);
1047 if (ret != (int)RecorderError.None)
1049 RecorderErrorFactory.ThrowException (ret, "Unsetting status changed callback failed");
1053 private void RegisterRecordingLimitReachedEvent()
1055 _recordingLimitReachedCallback = (RecordingLimitType type, IntPtr userData) =>
1057 RecordingLimitReachedEventArgs eventArgs = new RecordingLimitReachedEventArgs(type);
1058 _recordingLimitReached?.Invoke(this, eventArgs);
1060 int ret = Interop.Recorder.SetLimitReachedCallback (_handle, _recordingLimitReachedCallback, IntPtr.Zero);
1061 if (ret != (int)RecorderError.None)
1063 RecorderErrorFactory.ThrowException (ret, "Setting limit reached callback failed");
1067 private void UnregisterRecordingLimitReachedEvent()
1069 int ret = Interop.Recorder.UnsetLimitReachedCallback (_handle);
1070 if (ret != (int)RecorderError.None)
1072 RecorderErrorFactory.ThrowException(ret, "Unsetting limit reached callback failed");
1076 private void RegisterRecordingErrorOccuredEvent()
1078 _recorderErrorCallback = (RecorderErrorCode error, RecorderState current, IntPtr userData) =>
1080 RecordingErrorOccurredEventArgs eventArgs = new RecordingErrorOccurredEventArgs(error, current);
1081 _recordingErrorOccured?.Invoke(this, eventArgs);
1083 int ret = Interop.Recorder.SetErrorCallback (_handle, _recorderErrorCallback, IntPtr.Zero);
1084 if (ret != (int)RecorderError.None)
1086 RecorderErrorFactory.ThrowException (ret, "Setting Error callback failed");
1090 private void UnregisterRecordingErrorOccuredEvent()
1092 int ret = Interop.Recorder.UnsetErrorCallback (_handle);
1093 if (ret != (int)RecorderError.None)
1095 RecorderErrorFactory.ThrowException (ret, "Unsetting Error callback failed");