Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark as Hot Clip from live view #389

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/core/dvr.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
bool dvr_is_recording = false;

static pthread_mutex_t dvr_mutex;
void rename_hot_clip(int const seq);

///////////////////////////////////////////////////////////////////
//-1=error;
Expand Down Expand Up @@ -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);
}
}
1 change: 1 addition & 0 deletions src/core/dvr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions src/ui/page_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
57 changes: 11 additions & 46 deletions src/ui/page_playback.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/ui/page_playback.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Loading