History

lavfi/vf_deshake_opencl: switch to new FIFO API

Anton Khirnov committed 4 years ago

Commit c65c2ed1 parent 85c938f1 file · +29 −63Browse files

Unified · Split

libavfilter/vf_deshake_opencl.c+29−63
@@ -134,7 +134,7 @@ typedef struct DebugMatches { · 133 unmodified lines
134134 // for each frame
135135 typedef struct AbsoluteFrameMotion {
136136 // Array with the various ringbuffers, indexed via the RingbufferIndices enum
137− AVFifoBuffer *ringbuffers[RingbufCount];
137+ AVFifo *ringbuffers[RingbufCount];
138138
139139 // Offset to get to the current frame being processed
140140 // (not in bytes)
@@ -144,7 +144,7 @@ typedef struct AbsoluteFrameMotion { · 3 unmodified lines
144144 int data_start_offset;
145145 int data_end_offset;
146146
147− AVFifoBuffer *debug_matches;
147+ AVFifo *debug_matches;
148148 } AbsoluteFrameMotion;
149149
150150 // Takes care of freeing the arrays within the DebugMatches inside of the
@@ -156,18 +156,10 @@ static void free_debug_matches(AbsoluteFrameMotion *afm) { · 5 unmodified lines
156156 return;
157157 }
158158
159− while (av_fifo_size(afm->debug_matches) > 0) {
160− av_fifo_generic_read(
161− afm->debug_matches,
162− &dm,
163− sizeof(DebugMatches),
164− NULL
165− );
166−
159+ while (av_fifo_read(afm->debug_matches, &dm, 1) >= 0)
167160 av_freep(&dm.matches);
168− }
169161
170− av_fifo_freep(&afm->debug_matches);
162+ av_fifo_freep2(&afm->debug_matches);
171163 }
172164
173165 // Stores the translation, scale, rotation, and skew deltas between two frames
@@ -853,7 +845,7 @@ static IterIndices start_end_for(DeshakeOpenCLContext *deshake_ctx, int length) · 679 unmodified lines
853845 // clipping the offset into the appropriate range
854846 static void ringbuf_float_at(
855847 DeshakeOpenCLContext *deshake_ctx,
856− AVFifoBuffer *values,
848+ AVFifo *values,
857849 float *val,
858850 int offset
859851 ) {
@@ -863,7 +855,7 @@ static void ringbuf_float_at( · 3 unmodified lines
863855 } else {
864856 // This expression represents the last valid index in the buffer,
865857 // which we use repeatedly at the end of the video.
866− clip_end = deshake_ctx->smooth_window - (av_fifo_space(values) / sizeof(float)) - 1;
858+ clip_end = deshake_ctx->smooth_window - av_fifo_can_write(values) - 1;
867859 }
868860
869861 if (deshake_ctx->abs_motion.data_start_offset != -1) {
@@ -881,13 +873,7 @@ static void ringbuf_float_at( · 11 unmodified lines
881873 clip_end
882874 );
883875
884− av_fifo_generic_peek_at(
885− values,
886− val,
887− offset_clipped * sizeof(float),
888− sizeof(float),
889− NULL
890− );
876+ av_fifo_peek(values, val, 1, offset_clipped);
891877 }
892878
893879 // Returns smoothed current frame value of the given buffer of floats based on the
@@ -905,7 +891,7 @@ static float smooth( · 11 unmodified lines
905891 float *gauss_kernel,
906892 int length,
907893 float max_val,
908− AVFifoBuffer *values
894+ AVFifo *values
909895 ) {
910896 float new_large_s = 0, new_small_s = 0, new_best = 0, old, diff_between,
911897 percent_of_max, inverted_percent;
@@ -1069,7 +1055,7 @@ static av_cold void deshake_opencl_uninit(AVFilterContext *avctx) · 157 unmodified lines
10691055 cl_int cle;
10701056
10711057 for (int i = 0; i < RingbufCount; i++)
1072− av_fifo_freep(&ctx->abs_motion.ringbuffers[i]);
1058+ av_fifo_freep2(&ctx->abs_motion.ringbuffers[i]);
10731059
10741060 if (ctx->debug_on)
10751061 free_debug_matches(&ctx->abs_motion);
@@ -1188,10 +1174,8 @@ static int deshake_opencl_init(AVFilterContext *avctx) · 112 unmodified lines
11881174 }
11891175
11901176 for (int i = 0; i < RingbufCount; i++) {
1191− ctx->abs_motion.ringbuffers[i] = av_fifo_alloc_array(
1192− ctx->smooth_window,
1193− sizeof(float)
1194− );
1177+ ctx->abs_motion.ringbuffers[i] = av_fifo_alloc2(ctx->smooth_window,
1178+ sizeof(float), 0);
11951179
11961180 if (!ctx->abs_motion.ringbuffers[i]) {
11971181 err = AVERROR(ENOMEM);
@@ -1200,9 +1184,9 @@ static int deshake_opencl_init(AVFilterContext *avctx) · 2 unmodified lines
12001184 }
12011185
12021186 if (ctx->debug_on) {
1203− ctx->abs_motion.debug_matches = av_fifo_alloc_array(
1187+ ctx->abs_motion.debug_matches = av_fifo_alloc2(
12041188 ctx->smooth_window / 2,
1205− sizeof(DebugMatches)
1189+ sizeof(DebugMatches), 0
12061190 );
12071191
12081192 if (!ctx->abs_motion.debug_matches) {
@@ -1424,12 +1408,9 @@ static int filter_frame(AVFilterLink *link, AVFrame *input_frame) · 215 unmodified lines
14241408 const float luma_h_over_chroma_h = ((float)input_frame->height / (float)chroma_height);
14251409
14261410 if (deshake_ctx->debug_on) {
1427− av_fifo_generic_read(
1411+ av_fifo_read(
14281412 deshake_ctx->abs_motion.debug_matches,
1429− &debug_matches,
1430− sizeof(DebugMatches),
1431− NULL
1432− );
1413+ &debug_matches, 1);
14331414 }
14341415
14351416 if (input_frame->pkt_duration) {
@@ -1441,13 +1422,9 @@ static int filter_frame(AVFilterLink *link, AVFrame *input_frame) · 5 unmodified lines
14411422
14421423 // Get the absolute transform data for this frame
14431424 for (int i = 0; i < RingbufCount; i++) {
1444− av_fifo_generic_peek_at(
1445− deshake_ctx->abs_motion.ringbuffers[i],
1446− &old_vals[i],
1447− deshake_ctx->abs_motion.curr_frame_offset * sizeof(float),
1448− sizeof(float),
1449− NULL
1450− );
1425+ av_fifo_peek(deshake_ctx->abs_motion.ringbuffers[i],
1426+ &old_vals[i], 1,
1427+ deshake_ctx->abs_motion.curr_frame_offset);
14511428 }
14521429
14531430 if (deshake_ctx->tripod_mode) {
@@ -1842,7 +1819,7 @@ static int queue_frame(AVFilterLink *link, AVFrame *input_frame) · 388 unmodified lines
18421819 { sizeof(cl_mem), &deshake_ctx->brief_pattern}
18431820 );
18441821
1845− if (av_fifo_size(deshake_ctx->abs_motion.ringbuffers[RingbufX]) == 0) {
1822+ if (!av_fifo_can_read(deshake_ctx->abs_motion.ringbuffers[RingbufX])) {
18461823 // This is the first frame we've been given to queue, meaning there is
18471824 // no previous frame to match descriptors to
18481825
@@ -1892,7 +1869,7 @@ static int queue_frame(AVFilterLink *link, AVFrame *input_frame) · 43 unmodified lines
18921869 // old data (and just treat them all as part of the new values)
18931870 if (deshake_ctx->abs_motion.data_end_offset == -1) {
18941871 deshake_ctx->abs_motion.data_end_offset =
1895− av_fifo_size(deshake_ctx->abs_motion.ringbuffers[RingbufX]) / sizeof(float) - 1;
1872+ av_fifo_can_read(deshake_ctx->abs_motion.ringbuffers[RingbufX]) - 1;
18961873 }
18971874
18981875 goto no_motion_data;
@@ -1934,13 +1911,10 @@ static int queue_frame(AVFilterLink *link, AVFrame *input_frame) · 35 unmodified lines
19341911
19351912 // Get the absolute transform data for the previous frame
19361913 for (int i = 0; i < RingbufCount; i++) {
1937− av_fifo_generic_peek_at(
1914+ av_fifo_peek(
19381915 deshake_ctx->abs_motion.ringbuffers[i],
1939− &prev_vals[i],
1940− av_fifo_size(deshake_ctx->abs_motion.ringbuffers[i]) - sizeof(float),
1941− sizeof(float),
1942− NULL
1943− );
1916+ &prev_vals[i], 1,
1917+ av_fifo_can_read(deshake_ctx->abs_motion.ringbuffers[i]) - 1);
19441918 }
19451919
19461920 new_vals[RingbufX] = prev_vals[RingbufX] + relative.translation.s[0];
@@ -2011,21 +1985,13 @@ end: · 64 unmodified lines
20111985 }
20121986 debug_matches.num_matches = num_vectors;
20131987
2014− av_fifo_generic_write(
1988+ av_fifo_write(
20151989 deshake_ctx->abs_motion.debug_matches,
2016− &debug_matches,
2017− sizeof(DebugMatches),
2018− NULL
2019− );
1990+ &debug_matches, 1);
20201991 }
20211992
20221993 for (int i = 0; i < RingbufCount; i++) {
2023− av_fifo_generic_write(
2024− deshake_ctx->abs_motion.ringbuffers[i],
2025− &new_vals[i],
2026− sizeof(float),
2027− NULL
2028− );
1994+ av_fifo_write(deshake_ctx->abs_motion.ringbuffers[i], &new_vals[i], 1);
20291995 }
20301996
20311997 return ff_framequeue_add(&deshake_ctx->fq, input_frame);
@@ -2063,9 +2029,9 @@ static int activate(AVFilterContext *ctx) · 31 unmodified lines
20632029
20642030 // If there is no more space in the ringbuffers, remove the oldest
20652031 // values to make room for the new ones
2066− if (av_fifo_space(deshake_ctx->abs_motion.ringbuffers[RingbufX]) == 0) {
2032+ if (!av_fifo_can_write(deshake_ctx->abs_motion.ringbuffers[RingbufX])) {
20672033 for (int i = 0; i < RingbufCount; i++) {
2068− av_fifo_drain(deshake_ctx->abs_motion.ringbuffers[i], sizeof(float));
2034+ av_fifo_drain2(deshake_ctx->abs_motion.ringbuffers[i], 1);
20692035 }
20702036 }
20712037 ret = queue_frame(inlink, frame);
@@ -2092,7 +2058,7 @@ static int activate(AVFilterContext *ctx) · 20 unmodified lines
20922058 // Finish processing the rest of the frames in the queue.
20932059 while(ff_framequeue_queued_frames(&deshake_ctx->fq) != 0) {
20942060 for (int i = 0; i < RingbufCount; i++) {
2095− av_fifo_drain(deshake_ctx->abs_motion.ringbuffers[i], sizeof(float));
2061+ av_fifo_drain2(deshake_ctx->abs_motion.ringbuffers[i], 1);
20962062 }
20972063
20982064 ret = filter_frame(inlink, ff_framequeue_take(&deshake_ctx->fq));

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t