reuse tbm surface when player send decoded video frame
[platform/core/api/player.git] / include / player_msg.h
1 /*
2 * Copyright (c) 2011 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 #ifndef __TIZEN_MEDIA_PLAYER_MSG_PRIVATE_H__
18 #define __TIZEN_MEDIA_PLAYER_MSG_PRIVATE_H__
19
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23
24 #include <muse_player_msg.h>
25
26 /**
27  * @brief Create and send address of server side module infomation structure.
28  * @remarks Does NOT guarantee thread safe.
29  * @param[in] module The server side module infomation.
30  * @param[in] fd socket fd
31  */
32 #define muse_core_send_module_addr(module, fd) \
33         do {\
34                 char *__sndMsg__; \
35                 int __len__; \
36                 __sndMsg__ = muse_core_msg_json_factory_new(0, \
37                                 MUSE_TYPE_POINTER, #module, module, \
38                                 0); \
39                 __len__ = muse_core_ipc_send_msg(fd, __sndMsg__); \
40                 muse_core_msg_json_factory_free(__sndMsg__); \
41                 if (__len__ <= 0) { \
42                         LOGE("sending message failed"); \
43                         return PLAYER_ERROR_INVALID_OPERATION; \
44                 } \
45         } while (0)
46
47 /**
48  * @brief Create and send message. Wait for server result.
49  * @remarks Does NOT guarantee thread safe.
50  * @param[in] api The enum of module API.
51  * @param[in] player The handle of capi media player.
52  * @param[out] retbuf The buffer of return message. Must be char pointer.
53  * @param[out] ret The return value from server.
54  */
55 #define player_msg_send(api, player, retbuf, ret) \
56         do {    \
57                 char *__sndMsg__; \
58                 int __len__; \
59                 int __fd__; \
60                 int __timeout__ = client_get_api_timeout(player, api); \
61                 if (CALLBACK_INFO(player)) __fd__ = MSG_FD(player); \
62                 else {ret = PLAYER_ERROR_INVALID_STATE; break; } \
63                 __sndMsg__ = muse_core_msg_json_factory_new(api, \
64                                 0); \
65                 __len__ = muse_core_ipc_send_msg(__fd__, __sndMsg__); \
66                 if (__len__ <= 0) { \
67                         LOGE("sending message failed"); \
68                         ret = PLAYER_ERROR_INVALID_OPERATION; \
69                 } else \
70                         ret = client_wait_for_cb_return(api, CALLBACK_INFO(player), &retbuf, __timeout__); \
71                 muse_core_msg_json_factory_free(__sndMsg__); \
72         } while (0)
73
74 /**
75  * @brief Create and send message. Wait for server result.
76  * @remarks Does NOT guarantee thread safe.
77  * @param[in] api The enum of module API.
78  * @param[in] player The handle of capi media player.
79  * @param[out] retbuf The buffer of return message. Must be char pointer.Must free after use.
80  * @param[out] ret The return value from server.
81  * @param[in] type The enum of parameter type. Muse be one of thease(INT, INT64, POINTER, DOUBLE, STRING, ARRAY)
82  * @param[in] param the name of param is key, must be local variable. never be pointer.
83  */
84 #define player_msg_send1(api, player, retbuf, ret, type, param) \
85         do {    \
86                 char *__sndMsg__; \
87                 int __len__; \
88                 int __fd__; \
89                 int __timeout__ = client_get_api_timeout(player, api); \
90                 type __value__ = (type)param; \
91                 if (CALLBACK_INFO(player)) __fd__ = MSG_FD(player); \
92                 else {ret = PLAYER_ERROR_INVALID_STATE; break; } \
93                 __sndMsg__ = muse_core_msg_json_factory_new(api, \
94                                 MUSE_TYPE_##type, #param, __value__, \
95                                 0); \
96                 __len__ = muse_core_ipc_send_msg(__fd__, __sndMsg__); \
97                 if (__len__ <= 0) { \
98                         LOGE("sending message failed"); \
99                         ret = PLAYER_ERROR_INVALID_OPERATION; \
100                 } else \
101                         ret = client_wait_for_cb_return(api, CALLBACK_INFO(player), &retbuf, __timeout__); \
102                 muse_core_msg_json_factory_free(__sndMsg__); \
103         } while (0)
104
105 /**
106  * @brief Create and send message. Wait for server result.
107  * @remarks Does NOT guarantee thread safe.
108  * @param[in] api The enum of module API.
109  * @param[in] player The handle of capi media player.
110  * @param[out] retbuf The buffer of return message. Must be char pointer.Must free after use.
111  * @param[out] ret The return value from server.
112  * @param[in] type The enum of parameter type. Muse be one of thease(INT, INT64, POINTER, DOUBLE, STRING, ARRAY)
113  * @param[in] param# the name of param is key, must be local variable. never be pointer.
114  */
115 #define player_msg_send2(api, player, retbuf, ret, type1, param1, type2, param2) \
116         do {    \
117                 char *__sndMsg__; \
118                 int __len__; \
119                 int __fd__; \
120                 int __timeout__ = client_get_api_timeout(player, api); \
121                 type1 __value1__ = (type1)param1; \
122                 type2 __value2__ = (type2)param2; \
123                 if (CALLBACK_INFO(player)) __fd__ = MSG_FD(player); \
124                 else {ret = PLAYER_ERROR_INVALID_STATE; break; } \
125                 __sndMsg__ = muse_core_msg_json_factory_new(api, \
126                                 MUSE_TYPE_##type1, #param1, __value1__, \
127                                 MUSE_TYPE_##type2, #param2, __value2__, \
128                                 0); \
129                 __len__ = muse_core_ipc_send_msg(__fd__, __sndMsg__); \
130                 if (__len__ <= 0) { \
131                         LOGE("sending message failed"); \
132                         ret = PLAYER_ERROR_INVALID_OPERATION; \
133                 } else \
134                         ret = client_wait_for_cb_return(api, CALLBACK_INFO(player), &retbuf, __timeout__); \
135                 muse_core_msg_json_factory_free(__sndMsg__); \
136         } while (0)
137
138 /**
139  * @brief Create and send message. Wait for server result.
140  * @remarks Does NOT guarantee thread safe.
141  * @param[in] api The enum of module API.
142  * @param[in] player The handle of capi media player.
143  * @param[out] retbuf The buffer of return message. Must be char pointer.Must free after use.
144  * @param[out] ret The return value from server.
145  * @param[in] type The enum of parameter type. Muse be one of thease(INT, INT64, POINTER, DOUBLE, STRING, ARRAY)
146  * @param[in] param# the name of param is key, must be local variable. never be pointer.
147  */
148 #define player_msg_send3(api, player, retbuf, ret, type1, param1, type2, param2, type3, param3) \
149         do {    \
150                 char *__sndMsg__; \
151                 int __len__; \
152                 int __fd__; \
153                 int __timeout__ = client_get_api_timeout(player, api); \
154                 type1 __value1__ = (type1)param1; \
155                 type2 __value2__ = (type2)param2; \
156                 type3 __value3__ = (type3)param3; \
157                 if (CALLBACK_INFO(player)) __fd__ = MSG_FD(player); \
158                 else {ret = PLAYER_ERROR_INVALID_STATE; break; } \
159                 __sndMsg__ = muse_core_msg_json_factory_new(api, \
160                                 MUSE_TYPE_##type1, #param1, __value1__, \
161                                 MUSE_TYPE_##type2, #param2, __value2__, \
162                                 MUSE_TYPE_##type3, #param3, __value3__, \
163                                 0); \
164                 __len__ = muse_core_ipc_send_msg(__fd__, __sndMsg__); \
165                 if (__len__ <= 0) { \
166                         LOGE("sending message failed"); \
167                         ret = PLAYER_ERROR_INVALID_OPERATION; \
168                 } else \
169                         ret = client_wait_for_cb_return(api, CALLBACK_INFO(player), &retbuf, __timeout__); \
170                 muse_core_msg_json_factory_free(__sndMsg__); \
171         } while (0)
172
173 /**
174  * @brief Create and send message. Wait for server result.
175  * @remarks Does NOT guarantee thread safe.
176  * @param[in] api The enum of module API.
177  * @param[in] player The handle of capi media player.
178  * @param[out] retbuf The buffer of return message. Must be char pointer.Must free after use.
179  * @param[out] ret The return value from server.
180  * @param[in] type The enum of parameter type. Muse be one of thease(INT, INT64, POINTER, DOUBLE, STRING, ARRAY)
181  * @param[in] param# the name of param is key, must be local variable. never be pointer.
182  */
183 #define player_msg_send4(api, player, retbuf, ret, type1, param1, type2, param2, type3, param3, type4, param4) \
184         do {    \
185                 char *__sndMsg__; \
186                 int __len__; \
187                 int __fd__; \
188                 int __timeout__ = client_get_api_timeout(player, api); \
189                 type1 __value1__ = (type1)param1; \
190                 type2 __value2__ = (type2)param2; \
191                 type3 __value3__ = (type3)param3; \
192                 type4 __value4__ = (type4)param4; \
193                 if (CALLBACK_INFO(player)) __fd__ = MSG_FD(player); \
194                 else {ret = PLAYER_ERROR_INVALID_STATE; break; } \
195                 __sndMsg__ = muse_core_msg_json_factory_new(api, \
196                                 MUSE_TYPE_##type1, #param1, __value1__, \
197                                 MUSE_TYPE_##type2, #param2, __value2__, \
198                                 MUSE_TYPE_##type3, #param3, __value3__, \
199                                 MUSE_TYPE_##type4, #param4, __value4__, \
200                                 0); \
201                 __len__ = muse_core_ipc_send_msg(__fd__, __sndMsg__); \
202                 if (__len__ <= 0) { \
203                         LOGE("sending message failed"); \
204                         ret = PLAYER_ERROR_INVALID_OPERATION; \
205                 } else \
206                         ret = client_wait_for_cb_return(api, CALLBACK_INFO(player), &retbuf, __timeout__); \
207                 muse_core_msg_json_factory_free(__sndMsg__); \
208         } while (0)
209
210 /**
211  * @brief Create and send message. Wait for server result.
212  * @remarks Does NOT guarantee thread safe.
213  * @param[in] api The enum of module API.
214  * @param[in] player The handle of capi media player.
215  * @param[out] retbuf The buffer of return message. Must be char pointer.Must free after use.
216  * @param[out] ret The return value from server.
217  * @param[in] type The enum of parameter type. Muse be one of thease(INT, INT64, POINTER, DOUBLE, STRING, ARRAY)
218  * @param[in] param# the name of param is key, must be local variable. never be pointer.
219  */
220 #define player_msg_send5(api, player, retbuf, ret, type1, param1, type2, param2, type3, param3, type4, param4, type5, param5) \
221         do { \
222                 char *__sndMsg__; \
223                 int __len__; \
224                 int __fd__; \
225                 int __timeout__ = client_get_api_timeout(player, api); \
226                 type1 __value1__ = (type1)param1; \
227                 type2 __value2__ = (type2)param2; \
228                 type3 __value3__ = (type3)param3; \
229                 type4 __value4__ = (type4)param4; \
230                 type5 __value5__ = (type5)param5; \
231                 if (CALLBACK_INFO(player)) __fd__ = MSG_FD(player); \
232                 else {ret = PLAYER_ERROR_INVALID_STATE; break; } \
233                 __sndMsg__ = muse_core_msg_json_factory_new(api, \
234                         MUSE_TYPE_##type1, #param1, __value1__, \
235                         MUSE_TYPE_##type2, #param2, __value2__, \
236                         MUSE_TYPE_##type3, #param3, __value3__, \
237                         MUSE_TYPE_##type4, #param4, __value4__, \
238                         MUSE_TYPE_##type5, #param5, __value5__, \
239                         0); \
240                 __len__ = muse_core_ipc_send_msg(__fd__, __sndMsg__); \
241                 if (__len__ <= 0) { \
242                         LOGE("sending message failed"); \
243                         ret = PLAYER_ERROR_INVALID_OPERATION; \
244                 } else \
245                         ret = client_wait_for_cb_return(api, CALLBACK_INFO(player), &retbuf, __timeout__); \
246                 muse_core_msg_json_factory_free(__sndMsg__); \
247         } while (0)
248
249 /**
250  * @brief Create and send message. Wait for server result.
251  * @remarks Does NOT guarantee thread safe.
252  * @param[in] api The enum of module API.
253  * @param[in] player The handle of capi media player.
254  * @param[out] retbuf The buffer of return message. Must be char pointer.Must free after use.
255  * @param[out] ret The return value from server.
256  * @param[in] type The enum of parameter type. Muse be one of thease(INT, INT64, POINTER, DOUBLE, STRING, ARRAY)
257  * @param[in] param# the name of param is key, must be local variable. never be pointer.
258  */
259 #define player_msg_send6(api, player, retbuf, ret, type1, param1, type2, param2, type3, param3, type4, param4, type5, param5, type6, param6) \
260         do {    \
261                 char *__sndMsg__; \
262                 int __len__; \
263                 int __fd__; \
264                 int __timeout__ = client_get_api_timeout(player, api); \
265                 type1 __value1__ = (type1)param1; \
266                 type2 __value2__ = (type2)param2; \
267                 type3 __value3__ = (type3)param3; \
268                 type4 __value4__ = (type4)param4; \
269                 type5 __value5__ = (type5)param5; \
270                 type6 __value6__ = (type6)param6; \
271                 if (CALLBACK_INFO(player)) __fd__ = MSG_FD(player); \
272                 else {ret = PLAYER_ERROR_INVALID_STATE; break; } \
273                 __sndMsg__ = muse_core_msg_json_factory_new(api, \
274                                 MUSE_TYPE_##type1, #param1, __value1__, \
275                                 MUSE_TYPE_##type2, #param2, __value2__, \
276                                 MUSE_TYPE_##type3, #param3, __value3__, \
277                                 MUSE_TYPE_##type4, #param4, __value4__, \
278                                 MUSE_TYPE_##type5, #param5, __value5__, \
279                                 MUSE_TYPE_##type6, #param6, __value6__, \
280                                 0); \
281                 __len__ = muse_core_ipc_send_msg(__fd__, __sndMsg__); \
282                 if (__len__ <= 0) { \
283                         LOGE("sending message failed"); \
284                         ret = PLAYER_ERROR_INVALID_OPERATION; \
285                 } else \
286                         ret = client_wait_for_cb_return(api, CALLBACK_INFO(player), &retbuf, __timeout__); \
287                 muse_core_msg_json_factory_free(__sndMsg__); \
288         } while (0)
289
290 /**
291  * @brief Create and send message. Wait for server result.
292  * @remarks Does NOT guarantee thread safe.
293  * @param[in] api The enum of module API.
294  * @param[in] player The handle of capi media player.
295  * @param[out] retbuf The buffer of return message. Must be char pointer.Must free after use.
296  * @param[out] ret The return value from server.
297  * @param[in] param the name of param is key, must be local array/pointer variable.
298  * @param[in] length The size of array.
299  * @param[in] datum_size The size of a array's datum.
300  */
301 #define player_msg_send_array(api, player, retbuf, ret, param, length, datum_size) \
302         do {    \
303                 char *__sndMsg__; \
304                 int __len__; \
305                 int __fd__; \
306                 int __timeout__ = client_get_api_timeout(player, api); \
307                 int *__value__ = (int *)param; \
308                 if (CALLBACK_INFO(player)) __fd__ = MSG_FD(player); \
309                 else {ret = PLAYER_ERROR_INVALID_STATE; break; } \
310                 __sndMsg__ = muse_core_msg_json_factory_new(api, \
311                                 MUSE_TYPE_INT, #length, length, \
312                                 MUSE_TYPE_ARRAY, #param, \
313                                         datum_size == sizeof(int) ? length :  \
314                                         length / sizeof(int) + (length % sizeof(int) ? 1 : 0), \
315                                         __value__, \
316                                 0); \
317                 __len__ = muse_core_ipc_send_msg(__fd__, __sndMsg__); \
318                 if (__len__ <= 0) { \
319                         LOGE("sending message failed"); \
320                         ret = PLAYER_ERROR_INVALID_OPERATION; \
321                 } else \
322                         ret = client_wait_for_cb_return(api, CALLBACK_INFO(player), &retbuf, __timeout__); \
323                 muse_core_msg_json_factory_free(__sndMsg__); \
324         } while (0)
325
326 /**
327  * @brief Create and send message. Wait for server result.
328  * @remarks Does NOT guarantee thread safe.
329  * @param[in] api The enum of module API.
330  * @param[in] player The handle of capi media player.
331  * @param[out] retbuf The buffer of return message. Must be char pointer.Must free after use.
332  * @param[out] ret The return value from server.
333  * @param[in] param# the name of param is key, must be local array/pointer variable.
334  * @param[in] length# The size of array.
335  * @param[in] datum_size# The size of a array's datum.
336  */
337 #define player_msg_send_array2(api, player, retbuf, ret, param1, length1, datum_size1, param2, length2, datum_size2) \
338         do {    \
339                 char *__sndMsg__; \
340                 int __len__; \
341                 int __fd__; \
342                 int __timeout__ = client_get_api_timeout(player, api); \
343                 int *__value1__ = (int *)param1; \
344                 int *__value2__ = (int *)param2; \
345                 if (CALLBACK_INFO(player)) __fd__ = MSG_FD(player); \
346                 else {ret = PLAYER_ERROR_INVALID_STATE; break; } \
347                 __sndMsg__ = muse_core_msg_json_factory_new(api, \
348                                 MUSE_TYPE_INT, #length1, length1, \
349                                 MUSE_TYPE_ARRAY, #param1, \
350                                         datum_size1 == sizeof(int) ? length1 :  \
351                                         length1 / sizeof(int) + (length1 % sizeof(int) ? 1 : 0), \
352                                         __value1__, \
353                                 MUSE_TYPE_INT, #length2, length2, \
354                                 MUSE_TYPE_ARRAY, #param2, \
355                                         datum_size2 == sizeof(int) ? length2 :  \
356                                         length2 / sizeof(int) + (length2 % sizeof(int) ? 1 : 0), \
357                                         __value2__, \
358                                 0); \
359                 __len__ = muse_core_ipc_send_msg(__fd__, __sndMsg__); \
360                 if (__len__ <= 0) { \
361                         LOGE("sending message failed"); \
362                         ret = PLAYER_ERROR_INVALID_OPERATION; \
363                 } else \
364                         ret = client_wait_for_cb_return(api, CALLBACK_INFO(player), &retbuf, __timeout__); \
365                 muse_core_msg_json_factory_free(__sndMsg__); \
366         } while (0)
367
368 /**
369  * @brief Create and send message. Wait for server result.
370  * @remarks Does NOT guarantee thread safe.
371  * @param[in] api The enum of module API.
372  * @param[in] player The handle of capi media player.
373  * @param[out] retbuf The buffer of return message. Must be char pointer.Must free after use.
374  * @param[out] ret The return value from server.
375  * @param[in] param# the name of param is key, must be local array/pointer variable.
376  * @param[in] length# The size of array.
377  * @param[in] datum_size# The size of a array's datum.
378  */
379 #define player_msg_send1_array2(api, player, retbuf, ret, type1, param1, param2, length2, datum_size2, param3, length3, datum_size3) \
380         do { \
381                 char *__sndMsg__; \
382                 int __len__; \
383                 int __fd__; \
384                 int __timeout__ = client_get_api_timeout(player, api); \
385                 type1 __value1__ = (type1)param1; \
386                 int *__value2__ = (int *)param2; \
387                 int *__value3__ = (int *)param3; \
388                 if (CALLBACK_INFO(player)) __fd__ = MSG_FD(player); \
389                 else {ret = PLAYER_ERROR_INVALID_STATE; break; } \
390                 __sndMsg__ = muse_core_msg_json_factory_new(api, \
391                         MUSE_TYPE_##type1, #param1, __value1__, \
392                         MUSE_TYPE_INT, #length2, length2, \
393                         MUSE_TYPE_ARRAY, #param2, \
394                                 datum_size2 == sizeof(int) ? length2 :  \
395                                 length2 / sizeof(int) + (length2 % sizeof(int) ? 1 : 0), \
396                                 __value2__, \
397                         MUSE_TYPE_INT, #length3, length3, \
398                         MUSE_TYPE_ARRAY, #param3, \
399                                 datum_size3 == sizeof(int) ? length3 :  \
400                                 length3 / sizeof(int) + (length3 % sizeof(int) ? 1 : 0), \
401                                 __value3__, \
402                         0); \
403             __len__ = muse_core_ipc_send_msg(__fd__, __sndMsg__); \
404                 if (__len__ <= 0) { \
405                         LOGE("sending message failed"); \
406                         ret = PLAYER_ERROR_INVALID_OPERATION; \
407                 } else \
408                         ret = client_wait_for_cb_return(api, CALLBACK_INFO(player), &retbuf, __timeout__); \
409                 muse_core_msg_json_factory_free(__sndMsg__); \
410         } while (0)
411
412 /**
413  * @brief Create and send message. Wait for server result.
414  * @remarks Does NOT guarantee thread safe.
415  * @param[in] api The enum of module API.
416  * @param[in] player The handle of capi media player.
417  * @param[out] retbuf The buffer of return message. Must be char pointer.Must free after use.
418  * @param[out] ret The return value from server.
419  * @param[in] type The enum of parameter type. Muse be one of thease(INT, INT64, POINTER, DOUBLE, STRING, ARRAY)
420  * @param[in] param# the name of param is key, must be local variable. never be pointer.
421  * @param[in] length# The size of array.
422  * @param[in] datum_size# The size of a array's datum.
423  */
424 #define player_msg_send2_array(api, player, retbuf, ret, type1, param1, type2, param2, param_arr, length, datum_size) \
425         do {    \
426                 char *__sndMsg__; \
427                 int __len__; \
428                 int __fd__; \
429                 int __timeout__ = client_get_api_timeout(player, api); \
430                 type1 __value1__ = (type1)param1; \
431                 type2 __value2__ = (type2)param2; \
432                 int *__value_arr__ = (int *)param_arr; \
433                 if (CALLBACK_INFO(player)) __fd__ = MSG_FD(player); \
434                 else {ret = PLAYER_ERROR_INVALID_STATE; break; } \
435                 __sndMsg__ = muse_core_msg_json_factory_new(api, \
436                                 MUSE_TYPE_##type1, #param1, __value1__, \
437                                 MUSE_TYPE_##type2, #param2, __value2__, \
438                                 MUSE_TYPE_INT, #length, length, \
439                                 MUSE_TYPE_ARRAY, #param_arr, \
440                                         datum_size == sizeof(int) ? length :  \
441                                         length / sizeof(int) + (length % sizeof(int) ? 1 : 0), \
442                                         __value_arr__, \
443                                 0); \
444                 __len__ = muse_core_ipc_send_msg(__fd__, __sndMsg__); \
445                 if (__len__ <= 0) { \
446                         LOGE("sending message failed"); \
447                         ret = PLAYER_ERROR_INVALID_OPERATION; \
448                 } else \
449                         ret = client_wait_for_cb_return(api, CALLBACK_INFO(player), &retbuf, __timeout__); \
450                 muse_core_msg_json_factory_free(__sndMsg__); \
451         } while (0)
452
453 /**
454  * @brief Create and send message. Wait for server result.
455  * @remarks Does NOT guarantee thread safe.
456  * @param[in] api The enum of module API.
457  * @param[in] player The handle of capi media player.
458  * @param[out] retbuf The buffer of return message. Must be char pointer.Must free after use.
459  * @param[out] ret The return value from server.
460  * @param[in] type The enum of parameter type. Muse be one of thease(INT, INT64, POINTER, DOUBLE, STRING, ARRAY)
461  * @param[in] param# the name of param is key, must be local variable. never be pointer.
462  * @param[in] length# The size of array.
463  * @param[in] datum_size# The size of a array's datum.
464  */
465 #define player_msg_send3_array2(api, player, retbuf, ret, type1, param1, type2, param2, type3, param3, param4, length4, datum_size4, param5, length5, datum_size5) \
466         do { \
467                 char *__sndMsg__; \
468                 int __len__; \
469                 int __fd__; \
470                 int __timeout__ = client_get_api_timeout(player, api); \
471                 type1 __value1__ = (type1)param1; \
472                 type2 __value2__ = (type2)param2; \
473                 type3 __value3__ = (type3)param3; \
474                 int *__value4__ = (int *)param4; \
475                 int *__value5__ = (int *)param5; \
476                 if (CALLBACK_INFO(player)) __fd__ = MSG_FD(player); \
477                 else {ret = PLAYER_ERROR_INVALID_STATE; break; } \
478                 __sndMsg__ = muse_core_msg_json_factory_new(api, \
479                                 MUSE_TYPE_##type1, #param1, __value1__, \
480                                 MUSE_TYPE_##type2, #param2, __value2__, \
481                                 MUSE_TYPE_##type3, #param3, __value3__, \
482                                 MUSE_TYPE_INT, #length4, length4, \
483                                 MUSE_TYPE_ARRAY, #param4, \
484                                         datum_size4 == sizeof(int) ? length4 :  \
485                                         length4 / sizeof(int) + (length4 % sizeof(int) ? 1 : 0), \
486                                         __value4__, \
487                                 MUSE_TYPE_INT, #length5, length5, \
488                                 MUSE_TYPE_ARRAY, #param5, \
489                                         datum_size5 == sizeof(int) ? length5 :  \
490                                         length5 / sizeof(int) + (length5 % sizeof(int) ? 1 : 0), \
491                                         __value5__, \
492                                 0); \
493                 __len__ = muse_core_ipc_send_msg(__fd__, __sndMsg__); \
494                 if (__len__ <= 0) { \
495                         LOGE("sending message failed"); \
496                         ret = PLAYER_ERROR_INVALID_OPERATION; \
497                 } else \
498                         ret = client_wait_for_cb_return(api, CALLBACK_INFO(player), &retbuf, __timeout__); \
499                 muse_core_msg_json_factory_free(__sndMsg__); \
500         } while (0)
501
502 /**
503  * @brief Create and send message. Does not wait server result.
504  * @remarks Does NOT guarantee thread safe.
505  * @param[in] api The enum of module API.
506  * @param[in] player The handle of capi media player.
507  * @param[in] type The enum of parameter type. Muse be one of thease(INT, INT64, POINTER, DOUBLE, STRING, ARRAY)
508  * @param[in] param the name of param is key, must be local variable. never be pointer.
509  */
510 #define player_msg_send1_async(api, player, type, param) \
511         do {    \
512                 char *__sndMsg__; \
513                 int __len__; \
514                 int __fd__; \
515                 type __value__ = (type)param; \
516                 if (CALLBACK_INFO(player)) __fd__ = MSG_FD(player); \
517                 else {ret = PLAYER_ERROR_INVALID_STATE; break; } \
518                 __sndMsg__ = muse_core_msg_json_factory_new(api, \
519                                 MUSE_TYPE_##type, #param, __value__, \
520                                 0); \
521                 __len__ = muse_core_ipc_send_msg(__fd__, __sndMsg__); \
522                 muse_core_msg_json_factory_free(__sndMsg__); \
523                 if (__len__ <= 0) { \
524                         LOGE("sending message failed"); \
525                         return PLAYER_ERROR_INVALID_OPERATION; \
526                 } \
527         } while (0)
528
529 /**
530  * @brief Create and send message. Does not wait server result.
531  * @remarks Does NOT guarantee thread safe.
532  * @param[in] api The enum of module API.
533  * @param[in] player The handle of capi media player.
534  * @param[in] type The enum of parameter type. Muse be one of thease(INT, INT64, POINTER, DOUBLE, STRING, ARRAY)
535  * @param[in] param the name of param is key, must be local variable. never be pointer.
536  */
537 #define player_msg_send1_no_return(api, fd, type, param) \
538         do { \
539                 char *__sndMsg__; \
540                 int __len__; \
541                 type __value__ = (type)param; \
542                 __sndMsg__ = muse_core_msg_json_factory_new(api, \
543                                 MUSE_TYPE_##type, #param, __value__, \
544                                 0); \
545                 __len__ = muse_core_ipc_send_msg(fd, __sndMsg__); \
546                 muse_core_msg_json_factory_free(__sndMsg__); \
547                 if (__len__ <= 0) { \
548                         LOGE("sending message failed"); \
549                 } \
550         } while (0)
551
552 /**
553  * @brief Create and send message. Does not wait server result.
554  * @remarks Does NOT guarantee thread safe.
555  * @param[in] api The enum of module API.
556  * @param[in] player The server side handle of media player.
557  * @param[in] fd socket fd
558  * @param[in] type The enum of parameter type. Muse be one of thease(INT, INT64, POINTER, DOUBLE, STRING, ARRAY)
559  * @param[in] param the name of param is key, must be local variable. never be pointer.
560  */
561 #define player_msg_create_handle(api, fd, type1, param1, type2, param2) \
562         do {    \
563                 char *__sndMsg__; \
564                 int __len__; \
565                 type1 __value1__ = (type1)param1; \
566                 type2 __value2__ = (type2)param2; \
567                 __sndMsg__ = muse_core_msg_json_factory_new(api, \
568                                 MUSE_TYPE_##type1, #param1, __value1__, \
569                                 MUSE_TYPE_##type2, #param2, __value2__, \
570                                 0); \
571                 __len__ = muse_core_ipc_send_msg(fd, __sndMsg__); \
572                 muse_core_msg_json_factory_free(__sndMsg__); \
573                 if (__len__ <= 0) { \
574                         LOGE("sending message failed"); \
575                         return PLAYER_ERROR_INVALID_OPERATION; \
576                 } \
577         } while (0)
578
579
580 /**
581  * @brief Create and send message for callback. Does not wait server result.
582  * @remarks Does NOT guarantee thread safe.
583  * @param[in] api The enum of module API.
584  * @param[in] player The handle of capi media player.
585  * @param[out] ret set ERROR when fail to send msg.
586  * @param[in] event_type type of event (muse_player_event_e).
587  * @param[in] set 1 is set the user callback, 0 is unset the user callback.
588  */
589 #define player_msg_set_callback(api, player, ret, event_type, set) \
590         do {    \
591                 char *__sndMsg__; \
592                 int __len__; \
593                 int __fd__; \
594                 int __value1__ = (int)event_type; \
595                 int __value2__ = (int)set; \
596                 if (CALLBACK_INFO(player)) __fd__ = MSG_FD(player); \
597                 else {ret = PLAYER_ERROR_INVALID_STATE; break; } \
598                 __sndMsg__ = muse_core_msg_json_factory_new(api, \
599                                 MUSE_TYPE_INT, #event_type, __value1__, \
600                                 MUSE_TYPE_INT, #set, __value2__, \
601                                 0); \
602                 __len__ = muse_core_ipc_send_msg(__fd__, __sndMsg__); \
603                 muse_core_msg_json_factory_free(__sndMsg__); \
604                 if (__len__ <= 0) { \
605                         LOGE("sending message failed"); \
606                         ret = PLAYER_ERROR_INVALID_OPERATION; \
607                 } \
608         } while (0)
609
610 /**
611  * @brief Get value from Message.
612  * @remarks Does NOT guarantee thread safe.
613  * @param[in] buf string of message buffer. has key and value
614  * @param[out] param# the name of param is key, must be local variable. never be pointer.
615  * @param[in] type#The enum of parameter type. Muse be one of thease(INT, INT64, POINTER, DOUBLE)
616  * @param[out] arr_param the name of param is key, must be local variable. never be pointer.
617  * @param[out] ret result of get value
618
619  */
620 #define player_msg_get2_array(buf, param1, type1, param2, type2, arr_param, ret) \
621         do { \
622                 void *__jobj__ = muse_core_msg_json_object_new(buf, NULL, NULL); \
623                 if (!muse_core_msg_json_object_get_value(#param1, __jobj__, &param1, MUSE_TYPE_##type1)) { \
624                         LOGE("failed to get value(%s)", #param1); \
625                         ret = FALSE; \
626                 } \
627                 if (ret && !muse_core_msg_json_object_get_value(#param2, __jobj__, &param2, MUSE_TYPE_##type2)) { \
628                         LOGE("failed to get %s value", #param2); \
629                         ret = FALSE; \
630                 } \
631                 if (ret && !muse_core_msg_json_object_get_value(#arr_param, __jobj__, arr_param, MUSE_TYPE_ANY)) { \
632                         LOGE("failed to get %s value", #arr_param); \
633                         ret = FALSE; \
634                 } \
635                 muse_core_msg_json_object_free(__jobj__); \
636         } while (0)
637
638 /**
639  * @brief Get value from Message.
640  * @remarks Does NOT guarantee thread safe.
641  * @param[in] buf string of message buffer. has key and value
642  * @param[out] str_param# the name of param is key, must be local pointer variable.
643  * @param[out] ret result of get value
644  */
645 #define player_msg_get_string2(buf, str_param1, str_param2, ret) \
646         do { \
647                 muse_core_msg_parse_err_e __err__ = MUSE_MSG_PARSE_ERROR_NONE; \
648                 void *__jobj__ = muse_core_msg_json_object_new(buf, NULL, &__err__); \
649                 if (!__jobj__) { \
650                         LOGE("failed to get msg object. err:%d", __err__); \
651                         ret = FALSE; \
652                 } else { \
653                         if (!muse_core_msg_json_object_get_value(#str_param1, __jobj__, str_param1, MUSE_TYPE_STRING)) { \
654                                 LOGE("failed to get %s value", #str_param1); \
655                                 ret = FALSE; \
656                         } \
657                         if (ret && !muse_core_msg_json_object_get_value(#str_param2, __jobj__, str_param2, MUSE_TYPE_STRING)) { \
658                                 LOGE("failed to get %s value", #str_param2); \
659                                 ret = FALSE; \
660                         } \
661                         muse_core_msg_json_object_free(__jobj__); \
662                 } \
663         } while (0)
664
665 #endif /* __TIZEN_MEDIA_PLAYER_MSG_PRIVATE_H__ */