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.Diagnostics;
19 using Native = Interop.StreamRecorder;
21 namespace Tizen.Multimedia
23 public partial class StreamRecorder
26 /// Occurs when <see cref="StreamRecorder"/> state is changed.
28 public event EventHandler<StreamRecorderStateChangedEventArgs> StateChanged;
32 /// Occurs when a buffer had consumed completely.
34 public event EventHandler<StreamRecorderBufferConsumedEventArgs> BufferConsumed;
37 /// Occurs when recording status is changed.
39 public event EventHandler<RecordingStatusChangedEventArgs> RecordingStatusChanged;
42 /// Occurs when recording limit is reached.
44 public event EventHandler<RecordingLimitReachedEventArgs> RecordingLimitReached;
47 /// Occurs when an error occurred during a recorder operation.
49 public event EventHandler<StreamRecorderErrorOccurredEventArgs> ErrorOccurred;
51 private Native.RecordingLimitReachedCallback _recordingLimitReachedCallback;
52 private Native.RecorderErrorCallback _recorderErrorCallback;
53 private Native.RecordingStatusCallback _recordingStatusCallback;
54 private Native.BufferConsumedCallback _bufferConsumedCallback;
55 private Native.NotifiedCallback _notifiedCallback;
57 private void RegisterStreamRecorderNotifiedEvent()
59 _notifiedCallback = (previous, current, notify, _) =>
66 StateChanged?.Invoke(this, new StreamRecorderStateChangedEventArgs(
67 (RecorderState)previous, (RecorderState)current));
70 Native.SetNotifiedCallback(_handle, _notifiedCallback).
71 ThrowIfError("Failed to initialize state changed event.");
74 private void RegisterBufferConsumedEvent()
76 _bufferConsumedCallback = (lockedPacketHandle, _) =>
78 MediaPacket packet = null;
80 // Lock must be disposed here, note that the packet won't be disposed.
81 using (MediaPacket.Lock packetLock =
82 MediaPacket.Lock.FromHandle(lockedPacketHandle))
84 Debug.Assert(packetLock != null);
86 packet = packetLock.MediaPacket;
89 BufferConsumed?.Invoke(this, new StreamRecorderBufferConsumedEventArgs(packet));
92 Native.SetBufferConsumedCallback(_handle, _bufferConsumedCallback).
93 ThrowIfError("Failed to initialize buffer consumed event.");
96 private void RegisterRecordingStatusChangedEvent()
98 _recordingStatusCallback = (elapsedTime, fileSize, _) =>
100 RecordingStatusChanged?.Invoke(this, new RecordingStatusChangedEventArgs((long)elapsedTime, (long)fileSize));
102 Native.SetStatusChangedCallback(_handle, _recordingStatusCallback).
103 ThrowIfError("Failed to initialize status changed event.");
106 private void RegisterRecordingLimitReachedEvent()
108 _recordingLimitReachedCallback = (type, _) =>
110 RecordingLimitReached?.Invoke(this, new RecordingLimitReachedEventArgs(type));
113 Native.SetLimitReachedCallback(_handle, _recordingLimitReachedCallback).
114 ThrowIfError("Failed to initialize limit reached event.");
117 private void RegisterRecordingErrorOccurredEvent()
119 _recorderErrorCallback = (error, currentState, _) =>
121 ErrorOccurred?.Invoke(this, new StreamRecorderErrorOccurredEventArgs(
122 error == StreamRecorderErrorCode.OutOfStorage ?
123 StreamRecorderError.OutOfStorage : StreamRecorderError.InternalError, currentState));
125 Native.SetErrorCallback(_handle, _recorderErrorCallback).
126 ThrowIfError("Failed to set error callback");