Skip to content

Commit

Permalink
dual tunerletter detection
Browse files Browse the repository at this point in the history
  • Loading branch information
atvcaptain committed Sep 24, 2017
1 parent a60fea7 commit c29488a
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 56 deletions.
4 changes: 4 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,10 @@ if test x"$with_amlogic" = xyes ; then
ALSA_CFLAGS="-lasound"
fi

if test "$BOXTYPE" == "dm7080" -o "$BOXTYPE" == "dm820" -o "$BOXTYPE" == "dm800se" -o "$BOXTYPE" == "dm800sev2" -o "$BOXTYPE" == "dm7020hd" -o "$BOXTYPE" == "dm7020hdv2" -o "$BOXTYPE" == "dm900" -o "$BOXTYPE" == "dm920"; then
AC_DEFINE(DREAMBOX_DUAL_TUNER, 1,[define BOXTYPE DM7080])
fi

if test "$BOXTYPE" == "dm7080" -o "$BOXTYPE" == "dm820" -o "$BOXTYPE" == "dm900" -o "$BOXTYPE" == "dm920" -o "$BOXTYPE" == "dm520"; then
AC_DEFINE(CONFIG_ION, 1,[define BOX use ION Allocator])
fi
Expand Down
134 changes: 78 additions & 56 deletions lib/dvb_ci/dvbci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,67 @@

eDVBCIInterfaces *eDVBCIInterfaces::instance = 0;

static char* readInputCI(int NimNumber)
{
char id1[] = "NIM Socket";
char id2[] = "Input_Name";
char keys1[] = "1234567890";
char keys2[] = "12ABCDabcd";
char *inputName = 0;
char buf[256];
FILE *f;

f = fopen("/proc/bus/nim_sockets", "rt");
if (f)
{
while (fgets(buf, sizeof(buf), f))
{
char *p = strcasestr(buf, id1);
if (!p)
continue;

p += strlen(id1);
p += strcspn(p, keys1);
if (*p && strtol(p, 0, 0) == NimNumber)
break;
}

while (fgets(buf, sizeof(buf), f))
{
if (strcasestr(buf, id1))
break;

char *p = strcasestr(buf, id2);
if (!p)
continue;

p = strchr(p + strlen(id2), ':');
if (!p)
continue;

p++;
p += strcspn(p, keys2);
size_t len = strspn(p, keys2);
if (len > 0)
{
inputName = strndup(p, len);
break;
}
}

fclose(f);
}

return inputName;
}

static std::string getTunerLetterDM(int NimNumber)
{
char *srcCI = readInputCI(NimNumber);
if (srcCI) return std::string(srcCI);
return eDVBCISlot::getTunerLetter(NimNumber);
}

#ifdef __sh__
bool eDVBCISlot::checkQueueSize()
{
Expand Down Expand Up @@ -296,7 +357,11 @@ eDVBCIInterfaces::eDVBCIInterfaces()
}

for (eSmartPtrList<eDVBCISlot>::iterator it(m_slots.begin()); it != m_slots.end(); ++it)
#ifdef DREAMBOX_DUAL_TUNER
it->setSource(getTunerLetterDM(0));
#else
it->setSource("A");
#endif

for (int tuner_no = 0; tuner_no < 26; ++tuner_no) // NOTE: this assumes tuners are A .. Z max.
{
Expand All @@ -307,7 +372,11 @@ eDVBCIInterfaces::eDVBCIInterfaces()
if(::access(path.str().c_str(), R_OK) < 0)
break;

#ifdef DREAMBOX_DUAL_TUNER
setInputSource(tuner_no, getTunerLetterDM(tuner_no));
#else
setInputSource(tuner_no, eDVBCISlot::getTunerLetter(tuner_no));
#endif
}

eDebug("[CI] done, found %d common interface slots", num_ci);
Expand Down Expand Up @@ -724,7 +793,11 @@ void eDVBCIInterfaces::recheckPMTHandlers()
if (tunernum != -1)
{
setInputSource(tunernum, ci_source.str());
#ifdef DREAMBOX_DUAL_TUNER
ci_it->setSource(getTunerLetterDM(tunernum));
#else
ci_it->setSource(eDVBCISlot::getTunerLetter(tunernum));
#endif
}
else
{
Expand Down Expand Up @@ -820,7 +893,11 @@ void eDVBCIInterfaces::removePMTHandler(eDVBServicePMTHandler *pmthandler)
slot->sendCAPMT(pmthandler, caids); // send a capmt without caids to remove a running service
slot->removeService(service_to_remove.getServiceID().get());
/* restore ci source to the default (tuner "A") */
#ifdef DREAMBOX_DUAL_TUNER
slot->setSource(getTunerLetterDM(0));
#else
slot->setSource("A");
#endif
}

if (!--slot->use_count)
Expand Down Expand Up @@ -881,61 +958,6 @@ int eDVBCIInterfaces::getMMIState(int slotid)
return slot->getMMIState();
}

static char* readInputCI(int NimNumber)
{
char id1[] = "NIM Socket";
char id2[] = "Input_Name";
char keys1[] = "1234567890";
char keys2[] = "12ABCDabcd";
char *inputName = 0;
char buf[256];
FILE *f;

f = fopen("/proc/bus/nim_sockets", "rt");
if (f)
{
while (fgets(buf, sizeof(buf), f))
{
char *p = strcasestr(buf, id1);
if (!p)
continue;

p += strlen(id1);
p += strcspn(p, keys1);
if (*p && strtol(p, 0, 0) == NimNumber)
break;
}

while (fgets(buf, sizeof(buf), f))
{
if (strcasestr(buf, id1))
break;

char *p = strcasestr(buf, id2);
if (!p)
continue;

p = strchr(p + strlen(id2), ':');
if (!p)
continue;

p++;
p += strcspn(p, keys2);
size_t len = strspn(p, keys2);
if (len > 0)
{
inputName = strndup(p, len);
break;
}
}

fclose(f);
}

return inputName;
}


int eDVBCIInterfaces::setInputSource(int tuner_no, const std::string &source)
{
if (tuner_no >= 0)
Expand Down Expand Up @@ -1706,7 +1728,7 @@ int eDVBCISlot::setSource(const std::string &source)
snprintf(buf, sizeof(buf), "/proc/stb/tsmux/ci%d_input", slotid);
char *srcCI = NULL;

if(source.find("CI") == std::string::npos)
if(source.find("CI") == std::string::npos || source.size() == 1)
{
srcCI = readInputCI(source[0]-65);
}
Expand Down

0 comments on commit c29488a

Please sign in to comment.