2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.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
8 * http://floralicense.org/license/
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.
19 #include <X11/keysymdef.h>
26 #include "cam_sound.h"
29 #include "cam_error.h"
32 #include "cam_indicator_edc_callback.h"
33 #include "cam_recording_edc_callback.h"
34 #include "camera_utils.h"
35 #include "cam_popup.h"
37 #include "cam_common_edc_callback.h"
38 #include "cam_toolbar_edc_callback.h"
40 #ifdef USE_CAMERA_APP_SHUTTER_SOUND
41 static gint __cam_rec_sound_index_get(gint setting_index, gboolean start)
45 if (start) { /* start sound */
46 switch (setting_index) {
47 case CAM_SETTINGS_SOUND_1:
48 index = CAM_SOUND_EFFECT_REC_START3;
50 case CAM_SETTINGS_SOUND_2:
51 index = CAM_SOUND_EFFECT_REC_START2;
53 case CAM_SETTINGS_SOUND_3:
54 index = CAM_SOUND_EFFECT_REC_START3;
60 } else { /* commit sound */
61 switch (setting_index) {
63 case CAM_SETTINGS_SOUND_1:
64 index = CAM_SOUND_EFFECT_REC_COMMIT3;
66 case CAM_SETTINGS_SOUND_2:
67 index = CAM_SOUND_EFFECT_REC_COMMIT2;
69 case CAM_SETTINGS_SOUND_3:
70 index = CAM_SOUND_EFFECT_REC_COMMIT3;
79 static gchar *__get_tmpfile_name()
81 char tmpfile_name[256] = { 0 };
82 gchar *file_path = NULL;
83 file_path = (gchar *)cam_app_get_target_path();
85 snprintf(tmpfile_name, sizeof(tmpfile_name), "%s%s", file_path,
87 DEBUG_TRACE("#####################tmpfile_name=%s", tmpfile_name);
89 if (g_file_test(tmpfile_name, G_FILE_TEST_EXISTS)) {
90 DEBUG_TRACE("Error : tmp file exist on the %s", file_path);
91 cam_remove_tmp_file();
94 return g_strdup(tmpfile_name);
97 gboolean cam_video_record_start(void *data)
99 struct appdata *ad = (struct appdata *)data;
100 CamAppData *camapp = NULL;
101 gchar *filename = NULL;
105 debug_fenter(LOG_UI);
107 cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
108 camapp = ad->camapp_handle;
109 cam_retvm_if(camapp == NULL, FALSE, "camapp_handle is NULL");
111 if (ad->is_recording == TRUE) {
112 DEBUG_TRACE("Camera app is recording");
115 cam_critical(LOG_UI, "start reocrd");
118 if (ad->is_rotating == TRUE) {
119 DEBUG_TRACE("now in rotating target, do not start recording");
123 DEBUG_TRACE("start recording !!");
125 if (ad->timer_activated) {
126 CAM_UI_LOG("timer activated!");
129 gchar* target_path = (gchar*)cam_app_get_target_path();
130 if (target_path != NULL) {
131 remain = cam_get_free_space(target_path);
134 if (remain <= REC_MMS_MIN_SPACE) {
135 cam_app_notice_popup(ad, dgettext(PACKAGE, "IDS_CAM_BODY_UNABLE_TO_SAVE_NOT_ENOUGH_MEMORY"),
136 cam_app_popup_response_cb);
141 int gps_level = CAM_LBS_STATE_DISABLE;
142 gps_level = cam_lbs_get_state();
143 if (gps_level >=CAM_LBS_STATE_SERVICE_ENABLE) {
144 double longitude = -1.0;
145 double latitude = -1.0;
146 double altitude = -1.0;
147 time_t time_stamp = -1.0;
148 if (cam_lbs_get_current_position(&longitude, &latitude, &altitude, &time_stamp)) {
149 DEBUG_TRACE("GEO TAG [longitude = %d, latitude = %d, altitude = %d]", longitude, latitude, altitude);
150 if ( !cam_mm_set_gps_data(latitude, longitude, (double)altitude))
151 DEBUG_TRACE("cam_mm_set_gps_data failed");
156 filename = __get_tmpfile_name();
159 cam_debug(LOG_UI, "FILE NAME : %s", filename);
160 if (!cam_mm_set_filename(filename)) {
161 cam_critical(LOG_MM, "cannot set filename");
167 cam_critical(LOG_MM, "cannot get filename");
172 if (camapp->flash == CAM_FLASH_ON) {
173 if (!cam_mm_set_flash(CAM_FLASH_MOVIE_ON)) {
174 cam_critical(LOG_MM, "cam_mm_set_flash failed");
177 if (!cam_mm_set_flash(CAM_FLASH_OFF)) {
178 cam_critical(LOG_MM, "cam_mm_set_flash failed");
182 #ifdef USE_CAMERA_APP_SHUTTER_SOUND
183 /* play start effect sound */
184 cam_sound_play(__cam_rec_sound_index_get(camapp->shutter_sound, TRUE),
187 /* set sound path for recording MIC */
191 cam_set_orient_value(ad);
194 if (!cam_mm_rec_start(NULL)) {
195 cam_critical(LOG_MM, "cam_mm_rec_start failed");
196 cam_app_notice_popup(data,
197 dgettext(PACKAGE, "IDS_CAM_POP_ERROR_RECORDING_FAIL"),
198 cam_app_timeout_notice_response_cb);
201 /* set recording state */
202 ad->is_recording = TRUE;
204 /* change recording view */
206 if (load_recording_edje(ad)) {
207 cam_critical(LOG_UI, "load_recording_edje failed");
208 cam_video_record_cancel(ad);
212 if (ad->indicator_edje)
213 cam_indicator_update(ad);
215 cam_indicator_create(ad);
217 settings_guideline_refresh(ad);
221 gboolean cam_video_record_resume(void *data)
223 struct appdata *ad = (struct appdata *)data;
224 cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
226 if (!cam_mm_rec_start(NULL)) {
227 cam_critical(LOG_MM, "cam_mm_rec_start failed");
228 cam_app_notice_popup(data,
229 dgettext(PACKAGE, "IDS_CAM_POP_ERROR_RECORDING_FAIL"),
230 cam_app_timeout_notice_response_cb);
237 gboolean cam_video_record_pause(void *data)
239 struct appdata *ad = (struct appdata *)data;
240 cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
242 if (!cam_mm_rec_pause(NULL)) {
243 cam_critical(LOG_MM, "cam_mm_rec_start failed");
248 Eina_Bool cam_video_idler_record_stop(void *data)
250 struct appdata *ad = (struct appdata *)data;
251 cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
253 cam_video_record_stop(ad);
255 return ECORE_CALLBACK_CANCEL;
258 gboolean cam_video_record_stop(void *data)
260 struct appdata *ad = (struct appdata *)data;
261 CamAppData *camapp = NULL;
262 gboolean to_stop = FALSE;
264 debug_fenter(LOG_UI);
266 cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
267 camapp = ad->camapp_handle;
268 cam_retvm_if(camapp == NULL, FALSE, "camapp_handle is NULL");
270 if (ad->recording_commit) {
271 ecore_idler_del(ad->recording_commit);
272 ad->recording_commit = NULL;
274 /* check to_stop val */
276 if (!cam_mm_stop_focusing()){
277 cam_critical(LOG_MM, "cam_mm_stop_focusing error ");
280 if (!cam_mm_rec_stop(to_stop)) {
281 cam_critical(LOG_MM, "cam_mm_rec_stop failed");
282 if (!cam_mm_rec_cancel())
283 cam_critical(LOG_MM, "cam_mm_rec_cancel failed");
285 cam_app_notice_popup(data,
286 dgettext(PACKAGE, "IDS_CAM_POP_ERROR_RECORDING_FAIL"),
287 cam_app_timeout_notice_response_cb);
291 if (!cam_mm_set_flash(camapp->flash)) {
292 cam_critical(LOG_MM, "cam_mm_set_flash failed");
295 /* set sound path for effect sound */
296 #ifdef USE_CAMERA_APP_SHUTTER_SOUND
297 /* play end effect sound */
298 cam_sound_play(__cam_rec_sound_index_get(camapp->shutter_sound, FALSE), ad);
300 /* cam_sound_play(CAM_SOUND_EFFECT_REC_COMMIT); */
305 gboolean cam_video_record_cancel(void *data)
307 struct appdata *ad = (struct appdata *)data;
308 CamAppData *camapp = NULL;
310 debug_fenter(LOG_UI);
312 cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
313 camapp = ad->camapp_handle;
314 cam_retvm_if(camapp == NULL, FALSE, "camapp_handle is NULL");
317 if (!cam_mm_rec_cancel(NULL)) {
318 cam_critical(LOG_MM, "cam_mm_rec_cancel failed");
321 /* change to camera mode*/
323 * TODO: if for any reason, not run here, there will be caused now now recording, but in record mode
324 * So: I suggest while click capture button: judge now state and whether recording.
327 if(ad->launching_mode == CAM_LAUNCHING_MODE_NORMAL) {
328 if (ad->ug_state != CAM_UG_PAUSE_STATE) {/*if now is pause state, so do not set mode, just set while resume*/
330 GValue value = {0, };
331 CAM_GVALUE_SET_INT(value, CAM_CAMERA_MODE);
332 if (!cam_handle_value_set(ad, PROP_MODE, &value)) {
336 cam_app_update_quickview_icon(ad);
340 unload_recording_edje(ad);
341 camapp->rec_elapsed = 0;
342 cam_toolbar_update(ad);
344 if (ad->indicator_edje)
345 cam_indicator_update(ad);
347 cam_indicator_create(ad);
349 settings_guideline_refresh(ad);
350 cam_remove_tmp_file();
354 /* Idler of capture callback management. wh01.cho@samsung.com. 2010-12-15. */
355 Eina_Bool cam_video_capture_handle_idler(void *itm)
357 CamIdlerItem *item = (CamIdlerItem *) itm;
358 struct appdata *ad = NULL;
359 cam_retvm_if(!item, ECORE_CALLBACK_CANCEL, "CamIdlerItem is NULL");
361 ad = (struct appdata *)item->data;
362 cam_retvm_if(!ad, ECORE_CALLBACK_CANCEL, "appdata is NULL");
364 ad->capture_cb_list = g_list_remove(ad->capture_cb_list, item->idler);
368 return cam_video_capture_handle(ad);
371 gboolean cam_rec_save_and_register_video_file(void *data)
373 struct appdata *ad = (struct appdata *)data;
374 CamAppData *camapp = NULL;
375 cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
376 camapp = ad->camapp_handle;
377 cam_retvm_if(camapp == NULL, FALSE, "camapp_handle is NULL");
378 cam_retv_if(camapp->filename == NULL, FALSE);
380 GError *error = NULL;
381 cam_debug(LOG_FILE, "tmp file : %s", camapp->filename);
383 gchar *filename = NULL;
384 filename = cam_app_get_next_filename(CAM_FILE_EXTENTION_VIDEO);
387 cam_debug(LOG_UI, "FILE NAME : %s", filename);
391 ret = rename(camapp->filename, filename);
394 cam_critical(LOG_FILE, "rename is error %d", ret );
397 free(camapp->filename);
398 camapp->filename = strdup(filename);
403 if (!g_file_test(camapp->filename, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
404 cam_critical(LOG_FILE, "The File is not existed %s",camapp->filename );
405 return ECORE_CALLBACK_CANCEL;
408 cam_critical(LOG_MM, "cannot get filename");
409 return ECORE_CALLBACK_CANCEL;
411 if (!cam_file_register(camapp->filename, &error)) {
412 cam_critical(LOG_FILE, "cam_file_register fail");
414 cam_critical(LOG_FILE,
415 "cam_file_register error [%s]",
421 if (ad->launching_mode == CAM_LAUNCHING_MODE_NORMAL)
422 cam_app_update_thumbnail();
425 if (camapp->review) {
426 DEBUG_TRACE(" review on in recording mode");
427 cam_utils_request_main_pipe_handler(ad, NULL, CAM_MAIN_PIPE_OP_TYPE_RUN_IMAGE_VIEWER);
432 Eina_Bool cam_video_capture_handle(void *data)
434 struct appdata *ad = (struct appdata *)data;
435 CamAppData *camapp = NULL;
437 /* set recording state */
438 ad->is_recording = FALSE;
440 cam_retvm_if(ad == NULL, ECORE_CALLBACK_CANCEL, "appdata is NULL");
441 camapp = ad->camapp_handle;
442 cam_retvm_if(camapp == NULL, ECORE_CALLBACK_CANCEL,
443 "camapp_handle is NULL");
445 cam_debug(LOG_FILE, "");
447 camapp->rec_elapsed = 0;
448 SHOW_EVAS_OBJECT(ad->indicator_edje);
449 unload_recording_edje(ad);
450 camapp->rec_elapsed = 0;
451 cam_toolbar_update(ad);
452 if (ad->indicator_edje)
453 cam_indicator_update(ad);
455 cam_indicator_create(ad);
456 settings_guideline_refresh(ad);
458 if (camapp->filename) {
459 ad->remained_count--;
460 indicator_update_remain_count(ad);
462 g_queue_push_tail(ad->file_reg_queue, strdup(REC_FILE_SAVE_REG));
463 pthread_cond_signal(&ad->file_reg_cond);
465 switch (camapp->rec_stop_type) {
466 case CAM_REC_STOP_UNEXPECTED:
468 case CAM_REC_STOP_NORMAL:
470 case CAM_REC_STOP_LOW_BATTERY:
472 return ECORE_CALLBACK_CANCEL;
474 case CAM_REC_STOP_ASM:
476 case CAM_REC_STOP_MAX_SIZE:
478 case CAM_REC_STOP_TIME_LIMIT:
480 case CAM_REC_STOP_NO_SPACE:
481 cam_app_notice_popup(ad, dgettext(PACKAGE, "IDS_CAM_POP_VIDEOMEMORYFULL"),
482 cam_app_popup_response_cb);
484 case CAM_REC_STOP_USB_CONN:
486 case CAM_REC_STOP_POWER_KEY:
487 power_unlock_state(POWER_STATE_NORMAL);
492 camapp->rec_stop_type = CAM_REC_STOP_UNEXPECTED;
494 return ECORE_CALLBACK_CANCEL;