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.
This commit is contained in:
wm4 2015-02-20 21:08:10 +01:00
parent 44411674eb
commit 6c1355be96
5 changed files with 18 additions and 18 deletions

View File

@ -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)
{

View File

@ -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);

View File

@ -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;
}

View File

@ -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);
}

View File

@ -75,10 +75,8 @@ static void close_unused_demuxers(struct MPContext *mpctx)
goto skip;
}
struct stream *s = d->stream;
uninit_stream_sub_decoders(d);
free_demuxer(d);
free_stream(s);
free_demuxer_and_stream(d);
MP_TARRAY_REMOVE_AT(mpctx->sources, mpctx->num_sources, i);
skip:;
@ -723,10 +721,8 @@ struct track *mp_add_external_file(struct MPContext *mpctx, char *filename,
}
}
if (!first) {
free_demuxer(demuxer);
free_stream(stream);
MP_WARN(mpctx, "No streams added from file %s.\n",
disp_filename);
free_demuxer_and_stream(demuxer);
MP_WARN(mpctx, "No streams added from file %s.\n", disp_filename);
goto err_out;
}
@ -736,8 +732,7 @@ struct track *mp_add_external_file(struct MPContext *mpctx, char *filename,
return first;
err_out:
MP_ERR(mpctx, "Can not open external file %s.\n",
disp_filename);
MP_ERR(mpctx, "Can not open external file %s.\n", disp_filename);
return false;
}