summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2012-11-15 20:22:41 +0100
committerwm4 <wm4@nowhere>2012-11-16 21:21:15 +0100
commitdd7dc2ee3d060d77dbafb3182127eb1a59c2d79f (patch)
tree0cb31fc3cd28975a11faf161f2eac6a8d1f7e7fb
parent25a098fe78ad2aee0ad7e18f8d4326e5cd29aeb1 (diff)
downloadmpv-dd7dc2ee3d060d77dbafb3182127eb1a59c2d79f.tar.bz2
mpv-dd7dc2ee3d060d77dbafb3182127eb1a59c2d79f.tar.xz
subreader: replace sub_free() by talloc destructor
Makes it less annoying to free the sub_data.
-rw-r--r--core/mplayer.c11
-rw-r--r--sub/subreader.c13
-rw-r--r--sub/subreader.h1
3 files changed, 11 insertions, 14 deletions
diff --git a/core/mplayer.c b/core/mplayer.c
index d632bf5615..560733e6ab 100644
--- a/core/mplayer.c
+++ b/core/mplayer.c
@@ -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);
}
diff --git a/sub/subreader.c b/sub/subreader.c
index 583e719e55..99b2c6849c 100644
--- a/sub/subreader.c
+++ b/sub/subreader.c
@@ -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
diff --git a/sub/subreader.h b/sub/subreader.h
index db84fdd9a8..4584f2366a 100644
--- a/sub/subreader.h
+++ b/sub/subreader.h
@@ -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);