[DVDBurn] fix bug 333: display movie length in title list
[enigma2.git] / lib / dvb_ci / dvbci.cpp
index 64b029d46f1645ffa2433dfc2a5de43589547657..883fb5a47fd8373b2ce6b7589e34ca91588c837d 100644 (file)
@@ -200,36 +200,39 @@ int eDVBCIInterfaces::cancelEnq(int slotid)
 
 void eDVBCIInterfaces::ciRemoved(eDVBCISlot *slot)
 {
-       eDebug("CI Slot %d: removed... usecount %d", slot->getSlotID(), slot->use_count);
-       for (PMTHandlerList::iterator it(m_pmt_handlers.begin());
-               it != m_pmt_handlers.end(); ++it)
+       if (slot->use_count)
        {
-               if (it->cislot == slot) // remove the base slot
-                       it->cislot = slot->linked_next;
-               else if (it->cislot)
+               eDebug("CI Slot %d: removed... usecount %d", slot->getSlotID(), slot->use_count);
+               for (PMTHandlerList::iterator it(m_pmt_handlers.begin());
+                       it != m_pmt_handlers.end(); ++it)
                {
-                       eDVBCISlot *prevSlot = it->cislot, *hSlot = it->cislot->linked_next;
-                       while (hSlot)
+                       if (it->cislot == slot) // remove the base slot
+                               it->cislot = slot->linked_next;
+                       else if (it->cislot)
                        {
-                               if (hSlot == slot) {
-                                       prevSlot->linked_next = slot->linked_next;
-                                       break;
+                               eDVBCISlot *prevSlot = it->cislot, *hSlot = it->cislot->linked_next;
+                               while (hSlot)
+                               {
+                                       if (hSlot == slot) {
+                                               prevSlot->linked_next = slot->linked_next;
+                                               break;
+                                       }
+                                       prevSlot = hSlot;
+                                       hSlot = hSlot->linked_next;
                                }
-                               prevSlot = hSlot;
-                               hSlot = hSlot->linked_next;
                        }
                }
+               if (slot->linked_next)
+                       slot->linked_next->setSource(slot->current_source);
+               else // last CI in chain
+                       setInputSource(slot->current_tuner, slot->current_source);
+               slot->linked_next = 0;
+               slot->use_count=0;
+               slot->plugged=true;
+               slot->user_mapped=false;
+               slot->removeService(0xFFFF);
+               recheckPMTHandlers();
        }
-       if (slot->linked_next)
-               slot->linked_next->setSource(slot->current_source);
-       else // last CI in chain
-               setInputSource(slot->current_tuner, slot->current_source);
-       slot->linked_next = 0;
-       slot->use_count=0;
-       slot->plugged=true;
-       slot->user_mapped=false;
-       slot->removeService(0xFFFF);
-       recheckPMTHandlers();
 }
 
 static bool canDescrambleMultipleServices(int slotid)
@@ -549,6 +552,7 @@ void eDVBCIInterfaces::removePMTHandler(eDVBServicePMTHandler *pmthandler)
        if (it != m_pmt_handlers.end())
        {
                eDVBCISlot *slot = it->cislot;
+               eDVBCISlot *base_slot = slot;
                eDVBServicePMTHandler *pmthandler = it->pmthandler;
                m_pmt_handlers.erase(it);
 
@@ -572,20 +576,17 @@ void eDVBCIInterfaces::removePMTHandler(eDVBServicePMTHandler *pmthandler)
 
                while(slot)
                {
+                       eDVBCISlot *next = slot->linked_next;
                        if (!sameServiceExist)
                        {
-                               if (slot->getNumOfServices() > 1)
-                               {
-                                       eDebug("[eDVBCIInterfaces] remove last pmt handler for service %s send empty capmt",
-                                               service_to_remove.toString().c_str());
-                                               std::vector<uint16_t> caids;
-                                       caids.push_back(0xFFFF);
-                                       slot->sendCAPMT(pmthandler, caids);  // send a capmt without caids to remove a running service
-                               }
+                               eDebug("[eDVBCIInterfaces] remove last pmt handler for service %s send empty capmt",
+                                       service_to_remove.toString().c_str());
+                               std::vector<uint16_t> caids;
+                               caids.push_back(0xFFFF);
+                               slot->sendCAPMT(pmthandler, caids);  // send a capmt without caids to remove a running service
                                slot->removeService(service_to_remove.getServiceID().get());
                        }
 
-                       eDVBCISlot *next = slot->linked_next;
                        if (!--slot->use_count)
                        {
                                if (slot->linked_next)
@@ -593,9 +594,7 @@ void eDVBCIInterfaces::removePMTHandler(eDVBServicePMTHandler *pmthandler)
                                else
                                        setInputSource(slot->current_tuner, slot->current_source);
 
-                               if (it->cislot == slot) // remove the base slot
-                                       it->cislot = slot->linked_next;
-                               else
+                               if (base_slot != slot)
                                {
                                        eDVBCISlot *tmp = it->cislot;
                                        while(tmp->linked_next != slot)
@@ -606,6 +605,8 @@ void eDVBCIInterfaces::removePMTHandler(eDVBServicePMTHandler *pmthandler)
                                        else
                                                tmp->linked_next = 0;
                                }
+                               else // removed old base slot.. update ptr
+                                       base_slot = slot->linked_next;
                                slot->linked_next = 0;
                                slot->user_mapped = false;
                        }
@@ -1187,10 +1188,11 @@ int eDVBCISlot::sendCAPMT(eDVBServicePMTHandler *pmthandler, const std::vector<u
                uint16_t program_number = ref.getServiceID().get();
                std::map<uint16_t, uint8_t>::iterator it =
                        running_services.find(program_number);
+               bool sendEmpty = caids.size() == 1 && caids[0] == 0xFFFF;
 
                if ( it != running_services.end() &&
                        (pmt_version == it->second) &&
-                       !(caids.size() == 1 && caids[0] == 0xFFFF) )
+                       !sendEmpty )
                {
                        eDebug("[eDVBCISlot] dont send self capmt version twice");
                        return -1;
@@ -1215,7 +1217,7 @@ int eDVBCISlot::sendCAPMT(eDVBServicePMTHandler *pmthandler, const std::vector<u
                                capmt.append(*i++);
                        }
                        capmt.writeToBuffer(raw_data);
-#if 1
+
 // begin calc capmt length
                        int wp=0;
                        int hlen;
@@ -1236,19 +1238,22 @@ int eDVBCISlot::sendCAPMT(eDVBServicePMTHandler *pmthandler, const std::vector<u
                                hlen = 4;
                        }
 // end calc capmt length
-//                     eDebug("ca_manager %p dump capmt:", ca_manager);
-//                     for(int i=0;i<wp;i++)
-//                             eDebugNoNewLine("%02x ", raw_data[i]);
-//                     eDebug("");
-#endif
-                       if (caids.size() == 1 && caids[0] == 0xFFFF)
+
+                       if (sendEmpty)
                        {
 //                             eDebugNoNewLine("SEND EMPTY CAPMT.. old version is %02x", raw_data[hlen+3]);
+                               if (sendEmpty && running_services.size() == 1)  // check if this is the capmt for the last running service
+                                       raw_data[hlen] = 0x03; // send only instead of update... because of strange effects with alphacrypt
                                raw_data[hlen+3] &= ~0x3E;
                                raw_data[hlen+3] |= ((pmt_version+1) & 0x1F) << 1;
 //                             eDebug(" new version is %02x", raw_data[hlen+3]);
                        }
 
+//                     eDebug("ca_manager %p dump capmt:", ca_manager);
+//                     for(int i=0;i<wp;i++)
+//                             eDebugNoNewLine("%02x ", raw_data[i]);
+//                     eDebug("");
+
                        //dont need tag and lenfield
                        ca_manager->sendCAPMT(raw_data + hlen, wp - hlen);
                        running_services[program_number] = pmt_version;