Unified · Split
| @@ -134,7 +134,7 @@ typedef struct DebugMatches { · 133 unmodified lines | |||
| 134 | // for each frame | 134 | // for each frame |
| 135 | typedef struct AbsoluteFrameMotion { | 135 | typedef struct AbsoluteFrameMotion { |
| 136 | // Array with the various ringbuffers, indexed via the RingbufferIndices enum | 136 | // Array with the various ringbuffers, indexed via the RingbufferIndices enum |
| 137 | AVFifoBuffer *ringbuffers[RingbufCount]; | 137 | AVFifo *ringbuffers[RingbufCount]; |
| 138 | 138 | ||
| 139 | // Offset to get to the current frame being processed | 139 | // Offset to get to the current frame being processed |
| 140 | // (not in bytes) | 140 | // (not in bytes) |
| @@ -144,7 +144,7 @@ typedef struct AbsoluteFrameMotion { · 3 unmodified lines | |||
| 144 | int data_start_offset; | 144 | int data_start_offset; |
| 145 | int data_end_offset; | 145 | int data_end_offset; |
| 146 | 146 | ||
| 147 | AVFifoBuffer *debug_matches; | 147 | AVFifo *debug_matches; |
| 148 | } AbsoluteFrameMotion; | 148 | } AbsoluteFrameMotion; |
| 149 | 149 | ||
| 150 | // Takes care of freeing the arrays within the DebugMatches inside of the | 150 | // 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 | |||
| 156 | return; | 156 | return; |
| 157 | } | 157 | } |
| 158 | 158 | ||
| 159 | while (av_fifo_size(afm->debug_matches) > 0) { | 159 | while (av_fifo_read(afm->debug_matches, &dm, 1) >= 0) |
| 160 | av_fifo_generic_read( | ||
| 161 | afm->debug_matches, | ||
| 162 | &dm, | ||
| 163 | sizeof(DebugMatches), | ||
| 164 | NULL | ||
| 165 | ); | ||
| 166 | |||
| 167 | av_freep(&dm.matches); | 160 | av_freep(&dm.matches); |
| 168 | } | ||
| 169 | 161 | ||
| 170 | av_fifo_freep(&afm->debug_matches); | 162 | av_fifo_freep2(&afm->debug_matches); |
| 171 | } | 163 | } |
| 172 | 164 | ||
| 173 | // Stores the translation, scale, rotation, and skew deltas between two frames | 165 | // 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 | |||
| 853 | // clipping the offset into the appropriate range | 845 | // clipping the offset into the appropriate range |
| 854 | static void ringbuf_float_at( | 846 | static void ringbuf_float_at( |
| 855 | DeshakeOpenCLContext *deshake_ctx, | 847 | DeshakeOpenCLContext *deshake_ctx, |
| 856 | AVFifoBuffer *values, | 848 | AVFifo *values, |
| 857 | float *val, | 849 | float *val, |
| 858 | int offset | 850 | int offset |
| 859 | ) { | 851 | ) { |
| @@ -863,7 +855,7 @@ static void ringbuf_float_at( · 3 unmodified lines | |||
| 863 | } else { | 855 | } else { |
| 864 | // This expression represents the last valid index in the buffer, | 856 | // This expression represents the last valid index in the buffer, |
| 865 | // which we use repeatedly at the end of the video. | 857 | // 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; |
| 867 | } | 859 | } |
| 868 | 860 | ||
| 869 | if (deshake_ctx->abs_motion.data_start_offset != -1) { | 861 | if (deshake_ctx->abs_motion.data_start_offset != -1) { |
| @@ -881,13 +873,7 @@ static void ringbuf_float_at( · 11 unmodified lines | |||
| 881 | clip_end | 873 | clip_end |
| 882 | ); | 874 | ); |
| 883 | 875 | ||
| 884 | av_fifo_generic_peek_at( | 876 | av_fifo_peek(values, val, 1, offset_clipped); |
| 885 | values, | ||
| 886 | val, | ||
| 887 | offset_clipped * sizeof(float), | ||
| 888 | sizeof(float), | ||
| 889 | NULL | ||
| 890 | ); | ||
| 891 | } | 877 | } |
| 892 | 878 | ||
| 893 | // Returns smoothed current frame value of the given buffer of floats based on the | 879 | // Returns smoothed current frame value of the given buffer of floats based on the |
| @@ -905,7 +891,7 @@ static float smooth( · 11 unmodified lines | |||
| 905 | float *gauss_kernel, | 891 | float *gauss_kernel, |
| 906 | int length, | 892 | int length, |
| 907 | float max_val, | 893 | float max_val, |
| 908 | AVFifoBuffer *values | 894 | AVFifo *values |
| 909 | ) { | 895 | ) { |
| 910 | float new_large_s = 0, new_small_s = 0, new_best = 0, old, diff_between, | 896 | float new_large_s = 0, new_small_s = 0, new_best = 0, old, diff_between, |
| 911 | percent_of_max, inverted_percent; | 897 | percent_of_max, inverted_percent; |
| @@ -1069,7 +1055,7 @@ static av_cold void deshake_opencl_uninit(AVFilterContext *avctx) · 157 unmodified lines | |||
| 1069 | cl_int cle; | 1055 | cl_int cle; |
| 1070 | 1056 | ||
| 1071 | for (int i = 0; i < RingbufCount; i++) | 1057 | 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]); |
| 1073 | 1059 | ||
| 1074 | if (ctx->debug_on) | 1060 | if (ctx->debug_on) |
| 1075 | free_debug_matches(&ctx->abs_motion); | 1061 | free_debug_matches(&ctx->abs_motion); |
| @@ -1188,10 +1174,8 @@ static int deshake_opencl_init(AVFilterContext *avctx) · 112 unmodified lines | |||
| 1188 | } | 1174 | } |
| 1189 | 1175 | ||
| 1190 | for (int i = 0; i < RingbufCount; i++) { | 1176 | for (int i = 0; i < RingbufCount; i++) { |
| 1191 | ctx->abs_motion.ringbuffers[i] = av_fifo_alloc_array( | 1177 | ctx->abs_motion.ringbuffers[i] = av_fifo_alloc2(ctx->smooth_window, |
| 1192 | ctx->smooth_window, | 1178 | sizeof(float), 0); |
| 1193 | sizeof(float) | ||
| 1194 | ); | ||
| 1195 | 1179 | ||
| 1196 | if (!ctx->abs_motion.ringbuffers[i]) { | 1180 | if (!ctx->abs_motion.ringbuffers[i]) { |
| 1197 | err = AVERROR(ENOMEM); | 1181 | err = AVERROR(ENOMEM); |
| @@ -1200,9 +1184,9 @@ static int deshake_opencl_init(AVFilterContext *avctx) · 2 unmodified lines | |||
| 1200 | } | 1184 | } |
| 1201 | 1185 | ||
| 1202 | if (ctx->debug_on) { | 1186 | if (ctx->debug_on) { |
| 1203 | ctx->abs_motion.debug_matches = av_fifo_alloc_array( | 1187 | ctx->abs_motion.debug_matches = av_fifo_alloc2( |
| 1204 | ctx->smooth_window / 2, | 1188 | ctx->smooth_window / 2, |
| 1205 | sizeof(DebugMatches) | 1189 | sizeof(DebugMatches), 0 |
| 1206 | ); | 1190 | ); |
| 1207 | 1191 | ||
| 1208 | if (!ctx->abs_motion.debug_matches) { | 1192 | if (!ctx->abs_motion.debug_matches) { |
| @@ -1424,12 +1408,9 @@ static int filter_frame(AVFilterLink *link, AVFrame *input_frame) · 215 unmodified lines | |||
| 1424 | const float luma_h_over_chroma_h = ((float)input_frame->height / (float)chroma_height); | 1408 | const float luma_h_over_chroma_h = ((float)input_frame->height / (float)chroma_height); |
| 1425 | 1409 | ||
| 1426 | if (deshake_ctx->debug_on) { | 1410 | if (deshake_ctx->debug_on) { |
| 1427 | av_fifo_generic_read( | 1411 | av_fifo_read( |
| 1428 | deshake_ctx->abs_motion.debug_matches, | 1412 | deshake_ctx->abs_motion.debug_matches, |
| 1429 | &debug_matches, | 1413 | &debug_matches, 1); |
| 1430 | sizeof(DebugMatches), | ||
| 1431 | NULL | ||
| 1432 | ); | ||
| 1433 | } | 1414 | } |
| 1434 | 1415 | ||
| 1435 | if (input_frame->pkt_duration) { | 1416 | if (input_frame->pkt_duration) { |
| @@ -1441,13 +1422,9 @@ static int filter_frame(AVFilterLink *link, AVFrame *input_frame) · 5 unmodified lines | |||
| 1441 | 1422 | ||
| 1442 | // Get the absolute transform data for this frame | 1423 | // Get the absolute transform data for this frame |
| 1443 | for (int i = 0; i < RingbufCount; i++) { | 1424 | for (int i = 0; i < RingbufCount; i++) { |
| 1444 | av_fifo_generic_peek_at( | 1425 | av_fifo_peek(deshake_ctx->abs_motion.ringbuffers[i], |
| 1445 | deshake_ctx->abs_motion.ringbuffers[i], | 1426 | &old_vals[i], 1, |
| 1446 | &old_vals[i], | 1427 | deshake_ctx->abs_motion.curr_frame_offset); |
| 1447 | deshake_ctx->abs_motion.curr_frame_offset * sizeof(float), | ||
| 1448 | sizeof(float), | ||
| 1449 | NULL | ||
| 1450 | ); | ||
| 1451 | } | 1428 | } |
| 1452 | 1429 | ||
| 1453 | if (deshake_ctx->tripod_mode) { | 1430 | if (deshake_ctx->tripod_mode) { |
| @@ -1842,7 +1819,7 @@ static int queue_frame(AVFilterLink *link, AVFrame *input_frame) · 388 unmodified lines | |||
| 1842 | { sizeof(cl_mem), &deshake_ctx->brief_pattern} | 1819 | { sizeof(cl_mem), &deshake_ctx->brief_pattern} |
| 1843 | ); | 1820 | ); |
| 1844 | 1821 | ||
| 1845 | if (av_fifo_size(deshake_ctx->abs_motion.ringbuffers[RingbufX]) == 0) { | 1822 | if (!av_fifo_can_read(deshake_ctx->abs_motion.ringbuffers[RingbufX])) { |
| 1846 | // This is the first frame we've been given to queue, meaning there is | 1823 | // This is the first frame we've been given to queue, meaning there is |
| 1847 | // no previous frame to match descriptors to | 1824 | // no previous frame to match descriptors to |
| 1848 | 1825 | ||
| @@ -1892,7 +1869,7 @@ static int queue_frame(AVFilterLink *link, AVFrame *input_frame) · 43 unmodified lines | |||
| 1892 | // old data (and just treat them all as part of the new values) | 1869 | // old data (and just treat them all as part of the new values) |
| 1893 | if (deshake_ctx->abs_motion.data_end_offset == -1) { | 1870 | if (deshake_ctx->abs_motion.data_end_offset == -1) { |
| 1894 | deshake_ctx->abs_motion.data_end_offset = | 1871 | 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; |
| 1896 | } | 1873 | } |
| 1897 | 1874 | ||
| 1898 | goto no_motion_data; | 1875 | goto no_motion_data; |
| @@ -1934,13 +1911,10 @@ static int queue_frame(AVFilterLink *link, AVFrame *input_frame) · 35 unmodified lines | |||
| 1934 | 1911 | ||
| 1935 | // Get the absolute transform data for the previous frame | 1912 | // Get the absolute transform data for the previous frame |
| 1936 | for (int i = 0; i < RingbufCount; i++) { | 1913 | for (int i = 0; i < RingbufCount; i++) { |
| 1937 | av_fifo_generic_peek_at( | 1914 | av_fifo_peek( |
| 1938 | deshake_ctx->abs_motion.ringbuffers[i], | 1915 | deshake_ctx->abs_motion.ringbuffers[i], |
| 1939 | &prev_vals[i], | 1916 | &prev_vals[i], 1, |
| 1940 | av_fifo_size(deshake_ctx->abs_motion.ringbuffers[i]) - sizeof(float), | 1917 | av_fifo_can_read(deshake_ctx->abs_motion.ringbuffers[i]) - 1); |
| 1941 | sizeof(float), | ||
| 1942 | NULL | ||
| 1943 | ); | ||
| 1944 | } | 1918 | } |
| 1945 | 1919 | ||
| 1946 | new_vals[RingbufX] = prev_vals[RingbufX] + relative.translation.s[0]; | 1920 | new_vals[RingbufX] = prev_vals[RingbufX] + relative.translation.s[0]; |
| @@ -2011,21 +1985,13 @@ end: · 64 unmodified lines | |||
| 2011 | } | 1985 | } |
| 2012 | debug_matches.num_matches = num_vectors; | 1986 | debug_matches.num_matches = num_vectors; |
| 2013 | 1987 | ||
| 2014 | av_fifo_generic_write( | 1988 | av_fifo_write( |
| 2015 | deshake_ctx->abs_motion.debug_matches, | 1989 | deshake_ctx->abs_motion.debug_matches, |
| 2016 | &debug_matches, | 1990 | &debug_matches, 1); |
| 2017 | sizeof(DebugMatches), | ||
| 2018 | NULL | ||
| 2019 | ); | ||
| 2020 | } | 1991 | } |
| 2021 | 1992 | ||
| 2022 | for (int i = 0; i < RingbufCount; i++) { | 1993 | for (int i = 0; i < RingbufCount; i++) { |
| 2023 | av_fifo_generic_write( | 1994 | av_fifo_write(deshake_ctx->abs_motion.ringbuffers[i], &new_vals[i], 1); |
| 2024 | deshake_ctx->abs_motion.ringbuffers[i], | ||
| 2025 | &new_vals[i], | ||
| 2026 | sizeof(float), | ||
| 2027 | NULL | ||
| 2028 | ); | ||
| 2029 | } | 1995 | } |
| 2030 | 1996 | ||
| 2031 | return ff_framequeue_add(&deshake_ctx->fq, input_frame); | 1997 | return ff_framequeue_add(&deshake_ctx->fq, input_frame); |
| @@ -2063,9 +2029,9 @@ static int activate(AVFilterContext *ctx) · 31 unmodified lines | |||
| 2063 | 2029 | ||
| 2064 | // If there is no more space in the ringbuffers, remove the oldest | 2030 | // If there is no more space in the ringbuffers, remove the oldest |
| 2065 | // values to make room for the new ones | 2031 | // 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])) { |
| 2067 | for (int i = 0; i < RingbufCount; i++) { | 2033 | 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); |
| 2069 | } | 2035 | } |
| 2070 | } | 2036 | } |
| 2071 | ret = queue_frame(inlink, frame); | 2037 | ret = queue_frame(inlink, frame); |
| @@ -2092,7 +2058,7 @@ static int activate(AVFilterContext *ctx) · 20 unmodified lines | |||
| 2092 | // Finish processing the rest of the frames in the queue. | 2058 | // Finish processing the rest of the frames in the queue. |
| 2093 | while(ff_framequeue_queued_frames(&deshake_ctx->fq) != 0) { | 2059 | while(ff_framequeue_queued_frames(&deshake_ctx->fq) != 0) { |
| 2094 | for (int i = 0; i < RingbufCount; i++) { | 2060 | 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); |
| 2096 | } | 2062 | } |
| 2097 | 2063 | ||
| 2098 | ret = filter_frame(inlink, ff_framequeue_take(&deshake_ctx->fq)); | 2064 | ret = filter_frame(inlink, ff_framequeue_take(&deshake_ctx->fq)); |