summaryrefslogtreecommitdiffstats
path: root/demux
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-02-20 21:08:10 +0100
committerwm4 <wm4@nowhere>2015-02-20 21:08:10 +0100
commit6c1355be967751b194504ed73b053846fbae5fa9 (patch)
tree078c7a52448a2e47fb32e8ed56e67ccf8805acec /demux
parent44411674ebb764adeb806040d24700bc4cc493cc (diff)
downloadmpv-6c1355be967751b194504ed73b053846fbae5fa9.tar.bz2
mpv-6c1355be967751b194504ed73b053846fbae5fa9.tar.xz
demux: add free_demuxer_and_stream() function
Although their lifetimes are conceptually different, it happens often that a demuxer is destroyed together with its stream.
Diffstat (limited to 'demux')
-rw-r--r--demux/demux.c9
-rw-r--r--demux/demux.h1
-rw-r--r--demux/demux_mkv_timeline.c6
-rw-r--r--demux/timeline.c7
4 files changed, 14 insertions, 9 deletions
diff --git a/demux/demux.c b/demux/demux.c
index 8af76daa1f..b10b0d6f45 100644
--- a/demux/demux.c
+++ b/demux/demux.c
@@ -245,6 +245,15 @@ void free_demuxer(demuxer_t *demuxer)
talloc_free(demuxer);
}
+void free_demuxer_and_stream(struct demuxer *demuxer)
+{
+ if (!demuxer)
+ return;
+ struct stream *s = demuxer->stream;
+ free_demuxer(demuxer);
+ free_stream(s);
+}
+
// Start the demuxer thread, which reads ahead packets on its own.
void demux_start_thread(struct demuxer *demuxer)
{
diff --git a/demux/demux.h b/demux/demux.h
index 1d0038a5b0..848c7701f0 100644
--- a/demux/demux.h
+++ b/demux/demux.h
@@ -242,6 +242,7 @@ typedef struct {
} demux_program_t;
void free_demuxer(struct demuxer *demuxer);
+void free_demuxer_and_stream(struct demuxer *demuxer);
int demux_add_packet(struct sh_stream *stream, demux_packet_t *dp);
diff --git a/demux/demux_mkv_timeline.c b/demux/demux_mkv_timeline.c
index 1a1816b93e..735678f7db 100644
--- a/demux/demux_mkv_timeline.c
+++ b/demux/demux_mkv_timeline.c
@@ -157,9 +157,8 @@ static int enable_cache(struct mpv_global *global, struct stream **stream,
return 0;
char *filename = talloc_strdup(NULL, (*demuxer)->filename);
- free_demuxer(*demuxer);
- free_stream(*stream);
+ free_demuxer_and_stream(*demuxer);
*stream = stream_open(filename, global);
if (!*stream) {
talloc_free(filename);
@@ -251,8 +250,7 @@ static bool check_file_seg(struct tl_ctx *ctx, struct demuxer ***sources,
}
}
- free_demuxer(d);
- free_stream(s);
+ free_demuxer_and_stream(d);
return was_valid;
}
diff --git a/demux/timeline.c b/demux/timeline.c
index 6274c25fa3..9910abf46d 100644
--- a/demux/timeline.c
+++ b/demux/timeline.c
@@ -32,11 +32,8 @@ void timeline_destroy(struct timeline *tl)
return;
for (int n = 0; n < tl->num_sources; n++) {
struct demuxer *d = tl->sources[n];
- if (d != tl->demuxer) {
- struct stream *s = d->stream;
- free_demuxer(d);
- free_stream(s);
- }
+ if (d != tl->demuxer)
+ free_demuxer_and_stream(d);
}
talloc_free(tl);
}