From 53828f6a746ed4e93780b7aae3772ecddc252bb1 Mon Sep 17 00:00:00 2001 From: TangoCash Date: Fri, 7 Oct 2022 21:02:30 +0200 Subject: [PATCH] rework streaming part3 --- src/driver/streamts.cpp | 11 ++- src/gui/miscsettings_menu.cpp | 15 ++-- src/gui/miscsettings_menu.h | 4 +- src/nhttpd/tuxboxapi/controlapi.cpp | 113 +++++++++++++++++----------- src/nhttpd/tuxboxapi/controlapi.h | 1 + 5 files changed, 90 insertions(+), 54 deletions(-) diff --git a/src/driver/streamts.cpp b/src/driver/streamts.cpp index 4f867c47e..7c24f3ab4 100644 --- a/src/driver/streamts.cpp +++ b/src/driver/streamts.cpp @@ -165,6 +165,9 @@ void CStreamInstance::RemoveClient(int clientfd) bool CStreamInstance::Open() { + printf("CStreamInstance::run: %" PRIx64 "\n", channel_id); + set_threadname("n:streaminstance"); + CZapitChannel * tmpchan = CServiceManager::getInstance()->FindChannel(channel_id); if (!tmpchan) return false; @@ -303,7 +306,10 @@ bool CStreamManager::SetPort(int newport) #endif mutex.lock(); if (listenfd >= 0) + { close(listenfd); + listenfd = -1; + } ret = Listen(); mutex.unlock(); } @@ -436,7 +442,6 @@ bool CStreamManager::Parse(int fd, stream_pids_t &pids, t_channel_id &chid, CFro return false; } -// CFrontend *live_fe = NULL; CZapitChannel * channel = NULL; if (CNeutrinoApp::getInstance()->getMode() != NeutrinoModes::mode_standby) { @@ -529,8 +534,8 @@ void CStreamManager::PreparePids(CZapitChannel *channel, stream_pids_t &pids, bo { for(casys_pids_iterator_t it = channel->capids.begin(); it != channel->capids.end(); ++it) { - pids.insert((*it)); //all ECM Pids - printf("CStreamManager::PreparePids: capid 0x%04x \n", (*it)); + pids.insert((*it)); //all ECM Pids + printf("CStreamManager::PreparePids: capid 0x%04x \n", (*it)); } } diff --git a/src/gui/miscsettings_menu.cpp b/src/gui/miscsettings_menu.cpp index 9322b9476..3ddaa1dce 100644 --- a/src/gui/miscsettings_menu.cpp +++ b/src/gui/miscsettings_menu.cpp @@ -51,6 +51,7 @@ #include #include +#include #include #include @@ -744,20 +745,20 @@ int CMiscMenue::showMiscSettingsMenuStreaming() ms_sservices->addIntroItems(LOCALE_MISCSETTINGS_STREAMING); // port - CIntInput * miscSettings_streamingport = new CIntInput(LOCALE_STREAMING_PORT, &g_settings.streaming_port, 5); + CIntInput * miscSettings_streamingport = new CIntInput(LOCALE_STREAMING_PORT, &g_settings.streaming_port, 5, NONEXISTANT_LOCALE, NONEXISTANT_LOCALE, this); CMenuForwarder * mf = new CMenuDForwarder(LOCALE_STREAMING_PORT, true, to_string(g_settings.streaming_port), miscSettings_streamingport); ms_sservices->addItem(mf); - +#if 0 // entitlements entitlements = new CMenuOptionChooser(LOCALE_STREAMING_ECMMODE, &g_settings.streaming_ecmmode, OPTIONS_OFF0_ON1_OPTIONS, OPTIONS_OFF0_ON1_OPTION_COUNT, true); //entitlements->setHint(NEUTRINO_ICON_HINT_SETTINGS, LOCALE_MENU_HINT_ECMMODE_ENABLED); ms_sservices->addItem(entitlements); - // decrypt + // decrypt mode decrypt = new CMenuOptionChooser(LOCALE_STREAMING_DECRYPTMODE, &g_settings.streaming_decryptmode, OPTIONS_OFF0_ON1_OPTIONS, OPTIONS_OFF0_ON1_OPTION_COUNT, true); - //decrypt->setHint(NEUTRINO_ICON_HINT_SETTINGS, LOCALE_MENU_HINT_DECRYPTMODE_ENABLED); + // decrypt->setHint(NEUTRINO_ICON_HINT_SETTINGS, LOCALE_MENU_HINT_DECRYPTMODE_ENABLED); ms_sservices->addItem(decrypt); - +#endif int res = ms_sservices->exec(NULL, ""); delete ms_sservices; return res; @@ -886,5 +887,9 @@ bool CMiscMenue::changeNotify(const neutrino_locale_t OptionName, void */*data*/ shoutcast_dev_id_short.clear(); shoutcast_onoff->setActive(CApiKey::check_shoutcast_dev_id()); } + else if (ARE_LOCALES_EQUAL(OptionName, LOCALE_STREAMING_PORT)) + { + CStreamManager::getInstance()->SetPort(g_settings.streaming_port); + } return ret; } diff --git a/src/gui/miscsettings_menu.h b/src/gui/miscsettings_menu.h index f4c45cc65..dab132753 100644 --- a/src/gui/miscsettings_menu.h +++ b/src/gui/miscsettings_menu.h @@ -58,8 +58,8 @@ class CMiscMenue : public CMenuTarget, CChangeObserver CMenuOptionChooser *shoutcast_onoff; CMenuForwarder *epg_dir; CMenuForwarder *epg_read_now; - CMenuOptionChooser *ecm_onoff; - CMenuOptionChooser *dec_onoff; + CMenuOptionChooser *entitlements; + CMenuOptionChooser *decrypt; int width; diff --git a/src/nhttpd/tuxboxapi/controlapi.cpp b/src/nhttpd/tuxboxapi/controlapi.cpp index 204b57051..8790be89f 100644 --- a/src/nhttpd/tuxboxapi/controlapi.cpp +++ b/src/nhttpd/tuxboxapi/controlapi.cpp @@ -265,6 +265,7 @@ const CControlAPI::TyCgiCall CControlAPI::yCgiCallList[]= {"xmltvlist", &CControlAPI::xmltvlistCGI, "text/plain"}, // utils {"build_live_url", &CControlAPI::build_live_url, ""}, + {"build_playlist", &CControlAPI::build_playlist, ""}, {"get_logo", &CControlAPI::logoCGI, "text/plain"}, // settings {"config", &CControlAPI::ConfigCGI, "text/plain"}, @@ -3404,7 +3405,9 @@ void CControlAPI::xmltvm3uCGI(CyhookHandler *hh) /* strip off optional custom port */ if (url.rfind(":") != 4) url = url.substr(0, url.rfind(":")); // strip off optional custom port - url += ":31339/id="; + url += ":"; + url += to_string(g_settings.streaming_port); + url += "/id="; for (unsigned int i = 0; i < g_bouquetManager->Bouquets.size(); i++) { @@ -3513,45 +3516,10 @@ void CControlAPI::xmltvlistCGI(CyhookHandler *hh) hh->SendOk(); } //------------------------------------------------------------------------- -// audio_no : (optional) audio channel // host : (optional) ip of dbox void CControlAPI::build_live_url(CyhookHandler *hh) { - std::string xpids; int mode = NeutrinoAPI->Zapit->getMode(); - - if ( mode == CZapitClient::MODE_TV) - { - CZapitClient::responseGetPIDs pids; - int apid=0,apid_no=0,apid_idx=0; - pids.PIDs.vpid=0; - - if(!hh->ParamList["audio_no"].empty()) - apid_no = atoi(hh->ParamList["audio_no"].c_str()); - NeutrinoAPI->Zapit->getPIDS(pids); - - if( apid_no < (int)pids.APIDs.size()) - apid_idx=apid_no; - if(!pids.APIDs.empty()) - apid = pids.APIDs[apid_idx].pid; - xpids = string_printf("0x%04x,0x%04x,0x%04x",pids.PIDs.pmtpid,pids.PIDs.vpid,apid); - if (pids.PIDs.pcrpid != pids.PIDs.vpid) - xpids += string_printf(",0x%04x", pids.PIDs.pcrpid); - } - else if ( mode == CZapitClient::MODE_RADIO) - { - CZapitClient::responseGetPIDs pids; - int apid=0; - - NeutrinoAPI->Zapit->getPIDS(pids); - if(!pids.APIDs.empty()) - apid = pids.APIDs[0].pid; - - //xpids = string_printf("0x%04x",apid); - xpids = string_printf("0x%04x,0x%04x",pids.PIDs.pmtpid,apid); - } - else - hh->SendError(); // build url std::string url = ""; if(!hh->ParamList["host"].empty()) @@ -3562,21 +3530,78 @@ void CControlAPI::build_live_url(CyhookHandler *hh) if (url.rfind(":") != 4) url = url.substr(0, url.rfind(":")); - //url += (mode == CZapitClient::MODE_TV) ? ":31339/0," : ":31338/"; - url += ":31339/0,"; - url += xpids; + url += ":"; + url += to_string(g_settings.streaming_port); + url += "/id="; // response url if(!hh->ParamList["vlc_link"].empty()) { - write_to_file("/tmp/vlc.m3u", url); + write_to_file("/tmp/vlc.m3u", "#EXTM3U\n"); + for (int i = 0; i < (int) g_bouquetManager->Bouquets.size(); i++) + { + ZapitChannelList chanlist; + if (mode == CZapitClient::MODE_RADIO) + g_bouquetManager->Bouquets[i]->getRadioChannels(chanlist); + else + g_bouquetManager->Bouquets[i]->getTvChannels(chanlist); + if (!chanlist.empty() && !g_bouquetManager->Bouquets[i]->bHidden && g_bouquetManager->Bouquets[i]->bUser) + { + for (int j = 0; j < (int) chanlist.size(); j++) + { + CZapitChannel * channel = chanlist[j]; + //printf("---> %s/n",channel->getName().c_str()); + write_to_file("/tmp/vlc.m3u", "#EXTINF:-1,"+channel->getName()+"\n",true); + write_to_file("/tmp/vlc.m3u", url+string_printf(PRINTF_CHANNEL_ID_TYPE_NO_LEADING_ZEROS, channel->getChannelID())+"\n",true); + } + } + } hh->SendRedirect("/tmp/vlc.m3u"); + } else + hh->SendError(); +} + +//------------------------------------------------------------------------- +void CControlAPI::build_playlist(CyhookHandler *hh) +{ + // build url + std::string url = ""; + if(!hh->ParamList["host"].empty()) + url = "http://"+hh->ParamList["host"]; + else + url = "http://"+hh->HeaderList["Host"]; + /* strip off optional custom port */ + if (url.rfind(":") != 4) + url = url.substr(0, url.rfind(":")); + + url += ":"; + url += to_string(g_settings.streaming_port); + url += "/id="; + + if (!hh->ParamList["id"].empty()) + { + url += hh->ParamList["id"]; + t_channel_id channel_id; + sscanf(hh->ParamList["id"].c_str(), SCANF_CHANNEL_ID_TYPE, &channel_id); + std::string chan_name = NeutrinoAPI->Zapit->getChannelName(channel_id); + std::string illegalChars = "\\/:?\"<>|+ "; + std::string::iterator it; + for (it = chan_name.begin() ; it < chan_name.end() ; ++it) + { + bool found = illegalChars.find(*it) != std::string::npos; + if (found) + { + *it = '_'; + } + } + std::string m3u = "/tmp/" + chan_name + ".m3u"; + write_to_file(m3u, "#EXTM3U\n"); + write_to_file(m3u, "#EXTINF:-1," + NeutrinoAPI->Zapit->getChannelName(channel_id) + "\n", true); + write_to_file(m3u, url, true); + hh->SendRedirect(m3u); } else - { - hh->SetHeader(HTTP_OK, "text/html; charset=UTF-8"); - hh->Write(url); - } + hh->SendError(); } //------------------------------------------------------------------------- void CControlAPI::logoCGI(CyhookHandler *hh) diff --git a/src/nhttpd/tuxboxapi/controlapi.h b/src/nhttpd/tuxboxapi/controlapi.h index 7774a4a8c..719d5f3bd 100644 --- a/src/nhttpd/tuxboxapi/controlapi.h +++ b/src/nhttpd/tuxboxapi/controlapi.h @@ -132,6 +132,7 @@ private: void xmltvm3uCGI(CyhookHandler *hh); void xmltvlistCGI(CyhookHandler *hh); void build_live_url(CyhookHandler *hh); + void build_playlist(CyhookHandler *hh); void logoCGI(CyhookHandler *hh); void ConfigCGI(CyhookHandler *hh); void FileCGI(CyhookHandler *hh);