From: sejong123.park Date: Thu, 8 Jan 2015 07:29:10 +0000 (+0900) Subject: 1. Tizen 3.0 Recorder update X-Git-Tag: accepted/tizen/common/20150115.180943^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F07%2F33307%2F2;p=platform%2Fcore%2Fapi%2Frecorder.git 1. Tizen 3.0 Recorder update 2. Fix build error on 64bit build Change-Id: Ib2630868ea2600e915fde1e14d7d176d8e0d880e Signed-off-by: sejong123.park --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 7d34a11..442c103 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,7 +53,7 @@ ENDIF("${ARCH}" STREQUAL "arm") ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") ADD_DEFINITIONS("-DTIZEN_DEBUG") -SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=/usr/lib") +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=${LIB_INSTALL_DIR}") aux_source_directory(src SOURCES) ADD_LIBRARY(${fw_name} SHARED ${SOURCES}) @@ -67,7 +67,7 @@ SET_TARGET_PROPERTIES(${fw_name} CLEAN_DIRECT_OUTPUT 1 ) -INSTALL(TARGETS ${fw_name} DESTINATION lib) +INSTALL(TARGETS ${fw_name} DESTINATION ${LIB_INSTALL_DIR}) INSTALL( DIRECTORY ${INC_DIR}/ DESTINATION include/${service} FILES_MATCHING @@ -84,7 +84,7 @@ CONFIGURE_FILE( ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc @ONLY ) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc DESTINATION lib/pkgconfig) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) #ADD_SUBDIRECTORY(test) diff --git a/capi-media-recorder.pc.in b/capi-media-recorder.pc.in index 5d02f8d..1997d91 100644 --- a/capi-media-recorder.pc.in +++ b/capi-media-recorder.pc.in @@ -3,7 +3,7 @@ prefix=@PREFIX@ exec_prefix=/usr -libdir=/usr/lib +libdir=@LIB_INSTALL_DIR@ includedir=/usr/include/media Name: @PC_NAME@ diff --git a/include/recorder.h b/include/recorder.h index 75fbcb7..9caf672 100644 --- a/include/recorder.h +++ b/include/recorder.h @@ -61,6 +61,8 @@ typedef enum RECORDER_ERROR_SOUND_POLICY_BY_ALARM = RECORDER_ERROR_CLASS | 0x09, /**< Blocked by Audio Session Manager - ALARM */ RECORDER_ERROR_ESD = RECORDER_ERROR_CLASS | 0x0a, /**< ESD situation */ RECORDER_ERROR_OUT_OF_STORAGE = RECORDER_ERROR_CLASS | 0x0b, /**< Out of storage */ + RECORDER_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< The access to the resources can not be granted */ + RECORDER_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< The feature is not supported */ } recorder_error_e; /** @@ -250,6 +252,18 @@ typedef void (*recorder_interrupted_cb)(recorder_policy_e policy, recorder_state typedef void (*recorder_audio_stream_cb)(void* stream, int size, audio_sample_type_e format, int channel, unsigned int timestamp, void *user_data); /** + * @brief Called once for each supported video resolution. + * @since_tizen 2.3 + * @param[in] width The video image width + * @param[in] height The video image height + * @param[in] user_data The user data passed from the foreach function + * @return @c true to continue with the next iteration of the loop, \n otherwise @c false to break out of the loop + * @pre recorder_foreach_supported_video_resolution() will invoke this callback. + * @see recorder_foreach_supported_video_resolution() + */ +typedef bool (*recorder_supported_video_resolution_cb)(int width, int height, void *user_data); + +/** * @brief Called when the error occurred. * * @remarks @@ -676,6 +690,42 @@ int recorder_foreach_supported_audio_encoder(recorder_h recorder, recorder_suppo */ /** + * @brief Sets the resolution of the video recording. + * @since_tizen 2.3 + * @remarks This function should be called before recording (recorder_start()). + * @param[in] recorder The handle to the media recorder + * @param[in] width The preview width + * @param[in] height The preview height + * @return @c 0 on success, otherwise a negative error value + * @retval #RECORDER_ERROR_NONE Successful + * @retval #RECORDER_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #RECORDER_ERROR_INVALID_STATE Invalid state + * @retval #RECORDER_ERROR_PERMISSION_DENIED The access to the resources can not be granted + * @retval #RECORDER_ERROR_NOT_SUPPORTED The feature is not supported + * @pre The recorder state must be #RECORDER_STATE_CREATED or #RECORDER_STATE_READY. + * @see recorder_start() + * @see recorder_get_video_resolution() + * @see recorder_foreach_supported_video_resolution() + */ +int recorder_set_video_resolution(recorder_h recorder, int width, int height); + +/** + * @brief Gets the resolution of the video recording. + * @since_tizen 2.3 + * @param[in] recorder The handle to the media recorder + * @param[out] width The video width + * @param[out] height The video height + * @return 0 on success, otherwise a negative error value + * @retval #RECORDER_ERROR_NONE Successful + * @retval #RECORDER_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #RECORDER_ERROR_PERMISSION_DENIED The access to the resources can not be granted + * @retval #RECORDER_ERROR_NOT_SUPPORTED The feature is not supported + * @see recorder_set_video_resolution() + * @see recorder_foreach_supported_video_resolution() + */ +int recorder_get_video_resolution(recorder_h recorder, int *width, int *height); + +/** * @brief Sets the video codec for encoding video stream. * @remarks You can get available video encoders by using recorder_foreach_supported_video_encoder(). * @param[in] recorder The handle to media recorder @@ -713,6 +763,25 @@ int recorder_get_video_encoder(recorder_h recorder, recorder_video_codec_e *code */ /** + * @brief Retrieves all supported video resolutions by invoking callback function once for each supported video resolution. + * @since_tizen 2.3 + * @param[in] recorder The handle to the media recorder + * @param[in] foreach_cb The callback function to be invoked + * @param[in] user_data The user data to be passed to the callback function + * @return @c 0 on success, otherwise a negative error value + * @retval #RECORDER_ERROR_NONE Successful + * @retval #RECORDER_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #RECORDER_ERROR_PERMISSION_DENIED The access to the resources can not be granted + * @retval #RECORDER_ERROR_NOT_SUPPORTED The feature is not supported + * @post This function invokes recorder_supported_video_resolution_cb() repeatedly to retrieve each supported video resolution. + * @see recorder_set_video_resolution() + * @see recorder_get_video_resolution() + * @see recorder_supported_video_resolution_cb() + */ +int recorder_foreach_supported_video_resolution(recorder_h recorder, + recorder_supported_video_resolution_cb foreach_cb, void *user_data); + +/** * @brief Retrieves all supported video encoders by invoking a specific callback for each supported video encoder. * @param[in] recorder The handle to media recorder * @param[in] callback The iteration callback diff --git a/include/recorder_private.h b/include/recorder_private.h old mode 100755 new mode 100644 index 8ddf6db..50ec96c --- a/include/recorder_private.h +++ b/include/recorder_private.h @@ -26,11 +26,17 @@ extern "C" { #endif +typedef union _mediaSource{ + camera_h camera; +}mediasource; + + typedef enum { _RECORDER_EVENT_TYPE_STATE_CHANGE, _RECORDER_EVENT_TYPE_RECORDING_LIMITED, _RECORDER_EVENT_TYPE_RECORDING_STATUS, _RECORDER_EVENT_TYPE_INTERRUPTED, + _RECORDER_EVENT_TYPE_INTERRUPT_COMPLETED, _RECORDER_EVENT_TYPE_AUDIO_STREAM, _RECORDER_EVENT_TYPE_ERROR, _RECORDER_EVENT_TYPE_NUM @@ -43,16 +49,17 @@ typedef enum { typedef struct _recorder_s{ MMHandleType mm_handle; - camera_h camera; + mediasource mm_source; void* user_cb[_RECORDER_EVENT_TYPE_NUM]; void* user_data[_RECORDER_EVENT_TYPE_NUM]; - int state; + unsigned int state; _recorder_type_e type; int origin_preview_format; int changed_preview_format; double last_max_input_level; } recorder_s; +static int __convert_recorder_error_code(const char *func, int code); #ifdef __cplusplus } #endif diff --git a/packaging/capi-media-recorder.spec b/packaging/capi-media-recorder.spec index 6a1a483..86703fd 100644 --- a/packaging/capi-media-recorder.spec +++ b/packaging/capi-media-recorder.spec @@ -1,6 +1,6 @@ Name: capi-media-recorder Summary: A Recorder library in Tizen C API -Version: 0.1.3 +Version: 0.2.0 Release: 0 Group: Multimedia/API License: Apache-2.0 @@ -13,33 +13,39 @@ BuildRequires: pkgconfig(capi-base-common) BuildRequires: pkgconfig(capi-media-camera) BuildRequires: pkgconfig(capi-media-audio-io) + %description A Recorder library in Tizen C API + %package devel Summary: A Recorder library in Tizen C API (Development) Requires: %{name} = %{version}-%{release} + %description devel A Recorder library in Tizen C API Development Package. + %prep %setup -q + %build MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` -%cmake . -DFULLVER=%{version} -DMAJORVER=${MAJORVER} - - +%cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DFULLVER=%{version} -DMAJORVER=${MAJORVER} make %{?jobs:-j%jobs} + %install %make_install + %post -p /sbin/ldconfig + %postun -p /sbin/ldconfig diff --git a/src/recorder.c b/src/recorder.c index 1907c35..9654fd0 100644 --- a/src/recorder.c +++ b/src/recorder.c @@ -28,6 +28,9 @@ #include #include #include +#include +#include +#include #ifdef LOG_TAG #undef LOG_TAG @@ -35,6 +38,7 @@ #define LOG_TAG "TIZEN_N_RECORDER" #define LOWSET_DECIBEL -300.0 +#define RECORDER_PATH_RECORDER_RESOURCE "/usr/share/sounds/mm-camcorder/recorder_resource" /* @@ -68,14 +72,16 @@ static int __convert_error_code_camera_to_recorder(int code){ case CAMERA_ERROR_SECURITY_RESTRICTED: new_code = RECORDER_ERROR_SECURITY_RESTRICTED; break; + default: + break; } return new_code; } static int __convert_recorder_error_code(const char *func, int code){ int ret = RECORDER_ERROR_INVALID_OPERATION; - char *errorstr = NULL; - + const char *errorstr = NULL; + switch(code) { case RECORDER_ERROR_INVALID_PARAMETER: @@ -88,13 +94,16 @@ static int __convert_recorder_error_code(const char *func, int code){ break; case MM_ERROR_CAMCORDER_INVALID_ARGUMENT : case MM_ERROR_COMMON_INVALID_ATTRTYPE : - case MM_ERROR_COMMON_INVALID_PERMISSION : case MM_ERROR_COMMON_OUT_OF_ARRAY : case MM_ERROR_COMMON_OUT_OF_RANGE : case MM_ERROR_COMMON_ATTR_NOT_EXIST : ret = RECORDER_ERROR_INVALID_PARAMETER; errorstr = "INVALID_PARAMETER"; break; + case MM_ERROR_COMMON_INVALID_PERMISSION : + ret = RECORDER_ERROR_PERMISSION_DENIED; + errorstr = "ERROR_PERMISSION_DENIED"; + break; case MM_ERROR_CAMCORDER_NOT_INITIALIZED : case MM_ERROR_CAMCORDER_INVALID_STATE : ret = RECORDER_ERROR_INVALID_STATE; @@ -256,18 +265,18 @@ static int __mm_recorder_msg_cb(int message, void *param, void *user_data){ ((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]); } // should change intermediate state MM_CAMCORDER_STATE_READY is not valid in capi , change to NULL state - if( policy != RECORDER_POLICY_NONE ){ - if( previous_state != handle->state && handle->user_cb[_RECORDER_EVENT_TYPE_INTERRUPTED] ){ + if (policy != RECORDER_POLICY_NONE && + (m->state.current == MM_CAMCORDER_STATE_PAUSED || m->state.current == MM_CAMCORDER_STATE_NULL)) { + if (handle->user_cb[_RECORDER_EVENT_TYPE_INTERRUPTED]) { ((recorder_interrupted_cb)handle->user_cb[_RECORDER_EVENT_TYPE_INTERRUPTED])(policy, previous_state, handle->state, handle->user_data[_RECORDER_EVENT_TYPE_INTERRUPTED]); - } - if( m->state.previous == MM_CAMCORDER_STATE_PREPARE && m->state.current == MM_CAMCORDER_STATE_PREPARE ){ - mm_camcorder_unrealize(handle->mm_handle); + } else { + LOGW("_RECORDER_EVENT_TYPE_INTERRUPTED cb is NULL"); } } - + break; case MM_MESSAGE_CAMCORDER_MAX_SIZE: - case MM_MESSAGE_CAMCORDER_NO_FREE_SPACE: + case MM_MESSAGE_CAMCORDER_NO_FREE_SPACE: case MM_MESSAGE_CAMCORDER_TIME_LIMIT: { recorder_recording_limit_type_e type ; @@ -339,6 +348,9 @@ static int __mm_recorder_msg_cb(int message, void *param, void *user_data){ case MM_ERROR_OUT_OF_STORAGE: recorder_error = RECORDER_ERROR_OUT_OF_STORAGE; break; + default: + recorder_error = RECORDER_ERROR_INVALID_OPERATION; + break; } if( recorder_error != 0 && handle->user_cb[_RECORDER_EVENT_TYPE_ERROR] ) ((recorder_error_cb)handle->user_cb[_RECORDER_EVENT_TYPE_ERROR])(errorcode, handle->state , handle->user_data[_RECORDER_EVENT_TYPE_ERROR]); @@ -348,6 +360,8 @@ static int __mm_recorder_msg_cb(int message, void *param, void *user_data){ if( handle->last_max_input_level < m->rec_volume_dB ) handle->last_max_input_level = m->rec_volume_dB; break; + default: + break; } return 1; @@ -374,29 +388,48 @@ static int __mm_audio_stream_cb(MMCamcorderAudioStreamDataType *stream, void *us } -int recorder_create_videorecorder( camera_h camera, recorder_h* recorder){ +int recorder_create_videorecorder(camera_h camera, recorder_h* recorder) +{ + int resource_fd = -1; + recorder_s * handle = NULL; + int preview_format = MM_PIXEL_FORMAT_NV12; + if( camera == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); - recorder_s * handle; - int preview_format; - //Check already used in another recorder if( _camera_is_used(camera)){ LOGE("[%s] camera is using in another recorder.", __func__); return RECORDER_ERROR_INVALID_PARAMETER; } + resource_fd = open(RECORDER_PATH_RECORDER_RESOURCE, O_RDONLY); + if (resource_fd < 0) { + LOGE("failed to open recorder resource : errno [%d]", errno); + if (errno == EPERM || errno == EACCES) { + LOGE("permission denied"); + return RECORDER_ERROR_PERMISSION_DENIED; + } else { + LOGE("invalid operation"); + return RECORDER_ERROR_INVALID_OPERATION; + } + } + + close(resource_fd); + resource_fd = -1; + + LOGW("permission check done"); + handle = (recorder_s*)malloc( sizeof(recorder_s) ); if(handle == NULL){ LOGE("[%s] malloc error", __func__); return RECORDER_ERROR_OUT_OF_MEMORY; } - memset(handle, 0 , sizeof(recorder_s)); + memset(handle, 0 , sizeof(recorder_s)); handle->last_max_input_level = LOWSET_DECIBEL; handle->changed_preview_format = -1; - handle->camera = camera; + handle->mm_source.camera = camera; _camera_set_use(camera, true); _camera_get_mm_handle(camera, &handle->mm_handle); @@ -419,23 +452,23 @@ int recorder_create_videorecorder( camera_h camera, recorder_h* recorder){ } int recorder_create_audiorecorder( recorder_h* recorder){ - + if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); - - int ret; + + int ret = MM_ERROR_NONE; recorder_s * handle; MMCamPreset info; info.videodev_type= MM_VIDEO_DEVICE_NONE; - + handle = (recorder_s*)malloc( sizeof(recorder_s) ); if(handle==NULL){ LOGE( "[%s] OUT_OF_MEMORY(0x%08x)", __func__, RECORDER_ERROR_OUT_OF_MEMORY); return RECORDER_ERROR_OUT_OF_MEMORY; } - + memset(handle, 0 , sizeof(recorder_s)); handle->last_max_input_level = LOWSET_DECIBEL; - + ret = mm_camcorder_create(&handle->mm_handle, &info); if( ret != MM_ERROR_NONE){ free(handle); @@ -456,7 +489,7 @@ int recorder_create_audiorecorder( recorder_h* recorder){ handle->state = RECORDER_STATE_CREATED; mm_camcorder_set_message_callback(handle->mm_handle, __mm_recorder_msg_cb, (void*)handle); - handle->camera = NULL; + handle->mm_source.camera = NULL; handle->type = _RECORDER_TYPE_AUDIO; *recorder = (recorder_h)handle; @@ -467,7 +500,6 @@ int recorder_create_audiorecorder( recorder_h* recorder){ int recorder_get_state(recorder_h recorder, recorder_state_e * state){ - if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); if( state == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); @@ -475,30 +507,29 @@ int recorder_get_state(recorder_h recorder, recorder_state_e * state){ MMCamcorderStateType mmstate ; recorder_state_e capi_state; - mm_camcorder_get_state(handle->mm_handle, &mmstate); + mm_camcorder_get_state(handle->mm_handle, &mmstate); capi_state = __recorder_state_convert(mmstate); *state = capi_state; - return CAMERA_ERROR_NONE; - + return RECORDER_ERROR_NONE; } int recorder_destroy( recorder_h recorder){ if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); recorder_s * handle; - int ret = RECORDER_ERROR_NONE; + int ret = MM_ERROR_NONE; handle = (recorder_s *) recorder; if( handle->type == _RECORDER_TYPE_VIDEO ){ //set to unsed - _camera_set_use(handle->camera, false); + _camera_set_use(handle->mm_source.camera, false); int preview_format; mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_FORMAT, &preview_format, NULL); // preview format was changed? if( preview_format == handle->changed_preview_format ){ mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_FORMAT, handle->origin_preview_format,(void*)NULL); } - _camera_set_relay_mm_message_callback(handle->camera , NULL, NULL); + _camera_set_relay_mm_message_callback(handle->mm_source.camera , NULL, NULL); }else{ ret = mm_camcorder_destroy(handle->mm_handle); } @@ -511,20 +542,19 @@ int recorder_destroy( recorder_h recorder){ } int recorder_prepare( recorder_h recorder){ - if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); - int ret = 0; + int ret = MM_ERROR_NONE; recorder_s *handle = (recorder_s*)recorder; if( handle->type == _RECORDER_TYPE_VIDEO ){ - return __convert_error_code_camera_to_recorder(camera_start_preview(handle->camera)); + return __convert_error_code_camera_to_recorder(camera_start_preview(handle->mm_source.camera)); } MMCamcorderStateType mmstate ; mm_camcorder_get_state(handle->mm_handle, &mmstate); if( mmstate != MM_CAMCORDER_STATE_READY){ - ret = mm_camcorder_realize(handle->mm_handle); + ret = mm_camcorder_realize(handle->mm_handle); if( ret != MM_ERROR_NONE){ LOGE("[%s] mm_camcorder_realize fail", __func__); return __convert_recorder_error_code(__func__, ret); @@ -534,26 +564,26 @@ int recorder_prepare( recorder_h recorder){ ret = mm_camcorder_start(handle->mm_handle); if( ret != MM_ERROR_NONE){ - LOGE("[%s] mm_camcorder_start fail", __func__); + LOGE("[%s] mm_camcorder_start fail", __func__); mm_camcorder_unrealize(handle->mm_handle); return __convert_recorder_error_code(__func__, ret); - } + } return RECORDER_ERROR_NONE; } int recorder_unprepare( recorder_h recorder){ if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); - int ret = 0; + int ret = MM_ERROR_NONE; recorder_s *handle = (recorder_s*)recorder; MMCamcorderStateType mmstate ; - mm_camcorder_get_state(handle->mm_handle, &mmstate); - + mm_camcorder_get_state(handle->mm_handle, &mmstate); + if( mmstate == MM_CAMCORDER_STATE_PREPARE){ - ret = mm_camcorder_stop(handle->mm_handle); + ret = mm_camcorder_stop(handle->mm_handle); if( ret != MM_ERROR_NONE){ - LOGE("[%s] mm_camcorder_stop fail", __func__); + LOGE("[%s] mm_camcorder_stop fail", __func__); return __convert_recorder_error_code(__func__, ret); } } @@ -562,18 +592,16 @@ int recorder_unprepare( recorder_h recorder){ } int recorder_start( recorder_h recorder){ - if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); - int ret; + int ret = MM_ERROR_NONE; recorder_s *handle = (recorder_s*)recorder; ret = mm_camcorder_record(handle->mm_handle); return __convert_recorder_error_code(__func__, ret); } int recorder_pause( recorder_h recorder){ - if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); - int ret; + int ret = MM_ERROR_NONE; recorder_s *handle = (recorder_s*)recorder; ret = mm_camcorder_pause(handle->mm_handle); @@ -581,23 +609,98 @@ int recorder_pause( recorder_h recorder){ } int recorder_commit( recorder_h recorder){ - if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); - int ret; + int ret = MM_ERROR_NONE; recorder_s *handle = (recorder_s*)recorder; ret = mm_camcorder_commit(handle->mm_handle); - return __convert_recorder_error_code(__func__, ret); + return __convert_recorder_error_code(__func__, ret); } int recorder_cancel( recorder_h recorder){ - if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); - int ret; + int ret = MM_ERROR_NONE; recorder_s *handle = (recorder_s*)recorder; ret = mm_camcorder_cancel(handle->mm_handle); - return __convert_recorder_error_code(__func__, ret); + return __convert_recorder_error_code(__func__, ret); +} + + +int recorder_set_video_resolution(recorder_h recorder, int width, int height) +{ + int ret = MM_ERROR_NONE; + recorder_s *handle = (recorder_s*)recorder; + recorder_state_e state; + + if (!handle || !width || !height) { + LOGE("NULL pointer %p %p %p", handle, width, height); + return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); + } + + recorder_get_state(recorder, &state); + if (state > RECORDER_STATE_READY) { + LOGE("RECORDER_ERROR_INVALID_STATE (state:%d)", state); + return RECORDER_ERROR_INVALID_STATE; + } + + ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, + MMCAM_VIDEO_WIDTH, width, + MMCAM_VIDEO_HEIGHT, height, + NULL); + + return __convert_recorder_error_code(__func__, ret); } + +int recorder_get_video_resolution(recorder_h recorder, int *width, int *height) +{ + int ret = MM_ERROR_NONE; + recorder_s *handle = (recorder_s*)recorder; + + if (!handle || !width || !height) { + LOGE("NULL pointer %p %p %p", handle, width, height); + return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); + } + + ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, + MMCAM_VIDEO_WIDTH, width, + MMCAM_VIDEO_HEIGHT, height, + NULL); + + return __convert_recorder_error_code(__func__, ret); +} + + +int recorder_foreach_supported_video_resolution(recorder_h recorder, + recorder_supported_video_resolution_cb foreach_cb, void *user_data) +{ + int i = 0; + int ret = MM_ERROR_NONE; + recorder_s * handle = (recorder_s*)recorder; + MMCamAttrsInfo video_width; + MMCamAttrsInfo video_height; + + if (!handle || !foreach_cb) { + LOGE("NULL pointer %p %p", handle, foreach_cb); + return RECORDER_ERROR_INVALID_PARAMETER; + } + + ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_VIDEO_WIDTH , &video_width); + ret |= mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_VIDEO_HEIGHT , &video_height); + + if (ret != MM_ERROR_NONE ) { + return __convert_recorder_error_code(__func__, ret); + } + + for (i = 0 ; i < video_width.int_array.count ; i++) { + if (!foreach_cb(video_width.int_array.array[i], video_height.int_array.array[i], user_data)) { + break; + } + } + + return RECORDER_ERROR_NONE; +} + + int recorder_get_audio_level(recorder_h recorder, double *level){ if( recorder == NULL || level == NULL ) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); recorder_s *handle = (recorder_s*)recorder; @@ -615,10 +718,9 @@ int recorder_get_audio_level(recorder_h recorder, double *level){ } int recorder_set_filename(recorder_h recorder, const char *filename){ - if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); g_return_val_if_fail(filename != NULL, RECORDER_ERROR_INVALID_PARAMETER); - int ret; + int ret = MM_ERROR_NONE; recorder_s * handle = (recorder_s*)recorder; ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_TARGET_FILENAME , filename , strlen(filename), NULL); return __convert_recorder_error_code(__func__, ret); @@ -626,27 +728,29 @@ int recorder_set_filename(recorder_h recorder, const char *filename){ } int recorder_get_filename(recorder_h recorder, char **filename){ - if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); g_return_val_if_fail(filename != NULL, RECORDER_ERROR_INVALID_PARAMETER); - int ret; + int ret = MM_ERROR_NONE; recorder_s * handle = (recorder_s*)recorder; - char *record_filename; + char *record_filename = NULL; int record_filename_size; ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_TARGET_FILENAME , &record_filename, &record_filename_size, NULL); - if( ret == CAMERA_ERROR_NONE ){ + + if( ret == MM_ERROR_NONE && record_filename) { *filename = strdup(record_filename); + } else { + LOGE("internal return (0x%08x), get filename p:%p", ret, record_filename); + *filename = NULL; } return __convert_recorder_error_code(__func__, ret); - } int recorder_set_file_format(recorder_h recorder, recorder_file_format_e format) { - int ret; + int ret = MM_ERROR_NONE; int format_table[6] = { MM_FILE_FORMAT_3GP, //RECORDER_FILE_FORMAT_3GP MM_FILE_FORMAT_MP4, //RECORDER_FILE_FORMAT_MP4 MM_FILE_FORMAT_AMR, //RECORDER_FILE_FORMAT_AMR @@ -672,11 +776,9 @@ int recorder_set_file_format(recorder_h recorder, recorder_file_format_e format) } int recorder_get_file_format(recorder_h recorder, recorder_file_format_e *format){ - if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); - g_return_val_if_fail(format != NULL, RECORDER_ERROR_INVALID_PARAMETER); - - int ret; + g_return_val_if_fail(format != NULL, RECORDER_ERROR_INVALID_PARAMETER); + int ret = MM_ERROR_NONE; recorder_s * handle = (recorder_s*)recorder; int mm_format; ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_FILE_FORMAT , &mm_format, NULL); @@ -709,35 +811,29 @@ int recorder_get_file_format(recorder_h recorder, recorder_file_format_e *format return __convert_recorder_error_code(__func__, ret); } - - int recorder_set_state_changed_cb(recorder_h recorder, recorder_state_changed_cb callback, void* user_data){ - - if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); + if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); recorder_s *handle = (recorder_s*)recorder; if( callback == NULL ) return RECORDER_ERROR_INVALID_PARAMETER; - handle->user_cb[_RECORDER_EVENT_TYPE_STATE_CHANGE] = callback; handle->user_data[_RECORDER_EVENT_TYPE_STATE_CHANGE] = user_data; return RECORDER_ERROR_NONE; - } int recorder_unset_state_changed_cb(recorder_h recorder){ - - if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); + if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); recorder_s *handle = (recorder_s*)recorder; handle->user_cb[_RECORDER_EVENT_TYPE_STATE_CHANGE] = NULL; handle->user_data[_RECORDER_EVENT_TYPE_STATE_CHANGE] = NULL; - return RECORDER_ERROR_NONE; + return RECORDER_ERROR_NONE; } int recorder_set_interrupted_cb(recorder_h recorder, recorder_interrupted_cb callback, void *user_data){ - if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); + if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); recorder_s *handle = (recorder_s*)recorder; if( callback == NULL ) return RECORDER_ERROR_INVALID_PARAMETER; @@ -748,7 +844,7 @@ int recorder_set_interrupted_cb(recorder_h recorder, recorder_interrupted_cb cal return RECORDER_ERROR_NONE; } int recorder_unset_interrupted_cb(recorder_h recorder){ - if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); + if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); recorder_s *handle = (recorder_s*)recorder; handle->user_cb[_RECORDER_EVENT_TYPE_INTERRUPTED] = NULL; @@ -844,22 +940,20 @@ int recorder_unset_recording_limit_reached_cb(recorder_h recorder){ } int recorder_foreach_supported_file_format(recorder_h recorder, recorder_supported_file_format_cb foreach_cb , void *user_data){ - if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); if( foreach_cb == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); int ret; recorder_s * handle = (recorder_s*)recorder; MMCamAttrsInfo info; ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_FILE_FORMAT , &info); - if( ret != RECORDER_ERROR_NONE ) + if( ret != MM_ERROR_NONE ) return ret; - int i; for( i=0 ; i < info.int_array.count ; i++) { int format; - + switch( info.int_array.array[i] ){ case MM_FILE_FORMAT_3GP: format = RECORDER_FILE_FORMAT_3GP; @@ -884,42 +978,37 @@ int recorder_foreach_supported_file_format(recorder_h recorder, recorder_support break; } return RECORDER_ERROR_NONE; - + } int recorder_attr_set_size_limit(recorder_h recorder, int kbyte){ - if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); int ret; recorder_s * handle = (recorder_s*)recorder; ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, "target-max-size" , kbyte, NULL); return __convert_recorder_error_code(__func__, ret); - } int recorder_attr_set_time_limit(recorder_h recorder, int second){ - - if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); + if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); int ret; recorder_s * handle = (recorder_s*)recorder; ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_TARGET_TIME_LIMIT , second, NULL); - return __convert_recorder_error_code(__func__, ret); + return __convert_recorder_error_code(__func__, ret); } int recorder_attr_set_audio_device(recorder_h recorder , recorder_audio_device_e device){ - - if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); + if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); int ret; recorder_s * handle = (recorder_s*)recorder; ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_AUDIO_DEVICE , device, NULL); - return __convert_recorder_error_code(__func__, ret); + return __convert_recorder_error_code(__func__, ret); } int recorder_set_audio_encoder(recorder_h recorder, recorder_audio_codec_e codec){ - - if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); + if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); if( codec != RECORDER_AUDIO_CODEC_DISABLE && ( codec < RECORDER_AUDIO_CODEC_AMR || codec > RECORDER_AUDIO_CODEC_PCM) ) return RECORDER_ERROR_INVALID_PARAMETER; @@ -929,7 +1018,7 @@ int recorder_set_audio_encoder(recorder_h recorder, recorder_audio_codec_e code MM_AUDIO_CODEC_VORBIS, //RECORDER_AUDIO_CODEC_VORBIS MM_AUDIO_CODEC_WAVE //RECORDER_AUDIO_CODEC_PCM }; - int ret; + int ret = MM_ERROR_NONE; recorder_s * handle = (recorder_s*)recorder; if( codec == RECORDER_AUDIO_CODEC_DISABLE ) ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_AUDIO_DISABLE , 1, NULL); @@ -937,17 +1026,15 @@ int recorder_set_audio_encoder(recorder_h recorder, recorder_audio_codec_e code ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_AUDIO_ENCODER , audio_table[codec], MMCAM_AUDIO_DISABLE, 0, NULL); return __convert_recorder_error_code(__func__, ret); - } int recorder_get_audio_encoder(recorder_h recorder, recorder_audio_codec_e *codec){ - - if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); - g_return_val_if_fail(codec != NULL, RECORDER_ERROR_INVALID_PARAMETER); - int ret; + if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); + g_return_val_if_fail(codec != NULL, RECORDER_ERROR_INVALID_PARAMETER); + int ret = MM_ERROR_NONE; int mm_codec = 0; int audio_disable = 0; - + recorder_s * handle = (recorder_s*)recorder; ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_AUDIO_ENCODER , &mm_codec , MMCAM_AUDIO_DISABLE, &audio_disable, NULL); if( ret == 0 && audio_disable == 0 ){ @@ -971,14 +1058,13 @@ int recorder_get_audio_encoder(recorder_h recorder, recorder_audio_codec_e *code }else if( ret == 0 && audio_disable ){ *codec = RECORDER_AUDIO_CODEC_DISABLE; } - - return __convert_recorder_error_code(__func__, ret); + + return __convert_recorder_error_code(__func__, ret); } int recorder_set_video_encoder(recorder_h recorder, recorder_video_codec_e codec){ - - if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); - int ret; + if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); + int ret = MM_ERROR_NONE; int video_table[4] = { MM_VIDEO_CODEC_H263, //RECORDER_VIDEO_CODEC_H263, /**< H263 codec */ MM_VIDEO_CODEC_H264, //RECORDER_VIDEO_CODEC_H264, /**< H264 codec */ @@ -993,12 +1079,9 @@ int recorder_set_video_encoder(recorder_h recorder, recorder_video_codec_e code return __convert_recorder_error_code(__func__, ret); } - - int recorder_get_video_encoder(recorder_h recorder, recorder_video_codec_e *codec){ - - if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); - if( codec == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); + if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); + if( codec == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); int ret; int mm_codec = 0; @@ -1026,107 +1109,88 @@ int recorder_get_video_encoder(recorder_h recorder, recorder_video_codec_e *code } return __convert_recorder_error_code(__func__, ret); - } int recorder_attr_set_audio_samplerate(recorder_h recorder, int samplerate){ - - if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); - int ret; + if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); + int ret = MM_ERROR_NONE; recorder_s * handle = (recorder_s*)recorder; ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_AUDIO_SAMPLERATE , samplerate, NULL); return __convert_recorder_error_code(__func__, ret); - } int recorder_attr_set_audio_encoder_bitrate(recorder_h recorder, int bitrate){ - - if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); - int ret; + if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); + int ret = MM_ERROR_NONE; recorder_s * handle = (recorder_s*)recorder; ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_AUDIO_ENCODER_BITRATE , bitrate, NULL); return __convert_recorder_error_code(__func__, ret); - } int recorder_attr_set_video_encoder_bitrate(recorder_h recorder, int bitrate){ - - if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); - int ret; + if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); + int ret = MM_ERROR_NONE; recorder_s * handle = (recorder_s*)recorder; ret = mm_camcorder_set_attributes(handle->mm_handle ,NULL, MMCAM_VIDEO_ENCODER_BITRATE , bitrate, NULL); return __convert_recorder_error_code(__func__, ret); - } int recorder_attr_get_size_limit(recorder_h recorder, int *kbyte){ - - if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); + if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); int ret; recorder_s * handle = (recorder_s*)recorder; ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, "target-max-size" , kbyte, NULL); - return __convert_recorder_error_code(__func__, ret); + return __convert_recorder_error_code(__func__, ret); } int recorder_attr_get_time_limit(recorder_h recorder, int *second){ - - if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); + if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); int ret; recorder_s * handle = (recorder_s*)recorder; ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_TARGET_TIME_LIMIT , second, NULL); return __convert_recorder_error_code(__func__, ret); - } int recorder_attr_get_audio_device(recorder_h recorder , recorder_audio_device_e *device){ - - if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); + if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); int ret; recorder_s * handle = (recorder_s*)recorder; ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_AUDIO_DEVICE , device, NULL); - return __convert_recorder_error_code(__func__, ret); + return __convert_recorder_error_code(__func__, ret); } - - int recorder_attr_get_audio_samplerate(recorder_h recorder, int *samplerate){ - - if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); - int ret; + if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); + int ret = MM_ERROR_NONE; recorder_s * handle = (recorder_s*)recorder; ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_AUDIO_SAMPLERATE , samplerate, NULL); return __convert_recorder_error_code(__func__, ret); - } int recorder_attr_get_audio_encoder_bitrate(recorder_h recorder, int *bitrate){ - - if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); - int ret; + if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); + int ret = MM_ERROR_NONE; recorder_s * handle = (recorder_s*)recorder; ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_AUDIO_ENCODER_BITRATE , bitrate, NULL); return __convert_recorder_error_code(__func__, ret); } int recorder_attr_get_video_encoder_bitrate(recorder_h recorder, int *bitrate){ - - if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); - int ret; + if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); + int ret = MM_ERROR_NONE; recorder_s * handle = (recorder_s*)recorder; ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_VIDEO_ENCODER_BITRATE , bitrate, NULL); return __convert_recorder_error_code(__func__, ret); - } int recorder_foreach_supported_audio_encoder(recorder_h recorder, recorder_supported_audio_encoder_cb foreach_cb , void *user_data){ - - if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); - if( foreach_cb == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); + if( recorder == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); + if( foreach_cb == NULL) return __convert_recorder_error_code(__func__, RECORDER_ERROR_INVALID_PARAMETER); int ret; recorder_s * handle = (recorder_s*)recorder; MMCamAttrsInfo info; ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_AUDIO_ENCODER , &info); - if( ret != RECORDER_ERROR_NONE ) + if( ret != MM_ERROR_NONE ) return __convert_recorder_error_code(__func__, ret); int i; @@ -1163,7 +1227,7 @@ int recorder_foreach_supported_video_encoder(recorder_h recorder, recorder_suppo recorder_s * handle = (recorder_s*)recorder; MMCamAttrsInfo info; ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_VIDEO_ENCODER , &info); - if( ret != RECORDER_ERROR_NONE ) + if( ret != MM_ERROR_NONE ) return __convert_recorder_error_code(__func__, ret); int i; @@ -1210,7 +1274,9 @@ bool recorder_attr_is_muted(recorder_h recorder){ } recorder_s * handle = (recorder_s*)recorder; double volume = 1.0; - mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_AUDIO_VOLUME , &volume , NULL); + int ret = mm_camcorder_get_attributes(handle->mm_handle ,NULL, MMCAM_AUDIO_VOLUME , &volume , NULL); + + set_last_result(__convert_recorder_error_code(__func__, ret)); if( volume == 0.0 ) return true; else