Skip to content
Merged
42 changes: 14 additions & 28 deletions src/modules/qt/filter_gpsgraphic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
#include "filter_gpsgraphic.h"
#include "common.h"

#include <QMutex>
static QMutex f_mutex;

// Sets the private data to default values and frees gps points array
static void default_priv_data(private_data *pdata)
{
Expand Down Expand Up @@ -223,28 +220,17 @@ static int64_t get_original_video_file_time_mseconds(mlt_frame frame)
*/
static int64_t get_current_frame_time_ms(mlt_filter filter, mlt_frame frame)
{
mlt_properties properties = MLT_FILTER_PROPERTIES(filter);
private_data *pdata = (private_data *) filter->child;
int64_t file_time = 0, fr_time = 0;

file_time = get_original_video_file_time_mseconds(frame);
int64_t file_time_ms = get_original_video_file_time_mseconds(frame);
mlt_position frame_position = mlt_frame_original_position(frame);
// mlt_log_info(filter, "frame_pos=%d, frame_orig_pos=%d; file_time=%d\n", mlt_frame_get_position(frame), mlt_frame_original_position(frame), file_time/1000);
f_mutex.lock();
char *s = mlt_properties_frames_to_time(properties, frame_position, mlt_time_clock);
if (s) {
int h = 0, m = 0, sec = 0, msec = 0;
sscanf(s, "%d:%d:%d.%d", &h, &m, &sec, &msec);
fr_time = (h * 3600 + m * 60 + sec) * 1000 + msec;
} else
mlt_log_warning(filter,
"get_current_frame_time_ms time string null, giving up "
"[mlt_frame_original_position()=%d], retry result:%s\n",
frame_position,
mlt_properties_frames_to_time(properties, frame_position, mlt_time_clock));
f_mutex.unlock();

return file_time + fr_time * pdata->speed_multiplier;

double fps = mlt_profile_fps(mlt_service_profile(MLT_FILTER_SERVICE(filter)));
if (fps == 0)
fps = 30;

int64_t frame_time_ms = frame_position * pdata->speed_multiplier * 1000 / fps;

return file_time_ms + frame_time_ms;
}

//gets the nearest gps point [index] according to video time + input offset
Expand All @@ -255,12 +241,12 @@ int get_now_gpspoint_index(mlt_filter filter, mlt_frame frame, bool force_result
return binary_search_gps(filter_to_gps_data(filter), video_time_synced, force_result);
}

//returns the next gps point with a valid value for crt_source (starting with crt_i+1)
int get_next_valid_gpspoint_index(mlt_filter filter, int crt_i)
//returns gps point index with a valid value for crt_source (starts searching directly at crt_i)
int get_valid_gpspoint_index(mlt_filter filter, int crt_i)
{
private_data *pdata = (private_data *) filter->child;
while (++crt_i < pdata->gps_points_size && get_crtval_bysrc(filter, crt_i) == GPS_UNINIT)
;
while (crt_i < pdata->gps_points_size && get_crtval_bysrc(filter, crt_i) == GPS_UNINIT)
crt_i++;
//maybe TODO: add restriction for MAX_GPS_TIME? and allow depending on force_result
return CLAMP(crt_i, 0, pdata->gps_points_size - 1);
}
Expand All @@ -284,7 +270,7 @@ gps_point_proc get_now_weighted_gpspoint(mlt_filter filter,
return uninit_gps_proc_point;

//interpolate if everything ok
int next_i = get_next_valid_gpspoint_index(filter, i_now);
int next_i = get_valid_gpspoint_index(filter, i_now + 1);
if (non_forced_i != -1)
crt = weighted_middle_point_proc(&pdata->gps_points_p[i_now],
&pdata->gps_points_p[next_i],
Expand Down
4 changes: 2 additions & 2 deletions src/modules/qt/filter_gpsgraphic.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ double get_by_src(
double get_min_bysrc(mlt_filter filter, int subtype = 0);
double get_max_bysrc(mlt_filter filter, int subtype = 0);
double get_crtval_bysrc(mlt_filter filter, int i_gps, int subtype = 0, gps_point_proc *gps_p = NULL);
//returns the next gps point with a valid value for crt_source (starting with crt_i+1)
int get_next_valid_gpspoint_index(mlt_filter filter, int crt_i);
//returns gps point index with a valid value for crt_source (starts searching directly at crt_i)
int get_valid_gpspoint_index(mlt_filter filter, int crt_i);
//gets the nearest gps point [index] according to video time + input offset
int get_now_gpspoint_index(mlt_filter filter, mlt_frame frame, bool force_result = true);
//returns an interpolated gps point at the exact current video time + offset
Expand Down
40 changes: 19 additions & 21 deletions src/modules/qt/filter_gpstext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ typedef struct
int64_t last_gps_time;
int64_t gps_offset;
int64_t gps_proc_start_t; //process only points after this time (epoch milliseconds)
char last_read_gps_processing_start_time[20];
double speed_multiplier;
double updates_per_second;
char last_filename[PATH_MAX]; //gps file fullpath
Expand Down Expand Up @@ -197,20 +198,17 @@ static void get_current_frame_time_ns_decimals_str(mlt_filter filter,
double file_time_just_ms = (get_original_video_file_time_mseconds(frame) % 1000) / 1000.0;
mlt_position frame_position = mlt_frame_original_position(frame);

mlt_profile profile = mlt_service_profile(MLT_FILTER_SERVICE(filter));
double fps = mlt_profile_fps(profile);
double fps = mlt_profile_fps(mlt_service_profile(MLT_FILTER_SERVICE(filter)));
if (fps == 0)
fps = 30; //there's probably worse things happening if this returns 0

int64_t frame_time_ns = frame_position * pdata->speed_multiplier * 1000000000LL / fps;
// mlt_log_info(NULL, "before ns: fps=%.9f, frame_time_ns=%lld", fps, frame_time_ns);

if (pdata->updates_per_second > 0) {
int64_t upd_every_ns = llround(1e9 * fabs(pdata->speed_multiplier)
/ pdata->updates_per_second);
if (upd_every_ns) //avoid division (modulo) by 0
frame_time_ns -= frame_time_ns % upd_every_ns;
// mlt_log_info(NULL, "after: upd_every_ns=%lld, frame_time_ns=%lld, result_ns:%.9f", upd_every_ns, frame_time_ns, (file_time_just_ms + frame_time_ns / 1e9));
}
double result_ns = file_time_just_ms + frame_time_ns / 1e9;

Expand All @@ -234,24 +232,19 @@ static int64_t get_current_frame_time_ms(mlt_filter filter, mlt_frame frame)
int64_t file_time_ms = get_original_video_file_time_mseconds(frame);
mlt_position frame_position = mlt_frame_original_position(frame);

mlt_profile profile = mlt_service_profile(MLT_FILTER_SERVICE(filter));
double fps = mlt_profile_fps(profile);
double fps = mlt_profile_fps(mlt_service_profile(MLT_FILTER_SERVICE(filter)));
if (fps == 0)
fps = 30;

int64_t frame_time_ms = frame_position * pdata->speed_multiplier * 1000 / fps;
// mlt_log_info(NULL, "before ms : fps=%.9f, frame_time_ms=%lld", fps, frame_time_ms);

if (pdata->updates_per_second > 0) {
int64_t upd_every_ms = llround(1000.0 * fabs(pdata->speed_multiplier)
/ pdata->updates_per_second);
if (upd_every_ms)
frame_time_ms -= frame_time_ms % upd_every_ms;
// mlt_log_info(NULL, "after: upd_every_ms=%lld, frame_time_ms=%lld, result_ms:%lld", upd_every_ms, frame_time_ms, file_time_ms + frame_time_ms);
}
int64_t result_ms = file_time_ms + frame_time_ms;

return result_ms;
return file_time_ms + frame_time_ms;
}

/** Replaces file_datetime_now with absolute time-date string (video created + current timecode)
Expand Down Expand Up @@ -477,7 +470,6 @@ static void gps_point_to_output(mlt_filter filter,
}
}
strncat(result_gps_text, gps_text, MAX_TEXT_LEN - strlen(result_gps_text) - 1);
// mlt_log_info(NULL, "filter_gps.c gps_point_to_output, keyword=%s, result_gps_text=%s\n", keyword, result_gps_text);
}

/** Reads and updates all necessary filter properties, and processes the gps data if needed
Expand Down Expand Up @@ -510,18 +502,24 @@ static void process_filter_properties(mlt_filter filter, mlt_frame frame)
do_smoothing = 1;
}

if (read_gps_processing_start_time != NULL) {
int64_t gps_proc_t = 0;
if (strlen(read_gps_processing_start_time) != 0
&& strcmp(read_gps_processing_start_time, "yyyy-MM-dd hh:mm:ss"))
gps_proc_t = datetimeXMLstring_to_mseconds(read_gps_processing_start_time,
(char *) "yyyy-MM-dd hh:mm:ss");
if (gps_proc_t != pdata->gps_proc_start_t) {
pdata->gps_proc_start_t = gps_proc_t;
do_processing = 1;
//only update the processing start time if the new read datetime value is valid and different from last frame
if (read_gps_processing_start_time != NULL && strlen(read_gps_processing_start_time) == 19
&& strcmp(read_gps_processing_start_time, "yyyy-MM-dd hh:mm:ss")) {
if (strcmp(read_gps_processing_start_time, pdata->last_read_gps_processing_start_time)) {
strncpy(pdata->last_read_gps_processing_start_time,
read_gps_processing_start_time,
sizeof(pdata->last_read_gps_processing_start_time));

int64_t gps_proc_t = datetimeXMLstring_to_mseconds(read_gps_processing_start_time,
"yyyy-MM-dd hh:mm:ss");
if (gps_proc_t != pdata->gps_proc_start_t) {
pdata->gps_proc_start_t = gps_proc_t;
do_processing = 1;
}
}
} else if (pdata->gps_proc_start_t != 0) {
pdata->gps_proc_start_t = 0;
pdata->last_read_gps_processing_start_time[0] = 0;
do_processing = 1;
}

Expand Down
Loading
Loading