From 2d4f52ae6223b30a4f07a7fa89d1fe671944d021 Mon Sep 17 00:00:00 2001 From: Jacek Jendrzej Date: Tue, 29 Aug 2017 16:35:32 +0200 Subject: [PATCH] pic max10 code from commit f480ad018c72d40a9d2d2fb4006cfca1c262234d --- src/driver/radiotext.cpp | 42 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/src/driver/radiotext.cpp b/src/driver/radiotext.cpp index 773c51034..6374b477e 100644 --- a/src/driver/radiotext.cpp +++ b/src/driver/radiotext.cpp @@ -2375,7 +2375,13 @@ void CRadioText::run() uint current_pid = 0; printf("CRadioText::run: ###################### Starting thread ######################\n"); +#if HAVE_SPARK_HARDWARE || HAVE_DUCKBOX_HARDWARE || HAVE_GENERIC_HARDWARE + int buflen = 0; + unsigned char *buf = NULL; + audioDemux = new cDemux(0); // live demux +#else audioDemux = new cDemux(1); +#endif audioDemux->Open(DMX_PES_CHANNEL,0,128*1024); while(running) { @@ -2400,11 +2406,41 @@ void CRadioText::run() } mutex.unlock(); if (pid) { +#if HAVE_SPARK_HARDWARE || HAVE_DUCKBOX_HARDWARE || HAVE_GENERIC_HARDWARE + int n; + unsigned char tmp[6]; + + n = audioDemux->Read(tmp, 6, 500); + if (n != 6) { + usleep(10000); /* save CPU if nothing read */ + continue; + } + if (memcmp(tmp, "\000\000\001\300", 4)) + continue; + int packlen = ((tmp[4] << 8) | tmp[5]) + 6; + + if (buflen < packlen) { + if (buf) + free(buf); + buf = (unsigned char *) calloc(1, packlen); + buflen = packlen; + } + if (!buf) + break; + memcpy(buf, tmp, 6); + + while ((n < packlen) && running) { + int len = audioDemux->Read(buf + n, packlen - n, 500); + if (len < 0) + break; + n += len; + } +#else int n; unsigned char buf[0x1FFFF]; n = audioDemux->Read(buf, sizeof(buf), 500 /*5000*/); - +#endif if (n > 0) { //printf("."); fflush(stdout); mutex.lock(); @@ -2413,6 +2449,10 @@ void CRadioText::run() } } } +#if HAVE_SPARK_HARDWARE || HAVE_DUCKBOX_HARDWARE || HAVE_GENERIC_HARDWARE + if (buf) + free(buf); +#endif delete audioDemux; audioDemux = NULL; printf("CRadioText::run: ###################### exit ######################\n");