Commit 91f70c65 authored by Thomas Guillem's avatar Thomas Guillem

vout: process static filter chain in separate thread

parent c0094240
......@@ -697,6 +697,112 @@ static void VoutGetDisplayCfg(vout_thread_t *vout, const video_format_t *fmt, vo
cfg->align.vertical = VLC_VIDEO_ALIGN_BOTTOM;
}
static void *static_filter_thread_Run(void *ctx)
{
vout_thread_t *vout = ctx;
vout_thread_sys_t *sys = vout->p;
int canc = vlc_savecancel();
for (;;)
{
picture_t *pic = picture_fifo_Wait(sys->decoder_fifo);
const vlc_tick_t now_dbg = vlc_tick_now();
if (pic == NULL)
{
filter_chain_VideoFlush(sys->filter.chain_static);
vlc_restorecancel(canc);
vlc_testcancel();
canc = vlc_savecancel();
continue;
}
if (sys->is_late_dropped && !pic->b_force)
{
const vlc_tick_t system_now = vlc_tick_now();
const vlc_tick_t system_pts =
vlc_clock_ConvertToSystem(sys->clock, system_now,
pic->date, sys->rate);
if (system_pts != INT64_MAX &&
vout_IsPictureLate(vout, pic, system_now, system_pts))
{
picture_Release(pic);
vout_statistic_AddLost(&vout->p->statistic, 1);
continue;
}
}
pic = filter_chain_VideoFilter(sys->filter.chain_static, pic);
if (pic)
picture_fifo_Push(sys->filter.static_fifo, pic);
else
{
pic = filter_chain_VideoFilter(sys->filter.chain_static, NULL);
if (pic)
picture_fifo_Push(sys->filter.static_fifo, pic);
}
fprintf(stderr, "filter took %"PRId64 "\n", vlc_tick_now() - now_dbg);
}
vlc_assert_unreachable();
}
static int static_filter_thread_Start(vout_thread_t *vout)
{
vout_thread_sys_t *sys = vout->p;
assert(!sys->filter.static_fifo);
sys->filter.static_fifo = picture_fifo_New();
if (!sys->filter.static_fifo)
return VLC_ENOMEM;
int ret = vlc_clone(&sys->filter.static_thread, static_filter_thread_Run,
vout, VLC_THREAD_PRIORITY_OUTPUT);
if (ret != VLC_SUCCESS)
{
picture_fifo_Delete(sys->filter.static_fifo);
sys->filter.static_fifo = NULL;
return ret;
}
msg_Info(vout, "static_filter_thread_Start");
return VLC_SUCCESS;
}
static void static_filter_thread_Stop(vout_thread_t *vout)
{
vout_thread_sys_t *sys = vout->p;
if (!sys->filter.static_fifo)
return;
vlc_cancel(sys->filter.static_thread);
picture_fifo_Signal(sys->decoder_fifo);
vlc_join(sys->filter.static_thread, NULL);
picture_fifo_Delete(sys->filter.static_fifo);
sys->filter.static_fifo = NULL;
msg_Info(vout, "static_filter_thread_Stop");
}
static void static_filter_thread_Flush(vout_thread_t *vout)
{
vout_thread_sys_t *sys = vout->p;
if (!sys->filter.static_fifo)
return;
picture_fifo_Signal(sys->decoder_fifo);
}
/* */
static int FilterRestartCallback(vlc_object_t *p_this, char const *psz_var,
vlc_value_t oldval, vlc_value_t newval,
......@@ -737,7 +843,7 @@ static picture_t *VoutVideoFilterStaticNewPicture(filter_t *filter)
{
vout_thread_t *vout = filter->owner.sys;
vlc_mutex_assert(&vout->p->filter.lock);
//vlc_mutex_assert(&vout->p->filter.lock);
if (filter_chain_IsEmpty(vout->p->filter.chain_interactive))
// we may be using the last filter of both chains, so we get the picture
// from the display module pool, just like for the last interactive filter.
......@@ -762,10 +868,13 @@ static void ThreadFilterFlush(vout_thread_t *vout, bool is_locked)
if (!is_locked)
vlc_mutex_lock(&vout->p->filter.lock);
filter_chain_VideoFlush(vout->p->filter.chain_static);
filter_chain_VideoFlush(vout->p->filter.chain_interactive);
if (!is_locked)
vlc_mutex_unlock(&vout->p->filter.lock);
static_filter_thread_Flush(vout);
}
typedef struct {
......@@ -778,6 +887,8 @@ static void ThreadChangeFilters(vout_thread_t *vout,
const bool *new_deinterlace,
bool is_locked)
{
static_filter_thread_Stop(vout);
ThreadFilterFlush(vout, is_locked);
ThreadDelAllFilterCallbacks(vout);
......@@ -890,6 +1001,12 @@ static void ThreadChangeFilters(vout_thread_t *vout,
vout->p->filter.configuration = filters ? strdup(filters) : NULL;
}
if (!filter_chain_IsEmpty(vout->p->filter.chain_static))
{
if (static_filter_thread_Start(vout) != VLC_SUCCESS)
goto error;
}
if (!is_locked)
vlc_mutex_unlock(&vout->p->filter.lock);
......@@ -913,7 +1030,7 @@ static int ThreadDisplayPreparePicture(vout_thread_t *vout, bool reuse,
vlc_mutex_lock(&vout->p->filter.lock);
picture_t *picture = filter_chain_VideoFilter(vout->p->filter.chain_static, NULL);
picture_t *picture = NULL;
assert(!reuse || !picture);
while (!picture) {
......@@ -921,7 +1038,8 @@ static int ThreadDisplayPreparePicture(vout_thread_t *vout, bool reuse,
if (reuse && vout->p->displayed.decoded) {
decoded = picture_Hold(vout->p->displayed.decoded);
} else {
decoded = picture_fifo_Pop(vout->p->decoder_fifo);
decoded = sys->filter.static_fifo ? picture_fifo_Pop(sys->filter.static_fifo)
: picture_fifo_Pop(sys->decoder_fifo);
if (decoded) {
if (is_late_dropped && !decoded->b_force) {
......@@ -969,8 +1087,7 @@ static int ThreadDisplayPreparePicture(vout_thread_t *vout, bool reuse,
vout->p->displayed.decoded = picture_Hold(decoded);
vout->p->displayed.timestamp = decoded->date;
picture = filter_chain_VideoFilter(vout->p->filter.chain_static, decoded);
picture = decoded;
}
vlc_mutex_unlock(&vout->p->filter.lock);
......@@ -1422,6 +1539,8 @@ static void vout_FlushUnlocked(vout_thread_t *vout, bool below,
}
picture_fifo_Flush(sys->decoder_fifo, date, below);
if (sys->filter.static_fifo)
picture_fifo_Flush(sys->filter.static_fifo, date, below);
assert(sys->display != NULL);
vlc_mutex_lock(&sys->display_lock);
......@@ -1561,6 +1680,7 @@ static int vout_Start(vout_thread_t *vout, vlc_video_context *vctx, const vout_c
sys->private_pool = NULL;
sys->filter.configuration = NULL;
sys->filter.static_fifo = NULL;
video_format_Copy(&sys->filter.src_fmt, &sys->original);
sys->filter.src_vctx = vctx ? vlc_video_context_Hold(vctx) : NULL;
......@@ -1755,6 +1875,8 @@ static void vout_ReleaseDisplay(vout_thread_t *vout)
sys->display = NULL;
vlc_mutex_unlock(&sys->display_lock);
static_filter_thread_Stop(vout);
/* Destroy the video filters */
ThreadDelAllFilterCallbacks(vout);
filter_chain_Delete(sys->filter.chain_interactive);
......
......@@ -166,6 +166,9 @@ struct vout_thread_sys_t
struct filter_chain_t *chain_static;
struct filter_chain_t *chain_interactive;
bool has_deint;
vlc_thread_t static_thread;
picture_fifo_t *static_fifo;
} filter;
/* */
......
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