Splitted the project into multiple module level projects.
[platform/core/csapi/tizenfx.git] / src / Tizen.Multimedia.MediaPlayer / Interop / Interop.Player.cs
1 using System;
2 using System.Runtime.InteropServices;
3 using Tizen;
4 using Tizen.Multimedia;
5
6 internal static partial class Interop
7 {
8     internal static partial class NativePlayer
9     {
10
11         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
12         internal delegate void PlaybackCompletedCallback(IntPtr userData);
13
14         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
15         internal delegate void PlaybackInterruptedCallback(PlaybackInterruptionReason code, IntPtr userData);
16
17         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
18         internal delegate void PlaybackErrorCallback(int code, IntPtr userData);
19
20         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
21         internal delegate void VideoFrameDecodedCallback(IntPtr packetHandle, IntPtr userData);
22
23         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
24         internal delegate void SubtitleUpdatedCallback(uint duration, string text, IntPtr userData);
25
26         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
27         internal delegate void BufferingProgressCallback(int percent, IntPtr userData);
28
29         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
30         internal delegate void VideoStreamChangedCallback(int width, int height, int fps, int bitrate, IntPtr userData);
31
32         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
33         internal delegate void MediaStreamBufferStatusCallback(MediaStreamBufferStatus status, IntPtr userData);
34
35         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
36         internal delegate void MediaStreamSeekCallback(ulong offset, IntPtr userData);
37
38         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
39         internal delegate void VideoCaptureCallback(IntPtr data, int width, int height, uint size, IntPtr userData);
40
41         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
42         internal delegate void PrepareCallback(IntPtr userData);
43
44         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
45         internal delegate void SeekCompletedCallback(IntPtr userData);
46
47
48         [DllImport(Libraries.Player, EntryPoint = "player_create")]
49         internal static extern PlayerErrorCode Create(out PlayerHandle player);
50
51         [DllImport(Libraries.Player, EntryPoint = "player_destroy")]
52         internal static extern PlayerErrorCode Destroy(IntPtr player);
53
54         [DllImport(Libraries.Player, EntryPoint = "player_prepare")]
55         internal static extern PlayerErrorCode Prepare(IntPtr player);
56
57         [DllImport(Libraries.Player, EntryPoint = "player_unprepare")]
58         internal static extern PlayerErrorCode Unprepare(IntPtr player);
59
60         [DllImport(Libraries.Player, EntryPoint = "player_set_uri")]
61         internal static extern PlayerErrorCode SetUri(IntPtr player, string uri);
62
63         [DllImport(Libraries.Player, EntryPoint = "player_set_display")]
64         internal static extern PlayerErrorCode SetDisplay(IntPtr player, DisplayType type, IntPtr display);
65
66         [DllImport(Libraries.Player, EntryPoint = "player_start")]
67         internal static extern PlayerErrorCode Start(IntPtr player);
68
69         [DllImport(Libraries.Player, EntryPoint = "player_stop")]
70         internal static extern PlayerErrorCode Stop(IntPtr player);
71
72         [DllImport(Libraries.Player, EntryPoint = "player_pause")]
73         internal static extern PlayerErrorCode Pause(IntPtr player);
74
75         [DllImport(Libraries.Player, EntryPoint = "player_set_memory_buffer")]
76         internal static extern PlayerErrorCode SetMemoryBuffer(IntPtr player, byte[] data, int size);
77
78         [DllImport(Libraries.Player, EntryPoint = "player_get_state")]
79         internal static extern PlayerErrorCode GetState(IntPtr player, out int state);
80
81         [DllImport(Libraries.Player, EntryPoint = "player_set_volume")]
82         internal static extern PlayerErrorCode SetVolume(IntPtr player, float left, float right);
83
84         [DllImport(Libraries.Player, EntryPoint = "player_get_volume")]
85         internal static extern PlayerErrorCode GetVolume(IntPtr player, out float left, out float right);
86
87         [DllImport(Libraries.Player, EntryPoint = "player_set_sound_stream_info")]
88         internal static extern PlayerErrorCode SetAudioPolicyInfo(IntPtr player, IntPtr streamInfo);
89
90         [DllImport(Libraries.Player, EntryPoint = "player_set_audio_latency_mode")]
91         internal static extern PlayerErrorCode SetAudioLatencyMode(IntPtr player, AudioLatencyMode latencyMode);
92
93         [DllImport(Libraries.Player, EntryPoint = "player_get_audio_latency_mode")]
94         internal static extern PlayerErrorCode GetAudioLatencyMode(IntPtr player, out AudioLatencyMode latencyMode);
95
96         [DllImport(Libraries.Player, EntryPoint = "player_get_play_position")]
97         internal static extern PlayerErrorCode GetPlayPosition(IntPtr player, out int millisecond);
98
99         [DllImport(Libraries.Player, EntryPoint = "player_set_play_position")]
100         internal static extern PlayerErrorCode SetPlayPosition(IntPtr player, int millisecond,
101             bool accurate, SeekCompletedCallback cb, IntPtr userData = default(IntPtr));
102
103         [DllImport(Libraries.Player, EntryPoint = "player_set_mute")]
104         internal static extern PlayerErrorCode SetMute(IntPtr player, bool muted);
105
106         [DllImport(Libraries.Player, EntryPoint = "player_is_muted")]
107         internal static extern PlayerErrorCode IsMuted(IntPtr player, out bool muted);
108
109         [DllImport(Libraries.Player, EntryPoint = "player_set_looping")]
110         internal static extern PlayerErrorCode SetLooping(IntPtr player, bool looping);
111
112         [DllImport(Libraries.Player, EntryPoint = "player_is_looping")]
113         internal static extern PlayerErrorCode IsLooping(IntPtr player, out bool looping);
114
115         [DllImport(Libraries.Player, EntryPoint = "player_set_completed_cb")]
116         internal static extern PlayerErrorCode SetCompletedCb(IntPtr player,
117             PlaybackCompletedCallback callback, IntPtr userData = default(IntPtr));
118
119         [DllImport(Libraries.Player, EntryPoint = "player_unset_completed_cb")]
120         internal static extern PlayerErrorCode UnsetCompletedCb(IntPtr player);
121
122         [DllImport(Libraries.Player, EntryPoint = "player_set_interrupted_cb")]
123         internal static extern PlayerErrorCode SetInterruptedCb(IntPtr player,
124             PlaybackInterruptedCallback callback, IntPtr userData = default(IntPtr));
125
126         [DllImport(Libraries.Player, EntryPoint = "player_unset_interrupted_cb")]
127         internal static extern PlayerErrorCode UnsetInterruptedCb(IntPtr player);
128
129         [DllImport(Libraries.Player, EntryPoint = "player_set_error_cb")]
130         internal static extern PlayerErrorCode SetErrorCb(IntPtr player, PlaybackErrorCallback callback,
131             IntPtr userData = default(IntPtr));
132
133         [DllImport(Libraries.Player, EntryPoint = "player_unset_error_cb")]
134         internal static extern PlayerErrorCode UnsetErrorCb(IntPtr player);
135
136         [DllImport(Libraries.Player, EntryPoint = "player_capture_video")]
137         internal static extern PlayerErrorCode CaptureVideo(IntPtr player, VideoCaptureCallback callback,
138             IntPtr userData = default(IntPtr));
139
140         [DllImport(Libraries.Player, EntryPoint = "player_set_media_packet_video_frame_decoded_cb")]
141         internal static extern PlayerErrorCode SetVideoFrameDecodedCb(IntPtr player, VideoFrameDecodedCallback callback,
142             IntPtr userData = default(IntPtr));
143
144         [DllImport(Libraries.Player, EntryPoint = "player_unset_media_packet_video_frame_decoded_cb")]
145         internal static extern PlayerErrorCode UnsetVideoFrameDecodedCb(IntPtr player);
146
147         [DllImport(Libraries.Player, EntryPoint = "player_set_streaming_cookie")]
148         internal static extern PlayerErrorCode SetStreamingCookie(IntPtr player, string cookie, int size);
149
150         [DllImport(Libraries.Player, EntryPoint = "player_set_streaming_user_agent")]
151         internal static extern PlayerErrorCode SetStreamingUserAgent(IntPtr player, string userAgent, int size);
152
153         [DllImport(Libraries.Player, EntryPoint = "player_get_streaming_download_progress")]
154         internal static extern PlayerErrorCode GetStreamingDownloadProgress(IntPtr player, out int start, out int current);
155
156         [DllImport(Libraries.Player, EntryPoint = "player_set_buffering_cb")]
157         internal static extern PlayerErrorCode SetBufferingCb(IntPtr player,
158             BufferingProgressCallback callback, IntPtr userData = default(IntPtr));
159
160         [DllImport(Libraries.Player, EntryPoint = "player_unset_buffering_cb")]
161         internal static extern PlayerErrorCode UnsetBufferingCb(IntPtr player);
162
163         [DllImport(Libraries.Player, EntryPoint = "player_set_playback_rate")]
164         internal static extern PlayerErrorCode SetPlaybackRate(IntPtr player, float rate);
165
166         [DllImport(Libraries.Player, EntryPoint = "player_push_media_stream")]
167         internal static extern PlayerErrorCode PushMediaStream(IntPtr player, IntPtr packet);
168
169         [DllImport(Libraries.Player, EntryPoint = "player_set_media_stream_info")]
170         internal static extern PlayerErrorCode SetMediaStreamInfo(IntPtr player, int type, IntPtr format);
171
172         [DllImport(Libraries.Player, EntryPoint = "player_set_media_stream_buffer_status_cb")]
173         internal static extern PlayerErrorCode SetMediaStreamBufferStatusCb(IntPtr player, StreamType type,
174             MediaStreamBufferStatusCallback callback, IntPtr userData = default(IntPtr));
175
176         [DllImport(Libraries.Player, EntryPoint = "player_unset_media_stream_buffer_status_cb")]
177         internal static extern PlayerErrorCode UnsetMediaStreamBufferStatusCb(IntPtr player, int type);
178
179         [DllImport(Libraries.Player, EntryPoint = "player_set_media_stream_seek_cb")]
180         internal static extern PlayerErrorCode SetMediaStreamSeekCb(IntPtr player, StreamType type,
181             MediaStreamSeekCallback callback, IntPtr userData = default(IntPtr));
182
183         [DllImport(Libraries.Player, EntryPoint = "player_unset_media_stream_seek_cb")]
184         internal static extern PlayerErrorCode UnsetMediaStreamSeekCb(IntPtr player, int type);
185
186         [DllImport(Libraries.Player, EntryPoint = "player_set_media_stream_buffer_max_size")]
187         internal static extern PlayerErrorCode SetMediaStreamBufferMaxSize(IntPtr player, StreamType type, ulong maxSize);
188
189         [DllImport(Libraries.Player, EntryPoint = "player_get_media_stream_buffer_max_size")]
190         internal static extern PlayerErrorCode GetMediaStreamBufferMaxSize(IntPtr player, StreamType type, out ulong maxSize);
191
192         [DllImport(Libraries.Player, EntryPoint = "player_set_media_stream_buffer_min_threshold")]
193         internal static extern PlayerErrorCode SetMediaStreamBufferMinThreshold(IntPtr player, StreamType type, uint percent);
194
195         [DllImport(Libraries.Player, EntryPoint = "player_get_media_stream_buffer_min_threshold")]
196         internal static extern PlayerErrorCode GetMediaStreamBufferMinThreshold(IntPtr player, int type, out uint percent);
197
198         [DllImport(Libraries.Player, EntryPoint = "player_audio_effect_get_equalizer_bands_count")]
199         internal static extern PlayerErrorCode AudioEffectGetEqualizerBandsCount(IntPtr player, out int count);
200
201         [DllImport(Libraries.Player, EntryPoint = "player_audio_effect_set_equalizer_band_level")]
202         internal static extern PlayerErrorCode AudioEffectSetEqualizerBandLevel(IntPtr player, int index, int level);
203
204         [DllImport(Libraries.Player, EntryPoint = "player_audio_effect_get_equalizer_band_level")]
205         internal static extern PlayerErrorCode AudioEffectGetEqualizerBandLevel(IntPtr player, int index, out int level);
206
207         [DllImport(Libraries.Player, EntryPoint = "player_audio_effect_set_equalizer_all_bands")]
208         internal static extern PlayerErrorCode AudioEffectSetEqualizerAllBands(IntPtr player, out int band_levels, int length);
209
210         [DllImport(Libraries.Player, EntryPoint = "player_audio_effect_get_equalizer_level_range")]
211         internal static extern PlayerErrorCode AudioEffectGetEqualizerLevelRange(IntPtr player, out int min, out int max);
212
213         [DllImport(Libraries.Player, EntryPoint = "player_audio_effect_get_equalizer_band_frequency")]
214         internal static extern PlayerErrorCode AudioEffectGetEqualizerBandFrequency(IntPtr player, int index, out int frequency);
215
216         [DllImport(Libraries.Player, EntryPoint = "player_audio_effect_get_equalizer_band_frequency_range")]
217         internal static extern PlayerErrorCode AudioEffectGetEqualizerBandFrequencyRange(IntPtr player, int index, out int range);
218
219         [DllImport(Libraries.Player, EntryPoint = "player_audio_effect_equalizer_clear")]
220         internal static extern PlayerErrorCode AudioEffectEqualizerClear(IntPtr player);
221
222         [DllImport(Libraries.Player, EntryPoint = "player_audio_effect_equalizer_is_available")]
223         internal static extern PlayerErrorCode AudioEffectEqualizerIsAvailable(IntPtr player, out bool available);
224
225         [DllImport(Libraries.Player, EntryPoint = "player_set_display_mode")]
226         internal static extern PlayerErrorCode SetDisplayMode(IntPtr player, PlayerDisplayMode mode);
227
228         [DllImport(Libraries.Player, EntryPoint = "player_get_display_mode")]
229         internal static extern PlayerErrorCode GetDisplayMode(IntPtr player, out int mode);
230
231         [DllImport(Libraries.Player, EntryPoint = "player_set_display_visible")]
232         internal static extern PlayerErrorCode SetDisplayVisible(IntPtr player, bool visible);
233
234         [DllImport(Libraries.Player, EntryPoint = "player_is_display_visible")]
235         internal static extern PlayerErrorCode IsDisplayVisible(IntPtr player, out bool visible);
236
237         [DllImport(Libraries.Player, EntryPoint = "player_set_display_rotation")]
238         internal static extern PlayerErrorCode SetDisplayRotation(IntPtr player, PlayerDisplayRotation rotation);
239
240         [DllImport(Libraries.Player, EntryPoint = "player_get_display_rotation")]
241         internal static extern PlayerErrorCode GetDisplayRotation(IntPtr player, out int rotation);
242
243         [DllImport(Libraries.Player, EntryPoint = "player_set_display_roi_area")]
244         internal static extern PlayerErrorCode SetDisplayRoi(IntPtr player, int x, int y, int width, int height);
245
246         [DllImport(Libraries.Player, EntryPoint = "player_get_content_info")]
247         internal static extern PlayerErrorCode GetContentInfo(IntPtr player, StreamMetadataKey key, out IntPtr value);
248
249         [DllImport(Libraries.Player, EntryPoint = "player_get_codec_info")]
250         internal static extern PlayerErrorCode GetCodecInfo(IntPtr player, out IntPtr audioCodec, out IntPtr videoCodec);
251
252         [DllImport(Libraries.Player, EntryPoint = "player_get_audio_stream_info")]
253         internal static extern PlayerErrorCode GetAudioStreamInfo(IntPtr player, out int sampleRate, out int channel, out int bitRate);
254
255         [DllImport(Libraries.Player, EntryPoint = "player_get_video_stream_info")]
256         internal static extern PlayerErrorCode GetVideoStreamInfo(IntPtr player, out int fps, out int bitRate);
257
258         [DllImport(Libraries.Player, EntryPoint = "player_get_album_art")]
259         internal static extern PlayerErrorCode GetAlbumArt(IntPtr player, out IntPtr albumArt, out int size);
260
261         [DllImport(Libraries.Player, EntryPoint = "player_get_video_size")]
262         internal static extern PlayerErrorCode GetVideoSize(IntPtr player, out int width, out int height);
263
264         [DllImport(Libraries.Player, EntryPoint = "player_get_duration")]
265         internal static extern PlayerErrorCode GetDuration(IntPtr player, out int duration);
266
267         [DllImport(Libraries.Player, EntryPoint = "player_set_subtitle_path")]
268         internal static extern PlayerErrorCode SetSubtitlePath(IntPtr player, string path);
269
270         [DllImport(Libraries.Player, EntryPoint = "player_set_subtitle_updated_cb")]
271         internal static extern PlayerErrorCode SetSubtitleUpdatedCb(IntPtr player,
272             SubtitleUpdatedCallback callback, IntPtr userData = default(IntPtr));
273
274         [DllImport(Libraries.Player, EntryPoint = "player_unset_subtitle_updated_cb")]
275         internal static extern PlayerErrorCode UnsetSubtitleUpdatedCb(IntPtr player);
276
277         [DllImport(Libraries.Player, EntryPoint = "player_set_subtitle_position_offset")]
278         internal static extern PlayerErrorCode SetSubtitlePositionOffset(IntPtr player, int millisecond);
279
280         [DllImport(Libraries.Player, EntryPoint = "player_set_video_stream_changed_cb")]
281         internal static extern PlayerErrorCode SetVideoStreamChangedCb(IntPtr player,
282             VideoStreamChangedCallback callback, IntPtr userData = default(IntPtr));
283
284         [DllImport(Libraries.Player, EntryPoint = "player_unset_video_stream_changed_cb")]
285         internal static extern PlayerErrorCode UnsetVideoStreamChangedCb(IntPtr player);
286
287         [DllImport(Libraries.Player, EntryPoint = "player_get_track_count")]
288         internal static extern PlayerErrorCode GetTrackCount(IntPtr player, int type, out int count);
289
290         [DllImport(Libraries.Player, EntryPoint = "player_select_track")]
291         internal static extern PlayerErrorCode SelectTrack(IntPtr player, int type, int index);
292
293         [DllImport(Libraries.Player, EntryPoint = "player_get_current_track")]
294         internal static extern PlayerErrorCode GetCurrentTrack(IntPtr player, int type, out int index);
295
296         [DllImport(Libraries.Player, EntryPoint = "player_get_track_language_code")]
297         internal static extern PlayerErrorCode GetTrackLanguageCode(IntPtr player, int type, int index, out IntPtr code);
298     }
299
300     internal class PlayerHandle : SafeHandle
301     {
302         protected PlayerHandle() : base(IntPtr.Zero, true)
303         {
304         }
305
306         public override bool IsInvalid => handle == IntPtr.Zero;
307
308         protected override bool ReleaseHandle()
309         {
310             var ret = NativePlayer.Destroy(handle);
311             if (ret != PlayerErrorCode.None)
312             {
313                 Log.Debug(GetType().FullName, $"Failed to release native {GetType().Name}");
314                 return false;
315             }
316
317             return true;
318         }
319     }
320 }