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