Merge commit 'origin/bug_449_fix_wlan_usbstick_recognition'
[enigma2.git] / lib / dvb / radiotext.cpp
index eff40e9299f4627279e3ca41155130f7a449d93d..e9bdd63a860052f0261cdca9897355fe392ce7ed 100644 (file)
@@ -5,19 +5,22 @@
 
 DEFINE_REF(eDVBRdsDecoder);
 
-eDVBRdsDecoder::eDVBRdsDecoder(iDVBDemux *demux)
+eDVBRdsDecoder::eDVBRdsDecoder(iDVBDemux *demux, int type)
        :msgPtr(0), bsflag(0), qdar_pos(0), t_ptr(0), qdarmvi_show(0), state(0)
-       ,m_abortTimer(eApp)
+       ,m_type(type), m_pid(-1), m_abortTimer(eTimer::create(eApp))
 {
        setStreamID(0xC0, 0xC0);
 
        memset(rass_picture_mask, 0, sizeof(rass_picture_mask));
+       memset(rtp_item, 0, sizeof(rtp_item));
 
        if (demux->createPESReader(eApp, m_pes_reader))
                eDebug("failed to create PES reader!");
-       else
+       else if (type == 0)
                m_pes_reader->connectRead(slot(*this, &eDVBRdsDecoder::processData), m_read_connection);
-       CONNECT(m_abortTimer.timeout, eDVBRdsDecoder::abortNonAvail);
+       else
+               m_pes_reader->connectRead(slot(*this, &eDVBRdsDecoder::gotAncillaryData), m_read_connection);
+       CONNECT(m_abortTimer->timeout, eDVBRdsDecoder::abortNonAvail);
 }
 
 eDVBRdsDecoder::~eDVBRdsDecoder()
@@ -138,7 +141,6 @@ void eDVBRdsDecoder::removeFromPictureMask(int id)
 void eDVBRdsDecoder::processPESPacket(__u8 *data, int len)
 {
        int pos=9+data[8];// skip pes header
-       int cnt=0;
 
        while (pos < len)
        {
@@ -150,7 +152,7 @@ void eDVBRdsDecoder::processPESPacket(__u8 *data, int len)
                int channel = mode == 3 ? 1 : 2;
                int id = (data[pos + 1] >> 3) & 1;
                int emphasis_bit = data[pos + 3] & 3;
-               int protection_bit = data[pos + 1] & 1;
+               //int protection_bit = data[pos + 1] & 1;
                int rate = -1;
                int sample_freq = -1;
                int layer = -1;
@@ -193,10 +195,10 @@ void eDVBRdsDecoder::processPESPacket(__u8 *data, int len)
 
                if (data[offs] == 0xFD)
                {
-                       m_abortTimer.stop();
+                       m_abortTimer->stop();
                        int ancillary_len = 1 + data[offs - 1];
                        offs -= ancillary_len;
-                       gotAncillaryData(data+offs, ancillary_len);
+                       gotAncillaryData(data+offs, ancillary_len-1);
                }
        }
 }
@@ -310,13 +312,19 @@ void eDVBRdsDecoder::process_qdar(unsigned char *buf)
        }
 }
 
-inline void eDVBRdsDecoder::gotAncillaryData(__u8 *buf, int len)
+void eDVBRdsDecoder::gotAncillaryData(const __u8 *buf, int len)
 {
-       int cnt=buf[--len];
-       while ( cnt-- > 0 )
+       if (len <= 0)
+               return;
+       int pos = m_type ? 0 : len-1;
+       while ( len )
        {
-               unsigned char c = buf[--len];
-       
+               unsigned char c = buf[pos];
+
+               pos += m_type ? 1 : -1;
+
+               --len;
+
                if (bsflag == 1) // byte stuffing
                {
                        bsflag=2;
@@ -562,14 +570,20 @@ inline void eDVBRdsDecoder::gotAncillaryData(__u8 *buf, int len)
                                        rtp_len[1]   = 0x1f & rtp_buf[4];
                                                                        
                                        unsigned char rtplus_osd_tmp[64];
-                                                                       
-                                       memcpy(rtp_item[rtp_typ[0]],lastmessage+rtp_start[0],rtp_len[0]+1);
-                                       rtp_item[rtp_typ[0]][rtp_len[0]+1]=0;
+                                       
+                                       if (rtp_start[0] < 66 && (rtp_len[0]+rtp_start[0]) < 66)
+                                       {
+                                               memcpy(rtp_item[rtp_typ[0]],lastmessage+rtp_start[0],rtp_len[0]+1);
+                                               rtp_item[rtp_typ[0]][rtp_len[0]+1]=0;
+                                       }
                                                                        
                                        if (rtp_typ[0] != rtp_typ[1])
                                        {
-                                               memcpy(rtp_item[rtp_typ[1]],lastmessage+rtp_start[1],rtp_len[1]+1);
-                                               rtp_item[rtp_typ[1]][rtp_len[1]+1]=0;
+                                               if (rtp_start[1] < 66 && (rtp_len[1]+rtp_start[1]) < 66)
+                                               {
+                                                       memcpy(rtp_item[rtp_typ[1]],lastmessage+rtp_start[1],rtp_len[1]+1);
+                                                       rtp_item[rtp_typ[1]][rtp_len[1]+1]=0;
+                                               }
                                        }
 
                                        // main RTPlus item_types used by the radio stations:
@@ -632,8 +646,9 @@ std::string eDVBRdsDecoder::getRassPicture(int page, int subpage)
 int eDVBRdsDecoder::start(int pid)
 {
        int ret = -1;
-       if (m_pes_reader && !(ret = m_pes_reader->start(pid)))
-               m_abortTimer.startLongTimer(20);
+       if (m_pes_reader && !(ret = m_pes_reader->start(pid)) && m_type == 0)
+               m_abortTimer->startLongTimer(20);
+       m_pid = pid;
        return ret;
 }