Initial release
[adaptation/ap_samsung/gst-plugins-s5pc2xx.git] / camerasrc / src / gstcamerasrccontrol.c
1 /*
2  * camerasrc
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Jeongmo Yang <jm80.yang@samsung.com>
7  *
8  * This library is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU Lesser General Public License as published by the
10  * Free Software Foundation; either version 2.1 of the License, or (at your option)
11  * any later version.
12  *
13  * This library is distributed in the hope that it will be useful, but WITHOUT ANY
14  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
15  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16  * License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this library; if not, write to the Free Software Foundation, Inc., 51
20  * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  *
22  */
23
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27
28 #include <gst/gst.h>
29 #include "gstcamerasrccontrol.h"
30 #include "camerasrc-common.h"
31
32 #define gst_camerasrc_debug(fmt, args...)       GST_INFO(fmt, ##args)
33
34 #define CAMERA_CONTROL_AF_STOP_TOTALTIME        2000000
35 #define CAMERA_CONTROL_AF_STOP_INTERVAL         20000
36
37 GST_BOILERPLATE (GstCamerasrcControlChannel,
38     gst_camerasrc_control_channel,
39     GstCameraControlChannel, GST_TYPE_CAMERA_CONTROL_CHANNEL);
40
41
42 static void
43 gst_camerasrc_control_channel_base_init( gpointer g_class )
44 {
45         gst_camerasrc_debug( "" );
46 }
47
48 static void
49 gst_camerasrc_control_channel_class_init( GstCamerasrcControlChannelClass* klass )
50 {
51         gst_camerasrc_debug( "" );
52 }
53
54 static void
55 gst_camerasrc_control_channel_init( GstCamerasrcControlChannel* control_channel, GstCamerasrcControlChannelClass* klass )
56 {
57         gst_camerasrc_debug( "" );
58         
59         control_channel->id = (guint32) - 1;
60 }
61
62 static G_GNUC_UNUSED gboolean
63 gst_camerasrc_control_contains_channel( GstCameraSrc* camerasrc, GstCamerasrcControlChannel* camerasrc_control_channel )
64 {
65         gst_camerasrc_debug( "" );
66         
67         const GList* item;
68
69         for( item = camerasrc->camera_controls ; item != NULL ; item = item->next )
70         {
71                 if( item->data == camerasrc_control_channel )
72                 {
73                         return TRUE;
74                 }
75         }
76
77         return FALSE;
78 }
79
80 const GList*
81 gst_camerasrc_control_list_channels( GstCameraSrc* camerasrc )
82 {
83         gst_camerasrc_debug( "" );
84         
85         return camerasrc->camera_controls;
86 }
87
88 gboolean
89 gst_camerasrc_control_set_value( GstCameraSrc* camerasrc, GstCameraControlChannel *control_channel, gint value )
90 {
91         gst_camerasrc_debug( "" );
92         
93         int error = CAMERASRC_ERROR;
94         
95         GstCamerasrcControlChannel *camerasrc_control_channel = GST_CAMERASRC_CONTROL_CHANNEL( control_channel );
96
97         g_return_val_if_fail( camerasrc, FALSE );
98         g_return_val_if_fail( gst_camerasrc_control_contains_channel( camerasrc, camerasrc_control_channel ), FALSE );
99
100         error = camerasrc_set_control( camerasrc->v4l2_handle, camerasrc_control_channel->id, value );
101
102         if( error != CAMERASRC_SUCCESS )
103         {
104                 gst_camerasrc_debug( "Failed to set value. Ctrl-id [%d], value [%d], err code [%d]", camerasrc_control_channel->id, value, error );
105                 return FALSE;
106         }
107
108         return TRUE;
109 }
110
111 gboolean
112 gst_camerasrc_control_get_value( GstCameraSrc* camerasrc, GstCameraControlChannel *control_channel, gint *value )
113 {
114         gst_camerasrc_debug( "" );
115         
116         int error = CAMERASRC_ERROR;
117         
118         GstCamerasrcControlChannel *camerasrc_control_channel = GST_CAMERASRC_CONTROL_CHANNEL( control_channel );
119
120         g_return_val_if_fail( camerasrc, FALSE );
121         g_return_val_if_fail( gst_camerasrc_control_contains_channel( camerasrc, camerasrc_control_channel ), FALSE );
122
123         error = camerasrc_get_control( camerasrc->v4l2_handle, camerasrc_control_channel->id, value );
124
125         if( error != CAMERASRC_SUCCESS )
126         {
127                 gst_camerasrc_debug( "Failed to get control value. Ctrl-id [%d], err code[%x]", camerasrc_control_channel->id, error );
128                 return FALSE;
129         }
130
131         return TRUE;
132 }
133
134 gboolean
135 gst_camerasrc_control_set_exposure( GstCameraSrc* camerasrc, gint type, gint value1, gint value2 )
136 {
137         gst_camerasrc_debug( "" );
138         
139         int error = CAMERASRC_ERROR;
140         camerasrc_frac_t frac;
141         
142         g_return_val_if_fail( camerasrc, FALSE );
143
144         /* TODO : F number */
145         switch( type )
146         {
147                 case GST_CAMERA_CONTROL_F_NUMBER:
148                         error = CAMERASRC_SUCCESS;
149                         break;
150                 case GST_CAMERA_CONTROL_SHUTTER_SPEED:
151                         frac.numerator = value1;
152                         frac.denominator = value2;
153                         __ta__("                camerasrc_set_shutter_speed",  
154                         error = camerasrc_set_shutter_speed( camerasrc->v4l2_handle, frac );
155                         )
156                         break;
157                 case GST_CAMERA_CONTROL_ISO:
158                         __ta__("                camerasrc_set_iso_value",  
159                         error = camerasrc_set_control( camerasrc->v4l2_handle, CAMERASRC_CTRL_ISO, value1 );
160                         )
161                         break;
162                 case GST_CAMERA_CONTROL_PROGRAM_MODE:
163                         __ta__("                camerasrc_set_control",  
164                         error = camerasrc_set_control( camerasrc->v4l2_handle, CAMERASRC_CTRL_PROGRAM_MODE, value1 );
165                         )
166                         break;
167                 case GST_CAMERA_CONTROL_EXPOSURE_MODE:
168                         __ta__("                camerasrc_set_exposure_mode",  
169                         error = camerasrc_set_control( camerasrc->v4l2_handle, CAMERASRC_CTRL_PHOTOMETRY, value1 );
170                         )
171                         break;
172                 case GST_CAMERA_CONTROL_EXPOSURE_VALUE:
173                         frac.numerator = value1;
174                         frac.denominator = value2;              
175                         __ta__("                camerasrc_set_exposure_value",  
176                         error = camerasrc_set_exposure_value( camerasrc->v4l2_handle, frac );
177                         )
178                         break;
179                 default:
180                         gst_camerasrc_debug( "Not supported type." );
181                         return FALSE;
182         }
183
184         if( error != CAMERASRC_SUCCESS )
185         {
186                 gst_camerasrc_debug( "Failed to set exposure. Type[%d],value1[%d],value2[%d],err code[%x]", type, value1, value2, error );
187                 return FALSE;
188         }
189
190         return TRUE;
191 }
192
193 gboolean
194 gst_camerasrc_control_get_exposure( GstCameraSrc* camerasrc, gint type, gint* value1, gint* value2 )
195 {
196         gst_camerasrc_debug( "" );
197         
198         int error = CAMERASRC_ERROR;
199         camerasrc_frac_t frac;
200         
201         g_return_val_if_fail( camerasrc, FALSE );
202
203         /* TODO : F number */
204         switch( type )
205         {
206                 case GST_CAMERA_CONTROL_F_NUMBER:
207                         break;
208                 case GST_CAMERA_CONTROL_SHUTTER_SPEED:
209                         error = camerasrc_get_shutter_speed( camerasrc->v4l2_handle, &frac );
210                         if( error == CAMERASRC_SUCCESS )
211                         {
212                                 *value1 = frac.numerator;
213                                 *value2 = frac.denominator;
214                         }
215                         break;
216                 case GST_CAMERA_CONTROL_ISO:
217                         error = camerasrc_get_control( camerasrc->v4l2_handle, CAMERASRC_CTRL_ISO, value1 );
218                         break;
219                 case GST_CAMERA_CONTROL_PROGRAM_MODE:
220                         error = camerasrc_get_control( camerasrc->v4l2_handle, CAMERASRC_CTRL_PROGRAM_MODE, value1 );
221                         break;
222                 case GST_CAMERA_CONTROL_EXPOSURE_MODE:
223                         error = camerasrc_get_control( camerasrc->v4l2_handle, CAMERASRC_CTRL_PHOTOMETRY, value1 );
224                         break;
225                 case GST_CAMERA_CONTROL_EXPOSURE_VALUE:
226                         error = camerasrc_get_exposure_value( camerasrc->v4l2_handle, &frac );
227                         if( error == CAMERASRC_SUCCESS )
228                         {
229                                 *value1 = frac.numerator;
230                                 *value2 = frac.denominator;
231                         }
232                         break;
233                 default:
234                         gst_camerasrc_debug( "Not supported type." );
235                         return FALSE;
236         }
237
238         if( error != CAMERASRC_SUCCESS )
239         {
240                 gst_camerasrc_debug( "Failed to get exposure. Type [%d]", type );
241                 return FALSE;
242         }
243
244         return TRUE;
245 }
246
247 gboolean
248 gst_camerasrc_control_set_capture_mode( GstCameraSrc* camerasrc, gint type, gint value )
249 {
250         /* TODO : single/multishot select(capture mode), output mode, frame count, JPEG quality */
251
252         gst_camerasrc_debug( "" );
253
254         int error = CAMERASRC_ERROR;
255
256         g_return_val_if_fail( camerasrc, FALSE );
257
258         switch( type )
259         {
260                 case GST_CAMERA_CONTROL_CAPTURE_MODE:
261                         break;
262                 case GST_CAMERA_CONTROL_OUTPUT_MODE:
263                         break;
264                 case GST_CAMERA_CONTROL_FRAME_COUNT:
265                         break;
266                 case GST_CAMERA_CONTROL_JPEG_QUALITY:
267                         break;
268                 default:
269                         gst_camerasrc_debug( "Not supported type." );
270                         return FALSE;
271         }
272
273         if( error != CAMERASRC_SUCCESS )
274         {
275                 gst_camerasrc_debug( "Failed to set capture mode. Type[%d],value[%d],err code[%x]", type, value, error );
276                 return FALSE;
277         }
278
279         return TRUE;
280 }
281
282 gboolean
283 gst_camerasrc_control_get_capture_mode( GstCameraSrc* camerasrc, gint type, gint *value )
284 {
285         /* TODO : single/multishot select(capture mode), output mode, frame count, JPEG quality */
286
287         gst_camerasrc_debug( "" );
288
289         int error = CAMERASRC_ERROR;
290
291         g_return_val_if_fail( camerasrc, FALSE );
292
293         switch( type )
294         {
295                 case GST_CAMERA_CONTROL_CAPTURE_MODE:
296                         break;
297                 case GST_CAMERA_CONTROL_OUTPUT_MODE:
298                         break;
299                 case GST_CAMERA_CONTROL_FRAME_COUNT:
300                         break;
301                 case GST_CAMERA_CONTROL_JPEG_QUALITY:
302                         break;
303                 default:
304                         gst_camerasrc_debug( "Not supported type." );
305                         return FALSE;
306         }
307
308         if( error != CAMERASRC_SUCCESS )
309         {
310                 gst_camerasrc_debug( "Failed to set capture mode. Type[%d],value[%d],err code[%x]", type, value, error );
311                 return FALSE;
312         }
313
314         return TRUE;
315 }
316
317 gboolean
318 gst_camerasrc_control_set_strobe( GstCameraSrc* camerasrc, gint type, gint value )
319 {
320         gst_camerasrc_debug( "" );
321
322         int error = CAMERASRC_ERROR;
323
324         g_return_val_if_fail( camerasrc, FALSE );
325
326         switch( type )
327         {
328                 case GST_CAMERA_CONTROL_STROBE_MODE:
329                         error = camerasrc_set_strobe_mode( camerasrc->v4l2_handle, value );
330                         break;
331                 case GST_CAMERA_CONTROL_STROBE_CONTROL:
332                 case GST_CAMERA_CONTROL_STROBE_CAPABILITIES:
333                 case GST_CAMERA_CONTROL_STROBE_STATUS:
334                 case GST_CAMERA_CONTROL_STROBE_EV:
335                 default:
336                         gst_camerasrc_debug( "Not supported type[%d], return CAMERASRC_ERR_DEVICE_NOT_SUPPORT.", type );
337                         error = CAMERASRC_ERR_DEVICE_NOT_SUPPORT;
338                         break;
339         }
340
341         if( error != CAMERASRC_SUCCESS )
342         {
343                 gst_camerasrc_debug( "Failed to set strobe. Type[%d],value[%d],err code[%x]", type, value, error );
344                 return FALSE;
345         }
346
347         gst_camerasrc_debug( "Succeed to set strobe. Type[%d],value[%d]", type, value );
348
349         return TRUE;
350 }
351
352 gboolean
353 gst_camerasrc_control_get_strobe( GstCameraSrc* camerasrc, gint type, gint* value )
354 {
355         gst_camerasrc_debug( "" );
356         
357         int error = CAMERASRC_ERROR;
358
359         g_return_val_if_fail( camerasrc, FALSE );
360
361         switch( type )
362         {
363                 case GST_CAMERA_CONTROL_STROBE_MODE:
364                         error = camerasrc_get_strobe_mode( camerasrc->v4l2_handle, (camerasrc_strobe_mode_t *)value );
365                         break;
366                 case GST_CAMERA_CONTROL_STROBE_CONTROL:
367                 case GST_CAMERA_CONTROL_STROBE_CAPABILITIES:
368                 case GST_CAMERA_CONTROL_STROBE_STATUS:
369                 case GST_CAMERA_CONTROL_STROBE_EV:
370                 default:
371                         gst_camerasrc_debug( "Not supported type[%d].", type );
372                         error = CAMERASRC_ERR_DEVICE_NOT_SUPPORT;
373                         break;
374         }
375
376         if( error != CAMERASRC_SUCCESS )
377         {
378                 gst_camerasrc_debug( "Failed to get strobe. Type[%d],err code[%x]", type, error );
379                 return FALSE;
380         }
381
382         return TRUE;
383 }
384
385 gboolean
386 gst_camerasrc_control_set_detect( GstCameraSrc* camerasrc, gint type, gint value )
387 {
388         gst_camerasrc_debug( "" );
389         
390         int error = CAMERASRC_ERROR;
391
392         g_return_val_if_fail( camerasrc, FALSE );
393
394         /* TODO : detection number, focus select, select number, detect status */
395         switch( type )
396         {
397                 case GST_CAMERA_CONTROL_FACE_DETECT_MODE:
398                         if( value == 0 )
399                         {
400                                 error = camerasrc_stop_facedetection(camerasrc->v4l2_handle );
401                         }
402                         else if( value == 1 )
403                         {
404                                 error = camerasrc_start_facedetection(camerasrc->v4l2_handle );
405                         }
406                         break;
407                 case GST_CAMERA_CONTROL_FACE_DETECT_NUMBER:
408                         break;
409                 case GST_CAMERA_CONTROL_FACE_FOCUS_SELECT:
410                         break;
411                 case GST_CAMERA_CONTROL_FACE_SELECT_NUMBER:
412                         break;
413                 case GST_CAMERA_CONTROL_FACE_DETECT_STATUS:
414                         break;
415                 default:
416                         gst_camerasrc_debug( "Not supported type." );
417                         return FALSE;
418         }
419
420         if( error != CAMERASRC_SUCCESS )
421         {
422                 gst_camerasrc_debug( "Failed to set detect. Type[%d],value[%d],err code[%x]", type, value, error );
423                 return FALSE;
424         }
425
426         return TRUE;
427 }
428
429 gboolean
430 gst_camerasrc_control_get_detect( GstCameraSrc* camerasrc, gint type, gint *value )
431 {
432         gst_camerasrc_debug( "" );
433
434         int error = CAMERASRC_ERROR;
435
436         g_return_val_if_fail( camerasrc, FALSE );
437         
438         /* TODO : detection number, focus select, select number, detect status */
439         switch( type )
440         {
441                 case GST_CAMERA_CONTROL_FACE_DETECT_MODE:
442                         error = camerasrc_get_facedetection(camerasrc->v4l2_handle, value);
443                         break;
444                 case GST_CAMERA_CONTROL_FACE_DETECT_NUMBER:
445                         break;
446                 case GST_CAMERA_CONTROL_FACE_FOCUS_SELECT:
447                         break;
448                 case GST_CAMERA_CONTROL_FACE_SELECT_NUMBER:
449                         break;
450                 case GST_CAMERA_CONTROL_FACE_DETECT_STATUS:
451                         break;
452                 default:
453                         gst_camerasrc_debug( "Not supported type." );
454                         return FALSE;
455         }
456         
457         if( error != CAMERASRC_SUCCESS )
458         {
459                 gst_camerasrc_debug( "Failed to get detect. Type[%d],err code[%x]", type, error );
460                 return FALSE;
461         }
462
463         return TRUE;
464 }
465
466 gboolean
467 gst_camerasrc_control_set_zoom( GstCameraSrc* camerasrc, gint type, gint value )
468 {
469         gst_camerasrc_debug( "" );
470         
471         int error = CAMERASRC_ERROR;
472
473         g_return_val_if_fail( camerasrc, FALSE );
474
475         switch( type )
476         {
477                 case GST_CAMERA_CONTROL_DIGITAL_ZOOM:
478                         error = camerasrc_set_control (camerasrc->v4l2_handle, CAMERASRC_CTRL_DIGITAL_ZOOM, value );
479                         break;
480                 case GST_CAMERA_CONTROL_OPTICAL_ZOOM:
481                         error = camerasrc_set_control (camerasrc->v4l2_handle, CAMERASRC_CTRL_OPTICAL_ZOOM, value );
482                         break;
483                 default:
484                         gst_camerasrc_debug( "Not supported type." );
485                         return FALSE;
486         }
487
488         if( error != CAMERASRC_SUCCESS )
489         {
490                 gst_camerasrc_debug( "Failed to set zoom. Type[%d],value[%d],err code[%x]", type, value, error );
491                 return FALSE;
492         }
493
494         return TRUE;
495 }
496
497 gboolean
498 gst_camerasrc_control_get_zoom( GstCameraSrc* camerasrc, gint type, gint *value )
499 {
500         gst_camerasrc_debug( "" );
501         
502         int error = CAMERASRC_ERROR;
503
504         g_return_val_if_fail( camerasrc, FALSE );
505
506         switch( type )
507         {
508                 case GST_CAMERA_CONTROL_DIGITAL_ZOOM:
509                         error = camerasrc_get_control (camerasrc->v4l2_handle, CAMERASRC_CTRL_DIGITAL_ZOOM, value );
510                         break;
511                 case GST_CAMERA_CONTROL_OPTICAL_ZOOM:
512                         error = camerasrc_get_control (camerasrc->v4l2_handle, CAMERASRC_CTRL_OPTICAL_ZOOM, value );
513                         break;
514                 default:
515                         gst_camerasrc_debug( "Not supported type." );
516                         return FALSE;
517         }
518
519         if( error != CAMERASRC_SUCCESS )
520         {
521                 gst_camerasrc_debug( "Failed to get zoom. Type[%d],err code[%x]", type, error );
522                 return FALSE;
523         }
524
525         return TRUE;
526 }
527
528 gboolean
529 gst_camerasrc_control_set_focus( GstCameraSrc* camerasrc, gint focus_mode, gint focus_range )
530 {
531         gst_camerasrc_debug( "" );
532
533         int error = CAMERASRC_ERROR;
534
535         g_return_val_if_fail( camerasrc, FALSE );
536
537         error = camerasrc_init_autofocusing_mode( camerasrc->v4l2_handle, focus_mode, focus_range );
538
539         if( error != CAMERASRC_SUCCESS )
540         {
541                 gst_camerasrc_debug( "Failed to set AF mode." );
542                 return FALSE;
543         }
544
545         return TRUE;
546 }
547
548 gboolean
549 gst_camerasrc_control_get_focus( GstCameraSrc* camerasrc, gint *focus_mode, gint *focus_range )
550 {
551         gst_camerasrc_debug( "" );
552
553         int error = CAMERASRC_ERROR;
554
555         g_return_val_if_fail( camerasrc, FALSE );
556
557         error = camerasrc_get_autofocusing_mode(camerasrc->v4l2_handle, (camerasrc_af_mode_t *)focus_mode, (camerasrc_af_scan_range_t *)focus_range);
558
559         if( error != CAMERASRC_SUCCESS )
560         {
561                 gst_camerasrc_debug( "Failed to get AF mode." );
562                 return FALSE;
563         }
564
565         return TRUE;
566 }
567
568 gboolean
569 gst_camerasrc_control_start_auto_focus( GstCameraSrc* camerasrc )
570 {
571         gst_camerasrc_debug( "" );
572         
573         int error = CAMERASRC_ERROR;
574
575         g_return_val_if_fail( camerasrc, FALSE );
576
577         MMTA_ACUM_ITEM_BEGIN( "AutoFocus operating time", FALSE );
578
579         error = camerasrc_start_autofocusing( camerasrc->v4l2_handle );
580
581         if( error != CAMERASRC_SUCCESS )
582         {
583                 gst_camerasrc_debug( "Failed to start AF. error[%x]", error );
584                 return FALSE;
585         }
586         else
587         {
588                 gst_camerasrc_debug( "Succeeded to start AF." );
589                 return TRUE;
590         }
591 }
592
593 gboolean
594 gst_camerasrc_control_stop_auto_focus( GstCameraSrc* camerasrc )
595 {
596         gst_camerasrc_debug( "" );
597         
598         int error = CAMERASRC_ERROR;
599         int try_count = 0;
600         camerasrc_auto_focus_status_t af_status = CAMERASRC_AUTO_FOCUS_STATUS_RELEASED;
601
602         g_return_val_if_fail( camerasrc, FALSE );
603
604         error = camerasrc_stop_autofocusing( camerasrc->v4l2_handle );
605         if( error != CAMERASRC_SUCCESS )
606         {
607                 gst_camerasrc_debug( "Failed to stop autofocus." );
608                 return FALSE;
609         }
610
611         while( try_count++ < CAMERA_CONTROL_AF_STOP_TOTALTIME/CAMERA_CONTROL_AF_STOP_INTERVAL )
612         {
613                 error = camerasrc_get_autofocusing_status( camerasrc->v4l2_handle, &af_status );
614                 if( error != CAMERASRC_SUCCESS )
615                 {
616                         gst_camerasrc_debug( "Failed to get af status.(%x)", error );
617                         return FALSE;
618                 }
619
620                 if( af_status == CAMERASRC_AUTO_FOCUS_STATUS_RELEASED )
621                 {
622                         gst_camerasrc_debug( "AF Stop done. try count[%d]", try_count );
623                         break;
624                 }
625
626                 usleep( CAMERA_CONTROL_AF_STOP_INTERVAL );
627         }
628
629         return TRUE;
630 }
631
632 gboolean
633 gst_camerasrc_control_set_focus_level( GstCameraSrc* camerasrc, gint focus_level )
634 {
635         /* TODO : */
636
637         gst_camerasrc_debug( "Not support" );
638         return FALSE;
639 }
640
641 gboolean
642 gst_camerasrc_control_get_focus_level( GstCameraSrc* camerasrc, gint *focus_level )
643 {
644         /* TODO : */
645
646         gst_camerasrc_debug( "Not support" );
647         return FALSE;
648 }
649
650 gboolean
651 gst_camerasrc_control_set_auto_focus_area( GstCameraSrc* camerasrc, GstCameraControlRectType rect )
652 {
653         gst_camerasrc_debug( "" );
654         
655         int error = CAMERASRC_ERROR;
656         camerasrc_rect_t camerasrc_rect = { 0, 0, 0, 0 };
657
658         g_return_val_if_fail( camerasrc, FALSE );
659
660         if (camerasrc->camera_id == CAMERASRC_DEV_ID_SECONDARY) {
661                 GST_INFO_OBJECT(camerasrc, "It's secondary camera. Skip setting...");
662                 return TRUE;
663         }
664
665         camerasrc_rect.x = rect.x;
666         camerasrc_rect.y = rect.y;
667         camerasrc_rect.width = rect.width;
668         camerasrc_rect.height = rect.height;
669
670         GST_INFO_OBJECT(camerasrc, "Set AF area %d,%d,%dx%d",
671                                    camerasrc_rect.x, camerasrc_rect.y,
672                                    camerasrc_rect.width, camerasrc_rect.height);
673
674         error = camerasrc_set_autofocusing_area( camerasrc->v4l2_handle, &camerasrc_rect );
675
676         if( error != CAMERASRC_SUCCESS )
677         {
678                 GST_ERROR_OBJECT(camerasrc, "Failed to set auto focus area.");
679                 return FALSE;
680         }
681
682         return TRUE;
683 }
684
685 gboolean
686 gst_camerasrc_control_get_auto_focus_area( GstCameraSrc* camerasrc, GstCameraControlRectType* rect )
687 {
688         gst_camerasrc_debug( "" );
689         
690         int error = CAMERASRC_ERROR;
691         camerasrc_rect_t camerasrc_rect = { 0, 0, 0, 0 };
692
693         g_return_val_if_fail( camerasrc, FALSE );
694         g_return_val_if_fail( rect, FALSE );
695         
696         error = camerasrc_get_autofocusing_area( camerasrc->v4l2_handle, &camerasrc_rect );
697
698         if( error != CAMERASRC_SUCCESS )
699         {
700                 gst_camerasrc_debug( "Failed to get auto focus area." );
701                 
702                 rect->x = rect->y = -1;
703                 rect->width = rect->height = -1;
704
705                 return FALSE;
706         }
707
708         rect->x = camerasrc_rect.x;
709         rect->y = camerasrc_rect.y;
710         rect->width = camerasrc_rect.width;
711         rect->height = camerasrc_rect.height;
712
713         return TRUE;
714 }
715
716 gboolean
717 gst_camerasrc_control_set_wdr( GstCameraSrc* camerasrc, gint value )
718 {
719         gst_camerasrc_debug( "" );
720         
721         int error = CAMERASRC_ERROR;
722
723         g_return_val_if_fail( camerasrc, FALSE );
724
725         error = camerasrc_set_control (camerasrc->v4l2_handle, CAMERASRC_CTRL_WIDE_DYNAMIC_RANGE, value );
726
727         if( error != CAMERASRC_SUCCESS )
728         {
729                 gst_camerasrc_debug( "Failed to set wdr. value[%d],err code[%x]", value, error );
730                 return FALSE;
731         }
732         
733         return TRUE;
734 }
735
736 gboolean
737 gst_camerasrc_control_get_wdr( GstCameraSrc* camerasrc, gint* value )
738 {
739         gst_camerasrc_debug( "" );
740         
741         int error = CAMERASRC_ERROR;
742
743         g_return_val_if_fail( camerasrc, FALSE );
744
745         error = camerasrc_get_control (camerasrc->v4l2_handle, CAMERASRC_CTRL_WIDE_DYNAMIC_RANGE, value );
746
747         if( error != CAMERASRC_SUCCESS )
748         {
749                 gst_camerasrc_debug( "Failed to get wdr. err code[%x]", error );
750                 return FALSE;
751         }
752         
753         return TRUE;
754 }
755
756 gboolean
757 gst_camerasrc_control_set_ahs( GstCameraSrc* camerasrc, gint value )
758 {
759         gst_camerasrc_debug( "" );
760         
761         int error = CAMERASRC_ERROR;
762
763         g_return_val_if_fail( camerasrc, FALSE );
764
765         error = camerasrc_set_control (camerasrc->v4l2_handle, CAMERASRC_CTRL_ANTI_HANDSHAKE, value );
766
767         if( error != CAMERASRC_SUCCESS )
768         {
769                 gst_camerasrc_debug( "Failed to set ahs. value[%d],err code[%x]", value, error );
770                 return FALSE;
771         }
772         
773         return TRUE;
774 }
775
776 gboolean
777 gst_camerasrc_control_get_ahs( GstCameraSrc* camerasrc, gint* value )
778 {
779         gst_camerasrc_debug( "" );
780         
781         int error = CAMERASRC_ERROR;
782
783         g_return_val_if_fail( camerasrc, FALSE );
784
785         error = camerasrc_get_control (camerasrc->v4l2_handle, CAMERASRC_CTRL_ANTI_HANDSHAKE, value );
786
787         if( error != CAMERASRC_SUCCESS )
788         {
789                 gst_camerasrc_debug( "Failed to get ahs. err code[%x]", error );
790                 return FALSE;
791         }
792         
793         return TRUE;
794 }
795
796 gboolean
797 gst_camerasrc_control_set_part_color( GstCameraSrc* camerasrc, gint type, gint value )
798 {
799         gst_camerasrc_debug( "" );
800         
801         int error = CAMERASRC_ERROR;
802
803         g_return_val_if_fail( camerasrc, FALSE );
804
805         switch( type )
806         {
807                 case GST_CAMERA_CONTROL_PART_COLOR_SRC:
808                         error = camerasrc_set_control( camerasrc->v4l2_handle, CAMERASRC_CTRL_PARTCOLOR_SRC, value );
809                         break;
810                 case GST_CAMERA_CONTROL_PART_COLOR_DST:
811                         error = camerasrc_set_control( camerasrc->v4l2_handle, CAMERASRC_CTRL_PARTCOLOR_DST, value );
812                         break;
813                 case GST_CAMERA_CONTROL_PART_COLOR_MODE:
814                         error = camerasrc_set_control( camerasrc->v4l2_handle, CAMERASRC_CTRL_PARTCOLOR_MODE, value );
815                         break;
816                 default:
817                         gst_camerasrc_debug( "Not supported type." );
818                         return FALSE;
819         }
820
821         if( error != CAMERASRC_SUCCESS )
822         {
823                 gst_camerasrc_debug( "Failed to set part color. Type[%d],value[%d],err code[%x]", type, value, error );
824                 return FALSE;
825         }
826         
827         return TRUE;
828 }
829
830 gboolean
831 gst_camerasrc_control_get_part_color( GstCameraSrc* camerasrc, gint type, gint* value )
832 {
833         gst_camerasrc_debug( "" );
834         
835         int error = CAMERASRC_ERROR;
836
837         g_return_val_if_fail( camerasrc, FALSE );
838
839         switch( type )
840         {
841                 case GST_CAMERA_CONTROL_PART_COLOR_SRC:
842                         error = camerasrc_get_control( camerasrc->v4l2_handle, CAMERASRC_CTRL_PARTCOLOR_SRC, value );
843                         break;
844                 case GST_CAMERA_CONTROL_PART_COLOR_DST:
845                         error = camerasrc_get_control( camerasrc->v4l2_handle, CAMERASRC_CTRL_PARTCOLOR_DST, value );
846                         break;
847                 case GST_CAMERA_CONTROL_PART_COLOR_MODE:
848                         error = camerasrc_get_control( camerasrc->v4l2_handle, CAMERASRC_CTRL_PARTCOLOR_MODE, value );
849                         break;
850                 default:
851                         gst_camerasrc_debug( "Not supported type." );
852                         return FALSE;
853         }
854
855         if( error != CAMERASRC_SUCCESS )
856         {
857                 gst_camerasrc_debug( "Failed to get part color. Type[%d],err code[%x]", type, error );
858                 return FALSE;
859         }
860         
861         return TRUE;
862 }
863
864 gboolean
865 gst_camerasrc_control_get_exif_info( GstCameraSrc* camerasrc, GstCameraControlExifInfo* info )
866 {
867         gst_camerasrc_debug( "" );
868         
869         int error = CAMERASRC_ERROR;
870         camerasrc_exif_t exif_struct;
871
872         g_return_val_if_fail( camerasrc, FALSE );
873
874         error = camerasrc_get_exif_info( camerasrc->v4l2_handle, &exif_struct );
875
876         if( error != CAMERASRC_SUCCESS )
877         {
878                 gst_camerasrc_debug( "Failed to get exif info. err code[%x]", error );
879                 return FALSE;
880         }
881
882         /* Dynamic value */
883         info->exposure_time_numerator = exif_struct.exposure_time_numerator;
884         info->exposure_time_denominator = exif_struct.exposure_time_denominator;
885         info->shutter_speed_numerator = exif_struct.shutter_speed_numerator;
886         info->shutter_speed_denominator = exif_struct.shutter_speed_denominator;
887         info->brigtness_numerator = exif_struct.brigtness_numerator;
888         info->brightness_denominator = exif_struct.brightness_denominator;
889         info->iso = exif_struct.iso;
890         info->flash = exif_struct.flash;
891         info->metering_mode = exif_struct.metering_mode;
892         info->exif_image_width = exif_struct.exif_image_width;
893         info->exif_image_height = exif_struct.exif_image_height;
894         info->software_used = exif_struct.software_used;
895         info->exposure_bias_in_APEX = exif_struct.exposure_bias_in_APEX;
896
897         /* Fixed value */
898         info->component_configuration = exif_struct.component_configuration;
899         info->colorspace = exif_struct.colorspace;
900         info->max_lens_aperture_in_APEX = exif_struct.max_lens_aperture_in_APEX;
901
902         /*FIXME*/
903         if (camerasrc->camera_id == CAMERASRC_DEV_ID_PRIMARY) {
904                 info->focal_len_numerator = CAMERASRC_PRIMARY_FOCAL_LEGNTH_NUM;
905                 info->focal_len_denominator = CAMERASRC_PRIMARY_FOCAL_LEGNTH_DENOM;
906                 info->aperture_f_num_numerator = CAMERASRC_PRIMARY_F_NUMBER_NUM;
907                 info->aperture_f_num_denominator = CAMERASRC_PRIMARY_F_NUMBER_DENOM;
908         } else {
909                 info->focal_len_numerator = CAMERASRC_SECONDARY_FOCAL_LEGNTH_NUM;
910                 info->focal_len_denominator = CAMERASRC_SECONDARY_FOCAL_LEGNTH_DENOM;
911                 info->aperture_f_num_numerator = CAMERASRC_SECONDARY_F_NUMBER_NUM;
912                 info->aperture_f_num_denominator = CAMERASRC_SECONDARY_F_NUMBER_DENOM;
913         }
914         info->aperture_in_APEX = CAMERASRC_EXIF_APERTURE_VALUE_IN_APEX(info->aperture_f_num_numerator, info->aperture_f_num_denominator);
915
916         return TRUE;
917 }
918
919 gboolean gst_camerasrc_control_get_basic_dev_info ( GstCameraSrc* camerasrc, gint dev_id, GstCameraControlCapsInfoType* info )
920 {
921         gst_camerasrc_debug( "" );
922
923         int error = CAMERASRC_ERROR;
924
925         g_return_val_if_fail( camerasrc, FALSE );
926
927         /**
928          * Just implementation issue, but at this time, we assume
929          * GstCameraControlCapsInfoType is exactly same with camerasrc_caps_info_t
930          * For performance.
931          * Here is plugin code. we can do like this?
932          */
933 #if 1
934         error = camerasrc_read_basic_dev_info(dev_id, (camerasrc_caps_info_t*)info);
935         if(error != CAMERASRC_SUCCESS)
936         {
937                 return FALSE;
938         }
939 #else
940         int i, j, k;
941         camerasrc_caps_info_t caps_info;
942
943         error = camerasrc_read_basic_dev_info(dev_id, &caps_info);
944         if(error != CAMERASRC_SUCCESS)
945         {
946                 return FALSE;
947         }
948
949         if(caps_info.num_fmt_desc != 0)
950         {
951                 info->num_fmt_desc = caps_info.num_fmt_desc;
952                 for (i=0; i<caps_info.num_fmt_desc; i++) {
953                 if(caps_info.fmt_desc[i].num_resolution != 0)
954                 {
955                         info->fmt_desc[i].fcc = caps_info.fmt_desc[i].fcc;
956                         info->fmt_desc[i].num_resolution = caps_info.fmt_desc[i].num_resolution;
957                         for (j=0; j<caps_info.fmt_desc[i].num_resolution; j++)
958                         {
959                         if(caps_info.fmt_desc[i].resolutions[j].num_avail_tpf != 0)
960                         {
961                                 info->fmt_desc[i].resolutions[j].w = caps_info.fmt_desc[i].resolutions[j].w;
962                                 info->fmt_desc[i].resolutions[j].h = caps_info.fmt_desc[i].resolutions[j].h;
963                                 info->fmt_desc[i].resolutions[j].num_avail_tpf = caps_info.fmt_desc[i].resolutions[j].num_avail_tpf;
964                                 for(k=0; k< caps_info.fmt_desc[i].resolutions[j].num_avail_tpf; k++)
965                                 {
966                                 info->fmt_desc[i].resolutions[j].tpf[k].num = caps_info.fmt_desc[i].resolutions[j].tpf[k].num;
967                                 info->fmt_desc[i].resolutions[j].tpf[k].den = caps_info.fmt_desc[i].resolutions[j].tpf[k].den;
968                                 }
969                         }
970                         else
971                         {
972                                 /* No available timeperframe */
973                                 return FALSE;
974                         }
975                         }
976                 }
977                 else
978                 {
979                         /* No available resolution set */
980                         return FALSE;
981                 }
982                 }
983         }
984         else
985         {
986                 /* No available image format(fourcc) */
987                 return FALSE;
988         }
989 #endif
990         return TRUE;
991 }
992
993 gboolean gst_camerasrc_control_get_misc_dev_info( GstCameraSrc* camerasrc, gint dev_id, GstCameraControlCtrlListInfoType * info)
994 {
995         gst_camerasrc_debug( "" );
996
997         int error = CAMERASRC_ERROR;
998
999         g_return_val_if_fail( camerasrc, FALSE );
1000
1001         /**
1002          * Just implementation issue, but at this time, we assume
1003          * GstCameraControlCtrlListInfoType is exactly same with camerasrc_ctrl_list_info_t
1004          * For performance.
1005          * Here is plugin code. we can do like this?
1006          */
1007 #if 1
1008         error = camerasrc_read_misc_dev_info(dev_id, (camerasrc_ctrl_list_info_t*)info);
1009         if(error != CAMERASRC_SUCCESS)
1010         {
1011                 return FALSE;
1012         }
1013 #else
1014         int i, j;
1015         camerasrc_ctrl_list_info_t ctrl_info;
1016
1017         error = camerasrc_read_misc_dev_info(dev_id, &ctrl_info);
1018         if(error != CAMERASRC_SUCCESS)
1019         {
1020                 return FALSE;
1021         }
1022
1023         if(ctrl_info.num_ctrl_list_info != 0)
1024         {
1025                 info->num_ctrl_list_info = ctrl_info.num_ctrl_list_info;
1026                 for(i=0; i< ctrl_info.num_ctrl_list_info; i++)
1027                 {
1028                         info->ctrl_info[i].camerasrc_ctrl_id = ctrl_info.ctrl_info[i].camerasrc_ctrl_id;
1029                         info->ctrl_info[i].v4l2_ctrl_id = ctrl_info.ctrl_info[i].v4l2_ctrl_id;
1030                         info->ctrl_info[i].ctrl_type = ctrl_info.ctrl_info[i].ctrl_type;
1031                         info->ctrl_info[i].max = ctrl_info.ctrl_info[i].max;
1032                         info->ctrl_info[i].min = ctrl_info.ctrl_info[i].min;
1033                         info->ctrl_info[i].step = ctrl_info.ctrl_info[i].step;
1034                         info->ctrl_info[i].default_val = ctrl_info.ctrl_info[i].default_val;
1035                         info->ctrl_info[i].num_ctrl_menu = ctrl_info.ctrl_info[i].num_ctrl_menu;
1036                         memcpy(info->ctrl_info[i].ctrl_name,ctrl_info.ctrl_info[i].ctrl_name,MAX_SZ_CTRL_NAME_STRING);
1037                         if(ctrl_info.ctrl_info[i].ctrl_type == CTRL_TYPE_ARRAY && ctrl_info.ctrl_info[i].num_ctrl_menu != 0)
1038                         {
1039                                 for(j=0; j<ctrl_info.ctrl_info[i].num_ctrl_menu; j++)
1040                                 {
1041                                 info->ctrl_info[i].ctrl_menu[j].menu_index = ctrl_info.ctrl_info[i].ctrl_menu[j].menu_index;
1042                                 memcpy(info->ctrl_info[i].ctrl_menu[j].menu_name, ctrl_info.ctrl_info[i].ctrl_menu[j].menu_name, MAX_SZ_CTRL_NAME_STRING);
1043                                 }
1044                         }
1045                         else
1046                         {
1047                                 /* Not a menu type or not available menus */
1048                                 return FALSE;
1049                         }
1050                 }
1051         }
1052         else
1053         {
1054                 /* Not avaliable controls */
1055                 return FALSE;
1056         }
1057 #endif
1058         return TRUE;
1059 }
1060
1061 gboolean gst_camerasrc_control_get_extra_dev_info( GstCameraSrc* camerasrc, gint dev_id, GstCameraControlExtraInfoType * info)
1062 {
1063         int error = CAMERASRC_ERROR;
1064
1065         g_return_val_if_fail( camerasrc, FALSE );
1066
1067         gst_camerasrc_debug( "" );
1068
1069         /**
1070          * Just implementation issue, but at this time, we assume
1071          * GstCameraControlCtrlListInfoType is exactly same with camerasrc_ctrl_list_info_t
1072          * For performance.
1073          * Here is plugin code. we can do like this?
1074          */
1075
1076         error = camerasrc_read_extra_dev_info(dev_id, (camerasrc_extra_info_t*)info);
1077         if(error != CAMERASRC_SUCCESS)
1078         {
1079                 return FALSE;
1080         }
1081
1082         return TRUE;
1083 }
1084
1085 void gst_camerasrc_control_set_capture_command( GstCameraSrc* camerasrc, GstCameraControlCaptureCommand cmd )
1086 {
1087         gst_camerasrc_debug( "" );
1088
1089         if( camerasrc == NULL )
1090         {
1091                 gst_camerasrc_debug( "camerasrc is NULL" );
1092                 return;
1093         }
1094
1095         gst_camerasrc_set_capture_command( camerasrc, cmd );
1096
1097         return;
1098 }