private static void UnregisterDeviceStateChangedEvent() { Native.RemoveDeviceStateChangedCallback(_deviceStateChangedId). ThrowIfError("Failed to remove the event handler."); _deviceStateChangedCallback = null; }
/// <summary> /// Returns the state of recorder device. /// </summary> /// <exception cref="ArgumentException"><paramref name="type"/> is invalid.</exception> /// <since_tizen> 4 </since_tizen> public static RecorderDeviceState GetDeviceState(RecorderType type) { ValidationUtil.ValidateEnum(typeof(RecorderType), type, nameof(type)); Native.GetDeviceState(type, out var state).ThrowIfError("Failed to get device state"); return(state); }
/// <summary> /// Returns the peak audio input level in dB since the last call to this method. /// </summary> /// <remarks> /// 0dB indicates the maximum input level, -300dB indicates the minimum input level.<br/> /// <br/> /// The recorder must be in the <see cref="RecorderState.Recording"/> or the <see cref="RecorderState.Paused"/> state. /// </remarks> /// <exception cref="ObjectDisposedException">The recorder already has been disposed of.</exception> /// <since_tizen> 4 </since_tizen> public double GetPeakAudioLevel() { ValidateState(RecorderState.Recording, RecorderState.Paused); Native.GetAudioLevel(Handle, out var level).ThrowIfError("Failed to get audio level."); return(level); }
private void RegisterInterruptedEvent() { _interruptedCallback = (policy, previousState, currentState, _) => { Interrupted?.Invoke(this, new RecorderInterruptedEventArgs(policy, previousState, currentState)); }; Native.SetInterruptedCallback(_handle, _interruptedCallback, IntPtr.Zero). ThrowIfError("Failed to initialize Interrupted event"); }
/// <summary> /// Cancels the recording.<br/> /// The recording data is discarded and not written in the recording file. /// </summary> /// <remarks> /// The recorder must be in the <see cref="RecorderState.Recording"/> or the <see cref="RecorderState.Paused"/> state. /// The state of the recorder will be the <see cref="RecorderState.Ready"/> after the operation. /// </remarks> /// <exception cref="InvalidOperationException"> /// The recorder is not in the valid state.<br/> /// -or-<br/> /// The method is called in <see cref="AudioStreamStoring"/> event.<br/> /// -or-<br/> /// An internal error occurred. /// </exception> /// <exception cref="ObjectDisposedException">The recorder already has been disposed of.</exception> /// <since_tizen> 3 </since_tizen> public void Cancel() { ThrowIfAccessedInAudioStreamStoring(); ValidateState(RecorderState.Recording, RecorderState.Paused); Native.Cancel(Handle).ThrowIfError("Failed to cancel the recording"); SetState(RecorderState.Ready); }
/// <summary> /// Stops recording and saves the result. /// </summary> /// <remarks> /// The recorder must be in the <see cref="RecorderState.Recording"/> or the <see cref="RecorderState.Paused"/> state. /// The state of the recorder will be the <see cref="RecorderState.Ready"/> after the operation. /// </remarks> /// <exception cref="InvalidOperationException"> /// The recorder is not in the valid state.<br/> /// -or-<br/> /// The method is called in <see cref="AudioStreamStoring"/> event.<br/> /// -or-<br/> /// An internal error occurred. /// </exception> /// <exception cref="ObjectDisposedException">The recorder already has been disposed of.</exception> /// <since_tizen> 3 </since_tizen> public void Commit() { ThrowIfAccessedInAudioStreamStoring(); ValidateState(RecorderState.Recording, RecorderState.Paused); Native.Commit(Handle).ThrowIfError("Failed to save the recorded content"); SetState(RecorderState.Ready); }
private void RegisterRecordingProgressEvent() { _recordingProgressCallback = (ulong elapsedTime, ulong fileSize, IntPtr userData) => { RecordingStatusChanged?.Invoke(this, new RecordingStatusChangedEventArgs((long)elapsedTime, (long)fileSize)); }; Native.SetRecordingProgressCallback(_handle, _recordingProgressCallback, IntPtr.Zero). ThrowIfError("Failed to initialize RecordingStatusChanged event"); }
private void RegisterRecordingLimitReachedEvent() { _recordingLimitReachedCallback = (RecordingLimitType type, IntPtr userData) => { RecordingLimitReached?.Invoke(this, new RecordingLimitReachedEventArgs(type)); }; Native.SetLimitReachedCallback(_handle, _recordingLimitReachedCallback, IntPtr.Zero). ThrowIfError("Failed to initialize RecordingLimitReached event"); }
private void RegisterInterruptingEvent() { _interruptingCallback = (policy, state, _) => { Interrupting?.Invoke(this, new RecorderInterruptingEventArgs(policy, state)); }; Native.SetInterruptStartedCallback(_handle, _interruptingCallback). ThrowIfError("Failed to initialize Interrupting event"); }
private static void RegisterDeviceStateChangedEvent() { _deviceStateChangedCallback = (type, state, _) => { _deviceStateChanged?.Invoke(null, new RecorderDeviceStateChangedEventArgs(type, state)); }; Native.AddDeviceStateChangedCallback(_deviceStateChangedCallback, IntPtr.Zero, out _deviceStateChangedId). ThrowIfError("Failed to add the event handler."); }
private void RegisterErrorCallback() { _errorOccurredCallback = (error, state, _) => { ErrorOccurred?.Invoke(this, new RecordingErrorOccurredEventArgs(error, state)); }; Native.SetErrorCallback(_handle, _errorOccurredCallback, IntPtr.Zero). ThrowIfError("Failed to initialize ErrorOccurred event"); }
/// <summary> /// Apply the audio stream policy. /// </summary> /// <remarks> /// The recorder must be in the <see cref="RecorderState.Idle"/> or the <see cref="RecorderState.Ready"/> state. /// </remarks> /// <param name="policy">The policy to apply.</param> /// <exception cref="ArgumentNullException"><paramref name="policy"/> is null.</exception> /// <exception cref="InvalidOperationException"> /// The recorder is not in the valid state.<br/> /// -or-<br/> /// <paramref name="policy"/> is not supported for the recorder.<br/> /// -or-<br/> /// An internal error occurred. /// </exception> /// <exception cref="ObjectDisposedException"> /// The recorder already has been disposed of.<br/> /// -or-<br/> /// <paramref name="policy"/> already has been disposed of. /// </exception> /// <since_tizen> 4 </since_tizen> public void ApplyAudioStreamPolicy(AudioStreamPolicy policy) { if (policy == null) { throw new ArgumentNullException(nameof(policy)); } ValidateState(RecorderState.Idle, RecorderState.Ready); Native.SetAudioStreamPolicy(Handle, policy.Handle).ThrowIfError("Failed to apply the audio stream policy."); }
private void RegisterStateChangedEvent() { _stateChangedCallback = (RecorderState previous, RecorderState current, bool byPolicy, IntPtr userData) => { SetState(current); StateChanged?.Invoke(this, new RecorderStateChangedEventArgs(previous, current, byPolicy)); }; Native.SetStateChangedCallback(_handle, _stateChangedCallback, IntPtr.Zero). ThrowIfError("Failed to initialize StateChanged event"); }
private static NativeHandle CreateHandle(Camera camera) { if (camera == null) { throw new ArgumentNullException(nameof(camera)); } Native.CreateVideo(camera.Handle, out var handle). ThrowIfError("Failed to create video recorder."); return(handle); }
private static IEnumerable <Size> LoadVideoResolutions(CameraDevice device) { using (var camera = new Camera(device)) { Native.CreateVideo(camera.Handle, out var handle).ThrowIfError("Failed to get the resolutions"); using (handle) { return(GetVideoResolutions(handle)); } } }
private void RegisterMuxedStreamEvent() { _muxedStreamCallback = (IntPtr stream, int streamSize, ulong offset, IntPtr userData) => { using (var buffer = new ScopedMediaBuffer(stream, streamSize, true)) { MuxedStreamDelivered?.Invoke(this, new MuxedStreamDeliveredEventArgs(buffer, offset)); } }; Native.SetMuxedStreamCallback(_handle, _muxedStreamCallback, IntPtr.Zero). ThrowIfError("Failed to initialize MuxedStreamDelivered event"); }
/// <summary> /// Prepares the media recorder for recording. /// </summary> /// <remarks> /// The recorder should be in the <see cref="RecorderState.Idle"/> state. /// The state of the recorder will be the <see cref="RecorderState.Ready"/> after this. /// It has no effect if the current state is the <see cref="RecorderState.Ready"/>. /// </remarks> /// <exception cref="InvalidOperationException"> /// The recorder is not in the valid state.<br/> /// -or-<br/> /// An internal error occurred. /// </exception> /// <exception cref="ObjectDisposedException">The recorder already has been disposed of.</exception> /// <since_tizen> 3 </since_tizen> public void Prepare() { if (_state == RecorderState.Ready) { return; } ValidateState(RecorderState.Idle); Native.Prepare(Handle).ThrowIfError("Failed to prepare media recorder"); SetState(RecorderState.Ready); }
/// <summary> /// Pauses the recording. /// </summary> /// <remarks> /// The recorder should be in the <see cref="RecorderState.Recording"/> state. /// The state of the recorder will be the <see cref="RecorderState.Paused"/> after this. /// It has no effect if the current state is the <see cref="RecorderState.Paused"/>. /// </remarks> /// <exception cref="InvalidOperationException"> /// The recorder is not in the valid state.<br/> /// -or-<br/> /// An internal error occurred. /// </exception> /// <exception cref="ObjectDisposedException">The recorder already has been disposed of.</exception> /// <since_tizen> 3 </since_tizen> public void Pause() { if (_state == RecorderState.Paused) { return; } ValidateState(RecorderState.Recording); Native.Pause(Handle).ThrowIfError("Failed to pause the media recorder"); SetState(RecorderState.Paused); }
/// <summary> /// Resets the media recorder. /// </summary> /// <remarks> /// The recorder should be in the <see cref="RecorderState.Ready"/> state. /// The state of recorder will be the <see cref="RecorderState.Idle"/> after this. /// It has no effect if the current state is the <see cref="RecorderState.Idle"/>. /// </remarks> /// <exception cref="InvalidOperationException"> /// The recorder is not in the valid state.<br/> /// -or-<br/> /// An internal error occurred. /// </exception> /// <exception cref="ObjectDisposedException">The recorder already has been disposed of.</exception> /// <since_tizen> 3 </since_tizen> public void Unprepare() { ThrowIfAccessedInAudioStreamStoring(); if (_state == RecorderState.Idle) { return; } ValidateState(RecorderState.Ready); Native.Unprepare(Handle).ThrowIfError("Failed to reset the media recorder"); SetState(RecorderState.Idle); }
private static IEnumerable <Size> GetVideoResolutions(NativeHandle handle) { var result = new List <Size>(); var ret = Native.GetVideoResolutions(handle, (w, h, _) => { result.Add(new Size(w, h)); return(true); }); if (ret == RecorderErrorCode.NotSupported) { throw new NotSupportedException("Video recording is not supported."); } ret.ThrowIfError("Failed to load the resolutions"); return(result.AsReadOnly()); }
private static IEnumerable <Size> LoadVideoResolutions(CameraDevice device) { if (!Features.IsSupported(RecorderFeatures.VideoRecorder)) { throw new NotSupportedException("Video Recorder is not supported."); } using (var camera = new Camera(device)) { Native.CreateVideo(camera.Handle, out var handle).ThrowIfError("Failed to get the resolutions"); using (handle) { return(GetVideoResolutions(handle)); } } }
private static NativeHandle CreateHandle(Camera camera) { if (camera == null) { throw new ArgumentNullException(nameof(camera)); } if (!Features.IsSupported(RecorderFeatures.VideoRecorder)) { throw new NotSupportedException("Video Recorder is not supported."); } Native.CreateVideo(camera.Handle, out var handle). ThrowIfError("Failed to create video recorder."); return(handle); }
private void RegisterAudioStreamDeliveredEvent() { _audioStreamCallback = (stream, streamSize, type, channel, recordingTime, _) => { var handler = AudioStreamStoring; if (handler != null) { _isInAudioStreamStoring.Value = true; using (var buffer = new ScopedMediaBuffer(stream, streamSize)) { handler.Invoke(this, new AudioStreamStoringEventArgs(buffer, type, channel, recordingTime)); } } }; Native.SetAudioStreamCallback(_handle, _audioStreamCallback, IntPtr.Zero). ThrowIfError("Failed to initialize AudioStreamStoring event"); }
/// <summary> /// Starts the recording. /// </summary> /// <remarks> /// The recorder must be in the <see cref="RecorderState.Ready"/> state. /// The state of the recorder will be the <see cref="RecorderState.Recording"/> after this. <br/> /// <br/> /// If the specified path exists, the file is removed automatically and updated by new one.<br/> /// The mediastorage privilege(http://tizen.org/privilege/mediastorage) is required if the path is relevant to media storage.<br/> /// The externalstorage privilege(http://tizen.org/privilege/externalstorage) is required if the path is relevant to external storage.<br/> /// <br/> /// In the video recorder, some preview format does not support record mode. /// You should use the default preview format or the <see cref="CameraPixelFormat.Nv12"/> in the record mode. /// </remarks> /// <param name="savePath">The file path for recording result.</param> /// <privilege>http://tizen.org/privilege/recorder</privilege> /// <exception cref="InvalidOperationException"> /// The recorder is not in the valid state.<br/> /// -or-<br/> /// The preview format of the camera is not supported.<br/> /// -or-<br/> /// An internal error occurred. /// </exception> /// <exception cref="ObjectDisposedException">The recorder already has been disposed of.</exception> /// <exception cref="ArgumentNullException"><paramref name="savePath"/> is null.</exception> /// <exception cref="ArgumentException"><paramref name="savePath"/> is a zero-length string, contains only white space.</exception> /// <exception cref="UnauthorizedAccessException">Caller does not have required privilege.</exception> /// <seealso cref="Commit"/> /// <seealso cref="Cancel"/> /// <since_tizen> 4 </since_tizen> public void Start(string savePath) { ValidateState(RecorderState.Ready); if (savePath == null) { throw new ArgumentNullException(nameof(savePath)); } if (string.IsNullOrWhiteSpace(savePath)) { throw new ArgumentException($"{nameof(savePath)} is an empty string.", nameof(savePath)); } Native.SetFileName(Handle, savePath).ThrowIfError("Failed to set save path."); Native.Start(Handle).ThrowIfError("Failed to start the media recorder"); SetState(RecorderState.Recording); }
private RecorderErrorCode GetVideoEncoders(NativeHandle handle, List <RecorderVideoCodec> result) => Native.GetVideoEncoders(handle, (codec, _) => { result.Add(codec); return(true); });
private RecorderErrorCode GetFileFormats(NativeHandle handle, List <RecorderFileFormat> result) => Native.GetFileFormats(handle, (format, _) => { result.Add(format); return(true); });