Fixes #10118.
Unified · Split
| @@ -259,7 +259,7 @@ typedef struct MPContext { · 258 unmodified lines | ||
| 259 | 259 | struct osd_state *osd; |
| 260 | 260 | char *term_osd_text; |
| 261 | 261 | char *term_osd_status; |
| 262 | − char *term_osd_subs; | |
| 262 | + char *term_osd_subs[2]; | |
| 263 | 263 | char *term_osd_contents; |
| 264 | 264 | char *term_osd_title; |
| 265 | 265 | char *last_window_title; |
| @@ -585,7 +585,8 @@ void set_osd_bar(struct MPContext *mpctx, int type, · 319 unmodified lines | ||
| 585 | 585 | bool set_osd_msg(struct MPContext *mpctx, int level, int time, |
| 586 | 586 | const char* fmt, ...) PRINTF_ATTRIBUTE(4,5); |
| 587 | 587 | void set_osd_function(struct MPContext *mpctx, int osd_function); |
| 588 | −void term_osd_set_subs(struct MPContext *mpctx, const char *text); | |
| 588 | +void term_osd_clear_subs(struct MPContext *mpctx); | |
| 589 | +void term_osd_set_subs(struct MPContext *mpctx, const char *text, int order); | |
| 589 | 590 | void get_current_osd_sym(struct MPContext *mpctx, char *buf, size_t buf_size); |
| 590 | 591 | void set_osd_bar_chapters(struct MPContext *mpctx, int type); |
| 591 | 592 | |
| @@ -75,13 +75,15 @@ static bool term_osd_empty(char *text) · 74 unmodified lines | ||
| 75 | 75 | static void term_osd_update(struct MPContext *mpctx) |
| 76 | 76 | { |
| 77 | 77 | int num_parts = 0; |
| 78 | − char *parts[3] = {0}; | |
| 78 | + char *parts[4] = {0}; | |
| 79 | 79 | |
| 80 | 80 | if (!mpctx->opts->use_terminal) |
| 81 | 81 | return; |
| 82 | 82 | |
| 83 | − if (!term_osd_empty(mpctx->term_osd_subs)) | |
| 84 | − parts[num_parts++] = mpctx->term_osd_subs; | |
| 83 | + if (!term_osd_empty(mpctx->term_osd_subs[0])) | |
| 84 | + parts[num_parts++] = mpctx->term_osd_subs[0]; | |
| 85 | + if (!term_osd_empty(mpctx->term_osd_subs[1])) | |
| 86 | + parts[num_parts++] = mpctx->term_osd_subs[1]; | |
| 85 | 87 | if (!term_osd_empty(mpctx->term_osd_text)) |
| 86 | 88 | parts[num_parts++] = mpctx->term_osd_text; |
| 87 | 89 | if (!term_osd_empty(mpctx->term_osd_status)) |
| @@ -115,13 +117,19 @@ static void term_osd_update_title(struct MPContext *mpctx) · 27 unmodified lines | ||
| 115 | 117 | mpctx->term_osd_title = talloc_steal(mpctx, s); |
| 116 | 118 | } |
| 117 | 119 | |
| 118 | −void term_osd_set_subs(struct MPContext *mpctx, const char *text) | |
| 120 | +void term_osd_clear_subs(struct MPContext *mpctx) | |
| 119 | 121 | { |
| 120 | − if (mpctx->video_out || !text || !mpctx->opts->subs_shared->sub_visibility[0]) | |
| 122 | + term_osd_set_subs(mpctx, NULL, 0); | |
| 123 | + term_osd_set_subs(mpctx, NULL, 1); | |
| 124 | +} | |
| 125 | + | |
| 126 | +void term_osd_set_subs(struct MPContext *mpctx, const char *text, int order) | |
| 127 | +{ | |
| 128 | + if (mpctx->video_out || !text || !mpctx->opts->subs_shared->sub_visibility[order]) | |
| 121 | 129 | text = ""; // disable |
| 122 | − if (strcmp(mpctx->term_osd_subs ? mpctx->term_osd_subs : "", text) == 0) | |
| 130 | + if (strcmp(mpctx->term_osd_subs[order] ? mpctx->term_osd_subs[order] : "", text) == 0) | |
| 123 | 131 | return; |
| 124 | − talloc_replace(mpctx, mpctx->term_osd_subs, text); | |
| 132 | + talloc_replace(mpctx, mpctx->term_osd_subs[order], text); | |
| 125 | 133 | term_osd_update(mpctx); |
| 126 | 134 | } |
| 127 | 135 | |
| @@ -50,7 +50,6 @@ static void reset_subtitles(struct MPContext *mpctx, struct track *track) · 49 unmodified lines | ||
| 50 | 50 | sub_reset(track->d_sub); |
| 51 | 51 | sub_set_play_dir(track->d_sub, mpctx->play_dir); |
| 52 | 52 | } |
| 53 | − term_osd_set_subs(mpctx, NULL); | |
| 54 | 53 | } |
| 55 | 54 | |
| 56 | 55 | // Only matters for subs on an image. |
| @@ -69,15 +68,16 @@ void reset_subtitle_state(struct MPContext *mpctx) · 12 unmodified lines | ||
| 69 | 68 | { |
| 70 | 69 | for (int n = 0; n < mpctx->num_tracks; n++) |
| 71 | 70 | reset_subtitles(mpctx, mpctx->tracks[n]); |
| 72 | − term_osd_set_subs(mpctx, NULL); | |
| 71 | + term_osd_clear_subs(mpctx); | |
| 73 | 72 | } |
| 74 | 73 | |
| 75 | 74 | void uninit_sub(struct MPContext *mpctx, struct track *track) |
| 76 | 75 | { |
| 77 | 76 | if (track && track->d_sub) { |
| 77 | + int order = get_order(mpctx, track); | |
| 78 | 78 | reset_subtitles(mpctx, track); |
| 79 | + term_osd_set_subs(mpctx, NULL, order); | |
| 79 | 80 | sub_select(track->d_sub, false); |
| 80 | − int order = get_order(mpctx, track); | |
| 81 | 81 | osd_set_sub(mpctx->osd, order, NULL); |
| 82 | 82 | sub_destroy(track->d_sub); |
| 83 | 83 | track->d_sub = NULL; |
| @@ -133,10 +133,16 @@ static bool update_subtitle(struct MPContext *mpctx, double video_pts, · 49 unmodified lines | ||
| 133 | 133 | if (track->redraw_subs && still_image) |
| 134 | 134 | sub_redecode_cached_packets(dec_sub); |
| 135 | 135 | |
| 136 | − // Handle displaying subtitles on terminal; never done for secondary subs | |
| 136 | + // Handle displaying subtitles on terminal. | |
| 137 | 137 | if (mpctx->current_track[0][STREAM_SUB] == track && !mpctx->video_out) { |
| 138 | 138 | char *text = sub_get_text(dec_sub, video_pts, SD_TEXT_TYPE_PLAIN); |
| 139 | − term_osd_set_subs(mpctx, text); | |
| 139 | + term_osd_set_subs(mpctx, text, 0); | |
| 140 | + talloc_free(text); | |
| 141 | + } | |
| 142 | + | |
| 143 | + if (mpctx->current_track[1][STREAM_SUB] == track && !mpctx->video_out) { | |
| 144 | + char *text = sub_get_text(dec_sub, video_pts, SD_TEXT_TYPE_PLAIN); | |
| 145 | + term_osd_set_subs(mpctx, text, 1); | |
| 140 | 146 | talloc_free(text); |
| 141 | 147 | } |
| 142 | 148 | |
| @@ -284,7 +284,7 @@ void reinit_video_chain_src(struct MPContext *mpctx, struct track *track) · 283 unmodified lines | ||
| 284 | 284 | vo_set_paused(vo_c->vo, get_internal_paused(mpctx)); |
| 285 | 285 | |
| 286 | 286 | reset_video_state(mpctx); |
| 287 | − term_osd_set_subs(mpctx, NULL); | |
| 287 | + term_osd_clear_subs(mpctx); | |
| 288 | 288 | |
| 289 | 289 | return; |
| 290 | 290 | |