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 Tizen.Multimedia;
21 internal static partial class Interop
23 internal static partial class Recorder
25 [DllImport(Libraries.Recorder, EntryPoint = "recorder_create_audiorecorder")]
26 internal static extern RecorderErrorCode Create(out RecorderHandle handle);
28 [DllImport(Libraries.Recorder, EntryPoint = "recorder_create_videorecorder")]
29 internal static extern RecorderErrorCode CreateVideo(IntPtr cameraHandle, out RecorderHandle handle);
31 [DllImport(Libraries.Recorder, EntryPoint = "recorder_prepare")]
32 internal static extern RecorderErrorCode Prepare(RecorderHandle handle);
34 [DllImport(Libraries.Recorder, EntryPoint = "recorder_unprepare")]
35 internal static extern RecorderErrorCode Unprepare(RecorderHandle handle);
37 [DllImport(Libraries.Recorder, EntryPoint = "recorder_start")]
38 internal static extern RecorderErrorCode Start(RecorderHandle handle);
40 [DllImport(Libraries.Recorder, EntryPoint = "recorder_pause")]
41 internal static extern RecorderErrorCode Pause(RecorderHandle handle);
43 [DllImport(Libraries.Recorder, EntryPoint = "recorder_commit")]
44 internal static extern RecorderErrorCode Commit(RecorderHandle handle);
46 [DllImport(Libraries.Recorder, EntryPoint = "recorder_cancel")]
47 internal static extern RecorderErrorCode Cancel(RecorderHandle handle);
49 [DllImport(Libraries.Recorder, EntryPoint = "recorder_get_state")]
50 internal static extern RecorderErrorCode GetState(RecorderHandle handle, out RecorderState state);
52 [DllImport(Libraries.Recorder, EntryPoint = "recorder_set_sound_stream_info")]
53 internal static extern RecorderErrorCode SetAudioStreamPolicy(RecorderHandle handle, AudioStreamPolicyHandle streamInfoHandle);
55 [DllImport(Libraries.Recorder, EntryPoint = "recorder_get_device_state")]
56 internal static extern RecorderErrorCode GetDeviceState(RecorderType type, out RecorderDeviceState state);
59 internal class RecorderHandle : SafeHandle
61 [DllImport(Libraries.Recorder, EntryPoint = "recorder_destroy")]
62 private static extern RecorderErrorCode Destroy(IntPtr handle);
64 [DllImport(Libraries.Recorder, EntryPoint = "recorder_cancel")]
65 private static extern RecorderErrorCode Cancel(IntPtr handle);
67 [DllImport(Libraries.Recorder, EntryPoint = "recorder_unprepare")]
68 private static extern RecorderErrorCode Unprepare(IntPtr handle);
70 protected RecorderHandle() : base(IntPtr.Zero, true)
74 public override bool IsInvalid => handle == IntPtr.Zero;
76 protected override bool ReleaseHandle()
78 Cancel(handle).Ignore(RecorderErrorCode.InvalidState).ThrowIfError("Failed to cancel");
79 Unprepare(handle).Ignore(RecorderErrorCode.InvalidState).ThrowIfError("Failed to unprepare");
81 var ret = Destroy(handle);
82 if (ret != RecorderErrorCode.None)
84 Tizen.Log.Debug(GetType().FullName, $"Failed to release native RecorderHandle.");