Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions lib/upipe-filters/upipe_filter_format.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
#include <stdarg.h>
#include <string.h>

#define UPIPE_FFMT_DEINTERLACE_FILTER_DEFAULT "yadif"

/** @internal @This enumerates the supported surface types. */
enum upipe_ffmt_surface_type {
SW,
Expand All @@ -60,6 +62,8 @@ struct upipe_ffmt_format {
struct uref *flow_def;
/** surface type */
enum upipe_ffmt_surface_type surface_type;
/** frame rate */
struct urational fps;
/** horizontal size */
uint64_t hsize;
/** vertical size */
Expand Down Expand Up @@ -247,6 +251,8 @@ struct upipe_ffmt {
char *tonemap_param;
/** tonemap desat option */
char *tonemap_desat;
/** deinterlace filter option */
char *deinterlace_filter;

/** avfilter hw config type */
char *hw_type;
Expand Down Expand Up @@ -316,6 +322,7 @@ static struct upipe *upipe_ffmt_alloc(struct upipe_mgr *mgr,
upipe_ffmt->tonemap_tonemap = NULL;
upipe_ffmt->tonemap_param = NULL;
upipe_ffmt->tonemap_desat = NULL;
upipe_ffmt->deinterlace_filter = NULL;
upipe_ffmt->hw_type = NULL;
upipe_ffmt->hw_device = NULL;
upipe_throw_ready(upipe);
Expand Down Expand Up @@ -473,6 +480,8 @@ static int upipe_ffmt_format_set(struct upipe *upipe,
else
format->surface_type = SW;
format->hw = format->surface_type != SW;
format->fps.num = format->fps.den = 0;
uref_pic_flow_get_fps(flow_def, &format->fps);
format->hsize = 0;
uref_pic_flow_get_hsize(flow_def, &format->hsize);
format->vsize = 0;
Expand Down Expand Up @@ -629,6 +638,8 @@ static int upipe_ffmt_build(struct upipe *upipe, struct uref *flow_def,
UBASE_RETURN(uref_flow_get_def(flow_def, &def))

if (!ubase_ncmp(def, "pic.")) {
const char *deinterlace_filter = upipe_ffmt->deinterlace_filter;

/* check aspect ratio */
struct urational sar, dar;
if (ubase_check(uref_pic_flow_get_sar(flow_def_wanted, &sar)) &&
Expand Down Expand Up @@ -690,6 +701,15 @@ static int upipe_ffmt_build(struct upipe *upipe, struct uref *flow_def,
}
}

if (deinterlace_filter && config.need_deint) {
if (ffmt_mgr->avfilter_mgr)
use_avfilter = true;
else {
upipe_warn(upipe, "deinterlace filter requires avfilter");
return UBASE_ERR_UNHANDLED;
}
}

if (config.need_tonemap) {
if (ffmt_mgr->avfilter_mgr)
use_avfilter = true;
Expand Down Expand Up @@ -781,6 +801,15 @@ static int upipe_ffmt_build(struct upipe *upipe, struct uref *flow_def,
bool need_range = config.need_range;
bool need_tonemap = config.need_tonemap;

const char *deint_mode = "send_frame";
struct urational fps = config.in.fps;
fps.num *= 2;
if (fps.den && urational_cmp(&fps, &config.out.fps) == 0)
deint_mode = "send_field";

if (!deinterlace_filter)
deinterlace_filter = UPIPE_FFMT_DEINTERLACE_FILTER_DEFAULT;

char filters[512];
int pos = 0;
int opt;
Expand All @@ -802,8 +831,9 @@ static int upipe_ffmt_build(struct upipe *upipe, struct uref *flow_def,
add_filter("format");
add_option("%s", pix_fmt_planar_in);
}
add_filter("yadif");
add_filter(deinterlace_filter);
add_option("deint=interlaced");
add_option("mode=%s", deint_mode);
need_format =
strcmp(pix_fmt_planar_in, out->pix_fmt) != 0;
}
Expand Down Expand Up @@ -943,8 +973,9 @@ static int upipe_ffmt_build(struct upipe *upipe, struct uref *flow_def,
add_option("out_transfer=%s", color_transfer);
}
if (need_deint) {
add_filter("yadif");
add_filter(deinterlace_filter);
add_option("deint=interlaced");
add_option("mode=%s", deint_mode);
}
}
if (in->hw && !out->hw) {
Expand Down Expand Up @@ -1163,6 +1194,7 @@ static int upipe_ffmt_set_option(struct upipe *upipe,
SET_OPTION("tonemap/tonemap", tonemap_tonemap)
SET_OPTION("tonemap/param", tonemap_param)
SET_OPTION("tonemap/desat", tonemap_desat)
SET_OPTION("deinterlace-filter", deinterlace_filter)

if (!strcmp(option, "deinterlace-preset")) {
if (!strcmp(value, "fast")) {
Expand Down Expand Up @@ -1399,6 +1431,7 @@ static void upipe_ffmt_free(struct upipe *upipe)
free(upipe_ffmt->tonemap_tonemap);
free(upipe_ffmt->tonemap_param);
free(upipe_ffmt->tonemap_desat);
free(upipe_ffmt->deinterlace_filter);
free(upipe_ffmt->hw_type);
free(upipe_ffmt->hw_device);
upipe_ffmt_config_clean(&upipe_ffmt->config);
Expand Down
Loading