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