diff --git a/src/core/dvr.c b/src/core/dvr.c index fef9a72f..50e175cc 100644 --- a/src/core/dvr.c +++ b/src/core/dvr.c @@ -17,6 +17,7 @@ bool dvr_is_recording = false; static pthread_mutex_t dvr_mutex; +void rename_hot_clip(int const seq); /////////////////////////////////////////////////////////////////// //-1=error; @@ -180,4 +181,15 @@ void dvr_cmd(osd_dvr_cmd_t cmd) { } pthread_mutex_unlock(&dvr_mutex); +} + +void live_mark_video_file() { + bool dvr_was_recording = dvr_is_recording; + if (dvr_is_recording) { + dvr_cmd(DVR_STOP); + } + rename_hot_clip(0); + if (dvr_was_recording) { + dvr_cmd(DVR_START); + } } \ No newline at end of file diff --git a/src/core/dvr.h b/src/core/dvr.h index 17e6640e..7f83640e 100644 --- a/src/core/dvr.h +++ b/src/core/dvr.h @@ -23,6 +23,7 @@ void dvr_enable_line_out(bool enable); void dvr_cmd(osd_dvr_cmd_t cmd); void dvr_update_vi_conf(video_resolution_t fmt); void dvr_toggle(); +void live_mark_video_file(); #ifdef __cplusplus } diff --git a/src/ui/page_input.c b/src/ui/page_input.c index d963d7e2..df8c8022 100644 --- a/src/ui/page_input.c +++ b/src/ui/page_input.c @@ -36,8 +36,8 @@ typedef enum page_input_rows { static lv_coord_t col_dsc[] = {160, 200, 160, 160, 160, 120, LV_GRID_TEMPLATE_LAST}; static lv_coord_t row_dsc[] = {60, 60, 60, 60, 60, 60, 60, 60, 60, LV_GRID_TEMPLATE_LAST}; -const char *btnOptions[] = {"Toggle OSD", "Main menu", "Toggle DVR", "Center HT", "Calibrate HT", "Go Sleep!", "Toggle fan speed"}; -void (* const btnFunctionPointers[])() = {&osd_toggle, &app_switch_to_menu, &dvr_toggle, &ht_set_center_position, &ht_calibrate, &go_sleep, &step_topfan}; +const char *btnOptions[] = {"Toggle OSD", "Main menu", "Toggle DVR", "Center HT", "Calibrate HT", "Go Sleep!", "Toggle fan speed", "Mark Hot Clip"}; +void (*const btnFunctionPointers[])() = {&osd_toggle, &app_switch_to_menu, &dvr_toggle, &ht_set_center_position, &ht_calibrate, &go_sleep, &step_topfan, &live_mark_video_file}; const char *rollerOptions[] = {"Switch channel", "Change fan speed", "OLED Brightness"}; void (* const rollerFunctionPointers[])(uint8_t) = {&tune_channel, &change_topfan, &change_oled_brightness}; diff --git a/src/ui/page_playback.c b/src/ui/page_playback.c index 0d0d6425..3e07e2eb 100644 --- a/src/ui/page_playback.c +++ b/src/ui/page_playback.c @@ -231,43 +231,6 @@ static int walk_sdcard() { return media_db.count; } -static int find_next_available_hot_index() { - DIR *fd = opendir(MEDIA_FILES_DIR); - if (!fd) { - return 1; - } - - int result = 0; - struct dirent *in_file; - while ((in_file = readdir(fd))) { - if (in_file->d_name[0] == '.' || strncmp(in_file->d_name, REC_hotPREFIX, 4) != 0) { - continue; - } - - const char *dot = strrchr(in_file->d_name, '.'); - if (dot == NULL) { - // '.' not found - continue; - } - - if (strcasecmp(dot, "." REC_packTS) != 0 && strcasecmp(dot, "." REC_packMP4) != 0) { - continue; - } - - int index = 0; - if (sscanf(in_file->d_name, REC_packHotPREFIX "%d", &index) != 1) { - continue; - } - - if (index > result) { - result = index; - } - } - closedir(fd); - - return result + 1; -} - static void update_page() { uint32_t const page_num = (uint32_t)floor((double)media_db.cur_sel / ITEMS_LAYOUT_CNT); uint32_t const end_pos = media_db.count - page_num * ITEMS_LAYOUT_CNT; @@ -310,17 +273,22 @@ static void update_item(uint8_t cur_pos, uint8_t lst_pos) { } static void mark_video_file(int const seq) { + if (rename_hot_clip(seq)) { + walk_sdcard(); + media_db.cur_sel = constrain(seq, 0, (media_db.count - 1)); + update_page(); + } +} + +bool rename_hot_clip(int const seq) { media_file_node_t const *const pnode = get_list(seq); if (!pnode) { - return; + return false; } if (strncmp(pnode->filename, REC_hotPREFIX, 4) == 0) { // file already marked hot - return; + return false; } - - const int index = find_next_available_hot_index(); - char cmd[256]; char newLabel[68]; sprintf(newLabel, "%s%s", REC_hotPREFIX, pnode->label); @@ -329,10 +297,7 @@ static void mark_video_file(int const seq) { system_exec(cmd); sprintf(cmd, "mv %s%s." REC_packJPG " %s%s." REC_packJPG, MEDIA_FILES_DIR, pnode->label, MEDIA_FILES_DIR, newLabel); system_exec(cmd); - - walk_sdcard(); - media_db.cur_sel = constrain(seq, 0, (media_db.count - 1)); - update_page(); + return true; } static void delete_video_file(int seq) { diff --git a/src/ui/page_playback.h b/src/ui/page_playback.h index 56ce6c45..3ca83e23 100644 --- a/src/ui/page_playback.h +++ b/src/ui/page_playback.h @@ -53,6 +53,7 @@ void pb_key(uint8_t key); int get_videofile_cnt(); void clear_videofile_cnt(); +bool rename_hot_clip(int const seq); #ifdef __cplusplus }