summaryrefslogtreecommitdiff
path: root/src/edc-callback/cam_recording_edc_callback.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/edc-callback/cam_recording_edc_callback.c')
-rwxr-xr-xsrc/edc-callback/cam_recording_edc_callback.c383
1 files changed, 383 insertions, 0 deletions
diff --git a/src/edc-callback/cam_recording_edc_callback.c b/src/edc-callback/cam_recording_edc_callback.c
new file mode 100755
index 0000000..60a7b68
--- /dev/null
+++ b/src/edc-callback/cam_recording_edc_callback.c
@@ -0,0 +1,383 @@
+/*
+ * Copyright 2012 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include "cam.h"
+#include "cam_app.h"
+#include "cam_rec.h"
+#include "cam_mm.h"
+#include "cam_file.h"
+#include "edc_string.h"
+#include "camera_utils.h"
+#include "cam_property.h"
+#include "cam_toolbar_edc_callback.h"
+#include "cam_recording_edc_callback.h"
+
+#define REC_ICON_TIMER_INTERVAL (1)
+#define REC_TIMER_INTERVAL (0.5)
+#define PAUSE_TIMER_INTERVAL (0.5)
+#define PAUSE_TIMEOUT (120)
+#define SECONDS_IN_HOUR (1*60*60)
+
+enum _RecState {
+ CAM_REC_STATE_RECORDING,
+ CAM_REC_STATE_PAUSE,
+};
+#define TIME_FORMAT_MAX_LEN (128)
+/* static int rec_state = CAM_REC_STATE_RECORDING; */
+static double paused_time = 0.0;
+Eina_Bool recording_update_time_cb(void *data);
+Eina_Bool recording_update_icon_cb(void *data);
+Eina_Bool pause_timeout_cb(void *data);
+
+static void __recording_set_state(void *data, int new_state)
+{
+ CAM_UI_LOG();
+ struct appdata *ad = (struct appdata *)data;
+ cam_ret_if(ad == NULL);
+
+ if (new_state == CAM_REC_STATE_RECORDING) {
+ if (ad->rec_time_updater) {
+ ecore_timer_thaw(ad->rec_time_updater);
+ }
+ if (ad->rec_icon_updater) {
+ ecore_timer_thaw(ad->rec_icon_updater);
+ }
+ if (ad->rec_pause_timer) {
+ ecore_timer_del(ad->rec_pause_timer);
+ ad->rec_pause_timer = NULL;
+ }
+ edje_object_signal_emit(_EDJ(ad->recording_edje), "state,rec", "program");
+ } else if (new_state == CAM_REC_STATE_PAUSE) {
+ if (ad->rec_time_updater) {
+ ecore_timer_freeze(ad->rec_time_updater);
+ }
+ if (ad->rec_icon_updater) {
+ ecore_timer_freeze(ad->rec_icon_updater);
+ }
+ if (ad->rec_pause_timer) {
+ ecore_timer_del(ad->rec_pause_timer);
+ ad->rec_pause_timer = NULL;
+ }
+ paused_time = 0.0;
+ ad->rec_pause_timer = ecore_timer_add(REC_TIMER_INTERVAL, pause_timeout_cb, ad);
+ edje_object_signal_emit(_EDJ(ad->recording_edje), "state,pause", "program");
+ }
+ ad->recording_state = new_state;
+}
+
+/* you can use this function to set time text for recording */
+void recording_set_time(void *data, int hh, int mm, int ss)
+{
+ CAM_UI_LOG();
+ struct appdata *ad = (struct appdata *)data;
+ if (ad->recording_edje) {
+ char time_text[100] = "";
+ snprintf(time_text, sizeof(time_text), "%" CAM_TIME_FORMAT "", hh, mm, ss);
+ edje_object_part_text_set(_EDJ(ad->recording_edje), RECORDING_TEXT, time_text);
+ }
+}
+
+Eina_Bool pause_timeout_cb(void *data)
+{
+ struct appdata *ad = (struct appdata *)data;
+ cam_retv_if(ad == NULL, FALSE);
+ CamAppData *camapp = NULL;
+ camapp = ad->camapp_handle;
+ if (camapp == NULL) {
+ if (ad->rec_pause_timer)
+ ad->rec_pause_timer = NULL;
+ return ECORE_CALLBACK_CANCEL;
+ }
+
+ paused_time += PAUSE_TIMER_INTERVAL;
+ if (paused_time >= PAUSE_TIMEOUT) {
+ camapp->rec_stop_type = CAM_REC_STOP_NORMAL;
+ ad->recording_commit = ecore_idler_add(cam_video_idler_record_stop, ad);
+
+ if (ad->rec_pause_timer)
+ ad->rec_pause_timer = NULL;
+ return ECORE_CALLBACK_CANCEL;
+ }
+ if (ad->recording_edje) {
+ const char *state = edje_object_part_state_get(_EDJ(ad->recording_edje), RECORDING_IMAGE, NULL);
+
+ if (strcmp(state, "pause") == 0) {
+ edje_object_signal_emit(_EDJ(ad->recording_edje), "indicator,hide", "program");
+ } else if (strcmp(state, "invisible") == 0) {
+ edje_object_signal_emit(_EDJ(ad->recording_edje), "indicator,show", "program");
+ }
+ }
+ return ECORE_CALLBACK_RENEW;
+}
+
+Eina_Bool recording_update_icon_cb(void *data)
+{
+ struct appdata *ad = (struct appdata *)data;
+ static int count = 0;
+ if (ad == NULL) {
+ cam_critical(LOG_UI, "appdata is NULL");
+ /* ad->rec_icon_updater = NULL; */
+ return ECORE_CALLBACK_CANCEL;
+ }
+ if (count) {
+ edje_object_signal_emit(_EDJ(ad->recording_edje), "state,rec", "program");
+ } else {
+ edje_object_signal_emit(_EDJ(ad->recording_edje), "state,rec1", "program");
+ }
+ count = !count;
+ return ECORE_CALLBACK_RENEW;
+}
+
+Eina_Bool recording_update_time_cb(void *data)
+{
+ CAM_UI_LOG();
+ struct appdata *ad = (struct appdata *)data;
+ CamAppData *camapp = NULL;
+ if (ad == NULL) {
+ cam_critical(LOG_UI, "appdata is NULL");
+ return ECORE_CALLBACK_CANCEL;
+ }
+ camapp = ad->camapp_handle;
+ if (camapp == NULL) {
+ cam_critical(LOG_UI, "cam_handle is NULL");
+ ad->rec_time_updater = NULL;
+ return ECORE_CALLBACK_CANCEL;
+ }
+ char time_text[100] = "";
+ if (camapp->rec_elapsed < SECONDS_IN_HOUR)
+ snprintf(time_text, sizeof(time_text), "%" CAM_TIME_FORMAT "", CAM_TIME_ARGS(camapp->rec_elapsed));
+ else
+ snprintf(time_text, sizeof(time_text), "%" CAM_TIME_FORMAT2 "", CAM_TIME_ARGS2(camapp->rec_elapsed));
+ cam_debug(LOG_UI, "current time %s", time_text);
+ if (ad->recording_edje) {
+ edje_object_part_text_set(_EDJ(ad->recording_edje), RECORDING_TEXT, _(time_text));
+ }
+
+ if (camapp->size_limit != CAM_REC_NORMAL_MAX_SIZE) {
+ char str[10] = "";
+ char str2[10] = "";
+ char *filename = NULL;
+ int fname_size = 0;/*unused*/
+ guint64 size_limit = 0;
+ gdouble pbar_position = 0.0;
+ gdouble size_limit_in_mega = 0.0;
+ gdouble rec_filesize_in_mega = 0.0;
+ cam_mm_get_filename(&filename, &fname_size);
+ if (camapp->rec_filesize) {
+ size_limit = (guint64)camapp->size_limit;
+ pbar_position = camapp->rec_filesize / (gdouble) size_limit;
+ cam_app_set_progressbar_value(ad, pbar_position);
+
+ if (camapp->size_limit < 1024) {
+ snprintf(str, sizeof(str), "%dK", camapp->size_limit);
+ } else {
+ size_limit_in_mega = (gdouble)camapp->size_limit/(gdouble)1024;
+ snprintf(str, sizeof(str), "%.1fM", size_limit_in_mega);
+ }
+
+ if (camapp->rec_filesize < 1024) {
+ snprintf(str2, sizeof(str2), "%dK", camapp->rec_filesize);
+ } else {
+ rec_filesize_in_mega = (gdouble)camapp->rec_filesize/(gdouble)1024;
+ snprintf(str2, sizeof(str2), "%.1fM", rec_filesize_in_mega);
+ }
+
+ edje_object_part_text_set(_EDJ(ad->recording_edje), "progressbar_text", str);
+ edje_object_part_text_set(_EDJ(ad->recording_edje), "file_size_text", str2);
+ }
+ }
+
+ gchar * target_path = NULL;
+ target_path = (gchar*)cam_app_get_target_path();
+ double ration = 0.0;
+ if (target_path != NULL) {
+ gint64 free_space = cam_get_free_space(target_path);
+ gint64 capacity_space = cam_get_capacity_space(target_path);
+ ration = (double)free_space/(double)capacity_space;
+ }
+ DEBUG_TRACE("ration : %f ", ration);
+ if (ration < 0.20) {
+ /*show left time*/
+ char time_left_text[TIME_FORMAT_MAX_LEN + 1] = { '\0', };
+ guint64 remain_rec_time = 0;
+ remain_rec_time = cam_system_get_remain_rec_time((void*)ad);
+ DEBUG_TRACE("%d",remain_rec_time);
+ if (remain_rec_time < SECONDS_IN_HOUR) {
+ snprintf(time_left_text, TIME_FORMAT_MAX_LEN, "%" CAM_TIME_FORMAT "", CAM_TIME_ARGS(remain_rec_time));
+ DEBUG_TRACE("%s",time_left_text);
+ } else {
+ snprintf(time_left_text, TIME_FORMAT_MAX_LEN, "%" CAM_TIME_FORMAT2 "", CAM_TIME_ARGS2(remain_rec_time));
+ DEBUG_TRACE("%s",time_left_text);
+ }
+ edje_object_part_text_set(_EDJ(ad->recording_edje), RECORDING_LEFT_TEXT, _(time_left_text));
+
+ } else {
+ edje_object_part_text_set(_EDJ(ad->recording_edje), RECORDING_LEFT_TEXT, _(""));
+ }
+ return ECORE_CALLBACK_RENEW;
+}
+
+int load_recording_edje(struct appdata *ad)
+{
+ CamAppData *camapp = NULL;
+ cam_retvm_if(ad == NULL, EXIT_FAILURE, "appdata is NULL");
+ camapp = ad->camapp_handle;
+ cam_retvm_if(camapp == NULL, EXIT_FAILURE, "cam_handle is NULL");
+
+ cam_toolbar_update(ad);
+ DEL_EVAS_OBJECT(ad->recording_edje);
+
+ elm_object_part_content_unset(ad->ug_base, "recording_layout");
+
+ DEBUG_TRACE("ad->target_direction %d", ad->target_direction);
+ switch (ad->target_direction) {
+ case CAM_TARGET_DIRECTION_LANDSCAPE:
+ ad->recording_edje = cam_app_load_edj(ad->ug_base, CAM_RECORDING_EDJ_NAME, "recording_layout");
+ break;
+ case CAM_TARGET_DIRECTION_LANDSCAPE_INVERSE:
+ ad->recording_edje = cam_app_load_edj(ad->ug_base, CAM_RECORDING_INVERSE_EDJ_NAME, "recording_layout");
+ break;
+ case CAM_TARGET_DIRECTION_PORTRAIT:
+ ad->recording_edje = cam_app_load_edj(ad->ug_base, CAM_RECORDING_VERTICAL_EDJ_NAME, "recording_layout");
+ break;
+ case CAM_TARGET_DIRECTION_PORTRAIT_INVERSE:
+ ad->recording_edje = cam_app_load_edj(ad->ug_base, CAM_RECORDING_VERTICAL_INVERSE_EDJ_NAME, "recording_layout");
+ break;
+ default:
+ DEBUG_TRACE("note:reach un-able reached codes");
+ }
+
+ cam_retv_if(ad->recording_edje == NULL, -1);
+ elm_object_part_content_set(ad->ug_base, "recording_layout", ad->recording_edje);
+
+ if (camapp->size_limit != CAM_REC_NORMAL_MAX_SIZE) {
+ char str[10] = "";
+ char str2[10] = "";
+ gdouble size_limit_in_mega = 0.0;
+ camapp->rec_filesize =0;
+
+ if (camapp->size_limit < 1024) {
+ snprintf(str, sizeof(str), "%dK", camapp->size_limit);
+ } else {
+ size_limit_in_mega = (gdouble)camapp->size_limit/(gdouble)1024;
+ snprintf(str, sizeof(str), "%.1fM", size_limit_in_mega);
+ }
+
+ snprintf(str2, sizeof(str), "%dK", 0);
+ cam_app_create_progressbar(ad);
+
+ /* cam_app_set_progressbar_value(ad, 0.0); */
+ elm_object_part_content_set(ad->recording_edje, "progressbar", ad->progressbar);
+ edje_object_part_text_set(_EDJ(ad->recording_edje), "progressbar_text", str);
+ edje_object_part_text_set(_EDJ(ad->recording_edje), "file_size_text", str2);
+ }
+ camapp->rec_elapsed = 0;
+ __recording_set_state(ad, CAM_REC_STATE_RECORDING);
+ recording_set_time(ad, 0, 0, 0);
+ if (ad->rec_time_updater != NULL)
+ ecore_timer_del(ad->rec_time_updater);
+ if (ad->rec_icon_updater != NULL)
+ ecore_timer_del(ad->rec_icon_updater);
+ ad->rec_time_updater = ecore_timer_add(REC_TIMER_INTERVAL, recording_update_time_cb, ad);
+ ad->rec_icon_updater = ecore_timer_add(REC_ICON_TIMER_INTERVAL, recording_update_icon_cb, ad);
+
+ return EXIT_SUCCESS;
+}
+
+int unload_recording_edje(struct appdata *ad)
+{
+ cam_retv_if(ad == NULL, -1);
+ cam_app_destroy_progressbar(ad);
+ DEL_EVAS_OBJECT(ad->recording_edje);
+ REMOVE_TIMER(ad->rec_time_updater);
+ REMOVE_TIMER(ad->rec_icon_updater);
+
+ cam_toolbar_update(ad);
+
+ return EXIT_SUCCESS;
+}
+
+int cam_recording_rotate(struct appdata *ad)
+{
+ cam_retv_if(ad == NULL, -1);
+ CamAppData *camapp = ad->camapp_handle;
+ cam_retvm_if(camapp == NULL, EXIT_FAILURE, "cam_handle is NULL");
+
+ evas_object_hide(ad->indicator_edje);
+ elm_object_part_content_unset(ad->recording_edje, "progressbar");
+ evas_object_hide(ad->progressbar);
+ DEL_EVAS_OBJECT(ad->recording_edje);
+
+ elm_object_part_content_unset(ad->ug_base, "recording_layout");
+
+ switch (ad->target_direction) {
+ case CAM_TARGET_DIRECTION_LANDSCAPE:
+ ad->recording_edje = cam_app_load_edj(ad->ug_base, CAM_RECORDING_EDJ_NAME, "recording_layout");
+ break;
+ case CAM_TARGET_DIRECTION_LANDSCAPE_INVERSE:
+ ad->recording_edje = cam_app_load_edj(ad->ug_base, CAM_RECORDING_INVERSE_EDJ_NAME, "recording_layout");
+ break;
+ case CAM_TARGET_DIRECTION_PORTRAIT:
+ ad->recording_edje = cam_app_load_edj(ad->ug_base, CAM_RECORDING_VERTICAL_EDJ_NAME, "recording_layout");
+ break;
+ case CAM_TARGET_DIRECTION_PORTRAIT_INVERSE:
+ ad->recording_edje = cam_app_load_edj(ad->ug_base, CAM_RECORDING_VERTICAL_INVERSE_EDJ_NAME, "recording_layout");
+ break;
+ default:
+ DEBUG_TRACE("note:reach un-able reached codes");
+ }
+
+ cam_retv_if(ad->recording_edje == NULL, -1);
+ elm_object_part_content_set(ad->ug_base, "recording_layout", ad->recording_edje);
+
+ if (ad->recording_state == CAM_REC_STATE_RECORDING) {
+ edje_object_signal_emit(_EDJ(ad->recording_edje), "state,rec", "program");
+ } else if (ad->recording_state == CAM_REC_STATE_PAUSE) {
+ edje_object_signal_emit(_EDJ(ad->recording_edje), "state,pause", "program");
+ }
+ char time_text[100] = "";
+ if (camapp->rec_elapsed < 3600)
+ snprintf(time_text, sizeof(time_text), "%" CAM_TIME_FORMAT "",
+ CAM_TIME_ARGS(camapp->rec_elapsed));
+ else
+ snprintf(time_text, sizeof(time_text), "%" CAM_TIME_FORMAT2 "",
+ CAM_TIME_ARGS2(camapp->rec_elapsed));
+ cam_debug(LOG_UI, "current time %s", time_text);
+ if (ad->recording_edje) {
+ edje_object_part_text_set(_EDJ(ad->recording_edje), RECORDING_TEXT, _(time_text));
+ }
+ if (ad->progressbar) {
+ char str[10] = "";
+ char str2[10] = "";
+ char *filename = NULL;
+ int fname_size = 0;
+ guint64 size_limit = 0;
+ gdouble pbar_position = 0.0;
+ cam_mm_get_filename(&filename, &fname_size);
+ if (camapp->rec_filesize) {
+ size_limit = (guint64)camapp->size_limit;
+ pbar_position =camapp->rec_filesize/ (double)size_limit;
+ cam_app_set_progressbar_value(ad, pbar_position);
+ snprintf(str, sizeof(str), "%dK", camapp->size_limit);
+ snprintf(str2, sizeof(str2), "%dK", camapp->rec_filesize);
+ elm_object_part_content_set(ad->recording_edje, "progressbar", ad->progressbar);
+ edje_object_part_text_set(_EDJ(ad->recording_edje), "progressbar_text", str);
+ edje_object_part_text_set(_EDJ(ad->recording_edje), "progressbar_text", str2);
+ }
+ }
+ return EXIT_SUCCESS;
+}