Skip to content

Commit

Permalink
fix run-sh seek behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrieljablonski committed Jul 6, 2022
1 parent f882d2e commit ffdc94a
Showing 1 changed file with 53 additions and 43 deletions.
96 changes: 53 additions & 43 deletions src/framework/mlt_playlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -416,14 +416,17 @@ static void mlt_playlist_next( mlt_listener listener, mlt_properties owner, mlt_
struct run_and_play_args {
char *command;
mlt_producer producer;
double speed;
int seek;
};

void *run_and_play(void *a) {
struct run_and_play_args *args = (struct run_and_play_args *)a;
system(args->command);
mlt_producer_set_speed(args->producer, 1.0);
mlt_producer_seek(args->producer, args->seek);
mlt_producer_set_speed(args->producer, args->speed);
if (args->seek != -1) {
mlt_producer_seek(args->producer, args->seek);
}
}

/** Seek in the virtual playlist.
Expand Down Expand Up @@ -524,51 +527,12 @@ static mlt_service mlt_playlist_virtual_seek( mlt_playlist self, int *progressiv
char *playcast_id = mlt_properties_get(self, "meta.playcast.current-id");
int is_first_frame = mlt_properties_get_int(self, "meta.playcast.is-first-frame");
int is_last_frame = mlt_properties_get_int(self, "meta.playcast.is-last-frame");
double previous_speed = mlt_producer_get_speed(self);

if (!playcast_id) {
goto skip_run_sh;
}

if (!mlt_producer_get_speed(self) || (!is_first_frame && !is_last_frame)) {
goto skip_run_sh;
}

char run_sh_prop_name[1024];
snprintf(run_sh_prop_name, 1023, "meta.playcast.%s.run-sh-start", playcast_id);
char *command_start = mlt_properties_get(self, run_sh_prop_name);
snprintf(run_sh_prop_name, 1023, "meta.playcast.%s.run-sh-end", playcast_id);
char *command_end = mlt_properties_get(self, run_sh_prop_name);

if (!command_start && !command_end) {
goto skip_run_sh;
}
pthread_t run_and_play_thread;
char command_fork[10240];
if (is_first_frame && command_start && strlen(command_start)) {
snprintf(command_fork, 10239, "timeout 5 %s", command_start);
fprintf(stderr, "run start \"%s\"\n", command_fork);
mlt_producer_set_speed(self, 0);
mlt_producer_seek(self, original-1);
struct run_and_play_args cmd = {
.command = command_fork,
.producer = self,
.seek = original
};
pthread_create(&run_and_play_thread, NULL, &run_and_play, &cmd);
}
if (is_last_frame && command_end && strlen(command_end)) {
snprintf(command_fork, 10239, "timeout 5 %s", command_end);
fprintf(stderr, "run end \"%s\"\n", command_fork);
mlt_producer_set_speed(self, 0);
struct run_and_play_args cmd = {
.command = command_fork,
.producer = self,
.seek = original
};
pthread_create(&run_and_play_thread, NULL, &run_and_play, &cmd);
goto skip_playcast;
}

skip_run_sh:;
char pause_prop_name[1024];
snprintf(pause_prop_name, 1023, "meta.playcast.%s.pause-start", playcast_id);
int pause_start = mlt_properties_get_int(self, pause_prop_name);
Expand Down Expand Up @@ -625,6 +589,52 @@ skip_run_sh:;
}
}

if (!previous_speed || (!is_first_frame && !is_last_frame)) {
goto skip_playcast;
}

char run_sh_prop_name[1024];
snprintf(run_sh_prop_name, 1023, "meta.playcast.%s.run-sh-start", playcast_id);
char *command_start = mlt_properties_get(self, run_sh_prop_name);
snprintf(run_sh_prop_name, 1023, "meta.playcast.%s.run-sh-end", playcast_id);
char *command_end = mlt_properties_get(self, run_sh_prop_name);

if (!command_start && !command_end) {
goto skip_playcast;
}

pthread_t run_and_play_thread;
double new_speed = mlt_producer_get_speed(self);
char command_fork[10240];

if (is_first_frame && command_start && strlen(command_start)) {
snprintf(command_fork, 10239, "timeout 5 %s", command_start);
fprintf(stderr, "run start \"%s\"\n", command_fork);
mlt_producer_set_speed(self, 0);
mlt_producer_seek(self, original-1);
struct run_and_play_args cmd = {
.command = command_fork,
.producer = self,
.speed = new_speed,
.seek = original
};
pthread_create(&run_and_play_thread, NULL, &run_and_play, &cmd);
}

if (is_last_frame && command_end && strlen(command_end)) {
snprintf(command_fork, 10239, "timeout 5 %s", command_end);
fprintf(stderr, "run end \"%s\"\n", command_fork);
mlt_producer_set_speed(self, 0);
struct run_and_play_args cmd = {
.command = command_fork,
.producer = self,
.speed = new_speed,
.seek = -1
};
pthread_create(&run_and_play_thread, NULL, &run_and_play, &cmd);
}

skip_playcast:;
return MLT_PRODUCER_SERVICE( producer );
}

Expand Down

0 comments on commit ffdc94a

Please sign in to comment.