Add description
[platform/core/multimedia/libmm-wfd.git] / src / include / mm_wfd_sink.h
1 /*
2  * libmm-wfd
3  *
4  * Copyright (c) 2011 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: JongHyuk Choi <jhchoi.choi@samsung.com>, ByungWook Jang <bw.jang@samsung.com>,
7  * Maksym Ukhanov <m.ukhanov@samsung.com>, Hyunjun Ko <zzoon.ko@samsung.com>
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  */
22
23 #ifndef _MM_WFD_SINK_H_
24 #define _MM_WFD_SINK_H_
25
26 #include <string.h>
27 #include <glib.h>
28 #include <mm_message.h>
29 #include <mm_error.h>
30 #include <mm_types.h>
31
32 /**
33  *  * Enumerations of wifi-display sink state.
34  *   */
35 typedef enum {
36         MM_WFD_SINK_STATE_NONE,                         /**< wifi-display is not created */
37         MM_WFD_SINK_STATE_NULL,                         /**< wifi-display is created */
38         MM_WFD_SINK_STATE_PREPARED,                     /**< wifi-display is prepared */
39         MM_WFD_SINK_STATE_CONNECTED,             /**< wifi-display is connected */
40         MM_WFD_SINK_STATE_PLAYING,                      /**< wifi-display is now playing  */
41         MM_WFD_SINK_STATE_PAUSED,                       /**< wifi-display is now paused  */
42         MM_WFD_SINK_STATE_DISCONNECTED, /**< wifi-display is disconnected */
43         MM_WFD_SINK_STATE_NUM,                          /**< Number of wifi-display states */
44 } MMWFDSinkStateType;
45
46 /* audio codec : AAC, AC3, LPCM  */
47 typedef enum {
48         MM_WFD_SINK_AUDIO_CODEC_NONE,
49         MM_WFD_SINK_AUDIO_CODEC_AAC = 0x0F,
50         MM_WFD_SINK_AUDIO_CODEC_AC3 = 0x81,
51         MM_WFD_SINK_AUDIO_CODEC_LPCM = 0x83
52 } MMWFDSinkAudioCodec;
53
54 typedef enum {
55         MM_WFD_SINK_HDCP_v2_0 = 1,
56         MM_WFD_SINK_HDCP_v2_1
57 } MMWfdSinkHDCPVersion;
58
59 /* video codec */
60 typedef enum {
61         MM_WFD_SINK_VIDEO_CODEC_NONE,
62         MM_WFD_SINK_VIDEO_CODEC_H265 = 0x24,
63         MM_WFD_SINK_VIDEO_CODEC_VP9  = 0x91,
64         MM_WFD_SINK_VIDEO_CODEC_H264 = 0x1b
65 } MMWFDSinkVideoCodec;
66
67 typedef enum {
68         MM_WFD_COUPLED_SINK_STATUS_NOT_COUPLED = 0,
69         MM_WFD_COUPLED_SINK_STATUS_COUPLED,
70         MM_WFD_COUPLED_SINK_STATUS_TEARDOWN_COUPLING,
71         MM_WFD_COUPLED_SINK_STATUS_RESERVED
72 } MMWFDCoupledSinkStatus;
73
74 typedef void(*MMWFDMessageCallback)(int error_type, MMWFDSinkStateType state_type, void *user_data);
75
76 /**
77  * This function creates a wi-fi display sink object. \n
78  * The attributes of wi-fi display sink are created to get/set some values with application. \n
79  * And, mutex, gstreamer and other resources are initialized at this time. \n
80  * If wi-fi display sink is created, he state will become MM_WFD_SINK_STATE_NULL.. \n
81  *
82  * @param       wfd_sink                [out]   Handle of wi-fi display sink
83  *
84  * @return      This function returns zero on success, or negative value with error code. \n
85  *                      Please refer 'mm_error.h' to know it in detail.
86  * @pre         None
87  * @post        MM_WFD_SINK_STATE_NULL
88  * @see         mm_wfd_sink_destroy
89  * @remark      You can create multiple handles on a context at the same time. \n
90  *                      However, wi-fi display sink cannot guarantee proper operation because of limitation of resources, \n
91  *                      such as audio device or display device.
92  *
93  * @par Example
94  * @code
95 if (mm_wfd_sink_create(&g_wfd_sink_handle) != MM_ERROR_NONE)
96 {
97         wfd_sink_error("failed to create wi-fi display sink\n");
98 }
99
100 mm_wfd_sink_set_message_callback(g_wfd_sink_handle, msg_callback, (void*)g_wfd_sink_handle);
101  * @endcode
102  */
103 int mm_wfd_sink_create(MMHandleType *wfd_sink);
104
105 /**
106  * This function creates a wi-fi display R2 sink object. \n
107  * Description is same to 'mm_wfd_sink_create' but 'wfd_sink' parameter should be handle of wi-fi display R2(primary/secondary) sink. \n
108  *
109  * @param       wfd_sink                [out]   Handle of wi-fi display R2(primary/secondary) sink
110  */
111 int mm_wfd_sink_create_r2(MMHandleType *wfd_sink);
112
113 /**
114  * This function trys to make gstreamer pipeline. \n
115  * If wi-fi display sink is realized, the state will become MM_WFD_SINK_STATE_READY.. \n
116  *
117  * @param       wfd_sink                [out]   Handle of wi-fi display sink
118  *
119  * @return      This function returns zero on success, or negative value with error code. \n
120  *                      Please refer 'mm_error.h' to know it in detail.
121  * @pre         MM_WFD_SINK_STATE_NULL
122  * @post        MM_WFD_SINK_STATE_PREPARED
123  * @see         mm_wfd_sink_unprepare
124  * @remark      None
125  * @par Example
126  * @code
127 if (mm_wfd_sink_prepare(&g_wfd_sink_handle) != MM_ERROR_NONE)
128 {
129         wfd_sink_error("failed to realize wi-fi display sink\n");
130 }
131  * @endcode
132  */
133 int mm_wfd_sink_prepare(MMHandleType wfd_sink_handle);
134
135 /**
136  * This function connect wi-fi display source using uri. \n
137  * audio type(AC3 AAC, LPCM) is decided at this time. \n
138  *
139  * @param       wfd_sink_handle         [in]    Handle of wi-fi display sink
140  * @param       uri                                     [in]    URI of wi-fi displaysource to be connected
141  *
142  * @return      This function returns zero on success, or negative value with error code.
143  *
144  * @pre         wi-fi display sink state should be MM_WFD_SINK_STATE_PREPARED
145  * @post        wi-fi display sink state will be MM_WFD_SINK_STATE_CONNECTED with no preroll.
146  * @remark      None
147  * @par Example
148  * @code
149 if (mm_wfd_sink_connect(g_wfd_sink_handle, g_uri) != MM_ERROR_NONE)
150 {
151         wfd_sink_error("failed to connect to wi-fi display source\n");
152 }
153  * @endcode
154  */
155 int mm_wfd_sink_connect(MMHandleType wfd_sink_handle, const char *uri);
156
157 /**
158  * This function is to start playing. \n
159  * Data from wi-fi display source will be received. \n
160  *
161  * @param       wfd_sink_handle         [in]    Handle of wi-fi display sink
162  *
163  * @return      This function returns zero on success, or negative value with error code.
164  * @remark
165  *
166  * @pre         wi-fi display sink state may be MM_WFD_SINK_STATE_CONNECTED.
167  * @post        wi-fi display sink state will be MM_WFD_SINK_STATE_PLAYING.
168  * @see         mm_wfd_sink_disconnect
169  * @remark      None
170  * @par Example
171  * @code
172 if (mm_wfd_sink_start(g_wfd_sink_handle) != MM_ERROR_NONE)
173 {
174         wfd_sink_error("failed to start wi-fi display sink\n");
175 }
176  * @endcode
177  */
178 int mm_wfd_sink_start(MMHandleType wfd_sink_handle);
179
180 /**
181  * This function is to pause playing. \n
182  * The wi-fi display sink pause the current stream being received form wi-fi display source. \n
183  *
184  * @param       wfd_sink_handle         [in]    Handle of wi-fi display sink
185  *
186  * @return      This function returns zero on success, or negative value with error code.
187  * @remark
188  *
189  * @pre         wi-fi display sink state should be MM_WFD_SINK_STATE_PLAYING.
190  * @post        wi-fi display sink state will be MM_WFD_SINK_STATE_PAUSED.
191  * @see         mm_wfd_sink_pause
192  * @remark      None
193  * @par Example
194  * @code
195 if (mm_wfd_sink_pause(g_wfd_sink_handle) != MM_ERROR_NONE)
196 {
197         wfd_sink_error("failed to pause wi-fi display sink\n");
198 }
199  * @endcode
200  */
201 int mm_wfd_sink_pause(MMHandleType wfd_sink_handle);
202
203 /**
204  * This function is to resume playing. \n
205  * Data from wi-fi display source will be received. \n
206  *
207  * @param       wfd_sink_handle         [in]    Handle of wi-fi display sink
208  *
209  * @return      This function returns zero  on success, or negative value with error code.
210  * @remark
211  *
212  * @pre         wi-fi display sink state may be MM_WFD_SINK_STATE_PAUSED.
213  * @post        wi-fi display sink state will be MM_WFD_SINK_STATE_PLAYING.
214  * @see         mm_wfd_sink_disconnect
215  * @remark      None
216  * @par Example
217  * @code
218 if (mm_wfd_sink_start(g_wfd_sink_handle) != MM_ERROR_NONE)
219 {
220         wfd_sink_error("failed to resume wi-fi display sink\n");
221 }
222  * @endcode
223  */
224 int mm_wfd_sink_resume(MMHandleType wfd_sink_handle);
225
226 /**
227  * This function is to stop playing wi-fi display. \n
228  *
229  * @param       wfd_sink_handle         [in]    Handle of wi-fi display sink
230  *
231  * @return      This function returns zero on success, or negative value with error code.
232  *
233  * @pre         wi-fi display sink state may be MM_WFD_SINK_STATE_PLAYING.
234  * @post        wi-fi display sink state will be MM_WFD_SINK_STATE_DISCONNECTED.
235  * @see         mm_wfd_sink_start
236  * @remark      None
237  * @par Example
238  * @code
239 if (mm_wfd_sink_disconnect(g_wfd_sink_handle) != MM_ERROR_NONE)
240 {
241         wfd_sink_error("failed to stop wi-fi display sink\n");
242 }
243  * @endcode
244  */
245 int mm_wfd_sink_disconnect(MMHandleType wfd_sink_handle);
246
247 /**
248  * This function trys to destroy gstreamer pipeline. \n
249  *
250  * @param       wfd_sink_handle         [out]   Handle of wi-fi display sink
251  *
252  * @return      This function returns zero on success, or negative value with error code. \n
253  *                      Please refer 'mm_error.h' to know it in detail.
254  * @pre         wi-fi display sink state may be MM_WFD_SINK_STATE_PREPARED or MM_WFD_SINK_STATE_DISCONNECTED.
255  *                      But, it can be called in any state.
256  * @post        MM_WFD_SINK_STATE_NULL
257  * @see         mm_wfd_sink_prepare
258  * @remark      None
259  * @par Example
260  * @code
261 if (mm_wfd_sink_unprepare(&g_wfd_sink_handle) != MM_ERROR_NONE)
262 {
263         wfd_sink_error("failed to unprepare wi-fi display sink\n");
264 }
265  * @endcode
266  */
267 int mm_wfd_sink_unprepare(MMHandleType wfd_sink_handle);
268
269 /**
270  * This function releases wi-fi display sink object and all resources which were created by mm_wfd_sink_create(). \n
271  * And, wi-fi display sink handle will also be destroyed. \n
272  *
273  * @param       wfd_sink_handle         [in]    Handle of wi-fi display sink
274  *
275  * @return      This function returns zero on success, or negative value with error code.
276  * @pre         wi-fi display state may be MM_WFD_SINK_STATE_NULL. \n
277  *                      But, it can be called in any state.
278  * @post        Because handle is released, there is no any state.
279  * @see         mm_wfd_sink_create
280  * @remark      This method can be called with a valid wi-fi display sink handle from any state to \n
281  *                      completely shutdown the wi-fi display sink operation.
282  *
283  * @par Example
284  * @code
285 if (mm_wfd_sink_destroy(g_wfd_sink_handle) != MM_ERROR_NONE)
286 {
287         wfd_sink_error("failed to destroy wi-fi display sink\n");
288 }
289  * @endcode
290  */
291 int mm_wfd_sink_destroy(MMHandleType wfd_sink_handle);
292
293 /**
294  * This function sets callback function for receiving messages from wi-fi display sink. \n
295  * So, wi-fi display sink can notify warning, error and normal cases to application. \n
296  *
297  * @param       wfd_sink_handle         [in]    Handle of wi-fi display sink
298  * @param       callback                        [in]    Message callback function.
299  * @param       user_param                      [in]    User parameter which is passed to callback function.
300  *
301  * @return      This function returns zero on success, or negative value with error code.
302  * @see         MMWFDMessageCallback
303  * @remark      None
304  * @par Example
305  * @code
306
307 int msg_callback(int error_type, MMWFDSinkStateType state_type, void *user_data)
308 {
309         switch (state_type)
310         {
311                 case MM_WFD_SINK_STATE_NULL:
312                         //do something
313                         break;
314
315                 case MM_WFD_SINK_STATE_PREPARED:
316                         //do something
317                         break;
318
319                 case MM_WFD_SINK_STATE_CONNECTED:
320                         //do something
321                         break;
322
323                 case MM_WFD_SINK_STATE_PLAYING:
324                         //do something
325                         break;
326
327                 case MM_WFD_SINK_STATE_PAUSED:
328                         //do something
329                         break;
330
331                 case MM_WFD_SINK_DISCONNECTED:
332                         //do something
333                         break;
334
335                 default:
336                         break;
337         }
338         return TRUE;
339 }
340
341 mm_wfd_sink_set_message_callback(g_wfd_sink_handle, msg_callback, (void*)g_wfd_sink_handle);
342  * @endcode
343  */
344 int mm_wfd_sink_set_message_callback(MMHandleType wfd_sink_handle, MMWFDMessageCallback callback, void *user_param);
345
346 /**
347  * This function is to set attributes into screen mirroring sink handle. Multiple attributes can be set simultaneously. \n
348  * If one of attribute fails, this function will stop at the point and let you know the name which is failed. \n
349  *
350  * @param       wfd_sink_handle                 [in]    Handle of screen mirroring sink handle.
351  * @param       err_attr_name                   [out]   Name of attribute which is failed to set
352  * @param       first_attr_name                 [in]    Name of the first attribute to set
353  * @param       ...                                             [in]    Value for the first attribute, followed optionally by more name/value pairs, terminated by NULL.
354  *                                                                                      But, in the case of data or string type, it should be name/value/size.
355  *
356  * @return      This function returns zero on success, or negative value with error code.
357  *
358  * @remark      This function must be terminated by NULL argument.
359  *                      And, if this function is failed, err_attr_name param must be free.
360  * @par Example
361  * @code
362 char *g_err_attr_name = NULL;
363
364 if (mm_wfd_sink_set_attribute(g_scmirroring,
365                         &g_err_attr_name,
366                         "display_overlay", display_surface, sizeof(void *),
367                         "display_surface_type", type,
368                         NULL) != MM_ERROR_NONE) {
369     LOGW("failed to set %s attribute\n", g_err_attr_name);
370     free(g_err_attr_name);
371 }
372
373  * @endcode
374  */
375 int mm_wfd_sink_set_attribute(MMHandleType wfd_sink_handle,  char **err_attr_name, const char *first_attr_name, ...);
376
377 /**
378  * This function gets the width and height of video which is played by wi-fi display sink\n
379  *
380  * @param       wfd_sink_handle         [in]    Handle of wi-fi display sink
381  * @param       width                           [in]    Width of video
382  * @param       height                          [in]    Height of video
383  *
384  * @return      This function returns zero on success, or negative value with error code.
385  * @pre         wi-fi display state should be MM_WFD_SINK_STATE_CONNECTED or MM_WFD_SINK_STATE_PLAYING. \n
386  *
387  * @par Example
388  * @code
389 gint g_width=0, g_height=0;
390
391 if (mm_wfd_sink_get_video_resolution(g_wfd_sink_handle, &g_width, &g_height) != MM_ERROR_NONE)
392 {
393         wfd_sink_error("failed to get video resolution.\n");
394 }
395  * @endcode
396  */
397 int mm_wfd_sink_get_video_resolution(MMHandleType wfd_sink_handle, gint *width, gint *height);
398
399 /**
400  * This function gets the width and height of video which is played by wi-fi display sink\n
401  *
402  * @param       wfd_sink_handle         [in]    Handle of wi-fi display sink
403  * @param       framerate                       [in]    Framerate of video
404  *
405  * @return      This function returns zero on success, or negative value with error code.
406  * @pre         wi-fi display state should be MM_WFD_SINK_STATE_CONNECTED or MM_WFD_SINK_STATE_PLAYING. \n
407  *
408  * @par Example
409  * @code
410 gint g_framerate=0;
411
412 if (mm_wfd_sink_get_video_framerate(g_wfd_sink_handle, &g_framerate) != MM_ERROR_NONE)
413 {
414         wfd_sink_error("failed to get video framerate.\n");
415 }
416  * @endcode
417  */
418 int mm_wfd_sink_get_video_framerate(MMHandleType wfd_sink_handle,  gint *framerate);
419
420 /**
421  * This function sets the resolutions for wi-fi display sink\n
422  *
423  * @param       wfd_sink_handle         [in]    Handle of wi-fi display sink
424  * @param       resolution                      [in]    Resolutions for wi-fi display sink
425  *
426  * @return      This function returns zero on success, or negative value with error code.
427  * @pre         wi-fi display state should be MM_WFD_SINK_STATE_NULL. \n
428  *
429  */
430 int mm_wfd_sink_set_resolution(MMHandleType wfd_sink_handle,  gint resolution);
431
432 /**
433  * This function gets the negotiated video codec for wi-fi display sink\n
434  *
435  * @param       wfd_sink_handle         [in]    Handle of wi-fi display sink
436  * @param       codec                           [in]    video codec for wi-fi display sink
437  *
438  * @return      This function returns zero on success, or negative value with error code.
439  * @pre         wi-fi display state should be MM_WFD_SINK_STATE_CONNECTED, MM_WFD_SINK_STATE_PLAYING or MM_WFD_SINK_STATE_PAUSED. \n
440  *
441  */
442 int mm_wfd_sink_get_negotiated_video_codec(MMHandleType wfd_sink_handle,  gint *codec);
443
444 /**
445  * This function gets the negotiated video resolution for wi-fi display sink\n
446  *
447  * @param       wfd_sink_handle         [in]    Handle of wi-fi display sink
448  * @param       width                           [in]    video width for wi-fi display sink
449  * @param       height                          [in]    video height for wi-fi display sink
450  *
451  * @return      This function returns zero on success, or negative value with error code.
452  * @pre         wi-fi display state should be MM_WFD_SINK_STATE_CONNECTED, MM_WFD_SINK_STATE_PLAYING or MM_WFD_SINK_STATE_PAUSED. \n
453  *
454  */
455 int mm_wfd_sink_get_negotiated_video_resolution(MMHandleType wfd_sink_handle,  gint *width, gint *height);
456
457 /**
458  * This function gets the negotiated video framerate for wi-fi display sink\n
459  *
460  * @param       wfd_sink_handle         [in]    Handle of wi-fi display sink
461  * @param       framerate                       [in]    video framerate for wi-fi display sink
462  *
463  * @return      This function returns zero on success, or negative value with error code.
464  * @pre         wi-fi display state should be MM_WFD_SINK_STATE_CONNECTED, MM_WFD_SINK_STATE_PLAYING or MM_WFD_SINK_STATE_PAUSED. \n
465  *
466  */
467 int mm_wfd_sink_get_negotiated_video_frame_rate(MMHandleType wfd_sink_handle,  gint *frame_rate);
468
469 /**
470  * This function gets the negotiated audio codec for wi-fi display sink\n
471  *
472  * @param       wfd_sink_handle         [in]    Handle of wi-fi display sink
473  * @param       codec                           [in]    audio codec for wi-fi display sink
474  *
475  * @return      This function returns zero on success, or negative value with error code.
476  * @pre         wi-fi display state should be MM_WFD_SINK_STATE_CONNECTED, MM_WFD_SINK_STATE_PLAYING or MM_WFD_SINK_STATE_PAUSED. \n
477  *
478  */
479 int mm_wfd_sink_get_negotiated_audio_codec(MMHandleType wfd_sink_handle,  gint *codec);
480
481 /**
482  * This function gets the negotiated audio channel for wi-fi display sink\n
483  *
484  * @param       wfd_sink_handle         [in]    Handle of wi-fi display sink
485  * @param       channel                         [in]    audio channel for wi-fi display sink
486  *
487  * @return      This function returns zero on success, or negative value with error code.
488  * @pre         wi-fi display state should be MM_WFD_SINK_STATE_CONNECTED, MM_WFD_SINK_STATE_PLAYING or MM_WFD_SINK_STATE_PAUSED. \n
489  *
490  */
491 int mm_wfd_sink_get_negotiated_audio_channel(MMHandleType wfd_sink_handle,  gint *channel);
492
493 /**
494  * This function gets the negotiated audio sample rate for wi-fi display sink\n
495  *
496  * @param       wfd_sink_handle         [in]    Handle of wi-fi display sink
497  * @param       sample_rate                     [in]    audio sample rate for wi-fi display sink
498  *
499  * @return      This function returns zero on success, or negative value with error code.
500  * @pre         wi-fi display state should be MM_WFD_SINK_STATE_CONNECTED, MM_WFD_SINK_STATE_PLAYING or MM_WFD_SINK_STATE_PAUSED. \n
501  *
502  */
503 int mm_wfd_sink_get_negotiated_audio_sample_rate(MMHandleType wfd_sink_handle,  gint *sample_rate);
504
505 /**
506  * This function gets the negotiated audio bitwidth for wi-fi display sink\n
507  *
508  * @param       wfd_sink_handle         [in]    Handle of wi-fi display sink
509  * @param       bitwidth                        [in]    audio bitwidth for wi-fi display sink
510  *
511  * @return      This function returns zero on success, or negative value with error code.
512  * @pre         wi-fi display state should be MM_WFD_SINK_STATE_CONNECTED, MM_WFD_SINK_STATE_PLAYING or MM_WFD_SINK_STATE_PAUSED. \n
513  *
514  */
515 int mm_wfd_sink_get_negotiated_audio_bitwidth(MMHandleType wfd_sink_handle,  gint *bitwidth);
516
517 /**
518  * This function gets the current state for wi-fi display sink\n
519  *
520  * @param       wfd_sink_handle         [in]    Handle of wi-fi display sink
521  * @param       state                           [out]   Current state of wi-fi display sink
522  *
523  * @return      This function returns zero on success, or negative value with error code.
524  *
525  */
526 int mm_wfd_sink_get_current_state(MMHandleType wfd_sink_handle, gint *state);
527
528 /**
529  * This function sets the MAC(or IP) address of coupled wi-fi display R2 sink. \n
530  *
531  * @param       wfd_sink_handle         [in]    Handle of wi-fi display R2 sink
532  * @param       address                         [in]    Mac(or IP) address of coupled wi-fi display R2 sink.
533  *
534  * @return  This function returns zero on success, or negative value with error code.
535  *
536  */
537 int mm_wfd_sink_set_coupled_sink(MMHandleType wfd_sink_handle, gchar *address);
538
539 /**
540  * This function sets the coupling status of wi-fi display R2 sink. \n
541  *
542  * @param       wfd_sink_handle         [in]    Handle of wi-fi display R2 sink
543  * @param       status                          [in]    Coupling status of wi-fi display R2 sink.
544  *
545  * @return  This function returns zero on success, or negative value with error code.
546  *
547  */
548 int mm_wfd_sink_set_coupled_sink_status(MMHandleType wfd_sink_handle, guint status);
549
550 #endif