Also handle ASS subtitles when removing subtitles via sub_remove slave command.

Fixes memory leaks and other strange behaviour like mismatch of name and subtitle data.
Based on patch by Yuriy Kaminskiy [yumkam mail ru].


git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@30387 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
reimar 2010-01-22 21:10:40 +00:00
parent 3876d60f62
commit 66998a98da
1 changed files with 15 additions and 0 deletions

View File

@ -2341,6 +2341,9 @@ static void remove_subtitle_range(MPContext *mpctx, int start, int count)
int end = start + count; int end = start + count;
int after = mpctx->set_of_sub_size - end; int after = mpctx->set_of_sub_size - end;
sub_data **subs = mpctx->set_of_subtitles; sub_data **subs = mpctx->set_of_subtitles;
#ifdef CONFIG_ASS
ass_track_t **ass_tracks = mpctx->set_of_ass_tracks;
#endif
if (count < 0 || count > mpctx->set_of_sub_size || if (count < 0 || count > mpctx->set_of_sub_size ||
start < 0 || start > mpctx->set_of_sub_size - count) { start < 0 || start > mpctx->set_of_sub_size - count) {
mp_msg(MSGT_CPLAYER, MSGL_ERR, mp_msg(MSGT_CPLAYER, MSGL_ERR,
@ -2354,6 +2357,11 @@ static void remove_subtitle_range(MPContext *mpctx, int start, int count)
filename_recode(subd->filename)); filename_recode(subd->filename));
sub_free(subd); sub_free(subd);
subs[idx] = NULL; 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->global_sub_size -= count;
@ -2363,10 +2371,17 @@ static void remove_subtitle_range(MPContext *mpctx, int start, int count)
memmove(subs + start, subs + end, after * sizeof(*subs)); memmove(subs + start, subs + end, after * sizeof(*subs));
memset(subs + start + after, 0, count * 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) { if (mpctx->set_of_sub_pos >= start && mpctx->set_of_sub_pos < end) {
mpctx->global_sub_pos = -2; mpctx->global_sub_pos = -2;
subdata = NULL; subdata = NULL;
#ifdef CONFIG_ASS
ass_track = NULL;
#endif
mp_input_queue_cmd(mp_input_parse_cmd("sub_select")); mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
} else if (mpctx->set_of_sub_pos >= end) { } else if (mpctx->set_of_sub_pos >= end) {
mpctx->set_of_sub_pos -= count; mpctx->set_of_sub_pos -= count;