diff mbox series

[FFmpeg-devel,11/18] avradio/vissualize: rotate waterfall

Message ID 20230708212530.109692-11-michael@niedermayer.cc
State New
Headers show
Series [FFmpeg-devel,01/18] avradio/sdrdemux: Fix uninitialized access | expand

Checks

Context Check Description
yinshiyou/configure_loongarch64 warning Failed to apply patch
andriy/configure_x86 warning Failed to apply patch

Commit Message

Michael Niedermayer July 8, 2023, 9:25 p.m. UTC
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavradio/sdr.h        |  1 +
 libavradio/vissualize.c | 35 ++++++++++++++++++++++++++++++-----
 2 files changed, 31 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/libavradio/sdr.h b/libavradio/sdr.h
index 2940ffa389..8a2ab1c78a 100644
--- a/libavradio/sdr.h
+++ b/libavradio/sdr.h
@@ -116,6 +116,7 @@  typedef struct SDRStream {
     int frame_size;
     int frame_buffer_line;
     uint8_t *frame_buffer;
+    int64_t last_block_center_freq;
 } SDRStream;
 
 typedef struct SDRContext {
diff --git a/libavradio/vissualize.c b/libavradio/vissualize.c
index c165e0fb63..b27f78f171 100644
--- a/libavradio/vissualize.c
+++ b/libavradio/vissualize.c
@@ -90,6 +90,14 @@  static void draw_string(uint8_t *frame_buffer, ptrdiff_t stride, char *str, int
     }
 }
 
+static void advance_waterfall(SDRStream *sst, int h) {
+    if (!sst->frame_buffer_line) {
+        memcpy(sst->frame_buffer + sst->frame_size, sst->frame_buffer, sst->frame_size);
+        sst->frame_buffer_line = h-1;
+    } else
+        sst->frame_buffer_line--;
+}
+
 int ff_sdr_vissualization(SDRContext *sdr, AVStream *st, AVPacket *pkt)
 {
     SDRStream *sst = st->priv_data;
@@ -101,6 +109,27 @@  int ff_sdr_vissualization(SDRContext *sdr, AVStream *st, AVPacket *pkt)
     int skip = frame_index == last_index || sdr->missing_streams;
     av_assert0(sdr->missing_streams >= 0);
 
+    if (sdr->block_center_freq) {
+        if (sst->last_block_center_freq) {
+            int last_center = lrint((F2INDEX(sst->last_block_center_freq) - sdr->block_size) * w / (2*sdr->block_size));
+
+            last_center %= w;
+            if (last_center < 0)
+                last_center += w;
+            av_assert0(last_center >= 0 && last_center < w);
+
+            for(int y= 0; y<h - 1; y++) {
+                uint8_t *dst = sst->frame_buffer + 4*w*(sst->frame_buffer_line + y);
+                uint8_t *src = dst + 4*w;
+
+                memcpy(dst + 4*last_center, src,                       4*(w - last_center));
+                memcpy(dst                , src + 4*(w - last_center), 4*     last_center );
+            }
+            advance_waterfall(sst, h);
+        }
+        sst->last_block_center_freq = sdr->block_center_freq;
+    }
+
     for(int x= 0; x<w; x++) {
         int color;
         int idx = 4*(x + sst->frame_buffer_line*w);
@@ -188,11 +217,7 @@  int ff_sdr_vissualization(SDRContext *sdr, AVStream *st, AVPacket *pkt)
         }
     }
 
-    if (!sst->frame_buffer_line) {
-        memcpy(sst->frame_buffer + sst->frame_size, sst->frame_buffer, sst->frame_size);
-        sst->frame_buffer_line = h-1;
-    } else
-        sst->frame_buffer_line--;
+    advance_waterfall(sst, h);
 
 //TODO
 //                 draw RDS*