diff options
author | Uoti Urpala <uau@glyph.nonexistent.invalid> | 2010-01-25 15:59:53 +0200 |
---|---|---|
committer | Uoti Urpala <uau@glyph.nonexistent.invalid> | 2010-01-25 15:59:53 +0200 |
commit | e28e4a1b157bd0e9620fcff956d713a9921f506c (patch) | |
tree | d92e54e1e25feb84e692396cf234478f403e5738 /command.c | |
parent | 560acfd0407c757e17bf72b490687d4947b05675 (diff) | |
parent | 213092c8dcfc925d8d54cf320b60cf298a870696 (diff) | |
download | mpv-e28e4a1b157bd0e9620fcff956d713a9921f506c.tar.bz2 mpv-e28e4a1b157bd0e9620fcff956d713a9921f506c.tar.xz |
Merge svn changes up to r30419
Diffstat (limited to 'command.c')
-rw-r--r-- | command.c | 96 |
1 files changed, 56 insertions, 40 deletions
@@ -2490,6 +2490,60 @@ static const char *property_error_string(int error_value) return "UNKNOWN"; } +static void remove_subtitle_range(MPContext *mpctx, int start, int count) +{ + int idx; + int end = start + count; + int after = mpctx->set_of_sub_size - end; + sub_data **subs = mpctx->set_of_subtitles; +#ifdef CONFIG_ASS + struct ass_track **ass_tracks = mpctx->set_of_ass_tracks; +#endif + if (count < 0 || count > mpctx->set_of_sub_size || + start < 0 || start > mpctx->set_of_sub_size - count) { + mp_msg(MSGT_CPLAYER, MSGL_ERR, + "Cannot remove invalid subtitle range %i +%i\n", start, count); + return; + } + for (idx = start; idx < end; idx++) { + sub_data *subd = subs[idx]; + mp_msg(MSGT_CPLAYER, MSGL_STATUS, + "SUB: Removed subtitle file (%d): %s\n", idx + 1, + filename_recode(subd->filename)); + sub_free(subd); + subs[idx] = NULL; +#ifdef CONFIG_ASS + if (ass_tracks[idx]) + ass_free_track(ass_tracks[idx]); + ass_tracks[idx] = NULL; +#endif + } + + mpctx->global_sub_size -= count; + mpctx->set_of_sub_size -= count; + if (mpctx->set_of_sub_size <= 0) + mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1; + + memmove(subs + start, subs + end, after * sizeof(*subs)); + memset(subs + start + after, 0, count * sizeof(*subs)); +#ifdef CONFIG_ASS + memmove(ass_tracks + start, ass_tracks + end, after * sizeof(*ass_tracks)); + memset(ass_tracks + start + after, 0, count * sizeof(*ass_tracks)); +#endif + + if (mpctx->set_of_sub_pos >= start && mpctx->set_of_sub_pos < end) { + mpctx->global_sub_pos = -2; + subdata = NULL; +#ifdef CONFIG_ASS + ass_track = NULL; +#endif + mp_input_queue_cmd(mpctx->input, mp_input_parse_cmd("sub_select")); + } else if (mpctx->set_of_sub_pos >= end) { + mpctx->set_of_sub_pos -= count; + mpctx->global_sub_pos -= count; + } +} + void run_command(MPContext *mpctx, mp_cmd_t *cmd) { struct MPOpts *opts = &mpctx->opts; @@ -3056,48 +3110,10 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd) case MP_CMD_SUB_REMOVE: if (sh_video) { int v = cmd->args[0].v.i; - sub_data *subd; if (v < 0) { - for (v = 0; v < mpctx->set_of_sub_size; ++v) { - subd = mpctx->set_of_subtitles[v]; - mp_tmsg(MSGT_CPLAYER, MSGL_STATUS, - "SUB: Removed subtitle file (%d): %s\n", v + 1, - filename_recode(subd->filename)); - sub_free(subd); - mpctx->set_of_subtitles[v] = NULL; - } - mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1; - mpctx->global_sub_size -= mpctx->set_of_sub_size; - mpctx->set_of_sub_size = 0; - if (mpctx->set_of_sub_pos >= 0) { - mpctx->global_sub_pos = -2; - subdata = NULL; - mp_input_queue_cmd(mpctx->input, - mp_input_parse_cmd("sub_select")); - } + remove_subtitle_range(mpctx, 0, mpctx->set_of_sub_size); } else if (v < mpctx->set_of_sub_size) { - subd = mpctx->set_of_subtitles[v]; - mp_msg(MSGT_CPLAYER, MSGL_STATUS, - "SUB: Removed subtitle file (%d): %s\n", v + 1, - filename_recode(subd->filename)); - sub_free(subd); - if (mpctx->set_of_sub_pos == v) { - mpctx->global_sub_pos = -2; - subdata = NULL; - mp_input_queue_cmd(mpctx->input, - mp_input_parse_cmd("sub_select")); - } else if (mpctx->set_of_sub_pos > v) { - --mpctx->set_of_sub_pos; - --mpctx->global_sub_pos; - } - while (++v < mpctx->set_of_sub_size) - mpctx->set_of_subtitles[v - 1] = - mpctx->set_of_subtitles[v]; - --mpctx->set_of_sub_size; - --mpctx->global_sub_size; - if (mpctx->set_of_sub_size <= 0) - mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1; - mpctx->set_of_subtitles[mpctx->set_of_sub_size] = NULL; + remove_subtitle_range(mpctx, v, 1); } } break; |