From 15dd0964467caf3eede9b8b0e590120954faa351 Mon Sep 17 00:00:00 2001 From: Clive 'evilC' Galway Date: Wed, 24 Jan 2024 21:40:15 +0000 Subject: [PATCH 1/2] [Feature Request] Long press of Func button breaks recording and marks as Hot Clip Fixes #341 --- src/core/dvr.c | 18 ++++++++++++++++++ src/core/dvr.h | 1 + src/ui/page_input.c | 4 ++-- src/ui/page_playback.c | 8 ++++++-- src/ui/page_playback.h | 2 ++ 5 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/core/dvr.c b/src/core/dvr.c index fef9a72f..cf0cf221 100644 --- a/src/core/dvr.c +++ b/src/core/dvr.c @@ -18,6 +18,9 @@ bool dvr_is_recording = false; static pthread_mutex_t dvr_mutex; +int walk_sdcard(); +void mark_video_file(int const seq); + /////////////////////////////////////////////////////////////////// //-1=error; // 0=idle,1=recording,2=stopped,3=No SD card,4=recorf file path error, @@ -180,4 +183,19 @@ 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); + } + int cnt = walk_sdcard(); + LOGI("dvr_was_recording=%d, count=%d", dvr_was_recording, cnt); + if (cnt > 0) { + mark_video_file(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..ba856bcd 100644 --- a/src/ui/page_playback.c +++ b/src/ui/page_playback.c @@ -163,7 +163,9 @@ int hot_alphasort(const struct dirent **a, const struct dirent **b) { return strcoll((*a)->d_name, (*b)->d_name); } -static int walk_sdcard() { +// ToDo: This used to be static - did it need to be? +// static int walk_sdcard() { +int walk_sdcard() { char fname[512]; media_db.count = 0; @@ -309,7 +311,9 @@ static void update_item(uint8_t cur_pos, uint8_t lst_pos) { lv_obj_add_style(pb_ui[lst_pos]._img, &style_pb_dark, LV_PART_MAIN); } -static void mark_video_file(int const seq) { +// ToDo: Used to be static - does it need to be? +// static void mark_video_file(int const seq) { +void mark_video_file(int const seq) { media_file_node_t const *const pnode = get_list(seq); if (!pnode) { return; diff --git a/src/ui/page_playback.h b/src/ui/page_playback.h index 56ce6c45..8e82e344 100644 --- a/src/ui/page_playback.h +++ b/src/ui/page_playback.h @@ -53,6 +53,8 @@ void pb_key(uint8_t key); int get_videofile_cnt(); void clear_videofile_cnt(); +int walk_sdcard(); +void mark_video_file(int const seq); #ifdef __cplusplus } From 835e555277caa3c1ccfc5ad3439927fd604c75c1 Mon Sep 17 00:00:00 2001 From: Clive 'evilC' Galway Date: Thu, 25 Jan 2024 13:08:46 +0000 Subject: [PATCH 2/2] Avoid calling walk_sdcard --- src/core/dvr.c | 10 ++----- src/ui/page_playback.c | 65 +++++++++--------------------------------- src/ui/page_playback.h | 3 +- 3 files changed, 16 insertions(+), 62 deletions(-) diff --git a/src/core/dvr.c b/src/core/dvr.c index cf0cf221..50e175cc 100644 --- a/src/core/dvr.c +++ b/src/core/dvr.c @@ -17,9 +17,7 @@ bool dvr_is_recording = false; static pthread_mutex_t dvr_mutex; - -int walk_sdcard(); -void mark_video_file(int const seq); +void rename_hot_clip(int const seq); /////////////////////////////////////////////////////////////////// //-1=error; @@ -190,11 +188,7 @@ void live_mark_video_file() { if (dvr_is_recording) { dvr_cmd(DVR_STOP); } - int cnt = walk_sdcard(); - LOGI("dvr_was_recording=%d, count=%d", dvr_was_recording, cnt); - if (cnt > 0) { - mark_video_file(0); - } + rename_hot_clip(0); if (dvr_was_recording) { dvr_cmd(DVR_START); } diff --git a/src/ui/page_playback.c b/src/ui/page_playback.c index ba856bcd..3e07e2eb 100644 --- a/src/ui/page_playback.c +++ b/src/ui/page_playback.c @@ -163,9 +163,7 @@ int hot_alphasort(const struct dirent **a, const struct dirent **b) { return strcoll((*a)->d_name, (*b)->d_name); } -// ToDo: This used to be static - did it need to be? -// static int walk_sdcard() { -int walk_sdcard() { +static int walk_sdcard() { char fname[512]; media_db.count = 0; @@ -233,43 +231,6 @@ 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; @@ -311,20 +272,23 @@ static void update_item(uint8_t cur_pos, uint8_t lst_pos) { lv_obj_add_style(pb_ui[lst_pos]._img, &style_pb_dark, LV_PART_MAIN); } -// ToDo: Used to be static - does it need to be? -// static void mark_video_file(int const seq) { -void mark_video_file(int const seq) { +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); @@ -333,10 +297,7 @@ 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 8e82e344..3ca83e23 100644 --- a/src/ui/page_playback.h +++ b/src/ui/page_playback.h @@ -53,8 +53,7 @@ void pb_key(uint8_t key); int get_videofile_cnt(); void clear_videofile_cnt(); -int walk_sdcard(); -void mark_video_file(int const seq); +bool rename_hot_clip(int const seq); #ifdef __cplusplus }