<html><head></head><body>Hi,<br><br>It's needed in two cases, the duplicate module and the core (what the next patch removes). We can add it in duplicate, with a lot of boilerplate. But given that the ES output has a similar internal locking for essentially the same motivation (concurrent ES processed in different threads), it seems logical to move it from sout instance to sout stream instead and share the code.<br><br>In the common non-contended case, vlc_mutex_lock is just one atomic op extra.<br><br><div class="gmail_quote">Le 12 octobre 2020 09:57:20 GMT+03:00, Steve Lhomme <robux4@ycbcr.xyz> a écrit :<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<pre class="k9mail">This lock looks like in belongs in the duplicate module rather that do a <br>lock for all sout_stream_t users.<br><br>On 2020-10-11 16:30, Rémi Denis-Courmont wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #729fcf; padding-left: 1ex;">The stream output is called from multiple threads without<br>synchronisation, notably at least one thread per ES decoder. Normally,<br>the stream output instance (sout_instance_t) lock will serialise all<br>calls to the first stream output module instance (sout_stream_t) in the<br>stream output chain.<br><br>This is not practical if there is also concurrency within the chain.<br>One notable case is when the select/duplicate module is used in filter<br>mode and one of the select/duplicate target is threaded, e.g.:<br><br> #duplicate{dst=transcode{...},dst=transcode{...}}:std{...}<br><br>In that example, the standard output can be called from both transcode<br>filters.<br><br>To solve this, add a lock for each element in the stream output chain.<br>Alternatively, we could drop filter mode from select/duplicate, leaving<br>only the (more common) output mode where duplicate is the last element<br>in the chain.<hr> src/stream_output/stream_output.c | 44 +++++++++++++++++++++++++++----<br> 1 file changed, 39 insertions(+), 5 deletions(-)<br><br>diff --git a/src/stream_output/stream_output.c b/src/stream_output/stream_output.c<br>index e0769dc749..069fe57346 100644<br>--- a/src/stream_output/stream_output.c<br>+++ b/src/stream_output/stream_output.c<br>@@ -736,38 +736,71 @@ static void mrl_Clean( mrl_t *p_mrl )<br> <br> struct sout_stream_private {<br> sout_stream_t stream;<br>+ vlc_mutex_t lock;<br> module_t *module;<br> };<br> <br> #define sout_stream_priv(s) \<br> container_of(s, struct sout_stream_private, stream)<br> <br>+static void sout_StreamLock(sout_stream_t *s)<br>+{<br>+ vlc_mutex_lock(&sout_stream_priv(s)->lock);<br>+}<br>+<br>+static void sout_StreamUnlock(sout_stream_t *s)<br>+{<br>+ vlc_mutex_unlock(&sout_stream_priv(s)->lock);<br>+}<br>+<br> void *sout_StreamIdAdd(sout_stream_t *s, const es_format_t *fmt)<br> {<br>- return s->ops->add(s, fmt);<br>+ void *id;<br>+<br>+ sout_StreamLock(s);<br>+ id = s->ops->add(s, fmt);<br>+ sout_StreamUnlock(s);<br>+ return id;<br> }<br> <br> void sout_StreamIdDel(sout_stream_t *s, void *id)<br> {<br>+ sout_StreamLock(s);<br> s->ops->del(s, id);<br>+ sout_StreamUnlock(s);<br> }<br> <br> int sout_StreamIdSend(sout_stream_t *s, void *id, block_t *b)<br> {<br>- return s->ops->send(s, id, b);<br>+ int val;<br>+<br>+ sout_StreamLock(s);<br>+ val = s->ops->send(s, id, b);<br>+ sout_StreamUnlock(s);<br>+ return val;<br> }<br> <br> void sout_StreamFlush(sout_stream_t *s, void *id)<br> {<br> if (s->ops->flush != NULL)<br>+ {<br>+ sout_StreamLock(s);<br> s->ops->flush(s, id);<br>+ sout_StreamUnlock(s);<br>+ }<br> }<br> <br> int sout_StreamControlVa(sout_stream_t *s, int i_query, va_list args)<br> {<br>- if (s->ops->control == NULL)<br>- return VLC_EGENERIC;<br>- return s->ops->control(s, i_query, args);<br>+ int val = VLC_EGENERIC;<br>+<br>+ if (s->ops->control != NULL)<br>+ {<br>+ sout_StreamLock(s);<br>+ val = s->ops->control(s, i_query, args);<br>+ sout_StreamUnlock(s);<br>+ }<br>+ return val;<br> }<br> <br> /* Destroy a "stream_out" module */<br>@@ -823,6 +856,7 @@ static sout_stream_t *sout_StreamNew( vlc_object_t *parent, char *psz_name,<br> if (unlikely(priv == NULL))<br> return NULL;<br> <br>+ vlc_mutex_init(&priv->lock);<br> p_stream = &priv->stream;<br> p_stream->psz_name = psz_name;<br> p_stream->p_cfg = p_cfg;<br>-- <br>2.28.0<hr>vlc-devel mailing list<br>To unsubscribe or modify your subscription options:<br><a href="https://mailman.videolan.org/listinfo/vlc-devel">https://mailman.videolan.org/listinfo/vlc-devel</a><br><br></blockquote><hr>vlc-devel mailing list<br>To unsubscribe or modify your subscription options:<br><a href="https://mailman.videolan.org/listinfo/vlc-devel">https://mailman.videolan.org/listinfo/vlc-devel</a></pre></blockquote></div><br>-- <br>Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma brièveté.</body></html>