[MediaPlayer] Add API to export audio PCM data (#930)
[platform/core/csapi/tizenfx.git] / src / Tizen.Multimedia.MediaPlayer / Interop / Interop.Player.cs
1 /*
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 using System;
18 using System.Runtime.InteropServices;
19 using Tizen;
20 using Tizen.Multimedia;
21
22 internal static partial class Interop
23 {
24     internal static partial class NativePlayer
25     {
26
27         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
28         internal delegate void PlaybackCompletedCallback(IntPtr userData);
29
30         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
31         internal delegate void PlaybackInterruptedCallback(PlaybackInterruptionReason code, IntPtr userData);
32
33         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
34         internal delegate void PlaybackErrorCallback(int code, IntPtr userData);
35
36         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
37         internal delegate void VideoFrameDecodedCallback(IntPtr packetHandle, IntPtr userData);
38
39         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
40         internal delegate void AudioFrameDecodedCallback(IntPtr packetHandle, IntPtr userData);
41
42         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
43         internal delegate void SubtitleUpdatedCallback(uint duration, string text, IntPtr userData);
44
45         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
46         internal delegate void BufferingProgressCallback(int percent, IntPtr userData);
47
48         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
49         internal delegate void VideoStreamChangedCallback(int width, int height, int fps, int bitrate, IntPtr userData);
50
51         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
52         internal delegate void MediaStreamBufferStatusCallback(MediaStreamBufferStatus status, IntPtr userData);
53
54         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
55         internal delegate void MediaStreamSeekCallback(ulong offset, IntPtr userData);
56
57         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
58         internal delegate void VideoCaptureCallback(IntPtr data, int width, int height, uint size, IntPtr userData);
59
60         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
61         internal delegate void PrepareCallback(IntPtr userData);
62
63         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
64         internal delegate void SeekCompletedCallback(IntPtr userData);
65
66         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
67         internal delegate bool AdaptiveVariantCallback(int bandwidth, int width, int height, IntPtr userData);
68
69         [DllImport(Libraries.Player, EntryPoint = "player_create")]
70         internal static extern PlayerErrorCode Create(out PlayerHandle player);
71
72         [DllImport(Libraries.Player, EntryPoint = "player_destroy")]
73         internal static extern PlayerErrorCode Destroy(IntPtr player);
74
75         [DllImport(Libraries.Player, EntryPoint = "player_prepare")]
76         internal static extern PlayerErrorCode Prepare(IntPtr player);
77
78         [DllImport(Libraries.Player, EntryPoint = "player_unprepare")]
79         internal static extern PlayerErrorCode Unprepare(IntPtr player);
80
81         [DllImport(Libraries.Player, EntryPoint = "player_set_uri")]
82         internal static extern PlayerErrorCode SetUri(IntPtr player, string uri);
83
84         [DllImport(Libraries.Player, EntryPoint = "player_start")]
85         internal static extern PlayerErrorCode Start(IntPtr player);
86
87         [DllImport(Libraries.Player, EntryPoint = "player_stop")]
88         internal static extern PlayerErrorCode Stop(IntPtr player);
89
90         [DllImport(Libraries.Player, EntryPoint = "player_pause")]
91         internal static extern PlayerErrorCode Pause(IntPtr player);
92
93         [DllImport(Libraries.Player, EntryPoint = "player_set_memory_buffer")]
94         internal static extern PlayerErrorCode SetMemoryBuffer(IntPtr player, byte[] data, int size);
95
96         [DllImport(Libraries.Player, EntryPoint = "player_get_state")]
97         internal static extern PlayerErrorCode GetState(IntPtr player, out int state);
98
99         [DllImport(Libraries.Player, EntryPoint = "player_set_volume")]
100         internal static extern PlayerErrorCode SetVolume(IntPtr player, float left, float right);
101
102         [DllImport(Libraries.Player, EntryPoint = "player_get_volume")]
103         internal static extern PlayerErrorCode GetVolume(IntPtr player, out float left, out float right);
104
105         [DllImport(Libraries.Player, EntryPoint = "player_set_replaygain_enabled")]
106         internal static extern PlayerErrorCode SetReplayGain(IntPtr player, bool enabled);
107
108         [DllImport(Libraries.Player, EntryPoint = "player_is_replaygain_enabled")]
109         internal static extern PlayerErrorCode IsReplayGain(IntPtr player, out bool enabled);
110
111         [DllImport(Libraries.Player, EntryPoint = "player_set_sound_stream_info")]
112         internal static extern PlayerErrorCode SetAudioPolicyInfo(IntPtr player, AudioStreamPolicyHandle streamInfo);
113
114         [DllImport(Libraries.Player, EntryPoint = "player_set_audio_latency_mode")]
115         internal static extern PlayerErrorCode SetAudioLatencyMode(IntPtr player, AudioLatencyMode latencyMode);
116
117         [DllImport(Libraries.Player, EntryPoint = "player_get_audio_latency_mode")]
118         internal static extern PlayerErrorCode GetAudioLatencyMode(IntPtr player, out AudioLatencyMode latencyMode);
119
120         [DllImport(Libraries.Player, EntryPoint = "player_get_play_position")]
121         internal static extern PlayerErrorCode GetPlayPosition(IntPtr player, out int millisecond);
122
123         [DllImport(Libraries.Player, EntryPoint = "player_set_play_position")]
124         internal static extern PlayerErrorCode SetPlayPosition(IntPtr player, int millisecond,
125             bool accurate, SeekCompletedCallback cb, IntPtr userData = default(IntPtr));
126
127         [DllImport(Libraries.Player, EntryPoint = "player_get_play_position_nsec")]
128         internal static extern PlayerErrorCode GetPlayPositionNanoseconds(IntPtr player, out long nanoseconds);
129
130         [DllImport(Libraries.Player, EntryPoint = "player_set_play_position_nsec")]
131         internal static extern PlayerErrorCode SetPlayPositionNanoseconds(IntPtr player, long nanoseconds,
132             bool accurate, SeekCompletedCallback cb, IntPtr userData = default(IntPtr));
133
134         [DllImport(Libraries.Player, EntryPoint = "player_set_mute")]
135         internal static extern PlayerErrorCode SetMute(IntPtr player, bool muted);
136
137         [DllImport(Libraries.Player, EntryPoint = "player_is_muted")]
138         internal static extern PlayerErrorCode IsMuted(IntPtr player, out bool muted);
139
140         [DllImport(Libraries.Player, EntryPoint = "player_set_looping")]
141         internal static extern PlayerErrorCode SetLooping(IntPtr player, bool looping);
142
143         [DllImport(Libraries.Player, EntryPoint = "player_is_looping")]
144         internal static extern PlayerErrorCode IsLooping(IntPtr player, out bool looping);
145
146         [DllImport(Libraries.Player, EntryPoint = "player_set_completed_cb")]
147         internal static extern PlayerErrorCode SetCompletedCb(IntPtr player,
148             PlaybackCompletedCallback callback, IntPtr userData = default(IntPtr));
149
150         [DllImport(Libraries.Player, EntryPoint = "player_unset_completed_cb")]
151         internal static extern PlayerErrorCode UnsetCompletedCb(IntPtr player);
152
153         [DllImport(Libraries.Player, EntryPoint = "player_set_interrupted_cb")]
154         internal static extern PlayerErrorCode SetInterruptedCb(IntPtr player,
155             PlaybackInterruptedCallback callback, IntPtr userData = default(IntPtr));
156
157         [DllImport(Libraries.Player, EntryPoint = "player_unset_interrupted_cb")]
158         internal static extern PlayerErrorCode UnsetInterruptedCb(IntPtr player);
159
160         [DllImport(Libraries.Player, EntryPoint = "player_set_error_cb")]
161         internal static extern PlayerErrorCode SetErrorCb(IntPtr player, PlaybackErrorCallback callback,
162             IntPtr userData = default(IntPtr));
163
164         [DllImport(Libraries.Player, EntryPoint = "player_unset_error_cb")]
165         internal static extern PlayerErrorCode UnsetErrorCb(IntPtr player);
166
167         [DllImport(Libraries.Player, EntryPoint = "player_capture_video")]
168         internal static extern PlayerErrorCode CaptureVideo(IntPtr player, VideoCaptureCallback callback,
169             IntPtr userData = default(IntPtr));
170
171         [DllImport(Libraries.Player, EntryPoint = "player_set_media_packet_video_frame_decoded_cb")]
172         internal static extern PlayerErrorCode SetVideoFrameDecodedCb(IntPtr player, VideoFrameDecodedCallback callback,
173             IntPtr userData = default(IntPtr));
174
175         [DllImport(Libraries.Player, EntryPoint = "player_unset_media_packet_video_frame_decoded_cb")]
176         internal static extern PlayerErrorCode UnsetVideoFrameDecodedCb(IntPtr player);
177
178         [DllImport(Libraries.Player, EntryPoint = "player_set_media_packet_audio_frame_decoded_cb")]
179         internal static extern PlayerErrorCode SetAudioFrameDecodedCb(IntPtr player, IntPtr format, PlayerAudioExtractOption opt,
180             AudioFrameDecodedCallback callback, IntPtr userData = default(IntPtr));
181
182         [DllImport(Libraries.Player, EntryPoint = "player_unset_media_packet_audio_frame_decoded_cb")]
183         internal static extern PlayerErrorCode UnsetAudioFrameDecodedCb(IntPtr player);
184
185         [DllImport(Libraries.Player, EntryPoint = "player_set_streaming_cookie")]
186         internal static extern PlayerErrorCode SetStreamingCookie(IntPtr player, string cookie, int size);
187
188         [DllImport(Libraries.Player, EntryPoint = "player_set_streaming_user_agent")]
189         internal static extern PlayerErrorCode SetStreamingUserAgent(IntPtr player, string userAgent, int size);
190
191         [DllImport(Libraries.Player, EntryPoint = "player_get_streaming_download_progress")]
192         internal static extern PlayerErrorCode GetStreamingDownloadProgress(IntPtr player, out int start, out int current);
193
194         [DllImport(Libraries.Player, EntryPoint = "player_set_streaming_buffering_time")]
195         internal static extern PlayerErrorCode SetStreamingBufferingTime(IntPtr player, int bufferingTime, int reBufferingTime);
196
197         [DllImport(Libraries.Player, EntryPoint = "player_get_streaming_buffering_time")]
198         internal static extern PlayerErrorCode GetStreamingBufferingTime(IntPtr player, out int bufferingTime, out int reBufferingTime);
199
200         [DllImport(Libraries.Player, EntryPoint = "player_set_buffering_cb")]
201         internal static extern PlayerErrorCode SetBufferingCb(IntPtr player,
202             BufferingProgressCallback callback, IntPtr userData = default(IntPtr));
203
204         [DllImport(Libraries.Player, EntryPoint = "player_unset_buffering_cb")]
205         internal static extern PlayerErrorCode UnsetBufferingCb(IntPtr player);
206
207         [DllImport(Libraries.Player, EntryPoint = "player_set_playback_rate")]
208         internal static extern PlayerErrorCode SetPlaybackRate(IntPtr player, float rate);
209
210         [DllImport(Libraries.Player, EntryPoint = "player_push_media_stream")]
211         internal static extern PlayerErrorCode PushMediaStream(IntPtr player, IntPtr packet);
212
213         [DllImport(Libraries.Player, EntryPoint = "player_set_media_stream_info")]
214         internal static extern PlayerErrorCode SetMediaStreamInfo(IntPtr player, StreamType type, IntPtr format);
215
216         [DllImport(Libraries.Player, EntryPoint = "player_set_media_stream_buffer_status_cb")]
217         internal static extern PlayerErrorCode SetMediaStreamBufferStatusCb(IntPtr player, StreamType type,
218             MediaStreamBufferStatusCallback callback, IntPtr userData = default(IntPtr));
219
220         [DllImport(Libraries.Player, EntryPoint = "player_unset_media_stream_buffer_status_cb")]
221         internal static extern PlayerErrorCode UnsetMediaStreamBufferStatusCb(IntPtr player, int type);
222
223         [DllImport(Libraries.Player, EntryPoint = "player_set_media_stream_seek_cb")]
224         internal static extern PlayerErrorCode SetMediaStreamSeekCb(IntPtr player, StreamType type,
225             MediaStreamSeekCallback callback, IntPtr userData = default(IntPtr));
226
227         [DllImport(Libraries.Player, EntryPoint = "player_unset_media_stream_seek_cb")]
228         internal static extern PlayerErrorCode UnsetMediaStreamSeekCb(IntPtr player, int type);
229
230         [DllImport(Libraries.Player, EntryPoint = "player_set_media_stream_buffer_max_size")]
231         internal static extern PlayerErrorCode SetMediaStreamBufferMaxSize(IntPtr player, StreamType type, ulong maxSize);
232
233         [DllImport(Libraries.Player, EntryPoint = "player_get_media_stream_buffer_max_size")]
234         internal static extern PlayerErrorCode GetMediaStreamBufferMaxSize(IntPtr player, StreamType type, out ulong maxSize);
235
236         [DllImport(Libraries.Player, EntryPoint = "player_set_media_stream_buffer_min_threshold")]
237         internal static extern PlayerErrorCode SetMediaStreamBufferMinThreshold(IntPtr player, StreamType type, uint percent);
238
239         [DllImport(Libraries.Player, EntryPoint = "player_get_media_stream_buffer_min_threshold")]
240         internal static extern PlayerErrorCode GetMediaStreamBufferMinThreshold(IntPtr player, int type, out uint percent);
241
242         [DllImport(Libraries.Player, EntryPoint = "player_get_content_info")]
243         internal static extern PlayerErrorCode GetContentInfo(IntPtr player, StreamMetadataKey key, out IntPtr value);
244
245         [DllImport(Libraries.Player, EntryPoint = "player_get_codec_info")]
246         internal static extern PlayerErrorCode GetCodecInfo(IntPtr player, out IntPtr audioCodec, out IntPtr videoCodec);
247
248         [DllImport(Libraries.Player, EntryPoint = "player_get_audio_stream_info")]
249         internal static extern PlayerErrorCode GetAudioStreamInfo(IntPtr player, out int sampleRate, out int channel, out int bitRate);
250
251         [DllImport(Libraries.Player, EntryPoint = "player_get_video_stream_info")]
252         internal static extern PlayerErrorCode GetVideoStreamInfo(IntPtr player, out int fps, out int bitRate);
253
254         [DllImport(Libraries.Player, EntryPoint = "player_get_album_art")]
255         internal static extern PlayerErrorCode GetAlbumArt(IntPtr player, out IntPtr albumArt, out int size);
256
257         [DllImport(Libraries.Player, EntryPoint = "player_get_video_size")]
258         internal static extern PlayerErrorCode GetVideoSize(IntPtr player, out int width, out int height);
259
260         [DllImport(Libraries.Player, EntryPoint = "player_get_duration")]
261         internal static extern PlayerErrorCode GetDuration(IntPtr player, out int duration);
262
263         [DllImport(Libraries.Player, EntryPoint = "player_get_duration_nsec")]
264         internal static extern PlayerErrorCode GetDurationNanoseconds(IntPtr player, out long duration);
265
266         [DllImport(Libraries.Player, EntryPoint = "player_set_subtitle_path")]
267         internal static extern PlayerErrorCode SetSubtitlePath(IntPtr player, string path);
268
269         [DllImport(Libraries.Player, EntryPoint = "player_set_subtitle_updated_cb")]
270         internal static extern PlayerErrorCode SetSubtitleUpdatedCb(IntPtr player,
271             SubtitleUpdatedCallback callback, IntPtr userData = default(IntPtr));
272
273         [DllImport(Libraries.Player, EntryPoint = "player_unset_subtitle_updated_cb")]
274         internal static extern PlayerErrorCode UnsetSubtitleUpdatedCb(IntPtr player);
275
276         [DllImport(Libraries.Player, EntryPoint = "player_set_subtitle_position_offset")]
277         internal static extern PlayerErrorCode SetSubtitlePositionOffset(IntPtr player, int millisecond);
278
279         [DllImport(Libraries.Player, EntryPoint = "player_set_video_stream_changed_cb")]
280         internal static extern PlayerErrorCode SetVideoStreamChangedCb(IntPtr player,
281             VideoStreamChangedCallback callback, IntPtr userData = default(IntPtr));
282
283         [DllImport(Libraries.Player, EntryPoint = "player_unset_video_stream_changed_cb")]
284         internal static extern PlayerErrorCode UnsetVideoStreamChangedCb(IntPtr player);
285
286         [DllImport(Libraries.Player, EntryPoint = "player_get_track_count")]
287         internal static extern PlayerErrorCode GetTrackCount(IntPtr player, StreamType type, out int count);
288
289         [DllImport(Libraries.Player, EntryPoint = "player_select_track")]
290         internal static extern PlayerErrorCode SelectTrack(IntPtr player, StreamType type, int index);
291
292         [DllImport(Libraries.Player, EntryPoint = "player_get_current_track")]
293         internal static extern PlayerErrorCode GetCurrentTrack(IntPtr player, StreamType type,
294             out int index);
295
296         [DllImport(Libraries.Player, EntryPoint = "player_get_track_language_code")]
297         internal static extern PlayerErrorCode GetTrackLanguageCode(IntPtr player, StreamType type,
298             int index, out IntPtr code);
299
300         [DllImport(Libraries.Player, EntryPoint = "player_set_audio_only")]
301         internal static extern PlayerErrorCode SetAudioOnly(IntPtr player, bool audioOnly);
302
303         [DllImport(Libraries.Player, EntryPoint = "player_is_audio_only")]
304         internal static extern PlayerErrorCode IsAudioOnly(IntPtr player, out bool audioOnly);
305
306         [DllImport(Libraries.Player, EntryPoint = "player_360_is_content_spherical")]
307         internal static extern PlayerErrorCode IsSphericalContent(IntPtr player, out bool isspherical);
308
309         [DllImport(Libraries.Player, EntryPoint = "player_360_set_enabled")]
310         internal static extern PlayerErrorCode SetSphericalMode(IntPtr player, bool enabled);
311
312         [DllImport(Libraries.Player, EntryPoint = "player_360_is_enabled")]
313         internal static extern PlayerErrorCode IsSphericalMode(IntPtr player, out bool enabled);
314
315         [DllImport(Libraries.Player, EntryPoint = "player_360_set_direction_of_view")]
316         internal static extern PlayerErrorCode SetDirectionOfView(IntPtr player, float yaw, float pitch);
317
318         [DllImport(Libraries.Player, EntryPoint = "player_360_get_direction_of_view")]
319         internal static extern PlayerErrorCode GetDirectionOfView(IntPtr player, out float yaw, out float pitch);
320
321         [DllImport(Libraries.Player, EntryPoint = "player_360_set_zoom")]
322         internal static extern PlayerErrorCode SetZoom(IntPtr player, float level);
323
324         [DllImport(Libraries.Player, EntryPoint = "player_360_get_zoom")]
325         internal static extern PlayerErrorCode GetZoom(IntPtr player, out float level);
326
327         [DllImport(Libraries.Player, EntryPoint = "player_360_set_field_of_view")]
328         internal static extern PlayerErrorCode SetFieldOfView(IntPtr player, int horizontalDegrees, int verticalDegrees);
329
330         [DllImport(Libraries.Player, EntryPoint = "player_360_get_field_of_view")]
331         internal static extern PlayerErrorCode GetFieldOfView(IntPtr player, out int horizontalDegrees, out int verticalDegrees);
332
333         [DllImport(Libraries.Player, EntryPoint = "player_360_set_zoom_with_field_of_view")]
334         internal static extern PlayerErrorCode SetZoomWithFieldOfView(IntPtr player, float level, int horizontalDegrees, int verticalDegrees);
335
336         [DllImport(Libraries.Player, EntryPoint = "player_foreach_adaptive_variant")]
337         internal static extern PlayerErrorCode ForeachAdaptiveVariants(IntPtr player, AdaptiveVariantCallback callback, IntPtr userData);
338
339         [DllImport(Libraries.Player, EntryPoint = "player_set_max_adaptive_variant_limit")]
340         internal static extern PlayerErrorCode SetMaxLimit(IntPtr player, int bandwidth, int width, int height);
341
342         [DllImport(Libraries.Player, EntryPoint = "player_get_max_adaptive_variant_limit")]
343         internal static extern PlayerErrorCode GetMaxLimit(IntPtr player, out int bandwidth, out int width, out int height);
344
345         [DllImport(Libraries.Player, EntryPoint = "player_set_video_roi_area")]
346         internal static extern PlayerErrorCode SetVideoRoi(IntPtr player, double scaleX, double scaleY, double scaleWidth, double scaleHeight);
347
348         [DllImport(Libraries.Player, EntryPoint = "player_get_video_roi_area")]
349         internal static extern PlayerErrorCode GetVideoRoi(IntPtr player, out double scaleX, out double scaleY, out double scaleWidth, out double scaleHeight);
350
351         [DllImport(Libraries.Player, EntryPoint = "player_audio_pitch_set_enabled")]
352         internal static extern PlayerErrorCode SetAudioPitchEnabled(IntPtr player, bool enabled);
353
354         [DllImport(Libraries.Player, EntryPoint = "player_audio_pitch_is_enabled")]
355         internal static extern PlayerErrorCode IsAudioPitchEnabled(IntPtr player, out bool enabled);
356
357         [DllImport(Libraries.Player, EntryPoint = "player_audio_pitch_set_value")]
358         internal static extern PlayerErrorCode SetAudioPitch(IntPtr player, float level);
359
360         [DllImport(Libraries.Player, EntryPoint = "player_audio_pitch_get_value")]
361         internal static extern PlayerErrorCode GetAudioPitch(IntPtr player, out float level);
362     }
363
364     internal class PlayerHandle : SafeHandle
365     {
366         protected PlayerHandle() : base(IntPtr.Zero, true)
367         {
368         }
369
370         internal PlayerHandle(IntPtr rawHandle) : this()
371         {
372             handle = rawHandle;
373         }
374
375         public override bool IsInvalid => handle == IntPtr.Zero;
376
377         protected override bool ReleaseHandle()
378         {
379             var ret = NativePlayer.Destroy(handle);
380             if (ret != PlayerErrorCode.None)
381             {
382                 Log.Debug(GetType().FullName, $"Failed to release native {GetType().Name}");
383                 return false;
384             }
385
386             return true;
387         }
388     }
389 }