On Fri Sep 8 10:55:31 2023 +0000, Ziqing Hui wrote:
The condition variable is used here: https://gitlab.winehq.org/wine/wine/-/merge_requests/3303/diffs?commit_id=5f... After we done muxing, we call finalize() in our PE side, then PE side call the corresponding finalize() function in wg_muxer backend. Our backend finalize() look like this:
sink_event_cb() /* sink cb of muxer my_sink. */ { [...] switch (event->type) { case GST_EVENT_EOS: pthread_mutex_lock(&muxer->mutex); muxer->eos = true; pthread_mutex_unlock(&muxer->mutex); pthread_cond_signal(&muxer->cond); break; [...] } [...] } NTSTATUS wg_muxer_finalize(void *args) { struct wg_muxer *muxer = get_muxer(*(wg_muxer_t *)args); struct wg_muxer_stream *stream; /* Notify each stream of EOS. */ LIST_FOR_EACH_ENTRY(stream, &muxer->streams, struct wg_muxer_stream, entry) { if (!push_event(stream->my_src, gst_event_new_segment_done(GST_FORMAT_BYTES, -1)) || !push_event(stream->my_src, gst_event_new_eos())) return E_FAIL; } /* Wait for muxer EOS. */ pthread_mutex_lock(&muxer->mutex); while (!muxer->eos) pthread_cond_wait(&muxer->cond, &muxer->mutex); pthread_mutex_unlock(&muxer->mutex); return S_OK; }
The sink_event_cb() will be called in GstTask thread of mp4muxer element, which is not the same thread with wg_muxer_finalize(). If we get rid of condition variable, how do we wait for the EOS, use a simple while() loop?
I see, this is very unfortunate IMO... Looks like it's coming from the GstAggregator class.
I still think we should avoid the condition variable, but I don't really have any good suggestion to workaround that. A busy loop might be better, assuming it will quickly EOS, but it's a bit ugly.
Alternatively I had thought about implementing a GTask pool with Win32 threads, which would also solve some problems we have with logging, but I don't know if it's a good idea. It would let us use Win32 sync primitives for notifications instead though, so less ugly but a lot more code so I'm not sure it's worth it.
Then, as we already have condition variables elsewhere, I can probably live with it in this case, if you think it's better.