[vlc-devel] [PATCH 35/38] video context: allow storing typed extra data in the video context
Steve Lhomme
robux4 at ycbcr.xyz
Wed Oct 2 11:37:45 CEST 2019
On 2019-10-02 9:17, Thomas Guillem wrote:
> This commit could be moved before "nvdec: create a video context for the decoder" to avoid re-modifying all va modules.
OK
> On Tue, Oct 1, 2019, at 13:24, Steve Lhomme wrote:
>> Each video context can store extra objects, like the IDirect3DDevice9* for D3D9,
>> which is not found in the decoder device.
>> ---
>> include/vlc_picture.h | 18 +++++++++++++++++-
>> modules/codec/avcodec/d3d11va.c | 2 +-
>> modules/codec/avcodec/dxva2.c | 2 +-
>> modules/codec/avcodec/vaapi.c | 2 +-
>> modules/hw/nvdec/nvdec.c | 2 +-
>> modules/hw/vdpau/avcodec.c | 2 +-
>> src/input/decoder_helpers.c | 16 +++++++++++++---
>> src/libvlccore.sym | 1 +
>> src/video_output/display.c | 2 +-
>> 9 files changed, 37 insertions(+), 10 deletions(-)
>>
>> diff --git a/include/vlc_picture.h b/include/vlc_picture.h
>> index 9238e098956..9ca42b9b6e3 100644
>> --- a/include/vlc_picture.h
>> +++ b/include/vlc_picture.h
>> @@ -87,12 +87,28 @@ struct vlc_video_context_operations
>> void (*destroy)(void *priv);
>> };
>>
>> +/** Decoder device type */
>> +enum vlc_video_context_type
>> +{
>> + VLC_VIDEO_CONTEXT_NONE,
>> + VLC_VIDEO_CONTEXT_VAAPI,
>> + VLC_VIDEO_CONTEXT_VDPAU,
>> + VLC_VIDEO_CONTEXT_DXVA2,
>> + VLC_VIDEO_CONTEXT_D3D11VA,
>> + VLC_VIDEO_CONTEXT_AWINDOW,
>> + VLC_VIDEO_CONTEXT_NVDEC,
>> + VLC_VIDEO_CONTEXT_CVPX,
>> + VLC_VIDEO_CONTEXT_MMAL,
>> +};
>> +
>> VLC_API vlc_video_context *
>> vlc_video_context_Create(vlc_decoder_device *,
>> + enum vlc_video_context_type
>> private_type,
>> size_t private_size,
>> const struct
>> vlc_video_context_operations *);
>> VLC_API void vlc_video_context_Release(vlc_video_context *);
>>
>> -VLC_API void *vlc_video_context_GetPrivate(vlc_video_context *);
>> +VLC_API enum vlc_video_context_type vlc_video_context_GetType(const
>> vlc_video_context *);
>> +VLC_API void *vlc_video_context_GetPrivate(vlc_video_context *, enum
>> vlc_video_context_type);
>> VLC_API vlc_video_context *vlc_video_context_Hold(vlc_video_context *);
>>
>> /**
>> diff --git a/modules/codec/avcodec/d3d11va.c
>> b/modules/codec/avcodec/d3d11va.c
>> index e895129c202..4b079415e82 100644
>> --- a/modules/codec/avcodec/d3d11va.c
>> +++ b/modules/codec/avcodec/d3d11va.c
>> @@ -354,7 +354,7 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx,
>> enum PixelFormat pix_fmt,
>> if (sys->d3d_dev.context_mutex == INVALID_HANDLE_VALUE)
>> msg_Warn(va, "No mutex found to lock the decoder");
>>
>> - sys->vctx = vlc_video_context_Create( dec_device, 0, NULL
>> );
>> + sys->vctx = vlc_video_context_Create( dec_device,
>> VLC_VIDEO_CONTEXT_D3D11VA, 0, NULL );
>> if (likely(sys->vctx != NULL))
>> {
>> void *d3dvidctx = NULL;
>> diff --git a/modules/codec/avcodec/dxva2.c
>> b/modules/codec/avcodec/dxva2.c
>> index 353143214ba..12594ddf0e5 100644
>> --- a/modules/codec/avcodec/dxva2.c
>> +++ b/modules/codec/avcodec/dxva2.c
>> @@ -266,7 +266,7 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx,
>> enum PixelFormat pix_fmt,
>> d3d9_decoder_device_t *d3d9_decoder = GetD3D9OpaqueDevice(
>> dec_device );
>> if ( d3d9_decoder != NULL )
>> {
>> - sys->vctx = vlc_video_context_Create( dec_device, 0, NULL );
>> + sys->vctx = vlc_video_context_Create( dec_device,
>> VLC_VIDEO_CONTEXT_DXVA2, 0, NULL );
>> if (likely(sys->vctx != NULL))
>> {
>> D3D9_CloneExternal(&sys->hd3d, d3d9_decoder->device);
>> diff --git a/modules/codec/avcodec/vaapi.c
>> b/modules/codec/avcodec/vaapi.c
>> index c0acbd70f60..337a1b4f8c5 100644
>> --- a/modules/codec/avcodec/vaapi.c
>> +++ b/modules/codec/avcodec/vaapi.c
>> @@ -204,7 +204,7 @@ static int Create(vlc_va_t *va, AVCodecContext
>> *ctx, enum PixelFormat pix_fmt,
>>
>> msg_Info(va, "Using %s", vaQueryVendorString(sys->hw_ctx.display));
>>
>> - sys->vctx = vlc_video_context_Create( dec_device, 0, NULL );
>> + sys->vctx = vlc_video_context_Create( dec_device,
>> VLC_VIDEO_CONTEXT_VAAPI, 0, NULL );
>> if (sys->vctx == NULL)
>> goto error;
>>
>> diff --git a/modules/hw/nvdec/nvdec.c b/modules/hw/nvdec/nvdec.c
>> index 6d7f07314ac..d59949c8ff4 100644
>> --- a/modules/hw/nvdec/nvdec.c
>> +++ b/modules/hw/nvdec/nvdec.c
>> @@ -869,7 +869,7 @@ static int OpenDecoder(vlc_object_t *p_this)
>> goto error;
>> }
>>
>> - p_sys->vctx_out = vlc_video_context_Create( device, 0, NULL );
>> + p_sys->vctx_out = vlc_video_context_Create( device,
>> VLC_VIDEO_CONTEXT_NVDEC, 0, NULL );
>>
>> vlc_fourcc_t output_chromas[3];
>> size_t chroma_idx = 0;
>> diff --git a/modules/hw/vdpau/avcodec.c b/modules/hw/vdpau/avcodec.c
>> index e4a5c58b9fb..2688714c717 100644
>> --- a/modules/hw/vdpau/avcodec.c
>> +++ b/modules/hw/vdpau/avcodec.c
>> @@ -215,7 +215,7 @@ static int Open(vlc_va_t *va, AVCodecContext
>> *avctx, enum PixelFormat pix_fmt,
>> goto error;
>> }
>>
>> - sys->vctx = vlc_video_context_Create( device, 0, NULL );
>> + sys->vctx = vlc_video_context_Create( device,
>> VLC_VIDEO_CONTEXT_VDPAU, 0, NULL );
>> if (sys->vctx == NULL)
>> goto error;
>>
>> diff --git a/src/input/decoder_helpers.c b/src/input/decoder_helpers.c
>> index bc741867517..828e4bdb697 100644
>> --- a/src/input/decoder_helpers.c
>> +++ b/src/input/decoder_helpers.c
>> @@ -195,11 +195,13 @@ struct vlc_video_context
>> vlc_atomic_rc_t rc;
>> vlc_decoder_device *device;
>> const struct vlc_video_context_operations *ops;
>> + enum vlc_video_context_type private_type;
>> size_t private_size;
>> uint8_t private[];
>> };
>>
>> vlc_video_context * vlc_video_context_Create(vlc_decoder_device
>> *device,
>> + enum vlc_video_context_type
>> private_type,
>> size_t private_size,
>> const struct
>> vlc_video_context_operations *ops)
>> {
>> @@ -207,6 +209,7 @@ vlc_video_context *
>> vlc_video_context_Create(vlc_decoder_device *device,
>> if (unlikely(vctx == NULL))
>> return NULL;
>> vlc_atomic_rc_init( &vctx->rc );
>> + vctx->private_type = private_type;
>> vctx->private_size = private_size;
>> vctx->device = device;
>> if (vctx->device)
>> @@ -215,9 +218,16 @@ vlc_video_context *
>> vlc_video_context_Create(vlc_decoder_device *device,
>> return vctx;
>> }
>>
>> -void *vlc_video_context_GetPrivate(vlc_video_context *vctx)
>> +void *vlc_video_context_GetPrivate(vlc_video_context *vctx, enum
>> vlc_video_context_type type)
>> {
>> - return &vctx->private;
>> + if (vctx->private_type == type)
>> + return &vctx->private;
>> + return NULL;
>> +}
>> +
>> +enum vlc_video_context_type vlc_video_context_GetType(const
>> vlc_video_context *vctx)
>> +{
>> + return vctx->private_type;
>> }
>>
>> vlc_video_context *vlc_video_context_Hold(vlc_video_context *vctx)
>> @@ -233,7 +243,7 @@ void vlc_video_context_Release(vlc_video_context
>> *vctx)
>> if (vctx->device)
>> vlc_decoder_device_Release( vctx->device );
>> if ( vctx->ops && vctx->ops->destroy )
>> - vctx->ops->destroy( vlc_video_context_GetPrivate(vctx) );
>> + vctx->ops->destroy( vlc_video_context_GetPrivate(vctx,
>> vctx->private_type) );
>> free(vctx);
>> }
>> }
>> diff --git a/src/libvlccore.sym b/src/libvlccore.sym
>> index bba72aa0012..66899073871 100644
>> --- a/src/libvlccore.sym
>> +++ b/src/libvlccore.sym
>> @@ -948,6 +948,7 @@ vlc_media_tree_Preparse
>> vlc_viewpoint_to_4x4
>> vlc_video_context_Create
>> vlc_video_context_Release
>> +vlc_video_context_GetType
>> vlc_video_context_GetPrivate
>> vlc_video_context_Hold
>> vlc_video_context_HoldDevice
>> diff --git a/src/video_output/display.c b/src/video_output/display.c
>> index 56245be3b08..f9fb3d0e7c2 100644
>> --- a/src/video_output/display.c
>> +++ b/src/video_output/display.c
>> @@ -770,7 +770,7 @@ vout_display_t *vout_display_New(vlc_object_t
>> *parent,
>> if (owner)
>> vd->owner = *owner;
>>
>> - vlc_video_context *fake_vctx =
>> vlc_video_context_Create(dec_device, 0, NULL);
>> + vlc_video_context *fake_vctx =
>> vlc_video_context_Create(dec_device, VLC_VIDEO_CONTEXT_NONE, 0, NULL);
>>
>> if (vlc_module_load(vd, "vout display", module, module && *module != '\0',
>> vout_display_start, vd, &osys->cfg, &vd->fmt,
>> --
>> 2.17.1
>>
>> _______________________________________________
>> vlc-devel mailing list
>> To unsubscribe or modify your subscription options:
>> https://mailman.videolan.org/listinfo/vlc-devel
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel
>
More information about the vlc-devel
mailing list