@@ -828,10 +828,27 @@ void eDVBScan::channelDone()
828828
829829 m_ch_current->getHash (hash);
830830
831- eDVBNamespace dvbnamespace = buildNamespace (
832- (**m_SDT->getSections ().begin ()).getOriginalNetworkId (),
833- (**m_SDT->getSections ().begin ()).getTransportStreamId (),
834- hash);
831+ eOriginalNetworkID onid = (**m_SDT->getSections ().begin ()).getOriginalNetworkId ();
832+ eTransportStreamID tsid = (**m_SDT->getSections ().begin ()).getTransportStreamId ();
833+
834+ eDVBNamespace dvbnamespace = buildNamespace (onid, tsid, hash);
835+
836+ /* Detect namespace collision: if a channel with the same stripped namespace+TSID+ONID
837+ * already exists in the database but points to a different physical transponder,
838+ * preserve the frequency in the namespace to keep services unique.
839+ * This prevents services with the same SID on different transponders (e.g. EBU feeds)
840+ * from overwriting each other during manual scan. */
841+ eDVBChannelID chid_check (dvbnamespace, tsid, onid);
842+ if (ePtr<iDVBFrontendParameters> existing_ch;
843+ !eDVBDB::getInstance ()->getChannelFrontendData (chid_check, existing_ch))
844+ {
845+ int diff = 0 ;
846+ if (!m_ch_current->calculateDifference (&*existing_ch, diff, false ) && diff > 0 )
847+ {
848+ dvbnamespace = eDVBNamespace (hash);
849+ SCAN_eDebug (" [eDVBScan] namespace collision detected: different transponder uses same TSID/ONID, preserving frequency in namespace" );
850+ }
851+ }
835852
836853 SCAN_eDebug (" [eDVBScan] SDT: " );
837854 std::vector<ServiceDescriptionSection*>::const_iterator i;
@@ -847,11 +864,25 @@ void eDVBScan::channelDone()
847864 m_ch_current->getHash (hash);
848865
849866 int onid = 0 ; /* TODO: ATSC ONID? */
867+ eTransportStreamID tsid = (**m_VCT->getSections ().begin ()).getTransportStreamId ();
850868 eDVBNamespace dvbnamespace = buildNamespace (
851869 eOriginalNetworkID (onid),
852- (**m_VCT-> getSections (). begin ()). getTransportStreamId () ,
870+ tsid ,
853871 hash);
854872
873+ /* Detect namespace collision (same as SDT block above) */
874+ eDVBChannelID chid_check (dvbnamespace, tsid, eOriginalNetworkID (onid));
875+ if (ePtr<iDVBFrontendParameters> existing_ch;
876+ !eDVBDB::getInstance ()->getChannelFrontendData (chid_check, existing_ch))
877+ {
878+ int diff = 0 ;
879+ if (!m_ch_current->calculateDifference (&*existing_ch, diff, false ) && diff > 0 )
880+ {
881+ dvbnamespace = eDVBNamespace (hash);
882+ SCAN_eDebug (" [eDVBScan] namespace collision detected: different transponder uses same TSID/ONID, preserving frequency in namespace" );
883+ }
884+ }
885+
855886 SCAN_eDebug (" [eDVBScan] VCT: " );
856887 std::vector<VirtualChannelTableSection*>::const_iterator i;
857888 for (i = m_VCT->getSections ().begin (); i != m_VCT->getSections ().end (); ++i)
0 commit comments