Skip to content

Commit afc2d5b

Browse files
quariumcmassiot
authored andcommitted
upipe_avfilter: support hardware context with complex filters
1 parent 0375b67 commit afc2d5b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

lib/upipe-av/upipe_avfilter.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ struct upipe_avfilt_sub {
103103
const char *name;
104104
/** avfilter buffer source */
105105
AVFilterContext *buffer_ctx;
106+
/** reference to hardware frames context for input filters */
107+
AVBufferRef *hw_frames_ctx;
106108
/** system clock offset */
107109
uint64_t pts_sys_offset;
108110
/** prog clock offset */
@@ -724,6 +726,9 @@ static int build_input_filter(struct upipe *upipe, struct uref *flow_def,
724726
}
725727
p->time_base.num = 1;
726728
p->time_base.den = UCLOCK_FREQ;
729+
if (upipe_avfilt_sub)
730+
p->hw_frames_ctx = upipe_avfilt_sub->hw_frames_ctx;
731+
727732
switch (type) {
728733
case AVMEDIA_TYPE_VIDEO: {
729734
const char *chroma_map[UPIPE_AV_MAX_PLANES];
@@ -852,6 +857,7 @@ static struct upipe *upipe_avfilt_sub_alloc(struct upipe_mgr *mgr,
852857
upipe_avfilt_sub->last_pts_prog = UINT64_MAX;
853858
upipe_avfilt_sub->last_duration = 0;
854859
upipe_avfilt_sub->buffer_ctx = NULL;
860+
upipe_avfilt_sub->hw_frames_ctx = NULL;
855861
upipe_avfilt_sub->warn_not_configured = true;
856862
upipe_avfilt_sub->latency = 0;
857863
ulist_init(&upipe_avfilt_sub->urefs);
@@ -886,6 +892,7 @@ static void upipe_avfilt_sub_free(struct upipe *upipe)
886892

887893
upipe_throw_dead(upipe);
888894

895+
av_buffer_unref(&upipe_avfilt_sub->hw_frames_ctx);
889896
uref_free(upipe_avfilt_sub->flow_def_alloc);
890897
ubuf_mgr_release(upipe_avfilt_sub->ubuf_mgr);
891898
upipe_avfilt_sub_clean_upump(upipe);
@@ -1107,6 +1114,17 @@ static void upipe_avfilt_sub_input(struct upipe *upipe,
11071114
}
11081115

11091116
if (unlikely(!upipe_avfilt->configured)) {
1117+
AVFrame *frame = av_frame_alloc();
1118+
assert(frame);
1119+
if (ubase_check(ubuf_av_get_avframe(uref->ubuf, frame))) {
1120+
if (frame->hw_frames_ctx != NULL) {
1121+
av_buffer_unref(&upipe_avfilt_sub->hw_frames_ctx);
1122+
upipe_avfilt_sub->hw_frames_ctx = av_buffer_ref(frame->hw_frames_ctx);
1123+
}
1124+
}
1125+
av_frame_free(&frame);
1126+
upipe_avfilt_reset(upipe_avfilt_to_upipe(upipe_avfilt));
1127+
11101128
if (upipe_avfilt_sub->warn_not_configured)
11111129
upipe_warn(upipe, "filter graph is not configured");
11121130
upipe_avfilt_sub->warn_not_configured = false;

0 commit comments

Comments
 (0)