Commit 78eb0e16 authored by Thomas Guillem's avatar Thomas Guillem

ci_filters: rework CVPX to CVPX conversions

CD 155f0680-aa44-49a8-a2ec-e1a341fc55fe

These 2 extra conversions (CVPX_X to CVPX_RGBA and CVPX_RGBA to CVPX_X) will be
done only if ci_filters doesn't accept the input chroma. This won't happen
often since videotoolbox will most likely output chromas that can be accepted
by ci_filters.

This was not never touched since the initial commit and was not up to date.

(cherry picked from commit 4e803da8)
Signed-off-by: Thomas Guillem's avatarThomas Guillem <thomas@gllm.fr>
parent f41725e3
......@@ -45,40 +45,29 @@ static int Open_CVPX_to_CVPX(vlc_object_t *);
static void Close_CVPX_to_CVPX(vlc_object_t *);
#endif
vlc_module_begin ()
set_description("Conversions from/to CoreVideo buffers")
set_capability("video converter", 10)
set_callbacks(Open, Close)
#if TARGET_OS_IPHONE
vlc_module_end ()
struct filter_sys_t
{
filter_t *p_sw_filter;
CVPixelBufferPoolRef pool;
union
{
filter_t *p_sw_filter;
#if !TARGET_OS_IPHONE
VTPixelTransferSessionRef vttransfer;
#endif
};
};
#else
vlc_module_begin ()
set_description("Conversions from/to CoreVideo buffers")
set_capability("video converter", 10)
set_callbacks(Open, Close)
#if !TARGET_OS_IPHONE
add_submodule()
set_description("Conversions between CoreVideo buffers")
set_callbacks(Open_CVPX_to_CVPX, Close_CVPX_to_CVPX)
#endif
vlc_module_end ()
struct filter_sys_t
{
union
{
struct
{
filter_t *p_sw_filter;
CVPixelBufferPoolRef pool;
};
VTPixelTransferSessionRef vttransfer;
};
};
#endif
/********************************
* CVPX to/from I420 conversion *
......@@ -334,6 +323,8 @@ error:
static picture_t *
Filter(filter_t *filter, picture_t *src)
{
filter_sys_t *p_sys = filter->p_sys;
CVPixelBufferRef src_cvpx = cvpxpic_get_ref(src);
assert(src_cvpx);
......@@ -344,8 +335,13 @@ Filter(filter_t *filter, picture_t *src)
return NULL;
}
CVPixelBufferRef dst_cvpx = cvpxpic_get_ref(dst);
assert(dst_cvpx);
CVPixelBufferRef dst_cvpx = cvpxpool_new_cvpx(p_sys->pool);
if (dst_cvpx == NULL)
{
picture_Release(src);
picture_Release(dst);
return NULL;
}
if (VTPixelTransferSessionTransferImage(filter->p_sys->vttransfer,
src_cvpx, dst_cvpx) != noErr)
......@@ -355,6 +351,8 @@ Filter(filter_t *filter, picture_t *src)
return NULL;
}
cvpxpic_attach(dst, dst_cvpx);
picture_CopyProperties(dst, src);
picture_Release(src);
return dst;
......@@ -383,19 +381,26 @@ Open_CVPX_to_CVPX(vlc_object_t *obj)
CHECK_CHROMA(filter->fmt_out.video.i_chroma)
#undef CHECK_CHROMA
filter->p_sys = calloc(1, sizeof(filter_sys_t));
if (!filter->p_sys)
filter_sys_t *p_sys = filter->p_sys = calloc(1, sizeof(filter_sys_t));
if (!p_sys)
return VLC_ENOMEM;
if (VTPixelTransferSessionCreate(NULL, &filter->p_sys->vttransfer)
if (VTPixelTransferSessionCreate(NULL, &p_sys->vttransfer)
!= noErr)
{
free(filter->p_sys);
free(p_sys);
return VLC_EGENERIC;
}
filter->pf_video_filter = Filter;
if ((p_sys->pool = cvpxpool_create(&filter->fmt_out.video, 3)) == NULL)
{
VTPixelTransferSessionInvalidate(p_sys->vttransfer);
CFRelease(p_sys->vttransfer);
free(p_sys);
return VLC_EGENERIC;
}
filter->pf_video_filter = Filter;
return VLC_SUCCESS;
}
......@@ -403,9 +408,11 @@ static void
Close_CVPX_to_CVPX(vlc_object_t *obj)
{
filter_t *filter = (filter_t *)obj;
filter_sys_t *p_sys = filter->p_sys;
VTPixelTransferSessionInvalidate(filter->p_sys->vttransfer);
CFRelease(filter->p_sys->vttransfer);
VTPixelTransferSessionInvalidate(p_sys->vttransfer);
CFRelease(p_sys->vttransfer);
CVPixelBufferPoolRelease(p_sys->pool);
free(filter->p_sys);
}
......
......@@ -87,6 +87,7 @@ struct ci_filters_ctx
CVPixelBufferPoolRef outconv_cvpx_pool;
CIContext * ci_ctx;
struct filter_chain * fchain;
filter_t * src_converter;
filter_t * dst_converter;
};
......@@ -377,6 +378,13 @@ Filter(filter_t *filter, picture_t *src)
}
CFRelease(cvpx);
if (ctx->src_converter)
{
src = ctx->dst_converter->pf_video_filter(ctx->src_converter, src);
if (!src)
return NULL;
}
@autoreleasepool {
CIImage *ci_img = [CIImage imageWithCVImageBuffer: cvpxpic_get_ref(src)];
if (!ci_img)
......@@ -515,80 +523,59 @@ Open_CreateFilters(filter_t *filter, struct filter_chain **p_last_filter,
return VLC_SUCCESS;
}
static picture_t *
CVPX_buffer_new(filter_t *converter)
{
CVPixelBufferPoolRef pool = converter->owner.sys;
CVPixelBufferRef cvpx = cvpxpool_new_cvpx(pool);
if (!cvpx)
return NULL;
picture_t *pic = picture_NewFromFormat(&converter->fmt_out.video);
if (!pic || cvpxpic_attach(pic, cvpx))
{
CFRelease(cvpx);
return NULL;
}
CFRelease(cvpx);
return pic;
}
static void
Close_RemoveConverters(filter_t *filter, struct ci_filters_ctx *ctx)
{
VLC_UNUSED(filter);
if (ctx->src_converter)
{
module_unneed(ctx->src_converter, ctx->src_converter->p_module);
vlc_object_release(ctx->src_converter);
}
if (ctx->dst_converter)
{
module_unneed(ctx->dst_converter, ctx->dst_converter->p_module);
vlc_object_release(ctx->dst_converter);
CVPixelBufferPoolRelease(ctx->outconv_cvpx_pool);
}
}
static int
Open_AddConverter(filter_t *filter, struct ci_filters_ctx *ctx)
static picture_t *CVPX_to_CVPX_converter_BufferNew(filter_t *p_filter)
{
ctx->cvpx_pool_fmt = filter->fmt_in.video;
ctx->cvpx_pool_fmt.i_chroma = VLC_CODEC_CVPX_BGRA;
ctx->cvpx_pool = cvpxpool_create(&ctx->cvpx_pool_fmt, 3);
if (!ctx->cvpx_pool)
goto error;
ctx->dst_converter = vlc_object_create(filter, sizeof(filter_t));
if (!ctx->dst_converter)
goto error;
return picture_NewFromFormat(&p_filter->fmt_out.video);
}
ctx->dst_converter->fmt_in = filter->fmt_out;
ctx->dst_converter->fmt_out = filter->fmt_out;
ctx->dst_converter->fmt_in.video.i_chroma =
ctx->dst_converter->fmt_in.i_codec = VLC_CODEC_CVPX_BGRA;
static filter_t *
CVPX_to_CVPX_converter_Create(filter_t *filter, bool to_rgba)
{
filter_t *converter = vlc_object_create(filter, sizeof(filter_t));
if (!converter)
return NULL;
ctx->outconv_cvpx_pool =
cvpxpool_create(&filter->fmt_out.video, 2);
if (!ctx->outconv_cvpx_pool)
goto error;
converter->fmt_in = filter->fmt_out;
converter->fmt_out = filter->fmt_out;
ctx->dst_converter->owner.sys = ctx->outconv_cvpx_pool;
ctx->dst_converter->owner.video.buffer_new = CVPX_buffer_new;
if (to_rgba)
{
converter->fmt_out.video.i_chroma =
converter->fmt_out.i_codec = VLC_CODEC_CVPX_BGRA;
}
else
{
converter->fmt_in.video.i_chroma =
converter->fmt_in.i_codec = VLC_CODEC_CVPX_BGRA;
}
ctx->dst_converter->p_module =
module_need(ctx->dst_converter, "video converter", NULL, false);
if (!ctx->dst_converter->p_module)
goto error;
converter->owner.video.buffer_new = CVPX_to_CVPX_converter_BufferNew;
return VLC_SUCCESS;
error:
if (ctx->dst_converter)
converter->p_module = module_need(converter, "video converter", NULL, false);
if (!converter->p_module)
{
if (ctx->dst_converter->p_module)
module_unneed(ctx->dst_converter, ctx->dst_converter->p_module);
vlc_object_release(ctx->dst_converter);
if (ctx->outconv_cvpx_pool)
CVPixelBufferPoolRelease(ctx->outconv_cvpx_pool);
vlc_object_release(converter);
return NULL;
}
return VLC_EGENERIC;
return converter;
}
static int
......@@ -626,10 +613,19 @@ Open(vlc_object_t *obj, char const *psz_filter)
if (!ctx)
goto error;
ctx->cvpx_pool_fmt = filter->fmt_out.video;
if (filter->fmt_in.video.i_chroma != VLC_CODEC_CVPX_NV12
&& filter->fmt_in.video.i_chroma != VLC_CODEC_CVPX_BGRA
&& Open_AddConverter(filter, ctx))
goto error;
&& filter->fmt_in.video.i_chroma != VLC_CODEC_CVPX_BGRA)
{
ctx->src_converter =
CVPX_to_CVPX_converter_Create(filter, true);
ctx->dst_converter = ctx->src_converter ?
CVPX_to_CVPX_converter_Create(filter, false) : NULL;
if (!ctx->src_converter || !ctx->dst_converter)
goto error;
ctx->cvpx_pool_fmt.i_chroma = VLC_CODEC_CVPX_BGRA;
}
#if !TARGET_OS_IPHONE
CGLContextObj glctx = var_InheritAddress(filter, "macosx-glcontext");
......@@ -654,13 +650,9 @@ Open(vlc_object_t *obj, char const *psz_filter)
if (!ctx->ci_ctx)
goto error;
ctx->cvpx_pool = cvpxpool_create(&ctx->cvpx_pool_fmt, 2);
if (!ctx->cvpx_pool)
{
ctx->cvpx_pool_fmt = filter->fmt_out.video;
ctx->cvpx_pool = cvpxpool_create(&ctx->cvpx_pool_fmt, 2);
if (!ctx->cvpx_pool)
goto error;
}
goto error;
if (Open_CreateFilters(filter, &ctx->fchain, filter_types))
goto error;
......
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