[vlc-devel] [PATCH] Fix deleting stream demux
Petri Hintukainen
phintuka at gmail.com
Sun Jun 26 11:24:42 CEST 2016
Broken since 70a05fb54763bc5ed9bf78edcdffc9c186611ef9.
Alternative would be restoring null check to demux_DestroyDemux.
---
include/vlc_stream.h | 2 ++
modules/access/bluray.c | 4 ++--
src/input/stream_demux.c | 27 +++++++++++++++++++++------
src/libvlccore.sym | 1 +
4 files changed, 26 insertions(+), 8 deletions(-)
diff --git a/include/vlc_stream.h b/include/vlc_stream.h
index 06df123..8cc3f8c 100644
--- a/include/vlc_stream.h
+++ b/include/vlc_stream.h
@@ -201,6 +201,8 @@ static inline char *stream_ContentType( stream_t *s )
*/
VLC_API stream_t * stream_DemuxNew( demux_t *p_demux, const char *psz_demux, es_out_t *out );
+VLC_API void stream_DemuxDelete( stream_t *s );
+
/**
* Send data to a stream handle created by stream_DemuxNew().
*/
diff --git a/modules/access/bluray.c b/modules/access/bluray.c
index 8178617..19b1c53 100644
--- a/modules/access/bluray.c
+++ b/modules/access/bluray.c
@@ -882,7 +882,7 @@ static void blurayClose(vlc_object_t *object)
blurayReleaseVout(p_demux);
if (p_sys->p_parser)
- stream_Delete(p_sys->p_parser);
+ stream_DemuxDelete(p_sys->p_parser);
if (p_sys->p_out != NULL)
es_out_Delete(p_sys->p_out);
assert(vlc_array_count(&p_sys->es) == 0);
@@ -1697,7 +1697,7 @@ static void blurayResetParser(demux_t *p_demux)
*/
demux_sys_t *p_sys = p_demux->p_sys;
if (p_sys->p_parser)
- stream_Delete(p_sys->p_parser);
+ stream_DemuxDelete(p_sys->p_parser);
p_sys->p_parser = stream_DemuxNew(p_demux, "ts", p_sys->p_out);
diff --git a/src/input/stream_demux.c b/src/input/stream_demux.c
index 4ee2904..d496c98 100644
--- a/src/input/stream_demux.c
+++ b/src/input/stream_demux.c
@@ -53,6 +53,8 @@ struct stream_sys_t
int64_t length;
int64_t time;
} stats;
+
+ demux_t *p_demux;
};
static ssize_t DStreamRead( stream_t *, void *p_read, size_t i_read );
@@ -86,6 +88,7 @@ stream_t *stream_DemuxNew( demux_t *p_demux, const char *psz_demux, es_out_t *ou
p_sys->stats.position = 0.;
p_sys->stats.length = 0;
p_sys->stats.time = 0;
+ p_sys->p_demux = NULL;
/* decoder fifo */
if( ( p_sys->p_fifo = block_FifoNew() ) == NULL )
@@ -145,15 +148,30 @@ int stream_DemuxControlVa( stream_t *s, int query, va_list args )
return VLC_SUCCESS;
}
-static void DStreamDelete( stream_t *s )
+void stream_DemuxDelete( stream_t *s )
{
stream_sys_t *p_sys = s->p_sys;
block_t *p_empty;
+ /* stop demux thread */
atomic_store( &p_sys->active, false );
p_empty = block_Alloc( 0 );
block_FifoPut( p_sys->p_fifo, p_empty );
vlc_join( p_sys->thread, NULL );
+
+ /* demux creation may have failed */
+ if( p_sys->p_demux ) {
+ /* deleting demux also deletes the stream */
+ demux_Delete( p_sys->p_demux );
+ } else {
+ stream_Delete( s );
+ }
+}
+
+static void DStreamDelete( stream_t *s )
+{
+ stream_sys_t *p_sys = s->p_sys;
+
vlc_mutex_destroy( &p_sys->lock );
if( p_sys->p_block )
@@ -253,6 +271,8 @@ static void* DStreamThread( void *obj )
if( p_demux == NULL )
return NULL;
+ p_sys->p_demux = p_demux;
+
/* stream_Demux cannot apply DVB filters.
* Get all programs and let the E/S output sort them out. */
demux_Control( p_demux, DEMUX_SET_GROUP, -1, NULL );
@@ -287,10 +307,5 @@ static void* DStreamThread( void *obj )
break;
}
- /* Explicit kludge: the stream is destroyed by the owner of the
- * streamDemux, not here. */
- p_demux->s = NULL;
- demux_Delete( p_demux );
-
return NULL;
}
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 6000b17..6aff973 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -398,6 +398,7 @@ stream_Block
stream_Control
stream_CustomNew
stream_Delete
+stream_DemuxDelete
stream_DemuxNew
stream_DemuxSend
stream_DemuxControlVa
--
2.7.4
More information about the vlc-devel
mailing list