2de22532e43d901b7e41b8cdccb065a6e05e340e
[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_handle",
309                         MM_ATTRS_TYPE_DATA,
310                         MM_ATTRS_FLAG_RW,
311                         (void *) NULL,
312                         MM_ATTRS_VALID_TYPE_NONE,
313                         0,
314                         0
315                 },
316                 {
317                         (char *)"hdcp_version",
318                         MM_ATTRS_TYPE_INT,
319                         MM_ATTRS_FLAG_RW,
320                         (void *) 0,
321                         MM_ATTRS_VALID_TYPE_INT_RANGE,
322                         0,
323                         2
324                 },
325                 {
326                         (char *)"hdcp_port",
327                         MM_ATTRS_TYPE_INT,
328                         MM_ATTRS_FLAG_RW,
329                         (void *) 0,
330                         MM_ATTRS_VALID_TYPE_INT_RANGE,
331                         0,
332                         2147483647
333                 },
334         };
335
336         num_of_attrs = ARRAY_SIZE(wfd_attrs);
337
338         base = (mmf_attrs_construct_info_t *)malloc(num_of_attrs * sizeof(mmf_attrs_construct_info_t));
339
340         if (!base) {
341                 debug_error("Cannot create mmwfd attribute\n");
342                 goto ERROR;
343         }
344
345         /* initialize values of attributes */
346         for (idx = 0; idx < num_of_attrs; idx++) {
347                 base[idx].name = wfd_attrs[idx].name;
348                 base[idx].value_type = wfd_attrs[idx].value_type;
349                 base[idx].flags = wfd_attrs[idx].flags;
350                 base[idx].default_value = wfd_attrs[idx].default_value;
351         }
352
353         attrs = mmf_attrs_new_from_data(
354                     "mmwfd_attrs",
355                     base,
356                     num_of_attrs,
357                     NULL,
358                     NULL);
359
360         if (base) {
361                 g_free(base);
362                 base = NULL;
363         }
364
365         if (!attrs) {
366                 debug_error("Cannot create mmwfd attribute\n");
367                 goto ERROR;
368         }
369
370         /* set validity type and range */
371         for (idx = 0; idx < num_of_attrs; idx++) {
372                 switch (wfd_attrs[idx].valid_type) {
373                         case MM_ATTRS_VALID_TYPE_INT_RANGE: {
374                                         mmf_attrs_set_valid_type(attrs, idx, MM_ATTRS_VALID_TYPE_INT_RANGE);
375                                         mmf_attrs_set_valid_range(attrs, idx,
376                                                                   wfd_attrs[idx].value_min,
377                                                                   wfd_attrs[idx].value_max,
378                                                                   (int)wfd_attrs[idx].default_value);
379                                 }
380                                 break;
381
382                         case MM_ATTRS_VALID_TYPE_INT_ARRAY:
383                         case MM_ATTRS_VALID_TYPE_DOUBLE_ARRAY:
384                         case MM_ATTRS_VALID_TYPE_DOUBLE_RANGE:
385                         default:
386                                 break;
387                 }
388         }
389
390         debug_fleave();
391
392         return attrs;
393
394 ERROR:
395         _mmwfd_deconstruct_attribute(attrs);
396
397         return (MMHandleType)NULL;
398 }
399
400 void
401 _mmwfd_deconstruct_attribute(MMHandleType handle)
402 {
403         debug_fenter();
404
405         return_if_fail(handle);
406
407         if (handle)
408                 mmf_attrs_free(handle);
409
410         debug_fleave();
411 }
412
413 int
414 _mmwfd_get_attribute(MMHandleType handle,  char **err_attr_name, const char *attribute_name, va_list args_list)
415 {
416         int result = MM_ERROR_NONE;
417         MMHandleType attrs = 0;
418
419         debug_fenter();
420
421         /* NOTE : Don't need to check err_attr_name because it can be set NULL */
422         /* if it's not want to know it. */
423         return_val_if_fail(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
424         return_val_if_fail(handle, MM_ERROR_COMMON_INVALID_ARGUMENT);
425
426         attrs = handle;
427
428         return_val_if_fail(attrs, MM_ERROR_COMMON_INVALID_ARGUMENT);
429
430         result = mm_attrs_get_valist(attrs, err_attr_name, attribute_name, args_list);
431
432         if (result != MM_ERROR_NONE)
433                 debug_error("failed to get %s attribute\n", attribute_name);
434
435         debug_fleave();
436
437         return result;
438 }
439
440 int
441 _mmwfd_set_attribute(MMHandleType handle,  char **err_attr_name, const char *attribute_name, va_list args_list)
442 {
443         int result = MM_ERROR_NONE;
444         MMHandleType attrs = 0;
445
446         debug_fenter();
447
448         /* NOTE : Don't need to check err_attr_name because it can be set NULL */
449         /* if it's not want to know it. */
450         return_val_if_fail(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
451         return_val_if_fail(handle, MM_ERROR_COMMON_INVALID_ARGUMENT);
452
453         attrs = handle;
454
455         return_val_if_fail(attrs, MM_ERROR_COMMON_INVALID_ARGUMENT);
456
457         /* set attributes and commit them */
458         result = mm_attrs_set_valist(attrs, err_attr_name, attribute_name, args_list);
459
460         if (result != MM_ERROR_NONE) {
461                 debug_error("failed to set %s attribute\n", attribute_name);
462                 return result;
463         }
464
465         /*__mmwfd_apply_attribute(handle, attribute_name); */
466
467         debug_fleave();
468
469         return result;
470 }
471
472 /* Currently not used. */
473 /*static gboolean
474 __mmwfd_apply_attribute(MMHandleType handle, const char *attribute_name)
475 {
476   MMHandleType attrs = 0;
477   mm_wfd_t* wfd = 0;
478
479   debug_fenter();
480
481   return_val_if_fail(handle, MM_ERROR_COMMON_INVALID_ARGUMENT);
482   return_val_if_fail(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
483
484   attrs = handle;
485
486   return_val_if_fail(attrs, MM_ERROR_COMMON_INVALID_ARGUMENT);
487
488   wfd = (mm_wfd_t*)handle;
489
490   // TODO: This function is not useful at this moment
491
492   debug_fleave();
493
494   return TRUE;
495 }*/
496
497 int
498 _mmwfd_get_attributes_info(MMHandleType handle,  const char *attribute_name, MMWfdAttrsInfo *dst_info)
499 {
500         int result = MM_ERROR_NONE;
501         MMHandleType attrs = 0;
502         MMAttrsInfo src_info = {0, };
503
504         debug_fenter();
505
506         return_val_if_fail(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
507         return_val_if_fail(dst_info, MM_ERROR_COMMON_INVALID_ARGUMENT);
508         return_val_if_fail(handle, MM_ERROR_COMMON_INVALID_ARGUMENT);
509
510         attrs = handle;
511
512         return_val_if_fail(attrs, MM_ERROR_COMMON_INVALID_ARGUMENT);
513
514         result = mm_attrs_get_info_by_name(attrs, attribute_name, &src_info);
515
516         if (result != MM_ERROR_NONE) {
517                 debug_error("failed to get attribute info\n");
518                 return result;
519         }
520
521         memset(dst_info, 0x00, sizeof(MMWfdAttrsInfo));
522
523         dst_info->type = src_info.type;
524         dst_info->flag = src_info.flag;
525         dst_info->validity_type = src_info.validity_type;
526
527         switch (src_info.validity_type) {
528                 case MM_ATTRS_VALID_TYPE_INT_ARRAY:
529                         dst_info->int_array.array = src_info.int_array.array;
530                         dst_info->int_array.count = src_info.int_array.count;
531                         dst_info->int_array.d_val = src_info.int_array.dval;
532                         break;
533
534                 case MM_ATTRS_VALID_TYPE_INT_RANGE:
535                         dst_info->int_range.min = src_info.int_range.min;
536                         dst_info->int_range.max = src_info.int_range.max;
537                         dst_info->int_range.d_val = src_info.int_range.dval;
538                         break;
539
540                 case MM_ATTRS_VALID_TYPE_DOUBLE_ARRAY:
541                         dst_info->double_array.array = src_info.double_array.array;
542                         dst_info->double_array.count = src_info.double_array.count;
543                         dst_info->double_array.d_val = src_info.double_array.dval;
544                         break;
545
546                 case MM_ATTRS_VALID_TYPE_DOUBLE_RANGE:
547                         dst_info->double_range.min = src_info.double_range.min;
548                         dst_info->double_range.max = src_info.double_range.max;
549                         dst_info->double_range.d_val = src_info.double_range.dval;
550                         break;
551
552                 default:
553                         break;
554         }
555
556         debug_fleave();
557
558         return result;
559 }
560
561