2.0 init
[framework/api/recorder.git] / src / recorder.c
1 /*
2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17
18
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <mm.h>
23 #include <mm_camcorder.h>
24 #include <mm_types.h>
25 #include <math.h>
26 #include <camera.h>
27 #include <recorder.h>
28 #include <recorder_private.h>
29 #include <dlog.h>
30
31 #ifdef LOG_TAG
32 #undef LOG_TAG
33 #endif
34 #define LOG_TAG "TIZEN_N_RECORDER"
35
36 #define LOWSET_DECIBEL -300.0
37
38
39 /*
40  *      camera_private function
41 */
42 int _camera_get_mm_handle(camera_h camera , MMHandleType *handle);
43 int _camera_set_relay_mm_message_callback(camera_h camera, MMMessageCallback callback, void *user_data);
44 /*
45  * end of camera_private function
46  */
47
48 static int __mm_audio_stream_cb(MMCamcorderAudioStreamDataType *stream, void *user_param);
49 static int __mm_recorder_msg_cb(int message, void *param, void *user_data);
50
51
52 static int __convert_error_code_camera_to_recorder(int code){
53         int new_code = code;
54         switch(code)
55         {
56                 case CAMERA_ERROR_INVALID_STATE :
57                         new_code = RECORDER_ERROR_INVALID_STATE;
58                         break;
59                 case CAMERA_ERROR_DEVICE:
60                         new_code = RECORDER_ERROR_DEVICE;
61                         break;
62                 case CAMERA_ERROR_SOUND_POLICY:
63                         new_code = RECORDER_ERROR_SOUND_POLICY;
64                         break;
65                 case CAMERA_ERROR_SECURITY_RESTRICTED:
66                         new_code = RECORDER_ERROR_SECURITY_RESTRICTED;
67                         break;
68         }
69         return new_code;
70 }
71
72 static int __convert_recorder_error_code(const char *func, int code){
73         int ret = RECORDER_ERROR_INVALID_OPERATION;
74         char *errorstr = NULL;
75         
76         switch(code)
77         {
78                 case RECORDER_ERROR_INVALID_PARAMETER:
79                         ret = RECORDER_ERROR_INVALID_PARAMETER;
80                         errorstr = "INVALID_PARAMETER";                 
81                         break;                  
82                 case MM_ERROR_NONE:
83                         ret = RECORDER_ERROR_NONE;
84                         errorstr = "ERROR_NONE";
85                         break;
86                 case MM_ERROR_CAMCORDER_INVALID_ARGUMENT :
87                 case MM_ERROR_COMMON_INVALID_ATTRTYPE :
88                 case MM_ERROR_COMMON_INVALID_PERMISSION :
89                 case MM_ERROR_COMMON_OUT_OF_ARRAY :
90                 case MM_ERROR_COMMON_OUT_OF_RANGE :
91                 case MM_ERROR_COMMON_ATTR_NOT_EXIST :
92                         ret = RECORDER_ERROR_INVALID_PARAMETER;
93                         errorstr = "INVALID_PARAMETER";                 
94                         break;
95                 case MM_ERROR_CAMCORDER_NOT_INITIALIZED :
96                 case MM_ERROR_CAMCORDER_INVALID_STATE :
97                         ret = RECORDER_ERROR_INVALID_STATE;
98                         errorstr = "INVALID_STATE";                     
99                         break;
100
101                 case MM_ERROR_CAMCORDER_DEVICE :
102                 case MM_ERROR_CAMCORDER_DEVICE_NOT_FOUND :
103                 case MM_ERROR_CAMCORDER_DEVICE_BUSY     :
104                 case MM_ERROR_CAMCORDER_DEVICE_OPEN :
105                 case MM_ERROR_CAMCORDER_DEVICE_IO :
106                 case MM_ERROR_CAMCORDER_DEVICE_TIMEOUT  :
107                 case MM_ERROR_CAMCORDER_DEVICE_REG_TROUBLE :
108                 case MM_ERROR_CAMCORDER_DEVICE_WRONG_JPEG        :
109                 case MM_ERROR_CAMCORDER_DEVICE_LACK_BUFFER :
110                         ret = RECORDER_ERROR_DEVICE;
111                         errorstr = "ERROR_DEVICE";                      
112                         break;
113
114                 case MM_ERROR_CAMCORDER_GST_CORE :
115                 case MM_ERROR_CAMCORDER_GST_LIBRARY :
116                 case MM_ERROR_CAMCORDER_GST_RESOURCE :
117                 case MM_ERROR_CAMCORDER_GST_STREAM :
118                 case MM_ERROR_CAMCORDER_GST_STATECHANGE :
119                 case MM_ERROR_CAMCORDER_GST_NEGOTIATION :
120                 case MM_ERROR_CAMCORDER_GST_LINK :
121                 case MM_ERROR_CAMCORDER_GST_FLOW_ERROR :
122                 case MM_ERROR_CAMCORDER_ENCODER :
123                 case MM_ERROR_CAMCORDER_ENCODER_BUFFER :
124                 case MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE :
125                 case MM_ERROR_CAMCORDER_ENCODER_WORKING :
126                 case MM_ERROR_CAMCORDER_INTERNAL :
127                 case MM_ERROR_CAMCORDER_NOT_SUPPORTED :
128                 case MM_ERROR_CAMCORDER_RESPONSE_TIMEOUT :
129                 case MM_ERROR_CAMCORDER_CMD_IS_RUNNING :        
130                 case MM_ERROR_CAMCORDER_DSP_FAIL :
131                 case MM_ERROR_CAMCORDER_AUDIO_EMPTY :
132                 case MM_ERROR_CAMCORDER_CREATE_CONFIGURE :
133                 case MM_ERROR_CAMCORDER_FILE_SIZE_OVER :
134                 case MM_ERROR_CAMCORDER_DISPLAY_DEVICE_OFF :
135                 case MM_ERROR_CAMCORDER_INVALID_CONDITION :
136                         ret = RECORDER_ERROR_INVALID_OPERATION;
137                         errorstr = "INVALID_OPERATION";                 
138                         break;
139                 case MM_ERROR_CAMCORDER_RESOURCE_CREATION :
140                 case MM_ERROR_COMMON_OUT_OF_MEMORY:     
141                         ret = RECORDER_ERROR_OUT_OF_MEMORY;
142                         errorstr = "OUT_OF_MEMORY";                     
143                         break;
144
145                 case MM_ERROR_POLICY_BLOCKED:
146                         ret = RECORDER_ERROR_SOUND_POLICY;
147                         errorstr = "ERROR_SOUND_POLICY";                        
148                         break;
149
150                 case MM_ERROR_POLICY_RESTRICTED:
151                         ret = RECORDER_ERROR_SECURITY_RESTRICTED;
152                         errorstr = "ERROR_RESTRICTED";
153                         break;
154
155                 default:
156                         ret = RECORDER_ERROR_INVALID_OPERATION;
157                         errorstr = "INVALID_OPERATION";
158                 
159         }
160
161         LOGE( "[%s] %s(0x%08x) : core frameworks error code(0x%08x)",func, errorstr, ret, code);
162         
163
164         return ret;
165 }
166
167 static recorder_state_e __recorder_state_convert(MMCamcorderStateType mm_state )
168 {
169         recorder_state_e state = RECORDER_STATE_NONE;
170         switch( mm_state ){
171                 case MM_CAMCORDER_STATE_NONE:   
172                         state = RECORDER_STATE_NONE;
173                         break;
174                 case MM_CAMCORDER_STATE_NULL:
175                         state = RECORDER_STATE_CREATED;
176                         break;
177                 case MM_CAMCORDER_STATE_READY:
178                         state = RECORDER_STATE_CREATED;
179                         break;
180                 case MM_CAMCORDER_STATE_PREPARE:
181                         state = RECORDER_STATE_READY;
182                         break;
183                 case MM_CAMCORDER_STATE_CAPTURING:
184                         state = RECORDER_STATE_READY;
185                         break;
186                 case MM_CAMCORDER_STATE_RECORDING:
187                         state = RECORDER_STATE_RECORDING;
188                         break;
189                 case MM_CAMCORDER_STATE_PAUSED:
190                         state = RECORDER_STATE_PAUSED;
191                         break;
192                 default:
193                         state = RECORDER_STATE_NONE;
194                         break;
195         }
196
197         return state;
198 }
199
200 static int __mm_recorder_msg_cb(int message, void *param, void *user_data){
201         recorder_s * handle = (recorder_s*)user_data;
202         MMMessageParamType *m = (MMMessageParamType*)param;
203         recorder_state_e previous_state;
204
205         switch(message){
206                 case MM_MESSAGE_CAMCORDER_STATE_CHANGED:
207                 case MM_MESSAGE_CAMCORDER_STATE_CHANGED_BY_ASM:
208                 case MM_MESSAGE_CAMCORDER_STATE_CHANGED_BY_SECURITY:
209                                 previous_state = handle->state;
210                                 handle->state = __recorder_state_convert(m->state.current);
211                                 recorder_policy_e policy = RECORDER_POLICY_NONE;
212                                 if(message == MM_MESSAGE_CAMCORDER_STATE_CHANGED_BY_ASM )
213                                         policy = RECORDER_POLICY_SOUND;
214                                 else if( message == MM_MESSAGE_CAMCORDER_STATE_CHANGED_BY_SECURITY )
215                                         policy = RECORDER_POLICY_SECURITY;
216
217                                 if( previous_state != handle->state && handle->user_cb[_RECORDER_EVENT_TYPE_STATE_CHANGE] ){
218                                         ((recorder_state_changed_cb)handle->user_cb[_RECORDER_EVENT_TYPE_STATE_CHANGE])(previous_state, handle->state, policy , handle->user_data[_RECORDER_EVENT_TYPE_STATE_CHANGE]);
219                                 }
220                                 // should change intermediate state MM_CAMCORDER_STATE_READY is not valid in capi , change to NULL state
221                                 if( policy != RECORDER_POLICY_NONE ){
222                                         if( previous_state != handle->state && handle->user_cb[_RECORDER_EVENT_TYPE_INTERRUPTED] ){
223                                                 ((recorder_interrupted_cb)handle->user_cb[_RECORDER_EVENT_TYPE_INTERRUPTED])(policy, previous_state, handle->state, handle->user_data[_RECORDER_EVENT_TYPE_INTERRUPTED]);
224                                         }
225                                         if( m->state.previous == MM_CAMCORDER_STATE_PREPARE && m->state.current == MM_CAMCORDER_STATE_PREPARE ){
226                                                 mm_camcorder_unrealize(handle->mm_handle);
227                                         }
228                                 }
229                                 
230                                 break;
231                 case MM_MESSAGE_CAMCORDER_MAX_SIZE:
232                 case MM_MESSAGE_CAMCORDER_NO_FREE_SPACE:                        
233                 case MM_MESSAGE_CAMCORDER_TIME_LIMIT:
234                         {
235                                 recorder_recording_limit_type_e type ;
236                                 if( MM_MESSAGE_CAMCORDER_MAX_SIZE == message )
237                                         type = RECORDER_RECORDING_LIMIT_SIZE;
238                                 else if( MM_MESSAGE_CAMCORDER_NO_FREE_SPACE == message)
239                                         type = RECORDER_RECORDING_LIMIT_FREE_SPACE;
240                                 else
241                                         type = RECORDER_RECORDING_LIMIT_TIME;
242                                 if( handle->user_cb[_RECORDER_EVENT_TYPE_RECORDING_LIMITED] ){
243                                         ((recorder_recording_limit_reached_cb)handle->user_cb[_RECORDER_EVENT_TYPE_RECORDING_LIMITED])(type, handle->user_data[_RECORDER_EVENT_TYPE_RECORDING_LIMITED]);
244                                 }
245                         }                       
246                         break;
247                 case MM_MESSAGE_CAMCORDER_RECORDING_STATUS:
248                         if( handle->user_cb[_RECORDER_EVENT_TYPE_RECORDING_STATUS] ){
249                                 ((recorder_recording_status_cb)handle->user_cb[_RECORDER_EVENT_TYPE_RECORDING_STATUS])( m->recording_status.elapsed, m->recording_status.filesize, handle->user_data[_RECORDER_EVENT_TYPE_RECORDING_STATUS]);
250                         }
251                         break;
252                 case MM_MESSAGE_CAMCORDER_CAPTURED :
253                 {
254                         if( handle->type == _RECORDER_TYPE_AUDIO ){
255                                 MMCamRecordingReport *report = (MMCamRecordingReport *)m ->data;
256                                 if( report != NULL && report->recording_filename ){
257                                         free(report->recording_filename );
258                                         report->recording_filename = NULL;
259                                 }
260                                 if( report ){
261                                         free(report);
262                                         report = NULL;
263                                 }
264                         }
265                         break;
266                 }
267                 case MM_MESSAGE_CAMCORDER_ERROR:
268                 {
269                         int errorcode = m->code;
270                         int recorder_error = 0;
271                         switch( errorcode ){
272                                 case MM_ERROR_CAMCORDER_DEVICE :
273                                 case MM_ERROR_CAMCORDER_DEVICE_TIMEOUT :
274                                 case MM_ERROR_CAMCORDER_DEVICE_REG_TROUBLE :
275                                 case MM_ERROR_CAMCORDER_DEVICE_WRONG_JPEG :
276                                         recorder_error = RECORDER_ERROR_DEVICE;
277                                         break;
278                                 case MM_ERROR_CAMCORDER_GST_CORE :
279                                 case MM_ERROR_CAMCORDER_GST_LIBRARY :
280                                 case MM_ERROR_CAMCORDER_GST_RESOURCE :
281                                 case MM_ERROR_CAMCORDER_GST_STREAM :
282                                 case MM_ERROR_CAMCORDER_GST_NEGOTIATION :
283                                 case MM_ERROR_CAMCORDER_GST_FLOW_ERROR :
284                                 case MM_ERROR_CAMCORDER_ENCODER :
285                                 case MM_ERROR_CAMCORDER_ENCODER_BUFFER :
286                                 case MM_ERROR_CAMCORDER_ENCODER_WORKING :
287                                 case MM_ERROR_CAMCORDER_MNOTE_CREATION :
288                                 case MM_ERROR_CAMCORDER_MNOTE_ADD_ENTRY :
289                                 case MM_ERROR_CAMCORDER_INTERNAL :
290                                         recorder_error = RECORDER_ERROR_INVALID_OPERATION;
291                                         break;
292                                 case MM_ERROR_CAMCORDER_LOW_MEMORY :
293                                 case MM_ERROR_CAMCORDER_MNOTE_MALLOC :
294                                         recorder_error = RECORDER_ERROR_OUT_OF_MEMORY;
295                                         break;
296                         }
297                         if( recorder_error != 0 && handle->user_cb[_RECORDER_EVENT_TYPE_ERROR] )
298                                 ((recorder_error_cb)handle->user_cb[_RECORDER_EVENT_TYPE_ERROR])(errorcode, handle->state , handle->user_data[_RECORDER_EVENT_TYPE_ERROR]);
299                         break;
300                 }
301                 case MM_MESSAGE_CAMCORDER_CURRENT_VOLUME:
302                         if( handle->last_max_input_level < m->rec_volume_dB )
303                                 handle->last_max_input_level = m->rec_volume_dB;
304                         break;
305         }
306
307         return 1;
308 }
309
310 static int __mm_audio_stream_cb(MMCamcorderAudioStreamDataType *stream, void *user_param){
311         if( user_param == NULL || stream == NULL)
312                 return 0;
313
314         recorder_s * handle = (recorder_s*)user_param;
315         audio_sample_type_e format = AUDIO_SAMPLE_TYPE_U8;
316         if( stream->format == MM_CAMCORDER_AUDIO_FORMAT_PCM_S16_LE)
317                 format = AUDIO_SAMPLE_TYPE_S16_LE;
318
319         if( handle->user_cb[_RECORDER_EVENT_TYPE_AUDIO_STREAM] ){
320                 ((recorder_audio_stream_cb)(handle->user_cb[_RECORDER_EVENT_TYPE_AUDIO_STREAM]))(stream->data,
321                                                                                                                                                 stream->length,
322                                                                                                                                                 format,
323                                                                                                                                                 stream->channel,
324                                                                                                                                                 stream->timestamp,
325                                                                                                                                                 handle->user_data[_RECORDER_EVENT_TYPE_AUDIO_STREAM]);
326         }
327         return 1;
328 }
329
330
331 int recorder_create_videorecorder( camera_h camera, recorder_h* recorder){
332         
333         if( camera == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER);
334         if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); 
335
336         int ret;
337         recorder_s * handle;
338         camera_state_e camera_state;    
339         int preview_format;     
340
341         camera_get_state(camera, &camera_state);
342         //TODO. if allow compatible with video mode / image mode, it should be changed
343         if( camera_state != CAMERA_STATE_CREATED){
344                 LOGE("[%s] camera state(%d) is not CAMERA_STATE_CREATED ", __func__, camera_state);
345                 return RECORDER_ERROR_INVALID_PARAMETER;
346         }
347         
348         handle = (recorder_s*)malloc( sizeof(recorder_s) );
349         if(handle == NULL){
350                 LOGE("[%s] malloc error", __func__);
351                 return RECORDER_ERROR_OUT_OF_MEMORY;
352         }
353
354         memset(handle, 0 , sizeof(recorder_s));         
355         handle->last_max_input_level = LOWSET_DECIBEL;
356         handle->camera = camera;
357         //TODO if allow compatible with video mode / image mode, it should be changed.
358         handle->state = RECORDER_STATE_CREATED;
359         _camera_get_mm_handle(camera, &handle->mm_handle);
360         _camera_set_relay_mm_message_callback(camera, __mm_recorder_msg_cb , (void*)handle);
361
362         handle->type = _RECORDER_TYPE_VIDEO;
363         *recorder = (recorder_h)handle;
364
365         preview_format = MM_PIXEL_FORMAT_YUYV;
366         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_FORMAT, &preview_format, NULL);
367         handle->origin_preview_format = preview_format;
368         preview_format = MM_PIXEL_FORMAT_NV12;  
369         ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_RECOMMEND_PREVIEW_FORMAT_FOR_RECORDING, &preview_format, NULL);
370         
371         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
372                                                                                                                                 MMCAM_MODE , MM_CAMCORDER_MODE_VIDEO,
373                                                                                                                                 MMCAM_CAMERA_FORMAT, preview_format,
374                                                                                                                                 (void*)NULL);
375         return __convert_recorder_error_code(__func__, ret);
376         
377 }
378
379 int recorder_create_audiorecorder( recorder_h* recorder){
380         
381         if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); 
382         
383         int ret;
384         recorder_s * handle;
385         MMCamPreset info;
386         info.videodev_type= MM_VIDEO_DEVICE_NONE;
387         
388         handle = (recorder_s*)malloc( sizeof(recorder_s) );
389         if(handle==NULL){
390                 LOGE( "[%s] OUT_OF_MEMORY(0x%08x)", __func__, RECORDER_ERROR_OUT_OF_MEMORY);
391                 return RECORDER_ERROR_OUT_OF_MEMORY;
392         }
393         
394         memset(handle, 0 , sizeof(recorder_s));
395         handle->last_max_input_level = LOWSET_DECIBEL;
396         
397         ret = mm_camcorder_create(&handle->mm_handle, &info);
398         if( ret != MM_ERROR_NONE){
399                 free(handle);
400                 LOGE("[%s] mm_camcorder_create fail", __func__);
401                 return __convert_recorder_error_code(__func__, ret);
402         }
403         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
404                                                                                                                                 MMCAM_MODE , MM_CAMCORDER_MODE_AUDIO,
405                                                                                                                                 (void*)NULL);
406
407         if( ret != MM_ERROR_NONE){
408                 mm_camcorder_destroy(handle->mm_handle);
409                 free(handle);
410                 LOGE("[%s] AUDIO mode setting fail", __func__);
411                 return __convert_recorder_error_code(__func__, ret);
412         }
413
414
415         handle->state = RECORDER_STATE_CREATED;
416         mm_camcorder_set_message_callback(handle->mm_handle, __mm_recorder_msg_cb, (void*)handle);
417         handle->camera = NULL;
418         handle->type = _RECORDER_TYPE_AUDIO;
419
420         *recorder = (recorder_h)handle;
421
422         return RECORDER_ERROR_NONE;
423
424 }
425
426
427 int recorder_get_state(recorder_h recorder, recorder_state_e * state){
428         
429         if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); 
430         if( state == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER);    
431
432         recorder_s *handle = (recorder_s*)recorder;
433
434         MMCamcorderStateType mmstate ;
435         recorder_state_e capi_state;
436         mm_camcorder_get_state(handle->mm_handle, &mmstate);    
437         capi_state = __recorder_state_convert(mmstate);
438
439         *state = capi_state;
440         return CAMERA_ERROR_NONE;
441         
442 }
443
444 int recorder_destroy( recorder_h recorder){
445         
446         if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); 
447         recorder_s * handle;
448         int ret;
449
450         handle = (recorder_s *) recorder;
451         if( handle->type == _RECORDER_TYPE_VIDEO ){
452                 //camera object mode change
453                 ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
454                                                                                                                                 MMCAM_MODE , MM_CAMCORDER_MODE_IMAGE,
455                                                                                                                                 MMCAM_CAMERA_FORMAT,  handle->origin_preview_format,
456                                                                                                                                 MMCAM_IMAGE_ENCODER , MM_IMAGE_CODEC_JPEG,
457                                                                                                                                 MMCAM_CAPTURE_FORMAT, MM_PIXEL_FORMAT_ENCODED,
458                                                                                                                                 MMCAM_CAPTURE_COUNT, 1,
459                                                                                                                                 (void*)NULL);
460                 _camera_set_relay_mm_message_callback(handle->camera , NULL, NULL);
461         }else{
462                 ret = mm_camcorder_destroy(handle->mm_handle);
463         }
464
465         if(ret == MM_ERROR_NONE)
466                 free(handle);
467
468         return __convert_recorder_error_code(__func__, ret);
469
470 }
471
472 int recorder_prepare( recorder_h recorder){
473         
474         if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER);         
475         int ret = 0;
476         recorder_s *handle = (recorder_s*)recorder;
477
478         if( handle->type == _RECORDER_TYPE_VIDEO ){
479                 return __convert_error_code_camera_to_recorder(camera_start_preview(handle->camera));
480         }
481
482         MMCamcorderStateType mmstate ;
483         mm_camcorder_get_state(handle->mm_handle, &mmstate);
484
485         if( mmstate !=  MM_CAMCORDER_STATE_READY){
486                 ret = mm_camcorder_realize(handle->mm_handle);  
487                 if( ret != MM_ERROR_NONE){
488                         LOGE("[%s] mm_camcorder_realize fail", __func__);
489                         return __convert_recorder_error_code(__func__, ret);
490                 }
491         }
492
493         ret = mm_camcorder_start(handle->mm_handle);
494
495         if( ret != MM_ERROR_NONE){
496                 LOGE("[%s] mm_camcorder_start fail", __func__); 
497                 mm_camcorder_unrealize(handle->mm_handle);
498                 return __convert_recorder_error_code(__func__, ret);
499         }       
500
501         return RECORDER_ERROR_NONE;
502 }
503
504 int recorder_unprepare( recorder_h recorder){
505         if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); 
506         int ret = 0;
507         recorder_s *handle = (recorder_s*)recorder;
508
509         MMCamcorderStateType mmstate ;
510         mm_camcorder_get_state(handle->mm_handle, &mmstate);    
511         
512         if( mmstate ==  MM_CAMCORDER_STATE_PREPARE){
513                 ret = mm_camcorder_stop(handle->mm_handle);     
514                 if( ret != MM_ERROR_NONE){
515                         LOGE("[%s] mm_camcorder_stop fail", __func__);  
516                         return __convert_recorder_error_code(__func__, ret);
517                 }
518         }
519         ret = mm_camcorder_unrealize(handle->mm_handle);
520         return __convert_recorder_error_code(__func__, ret);
521 }
522
523 int recorder_start( recorder_h recorder){
524         
525         if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER);         
526         int ret;
527         recorder_s *handle = (recorder_s*)recorder;
528         ret = mm_camcorder_record(handle->mm_handle);
529         return __convert_recorder_error_code(__func__, ret);
530 }
531
532 int recorder_pause( recorder_h recorder){
533         
534         if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER);         
535         int ret;
536         recorder_s *handle = (recorder_s*)recorder;
537         ret = mm_camcorder_pause(handle->mm_handle);
538
539         return __convert_recorder_error_code(__func__, ret);
540 }
541
542 int recorder_commit( recorder_h recorder){
543         
544         if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER);         
545         int ret;
546         recorder_s *handle = (recorder_s*)recorder;
547         ret = mm_camcorder_commit(handle->mm_handle);
548         return __convert_recorder_error_code(__func__, ret);    
549 }
550
551 int recorder_cancel( recorder_h recorder){
552         
553         if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER);         
554         int ret;
555         recorder_s *handle = (recorder_s*)recorder;
556         ret = mm_camcorder_cancel(handle->mm_handle);
557         return __convert_recorder_error_code(__func__, ret);    
558 }
559
560 int recorder_get_audio_level(recorder_h recorder, double *level){
561         if( recorder == NULL || level == NULL ) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER);
562         recorder_s *handle = (recorder_s*)recorder;
563
564         recorder_state_e state;
565         recorder_get_state(recorder, &state);
566         if( state < RECORDER_STATE_RECORDING ){
567                 LOGE("[%s]RECORDER_ERROR_INVALID_STATE(0x%08x) ",__func__, RECORDER_ERROR_INVALID_STATE);
568                 return RECORDER_ERROR_INVALID_STATE;
569         }
570
571         *level = handle->last_max_input_level ;
572         handle->last_max_input_level = LOWSET_DECIBEL;
573         return RECORDER_ERROR_NONE;
574 }
575
576 int recorder_set_filename(recorder_h recorder,  const char *filename){
577         
578         if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER);         
579         g_return_val_if_fail(filename != NULL, RECORDER_ERROR_INVALID_PARAMETER);                       
580         int ret;
581         recorder_s * handle = (recorder_s*)recorder;
582         ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL,  MMCAM_TARGET_FILENAME  , filename , strlen(filename), NULL);
583         return __convert_recorder_error_code(__func__, ret);
584
585 }
586
587 int recorder_get_filename(recorder_h recorder,  char **filename){
588         
589         if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER);         
590         g_return_val_if_fail(filename != NULL, RECORDER_ERROR_INVALID_PARAMETER);                       
591         int ret;
592         recorder_s * handle = (recorder_s*)recorder;
593
594         char *record_filename;
595         int record_filename_size;
596         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_TARGET_FILENAME , &record_filename, &record_filename_size, NULL);
597         if( ret == CAMERA_ERROR_NONE ){
598                 *filename = strdup(record_filename);
599         }
600
601         return __convert_recorder_error_code(__func__, ret);
602         
603 }
604
605
606 int recorder_set_file_format(recorder_h recorder, recorder_file_format_e format){
607         
608         if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER);         
609         int ret;
610         int format_table[5] = { MM_FILE_FORMAT_3GP ,  // RECORDER_FILE_FORMAT_3GP,
611                                                                                           MM_FILE_FORMAT_MP4 , //RECORDER_FILE_FORMAT_MP4,
612                                                                                           MM_FILE_FORMAT_AMR, //RECORDER_FILE_FORMAT_AMR,
613                                                                                           MM_FILE_FORMAT_AAC, //RECORDER_FILE_FORMAT_ADTS
614                                                                                           MM_FILE_FORMAT_WAV //RECORDER_FILE_FORMAT_WAV
615                                                                                         };
616
617         if( format < RECORDER_FILE_FORMAT_3GP || format > RECORDER_FILE_FORMAT_WAV )
618                 return RECORDER_ERROR_INVALID_PARAMETER;
619
620         recorder_s * handle = (recorder_s*)recorder;
621         ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_FILE_FORMAT  , format_table[format], NULL);
622         return __convert_recorder_error_code(__func__, ret);
623 }
624
625 int recorder_get_file_format(recorder_h recorder, recorder_file_format_e *format){
626         
627         if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER);         
628         g_return_val_if_fail(format != NULL, RECORDER_ERROR_INVALID_PARAMETER);         
629         
630         int ret;
631         recorder_s * handle = (recorder_s*)recorder;
632         int mm_format;
633         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_FILE_FORMAT  , &mm_format, NULL);
634
635         if( ret == 0 ){
636                 switch( mm_format ){
637                         case MM_FILE_FORMAT_3GP:
638                                 *format = RECORDER_FILE_FORMAT_3GP;
639                                 break;
640                         case MM_FILE_FORMAT_MP4 :
641                                 *format = RECORDER_FILE_FORMAT_MP4;
642                                 break;
643                         case MM_FILE_FORMAT_AMR :
644                                 *format = RECORDER_FILE_FORMAT_AMR;
645                                 break;
646                         case MM_FILE_FORMAT_AAC :
647                                 *format = RECORDER_FILE_FORMAT_ADTS;
648                                 break;
649                         case MM_FILE_FORMAT_WAV:
650                                 *format = RECORDER_FILE_FORMAT_WAV;
651                                 break;
652                         default :
653                                 ret = MM_ERROR_CAMCORDER_INTERNAL;
654                                 break;
655                 }
656         }
657         return __convert_recorder_error_code(__func__, ret);
658 }
659
660
661
662 int recorder_set_state_changed_cb(recorder_h recorder, recorder_state_changed_cb callback, void* user_data){
663         
664         if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); 
665         recorder_s *handle = (recorder_s*)recorder;
666         if( callback == NULL )
667                 return RECORDER_ERROR_INVALID_PARAMETER;
668         
669         handle->user_cb[_RECORDER_EVENT_TYPE_STATE_CHANGE] = callback;
670         handle->user_data[_RECORDER_EVENT_TYPE_STATE_CHANGE] = user_data;
671
672         return RECORDER_ERROR_NONE;
673         
674 }
675
676 int recorder_unset_state_changed_cb(recorder_h recorder){
677         
678         if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER);         
679         recorder_s *handle = (recorder_s*)recorder;
680
681         handle->user_cb[_RECORDER_EVENT_TYPE_STATE_CHANGE] = NULL;
682         handle->user_data[_RECORDER_EVENT_TYPE_STATE_CHANGE] = NULL;
683
684         return RECORDER_ERROR_NONE;     
685 }
686
687 int recorder_set_interrupted_cb(recorder_h recorder, recorder_interrupted_cb callback, void *user_data){
688         if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); 
689         recorder_s *handle = (recorder_s*)recorder;
690         if( callback == NULL )
691                 return RECORDER_ERROR_INVALID_PARAMETER;
692
693         handle->user_cb[_RECORDER_EVENT_TYPE_INTERRUPTED] = callback;
694         handle->user_data[_RECORDER_EVENT_TYPE_INTERRUPTED] = user_data;
695
696         return RECORDER_ERROR_NONE;
697 }
698 int recorder_unset_interrupted_cb(recorder_h recorder){
699         if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER);         
700         recorder_s *handle = (recorder_s*)recorder;
701
702         handle->user_cb[_RECORDER_EVENT_TYPE_INTERRUPTED] = NULL;
703         handle->user_data[_RECORDER_EVENT_TYPE_INTERRUPTED] = NULL;
704
705         return RECORDER_ERROR_NONE;
706 }
707
708 int recorder_set_audio_stream_cb(recorder_h recorder, recorder_audio_stream_cb callback, void* user_data){
709         if( recorder == NULL || callback == NULL ) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER);
710         int ret;
711         recorder_s *handle = (recorder_s*)recorder;
712         ret = mm_camcorder_set_audio_stream_callback( handle->mm_handle, __mm_audio_stream_cb, handle);
713         if( ret == 0 ){
714                 handle->user_cb[_RECORDER_EVENT_TYPE_AUDIO_STREAM] = callback;
715                 handle->user_data[_RECORDER_EVENT_TYPE_AUDIO_STREAM] = user_data;
716         }
717         return __convert_recorder_error_code(__func__, ret);
718 }
719
720 int recorder_unset_audio_stream_cb(recorder_h recorder){
721         if( recorder == NULL ) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER);
722         int ret;
723         recorder_s *handle = (recorder_s*)recorder;
724         handle->user_cb[_RECORDER_EVENT_TYPE_AUDIO_STREAM] = NULL;
725         handle->user_data[_RECORDER_EVENT_TYPE_AUDIO_STREAM] = NULL;
726         ret = mm_camcorder_set_audio_stream_callback( handle->mm_handle, NULL, NULL);
727         return __convert_recorder_error_code(__func__, ret);
728 }
729
730 int recorder_set_error_cb(recorder_h recorder, recorder_error_cb callback, void *user_data){
731         if( recorder == NULL || callback == NULL ) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER);
732         recorder_s *handle = (recorder_s*)recorder;
733         handle->user_cb[_RECORDER_EVENT_TYPE_ERROR] = callback;
734         handle->user_data[_RECORDER_EVENT_TYPE_ERROR] = user_data;
735         return RECORDER_ERROR_NONE;
736 }
737
738 int recorder_unset_error_cb(recorder_h recorder){
739         if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER);
740         recorder_s *handle = (recorder_s*)recorder;
741         handle->user_cb[_RECORDER_EVENT_TYPE_ERROR] = NULL;
742         handle->user_data[_RECORDER_EVENT_TYPE_ERROR] = NULL;
743         return RECORDER_ERROR_NONE;
744 }
745
746 int recorder_set_recording_status_cb(recorder_h recorder, recorder_recording_status_cb callback, void* user_data){
747         
748         if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER);         
749         recorder_s *handle = (recorder_s*)recorder;
750         if( callback == NULL )
751                 return RECORDER_ERROR_INVALID_PARAMETER;
752         
753         handle->user_cb[_RECORDER_EVENT_TYPE_RECORDING_STATUS] = callback;
754         handle->user_data[_RECORDER_EVENT_TYPE_RECORDING_STATUS] = user_data;
755
756         return RECORDER_ERROR_NONE;
757 }
758
759 int recorder_unset_recording_status_cb(recorder_h recorder){
760         
761         if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER);         
762         recorder_s *handle = (recorder_s*)recorder;     
763         handle->user_cb[_RECORDER_EVENT_TYPE_RECORDING_STATUS] = NULL;
764         handle->user_data[_RECORDER_EVENT_TYPE_RECORDING_STATUS] = NULL;
765         
766         return RECORDER_ERROR_NONE;
767         
768 }
769
770 int recorder_set_recording_limit_reached_cb(recorder_h recorder, recorder_recording_limit_reached_cb callback, void* user_data){
771         
772         if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER);         
773         recorder_s *handle = (recorder_s*)recorder;
774         if( callback == NULL )
775                 return RECORDER_ERROR_INVALID_PARAMETER;
776         
777         handle->user_cb[_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = callback;
778         handle->user_data[_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = user_data;
779
780         return RECORDER_ERROR_NONE;
781         
782 }
783
784 int recorder_unset_recording_limit_reached_cb(recorder_h recorder){
785         
786         if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER);         
787         recorder_s *handle = (recorder_s*)recorder;
788         handle->user_cb[_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = NULL;
789         handle->user_data[_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = NULL;
790
791         return RECORDER_ERROR_NONE;     
792 }
793
794 int recorder_foreach_supported_file_format(recorder_h recorder, recorder_supported_file_format_cb foreach_cb , void *user_data){
795         
796         if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER);         
797         if( foreach_cb == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER);                       
798         int ret;
799         recorder_s * handle = (recorder_s*)recorder;
800         MMCamAttrsInfo info;
801         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_FILE_FORMAT , &info);
802         if( ret != RECORDER_ERROR_NONE )
803                 return ret;
804         
805         int i;
806         for( i=0 ; i < info.int_array.count ; i++)
807         {
808
809                 int format;
810                 
811                 switch(  info.int_array.array[i] ){
812                         case MM_FILE_FORMAT_3GP:
813                                 format = RECORDER_FILE_FORMAT_3GP;
814                                 break;
815                         case MM_FILE_FORMAT_MP4 :
816                                 format = RECORDER_FILE_FORMAT_MP4;
817                                 break;
818                         case MM_FILE_FORMAT_AMR :
819                                 format = RECORDER_FILE_FORMAT_AMR;
820                                 break;
821                         case MM_FILE_FORMAT_AAC:
822                                 format = RECORDER_FILE_FORMAT_ADTS;
823                                 break;
824                         case MM_FILE_FORMAT_WAV:
825                                 format = RECORDER_FILE_FORMAT_WAV;
826                                 break;
827                         default :
828                                 format = -1;
829                 }
830
831                 if ( format != -1 && !foreach_cb(format,user_data) )
832                         break;
833         }
834         return RECORDER_ERROR_NONE;
835         
836 }
837
838
839
840 int recorder_attr_set_size_limit(recorder_h recorder,  int kbyte){
841         
842         if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER);         
843         int ret;
844         recorder_s * handle = (recorder_s*)recorder;
845         ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, "target-max-size"  , kbyte, NULL);
846         return __convert_recorder_error_code(__func__, ret);
847         
848 }
849
850 int recorder_attr_set_time_limit(recorder_h recorder,  int second){
851         
852         if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER);         
853         int ret;
854         recorder_s * handle = (recorder_s*)recorder;
855         ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_TARGET_TIME_LIMIT , second, NULL);
856         return __convert_recorder_error_code(__func__, ret);    
857 }
858
859 int recorder_attr_set_audio_device(recorder_h recorder , recorder_audio_device_e device){
860         
861         if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER);         
862         int ret;
863         recorder_s * handle = (recorder_s*)recorder;
864         ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_AUDIO_DEVICE , device, NULL);
865         return __convert_recorder_error_code(__func__, ret);    
866 }
867
868 int recorder_set_audio_encoder(recorder_h recorder, recorder_audio_codec_e  codec){
869         
870         if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER);         
871
872         if( codec != RECORDER_AUDIO_CODEC_DISABLE && ( codec < RECORDER_AUDIO_CODEC_AMR || codec > RECORDER_AUDIO_CODEC_PCM) )
873                 return RECORDER_ERROR_INVALID_PARAMETER;
874
875         int audio_table[4] = { MM_AUDIO_CODEC_AMR, //RECORDER_AUDIO_CODEC_AMR
876                                                                                         MM_AUDIO_CODEC_AAC,  //RECORDER_AUDIO_CODEC_AAC
877                                                                                         MM_AUDIO_CODEC_VORBIS, //RECORDER_AUDIO_CODEC_VORBIS
878                                                                                         MM_AUDIO_CODEC_WAVE //RECORDER_AUDIO_CODEC_PCM
879                                                                                 };
880         int ret;
881         recorder_s * handle = (recorder_s*)recorder;
882         if( codec == RECORDER_AUDIO_CODEC_DISABLE )
883                 ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_AUDIO_DISABLE , 1, NULL);
884         else
885                 ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_AUDIO_ENCODER , audio_table[codec], MMCAM_AUDIO_DISABLE, 0, NULL);
886
887         return __convert_recorder_error_code(__func__, ret);
888         
889 }
890
891 int recorder_get_audio_encoder(recorder_h recorder, recorder_audio_codec_e *codec){
892         
893         if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER);         
894         g_return_val_if_fail(codec != NULL, RECORDER_ERROR_INVALID_PARAMETER);          
895         int ret;
896         int mm_codec = 0;
897         int audio_disable = 0;
898         
899         recorder_s * handle = (recorder_s*)recorder;
900         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_AUDIO_ENCODER , &mm_codec , MMCAM_AUDIO_DISABLE, &audio_disable, NULL);
901         if( ret == 0 && audio_disable == 0 ){
902                 switch( mm_codec ){
903                         case MM_AUDIO_CODEC_AMR :
904                                 *codec = RECORDER_AUDIO_CODEC_AMR;
905                                 break;
906                         case MM_AUDIO_CODEC_AAC :
907                                 *codec = RECORDER_AUDIO_CODEC_AAC;
908                                 break;
909                         case MM_AUDIO_CODEC_VORBIS:
910                                 *codec = RECORDER_AUDIO_CODEC_VORBIS;
911                                 break;
912                         case MM_AUDIO_CODEC_WAVE:
913                                 *codec = RECORDER_AUDIO_CODEC_PCM;
914                                 break;
915                         default :
916                                 ret = MM_ERROR_CAMCORDER_INTERNAL;
917                                 break;
918                 }
919         }else if( ret == 0 && audio_disable ){
920                 *codec = RECORDER_AUDIO_CODEC_DISABLE;
921         }
922                 
923         return __convert_recorder_error_code(__func__, ret);    
924 }
925
926 int recorder_set_video_encoder(recorder_h recorder, recorder_video_codec_e  codec){
927         
928         if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER);         
929         int ret;
930
931         int video_table[4] = { MM_VIDEO_CODEC_H263,             //RECORDER_VIDEO_CODEC_H263,                    /**< H263 codec         */
932                                                                                         MM_VIDEO_CODEC_H264,    //RECORDER_VIDEO_CODEC_H264,                    /**< H264 codec         */
933                                                                                         MM_VIDEO_CODEC_MPEG4,   //RECORDER_VIDEO_CODEC_MPEG4,                   /**< MPEG4 codec        */
934                                                                                         MM_VIDEO_CODEC_THEORA //RECORDER_VIDEO_CODEC_THEORA
935                                                                                 };
936         if( codec < RECORDER_VIDEO_CODEC_H263 || codec > RECORDER_VIDEO_CODEC_THEORA )
937                 return RECORDER_ERROR_INVALID_PARAMETER;
938         recorder_s * handle = (recorder_s*)recorder;
939
940         ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_VIDEO_ENCODER   , video_table[codec], NULL);
941         return __convert_recorder_error_code(__func__, ret);
942 }
943
944
945
946 int recorder_get_video_encoder(recorder_h recorder, recorder_video_codec_e *codec){
947         
948         if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); 
949         if( codec == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER);    
950
951         int ret;
952         int mm_codec = 0;
953
954         recorder_s * handle = (recorder_s*)recorder;
955         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_VIDEO_ENCODER , &mm_codec, NULL);
956         if( ret == 0 ){
957                 switch( mm_codec ){
958                         case MM_VIDEO_CODEC_H263 :
959                                 *codec = RECORDER_VIDEO_CODEC_H263;
960                                 break;
961                         case MM_VIDEO_CODEC_H264 :
962                                 *codec = RECORDER_VIDEO_CODEC_H264;
963                                 break;
964                         case MM_VIDEO_CODEC_MPEG4 :
965                                 *codec = RECORDER_VIDEO_CODEC_MPEG4;
966                                 break;
967                         case MM_VIDEO_CODEC_THEORA:
968                                 *codec = RECORDER_VIDEO_CODEC_THEORA;
969                                 break;
970                         default :
971                                 ret = MM_ERROR_CAMCORDER_INTERNAL;
972                                 break;
973                 }
974         }
975         
976         return __convert_recorder_error_code(__func__, ret);
977         
978 }
979
980 int recorder_attr_set_audio_samplerate(recorder_h recorder, int samplerate){
981         
982         if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER);         
983         int ret;
984         recorder_s * handle = (recorder_s*)recorder;
985         ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_AUDIO_SAMPLERATE  , samplerate, NULL);
986         return __convert_recorder_error_code(__func__, ret);
987         
988 }
989
990 int recorder_attr_set_audio_encoder_bitrate(recorder_h recorder,  int bitrate){
991         
992         if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER);         
993         int ret;
994         recorder_s * handle = (recorder_s*)recorder;
995         ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_AUDIO_ENCODER_BITRATE  , bitrate, NULL);
996         return __convert_recorder_error_code(__func__, ret);
997         
998 }
999
1000 int recorder_attr_set_video_encoder_bitrate(recorder_h recorder,  int bitrate){
1001         
1002         if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER);         
1003         int ret;
1004         recorder_s * handle = (recorder_s*)recorder;
1005         ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_VIDEO_ENCODER_BITRATE  , bitrate, NULL);
1006         return __convert_recorder_error_code(__func__, ret);
1007         
1008 }
1009
1010 int recorder_attr_get_size_limit(recorder_h recorder,  int *kbyte){
1011         
1012         if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER);         
1013         int ret;
1014         recorder_s * handle = (recorder_s*)recorder;
1015         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, "target-max-size"  , kbyte, NULL);
1016         return __convert_recorder_error_code(__func__, ret);    
1017 }
1018
1019 int recorder_attr_get_time_limit(recorder_h recorder,  int *second){
1020         
1021         if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER);         
1022         int ret;
1023         recorder_s * handle = (recorder_s*)recorder;
1024         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_TARGET_TIME_LIMIT , second, NULL);
1025         return __convert_recorder_error_code(__func__, ret);
1026         
1027 }
1028
1029 int recorder_attr_get_audio_device(recorder_h recorder , recorder_audio_device_e *device){
1030         
1031         if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER);         
1032         int ret;
1033         recorder_s * handle = (recorder_s*)recorder;
1034         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_AUDIO_DEVICE , device, NULL);
1035         return __convert_recorder_error_code(__func__, ret);    
1036 }
1037
1038
1039
1040 int recorder_attr_get_audio_samplerate(recorder_h recorder, int *samplerate){
1041         
1042         if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER);         
1043         int ret;
1044         recorder_s * handle = (recorder_s*)recorder;
1045         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_AUDIO_SAMPLERATE , samplerate, NULL);
1046         return __convert_recorder_error_code(__func__, ret);
1047         
1048 }
1049
1050 int recorder_attr_get_audio_encoder_bitrate(recorder_h recorder,  int *bitrate){
1051         
1052         if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER);         
1053         int ret;
1054         recorder_s * handle = (recorder_s*)recorder;
1055         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_AUDIO_ENCODER_BITRATE , bitrate, NULL);
1056         return __convert_recorder_error_code(__func__, ret);
1057 }
1058
1059 int recorder_attr_get_video_encoder_bitrate(recorder_h recorder,  int *bitrate){
1060         
1061         if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER);         
1062         int ret;
1063         recorder_s * handle = (recorder_s*)recorder;
1064         ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_VIDEO_ENCODER_BITRATE , bitrate, NULL);
1065         return __convert_recorder_error_code(__func__, ret);
1066         
1067 }
1068
1069 int recorder_foreach_supported_audio_encoder(recorder_h recorder, recorder_supported_audio_encoder_cb foreach_cb , void *user_data){
1070         
1071         if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER);         
1072         if( foreach_cb == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER);               
1073         int ret;
1074         recorder_s * handle = (recorder_s*)recorder;
1075         MMCamAttrsInfo info;
1076         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_AUDIO_ENCODER , &info);
1077         if( ret != RECORDER_ERROR_NONE )
1078                 return __convert_recorder_error_code(__func__, ret);
1079         
1080         int i;
1081         for( i=0 ; i < info.int_array.count ; i++)
1082         {
1083                 int codec;
1084                 
1085                 switch(  info.int_array.array[i] ){
1086                         case MM_AUDIO_CODEC_AMR:
1087                                 codec = RECORDER_AUDIO_CODEC_AMR;
1088                                 break;
1089                         case MM_AUDIO_CODEC_AAC :
1090                                 codec = RECORDER_AUDIO_CODEC_AAC;
1091                                 break;
1092                         case MM_AUDIO_CODEC_VORBIS:
1093                                 codec = RECORDER_AUDIO_CODEC_VORBIS;
1094                                 break;
1095                         case MM_AUDIO_CODEC_WAVE:
1096                                 codec = RECORDER_AUDIO_CODEC_PCM;
1097                                 break;
1098                         default :
1099                                 codec = -1;
1100                 }       
1101                 if( codec != -1 && !foreach_cb(codec,user_data) )
1102                         break;
1103         }
1104         return RECORDER_ERROR_NONE;     
1105 }
1106 int recorder_foreach_supported_video_encoder(recorder_h recorder, recorder_supported_video_encoder_cb foreach_cb , void *user_data){
1107         
1108         if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER);
1109         if( foreach_cb == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER);
1110         int ret;
1111         recorder_s * handle = (recorder_s*)recorder;
1112         MMCamAttrsInfo info;
1113         ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_VIDEO_ENCODER , &info);
1114         if( ret != RECORDER_ERROR_NONE )
1115                 return __convert_recorder_error_code(__func__, ret);
1116         
1117         int i;
1118         for( i=0 ; i < info.int_array.count ; i++)
1119         {
1120                 int codec;
1121                 
1122                 switch(  info.int_array.array[i] ){
1123                         case MM_VIDEO_CODEC_H263 :
1124                                 codec = RECORDER_VIDEO_CODEC_H263;
1125                                 break;
1126                         case MM_VIDEO_CODEC_H264 :
1127                                 codec = RECORDER_VIDEO_CODEC_H264;
1128                                 break;
1129                         case MM_VIDEO_CODEC_MPEG4 :
1130                                 codec = RECORDER_VIDEO_CODEC_MPEG4;
1131                                 break;
1132                         case MM_VIDEO_CODEC_THEORA :
1133                                 codec = RECORDER_VIDEO_CODEC_THEORA;
1134                                 break;
1135                         default :
1136                                 codec = -1;
1137                 }       
1138         
1139                 if ( codec != -1 &&  !foreach_cb(codec,user_data) )
1140                         break;
1141         }
1142         return RECORDER_ERROR_NONE;
1143         
1144 }
1145
1146
1147 int recorder_attr_set_mute(recorder_h recorder, bool enable){
1148         if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER);
1149         recorder_s * handle = (recorder_s*)recorder;
1150         int ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_AUDIO_VOLUME , enable ? 0.0 : 1.0 , NULL);
1151         return  __convert_recorder_error_code(__func__, ret);
1152 }
1153
1154 bool recorder_attr_is_muted(recorder_h recorder){
1155         if( recorder == NULL){
1156                 __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER);
1157                 return false;
1158         }
1159         recorder_s * handle = (recorder_s*)recorder;
1160         double volume = 1.0;
1161         mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_AUDIO_VOLUME , &volume , NULL);
1162         if( volume == 0.0 )
1163                 return true;
1164         else
1165                 return false;
1166 }
1167
1168 int recorder_attr_set_recording_motion_rate(recorder_h recorder , double rate){
1169         if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER);
1170         recorder_s * handle = (recorder_s*)recorder;
1171         int ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, "camera-recording-motion-rate" , rate, NULL);
1172         return  __convert_recorder_error_code(__func__, ret);
1173 }
1174
1175 int recorder_attr_get_recording_motion_rate(recorder_h recorder , double *rate){
1176         if( recorder == NULL || rate == NULL )
1177                 return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER);
1178
1179         recorder_s * handle = (recorder_s*)recorder;
1180         int ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, "camera-recording-motion-rate" , rate , NULL);
1181         return  __convert_recorder_error_code(__func__, ret);
1182 }
1183
1184
1185
1186 int recorder_attr_set_slow_motion_rate(recorder_h recorder , double rate){
1187         return recorder_attr_set_recording_motion_rate(recorder, rate);
1188 }
1189
1190 int recorder_attr_get_slow_motion_rate(recorder_h recorder , double *rate){
1191         return recorder_attr_get_recording_motion_rate(recorder, rate);
1192 }
1193
1194
1195 int recorder_attr_set_audio_channel(recorder_h recorder, int channel_count){
1196         if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER);
1197         recorder_s * handle = (recorder_s*)recorder;
1198         int ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_AUDIO_CHANNEL, channel_count, NULL);
1199         return  __convert_recorder_error_code(__func__, ret);
1200 }
1201
1202 int recorder_attr_get_audio_channel(recorder_h recorder, int *channel_count){
1203         if( recorder == NULL || channel_count == NULL )
1204                 return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER);
1205
1206         recorder_s * handle = (recorder_s*)recorder;
1207         int ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_AUDIO_CHANNEL , channel_count, NULL);
1208         return  __convert_recorder_error_code(__func__, ret);
1209 }
1210
1211 int recorder_attr_set_recording_orientation(recorder_h recorder, recorder_rotation_e orientation){
1212         if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER);
1213         recorder_s * handle = (recorder_s*)recorder;
1214         int ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, "camcorder-rotation", orientation, NULL);
1215         return  __convert_recorder_error_code(__func__, ret);
1216 }
1217
1218 int recorder_attr_get_recording_orientation(recorder_h recorder, recorder_rotation_e *orientation){
1219         if( recorder == NULL || orientation == NULL ) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER);
1220         recorder_s * handle = (recorder_s*)recorder;
1221         int ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, "camcorder-rotation" , orientation, NULL);
1222         return  __convert_recorder_error_code(__func__, ret);
1223 }