1. Split audiobin/videobin into decodebin/sinkbin
[platform/core/multimedia/libmm-wfd.git] / common / mm_wfd_attrs.c
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  * Manoj Kumar K <manojkumar.k@samsung.com>, Hyunil Park <hyunil46.park@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 #include "mm_wfd_attrs.h"
24
25 typedef struct {
26         char *name;
27         int value_type;
28         int flags;           /* r, w */
29         void *default_value;
30         int valid_type;
31         int value_min;
32         int value_max;
33 } MMWfdAttrsSpec;
34
35 /*static gboolean __mmwfd_apply_attribute(MMHandleType handle, const char *attribute_name); */
36
37 MMHandleType
38 _mmwfd_construct_attribute(MMHandleType handle)
39 {
40         int idx = 0;
41         MMHandleType attrs = 0;
42         int num_of_attrs = 0;
43         mmf_attrs_construct_info_t *base = NULL;
44
45         debug_fenter();
46
47         return_val_if_fail(handle, (MMHandleType) NULL);
48
49         MMWfdAttrsSpec wfd_attrs[] = {
50                 {
51                         (char *)"server_ip",
52                         MM_ATTRS_TYPE_STRING,
53                         MM_ATTRS_FLAG_RW,
54                         (void *)"127.0.0.1",
55                         MM_ATTRS_VALID_TYPE_NONE,
56                         0,
57                         0
58                 },
59
60                 {
61                         (char *)"server_port",
62                         MM_ATTRS_TYPE_STRING,
63                         MM_ATTRS_FLAG_RW,
64                         (void *)"8554",
65                         MM_ATTRS_VALID_TYPE_NONE,
66                         0,
67                         0
68                 },
69
70                 {
71                         (char *)"max_client_count",
72                         MM_ATTRS_TYPE_INT,
73                         MM_ATTRS_FLAG_RW,
74                         (void *)1,
75                         MM_ATTRS_VALID_TYPE_INT_RANGE,
76                         0,
77                         10
78                 },
79                 /* Initialized with invalid native type, if a valid value is set then only this atribute will be considered */
80                 {
81                         (char *)"native_resolution",
82                         MM_ATTRS_TYPE_INT,
83                         MM_ATTRS_FLAG_RW,
84                         (void *)0,
85                         MM_ATTRS_VALID_TYPE_INT_RANGE,
86                         0,
87                         3
88                 },
89                 /* Initialized with invalid resolution, if a valid value is set then only this atribute will be considered */
90                 {
91                         (char *)"prefered_resolutions",
92                         MM_ATTRS_TYPE_INT,
93                         MM_ATTRS_FLAG_RW,
94                         (void *)2147483647,
95                         MM_ATTRS_VALID_TYPE_INT_RANGE,
96                         0,
97                         2147483647
98                 },
99                 /* Initialized with invalid uibc option, if a valid value is set then only this atribute will be considered */
100                 {
101                         (char *)"set_hdcp",
102                         MM_ATTRS_TYPE_INT,
103                         MM_ATTRS_FLAG_RW,
104                         (void *)2,
105                         MM_ATTRS_VALID_TYPE_INT_RANGE,
106                         0,
107                         2
108                 },
109                 {
110                         (char *)"display_rotate",
111                         MM_ATTRS_TYPE_INT,
112                         MM_ATTRS_FLAG_RW,
113                         (void *)0,
114                         MM_ATTRS_VALID_TYPE_INT_RANGE,
115                         0,
116                         3
117                 },
118                 {
119                         (char *)"display_src_crop_x",
120                         MM_ATTRS_TYPE_INT,
121                         MM_ATTRS_FLAG_RW,
122                         (void *) 0,
123                         MM_ATTRS_VALID_TYPE_INT_RANGE,
124                         0,
125                         4096
126                 },
127                 {
128                         (char *)"display_src_crop_y",
129                         MM_ATTRS_TYPE_INT,
130                         MM_ATTRS_FLAG_RW,
131                         (void *) 0,
132                         MM_ATTRS_VALID_TYPE_INT_RANGE,
133                         0,
134                         4096
135                 },
136                 {
137                         (char *)"display_src_crop_width",
138                         MM_ATTRS_TYPE_INT,
139                         MM_ATTRS_FLAG_RW,
140                         (void *) 0,
141                         MM_ATTRS_VALID_TYPE_INT_RANGE,
142                         0,
143                         4096
144                 },
145                 {
146                         (char *)"display_src_crop_height",
147                         MM_ATTRS_TYPE_INT,
148                         MM_ATTRS_FLAG_RW,
149                         (void *) 0,
150                         MM_ATTRS_VALID_TYPE_INT_RANGE,
151                         0,
152                         4096
153                 },
154                 {
155                         (char *)"display_roi_x",
156                         MM_ATTRS_TYPE_INT,
157                         MM_ATTRS_FLAG_RW,
158                         (void *) 0,
159                         MM_ATTRS_VALID_TYPE_INT_RANGE,
160                         0,
161                         4096
162                 },
163                 {
164                         (char *)"display_roi_y",
165                         MM_ATTRS_TYPE_INT,
166                         MM_ATTRS_FLAG_RW,
167                         (void *) 0,
168                         MM_ATTRS_VALID_TYPE_INT_RANGE,
169                         0,
170                         4096
171                 },
172                 {
173                         (char *)"display_roi_width",
174                         MM_ATTRS_TYPE_INT,
175                         MM_ATTRS_FLAG_RW,
176                         (void *) 480,
177                         MM_ATTRS_VALID_TYPE_INT_RANGE,
178                         0,
179                         4096
180                 },
181                 {
182                         (char *)"display_roi_height",
183                         MM_ATTRS_TYPE_INT,
184                         MM_ATTRS_FLAG_RW,
185                         (void *) 800,
186                         MM_ATTRS_VALID_TYPE_INT_RANGE,
187                         0,
188                         4096
189                 },
190                 {
191                         (char *)"display_roi_mode",
192                         MM_ATTRS_TYPE_INT,
193                         MM_ATTRS_FLAG_RW,
194                         (void *) MM_DISPLAY_METHOD_CUSTOM_ROI_FULL_SCREEN,
195                         MM_ATTRS_VALID_TYPE_INT_RANGE,
196                         MM_DISPLAY_METHOD_CUSTOM_ROI_FULL_SCREEN,
197                         MM_DISPLAY_METHOD_CUSTOM_ROI_LETER_BOX
198                 },
199                 {
200                         (char *)"display_rotation",
201                         MM_ATTRS_TYPE_INT,
202                         MM_ATTRS_FLAG_RW,
203                         (void *) MM_DISPLAY_ROTATION_NONE,
204                         MM_ATTRS_VALID_TYPE_INT_RANGE,
205                         MM_DISPLAY_ROTATION_NONE,
206                         MM_DISPLAY_ROTATION_270
207                 },
208                 {
209                         (char *)"display_visible",
210                         MM_ATTRS_TYPE_INT,
211                         MM_ATTRS_FLAG_RW,
212                         (void *) TRUE,
213                         MM_ATTRS_VALID_TYPE_INT_RANGE,
214                         0,
215                         1
216                 },
217                 {
218                         (char *)"display_method",
219                         MM_ATTRS_TYPE_INT,
220                         MM_ATTRS_FLAG_RW,
221                         (void *) MM_DISPLAY_METHOD_LETTER_BOX,
222                         MM_ATTRS_VALID_TYPE_INT_RANGE,
223                         MM_DISPLAY_METHOD_LETTER_BOX,
224                         MM_DISPLAY_METHOD_CUSTOM_ROI
225                 },
226                 {
227                         (char *)"display_overlay",
228                         MM_ATTRS_TYPE_DATA,
229                         MM_ATTRS_FLAG_RW,
230                         (void *) NULL,
231                         MM_ATTRS_VALID_TYPE_NONE,
232                         0,
233                         0
234                 },
235                 {
236                         (char *)"display_overlay_user_data",
237                         MM_ATTRS_TYPE_DATA,
238                         MM_ATTRS_FLAG_RW,
239                         (void *) NULL,
240                         MM_ATTRS_VALID_TYPE_NONE,
241                         0,
242                         0
243                 },
244                 {
245                         (char *)"display_zoom",
246                         MM_ATTRS_TYPE_DOUBLE,
247                         MM_ATTRS_FLAG_RW,
248                         (void *) 1,
249                         MM_ATTRS_VALID_TYPE_DOUBLE_RANGE,
250                         1.0,
251                         9.0
252                 },
253                 {
254                         (char *)"display_surface_type",
255                         MM_ATTRS_TYPE_INT,
256                         MM_ATTRS_FLAG_RW,
257                         (void *) MM_DISPLAY_SURFACE_NULL,
258                         MM_ATTRS_VALID_TYPE_INT_RANGE,
259                         MM_DISPLAY_SURFACE_X,
260                         MM_DISPLAY_SURFACE_X_EXT
261                 },
262                 {
263                         (char *)"display_width",   /* dest width of fimcconvert ouput */
264                         MM_ATTRS_TYPE_INT,
265                         MM_ATTRS_FLAG_RW,
266                         (void *) 0,
267                         MM_ATTRS_VALID_TYPE_INT_RANGE,
268                         0,
269                         4096
270                 },
271                 {
272                         (char *)"display_height",   /* dest height of fimcconvert ouput */
273                         MM_ATTRS_TYPE_INT,
274                         MM_ATTRS_FLAG_RW,
275                         (void *) 0,
276                         MM_ATTRS_VALID_TYPE_INT_RANGE,
277                         0,
278                         4096
279                 },
280                 {
281                         (char *)"display_evas_do_scaling",
282                         MM_ATTRS_TYPE_INT,
283                         MM_ATTRS_FLAG_RW,
284                         (void *) TRUE,
285                         MM_ATTRS_VALID_TYPE_INT_RANGE,
286                         FALSE,
287                         TRUE
288                 },
289                 {
290                         (char *)"display_x",
291                         MM_ATTRS_TYPE_INT,
292                         MM_ATTRS_FLAG_RW,
293                         (void *) 0,
294                         MM_ATTRS_VALID_TYPE_INT_RANGE,
295                         0,
296                         4096
297                 },
298                 {
299                         (char *)"display_y",
300                         MM_ATTRS_TYPE_INT,
301                         MM_ATTRS_FLAG_RW,
302                         (void *) 0,
303                         MM_ATTRS_VALID_TYPE_INT_RANGE,
304                         0,
305                         4096
306                 },
307                 {
308                         (char *)"hdcp_version",
309                         MM_ATTRS_TYPE_INT,
310                         MM_ATTRS_FLAG_RW,
311                         (void *) 0,
312                         MM_ATTRS_VALID_TYPE_INT_RANGE,
313                         0,
314                         2
315                 },
316                 {
317                         (char *)"hdcp_port",
318                         MM_ATTRS_TYPE_INT,
319                         MM_ATTRS_FLAG_RW,
320                         (void *) 0,
321                         MM_ATTRS_VALID_TYPE_INT_RANGE,
322                         0,
323                         2147483647
324                 },
325         };
326
327         num_of_attrs = ARRAY_SIZE(wfd_attrs);
328
329         base = (mmf_attrs_construct_info_t *)malloc(num_of_attrs * sizeof(mmf_attrs_construct_info_t));
330
331         if (!base) {
332                 debug_error("Cannot create mmwfd attribute\n");
333                 goto ERROR;
334         }
335
336         /* initialize values of attributes */
337         for (idx = 0; idx < num_of_attrs; idx++) {
338                 base[idx].name = wfd_attrs[idx].name;
339                 base[idx].value_type = wfd_attrs[idx].value_type;
340                 base[idx].flags = wfd_attrs[idx].flags;
341                 base[idx].default_value = wfd_attrs[idx].default_value;
342         }
343
344         attrs = mmf_attrs_new_from_data(
345                     "mmwfd_attrs",
346                     base,
347                     num_of_attrs,
348                     NULL,
349                     NULL);
350
351         if (base) {
352                 g_free(base);
353                 base = NULL;
354         }
355
356         if (!attrs) {
357                 debug_error("Cannot create mmwfd attribute\n");
358                 goto ERROR;
359         }
360
361         /* set validity type and range */
362         for (idx = 0; idx < num_of_attrs; idx++) {
363                 switch (wfd_attrs[idx].valid_type) {
364                         case MM_ATTRS_VALID_TYPE_INT_RANGE: {
365                                         mmf_attrs_set_valid_type(attrs, idx, MM_ATTRS_VALID_TYPE_INT_RANGE);
366                                         mmf_attrs_set_valid_range(attrs, idx,
367                                                                   wfd_attrs[idx].value_min,
368                                                                   wfd_attrs[idx].value_max,
369                                                                   (int)wfd_attrs[idx].default_value);
370                                 }
371                                 break;
372
373                         case MM_ATTRS_VALID_TYPE_INT_ARRAY:
374                         case MM_ATTRS_VALID_TYPE_DOUBLE_ARRAY:
375                         case MM_ATTRS_VALID_TYPE_DOUBLE_RANGE:
376                         default:
377                                 break;
378                 }
379         }
380
381         debug_fleave();
382
383         return attrs;
384
385 ERROR:
386         _mmwfd_deconstruct_attribute(attrs);
387
388         return (MMHandleType)NULL;
389 }
390
391 void
392 _mmwfd_deconstruct_attribute(MMHandleType handle)
393 {
394         debug_fenter();
395
396         return_if_fail(handle);
397
398         if (handle)
399                 mmf_attrs_free(handle);
400
401         debug_fleave();
402 }
403
404 int
405 _mmwfd_get_attribute(MMHandleType handle,  char **err_attr_name, const char *attribute_name, va_list args_list)
406 {
407         int result = MM_ERROR_NONE;
408         MMHandleType attrs = 0;
409
410         debug_fenter();
411
412         /* NOTE : Don't need to check err_attr_name because it can be set NULL */
413         /* if it's not want to know it. */
414         return_val_if_fail(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
415         return_val_if_fail(handle, MM_ERROR_COMMON_INVALID_ARGUMENT);
416
417         attrs = handle;
418
419         return_val_if_fail(attrs, MM_ERROR_COMMON_INVALID_ARGUMENT);
420
421         result = mm_attrs_get_valist(attrs, err_attr_name, attribute_name, args_list);
422
423         if (result != MM_ERROR_NONE)
424                 debug_error("failed to get %s attribute\n", attribute_name);
425
426         debug_fleave();
427
428         return result;
429 }
430
431 int
432 _mmwfd_set_attribute(MMHandleType handle,  char **err_attr_name, const char *attribute_name, va_list args_list)
433 {
434         int result = MM_ERROR_NONE;
435         MMHandleType attrs = 0;
436
437         debug_fenter();
438
439         /* NOTE : Don't need to check err_attr_name because it can be set NULL */
440         /* if it's not want to know it. */
441         return_val_if_fail(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
442         return_val_if_fail(handle, MM_ERROR_COMMON_INVALID_ARGUMENT);
443
444         attrs = handle;
445
446         return_val_if_fail(attrs, MM_ERROR_COMMON_INVALID_ARGUMENT);
447
448         /* set attributes and commit them */
449         result = mm_attrs_set_valist(attrs, err_attr_name, attribute_name, args_list);
450
451         if (result != MM_ERROR_NONE) {
452                 debug_error("failed to set %s attribute\n", attribute_name);
453                 return result;
454         }
455
456         /*__mmwfd_apply_attribute(handle, attribute_name); */
457
458         debug_fleave();
459
460         return result;
461 }
462
463 /* Currently not used. */
464 /*static gboolean
465 __mmwfd_apply_attribute(MMHandleType handle, const char *attribute_name)
466 {
467   MMHandleType attrs = 0;
468   mm_wfd_t* wfd = 0;
469
470   debug_fenter();
471
472   return_val_if_fail(handle, MM_ERROR_COMMON_INVALID_ARGUMENT);
473   return_val_if_fail(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
474
475   attrs = handle;
476
477   return_val_if_fail(attrs, MM_ERROR_COMMON_INVALID_ARGUMENT);
478
479   wfd = (mm_wfd_t*)handle;
480
481   // TODO: This function is not useful at this moment
482
483   debug_fleave();
484
485   return TRUE;
486 }*/
487
488 int
489 _mmwfd_get_attributes_info(MMHandleType handle,  const char *attribute_name, MMWfdAttrsInfo *dst_info)
490 {
491         int result = MM_ERROR_NONE;
492         MMHandleType attrs = 0;
493         MMAttrsInfo src_info = {0, };
494
495         debug_fenter();
496
497         return_val_if_fail(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
498         return_val_if_fail(dst_info, MM_ERROR_COMMON_INVALID_ARGUMENT);
499         return_val_if_fail(handle, MM_ERROR_COMMON_INVALID_ARGUMENT);
500
501         attrs = handle;
502
503         return_val_if_fail(attrs, MM_ERROR_COMMON_INVALID_ARGUMENT);
504
505         result = mm_attrs_get_info_by_name(attrs, attribute_name, &src_info);
506
507         if (result != MM_ERROR_NONE) {
508                 debug_error("failed to get attribute info\n");
509                 return result;
510         }
511
512         memset(dst_info, 0x00, sizeof(MMWfdAttrsInfo));
513
514         dst_info->type = src_info.type;
515         dst_info->flag = src_info.flag;
516         dst_info->validity_type = src_info.validity_type;
517
518         switch (src_info.validity_type) {
519                 case MM_ATTRS_VALID_TYPE_INT_ARRAY:
520                         dst_info->int_array.array = src_info.int_array.array;
521                         dst_info->int_array.count = src_info.int_array.count;
522                         dst_info->int_array.d_val = src_info.int_array.dval;
523                         break;
524
525                 case MM_ATTRS_VALID_TYPE_INT_RANGE:
526                         dst_info->int_range.min = src_info.int_range.min;
527                         dst_info->int_range.max = src_info.int_range.max;
528                         dst_info->int_range.d_val = src_info.int_range.dval;
529                         break;
530
531                 case MM_ATTRS_VALID_TYPE_DOUBLE_ARRAY:
532                         dst_info->double_array.array = src_info.double_array.array;
533                         dst_info->double_array.count = src_info.double_array.count;
534                         dst_info->double_array.d_val = src_info.double_array.dval;
535                         break;
536
537                 case MM_ATTRS_VALID_TYPE_DOUBLE_RANGE:
538                         dst_info->double_range.min = src_info.double_range.min;
539                         dst_info->double_range.max = src_info.double_range.max;
540                         dst_info->double_range.d_val = src_info.double_range.dval;
541                         break;
542
543                 default:
544                         break;
545         }
546
547         debug_fleave();
548
549         return result;
550 }
551
552