Skip to content

Commit 49b6d80

Browse files
committed
player/loadfile: possibly do a reset of sd_ass when turning on video
It's a pretty niche case, but if you start a file with no video with animated ass subtitles and then turned on the video later, the subtitles would not actually be rendered animated. This because the subtitles were already decoded, and we do not do a check for animations expect in the specific case of an image being played back on the video since the check can be quite expensive. To fix this edge case, we just need to reset the ass before doing the track switch in the case where we go from no video to a track that's an image. SD_CTRL_RESET_SOFT is added as a a sub_ctrl to accomplish this. Fixes #17268.
1 parent fdb996a commit 49b6d80

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

player/loadfile.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,20 @@ void mp_switch_track_n(struct MPContext *mpctx, int order, enum stream_type type
745745
reselect_demux_stream(mpctx, current, false);
746746
}
747747

748+
// For the edge case of switching from no video to a still image, we need to
749+
// flush the ass events of any sub track for potential animations.
750+
if (type == STREAM_VIDEO && order == 0 && !current && track->image) {
751+
for (int n = 0; n < num_ptracks[STREAM_SUB]; n++) {
752+
struct track *sub_track = mpctx->current_track[n][STREAM_SUB];
753+
if (sub_track && sub_track->d_sub) {
754+
sub_control(sub_track->d_sub, SD_CTRL_RESET_SOFT, NULL);
755+
sub_reset(sub_track->d_sub);
756+
if (sub_track->selected)
757+
reselect_demux_stream(mpctx, sub_track, true);
758+
}
759+
}
760+
}
761+
748762
mpctx->current_track[order][type] = track;
749763

750764
if (track) {

sub/dec_sub.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ enum sd_ctrl {
1919
SD_CTRL_SET_ANIMATED_CHECK,
2020
SD_CTRL_SET_VIDEO_PARAMS,
2121
SD_CTRL_SET_VIDEO_DEF_FPS,
22+
SD_CTRL_RESET_SOFT,
2223
SD_CTRL_UPDATE_OPTS,
2324
};
2425

sub/sd_ass.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,10 @@ static int control(struct sd *sd, enum sd_ctrl cmd, void *arg)
10341034
case SD_CTRL_SET_ANIMATED_CHECK:
10351035
ctx->check_animated = *(bool *)arg;
10361036
return CONTROL_OK;
1037+
case SD_CTRL_RESET_SOFT:
1038+
ctx->clear_once = true;
1039+
reset(sd);
1040+
return CONTROL_OK;
10371041
case SD_CTRL_SET_VIDEO_PARAMS:
10381042
ctx->video_params = *(struct mp_image_params *)arg;
10391043
return CONTROL_OK;

0 commit comments

Comments
 (0)