Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/winegstreamer/gstdemux.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/dlls/winegstreamer/gstdemux.c b/dlls/winegstreamer/gstdemux.c index 734984d7fed..21d6e324add 100644 --- a/dlls/winegstreamer/gstdemux.c +++ b/dlls/winegstreamer/gstdemux.c @@ -53,6 +53,8 @@ struct wg_parser GstPad *my_src, *their_sink;
guint64 file_size, start_offset, next_offset, stop_offset; + + pthread_t push_thread; };
struct parser @@ -82,8 +84,6 @@ struct parser pthread_cond_t init_cond; bool no_more_pads, has_duration, error;
- pthread_t push_thread; - HANDLE read_thread; pthread_cond_t read_cond, read_done_cond; struct @@ -635,7 +635,7 @@ static gboolean gst_base_src_perform_seek(struct parser *This, GstEvent *event) gboolean flush; guint32 seqnum; GstEvent *tevent; - BOOL thread = !!This->push_thread; + BOOL thread = !!parser->push_thread;
gst_event_parse_seek(event, &rate, &seek_format, &flags, &cur_type, &cur, &stop_type, &stop); @@ -1436,19 +1436,19 @@ static gboolean activate_push(GstPad *pad, gboolean activate) struct wg_parser *parser = This->wg_parser;
if (!activate) { - if (This->push_thread) { - pthread_join(This->push_thread, NULL); - This->push_thread = 0; + if (parser->push_thread) { + pthread_join(parser->push_thread, NULL); + parser->push_thread = 0; } if (This->filter.state == State_Stopped) parser->next_offset = parser->start_offset; - } else if (!This->push_thread) { + } else if (!parser->push_thread) { int ret;
- if ((ret = pthread_create(&This->push_thread, NULL, push_data, This))) + if ((ret = pthread_create(&parser->push_thread, NULL, push_data, This))) { GST_ERROR("Failed to create push thread: %s", strerror(errno)); - This->push_thread = 0; + parser->push_thread = 0; return FALSE; } }
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/winegstreamer/gstdemux.c | 58 +++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 26 deletions(-)
diff --git a/dlls/winegstreamer/gstdemux.c b/dlls/winegstreamer/gstdemux.c index 21d6e324add..2c838643554 100644 --- a/dlls/winegstreamer/gstdemux.c +++ b/dlls/winegstreamer/gstdemux.c @@ -55,6 +55,9 @@ struct wg_parser guint64 file_size, start_offset, next_offset, stop_offset;
pthread_t push_thread; + + pthread_cond_t init_cond; + bool no_more_pads, has_duration, error; };
struct parser @@ -81,8 +84,6 @@ struct parser uint64_t next_pull_offset;
pthread_mutex_t mutex; - pthread_cond_t init_cond; - bool no_more_pads, has_duration, error;
HANDLE read_thread; pthread_cond_t read_cond, read_done_cond; @@ -730,6 +731,7 @@ static gboolean event_sink(GstPad *pad, GstObject *parent, GstEvent *event) { struct parser_source *pin = gst_pad_get_element_private(pad); struct parser *filter = impl_from_strmbase_filter(pin->pin.pin.filter); + struct wg_parser *parser = filter->wg_parser;
GST_LOG("pin %p, type "%s".", pin, GST_EVENT_TYPE_NAME(event));
@@ -772,7 +774,7 @@ static gboolean event_sink(GstPad *pad, GstObject *parent, GstEvent *event) pthread_mutex_lock(&filter->mutex); pin->eos = true; pthread_mutex_unlock(&filter->mutex); - pthread_cond_signal(&filter->init_cond); + pthread_cond_signal(&parser->init_cond); } break;
@@ -819,7 +821,7 @@ static gboolean event_sink(GstPad *pad, GstObject *parent, GstEvent *event) pthread_mutex_lock(&filter->mutex); gst_caps_replace(&pin->caps, caps); pthread_mutex_unlock(&filter->mutex); - pthread_cond_signal(&filter->init_cond); + pthread_cond_signal(&parser->init_cond); break; }
@@ -1476,13 +1478,14 @@ static gboolean activate_mode(GstPad *pad, GstObject *parent, GstPadMode mode, g static void no_more_pads(GstElement *decodebin, gpointer user) { struct parser *filter = user; + struct wg_parser *parser = filter->wg_parser;
GST_DEBUG("filter %p.", filter);
pthread_mutex_lock(&filter->mutex); - filter->no_more_pads = true; + parser->no_more_pads = true; pthread_mutex_unlock(&filter->mutex); - pthread_cond_signal(&filter->init_cond); + pthread_cond_signal(&parser->init_cond); }
static GstAutoplugSelectResult autoplug_blacklist(GstElement *bin, GstPad *pad, GstCaps *caps, GstElementFactory *fact, gpointer user) @@ -1507,6 +1510,7 @@ static GstAutoplugSelectResult autoplug_blacklist(GstElement *bin, GstPad *pad, static GstBusSyncReply watch_bus(GstBus *bus, GstMessage *msg, gpointer data) { struct parser *filter = data; + struct wg_parser *parser = filter->wg_parser; GError *err = NULL; gchar *dbg_info = NULL;
@@ -1521,9 +1525,9 @@ static GstBusSyncReply watch_bus(GstBus *bus, GstMessage *msg, gpointer data) g_error_free(err); g_free(dbg_info); pthread_mutex_lock(&filter->mutex); - filter->error = true; + parser->error = true; pthread_mutex_unlock(&filter->mutex); - pthread_cond_signal(&filter->init_cond); + pthread_cond_signal(&parser->init_cond); break;
case GST_MESSAGE_WARNING: @@ -1536,9 +1540,9 @@ static GstBusSyncReply watch_bus(GstBus *bus, GstMessage *msg, gpointer data)
case GST_MESSAGE_DURATION_CHANGED: pthread_mutex_lock(&filter->mutex); - filter->has_duration = true; + parser->has_duration = true; pthread_mutex_unlock(&filter->mutex); - pthread_cond_signal(&filter->init_cond); + pthread_cond_signal(&parser->init_cond); break;
default: @@ -1616,9 +1620,9 @@ static HRESULT GST_Connect(struct parser *This, IPin *pConnectPin)
pin->seek.llDuration = pin->seek.llStop = query_duration(pin->their_src); pin->seek.llCurrent = 0; - while (!pin->caps && !This->error) - pthread_cond_wait(&This->init_cond, &This->mutex); - if (This->error) + while (!pin->caps && !parser->error) + pthread_cond_wait(&parser->init_cond, &This->mutex); + if (parser->error) { pthread_mutex_unlock(&This->mutex); return E_FAIL; @@ -1666,6 +1670,8 @@ static void wg_parser_destroy(struct wg_parser *parser) gst_object_unref(parser->bus); }
+ pthread_cond_destroy(&parser->init_cond); + free(parser); }
@@ -1691,7 +1697,6 @@ static void parser_destroy(struct strmbase_filter *iface)
pthread_cond_destroy(&filter->read_cond); pthread_cond_destroy(&filter->read_done_cond); - pthread_cond_destroy(&filter->init_cond); pthread_mutex_destroy(&filter->mutex);
strmbase_sink_cleanup(&filter->sink); @@ -1867,7 +1872,7 @@ static BOOL decodebin_parser_init_gst(struct parser *filter) parser->their_sink = gst_element_get_static_pad(element, "sink");
pthread_mutex_lock(&filter->mutex); - filter->no_more_pads = filter->error = false; + parser->no_more_pads = parser->error = false; pthread_mutex_unlock(&filter->mutex);
if ((ret = gst_pad_link(parser->my_src, parser->their_sink)) < 0) @@ -1885,9 +1890,9 @@ static BOOL decodebin_parser_init_gst(struct parser *filter) }
pthread_mutex_lock(&filter->mutex); - while (!filter->no_more_pads && !filter->error) - pthread_cond_wait(&filter->init_cond, &filter->mutex); - if (filter->error) + while (!parser->no_more_pads && !parser->error) + pthread_cond_wait(&parser->init_cond, &filter->mutex); + if (parser->error) { pthread_mutex_unlock(&filter->mutex); return FALSE; @@ -1989,7 +1994,6 @@ static BOOL parser_init_gstreamer(void) static void parser_init_common(struct parser *object) { pthread_mutex_init(&object->mutex, NULL); - pthread_cond_init(&object->init_cond, NULL); pthread_cond_init(&object->read_cond, NULL); pthread_cond_init(&object->read_done_cond, NULL); object->flushing = true; @@ -2002,6 +2006,8 @@ static struct wg_parser *wg_parser_create(void) if (!(parser = calloc(1, sizeof(*parser)))) return NULL;
+ pthread_cond_init(&parser->init_cond, NULL); + TRACE("Created winegstreamer parser %p.\n", parser); return parser; } @@ -2736,7 +2742,7 @@ static BOOL avi_splitter_init_gst(struct parser *filter) parser->their_sink = gst_element_get_static_pad(element, "sink");
pthread_mutex_lock(&filter->mutex); - filter->no_more_pads = filter->error = false; + parser->no_more_pads = parser->error = false; pthread_mutex_unlock(&filter->mutex);
if ((ret = gst_pad_link(parser->my_src, parser->their_sink)) < 0) @@ -2754,9 +2760,9 @@ static BOOL avi_splitter_init_gst(struct parser *filter) }
pthread_mutex_lock(&filter->mutex); - while (!filter->no_more_pads && !filter->error) - pthread_cond_wait(&filter->init_cond, &filter->mutex); - if (filter->error) + while (!parser->no_more_pads && !parser->error) + pthread_cond_wait(&parser->init_cond, &filter->mutex); + if (parser->error) { pthread_mutex_unlock(&filter->mutex); return FALSE; @@ -2882,9 +2888,9 @@ static BOOL mpeg_splitter_init_gst(struct parser *filter) }
pthread_mutex_lock(&filter->mutex); - while (!filter->has_duration && !filter->error && !pin->eos) - pthread_cond_wait(&filter->init_cond, &filter->mutex); - if (filter->error) + while (!parser->has_duration && !parser->error && !pin->eos) + pthread_cond_wait(&parser->init_cond, &filter->mutex); + if (parser->error) { pthread_mutex_unlock(&filter->mutex); return FALSE;
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/winegstreamer/gstdemux.c | 63 ++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 30 deletions(-)
diff --git a/dlls/winegstreamer/gstdemux.c b/dlls/winegstreamer/gstdemux.c index 2c838643554..ea5d84e4105 100644 --- a/dlls/winegstreamer/gstdemux.c +++ b/dlls/winegstreamer/gstdemux.c @@ -58,6 +58,16 @@ struct wg_parser
pthread_cond_t init_cond; bool no_more_pads, has_duration, error; + + pthread_cond_t read_cond, read_done_cond; + struct + { + GstBuffer *buffer; + uint64_t offset; + uint32_t size; + bool done; + GstFlowReturn ret; + } read_request; };
struct parser @@ -86,15 +96,6 @@ struct parser pthread_mutex_t mutex;
HANDLE read_thread; - pthread_cond_t read_cond, read_done_cond; - struct - { - GstBuffer *buffer; - uint64_t offset; - uint32_t size; - bool done; - GstFlowReturn ret; - } read_request;
BOOL (*init_gst)(struct parser *filter); HRESULT (*source_query_accept)(struct parser_source *pin, const AM_MEDIA_TYPE *mt); @@ -1108,6 +1109,7 @@ static DWORD CALLBACK stream_thread(void *arg) static GstFlowReturn request_buffer_src(GstPad *pad, GstObject *parent, guint64 offset, guint size, GstBuffer **buffer) { struct parser *filter = gst_pad_get_element_private(pad); + struct wg_parser *parser = filter->wg_parser; GstBuffer *new_buffer = NULL; GstFlowReturn ret;
@@ -1118,21 +1120,21 @@ static GstFlowReturn request_buffer_src(GstPad *pad, GstObject *parent, guint64
pthread_mutex_lock(&filter->mutex);
- assert(!filter->read_request.buffer); - filter->read_request.buffer = *buffer; - filter->read_request.offset = offset; - filter->read_request.size = size; - filter->read_request.done = false; - pthread_cond_signal(&filter->read_cond); + assert(!parser->read_request.buffer); + parser->read_request.buffer = *buffer; + parser->read_request.offset = offset; + parser->read_request.size = size; + parser->read_request.done = false; + pthread_cond_signal(&parser->read_cond);
/* Note that we don't unblock this wait on GST_EVENT_FLUSH_START. We expect * the upstream pin to flush if necessary. We should never be blocked on * read_thread() not running. */
- while (!filter->read_request.done) - pthread_cond_wait(&filter->read_done_cond, &filter->mutex); + while (!parser->read_request.done) + pthread_cond_wait(&parser->read_done_cond, &filter->mutex);
- ret = filter->read_request.ret; + ret = parser->read_request.ret;
pthread_mutex_unlock(&filter->mutex);
@@ -1177,6 +1179,7 @@ static GstFlowReturn read_buffer(struct parser *This, guint64 ofs, guint len, Gs static DWORD CALLBACK read_thread(void *arg) { struct parser *filter = arg; + struct wg_parser *parser = filter->wg_parser;
TRACE("Starting read thread for filter %p.\n", filter);
@@ -1184,17 +1187,17 @@ static DWORD CALLBACK read_thread(void *arg)
for (;;) { - while (filter->sink_connected && !filter->read_request.buffer) - pthread_cond_wait(&filter->read_cond, &filter->mutex); + while (filter->sink_connected && !parser->read_request.buffer) + pthread_cond_wait(&parser->read_cond, &filter->mutex);
if (!filter->sink_connected) break;
- filter->read_request.done = true; - filter->read_request.ret = read_buffer(filter, filter->read_request.offset, - filter->read_request.size, filter->read_request.buffer); - filter->read_request.buffer = NULL; - pthread_cond_signal(&filter->read_done_cond); + parser->read_request.done = true; + parser->read_request.ret = read_buffer(filter, parser->read_request.offset, + parser->read_request.size, parser->read_request.buffer); + parser->read_request.buffer = NULL; + pthread_cond_signal(&parser->read_done_cond); }
pthread_mutex_unlock(&filter->mutex); @@ -1671,6 +1674,8 @@ static void wg_parser_destroy(struct wg_parser *parser) }
pthread_cond_destroy(&parser->init_cond); + pthread_cond_destroy(&parser->read_cond); + pthread_cond_destroy(&parser->read_done_cond);
free(parser); } @@ -1695,8 +1700,6 @@ static void parser_destroy(struct strmbase_filter *iface)
wg_parser_destroy(filter->wg_parser);
- pthread_cond_destroy(&filter->read_cond); - pthread_cond_destroy(&filter->read_done_cond); pthread_mutex_destroy(&filter->mutex);
strmbase_sink_cleanup(&filter->sink); @@ -1994,8 +1997,6 @@ static BOOL parser_init_gstreamer(void) static void parser_init_common(struct parser *object) { pthread_mutex_init(&object->mutex, NULL); - pthread_cond_init(&object->read_cond, NULL); - pthread_cond_init(&object->read_done_cond, NULL); object->flushing = true; }
@@ -2007,6 +2008,8 @@ static struct wg_parser *wg_parser_create(void) return NULL;
pthread_cond_init(&parser->init_cond, NULL); + pthread_cond_init(&parser->read_cond, NULL); + pthread_cond_init(&parser->read_done_cond, NULL);
TRACE("Created winegstreamer parser %p.\n", parser); return parser; @@ -2537,7 +2540,7 @@ static HRESULT GST_RemoveOutputPins(struct parser *This) pthread_mutex_lock(&This->mutex); This->sink_connected = false; pthread_mutex_unlock(&This->mutex); - pthread_cond_signal(&This->read_cond); + pthread_cond_signal(&parser->read_cond); WaitForSingleObject(This->read_thread, INFINITE); CloseHandle(This->read_thread);
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/winegstreamer/gstdemux.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/dlls/winegstreamer/gstdemux.c b/dlls/winegstreamer/gstdemux.c index ea5d84e4105..ab7efc24018 100644 --- a/dlls/winegstreamer/gstdemux.c +++ b/dlls/winegstreamer/gstdemux.c @@ -68,6 +68,8 @@ struct wg_parser bool done; GstFlowReturn ret; } read_request; + + bool flushing; };
struct parser @@ -89,7 +91,7 @@ struct parser /* FIXME: It would be nice to avoid duplicating these with strmbase. * However, synchronization is tricky; we need access to be protected by a * separate lock. */ - bool streaming, flushing, sink_connected; + bool streaming, sink_connected;
uint64_t next_pull_offset;
@@ -1037,13 +1039,14 @@ static void send_buffer(struct parser_source *pin, GstBuffer *buf) static bool get_stream_event(struct parser_source *pin, struct parser_event *event) { struct parser *filter = impl_from_strmbase_filter(pin->pin.pin.filter); + struct wg_parser *parser = filter->wg_parser;
pthread_mutex_lock(&filter->mutex);
- while (!filter->flushing && pin->event.type == PARSER_EVENT_NONE) + while (!parser->flushing && pin->event.type == PARSER_EVENT_NONE) pthread_cond_wait(&pin->event_cond, &filter->mutex);
- if (filter->flushing) + if (parser->flushing) { pthread_mutex_unlock(&filter->mutex); TRACE("Filter is flushing.\n"); @@ -1720,7 +1723,7 @@ static HRESULT parser_init_stream(struct strmbase_filter *iface)
filter->streaming = true; pthread_mutex_lock(&filter->mutex); - filter->flushing = false; + parser->flushing = false; pthread_mutex_unlock(&filter->mutex);
/* DirectShow retains the old seek positions, but resets to them every time @@ -1761,7 +1764,7 @@ static HRESULT parser_cleanup_stream(struct strmbase_filter *iface)
filter->streaming = false; pthread_mutex_lock(&filter->mutex); - filter->flushing = true; + parser->flushing = true; pthread_mutex_unlock(&filter->mutex);
for (i = 0; i < filter->source_count; ++i) @@ -1997,7 +2000,6 @@ static BOOL parser_init_gstreamer(void) static void parser_init_common(struct parser *object) { pthread_mutex_init(&object->mutex, NULL); - object->flushing = true; }
static struct wg_parser *wg_parser_create(void) @@ -2010,6 +2012,7 @@ static struct wg_parser *wg_parser_create(void) pthread_cond_init(&parser->init_cond, NULL); pthread_cond_init(&parser->read_cond, NULL); pthread_cond_init(&parser->read_done_cond, NULL); + parser->flushing = true;
TRACE("Created winegstreamer parser %p.\n", parser); return parser; @@ -2149,6 +2152,7 @@ static HRESULT WINAPI GST_Seeking_SetPositions(IMediaSeeking *iface, GstSeekType current_type = GST_SEEK_TYPE_SET, stop_type = GST_SEEK_TYPE_SET; struct parser_source *pin = impl_from_IMediaSeeking(iface); struct parser *filter = impl_from_strmbase_filter(pin->pin.pin.filter); + struct wg_parser *parser = filter->wg_parser; GstSeekFlags flags = 0; HRESULT hr = S_OK; int i; @@ -2168,7 +2172,7 @@ static HRESULT WINAPI GST_Seeking_SetPositions(IMediaSeeking *iface, if (!(current_flags & AM_SEEKING_NoFlush)) { pthread_mutex_lock(&filter->mutex); - filter->flushing = true; + parser->flushing = true; pthread_mutex_unlock(&filter->mutex);
for (i = 0; i < filter->source_count; ++i) @@ -2217,7 +2221,7 @@ static HRESULT WINAPI GST_Seeking_SetPositions(IMediaSeeking *iface, if (!(current_flags & AM_SEEKING_NoFlush)) { pthread_mutex_lock(&filter->mutex); - filter->flushing = false; + parser->flushing = false; pthread_mutex_unlock(&filter->mutex);
for (i = 0; i < filter->source_count; ++i)
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/winegstreamer/gstdemux.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/dlls/winegstreamer/gstdemux.c b/dlls/winegstreamer/gstdemux.c index ab7efc24018..1ddbc954fb4 100644 --- a/dlls/winegstreamer/gstdemux.c +++ b/dlls/winegstreamer/gstdemux.c @@ -69,7 +69,7 @@ struct wg_parser GstFlowReturn ret; } read_request;
- bool flushing; + bool flushing, sink_connected; };
struct parser @@ -1188,12 +1188,12 @@ static DWORD CALLBACK read_thread(void *arg)
pthread_mutex_lock(&filter->mutex);
- for (;;) + while (filter->sink_connected) { - while (filter->sink_connected && !parser->read_request.buffer) + while (parser->sink_connected && !parser->read_request.buffer) pthread_cond_wait(&parser->read_cond, &filter->mutex);
- if (!filter->sink_connected) + if (!parser->sink_connected) break;
parser->read_request.done = true; @@ -1593,6 +1593,7 @@ static HRESULT GST_Connect(struct parser *This, IPin *pConnectPin) parser->file_size = This->file_size;
This->sink_connected = true; + parser->sink_connected = true;
This->read_thread = CreateThread(NULL, 0, read_thread, This, 0, NULL);
@@ -2541,8 +2542,9 @@ static HRESULT GST_RemoveOutputPins(struct parser *This)
/* read_thread() needs to stay alive to service any read requests GStreamer * sends, so we can only shut it down after GStreamer stops. */ - pthread_mutex_lock(&This->mutex); This->sink_connected = false; + pthread_mutex_lock(&This->mutex); + parser->sink_connected = false; pthread_mutex_unlock(&This->mutex); pthread_cond_signal(&parser->read_cond); WaitForSingleObject(This->read_thread, INFINITE);