From 1f3788c5e1a47fa9b0412902acba38c86b53bb63 Mon Sep 17 00:00:00 2001 From: Andreas Monzner Date: Sun, 14 May 2006 12:23:23 +0000 Subject: [PATCH] remove unneeded caching of caids, use an array for pidcache instead of std::map (safe memory) prepare for different video stream types.. (H264) ( NOT for dm7025 ) --- lib/dvb/db.cpp | 36 ++++++++++++++++++++++-------------- lib/dvb/decoder.cpp | 17 +++++++++++++---- lib/dvb/decoder.h | 9 +++++---- lib/dvb/idvb.h | 14 ++++++++------ lib/dvb/pmt.cpp | 14 ++++++++++++++ lib/dvb/pmt.h | 4 +++- lib/dvb/scan.cpp | 2 ++ lib/service/servicedvb.cpp | 8 ++++++-- 8 files changed, 73 insertions(+), 31 deletions(-) diff --git a/lib/dvb/db.cpp b/lib/dvb/db.cpp index 22b6267b..64ef6ed7 100644 --- a/lib/dvb/db.cpp +++ b/lib/dvb/db.cpp @@ -116,20 +116,29 @@ RESULT eBouquet::setListName(const std::string &name) eDVBService::eDVBService() :m_flags(0) { + memset(m_cache, -1, sizeof(m_cache)); } eDVBService::~eDVBService() { } +bool eDVBService::cacheEmpty() +{ + for (int i=0; i < cacheMax; ++i) + if (m_cache[i] != -1) + return false; + return true; +} + eDVBService &eDVBService::operator=(const eDVBService &s) { m_service_name = s.m_service_name; m_service_name_sort = s.m_service_name_sort; m_provider_name = s.m_provider_name; m_flags = s.m_flags; - m_ca = s.m_ca; - m_cache = s.m_cache; +// m_ca = s.m_ca; + memcpy(m_cache, s.m_cache, sizeof(m_cache)); return *this; } @@ -225,17 +234,14 @@ int eDVBService::checkFilter(const eServiceReferenceDVB &ref, const eDVBChannelQ int eDVBService::getCachePID(cacheID id) { - std::map::iterator it = m_cache.find(id); - if ( it != m_cache.end() ) - return it->second; - return -1; + if (id >= cacheMax) + return -1; + return m_cache[id]; } void eDVBService::setCachePID(cacheID id, int pid) { - if (pid == -1) - m_cache.erase(id); - else + if (id < cacheMax) m_cache[id] = pid; } @@ -421,12 +427,12 @@ void eDVBDB::reloadServicelist() int cid, val; sscanf(v.c_str(), "%02d%04x", &cid, &val); s->m_cache[cid]=val; - } else if (p == 'C') + }/* else if (p == 'C') { int val; sscanf(v.c_str(), "%04x", &val); s->m_ca.insert(val); - } + }*/ } addService(ref, s); } @@ -510,14 +516,16 @@ void eDVBDB::saveServicelist() fprintf(f, "p:%s", i->second->m_provider_name.c_str()); // write cached pids - for (std::map::const_iterator ca(i->second->m_cache.begin()); - ca != i->second->m_cache.end(); ++ca) - fprintf(f, ",c:%02d%04x", ca->first, ca->second); + for (int x=0; x < eDVBService::cacheMax; ++x) + if (i->second->m_cache[x] != -1) + fprintf(f, ",c:%02d%04x", x, i->second->m_cache[x]); +/* // write cached ca pids for (std::set::const_iterator ca(i->second->m_ca.begin()); ca != i->second->m_ca.end(); ++ca) fprintf(f, ",C:%04x", *ca); +*/ if (i->second->m_flags) fprintf(f, ",f:%x", i->second->m_flags); diff --git a/lib/dvb/decoder.cpp b/lib/dvb/decoder.cpp index a6537e81..1bec997d 100644 --- a/lib/dvb/decoder.cpp +++ b/lib/dvb/decoder.cpp @@ -175,13 +175,21 @@ eDVBVideo::eDVBVideo(eDVBDemux *demux, int dev): m_demux(demux), m_dev(dev) eWarning("%s: %m", filename); eDebug("demux device: %s", filename); } - -int eDVBVideo::startPid(int pid) + +// not finally values i think.. !! +#define VIDEO_STREAMTYPE_MPEG2 0 +#define VIDEO_STREAMTYPE_MPEG4_H264 1 + +int eDVBVideo::startPid(int pid, int type) { if ((m_fd < 0) || (m_fd_demux < 0)) return -1; dmx_pes_filter_params pes; + if (::ioctl(m_fd, VIDEO_SET_STREAMTYPE, + type == MPEG4_H264 ? VIDEO_STREAMTYPE_MPEG4_H264 : VIDEO_STREAMTYPE_MPEG2) < 0) + eWarning("video: VIDEO_SET_STREAMTYPE: %m"); + pes.pid = pid; pes.input = DMX_IN_FRONTEND; pes.output = DMX_OUT_DECODER; @@ -465,7 +473,7 @@ int eTSMPEGDecoder::setState() { eDebug("new video"); m_video = new eDVBVideo(m_demux, m_decoder); - if (m_video->startPid(m_vpid)) + if (m_video->startPid(m_vpid, m_vtype)) { eWarning("video: startpid failed!"); res = -1; @@ -522,12 +530,13 @@ eTSMPEGDecoder::~eTSMPEGDecoder() setState(); } -RESULT eTSMPEGDecoder::setVideoPID(int vpid) +RESULT eTSMPEGDecoder::setVideoPID(int vpid, int type) { if (m_vpid != vpid) { m_changed |= changeVideo; m_vpid = vpid; + m_vtype = type; } return 0; } diff --git a/lib/dvb/decoder.h b/lib/dvb/decoder.h index bceca040..834499b0 100644 --- a/lib/dvb/decoder.h +++ b/lib/dvb/decoder.h @@ -11,7 +11,7 @@ private: ePtr m_demux; int m_fd, m_fd_demux, m_dev; public: - enum {aMPEG, aAC3, aDTS }; + enum { aMPEG, aAC3, aDTS, aAAC }; eDVBAudio(eDVBDemux *demux, int dev); int startPid(int pid, int type); void stop(); @@ -35,8 +35,9 @@ private: int m_is_slow_motion, m_is_fast_forward; public: + enum { MPEG2, MPEG4_H264 }; eDVBVideo(eDVBDemux *demux, int dev); - int startPid(int pid); + int startPid(int pid, int type); void stop(); #if HAVE_DVB_API_VERSION < 3 void start(); @@ -86,7 +87,7 @@ private: ePtr m_video; ePtr m_pcr; ePtr m_text; - int m_vpid, m_apid, m_atype, m_pcrpid, m_textpid; + int m_vpid, m_vtype, m_apid, m_atype, m_pcrpid, m_textpid; enum { changeVideo = 1, @@ -104,7 +105,7 @@ public: enum { pidNone = -1 }; eTSMPEGDecoder(eDVBDemux *demux, int decoder); virtual ~eTSMPEGDecoder(); - RESULT setVideoPID(int vpid); + RESULT setVideoPID(int vpid, int type); RESULT setAudioPID(int apid, int type); RESULT setSyncPCR(int pcrpid); RESULT setTextPID(int textpid); diff --git a/lib/dvb/idvb.h b/lib/dvb/idvb.h index 06080429..ecf8bb92 100644 --- a/lib/dvb/idvb.h +++ b/lib/dvb/idvb.h @@ -223,12 +223,13 @@ class eDVBService: public iStaticServiceInformation public: enum cacheID { - cVPID, cAPID, cTPID, cPCRPID, cAC3PID, cacheMax + cVPID, cAPID, cTPID, cPCRPID, cAC3PID, cVTYPE, cacheMax }; int getCachePID(cacheID); void setCachePID(cacheID, int); - bool cacheEmpty() { return m_cache.empty(); } + + bool cacheEmpty(); eDVBService(); /* m_service_name_sort is uppercase, with special chars removed, to increase sort performance. */ @@ -249,8 +250,9 @@ public: bool usePMT() const { return !(m_flags & dxNoDVB); } - std::set m_ca; - std::map m_cache; +// std::set m_ca; + + int m_cache[cacheMax]; virtual ~eDVBService(); eDVBService &operator=(const eDVBService &); @@ -572,8 +574,8 @@ class iTSMPEGDecoder: public iObject { public: enum { pidDisabled = -1 }; - /** Set Displayed Video PID */ - virtual RESULT setVideoPID(int vpid)=0; + /** Set Displayed Video PID and type */ + virtual RESULT setVideoPID(int vpid, int type)=0; enum { af_MPEG, af_AC3, af_DTS }; /** Set Displayed Audio PID and type */ diff --git a/lib/dvb/pmt.cpp b/lib/dvb/pmt.cpp index 4af18020..11cda125 100644 --- a/lib/dvb/pmt.cpp +++ b/lib/dvb/pmt.cpp @@ -250,9 +250,12 @@ int eDVBServicePMTHandler::getProgramInfo(struct program &program) video.pid = (*es)->getPid(); audio.pid = (*es)->getPid(); + video.type = videoStream::vtMPEG2; switch ((*es)->getType()) { + case 0x1b: // AVC Video Stream (MPEG4 H264) + video.type = videoStream::vtMPEG4_H264; case 0x01: // MPEG 1 video case 0x02: // MPEG 2 video isvideo = 1; @@ -277,6 +280,13 @@ int eDVBServicePMTHandler::getProgramInfo(struct program &program) if ( program.textPid == -1 || (*es)->getPid() == cached_tpid ) program.textPid = (*es)->getPid(); break; + case DTS_DESCRIPTOR: + if (!isvideo) + { + isaudio = 1; + audio.type = audioStream::atDTS; + } + break; case AC3_DESCRIPTOR: if (!isvideo) { @@ -354,11 +364,15 @@ int eDVBServicePMTHandler::getProgramInfo(struct program &program) apid_mpeg = m_service->getCachePID(eDVBService::cAPID), pcrpid = m_service->getCachePID(eDVBService::cPCRPID), tpid = m_service->getCachePID(eDVBService::cTPID), + vpidtype = m_service->getCachePID(eDVBService::cVTYPE), cnt=0; + if ( vpidtype == -1 ) + vpidtype = videoStream::vtMPEG2; if ( vpid != -1 ) { videoStream s; s.pid = vpid; + s.type = vpidtype; program.videoStreams.push_back(s); ++cnt; } diff --git a/lib/dvb/pmt.h b/lib/dvb/pmt.h index 6a5b00db..b6a3743f 100644 --- a/lib/dvb/pmt.h +++ b/lib/dvb/pmt.h @@ -99,12 +99,14 @@ public: { int pid; int component_tag; + enum { vtMPEG2, vtMPEG4_H264 }; + int type; }; struct audioStream { int pid; - enum { atMPEG, atAC3, atDTS }; + enum { atMPEG, atAC3, atDTS, atAAC }; int type; // mpeg2, ac3, dts, ... int component_tag; diff --git a/lib/dvb/scan.cpp b/lib/dvb/scan.cpp index ade63d8f..3bfbe571 100644 --- a/lib/dvb/scan.cpp +++ b/lib/dvb/scan.cpp @@ -580,6 +580,7 @@ RESULT eDVBScan::processSDT(eDVBNamespace dvbnamespace, const ServiceDescription SCAN_eDebug("name '%s', provider_name '%s'", service->m_service_name.c_str(), service->m_provider_name.c_str()); break; } +/* case CA_IDENTIFIER_DESCRIPTOR: { CaIdentifierDescriptor &d = (CaIdentifierDescriptor&)**desc; @@ -593,6 +594,7 @@ RESULT eDVBScan::processSDT(eDVBNamespace dvbnamespace, const ServiceDescription SCAN_eDebug(""); break; } +*/ default: SCAN_eDebug("descr<%x>", (*desc)->getTag()); break; diff --git a/lib/service/servicedvb.cpp b/lib/service/servicedvb.cpp index 192d3a64..742d60ee 100644 --- a/lib/service/servicedvb.cpp +++ b/lib/service/servicedvb.cpp @@ -1559,7 +1559,7 @@ void eDVBServicePlay::switchToTimeshift() void eDVBServicePlay::updateDecoder() { - int vpid = -1, apid = -1, apidtype = -1, pcrpid = -1, tpid = -1; + int vpid = -1, vpidtype = -1, apid = -1, apidtype = -1, pcrpid = -1, tpid = -1; eDVBServicePMTHandler &h = m_timeshift_active ? m_service_handler_timeshift : m_service_handler; bool defaultac3=false; @@ -1582,7 +1582,10 @@ void eDVBServicePlay::updateDecoder() i != program.videoStreams.end(); ++i) { if (vpid == -1) + { vpid = i->pid; + vpidtype = i->type; + } if (i != program.videoStreams.begin()) eDebugNoNewLine(", "); eDebugNoNewLine("%04x", i->pid); @@ -1631,7 +1634,7 @@ void eDVBServicePlay::updateDecoder() if (m_decoder) { - m_decoder->setVideoPID(vpid); + m_decoder->setVideoPID(vpid, vpidtype); m_current_audio_stream = 0; m_decoder->setAudioPID(apid, apidtype); if (!(m_is_pvr || m_timeshift_active || !m_is_primary)) @@ -1666,6 +1669,7 @@ void eDVBServicePlay::updateDecoder() m_dvb_service->setCachePID(eDVBService::cAC3PID, apid); } m_dvb_service->setCachePID(eDVBService::cVPID, vpid); + m_dvb_service->setCachePID(eDVBService::cVTYPE, vpidtype); m_dvb_service->setCachePID(eDVBService::cPCRPID, pcrpid); m_dvb_service->setCachePID(eDVBService::cTPID, tpid); } -- 2.30.2