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
24 internal static partial class Recorder
26 [DllImport(Libraries.Recorder, EntryPoint = "recorder_create_audiorecorder")]
27 internal static extern RecorderErrorCode Create(out RecorderHandle handle);
29 [DllImport(Libraries.Recorder, EntryPoint = "recorder_create_videorecorder")]
30 internal static extern RecorderErrorCode CreateVideo(IntPtr cameraHandle, out RecorderHandle handle);
32 [DllImport(Libraries.Recorder, EntryPoint = "recorder_prepare")]
33 internal static extern RecorderErrorCode Prepare(RecorderHandle handle);
35 [DllImport(Libraries.Recorder, EntryPoint = "recorder_unprepare")]
36 internal static extern RecorderErrorCode Unprepare(RecorderHandle handle);
38 [DllImport(Libraries.Recorder, EntryPoint = "recorder_start")]
39 internal static extern RecorderErrorCode Start(RecorderHandle handle);
41 [DllImport(Libraries.Recorder, EntryPoint = "recorder_pause")]
42 internal static extern RecorderErrorCode Pause(RecorderHandle handle);
44 [DllImport(Libraries.Recorder, EntryPoint = "recorder_commit")]
45 internal static extern RecorderErrorCode Commit(RecorderHandle handle);
47 [DllImport(Libraries.Recorder, EntryPoint = "recorder_cancel")]
48 internal static extern RecorderErrorCode Cancel(RecorderHandle handle);
50 [DllImport(Libraries.Recorder, EntryPoint = "recorder_get_state")]
51 internal static extern RecorderErrorCode GetState(RecorderHandle handle, out RecorderState state);
53 [DllImport(Libraries.Recorder, EntryPoint = "recorder_set_sound_stream_info")]
54 internal static extern RecorderErrorCode SetAudioStreamPolicy(RecorderHandle handle, AudioStreamPolicyHandle streamInfoHandle);
56 [DllImport(Libraries.Recorder, EntryPoint = "recorder_get_device_state")]
57 internal static extern RecorderErrorCode GetDeviceState(RecorderType type, out RecorderDeviceState state);
60 internal class RecorderHandle : SafeHandle
62 [DllImport(Libraries.Recorder, EntryPoint = "recorder_destroy")]
63 private static extern RecorderErrorCode Destroy(IntPtr handle);
65 [DllImport(Libraries.Recorder, EntryPoint = "recorder_cancel")]
66 private static extern RecorderErrorCode Cancel(IntPtr handle);
68 [DllImport(Libraries.Recorder, EntryPoint = "recorder_unprepare")]
69 private static extern RecorderErrorCode Unprepare(IntPtr handle);
71 protected RecorderHandle() : base(IntPtr.Zero, true)
75 public override bool IsInvalid => handle == IntPtr.Zero;
77 protected override bool ReleaseHandle()
79 Cancel(handle).Ignore(RecorderErrorCode.InvalidState).ThrowIfError("Failed to cancel");
80 Unprepare(handle).Ignore(RecorderErrorCode.InvalidState).ThrowIfError("Failed to unprepare");
82 var ret = Destroy(handle);
83 if (ret != RecorderErrorCode.None)
85 Tizen.Log.Debug(GetType().FullName, $"Failed to release native RecorderHandle.");