Skip to content

Commit

Permalink
libvlc: merge libvlc_video_setup_cb and libvlc_video_direct3d_device_…
Browse files Browse the repository at this point in the history
…setup_cb

For now the OpenGL setup doesn't need to get any adapter or context from the
host app.
  • Loading branch information
robUx4 committed Feb 10, 2020
1 parent 2369082 commit 8cbb084
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 55 deletions.
3 changes: 2 additions & 1 deletion doc/libvlc/QtGL/qtvlcwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ class VLCVideo
}

// This callback is called during initialisation.
static bool setup(void** data)
static bool setup(void** data, const libvlc_video_setup_device_cfg_t *cfg,
libvlc_video_setup_device_info_t *out)
{
if (!QOpenGLContext::supportsThreadedOpenGL())
return false;
Expand Down
3 changes: 2 additions & 1 deletion doc/libvlc/sdl_opengl_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ class VLCVideo
}

// This callback is called during initialisation.
static bool setup(void** data)
static bool setup(void** data, const libvlc_video_setup_device_cfg_t *cfg,
libvlc_video_setup_device_info_t *out)
{
VLCVideo** that = static_cast<VLCVideo**>(data);
(*that)->m_width = 0;
Expand Down
87 changes: 38 additions & 49 deletions include/vlc/libvlc_media_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -503,16 +503,44 @@ void libvlc_video_set_format_callbacks( libvlc_media_player_t *mp,
libvlc_video_cleanup_cb cleanup );


typedef struct
{
bool hardware_decoding; /** set if D3D11_CREATE_DEVICE_VIDEO_SUPPORT is needed for D3D11 */
} libvlc_video_setup_device_cfg_t;

typedef struct
{
union {
void *device_context; /** ID3D11DeviceContext* for D3D11, IDirect3D9 * for D3D9 */
int adapter; /** Adapter to use with the IDirect3D9 for D3D9 */
};
} libvlc_video_setup_device_info_t;

/**
* Callback prototype called to initialize user data.
* Setup the rendering environment.
*
* \param opaque private pointer passed to the @a libvlc_video_set_output_callbacks()
* or @a libvlc_video_direct3d_set_callbacks()
* on input. The callback can change this value on output to be
* passed to all the other callbacks set on @a libvlc_video_set_output_callbacks(). [IN/OUT]
* or @a libvlc_video_set_output_callbacks(). [IN/OUT]
* \param cfg requested configuration of the video device [IN]
* \param out libvlc_video_setup_device_info_t* to fill [OUT]
* \return true on success
* \version LibVLC 4.0.0 or later
*
* For \ref libvlc_video_direct3d_engine_d3d9 the output must be a IDirect3D9*.
* A reference to this object is held until the \ref LIBVLC_VIDEO_DEVICE_CLEANUP is called.
* the device must be created with D3DPRESENT_PARAMETERS.hDeviceWindow set to 0.
*
* For \ref libvlc_video_direct3d_engine_d3d11 the output must be a ID3D11DeviceContext*.
* A reference to this object is held until the \ref LIBVLC_VIDEO_DEVICE_CLEANUP is called.
* The ID3D11Device used to create ID3D11DeviceContext must have multithreading enabled.
*/
typedef bool (*libvlc_video_setup_cb)(void** opaque);
typedef bool (*libvlc_video_setup_cb)(void **opaque,
const libvlc_video_setup_device_cfg_t *cfg,
libvlc_video_setup_device_info_t *out);


/**
Expand Down Expand Up @@ -551,8 +579,7 @@ typedef struct
* Callback prototype called on video size changes.
* Update the rendering output setup.
*
* \param opaque private pointer set on the opaque parameter of @a libvlc_video_setup_cb()
* or @a libvlc_video_direct3d_device_setup_cb() [IN]
* \param opaque private pointer set on the opaque parameter of @a libvlc_video_setup_cb() [IN]
* \param cfg configuration of the video that will be rendered [IN]
* \param output configuration describing with how the rendering is setup [OUT]
* \version LibVLC 4.0.0 or later
Expand All @@ -572,8 +599,7 @@ typedef bool (*libvlc_video_update_output_cb)(void* opaque, const libvlc_video_r
/**
* Callback prototype called after performing drawing calls.
*
* \param opaque private pointer set on the opaque parameter of @a libvlc_video_setup_cb()
* or @a libvlc_video_direct3d_device_setup_cb() [IN]
* \param opaque private pointer set on the opaque parameter of @a libvlc_video_setup_cb() [IN]
* \version LibVLC 4.0.0 or later
*/
typedef void (*libvlc_video_swap_cb)(void* opaque);
Expand All @@ -582,8 +608,7 @@ typedef void (*libvlc_video_swap_cb)(void* opaque);
* Callback prototype to set up the OpenGL context for rendering.
* Tell the host the rendering is about to start/has finished.
*
* \param opaque private pointer set on the opaque parameter of @a libvlc_video_setup_cb()
* or @a libvlc_video_direct3d_device_setup_cb() [IN]
* \param opaque private pointer set on the opaque parameter of @a libvlc_video_setup_cb() [IN]
* \param enter true to set the context as current, false to unset it [IN]
* \return true on success
* \version LibVLC 4.0.0 or later
Expand Down Expand Up @@ -696,44 +721,9 @@ typedef enum libvlc_video_direct3d_engine_t {
libvlc_video_direct3d_engine_d3d9,
} libvlc_video_direct3d_engine_t;

typedef struct
{
bool hardware_decoding; /** set if D3D11_CREATE_DEVICE_VIDEO_SUPPORT is needed for D3D11 */
} libvlc_video_setup_device_cfg_t;

typedef struct
{
union {
void *device_context; /** ID3D11DeviceContext* for D3D11, IDirect3D9 * for D3D9 */
int adapter; /** Adapter to use with the IDirect3D9 for D3D9 */
};
} libvlc_video_setup_device_info_t;

/** Setup the rendering environment.
/** Cleanup the rendering environment initialized during \ref libvlc_video_setup_cb.
*
* \param opaque private pointer passed to the @a libvlc_video_direct3d_set_callbacks()
* on input. The callback can change this value on output to be
* passed to all the other callbacks set on @a libvlc_video_direct3d_set_callbacks(). [IN/OUT]
* \param cfg requested configuration of the video device [IN]
* \param out libvlc_video_setup_device_info_t* to fill [OUT]
* \return true on success
* \version LibVLC 4.0.0 or later
*
* For \ref libvlc_video_direct3d_engine_d3d9 the output must be a IDirect3D9*.
* A reference to this object is held until the \ref LIBVLC_VIDEO_DEVICE_CLEANUP is called.
* the device must be created with D3DPRESENT_PARAMETERS.hDeviceWindow set to 0.
*
* For \ref libvlc_video_direct3d_engine_d3d11 the output must be a ID3D11DeviceContext*.
* A reference to this object is held until the \ref LIBVLC_VIDEO_DEVICE_CLEANUP is called.
* The ID3D11Device used to create ID3D11DeviceContext must have multithreading enabled.
*/
typedef bool( *libvlc_video_direct3d_device_setup_cb )( void **opaque,
const libvlc_video_setup_device_cfg_t *cfg,
libvlc_video_setup_device_info_t *out );

/** Cleanup the rendering environment initialized during \ref libvlc_video_direct3d_device_setup_cb.
*
* \param opaque private pointer set on the opaque parameter of @a libvlc_video_direct3d_device_setup_cb() [IN]
* \param opaque private pointer set on the opaque parameter of @a libvlc_video_setup_cb() [IN]
* \version LibVLC 4.0.0 or later
*/
typedef void( *libvlc_video_direct3d_device_cleanup_cb )( void *opaque );
Expand All @@ -743,9 +733,9 @@ typedef void( *libvlc_video_direct3d_device_cleanup_cb )( void *opaque );
* This allows text rendering and aspect ratio to be handled properly when the host
* rendering size changes.
*
* It may be called before the \ref libvlc_video_direct3d_device_setup_cb callback.
* It may be called before the \ref libvlc_video_setup_cb callback.
*
* \param opaque private pointer set on the opaque parameter of @a libvlc_video_direct3d_device_setup_cb() [IN]
* \param opaque private pointer set on the opaque parameter of @a libvlc_video_setup_cb() [IN]
* \param report_size_change callback which must be called when the host size changes. [IN]
* The callback is valid until another call to \ref libvlc_video_direct3d_set_resize_cb
* is done. This may be called from any thread.
Expand All @@ -757,8 +747,7 @@ typedef void( *libvlc_video_direct3d_set_resize_cb )( void *opaque,

/** Tell the host the rendering for the given plane is about to start
*
* \param opaque private pointer set on the opaque parameter of @a libvlc_video_setup_cb()
* or @a libvlc_video_direct3d_device_setup_cb() [IN]
* \param opaque private pointer set on the opaque parameter of @a libvlc_video_setup_cb() [IN]
* \param plane number of the rendering plane to select
* \return true on success
* \version LibVLC 4.0.0 or later
Expand Down Expand Up @@ -802,7 +791,7 @@ typedef bool( *libvlc_video_direct3d_select_plane_cb )( void *opaque, size_t pla
LIBVLC_API
bool libvlc_video_direct3d_set_callbacks( libvlc_media_player_t *mp,
libvlc_video_direct3d_engine_t engine,
libvlc_video_direct3d_device_setup_cb setup_cb,
libvlc_video_setup_cb setup_cb,
libvlc_video_direct3d_device_cleanup_cb cleanup_cb,
libvlc_video_direct3d_set_resize_cb resize_cb,
libvlc_video_update_output_cb update_output_cb,
Expand Down
2 changes: 1 addition & 1 deletion lib/media_player.c
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,7 @@ bool libvlc_video_set_output_callbacks(libvlc_media_player_t *mp,

bool libvlc_video_direct3d_set_callbacks(libvlc_media_player_t *mp,
libvlc_video_direct3d_engine_t engine,
libvlc_video_direct3d_device_setup_cb setup_cb,
libvlc_video_setup_cb setup_cb,
libvlc_video_direct3d_device_cleanup_cb cleanup_cb,
libvlc_video_direct3d_set_resize_cb resize_cb,
libvlc_video_update_output_cb update_output_cb,
Expand Down
2 changes: 1 addition & 1 deletion modules/hw/d3d11/d3d11_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ static int D3D11OpenDecoderDevice(vlc_decoder_device *device, bool forced, vout_
else
#endif
{
libvlc_video_direct3d_device_setup_cb setupDeviceCb = var_InheritAddress( device, "vout-cb-setup" );
libvlc_video_setup_cb setupDeviceCb = var_InheritAddress( device, "vout-cb-setup" );
if ( setupDeviceCb )
{
/* decoder device coming from the external app */
Expand Down
2 changes: 1 addition & 1 deletion modules/hw/d3d9/d3d9_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ int D3D9OpenDecoderDevice(vlc_decoder_device *device, vout_window_t *wnd)

int adapter;
sys->cleanupDeviceCb = NULL;
libvlc_video_direct3d_device_setup_cb setupDeviceCb = var_InheritAddress( device, "vout-cb-setup" );
libvlc_video_setup_cb setupDeviceCb = var_InheritAddress( device, "vout-cb-setup" );
if ( setupDeviceCb )
{
/* external rendering */
Expand Down
6 changes: 5 additions & 1 deletion modules/video_output/vgl.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,15 @@ static int Open(vlc_gl_t *gl, unsigned width, unsigned height)
gl->destroy = Close;

if( sys->setupCb )
if( !sys->setupCb(&sys->opaque) )
{
libvlc_video_setup_device_cfg_t setup_cfg = {};
libvlc_video_setup_device_info_t configured_cfg;
if( !sys->setupCb(&sys->opaque, &setup_cfg, &configured_cfg) )
{
msg_Err( gl, "user setup failed" );
return VLC_EGENERIC;
}
}

Resize(gl, width, height);
return VLC_SUCCESS;
Expand Down

0 comments on commit 8cbb084

Please sign in to comment.