Commit 537ef170 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

filter: use constant callback structures

parent 9882ff2e
......@@ -38,21 +38,24 @@
typedef struct filter_owner_sys_t filter_owner_sys_t;
typedef struct filter_owner_t
struct filter_video_callbacks
{
void *sys;
picture_t *(*buffer_new)(filter_t *);
};
struct filter_subpicture_callbacks
{
subpicture_t *(*buffer_new)(filter_t *);
};
typedef struct filter_owner_t
{
union
{
struct
{
picture_t * (*buffer_new)( filter_t * );
} video;
struct
{
subpicture_t * (*buffer_new)( filter_t * );
} sub;
const struct filter_video_callbacks *video;
const struct filter_subpicture_callbacks *sub;
};
void *sys;
} filter_owner_t;
struct vlc_mouse_t;
......@@ -162,7 +165,7 @@ struct filter_t
*/
static inline picture_t *filter_NewPicture( filter_t *p_filter )
{
picture_t *pic = p_filter->owner.video.buffer_new( p_filter );
picture_t *pic = p_filter->owner.video->buffer_new( p_filter );
if( pic == NULL )
msg_Warn( p_filter, "can't get output picture" );
return pic;
......@@ -208,7 +211,7 @@ static inline block_t *filter_DrainAudio( filter_t *p_filter )
*/
static inline subpicture_t *filter_NewSubpicture( filter_t *p_filter )
{
subpicture_t *subpic = p_filter->owner.sub.buffer_new( p_filter );
subpicture_t *subpic = p_filter->owner.sub->buffer_new( p_filter );
if( subpic == NULL )
msg_Warn( p_filter, "can't get output subpicture" );
return subpic;
......
......@@ -383,15 +383,18 @@ static void *Add( sout_stream_t *p_stream, const es_format_t *p_fmt )
msg_Dbg( p_stream, "mosaic bridge id=%s pos=%d", p_es->psz_id, i );
/* Create user specified video filters */
static const struct filter_video_callbacks cbs =
{
.buffer_new = video_new_buffer_filter,
};
psz_chain = var_GetNonEmptyString( p_stream, CFG_PREFIX "vfilter" );
msg_Dbg( p_stream, "psz_chain: %s", psz_chain );
if( psz_chain )
{
filter_owner_t owner = {
.video = &cbs,
.sys = p_owner,
.video = {
.buffer_new = video_new_buffer_filter,
},
};
p_sys->p_vf2 = filter_chain_NewVideo( p_stream, false, &owner );
......
......@@ -302,15 +302,18 @@ static int transcode_video_new( sout_stream_t *p_stream, sout_stream_id_sys_t *i
return VLC_SUCCESS;
}
static const struct filter_video_callbacks transcode_filter_video_cbs =
{
.buffer_new = transcode_video_filter_buffer_new,
};
static void transcode_video_filter_init( sout_stream_t *p_stream,
sout_stream_id_sys_t *id )
{
sout_stream_sys_t *p_sys = p_stream->p_sys;
filter_owner_t owner = {
.video = &transcode_filter_video_cbs,
.sys = p_sys,
.video = {
.buffer_new = transcode_video_filter_buffer_new,
},
};
const es_format_t *p_fmt_out = &id->p_decoder->fmt_out;
......
......@@ -140,6 +140,11 @@ static picture_t *BufferNew( filter_t *p_filter )
#define CHAIN_LEVEL_MAX 2
static const struct filter_video_callbacks filter_video_chain_cbs =
{
.buffer_new = BufferNew,
};
/*****************************************************************************
* Activate: allocate a chroma function
*****************************************************************************
......@@ -155,10 +160,8 @@ static int Activate( filter_t *p_filter, int (*pf_build)(filter_t *) )
return VLC_ENOMEM;
filter_owner_t owner = {
.video = &filter_video_chain_cbs,
.sys = p_filter,
.video = {
.buffer_new = BufferNew,
},
};
p_sys->p_chain = filter_chain_NewVideo( p_filter, p_filter->b_allow_fmt_out_change, &owner );
......
......@@ -137,6 +137,11 @@ static picture_t *video_new( filter_t *p_filter )
return filter_NewPicture( p_filter->owner.sys );
}
static const struct filter_video_callbacks canvas_cbs =
{
.buffer_new = video_new,
};
/*****************************************************************************
*
*****************************************************************************/
......@@ -232,10 +237,8 @@ static int Activate( vlc_object_t *p_this )
p_filter->p_sys = p_sys;
filter_owner_t owner = {
.video = &canvas_cbs,
.sys = p_filter,
.video = {
.buffer_new = video_new,
},
};
p_sys->p_chain = filter_chain_NewVideo( p_filter, true, &owner );
......
......@@ -84,6 +84,11 @@ typedef struct
filter_chain_t *p_chain;
} filter_sys_t;
static const struct filter_video_callbacks filter_video_edge_cbs =
{
.buffer_new = new_frame,
};
/*****************************************************************************
* Opens the filter.
* Allocates and initializes data needed by the filter. The image needs to
......@@ -96,10 +101,8 @@ static int Open( vlc_object_t *p_this )
int i_ret;
filter_t *p_filter = (filter_t *)p_this;
filter_owner_t owner = {
.video = &filter_video_edge_cbs,
.sys = p_filter,
.video = {
.buffer_new = new_frame,
},
};
/* Store the filter chain in p_sys */
p_filter->p_sys = (filter_sys_t *)filter_chain_NewVideo( p_filter, true, &owner );
......
......@@ -122,21 +122,24 @@ static picture_t *filter_chain_VideoBufferNew( filter_t *filter )
/* XXX ugly */
filter->owner.sys = chain->owner.sys;
picture_t *pic = chain->owner.video.buffer_new( filter );
picture_t *pic = chain->owner.video->buffer_new( filter );
filter->owner.sys = chain;
return pic;
}
}
static const struct filter_video_callbacks filter_chain_video_cbs =
{
.buffer_new = filter_chain_VideoBufferNew,
};
#undef filter_chain_NewVideo
filter_chain_t *filter_chain_NewVideo( vlc_object_t *obj, bool allow_change,
const filter_owner_t *restrict owner )
{
filter_owner_t callbacks = {
.video = &filter_chain_video_cbs,
.sys = obj,
.video = {
.buffer_new = filter_chain_VideoBufferNew,
},
};
return filter_chain_NewInner( &callbacks, "video filter",
......
......@@ -810,13 +810,18 @@ static picture_t *filter_new_picture( filter_t *p_filter )
return picture_NewFromFormat( &p_filter->fmt_out.video );
}
static const struct filter_video_callbacks image_filter_cbs =
{
.buffer_new = filter_new_picture,
};
static filter_t *CreateFilter( vlc_object_t *p_this, const es_format_t *p_fmt_in,
const video_format_t *p_fmt_out )
{
filter_t *p_filter;
p_filter = vlc_custom_create( p_this, sizeof(filter_t), "filter" );
p_filter->owner.video.buffer_new = filter_new_picture;
p_filter->owner.video = &image_filter_cbs;
es_format_Copy( &p_filter->fmt_in, p_fmt_in );
es_format_Copy( &p_filter->fmt_out, p_fmt_in );
......
......@@ -370,14 +370,16 @@ typedef struct {
atomic_bool reset_pictures;
} vout_display_owner_sys_t;
static const struct filter_video_callbacks vout_display_filter_cbs = {
.buffer_new = VideoBufferNew,
};
static int VoutDisplayCreateRender(vout_display_t *vd)
{
vout_display_owner_sys_t *osys = vd->owner.sys;
filter_owner_t owner = {
.video = &vout_display_filter_cbs,
.sys = vd,
.video = {
.buffer_new = VideoBufferNew,
},
};
osys->filters = filter_chain_NewVideo(vd, false, &owner);
......
......@@ -909,10 +909,11 @@ static picture_t *ConvertRGB32AndBlend(vout_thread_t *vout, picture_t *pic,
assert(vout->p->spu_blend);
static const struct filter_video_callbacks cbs = {
.buffer_new = ConvertRGB32AndBlendBufferNew,
};
filter_owner_t owner = {
.video = {
.buffer_new = ConvertRGB32AndBlendBufferNew,
},
.video = &cbs,
};
filter_chain_t *filterc = filter_chain_NewVideo(vout, false, &owner);
if (!filterc)
......@@ -1470,16 +1471,20 @@ static int ThreadStart(vout_thread_t *vout, vout_display_state_t *state)
vout->p->filter.configuration = NULL;
video_format_Copy(&vout->p->filter.format, &vout->p->original);
static const struct filter_video_callbacks static_cbs = {
.buffer_new = VoutVideoFilterStaticNewPicture,
};
static const struct filter_video_callbacks interactive_cbs = {
.buffer_new = VoutVideoFilterInteractiveNewPicture,
};
filter_owner_t owner = {
.video = &static_cbs,
.sys = vout,
.video = {
.buffer_new = VoutVideoFilterStaticNewPicture,
},
};
vout->p->filter.chain_static =
filter_chain_NewVideo( vout, true, &owner );
owner.video.buffer_new = VoutVideoFilterInteractiveNewPicture;
owner.video = &interactive_cbs;
vout->p->filter.chain_interactive =
filter_chain_NewVideo( vout, true, &owner );
......
......@@ -214,6 +214,10 @@ static filter_t *SpuRenderCreateAndLoadText(spu_t *spu)
return text;
}
static const struct filter_video_callbacks spu_scaler_cbs = {
.buffer_new = spu_new_video_buffer,
};
static filter_t *SpuRenderCreateAndLoadScale(vlc_object_t *object,
vlc_fourcc_t src_chroma,
vlc_fourcc_t dst_chroma,
......@@ -237,7 +241,7 @@ static filter_t *SpuRenderCreateAndLoadScale(vlc_object_t *object,
scale->fmt_out.video.i_height =
scale->fmt_out.video.i_visible_height = require_resize ? 16 : 32;
scale->owner.video.buffer_new = spu_new_video_buffer;
scale->owner.video = &spu_scaler_cbs;
scale->p_module = module_need(scale, "video converter", NULL, false);
......@@ -1202,13 +1206,17 @@ static subpicture_t *sub_new_buffer(filter_t *filter)
return subpicture;
}
static const struct filter_subpicture_callbacks sub_cbs = {
.buffer_new = sub_new_buffer,
};
static int SubSourceInit(filter_t *filter, void *data)
{
spu_t *spu = data;
int channel = spu_RegisterChannel(spu);
filter->owner.sys = (void *)(intptr_t)channel;
filter->owner.sub.buffer_new = sub_new_buffer;
filter->owner.sub = &sub_cbs;
return VLC_SUCCESS;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment