[vlc-commits] input: rework decoder_device handling
Thomas Guillem
git at videolan.org
Mon Jul 6 08:47:54 CEST 2020
vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Tue Jun 30 14:42:32 2020 +0200| [6134804bde41e8d5d6909472a3cbafa2e5e1fbc0] | committer: Thomas Guillem
input: rework decoder_device handling
Merge input_resource_GetVoutDecoderDevice() and input_resource_StartVout() into
input_resource_RequestVout().
RequestVout() can be used to create a vout without starting it (if cfg->fmt is
NULL). It allows the decoder to create a decoder_device from the vout manually,
then call RequestVout() again with a valid cfg->fmt to start it.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=6134804bde41e8d5d6909472a3cbafa2e5e1fbc0
---
src/input/decoder.c | 35 ++++++++++---------------
src/input/resource.c | 73 +++++++++++++++++++++++++++++-----------------------
src/input/resource.h | 8 +++---
3 files changed, 57 insertions(+), 59 deletions(-)
diff --git a/src/input/decoder.c b/src/input/decoder.c
index b013e485f8..4bb809610d 100644
--- a/src/input/decoder.c
+++ b/src/input/decoder.c
@@ -463,10 +463,9 @@ static int ModuleThread_UpdateVideoFormat( decoder_t *p_dec, vlc_video_context *
return -1;
}
}
- int res;
if (p_owner->vout_thread_started)
{
- res = vout_ChangeSource(p_vout, &p_dec->fmt_out.video);
+ int res = vout_ChangeSource(p_vout, &p_dec->fmt_out.video);
if (res == 0)
// the display/thread is started and can handle the new source format
return 0;
@@ -476,13 +475,14 @@ static int ModuleThread_UpdateVideoFormat( decoder_t *p_dec, vlc_video_context *
.vout = p_vout, .clock = p_owner->p_clock, .fmt = &p_dec->fmt_out.video,
.mouse_event = MouseEvent, .mouse_opaque = p_dec,
};
- res = input_resource_StartVout( p_owner->p_resource, vctx, &cfg);
- if (res == 0)
+ p_vout = input_resource_RequestVout( p_owner->p_resource, vctx, &cfg, NULL);
+ if (p_vout != NULL)
{
p_owner->vout_thread_started = true;
decoder_Notify(p_owner, on_vout_started, p_vout, vout_order);
+ return 0;
}
- return res;
+ return -1;
}
static int CreateVoutIfNeeded(vlc_input_decoder_t *p_owner,
@@ -537,15 +537,11 @@ static int CreateVoutIfNeeded(vlc_input_decoder_t *p_owner,
{
if (pp_vout || pp_dec_dev)
{
- vlc_mutex_lock( &p_owner->lock );
if ( pp_vout )
*pp_vout = p_owner->p_vout;
if ( pp_dec_dev )
- *pp_dec_dev = NULL;
- input_resource_GetVoutDecoderDevice( p_owner->p_resource,
- p_owner->p_vout, order, pp_dec_dev );
+ *pp_dec_dev = vout_GetDevice(p_owner->p_vout);
*order = p_owner->vout_order;
- vlc_mutex_unlock( &p_owner->lock );
}
return 0; // vout unchanged
}
@@ -556,24 +552,16 @@ static int CreateVoutIfNeeded(vlc_input_decoder_t *p_owner,
p_owner->p_vout = NULL; // the DecoderThread should not use the old vout anymore
vlc_mutex_unlock( &p_owner->lock );
- if ( pp_dec_dev ) *pp_dec_dev = NULL;
- p_vout = input_resource_GetVoutDecoderDevice( p_owner->p_resource,
- p_vout, order, pp_dec_dev );
-
+ if ( pp_dec_dev )
+ *pp_dec_dev = NULL;
+ const vout_configuration_t cfg = { .vout = p_vout, .fmt = NULL };
+ p_vout = input_resource_RequestVout( p_owner->p_resource, NULL, &cfg, order );
if (pp_vout)
*pp_vout = p_vout;
vlc_mutex_lock( &p_owner->lock );
p_owner->p_vout = p_vout;
p_owner->vout_order = *order;
- if ( pp_dec_dev )
- {
- if( p_vout == NULL && *pp_dec_dev != NULL )
- {
- vlc_decoder_device_Release( *pp_dec_dev );
- *pp_dec_dev = NULL;
- }
- }
DecoderUpdateFormatLocked( p_owner );
p_owner->fmt.video.i_chroma = p_dec->fmt_out.i_codec;
@@ -591,6 +579,9 @@ static int CreateVoutIfNeeded(vlc_input_decoder_t *p_owner,
return -1;
}
+ if (pp_dec_dev != NULL)
+ *pp_dec_dev = vout_GetDevice(p_owner->p_vout);
+
vlc_fifo_Lock( p_owner->p_fifo );
p_owner->reset_out_state = true;
vlc_fifo_Unlock( p_owner->p_fifo );
diff --git a/src/input/resource.c b/src/input/resource.c
index 5e24660dec..606a9e84df 100644
--- a/src/input/resource.c
+++ b/src/input/resource.c
@@ -410,16 +410,11 @@ void input_resource_PutVout(input_resource_t *p_resource,
vlc_mutex_unlock( &p_resource->lock );
}
-vout_thread_t *input_resource_GetVoutDecoderDevice(input_resource_t *p_resource,
- vout_thread_t *cfg_vout,
- enum vlc_vout_order *order,
- vlc_decoder_device **pp_dec_dev)
+static struct vout_resource *
+RequestVoutRsc(input_resource_t *p_resource)
{
- vout_thread_t *vout;
struct vout_resource *vout_rsc = NULL;
- vlc_mutex_lock( &p_resource->lock );
- if (cfg_vout == NULL) {
if( p_resource->vout_rsc_free != NULL )
{
/* The free vout is always the first one */
@@ -427,7 +422,6 @@ vout_thread_t *input_resource_GetVoutDecoderDevice(input_resource_t *p_resource,
vout_rsc = p_resource->vout_rsc_free;
p_resource->vout_rsc_free = NULL;
- cfg_vout = vout_rsc->vout;
}
else
{
@@ -436,16 +430,15 @@ vout_thread_t *input_resource_GetVoutDecoderDevice(input_resource_t *p_resource,
* pre-configured on this dummy vout. */
vlc_object_t *parent = vlc_list_is_empty( &p_resource->vout_rscs ) ?
VLC_OBJECT(p_resource->p_vout_dummy) : p_resource->p_parent;
- cfg_vout = vout = vout_Create(parent);
+ vout_thread_t *vout = vout_Create(parent);
if (vout == NULL)
- goto out;
+ return NULL;
vout_rsc = vout_resource_Create(vout);
if (vout_rsc == NULL)
{
vout_Close(vout);
- cfg_vout = vout = NULL;
- goto out;
+ return NULL;
}
vout_rsc->order = vlc_list_is_empty( &p_resource->vout_rscs ) ?
@@ -455,10 +448,32 @@ vout_thread_t *input_resource_GetVoutDecoderDevice(input_resource_t *p_resource,
vout_resource_Add(vout_rsc, p_resource);
vlc_mutex_unlock(&p_resource->lock_hold);
}
+
+ return vout_rsc;
+}
+
+vout_thread_t *input_resource_RequestVout(input_resource_t *p_resource,
+ vlc_video_context *vctx,
+ const vout_configuration_t *cfg,
+ enum vlc_vout_order *order)
+{
+ vlc_mutex_lock( &p_resource->lock );
+ struct vout_resource *vout_rsc = NULL;
+
+ vout_configuration_t dcfg = *cfg;
+ if (dcfg.vout == NULL)
+ {
+ vout_rsc = RequestVoutRsc(p_resource);
+ if (vout_rsc == NULL)
+ {
+ vlc_mutex_unlock( &p_resource->lock );
+ return NULL;
+ }
+ dcfg.vout = vout_rsc->vout;
}
else
{
- vout_rsc = resource_GetVoutRsc(p_resource, cfg_vout);
+ vout_rsc = resource_GetVoutRsc(p_resource, dcfg.vout);
assert(vout_rsc != NULL);
/* the caller is going to reuse the free vout, it's not free anymore */
@@ -466,27 +481,21 @@ vout_thread_t *input_resource_GetVoutDecoderDevice(input_resource_t *p_resource,
p_resource->vout_rsc_free = NULL;
}
- if (pp_dec_dev)
- *pp_dec_dev = vout_GetDevice(cfg_vout);
-
- *order = vout_rsc->order;
-
- vout = cfg_vout;
+ if (order != NULL)
+ *order = vout_rsc->order;
-out:
- vlc_mutex_unlock( &p_resource->lock );
- return vout;
-}
+ if (dcfg.fmt == NULL)
+ {
+ /* A NULL fmt means that only the vout creation is requested, do not
+ * start it with vout_Request(). */
+ vlc_mutex_unlock(&p_resource->lock);
+ return dcfg.vout;
+ }
-int input_resource_StartVout(input_resource_t *p_resource,
- vlc_video_context *vctx,
- const vout_configuration_t *cfg)
-{
- vlc_mutex_lock( &p_resource->lock );
- if (vout_Request(cfg, vctx, p_resource->p_input)) {
- input_resource_PutVoutLocked(p_resource, cfg->vout);
+ if (vout_Request(&dcfg, vctx, p_resource->p_input)) {
+ input_resource_PutVoutLocked(p_resource, dcfg.vout);
vlc_mutex_unlock(&p_resource->lock);
- return -1;
+ return NULL;
}
DisplayVoutTitle(p_resource, cfg->vout);
@@ -499,7 +508,7 @@ int input_resource_StartVout(input_resource_t *p_resource,
¶m);
}
vlc_mutex_unlock( &p_resource->lock );
- return 0;
+ return dcfg.vout;
}
vout_thread_t *input_resource_HoldVout( input_resource_t *p_resource )
diff --git a/src/input/resource.h b/src/input/resource.h
index b46ef6a33d..7a725aabcf 100644
--- a/src/input/resource.h
+++ b/src/input/resource.h
@@ -37,11 +37,9 @@ void input_resource_SetInput( input_resource_t *, input_thread_t * );
*/
sout_instance_t *input_resource_RequestSout( input_resource_t *, sout_instance_t *, const char *psz_sout );
-vout_thread_t *input_resource_GetVoutDecoderDevice(input_resource_t *,
- vout_thread_t *cfg_vout,
- enum vlc_vout_order *order,
- vlc_decoder_device **);
-int input_resource_StartVout(input_resource_t *, vlc_video_context *, const vout_configuration_t *);
+vout_thread_t *input_resource_RequestVout(input_resource_t *, vlc_video_context *,
+ const vout_configuration_t *,
+ enum vlc_vout_order *order);
void input_resource_PutVout(input_resource_t *, vout_thread_t *);
/**
More information about the vlc-commits
mailing list