mirror of https://github.com/mpv-player/mpv
subreader: replace sub_free() by talloc destructor
Makes it less annoying to free the sub_data.
This commit is contained in:
parent
25a098fe78
commit
dd7dc2ee3d
|
@ -530,10 +530,7 @@ void uninit_player(struct MPContext *mpctx, unsigned int mask)
|
|||
if (mask & INITIALIZED_DEMUXER) {
|
||||
mpctx->initialized_flags &= ~INITIALIZED_DEMUXER;
|
||||
for (int i = 0; i < mpctx->num_tracks; i++) {
|
||||
struct track *track = mpctx->tracks[i];
|
||||
sub_free(track->subdata);
|
||||
talloc_free(track->sh_sub);
|
||||
talloc_free(track);
|
||||
talloc_free(mpctx->tracks[i]);
|
||||
}
|
||||
mpctx->num_tracks = 0;
|
||||
for (int t = 0; t < STREAM_TYPE_COUNT; t++)
|
||||
|
@ -965,7 +962,7 @@ void add_subtitles(struct MPContext *mpctx, char *filename, float fps,
|
|||
subd = sub_read_file(filename, fps, &mpctx->opts);
|
||||
if (subd) {
|
||||
asst = mp_ass_read_subdata(mpctx->ass_library, opts, subd, fps);
|
||||
sub_free(subd);
|
||||
talloc_free(subd);
|
||||
subd = NULL;
|
||||
}
|
||||
}
|
||||
|
@ -989,8 +986,8 @@ void add_subtitles(struct MPContext *mpctx, char *filename, float fps,
|
|||
.user_tid = find_new_tid(mpctx, STREAM_SUB),
|
||||
.demuxer_id = -1,
|
||||
.is_external = true,
|
||||
.sh_sub = sh,
|
||||
.subdata = subd,
|
||||
.sh_sub = talloc_steal(track, sh),
|
||||
.subdata = talloc_steal(track, subd),
|
||||
};
|
||||
MP_TARRAY_APPEND(mpctx, mpctx->tracks, mpctx->num_tracks, track);
|
||||
}
|
||||
|
|
|
@ -1374,6 +1374,8 @@ const char* guess_cp(stream_t *st, const char *preferred_language, const char *f
|
|||
#undef MAX_GUESS_BUFFER_SIZE
|
||||
#endif
|
||||
|
||||
static int sub_destroy(void *ptr);
|
||||
|
||||
sub_data* sub_read_file(char *filename, float fps, struct MPOpts *opts)
|
||||
{
|
||||
int utf16;
|
||||
|
@ -1758,7 +1760,8 @@ if ((suboverlap_enabled == 2) ||
|
|||
return_sub = first;
|
||||
}
|
||||
if (return_sub == NULL) return NULL;
|
||||
subt_data = malloc(sizeof(sub_data));
|
||||
subt_data = talloc_zero(NULL, sub_data);
|
||||
talloc_set_destructor(subt_data, sub_destroy);
|
||||
subt_data->filename = strdup(filename);
|
||||
subt_data->sub_uses_time = uses_time;
|
||||
subt_data->sub_num = sub_num;
|
||||
|
@ -1767,18 +1770,16 @@ if ((suboverlap_enabled == 2) ||
|
|||
return subt_data;
|
||||
}
|
||||
|
||||
void sub_free( sub_data * subd )
|
||||
static int sub_destroy(void *ptr)
|
||||
{
|
||||
sub_data *subd = ptr;
|
||||
int i, j;
|
||||
|
||||
if ( !subd ) return;
|
||||
|
||||
for (i = 0; i < subd->sub_num; i++)
|
||||
for (j = 0; j < subd->subtitles[i].lines; j++)
|
||||
free( subd->subtitles[i].text[j] );
|
||||
free( subd->subtitles );
|
||||
free( subd->filename );
|
||||
free( subd );
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define MAX_SUBLINE 512
|
||||
|
|
|
@ -91,7 +91,6 @@ void subcp_close (void); /* for demux_ogg.c */
|
|||
const char* guess_buffer_cp(unsigned char* buffer, int buflen, const char *preferred_language, const char *fallback);
|
||||
const char* guess_cp(struct stream *st, const char *preferred_language, const char *fallback);
|
||||
#endif
|
||||
void sub_free( sub_data * subd );
|
||||
struct MPContext;
|
||||
void find_sub(struct MPContext *mpctx, sub_data* subd,int key);
|
||||
void step_sub(sub_data *subd, float pts, int movement);
|
||||
|
|
Loading…
Reference in New Issue