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;
20 using Tizen.Multimedia;
22 internal static partial class Interop
24 internal static partial class NativePlayer
27 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
28 internal delegate void PlaybackCompletedCallback(IntPtr userData);
30 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
31 internal delegate void PlaybackInterruptedCallback(PlaybackInterruptionReason code, IntPtr userData);
33 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
34 internal delegate void PlaybackErrorCallback(int code, IntPtr userData);
36 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
37 internal delegate void VideoFrameDecodedCallback(IntPtr packetHandle, IntPtr userData);
39 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
40 internal delegate void SubtitleUpdatedCallback(uint duration, string text, IntPtr userData);
42 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
43 internal delegate void BufferingProgressCallback(int percent, IntPtr userData);
45 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
46 internal delegate void VideoStreamChangedCallback(int width, int height, int fps, int bitrate, IntPtr userData);
48 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
49 internal delegate void MediaStreamBufferStatusCallback(MediaStreamBufferStatus status, IntPtr userData);
51 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
52 internal delegate void MediaStreamSeekCallback(ulong offset, IntPtr userData);
54 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
55 internal delegate void VideoCaptureCallback(IntPtr data, int width, int height, uint size, IntPtr userData);
57 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
58 internal delegate void PrepareCallback(IntPtr userData);
60 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
61 internal delegate void SeekCompletedCallback(IntPtr userData);
63 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
64 internal delegate bool AdaptiveVariantCallback(int bandwidth, int width, int height, IntPtr userData);
66 [DllImport(Libraries.Player, EntryPoint = "player_create")]
67 internal static extern PlayerErrorCode Create(out PlayerHandle player);
69 [DllImport(Libraries.Player, EntryPoint = "player_destroy")]
70 internal static extern PlayerErrorCode Destroy(IntPtr player);
72 [DllImport(Libraries.Player, EntryPoint = "player_prepare")]
73 internal static extern PlayerErrorCode Prepare(IntPtr player);
75 [DllImport(Libraries.Player, EntryPoint = "player_unprepare")]
76 internal static extern PlayerErrorCode Unprepare(IntPtr player);
78 [DllImport(Libraries.Player, EntryPoint = "player_set_uri")]
79 internal static extern PlayerErrorCode SetUri(IntPtr player, string uri);
81 [DllImport(Libraries.Player, EntryPoint = "player_start")]
82 internal static extern PlayerErrorCode Start(IntPtr player);
84 [DllImport(Libraries.Player, EntryPoint = "player_stop")]
85 internal static extern PlayerErrorCode Stop(IntPtr player);
87 [DllImport(Libraries.Player, EntryPoint = "player_pause")]
88 internal static extern PlayerErrorCode Pause(IntPtr player);
90 [DllImport(Libraries.Player, EntryPoint = "player_set_memory_buffer")]
91 internal static extern PlayerErrorCode SetMemoryBuffer(IntPtr player, byte[] data, int size);
93 [DllImport(Libraries.Player, EntryPoint = "player_get_state")]
94 internal static extern PlayerErrorCode GetState(IntPtr player, out int state);
96 [DllImport(Libraries.Player, EntryPoint = "player_set_volume")]
97 internal static extern PlayerErrorCode SetVolume(IntPtr player, float left, float right);
99 [DllImport(Libraries.Player, EntryPoint = "player_get_volume")]
100 internal static extern PlayerErrorCode GetVolume(IntPtr player, out float left, out float right);
102 [DllImport(Libraries.Player, EntryPoint = "player_set_sound_stream_info")]
103 internal static extern PlayerErrorCode SetAudioPolicyInfo(IntPtr player, AudioStreamPolicyHandle streamInfo);
105 [DllImport(Libraries.Player, EntryPoint = "player_set_audio_latency_mode")]
106 internal static extern PlayerErrorCode SetAudioLatencyMode(IntPtr player, AudioLatencyMode latencyMode);
108 [DllImport(Libraries.Player, EntryPoint = "player_get_audio_latency_mode")]
109 internal static extern PlayerErrorCode GetAudioLatencyMode(IntPtr player, out AudioLatencyMode latencyMode);
111 [DllImport(Libraries.Player, EntryPoint = "player_get_play_position")]
112 internal static extern PlayerErrorCode GetPlayPosition(IntPtr player, out int millisecond);
114 [DllImport(Libraries.Player, EntryPoint = "player_set_play_position")]
115 internal static extern PlayerErrorCode SetPlayPosition(IntPtr player, int millisecond,
116 bool accurate, SeekCompletedCallback cb, IntPtr userData = default(IntPtr));
118 [DllImport(Libraries.Player, EntryPoint = "player_set_mute")]
119 internal static extern PlayerErrorCode SetMute(IntPtr player, bool muted);
121 [DllImport(Libraries.Player, EntryPoint = "player_is_muted")]
122 internal static extern PlayerErrorCode IsMuted(IntPtr player, out bool muted);
124 [DllImport(Libraries.Player, EntryPoint = "player_set_looping")]
125 internal static extern PlayerErrorCode SetLooping(IntPtr player, bool looping);
127 [DllImport(Libraries.Player, EntryPoint = "player_is_looping")]
128 internal static extern PlayerErrorCode IsLooping(IntPtr player, out bool looping);
130 [DllImport(Libraries.Player, EntryPoint = "player_set_completed_cb")]
131 internal static extern PlayerErrorCode SetCompletedCb(IntPtr player,
132 PlaybackCompletedCallback callback, IntPtr userData = default(IntPtr));
134 [DllImport(Libraries.Player, EntryPoint = "player_unset_completed_cb")]
135 internal static extern PlayerErrorCode UnsetCompletedCb(IntPtr player);
137 [DllImport(Libraries.Player, EntryPoint = "player_set_interrupted_cb")]
138 internal static extern PlayerErrorCode SetInterruptedCb(IntPtr player,
139 PlaybackInterruptedCallback callback, IntPtr userData = default(IntPtr));
141 [DllImport(Libraries.Player, EntryPoint = "player_unset_interrupted_cb")]
142 internal static extern PlayerErrorCode UnsetInterruptedCb(IntPtr player);
144 [DllImport(Libraries.Player, EntryPoint = "player_set_error_cb")]
145 internal static extern PlayerErrorCode SetErrorCb(IntPtr player, PlaybackErrorCallback callback,
146 IntPtr userData = default(IntPtr));
148 [DllImport(Libraries.Player, EntryPoint = "player_unset_error_cb")]
149 internal static extern PlayerErrorCode UnsetErrorCb(IntPtr player);
151 [DllImport(Libraries.Player, EntryPoint = "player_capture_video")]
152 internal static extern PlayerErrorCode CaptureVideo(IntPtr player, VideoCaptureCallback callback,
153 IntPtr userData = default(IntPtr));
155 [DllImport(Libraries.Player, EntryPoint = "player_set_media_packet_video_frame_decoded_cb")]
156 internal static extern PlayerErrorCode SetVideoFrameDecodedCb(IntPtr player, VideoFrameDecodedCallback callback,
157 IntPtr userData = default(IntPtr));
159 [DllImport(Libraries.Player, EntryPoint = "player_unset_media_packet_video_frame_decoded_cb")]
160 internal static extern PlayerErrorCode UnsetVideoFrameDecodedCb(IntPtr player);
162 [DllImport(Libraries.Player, EntryPoint = "player_set_streaming_cookie")]
163 internal static extern PlayerErrorCode SetStreamingCookie(IntPtr player, string cookie, int size);
165 [DllImport(Libraries.Player, EntryPoint = "player_set_streaming_user_agent")]
166 internal static extern PlayerErrorCode SetStreamingUserAgent(IntPtr player, string userAgent, int size);
168 [DllImport(Libraries.Player, EntryPoint = "player_get_streaming_download_progress")]
169 internal static extern PlayerErrorCode GetStreamingDownloadProgress(IntPtr player, out int start, out int current);
171 [DllImport(Libraries.Player, EntryPoint = "player_set_streaming_buffering_time")]
172 internal static extern PlayerErrorCode SetStreamingBufferingTime(IntPtr player, int bufferingTime, int reBufferingTime);
174 [DllImport(Libraries.Player, EntryPoint = "player_get_streaming_buffering_time")]
175 internal static extern PlayerErrorCode GetStreamingBufferingTime(IntPtr player, out int bufferingTime, out int reBufferingTime);
177 [DllImport(Libraries.Player, EntryPoint = "player_set_buffering_cb")]
178 internal static extern PlayerErrorCode SetBufferingCb(IntPtr player,
179 BufferingProgressCallback callback, IntPtr userData = default(IntPtr));
181 [DllImport(Libraries.Player, EntryPoint = "player_unset_buffering_cb")]
182 internal static extern PlayerErrorCode UnsetBufferingCb(IntPtr player);
184 [DllImport(Libraries.Player, EntryPoint = "player_set_playback_rate")]
185 internal static extern PlayerErrorCode SetPlaybackRate(IntPtr player, float rate);
187 [DllImport(Libraries.Player, EntryPoint = "player_push_media_stream")]
188 internal static extern PlayerErrorCode PushMediaStream(IntPtr player, IntPtr packet);
190 [DllImport(Libraries.Player, EntryPoint = "player_set_media_stream_info")]
191 internal static extern PlayerErrorCode SetMediaStreamInfo(IntPtr player, StreamType type, IntPtr format);
193 [DllImport(Libraries.Player, EntryPoint = "player_set_media_stream_buffer_status_cb")]
194 internal static extern PlayerErrorCode SetMediaStreamBufferStatusCb(IntPtr player, StreamType type,
195 MediaStreamBufferStatusCallback callback, IntPtr userData = default(IntPtr));
197 [DllImport(Libraries.Player, EntryPoint = "player_unset_media_stream_buffer_status_cb")]
198 internal static extern PlayerErrorCode UnsetMediaStreamBufferStatusCb(IntPtr player, int type);
200 [DllImport(Libraries.Player, EntryPoint = "player_set_media_stream_seek_cb")]
201 internal static extern PlayerErrorCode SetMediaStreamSeekCb(IntPtr player, StreamType type,
202 MediaStreamSeekCallback callback, IntPtr userData = default(IntPtr));
204 [DllImport(Libraries.Player, EntryPoint = "player_unset_media_stream_seek_cb")]
205 internal static extern PlayerErrorCode UnsetMediaStreamSeekCb(IntPtr player, int type);
207 [DllImport(Libraries.Player, EntryPoint = "player_set_media_stream_buffer_max_size")]
208 internal static extern PlayerErrorCode SetMediaStreamBufferMaxSize(IntPtr player, StreamType type, ulong maxSize);
210 [DllImport(Libraries.Player, EntryPoint = "player_get_media_stream_buffer_max_size")]
211 internal static extern PlayerErrorCode GetMediaStreamBufferMaxSize(IntPtr player, StreamType type, out ulong maxSize);
213 [DllImport(Libraries.Player, EntryPoint = "player_set_media_stream_buffer_min_threshold")]
214 internal static extern PlayerErrorCode SetMediaStreamBufferMinThreshold(IntPtr player, StreamType type, uint percent);
216 [DllImport(Libraries.Player, EntryPoint = "player_get_media_stream_buffer_min_threshold")]
217 internal static extern PlayerErrorCode GetMediaStreamBufferMinThreshold(IntPtr player, int type, out uint percent);
219 [DllImport(Libraries.Player, EntryPoint = "player_get_content_info")]
220 internal static extern PlayerErrorCode GetContentInfo(IntPtr player, StreamMetadataKey key, out IntPtr value);
222 [DllImport(Libraries.Player, EntryPoint = "player_get_codec_info")]
223 internal static extern PlayerErrorCode GetCodecInfo(IntPtr player, out IntPtr audioCodec, out IntPtr videoCodec);
225 [DllImport(Libraries.Player, EntryPoint = "player_get_audio_stream_info")]
226 internal static extern PlayerErrorCode GetAudioStreamInfo(IntPtr player, out int sampleRate, out int channel, out int bitRate);
228 [DllImport(Libraries.Player, EntryPoint = "player_get_video_stream_info")]
229 internal static extern PlayerErrorCode GetVideoStreamInfo(IntPtr player, out int fps, out int bitRate);
231 [DllImport(Libraries.Player, EntryPoint = "player_get_album_art")]
232 internal static extern PlayerErrorCode GetAlbumArt(IntPtr player, out IntPtr albumArt, out int size);
234 [DllImport(Libraries.Player, EntryPoint = "player_get_video_size")]
235 internal static extern PlayerErrorCode GetVideoSize(IntPtr player, out int width, out int height);
237 [DllImport(Libraries.Player, EntryPoint = "player_get_duration")]
238 internal static extern PlayerErrorCode GetDuration(IntPtr player, out int duration);
240 [DllImport(Libraries.Player, EntryPoint = "player_set_subtitle_path")]
241 internal static extern PlayerErrorCode SetSubtitlePath(IntPtr player, string path);
243 [DllImport(Libraries.Player, EntryPoint = "player_set_subtitle_updated_cb")]
244 internal static extern PlayerErrorCode SetSubtitleUpdatedCb(IntPtr player,
245 SubtitleUpdatedCallback callback, IntPtr userData = default(IntPtr));
247 [DllImport(Libraries.Player, EntryPoint = "player_unset_subtitle_updated_cb")]
248 internal static extern PlayerErrorCode UnsetSubtitleUpdatedCb(IntPtr player);
250 [DllImport(Libraries.Player, EntryPoint = "player_set_subtitle_position_offset")]
251 internal static extern PlayerErrorCode SetSubtitlePositionOffset(IntPtr player, int millisecond);
253 [DllImport(Libraries.Player, EntryPoint = "player_set_video_stream_changed_cb")]
254 internal static extern PlayerErrorCode SetVideoStreamChangedCb(IntPtr player,
255 VideoStreamChangedCallback callback, IntPtr userData = default(IntPtr));
257 [DllImport(Libraries.Player, EntryPoint = "player_unset_video_stream_changed_cb")]
258 internal static extern PlayerErrorCode UnsetVideoStreamChangedCb(IntPtr player);
260 [DllImport(Libraries.Player, EntryPoint = "player_get_track_count")]
261 internal static extern PlayerErrorCode GetTrackCount(IntPtr player, StreamType type, out int count);
263 [DllImport(Libraries.Player, EntryPoint = "player_select_track")]
264 internal static extern PlayerErrorCode SelectTrack(IntPtr player, StreamType type, int index);
266 [DllImport(Libraries.Player, EntryPoint = "player_get_current_track")]
267 internal static extern PlayerErrorCode GetCurrentTrack(IntPtr player, StreamType type,
270 [DllImport(Libraries.Player, EntryPoint = "player_get_track_language_code")]
271 internal static extern PlayerErrorCode GetTrackLanguageCode(IntPtr player, StreamType type,
272 int index, out IntPtr code);
274 [DllImport(Libraries.Player, EntryPoint = "player_set_audio_only")]
275 internal static extern PlayerErrorCode SetAudioOnly(IntPtr player, bool audioOnly);
277 [DllImport(Libraries.Player, EntryPoint = "player_is_audio_only")]
278 internal static extern PlayerErrorCode IsAudioOnly(IntPtr player, out bool audioOnly);
280 [DllImport(Libraries.Player, EntryPoint = "player_360_is_content_spherical")]
281 internal static extern PlayerErrorCode IsSphericalContent(IntPtr player, out bool isspherical);
283 [DllImport(Libraries.Player, EntryPoint = "player_360_set_enabled")]
284 internal static extern PlayerErrorCode SetSphericalMode(IntPtr player, bool enabled);
286 [DllImport(Libraries.Player, EntryPoint = "player_360_is_enabled")]
287 internal static extern PlayerErrorCode IsSphericalMode(IntPtr player, out bool enabled);
289 [DllImport(Libraries.Player, EntryPoint = "player_360_set_direction_of_view")]
290 internal static extern PlayerErrorCode SetDirectionOfView(IntPtr player, float yaw, float pitch);
292 [DllImport(Libraries.Player, EntryPoint = "player_360_get_direction_of_view")]
293 internal static extern PlayerErrorCode GetDirectionOfView(IntPtr player, out float yaw, out float pitch);
295 [DllImport(Libraries.Player, EntryPoint = "player_360_set_zoom")]
296 internal static extern PlayerErrorCode SetZoom(IntPtr player, float level);
298 [DllImport(Libraries.Player, EntryPoint = "player_360_get_zoom")]
299 internal static extern PlayerErrorCode GetZoom(IntPtr player, out float level);
301 [DllImport(Libraries.Player, EntryPoint = "player_360_set_field_of_view")]
302 internal static extern PlayerErrorCode SetFieldOfView(IntPtr player, int horizontalDegrees, int verticalDegrees);
304 [DllImport(Libraries.Player, EntryPoint = "player_360_get_field_of_view")]
305 internal static extern PlayerErrorCode GetFieldOfView(IntPtr player, out int horizontalDegrees, out int verticalDegrees);
307 [DllImport(Libraries.Player, EntryPoint = "player_foreach_adaptive_variant")]
308 internal static extern PlayerErrorCode ForeachAdaptiveVariants(IntPtr player, AdaptiveVariantCallback callback, IntPtr userData);
310 [DllImport(Libraries.Player, EntryPoint = "player_set_max_adaptive_variant_limit")]
311 internal static extern PlayerErrorCode SetMaxLimit(IntPtr player, int bandwidth, int width, int height);
313 [DllImport(Libraries.Player, EntryPoint = "player_get_max_adaptive_variant_limit")]
314 internal static extern PlayerErrorCode GetMaxLimit(IntPtr player, out int bandwidth, out int width, out int height);
317 internal class PlayerHandle : SafeHandle
319 protected PlayerHandle() : base(IntPtr.Zero, true)
323 internal PlayerHandle(IntPtr rawHandle) : this()
328 public override bool IsInvalid => handle == IntPtr.Zero;
330 protected override bool ReleaseHandle()
332 var ret = NativePlayer.Destroy(handle);
333 if (ret != PlayerErrorCode.None)
335 Log.Debug(GetType().FullName, $"Failed to release native {GetType().Name}");