[vlc-devel] [PATCH 16/39] decoder: split the creation of the vout/decoder device and the display module
Steve Lhomme
robux4 at ycbcr.xyz
Wed Oct 2 16:23:31 CEST 2019
First handle the resources needed by the get_device() call, then the
format_update() which creates the display.
---
src/input/decoder.c | 55 +++++++++++++++++++++++++++++++--------------
1 file changed, 38 insertions(+), 17 deletions(-)
diff --git a/src/input/decoder.c b/src/input/decoder.c
index c5917ce0302..3b6c4f05771 100644
--- a/src/input/decoder.c
+++ b/src/input/decoder.c
@@ -460,13 +460,18 @@ static void FixDisplayFormat(decoder_t *p_dec, video_format_t *fmt)
video_format_AdjustColorSpace( fmt );
}
-static int CreateDisplay(struct decoder_owner *p_owner, vlc_decoder_device *dec_dev, vout_thread_t *p_vout)
+static int ModuleThread_UpdateVideoFormat( decoder_t *p_dec )
{
+ struct decoder_owner *p_owner = dec_get_owner( p_dec );
+
+ vlc_mutex_lock( &p_owner->lock );
+
+ vout_thread_t *p_vout = p_owner->p_vout;
+ vlc_mutex_unlock( &p_owner->lock );
+
if (!p_vout)
return -1;
- decoder_t *p_dec = &p_owner->dec;
-
video_format_t fmt;
FixDisplayFormat( p_dec, &fmt );
@@ -496,10 +501,10 @@ static int CreateDisplay(struct decoder_owner *p_owner, vlc_decoder_device *dec_
.dpb_size = dpb_size + p_dec->i_extra_picture_buffers + 1,
.mouse_event = MouseEvent, .mouse_opaque = p_dec,
};
- return input_resource_GetDisplay( p_owner->p_resource, dec_dev, &cfg);
+ return input_resource_GetDisplay( p_owner->p_resource, p_owner->p_dec_dev, &cfg);
}
-static int CreateVoutIfNeeded(struct decoder_owner *p_owner)
+static int CreateVoutIfNeeded(struct decoder_owner *p_owner, vlc_decoder_device **pp_dec_dev)
{
decoder_t *p_dec = &p_owner->dec;
bool need_vout = false;
@@ -566,24 +571,30 @@ static int CreateVoutIfNeeded(struct decoder_owner *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;
enum vlc_vout_order order;
vout_configuration_t cfg = {
.vout = p_vout, .clock = p_owner->p_clock, .fmt = &fmt,
.mouse_event = MouseEvent, .mouse_opaque = p_dec
};
- vlc_decoder_device *dec_dev = NULL;
p_vout = input_resource_GetVoutDecoderDevice( p_owner->p_resource,
- &cfg, &order, &dec_dev );
- if (CreateDisplay( p_owner, dec_dev, p_vout ) != 0)
- p_vout = NULL;
+ &cfg, &order, pp_dec_dev );
if (p_vout)
decoder_Notify(p_owner, on_vout_added, p_vout, order);
vlc_mutex_lock( &p_owner->lock );
p_owner->p_vout = p_vout;
- if ( p_owner->p_dec_dev != NULL )
- vlc_decoder_device_Release( p_owner->p_dec_dev );
- p_owner->p_dec_dev = dec_dev;
+ if ( pp_dec_dev )
+ {
+ if ( p_owner->p_dec_dev != NULL )
+ vlc_decoder_device_Release( p_owner->p_dec_dev );
+ if( p_vout == NULL && *pp_dec_dev != NULL )
+ {
+ vlc_decoder_device_Release( *pp_dec_dev );
+ *pp_dec_dev = NULL;
+ }
+ p_owner->p_dec_dev = *pp_dec_dev ? vlc_decoder_device_Hold(*pp_dec_dev) : NULL;
+ }
DecoderUpdateFormatLocked( p_owner );
p_owner->fmt.video.i_chroma = p_dec->fmt_out.i_codec;
@@ -602,13 +613,22 @@ static int CreateVoutIfNeeded(struct decoder_owner *p_owner)
return 1; // new vout was created
}
-static int ModuleThread_UpdateVideoFormat( decoder_t *p_dec )
+static vlc_decoder_device * ModuleThread_GetDecoderDevice( decoder_t *p_dec )
{
struct decoder_owner *p_owner = dec_get_owner( p_dec );
- int created_vout = CreateVoutIfNeeded(p_owner);
- if (created_vout != 0)
- return created_vout == -1 ? -1 : 0; // error or new vout was created
+ vlc_decoder_device *dec_device = NULL;
+ int created_vout = CreateVoutIfNeeded(p_owner, &dec_device);
+ if (created_vout == -1)
+ {
+ if ( dec_device )
+ vlc_decoder_device_Release( dec_device );
+ return NULL; // error
+ }
+ if (created_vout == 1)
+ {
+ return dec_device; // new vout was created with a decoder device
+ }
bool need_format_update = false;
if ( memcmp( &p_dec->fmt_out.video.mastering,
@@ -634,7 +654,7 @@ static int ModuleThread_UpdateVideoFormat( decoder_t *p_dec )
DecoderUpdateFormatLocked( p_owner );
vlc_mutex_unlock( &p_owner->lock );
}
- return 0;
+ return dec_device;
}
static picture_t *ModuleThread_NewVideoBuffer( decoder_t *p_dec )
@@ -1741,6 +1761,7 @@ static void *DecoderThread( void *p_data )
static const struct decoder_owner_callbacks dec_video_cbs =
{
.video = {
+ .get_device = ModuleThread_GetDecoderDevice,
.format_update = ModuleThread_UpdateVideoFormat,
.buffer_new = ModuleThread_NewVideoBuffer,
.abort_pictures = DecoderThread_AbortPictures,
--
2.17.1
More information about the vlc-devel
mailing list