-
Notifications
You must be signed in to change notification settings - Fork 241
/
StreamRecorder.Events.cs
140 lines (120 loc) · 5.43 KB
/
StreamRecorder.Events.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
* Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Diagnostics;
using Native = Interop.StreamRecorder;
namespace Tizen.Multimedia
{
/// <since_tizen> 3 </since_tizen>
public partial class StreamRecorder
{
/// <summary>
/// Occurs when <see cref="StreamRecorder"/> state is changed.
/// </summary>
/// <since_tizen> 4 </since_tizen>
[Obsolete("Deprecated in API10; Will be removed in API12")]
public event EventHandler<StreamRecorderStateChangedEventArgs> StateChanged;
/// <summary>
/// Occurs when a buffer had consumed completely.
/// </summary>
/// <since_tizen> 3 </since_tizen>
[Obsolete("Deprecated in API10; Will be removed in API12")]
public event EventHandler<StreamRecorderBufferConsumedEventArgs> BufferConsumed;
/// <summary>
/// Occurs when recording status is changed.
/// </summary>
/// <since_tizen> 3 </since_tizen>
[Obsolete("Deprecated in API10; Will be removed in API12")]
public event EventHandler<RecordingStatusChangedEventArgs> RecordingStatusChanged;
/// <summary>
/// Occurs when recording limit is reached.
/// </summary>
/// <since_tizen> 3 </since_tizen>
[Obsolete("Deprecated in API10; Will be removed in API12")]
public event EventHandler<RecordingLimitReachedEventArgs> RecordingLimitReached;
/// <summary>
/// Occurs when an error occurred during a recorder operation.
/// </summary>
/// <since_tizen> 4 </since_tizen>
[Obsolete("Deprecated in API10; Will be removed in API12")]
public event EventHandler<StreamRecorderErrorOccurredEventArgs> ErrorOccurred;
private Native.RecordingLimitReachedCallback _recordingLimitReachedCallback;
private Native.RecorderErrorCallback _recorderErrorCallback;
private Native.RecordingStatusCallback _recordingStatusCallback;
private Native.BufferConsumedCallback _bufferConsumedCallback;
private Native.NotifiedCallback _notifiedCallback;
private void RegisterStreamRecorderNotifiedEvent()
{
_notifiedCallback = (previous, current, notify, _) =>
{
if (previous == 0)
{
return;
}
StateChanged?.Invoke(this, new StreamRecorderStateChangedEventArgs(
(RecorderState)previous, (RecorderState)current));
};
Native.SetNotifiedCallback(_handle, _notifiedCallback).
ThrowIfError("Failed to initialize state changed event.");
}
private void RegisterBufferConsumedEvent()
{
_bufferConsumedCallback = (lockedPacketHandle, _) =>
{
MediaPacket packet = null;
// Lock must be disposed here, note that the packet won't be disposed.
using (MediaPacket.Lock packetLock =
MediaPacket.Lock.FromHandle(lockedPacketHandle))
{
Debug.Assert(packetLock != null);
packet = packetLock.MediaPacket;
}
BufferConsumed?.Invoke(this, new StreamRecorderBufferConsumedEventArgs(packet));
};
Native.SetBufferConsumedCallback(_handle, _bufferConsumedCallback).
ThrowIfError("Failed to initialize buffer consumed event.");
}
private void RegisterRecordingStatusChangedEvent()
{
_recordingStatusCallback = (elapsedTime, fileSize, _) =>
{
RecordingStatusChanged?.Invoke(this, new RecordingStatusChangedEventArgs((long)elapsedTime, (long)fileSize));
};
Native.SetStatusChangedCallback(_handle, _recordingStatusCallback).
ThrowIfError("Failed to initialize status changed event.");
}
private void RegisterRecordingLimitReachedEvent()
{
_recordingLimitReachedCallback = (type, _) =>
{
RecordingLimitReached?.Invoke(this, new RecordingLimitReachedEventArgs(type));
};
Native.SetLimitReachedCallback(_handle, _recordingLimitReachedCallback).
ThrowIfError("Failed to initialize limit reached event.");
}
private void RegisterRecordingErrorOccurredEvent()
{
_recorderErrorCallback = (error, currentState, _) =>
{
ErrorOccurred?.Invoke(this, new StreamRecorderErrorOccurredEventArgs(
error == StreamRecorderErrorCode.OutOfStorage ?
StreamRecorderError.OutOfStorage : StreamRecorderError.InternalError, currentState));
};
Native.SetErrorCallback(_handle, _recorderErrorCallback).
ThrowIfError("Failed to set error callback");
}
}
}