2 using System.Runtime.InteropServices;
4 using Tizen.Multimedia;
6 internal static partial class Interop
8 internal static partial class NativePlayer
11 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
12 internal delegate void PlaybackCompletedCallback(IntPtr userData);
14 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
15 internal delegate void PlaybackInterruptedCallback(PlaybackInterruptionReason code, IntPtr userData);
17 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
18 internal delegate void PlaybackErrorCallback(int code, IntPtr userData);
20 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
21 internal delegate void VideoFrameDecodedCallback(IntPtr packetHandle, IntPtr userData);
23 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
24 internal delegate void SubtitleUpdatedCallback(uint duration, string text, IntPtr userData);
26 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
27 internal delegate void BufferingProgressCallback(int percent, IntPtr userData);
29 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
30 internal delegate void VideoStreamChangedCallback(int width, int height, int fps, int bitrate, IntPtr userData);
32 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
33 internal delegate void MediaStreamBufferStatusCallback(MediaStreamBufferStatus status, IntPtr userData);
35 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
36 internal delegate void MediaStreamSeekCallback(ulong offset, IntPtr userData);
38 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
39 internal delegate void VideoCaptureCallback(IntPtr data, int width, int height, uint size, IntPtr userData);
41 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
42 internal delegate void PrepareCallback(IntPtr userData);
44 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
45 internal delegate void SeekCompletedCallback(IntPtr userData);
48 [DllImport(Libraries.Player, EntryPoint = "player_create")]
49 internal static extern PlayerErrorCode Create(out PlayerHandle player);
51 [DllImport(Libraries.Player, EntryPoint = "player_destroy")]
52 internal static extern PlayerErrorCode Destroy(IntPtr player);
54 [DllImport(Libraries.Player, EntryPoint = "player_prepare")]
55 internal static extern PlayerErrorCode Prepare(IntPtr player);
57 [DllImport(Libraries.Player, EntryPoint = "player_unprepare")]
58 internal static extern PlayerErrorCode Unprepare(IntPtr player);
60 [DllImport(Libraries.Player, EntryPoint = "player_set_uri")]
61 internal static extern PlayerErrorCode SetUri(IntPtr player, string uri);
63 [DllImport(Libraries.Player, EntryPoint = "player_set_display")]
64 internal static extern PlayerErrorCode SetDisplay(IntPtr player, DisplayType type, IntPtr display);
66 [DllImport(Libraries.Player, EntryPoint = "player_start")]
67 internal static extern PlayerErrorCode Start(IntPtr player);
69 [DllImport(Libraries.Player, EntryPoint = "player_stop")]
70 internal static extern PlayerErrorCode Stop(IntPtr player);
72 [DllImport(Libraries.Player, EntryPoint = "player_pause")]
73 internal static extern PlayerErrorCode Pause(IntPtr player);
75 [DllImport(Libraries.Player, EntryPoint = "player_set_memory_buffer")]
76 internal static extern PlayerErrorCode SetMemoryBuffer(IntPtr player, byte[] data, int size);
78 [DllImport(Libraries.Player, EntryPoint = "player_get_state")]
79 internal static extern PlayerErrorCode GetState(IntPtr player, out int state);
81 [DllImport(Libraries.Player, EntryPoint = "player_set_volume")]
82 internal static extern PlayerErrorCode SetVolume(IntPtr player, float left, float right);
84 [DllImport(Libraries.Player, EntryPoint = "player_get_volume")]
85 internal static extern PlayerErrorCode GetVolume(IntPtr player, out float left, out float right);
87 [DllImport(Libraries.Player, EntryPoint = "player_set_sound_stream_info")]
88 internal static extern PlayerErrorCode SetAudioPolicyInfo(IntPtr player, IntPtr streamInfo);
90 [DllImport(Libraries.Player, EntryPoint = "player_set_audio_latency_mode")]
91 internal static extern PlayerErrorCode SetAudioLatencyMode(IntPtr player, AudioLatencyMode latencyMode);
93 [DllImport(Libraries.Player, EntryPoint = "player_get_audio_latency_mode")]
94 internal static extern PlayerErrorCode GetAudioLatencyMode(IntPtr player, out AudioLatencyMode latencyMode);
96 [DllImport(Libraries.Player, EntryPoint = "player_get_play_position")]
97 internal static extern PlayerErrorCode GetPlayPosition(IntPtr player, out int millisecond);
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));
103 [DllImport(Libraries.Player, EntryPoint = "player_set_mute")]
104 internal static extern PlayerErrorCode SetMute(IntPtr player, bool muted);
106 [DllImport(Libraries.Player, EntryPoint = "player_is_muted")]
107 internal static extern PlayerErrorCode IsMuted(IntPtr player, out bool muted);
109 [DllImport(Libraries.Player, EntryPoint = "player_set_looping")]
110 internal static extern PlayerErrorCode SetLooping(IntPtr player, bool looping);
112 [DllImport(Libraries.Player, EntryPoint = "player_is_looping")]
113 internal static extern PlayerErrorCode IsLooping(IntPtr player, out bool looping);
115 [DllImport(Libraries.Player, EntryPoint = "player_set_completed_cb")]
116 internal static extern PlayerErrorCode SetCompletedCb(IntPtr player,
117 PlaybackCompletedCallback callback, IntPtr userData = default(IntPtr));
119 [DllImport(Libraries.Player, EntryPoint = "player_unset_completed_cb")]
120 internal static extern PlayerErrorCode UnsetCompletedCb(IntPtr player);
122 [DllImport(Libraries.Player, EntryPoint = "player_set_interrupted_cb")]
123 internal static extern PlayerErrorCode SetInterruptedCb(IntPtr player,
124 PlaybackInterruptedCallback callback, IntPtr userData = default(IntPtr));
126 [DllImport(Libraries.Player, EntryPoint = "player_unset_interrupted_cb")]
127 internal static extern PlayerErrorCode UnsetInterruptedCb(IntPtr player);
129 [DllImport(Libraries.Player, EntryPoint = "player_set_error_cb")]
130 internal static extern PlayerErrorCode SetErrorCb(IntPtr player, PlaybackErrorCallback callback,
131 IntPtr userData = default(IntPtr));
133 [DllImport(Libraries.Player, EntryPoint = "player_unset_error_cb")]
134 internal static extern PlayerErrorCode UnsetErrorCb(IntPtr player);
136 [DllImport(Libraries.Player, EntryPoint = "player_capture_video")]
137 internal static extern PlayerErrorCode CaptureVideo(IntPtr player, VideoCaptureCallback callback,
138 IntPtr userData = default(IntPtr));
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));
144 [DllImport(Libraries.Player, EntryPoint = "player_unset_media_packet_video_frame_decoded_cb")]
145 internal static extern PlayerErrorCode UnsetVideoFrameDecodedCb(IntPtr player);
147 [DllImport(Libraries.Player, EntryPoint = "player_set_streaming_cookie")]
148 internal static extern PlayerErrorCode SetStreamingCookie(IntPtr player, string cookie, int size);
150 [DllImport(Libraries.Player, EntryPoint = "player_set_streaming_user_agent")]
151 internal static extern PlayerErrorCode SetStreamingUserAgent(IntPtr player, string userAgent, int size);
153 [DllImport(Libraries.Player, EntryPoint = "player_get_streaming_download_progress")]
154 internal static extern PlayerErrorCode GetStreamingDownloadProgress(IntPtr player, out int start, out int current);
156 [DllImport(Libraries.Player, EntryPoint = "player_set_buffering_cb")]
157 internal static extern PlayerErrorCode SetBufferingCb(IntPtr player,
158 BufferingProgressCallback callback, IntPtr userData = default(IntPtr));
160 [DllImport(Libraries.Player, EntryPoint = "player_unset_buffering_cb")]
161 internal static extern PlayerErrorCode UnsetBufferingCb(IntPtr player);
163 [DllImport(Libraries.Player, EntryPoint = "player_set_playback_rate")]
164 internal static extern PlayerErrorCode SetPlaybackRate(IntPtr player, float rate);
166 [DllImport(Libraries.Player, EntryPoint = "player_push_media_stream")]
167 internal static extern PlayerErrorCode PushMediaStream(IntPtr player, IntPtr packet);
169 [DllImport(Libraries.Player, EntryPoint = "player_set_media_stream_info")]
170 internal static extern PlayerErrorCode SetMediaStreamInfo(IntPtr player, int type, IntPtr format);
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));
176 [DllImport(Libraries.Player, EntryPoint = "player_unset_media_stream_buffer_status_cb")]
177 internal static extern PlayerErrorCode UnsetMediaStreamBufferStatusCb(IntPtr player, int type);
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));
183 [DllImport(Libraries.Player, EntryPoint = "player_unset_media_stream_seek_cb")]
184 internal static extern PlayerErrorCode UnsetMediaStreamSeekCb(IntPtr player, int type);
186 [DllImport(Libraries.Player, EntryPoint = "player_set_media_stream_buffer_max_size")]
187 internal static extern PlayerErrorCode SetMediaStreamBufferMaxSize(IntPtr player, StreamType type, ulong maxSize);
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);
192 [DllImport(Libraries.Player, EntryPoint = "player_set_media_stream_buffer_min_threshold")]
193 internal static extern PlayerErrorCode SetMediaStreamBufferMinThreshold(IntPtr player, StreamType type, uint percent);
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);
198 [DllImport(Libraries.Player, EntryPoint = "player_audio_effect_get_equalizer_bands_count")]
199 internal static extern PlayerErrorCode AudioEffectGetEqualizerBandsCount(IntPtr player, out int count);
201 [DllImport(Libraries.Player, EntryPoint = "player_audio_effect_set_equalizer_band_level")]
202 internal static extern PlayerErrorCode AudioEffectSetEqualizerBandLevel(IntPtr player, int index, int level);
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);
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);
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);
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);
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);
219 [DllImport(Libraries.Player, EntryPoint = "player_audio_effect_equalizer_clear")]
220 internal static extern PlayerErrorCode AudioEffectEqualizerClear(IntPtr player);
222 [DllImport(Libraries.Player, EntryPoint = "player_audio_effect_equalizer_is_available")]
223 internal static extern PlayerErrorCode AudioEffectEqualizerIsAvailable(IntPtr player, out bool available);
225 [DllImport(Libraries.Player, EntryPoint = "player_set_display_mode")]
226 internal static extern PlayerErrorCode SetDisplayMode(IntPtr player, PlayerDisplayMode mode);
228 [DllImport(Libraries.Player, EntryPoint = "player_get_display_mode")]
229 internal static extern PlayerErrorCode GetDisplayMode(IntPtr player, out int mode);
231 [DllImport(Libraries.Player, EntryPoint = "player_set_display_visible")]
232 internal static extern PlayerErrorCode SetDisplayVisible(IntPtr player, bool visible);
234 [DllImport(Libraries.Player, EntryPoint = "player_is_display_visible")]
235 internal static extern PlayerErrorCode IsDisplayVisible(IntPtr player, out bool visible);
237 [DllImport(Libraries.Player, EntryPoint = "player_set_display_rotation")]
238 internal static extern PlayerErrorCode SetDisplayRotation(IntPtr player, PlayerDisplayRotation rotation);
240 [DllImport(Libraries.Player, EntryPoint = "player_get_display_rotation")]
241 internal static extern PlayerErrorCode GetDisplayRotation(IntPtr player, out int rotation);
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);
246 [DllImport(Libraries.Player, EntryPoint = "player_get_content_info")]
247 internal static extern PlayerErrorCode GetContentInfo(IntPtr player, StreamMetadataKey key, out IntPtr value);
249 [DllImport(Libraries.Player, EntryPoint = "player_get_codec_info")]
250 internal static extern PlayerErrorCode GetCodecInfo(IntPtr player, out IntPtr audioCodec, out IntPtr videoCodec);
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);
255 [DllImport(Libraries.Player, EntryPoint = "player_get_video_stream_info")]
256 internal static extern PlayerErrorCode GetVideoStreamInfo(IntPtr player, out int fps, out int bitRate);
258 [DllImport(Libraries.Player, EntryPoint = "player_get_album_art")]
259 internal static extern PlayerErrorCode GetAlbumArt(IntPtr player, out IntPtr albumArt, out int size);
261 [DllImport(Libraries.Player, EntryPoint = "player_get_video_size")]
262 internal static extern PlayerErrorCode GetVideoSize(IntPtr player, out int width, out int height);
264 [DllImport(Libraries.Player, EntryPoint = "player_get_duration")]
265 internal static extern PlayerErrorCode GetDuration(IntPtr player, out int duration);
267 [DllImport(Libraries.Player, EntryPoint = "player_set_subtitle_path")]
268 internal static extern PlayerErrorCode SetSubtitlePath(IntPtr player, string path);
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));
274 [DllImport(Libraries.Player, EntryPoint = "player_unset_subtitle_updated_cb")]
275 internal static extern PlayerErrorCode UnsetSubtitleUpdatedCb(IntPtr player);
277 [DllImport(Libraries.Player, EntryPoint = "player_set_subtitle_position_offset")]
278 internal static extern PlayerErrorCode SetSubtitlePositionOffset(IntPtr player, int millisecond);
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));
284 [DllImport(Libraries.Player, EntryPoint = "player_unset_video_stream_changed_cb")]
285 internal static extern PlayerErrorCode UnsetVideoStreamChangedCb(IntPtr player);
287 [DllImport(Libraries.Player, EntryPoint = "player_get_track_count")]
288 internal static extern PlayerErrorCode GetTrackCount(IntPtr player, int type, out int count);
290 [DllImport(Libraries.Player, EntryPoint = "player_select_track")]
291 internal static extern PlayerErrorCode SelectTrack(IntPtr player, int type, int index);
293 [DllImport(Libraries.Player, EntryPoint = "player_get_current_track")]
294 internal static extern PlayerErrorCode GetCurrentTrack(IntPtr player, int type, out int index);
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);
300 internal class PlayerHandle : SafeHandle
302 protected PlayerHandle() : base(IntPtr.Zero, true)
306 public override bool IsInvalid => handle == IntPtr.Zero;
308 protected override bool ReleaseHandle()
310 var ret = NativePlayer.Destroy(handle);
311 if (ret != PlayerErrorCode.None)
313 Log.Debug(GetType().FullName, $"Failed to release native {GetType().Name}");