[FFmpeg-devel] [PATCH 07/14] avradio/rds: Implement RadioText Plus

Michael Niedermayer michael at niedermayer.cc
Thu Jul 13 02:36:59 EEST 2023


Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
---
 libavradio/rds.c        | 44 ++++++++++++++++++++++++++++++++++++++++-
 libavradio/sdr.h        |  7 +++++++
 libavradio/vissualize.c |  5 +++++
 3 files changed, 55 insertions(+), 1 deletion(-)

diff --git a/libavradio/rds.c b/libavradio/rds.c
index e121c9db8e..30e4209ae8 100644
--- a/libavradio/rds.c
+++ b/libavradio/rds.c
@@ -143,6 +143,17 @@ static int decode_rds_group(SDRContext *sdr, Station *station, uint16_t group[4]
             AV_WB16(station->radiotext + 4*(group[1]&15) + 2, group[3]);
         }
     break;}
+    case 3:
+        if (!b) {
+            int application_id = group[3];
+            switch (application_id) {
+            case 0x4BD7:
+                //RadioText Plus / RT+ for group 2A RT - IEC 62106-6:2023
+                station->rtp_appgroup = group[1] & 31;
+                break;
+            }
+        }
+    break;
     case 10:
         if (b==0) {
             AV_WB16(station->programm_type_name + 4*(group[1]&1)    , group[2]);
@@ -152,7 +163,38 @@ static int decode_rds_group(SDRContext *sdr, Station *station, uint16_t group[4]
 //     case 14:
 //     break;
     default:
-        av_log(sdr->avfmt, AV_LOG_DEBUG, "RDS: PI %X, A %X B %X PTY %X\n", pi,a,b,pty);
+        if (2*a + b == station->rtp_appgroup) {
+            int toggle_bit  = group[1]&16;
+            int running_bit = group[1]&8;
+            uint64_t v = ((group[1]&7LL)<<32) + ((uint64_t)group[2]<<16) + group[3];
+            int tag[2][3];
+            if (toggle_bit != station->rtp_toggle_bit) {
+                station->artist[0] =
+                station->title[0] =
+                station->album[0] = 0;
+            }
+            station->rtp_toggle_bit = toggle_bit;
+            for(int i = 0; i<6; i++) {
+                tag[i/3][i%3] = (v>>29) & 63;
+                v <<= 6;
+            }
+            tag[1][2] >>= 1;
+            av_log(0,0, "\n");
+            for(int i = 0; i<2; i++) {
+                char *target= NULL;
+                switch(tag[i][0]) {
+                case 1: target = station->title; break;
+                case 2: target = station->album; break;
+                case 4: target = station->artist; break;
+                default:
+                    av_log(sdr->avfmt, AV_LOG_DEBUG, "Unhandled RT+ code %d\n", tag[i][0]);
+                }
+                if (target) {
+                    memcpy(target, station->radiotext + tag[i][1], 1 + tag[i][2]);
+                    target[1+tag[i][2]] = 0;
+                }
+            }
+        }
     }
 
     return 0;
diff --git a/libavradio/sdr.h b/libavradio/sdr.h
index 4b3e14da02..ac6b7dffe0 100644
--- a/libavradio/sdr.h
+++ b/libavradio/sdr.h
@@ -72,10 +72,17 @@ typedef enum Modulation {
 
 typedef struct Station {
     char name[9];
+
     char radiotext[65];
+    char artist[65];
+    char title[65];
+    char album[65];
     char programm_type_name[9];
     int program_id[2];
     uint8_t rt_ab_flag;
+    uint8_t rtp_toggle_bit;
+    uint8_t rtp_running_bit;
+    uint16_t rtp_appgroup;
 
     enum Modulation modulation;
     double frequency;
diff --git a/libavradio/vissualize.c b/libavradio/vissualize.c
index d87ca167de..a3dcf5801b 100644
--- a/libavradio/vissualize.c
+++ b/libavradio/vissualize.c
@@ -221,6 +221,11 @@ int ff_sdr_vissualization(SDRContext *sdr, AVStream *st, AVPacket *pkt)
             if (s->radiotext[0]) {
                 draw_string(pkt->data, 4*w, s->radiotext, xmid + 8*yd, 320*h2 + 24*yd, xd, yd, color, color, color, w, h);
             }
+            if (s->title[0] || s->artist[0]) {
+                int len = strlen(s->title) + 1;
+                draw_string(pkt->data, 4*w, s->title , xmid + 8*yd, 320*h2 + 2*24*yd, xd, yd, color, color*1.5, color, w, h);
+                draw_string(pkt->data, 4*w, s->artist, xmid + 8*yd + 9*xd*len, 320*h2 + 2*24*yd + 9*yd*len, xd, yd, color, color*2, color, w, h);
+            }
         }
     }
 
-- 
2.31.1



More information about the ffmpeg-devel mailing list