mirror of
https://github.com/videolan/vlc.git
synced 2024-11-23 18:03:48 +08:00
thumbnailer: use a struct of callbacks
In order to behave like the vlc_preparser.h API.
This commit is contained in:
parent
e8a0160684
commit
7e22dbe1d3
@ -32,20 +32,29 @@ typedef size_t vlc_thumbnailer_req_id;
|
||||
#define VLC_THUMBNAILER_REQ_ID_INVALID 0
|
||||
|
||||
/**
|
||||
* \brief vlc_thumbnailer_cb defines a callback invoked on thumbnailing completion or error
|
||||
*
|
||||
* This callback will always be called, provided vlc_thumbnailer_Request returned
|
||||
* a non NULL request, and provided the request is not cancelled before its
|
||||
* completion.
|
||||
* In case of failure, p_thumbnail will be NULL.
|
||||
* The picture, if any, is owned by the thumbnailer, and must be acquired by using
|
||||
* \link picture_Hold \endlink to use it pass the callback's scope.
|
||||
*
|
||||
* \param data Is the opaque pointer passed as vlc_thumbnailer_Request last parameter
|
||||
* \param thumbnail The generated thumbnail, or NULL in case of failure or timeout
|
||||
* thumbnailer callbacks
|
||||
*/
|
||||
typedef void(*vlc_thumbnailer_cb)( void* data, picture_t* thumbnail );
|
||||
|
||||
struct vlc_thumbnailer_cbs
|
||||
{
|
||||
/**
|
||||
* Event received on thumbnailing completion or error
|
||||
*
|
||||
* This callback will always be called, provided vlc_thumbnailer_Request
|
||||
* returned a valid request, and provided the request is not cancelled
|
||||
* before its completion.
|
||||
*
|
||||
* @note This callback is mandatory.
|
||||
*
|
||||
* In case of failure, p_thumbnail will be NULL. The picture, if any, is
|
||||
* owned by the thumbnailer, and must be acquired by using \link
|
||||
* picture_Hold \endlink to use it pass the callback's scope.
|
||||
* \param thumbnail The generated thumbnail, or NULL in case of failure or
|
||||
* timeout
|
||||
* \param data Is the opaque pointer passed as vlc_thumbnailer_Request last
|
||||
* parameter
|
||||
*/
|
||||
void (*on_ended)(picture_t* thumbnail, void *data);
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief vlc_thumbnailer_Create Creates a thumbnailer object
|
||||
@ -93,8 +102,8 @@ struct vlc_thumbnailer_seek_arg
|
||||
* \param seek_arg pointer to a seek struct, that tell at which time the
|
||||
* thumbnail should be taken, NULL to disable seek
|
||||
* \param timeout A timeout value, or VLC_TICK_INVALID to disable timeout
|
||||
* \param cb A user callback to be called on completion (success & error)
|
||||
* \param user_data An opaque value, provided as pf_cb's first parameter
|
||||
* \param cbs callback to listen to events (can't be NULL)
|
||||
* \param cbs_userdata opaque pointer used by the callbacks
|
||||
* \returns > 0 if the item was scheduled for thumbnailing, 0 in case of error.
|
||||
*
|
||||
* If this function returns a valid id, the callback is guaranteed
|
||||
@ -107,7 +116,8 @@ VLC_API vlc_thumbnailer_req_id
|
||||
vlc_thumbnailer_Request( vlc_thumbnailer_t *thumbnailer,
|
||||
input_item_t *input_item,
|
||||
const struct vlc_thumbnailer_seek_arg *seek_arg,
|
||||
vlc_thumbnailer_cb cb, void* user_data );
|
||||
const struct vlc_thumbnailer_cbs *cbs,
|
||||
void *cbs_userdata );
|
||||
|
||||
/**
|
||||
* \brief vlc_thumbnailer_Camcel Cancel a thumbnail request
|
||||
|
@ -927,7 +927,7 @@ struct libvlc_media_thumbnail_request_t
|
||||
vlc_thumbnailer_req_id id;
|
||||
};
|
||||
|
||||
static void media_on_thumbnail_ready( void* data, picture_t* thumbnail )
|
||||
static void media_on_thumbnail_ready( picture_t* thumbnail, void* data )
|
||||
{
|
||||
libvlc_media_thumbnail_request_t *req = data;
|
||||
libvlc_media_t *p_media = req->md;
|
||||
@ -972,8 +972,11 @@ libvlc_media_thumbnail_request( libvlc_instance_t *inst,
|
||||
req->type = picture_type;
|
||||
req->crop = crop;
|
||||
libvlc_media_retain( md );
|
||||
static const struct vlc_thumbnailer_cbs cbs = {
|
||||
.on_ended = media_on_thumbnail_ready,
|
||||
};
|
||||
req->id = vlc_thumbnailer_Request( thumb, md->p_input_item, seek_arg,
|
||||
media_on_thumbnail_ready, req );
|
||||
&cbs, req );
|
||||
if ( req->id == VLC_PREPARSER_REQ_ID_INVALID )
|
||||
{
|
||||
free( req );
|
||||
|
@ -43,7 +43,7 @@ Thumbnailer::Thumbnailer( vlc_medialibrary_module_t* ml )
|
||||
throw std::runtime_error( "Failed to instantiate a vlc_thumbnailer_t" );
|
||||
}
|
||||
|
||||
void Thumbnailer::onThumbnailComplete( void* data, picture_t* thumbnail )
|
||||
void Thumbnailer::onThumbnailComplete( picture_t* thumbnail, void *data )
|
||||
{
|
||||
ThumbnailerCtx* ctx = static_cast<ThumbnailerCtx*>( data );
|
||||
|
||||
@ -76,9 +76,13 @@ bool Thumbnailer::generate( const medialibrary::IMedia&, const std::string& mrl,
|
||||
.pos = position,
|
||||
.speed = vlc_thumbnailer_seek_arg::VLC_THUMBNAILER_SEEK_FAST,
|
||||
};
|
||||
|
||||
static const struct vlc_thumbnailer_cbs cbs = {
|
||||
.on_ended = onThumbnailComplete,
|
||||
};
|
||||
vlc_thumbnailer_req_id requestId =
|
||||
vlc_thumbnailer_Request( m_thumbnailer.get(), item.get(), &seek_arg,
|
||||
&onThumbnailComplete, &ctx );
|
||||
&cbs, &ctx );
|
||||
|
||||
if (requestId == VLC_THUMBNAILER_REQ_ID_INVALID)
|
||||
{
|
||||
|
@ -137,7 +137,7 @@ public:
|
||||
void stop() override;
|
||||
|
||||
private:
|
||||
static void onThumbnailComplete( void* data, picture_t* thumbnail );
|
||||
static void onThumbnailComplete( picture_t* thumbnail, void* data );
|
||||
|
||||
private:
|
||||
vlc_medialibrary_module_t* m_ml;
|
||||
|
@ -47,7 +47,7 @@ typedef struct task
|
||||
|
||||
struct vlc_thumbnailer_seek_arg seek_arg;
|
||||
input_item_t *item;
|
||||
vlc_thumbnailer_cb cb;
|
||||
const struct vlc_thumbnailer_cbs *cbs;
|
||||
void* userdata;
|
||||
|
||||
enum
|
||||
@ -69,7 +69,7 @@ static void RunnableRun(void *);
|
||||
static task_t *
|
||||
TaskNew(vlc_thumbnailer_t *thumbnailer, input_item_t *item,
|
||||
const struct vlc_thumbnailer_seek_arg *seek_arg,
|
||||
vlc_thumbnailer_cb cb, void *userdata)
|
||||
const struct vlc_thumbnailer_cbs *cbs, void *userdata )
|
||||
{
|
||||
task_t *task = malloc(sizeof(*task));
|
||||
if (!task)
|
||||
@ -84,7 +84,7 @@ TaskNew(vlc_thumbnailer_t *thumbnailer, input_item_t *item,
|
||||
else
|
||||
task->seek_arg = *seek_arg;
|
||||
|
||||
task->cb = cb;
|
||||
task->cbs = cbs;
|
||||
task->userdata = userdata;
|
||||
|
||||
task->status = RUNNING;
|
||||
@ -107,8 +107,7 @@ TaskDestroy(task_t *task)
|
||||
|
||||
static void NotifyThumbnail(task_t *task, picture_t *pic)
|
||||
{
|
||||
assert(task->cb);
|
||||
task->cb(task->userdata, pic);
|
||||
task->cbs->on_ended(pic, task->userdata);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -232,9 +231,11 @@ vlc_thumbnailer_req_id
|
||||
vlc_thumbnailer_Request( vlc_thumbnailer_t *thumbnailer,
|
||||
input_item_t *item,
|
||||
const struct vlc_thumbnailer_seek_arg *seek_arg,
|
||||
vlc_thumbnailer_cb cb, void* userdata )
|
||||
const struct vlc_thumbnailer_cbs *cbs, void *userdata )
|
||||
{
|
||||
task_t *task = TaskNew(thumbnailer, item, seek_arg, cb, userdata);
|
||||
assert( cbs != NULL && cbs->on_ended != NULL );
|
||||
|
||||
task_t *task = TaskNew(thumbnailer, item, seek_arg, cbs, userdata);
|
||||
if (!task)
|
||||
return 0;
|
||||
|
||||
|
@ -68,7 +68,7 @@ struct test_ctx
|
||||
bool b_done;
|
||||
};
|
||||
|
||||
static void thumbnailer_callback( void* data, picture_t* thumbnail )
|
||||
static void thumbnailer_callback( picture_t* thumbnail, void *data )
|
||||
{
|
||||
struct test_ctx* p_ctx = data;
|
||||
vlc_mutex_lock( &p_ctx->lock );
|
||||
@ -152,8 +152,11 @@ static void test_thumbnails( libvlc_instance_t* p_vlc )
|
||||
seek_arg.speed = test_params[i].b_fast_seek ?
|
||||
VLC_THUMBNAILER_SEEK_FAST : VLC_THUMBNAILER_SEEK_PRECISE;
|
||||
}
|
||||
static const struct vlc_thumbnailer_cbs cbs = {
|
||||
.on_ended = thumbnailer_callback,
|
||||
};
|
||||
id = vlc_thumbnailer_Request( p_thumbnailer, p_item, &seek_arg,
|
||||
thumbnailer_callback, &ctx );
|
||||
&cbs, &ctx );
|
||||
assert( id != VLC_THUMBNAILER_REQ_ID_INVALID );
|
||||
|
||||
while ( ctx.b_done == false )
|
||||
@ -168,7 +171,7 @@ static void test_thumbnails( libvlc_instance_t* p_vlc )
|
||||
}
|
||||
}
|
||||
|
||||
static void thumbnailer_callback_cancel( void* data, picture_t* p_thumbnail )
|
||||
static void thumbnailer_callback_cancel( picture_t* p_thumbnail, void *data )
|
||||
{
|
||||
(void) data; (void) p_thumbnail;
|
||||
/* This callback should not be called since the request is cancelled */
|
||||
@ -188,9 +191,12 @@ static void test_cancel_thumbnail( libvlc_instance_t* p_vlc )
|
||||
input_item_t* p_item = input_item_New( psz_mrl, "mock item" );
|
||||
assert( p_item != NULL );
|
||||
|
||||
static const struct vlc_thumbnailer_cbs cbs = {
|
||||
.on_ended = thumbnailer_callback_cancel,
|
||||
};
|
||||
|
||||
vlc_thumbnailer_req_id id =
|
||||
vlc_thumbnailer_Request( p_thumbnailer, p_item, NULL,
|
||||
thumbnailer_callback_cancel, NULL );
|
||||
vlc_thumbnailer_Request( p_thumbnailer, p_item, NULL, &cbs, NULL );
|
||||
|
||||
vlc_thumbnailer_Cancel( p_thumbnailer, id );
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user