Skip to content

Commit 94bc62b

Browse files
committed
Only report ID3 when the content changes
1 parent 292e1dc commit 94bc62b

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/output.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ void output_reset(output_t *st)
207207

208208
for (int i = 0; i < MAX_PROGRAMS; i++)
209209
{
210+
st->last_psd[i] = NULL;
211+
st->last_psd_len[i] = 0;
210212
for (int j = 0; j < MAX_STREAMS; j++)
211213
{
212214
for (int k = 0; k < ELASTIC_BUFFER_LEN; k++)
@@ -287,6 +289,18 @@ static void output_id3(output_t *st, unsigned int program, uint8_t *buf, unsigne
287289
evt.event = NRSC5_EVENT_ID3;
288290
evt.id3.comments = NULL;
289291

292+
if ((len == st->last_psd_len[program]) && (memcmp(buf, st->last_psd[program], len) == 0))
293+
{
294+
return;
295+
}
296+
else
297+
{
298+
free(st->last_psd[program]);
299+
st->last_psd_len[program] = len;
300+
st->last_psd[program] = malloc(len);
301+
memcpy(st->last_psd[program], buf, len);
302+
}
303+
290304
if (len < 10 || memcmp(buf, "ID3\x03\x00", 5) || buf[5]) return;
291305
id3_len = id3_length(buf + 6) + 10;
292306
if (id3_len > len) return;

src/output.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ typedef struct
120120
{
121121
nrsc5_t *radio;
122122
elastic_buffer_t elastic[MAX_PROGRAMS][MAX_STREAMS];
123+
uint8_t *last_psd[MAX_PROGRAMS];
124+
unsigned int last_psd_len[MAX_PROGRAMS];
123125
#ifdef HAVE_FAAD2
124126
NeAACDecHandle aacdec[MAX_PROGRAMS];
125127
int16_t silence[NRSC5_AUDIO_FRAME_SAMPLES * 2];

0 commit comments

Comments
 (0)