X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/008552809692c70b231d58032408790e578a6306..dec9693d8437a31dab8e4010b33b57e1476a315c:/lib/dvb/pmt.cpp diff --git a/lib/dvb/pmt.cpp b/lib/dvb/pmt.cpp index 842d6979..4ad4e76f 100644 --- a/lib/dvb/pmt.cpp +++ b/lib/dvb/pmt.cpp @@ -16,15 +16,18 @@ #include #include #include +#include +#include eDVBServicePMTHandler::eDVBServicePMTHandler() - :m_ca_servicePtr(0), m_dvb_scan(0), m_decode_demux_num(0xFF) + :m_ca_servicePtr(0), m_dvb_scan(0), m_decode_demux_num(0xFF), m_no_pat_entry_delay(eTimer::create()) { m_use_decode_demux = 0; m_pmt_pid = -1; eDVBResourceManager::getInstance(m_resourceManager); CONNECT(m_PMT.tableReady, eDVBServicePMTHandler::PMTready); CONNECT(m_PAT.tableReady, eDVBServicePMTHandler::PATready); + CONNECT(m_no_pat_entry_delay->timeout, eDVBServicePMTHandler::sendEventNoPatEntry); } eDVBServicePMTHandler::~eDVBServicePMTHandler() @@ -50,10 +53,13 @@ void eDVBServicePMTHandler::channelStateChanged(iDVBChannel *channel) { eDebug("ok ... now we start!!"); - if (m_pmt_pid == -1) - m_PAT.begin(eApp, eDVBPATSpec(), m_demux); - else - m_PMT.begin(eApp, eDVBPMTSpec(m_pmt_pid, m_reference.getServiceID().get()), m_demux); + if (!m_service || m_service->usePMT()) + { + if (m_pmt_pid == -1) + m_PAT.begin(eApp, eDVBPATSpec(), m_demux); + else + m_PMT.begin(eApp, eDVBPMTSpec(m_pmt_pid, m_reference.getServiceID().get()), m_demux); + } if ( m_service && !m_service->cacheEmpty() ) serviceEvent(eventNewProgramInfo); @@ -70,6 +76,9 @@ void eDVBServicePMTHandler::channelEvent(iDVBChannel *channel, int event) { switch (event) { + case iDVBChannel::evtPreStart: + serviceEvent(eventPreStart); + break; case iDVBChannel::evtEOF: serviceEvent(eventEOF); break; @@ -118,30 +127,60 @@ void eDVBServicePMTHandler::PMTready(int error) } } +void eDVBServicePMTHandler::sendEventNoPatEntry() +{ + serviceEvent(eventNoPATEntry); +} + void eDVBServicePMTHandler::PATready(int) { + eDebug("PATready"); ePtr > ptr; if (!m_PAT.getCurrent(ptr)) { + int service_id_single = -1; + int pmtpid_single = -1; int pmtpid = -1; + int cnt=0; std::vector::const_iterator i; - for (i = ptr->getSections().begin(); i != ptr->getSections().end(); ++i) + for (i = ptr->getSections().begin(); pmtpid == -1 && i != ptr->getSections().end(); ++i) { const ProgramAssociationSection &pat = **i; ProgramAssociationConstIterator program; - for (program = pat.getPrograms()->begin(); program != pat.getPrograms()->end(); ++program) + for (program = pat.getPrograms()->begin(); pmtpid == -1 && program != pat.getPrograms()->end(); ++program) + { + ++cnt; if (eServiceID((*program)->getProgramNumber()) == m_reference.getServiceID()) pmtpid = (*program)->getProgramMapPid(); + if (++cnt == 1 && pmtpid_single == -1 && pmtpid == -1) + { + pmtpid_single = (*program)->getProgramMapPid(); + service_id_single = (*program)->getProgramNumber(); + } + else + pmtpid_single = service_id_single = -1; + } } - if (pmtpid == -1) - serviceEvent(eventNoPATEntry); - else + if (pmtpid_single != -1) // only one PAT entry .. and not valid pmtpid found + { + eDebug("use single pat entry!"); + m_reference.setServiceID(eServiceID(service_id_single)); + pmtpid = pmtpid_single; + } + if (pmtpid == -1) { + eDebug("no PAT entry found.. start delay"); + m_no_pat_entry_delay->start(1000, true); + } + else { + eDebug("use pmtpid %04x for service_id %04x", pmtpid, m_reference.getServiceID().get()); + m_no_pat_entry_delay->stop(); m_PMT.begin(eApp, eDVBPMTSpec(pmtpid, m_reference.getServiceID().get()), m_demux); + } } else serviceEvent(eventNoPAT); } -PyObject *eDVBServicePMTHandler::getCaIds() +PyObject *eDVBServicePMTHandler::getCaIds(bool pair) { ePyObject ret; @@ -149,20 +188,37 @@ PyObject *eDVBServicePMTHandler::getCaIds() if ( !getProgramInfo(prog) ) { - int cnt=prog.caids.size(); - if (cnt) + if (pair) { + int cnt=prog.caids.size(); + if (cnt) + { + ret=PyList_New(cnt); + std::list::iterator it(prog.caids.begin()); + while(cnt--) + { + ePyObject tuple = PyTuple_New(2); + PyTuple_SET_ITEM(tuple, 0, PyInt_FromLong(it->caid)); + PyTuple_SET_ITEM(tuple, 1, PyInt_FromLong((it++)->capid)); + PyList_SET_ITEM(ret, cnt, tuple); + } + } + } + else + { + std::set set(prog.caids.begin(), prog.caids.end()); + std::set::iterator it(set.begin()); + int cnt=set.size(); ret=PyList_New(cnt); - std::set::iterator it(prog.caids.begin()); while(cnt--) - PyList_SET_ITEM(ret, cnt, PyInt_FromLong(*it++)); + PyList_SET_ITEM(ret, cnt, PyInt_FromLong((it++)->caid)); } } return ret ? (PyObject*)ret : (PyObject*)PyList_New(0); } -int eDVBServicePMTHandler::getProgramInfo(struct program &program) +int eDVBServicePMTHandler::getProgramInfo(program &program) { ePtr > ptr; int cached_apid_ac3 = -1; @@ -179,6 +235,7 @@ int eDVBServicePMTHandler::getProgramInfo(struct program &program) int first_ac3 = -1; program.defaultAudioStream = 0; + audioStream *prev_audio = 0; if ( m_service && !m_service->cacheEmpty() ) { @@ -204,45 +261,137 @@ int eDVBServicePMTHandler::getProgramInfo(struct program &program) for (i = ptr->getSections().begin(); i != ptr->getSections().end(); ++i) { const ProgramMapSection &pmt = **i; + int is_hdmv = 0; + program.pcrPid = pmt.getPcrPid(); - + + for (DescriptorConstIterator desc = pmt.getDescriptors()->begin(); + desc != pmt.getDescriptors()->end(); ++desc) + { + if ((*desc)->getTag() == CA_DESCRIPTOR) + { + CaDescriptor *descr = (CaDescriptor*)(*desc); + program::capid_pair pair; + pair.caid = descr->getCaSystemId(); + pair.capid = descr->getCaPid(); + program.caids.push_back(pair); + } + else if ((*desc)->getTag() == REGISTRATION_DESCRIPTOR) + { + RegistrationDescriptor *d = (RegistrationDescriptor*)(*desc); + if (d->getFormatIdentifier() == 0x48444d56) // HDMV + is_hdmv = 1; + } + } + ElementaryStreamInfoConstIterator es; for (es = pmt.getEsInfo()->begin(); es != pmt.getEsInfo()->end(); ++es) { - int isaudio = 0, isvideo = 0; + int isaudio = 0, isvideo = 0, issubtitle = 0, forced_video = 0, forced_audio = 0, isteletext = 0; + int streamtype = (*es)->getType(); videoStream video; audioStream audio; audio.component_tag=video.component_tag=-1; video.type = videoStream::vtMPEG2; + audio.type = audioStream::atMPEG; + audio.rdsPid = -1; - switch ((*es)->getType()) + switch (streamtype) { case 0x1b: // AVC Video Stream (MPEG4 H264) video.type = videoStream::vtMPEG4_H264; + isvideo = 1; + //break; fall through !!! + case 0x10: // MPEG 4 Part 2 + if (!isvideo) + { + video.type = videoStream::vtMPEG4_Part2; + isvideo = 1; + } + //break; fall through !!! case 0x01: // MPEG 1 video + if (!isvideo) + video.type = videoStream::vtMPEG1; + //break; fall through !!! case 0x02: // MPEG 2 video isvideo = 1; + forced_video = 1; //break; fall through !!! case 0x03: // MPEG 1 audio case 0x04: // MPEG 2 audio: - if (!isvideo) + if (!isvideo) { + isaudio = 1; + forced_audio = 1; + } + //break; fall through !!! + case 0x0f: // MPEG 2 AAC + if (!isvideo && !isaudio) { isaudio = 1; - audio.type = audioStream::atMPEG; + audio.type = audioStream::atAAC; + forced_audio = 1; } //break; fall through !!! + case 0x11: // MPEG 4 AAC + if (!isvideo && !isaudio) + { + isaudio = 1; + audio.type = audioStream::atAACHE; + forced_audio = 1; + } + case 0x80: // user private ... but bluray LPCM + case 0xA0: // bluray secondary LPCM + if (!isvideo && !isaudio && is_hdmv) + { + isaudio = 1; + audio.type = audioStream::atLPCM; + } + case 0x81: // user private ... but bluray AC3 + case 0xA1: // bluray secondary AC3 + if (!isvideo && !isaudio && is_hdmv) + { + isaudio = 1; + audio.type = audioStream::atAC3; + } + case 0x82: // bluray DTS (dvb user private...) + case 0xA2: // bluray secondary DTS + if (!isvideo && !isaudio && is_hdmv) + { + isaudio = 1; + audio.type = audioStream::atDTS; + } + case 0x86: // bluray DTS-HD (dvb user private...) + case 0xA6: // bluray secondary DTS-HD + if (!isvideo && !isaudio && is_hdmv) + { + isaudio = 1; + audio.type = audioStream::atDTSHD; + } case 0x06: // PES Private - case 0x81: // user private + case 0xEA: // TS_PSI_ST_SMPTE_VC1 + { + int num_descriptors = 0; for (DescriptorConstIterator desc = (*es)->getDescriptors()->begin(); - desc != (*es)->getDescriptors()->end(); ++desc) + desc != (*es)->getDescriptors()->end(); ++desc) { uint8_t tag = (*desc)->getTag(); - if (!isaudio && !isvideo) + /* check descriptors to get the exakt stream type. */ + ++num_descriptors; + if (!forced_video && !forced_audio) { - /* PES private can contain AC-3, DTS or lots of other stuff. - check descriptors to get the exakt type. */ switch (tag) { + case AUDIO_STREAM_DESCRIPTOR: + isaudio = 1; + break; + case VIDEO_STREAM_DESCRIPTOR: + { + isvideo = 1; + VideoStreamDescriptor *d = (VideoStreamDescriptor*)(*desc); + if (d->getMpeg1OnlyFlag()) + video.type = videoStream::vtMPEG1; + break; + } case SUBTITLING_DESCRIPTOR: { SubtitlingDescriptor *d = (SubtitlingDescriptor*)(*desc); @@ -268,6 +417,7 @@ int eDVBServicePMTHandler::getProgramInfo(struct program &program) s.language_code = (*it)->getIso639LanguageCode(); // eDebug("add dvb subtitle %s PID %04x, type %d, composition page %d, ancillary_page %d", // s.language_code.c_str(), s.pid, s.subtitling_type, s.composition_page_id, s.ancillary_page_id); + issubtitle=1; program.subtitleStreams.push_back(s); } break; @@ -279,6 +429,7 @@ int eDVBServicePMTHandler::getProgramInfo(struct program &program) s.subtitling_type = 0x01; // EBU TELETEXT SUBTITLES s.pid = program.textPid = (*es)->getPid(); TeletextDescriptor *d = (TeletextDescriptor*)(*desc); + isteletext = 1; const VbiTeletextList *list = d->getVbiTeletexts(); for (VbiTeletextConstIterator it(list->begin()); it != list->end(); ++it) { @@ -292,6 +443,8 @@ int eDVBServicePMTHandler::getProgramInfo(struct program &program) // eDebug("add teletext subtitle %s PID %04x, page number %d, magazine number %d", // s.language_code.c_str(), s.pid, s.teletext_page_number, s.teletext_magazine_number); program.subtitleStreams.push_back(s); + issubtitle=1; + default: break; } } @@ -301,9 +454,14 @@ int eDVBServicePMTHandler::getProgramInfo(struct program &program) isaudio = 1; audio.type = audioStream::atDTS; break; + case 0x2B: // TS_PSI_DT_MPEG2_AAC + isaudio = 1; + audio.type = audioStream::atAAC; // MPEG2-AAC + break; + case 0x1C: // TS_PSI_DT_MPEG4_Audio case AAC_DESCRIPTOR: isaudio = 1; - audio.type = audioStream::atAAC; + audio.type = audioStream::atAACHE; // MPEG4-AAC break; case AC3_DESCRIPTOR: isaudio = 1; @@ -311,69 +469,106 @@ int eDVBServicePMTHandler::getProgramInfo(struct program &program) break; case REGISTRATION_DESCRIPTOR: /* some services don't have a separate AC3 descriptor */ { - /* libdvbsi++ doesn't yet support this descriptor type, so work around. */ - if ((*desc)->getLength() != 4) - break; - unsigned char descr[6]; - (*desc)->writeToBuffer(descr); - int format_identifier = (descr[2] << 24) | (descr[3] << 16) | (descr[4] << 8) | (descr[5]); - switch (format_identifier) + RegistrationDescriptor *d = (RegistrationDescriptor*)(*desc); + switch (d->getFormatIdentifier()) { - case 0x41432d33: + case 0x44545331 ... 0x44545333: // DTS1/DTS2/DTS3 + isaudio = 1; + audio.type = audioStream::atDTS; + break; + case 0x41432d33: // == 'AC-3' isaudio = 1; audio.type = audioStream::atAC3; break; + case 0x42535344: // == 'BSSD' (LPCM) + isaudio = 1; + audio.type = audioStream::atLPCM; + break; + case 0x56432d31: // == 'VC-1' + { + const AdditionalIdentificationInfoVector *vec = d->getAdditionalIdentificationInfo(); + if (vec->size() > 1 && (*vec)[0] == 0x01) // subdescriptor tag + { + if ((*vec)[1] >= 0x90) // profile_level + video.type = videoStream::vtVC1; // advanced profile + else + video.type = videoStream::vtVC1_SM; // simple main + isvideo = 1; + } + } default: break; } break; } + case 0x28: // TS_PSI_DT_AVC + isvideo = 1; + video.type = videoStream::vtMPEG4_H264; + break; + case 0x1B: // TS_PSI_DT_MPEG4_Video + isvideo = 1; + video.type = videoStream::vtMPEG4_Part2; + break; default: break; } } switch (tag) { - case ISO_639_LANGUAGE_DESCRIPTOR: - if (!isvideo) + case ISO_639_LANGUAGE_DESCRIPTOR: + if (!isvideo) + { + int cnt=0; + const Iso639LanguageList *languages = ((Iso639LanguageDescriptor*)*desc)->getIso639Languages(); + /* use last language code */ + for (Iso639LanguageConstIterator i(languages->begin()); i != languages->end(); ++i, ++cnt) { - const Iso639LanguageList *languages = ((Iso639LanguageDescriptor*)*desc)->getIso639Languages(); - /* use last language code */ - for (Iso639LanguageConstIterator i(languages->begin()); i != languages->end(); ++i) + if (cnt == 0) audio.language_code = (*i)->getIso639LanguageCode(); + else + audio.language_code += "/" + (*i)->getIso639LanguageCode(); } - break; - case STREAM_IDENTIFIER_DESCRIPTOR: - audio.component_tag = - video.component_tag = - ((StreamIdentifierDescriptor*)*desc)->getComponentTag(); - break; - case CA_DESCRIPTOR: - { - CaDescriptor *descr = (CaDescriptor*)(*desc); - program.caids.insert(descr->getCaSystemId()); - break; } - default: - break; + break; + case STREAM_IDENTIFIER_DESCRIPTOR: + audio.component_tag = + video.component_tag = + ((StreamIdentifierDescriptor*)*desc)->getComponentTag(); + break; + case CA_DESCRIPTOR: + { + CaDescriptor *descr = (CaDescriptor*)(*desc); + program::capid_pair pair; + pair.caid = descr->getCaSystemId(); + pair.capid = descr->getCaPid(); + program.caids.push_back(pair); + break; + } + default: + break; } } + if (!num_descriptors && streamtype == 0x06 && prev_audio) + { + prev_audio->rdsPid = (*es)->getPid(); + eDebug("Rds PID %04x detected ? ! ?", prev_audio->rdsPid); + } + prev_audio = 0; + } + default: break; } - if (isaudio) + if (isteletext && (isaudio || isvideo)) { - audio.pid = (*es)->getPid(); - - /* if we find the cached pids, this will be our default stream */ - if (audio.pid == cached_apid_ac3 || audio.pid == cached_apid_mpeg) - program.defaultAudioStream = program.audioStreams.size(); - - /* also, we need to know the first non-mpeg (i.e. "ac3"/dts/...) stream */ - if ((audio.type != audioStream::atMPEG) && ((first_ac3 == -1) || (audio.pid == cached_apid_ac3))) - first_ac3 = program.audioStreams.size(); - - program.audioStreams.push_back(audio); + eDebug("ambiguous streamtype for PID %04x detected.. forced as teletext!", (*es)->getPid()); + continue; // continue with next PID } + else if (issubtitle && (isaudio || isvideo)) + eDebug("ambiguous streamtype for PID %04x detected.. forced as subtitle!", (*es)->getPid()); + else if (isaudio && isvideo) + eDebug("ambiguous streamtype for PID %04x detected.. forced as video!", (*es)->getPid()); + if (issubtitle) // continue with next PID + continue; else if (isvideo) { video.pid = (*es)->getPid(); @@ -385,22 +580,27 @@ int eDVBServicePMTHandler::getProgramInfo(struct program &program) else program.videoStreams.push_back(video); } - else - continue; - } - for (DescriptorConstIterator desc = pmt.getDescriptors()->begin(); - desc != pmt.getDescriptors()->end(); ++desc) - { - if ((*desc)->getTag() == CA_DESCRIPTOR) + else if (isaudio) { - CaDescriptor *descr = (CaDescriptor*)(*desc); - program.caids.insert(descr->getCaSystemId()); + audio.pid = (*es)->getPid(); + + /* if we find the cached pids, this will be our default stream */ + if (audio.pid == cached_apid_ac3 || audio.pid == cached_apid_mpeg) + program.defaultAudioStream = program.audioStreams.size(); + + /* also, we need to know the first non-mpeg (i.e. "ac3"/dts/...) stream */ + if ((audio.type != audioStream::atMPEG) && ((first_ac3 == -1) || (audio.pid == cached_apid_ac3))) + first_ac3 = program.audioStreams.size(); + + program.audioStreams.push_back(audio); + prev_audio = &program.audioStreams.back(); } + else + continue; } } ret = 0; - /* finally some fixup: if our default audio stream is an MPEG audio stream, and we have 'defaultac3' set, use the first available ac3 stream instead. (note: if an ac3 audio stream was selected before, this will be also stored @@ -437,6 +637,7 @@ int eDVBServicePMTHandler::getProgramInfo(struct program &program) audioStream s; s.type = audioStream::atAC3; s.pid = cached_apid_ac3; + s.rdsPid = -1; program.audioStreams.push_back(s); ++cnt; } @@ -445,6 +646,7 @@ int eDVBServicePMTHandler::getProgramInfo(struct program &program) audioStream s; s.type = audioStream::atMPEG; s.pid = cached_apid_mpeg; + s.rdsPid = -1; program.audioStreams.push_back(s); ++cnt; } @@ -459,8 +661,12 @@ int eDVBServicePMTHandler::getProgramInfo(struct program &program) program.textPid = cached_tpid; } CAID_LIST &caids = m_service->m_ca; - for (CAID_LIST::iterator it(caids.begin()); it != caids.end(); ++it) - program.caids.insert(*it); + for (CAID_LIST::iterator it(caids.begin()); it != caids.end(); ++it) { + program::capid_pair pair; + pair.caid = *it; + pair.capid = -1; // not known yet + program.caids.push_back(pair); + } if ( cnt ) ret = 0; } @@ -543,12 +749,21 @@ void eDVBServicePMTHandler::SDTScanEvent(int event) } } -int eDVBServicePMTHandler::tune(eServiceReferenceDVB &ref, int use_decode_demux, eCueSheet *cue, bool simulate) +int eDVBServicePMTHandler::tune(eServiceReferenceDVB &ref, int use_decode_demux, eCueSheet *cue, bool simulate, eDVBService *service) +{ + ePtr s; + return tuneExt(ref, use_decode_demux, s, NULL, cue, simulate, service); +} + +int eDVBServicePMTHandler::tuneExt(eServiceReferenceDVB &ref, int use_decode_demux, ePtr &source, const char *streaminfo_file, eCueSheet *cue, bool simulate, eDVBService *service) { RESULT res=0; m_reference = ref; - m_use_decode_demux = use_decode_demux; + m_no_pat_entry_delay->stop(); + + /* use given service as backup. This is used for timeshift where we want to clone the live stream using the cache, but in fact have a PVR channel */ + m_service = service; /* is this a normal (non PVR) channel? */ if (ref.path.empty()) @@ -567,16 +782,14 @@ int eDVBServicePMTHandler::tune(eServiceReferenceDVB &ref, int use_decode_demux, eDVBCIInterfaces::getInstance()->addPMTHandler(this); } else if (!simulate) // no simulation of playback services { - eDVBMetaParser parser; - - int ret=parser.parseFile(ref.path); - if (ret || !parser.m_ref.getServiceID().get() /* incorrect sid in meta file or recordings.epl*/ ) + if (!ref.getServiceID().get() /* incorrect sid in meta file or recordings.epl*/ ) { - eWarning("no .meta file found, trying to find PMT pid"); eDVBTSTools tstools; - if (tstools.openFile(ref.path.c_str())) - eWarning("failed to open file"); - else + bool b = source || !tstools.openFile(ref.path.c_str(), 1); + eWarning("no .meta file found, trying to find PMT pid"); + if (source) + tstools.setSource(source, NULL); + if (b) { int service_id, pmt_pid; if (!tstools.findPMT(pmt_pid, service_id)) @@ -586,9 +799,9 @@ int eDVBServicePMTHandler::tune(eServiceReferenceDVB &ref, int use_decode_demux, m_pmt_pid = pmt_pid; } } - } else - m_reference = parser.m_ref; - + else + eWarning("no valid source to find PMT pid!"); + } eDebug("alloc PVR"); /* allocate PVR */ res = m_resourceManager->allocatePVRChannel(m_pvr_channel); @@ -629,7 +842,10 @@ int eDVBServicePMTHandler::tune(eServiceReferenceDVB &ref, int use_decode_demux, if (m_pvr_channel) { m_pvr_channel->setCueSheet(cue); - m_pvr_channel->playFile(ref.path.c_str()); + if (source) + m_pvr_channel->playSource(source, streaminfo_file); + else + m_pvr_channel->playFile(ref.path.c_str()); } } @@ -1143,8 +1359,8 @@ void eDVBCAService::sendCAPMT() static PyObject *createTuple(int pid, const char *type) { PyObject *r = PyTuple_New(2); - PyTuple_SetItem(r, 0, PyInt_FromLong(pid)); - PyTuple_SetItem(r, 1, PyString_FromString(type)); + PyTuple_SET_ITEM(r, 0, PyInt_FromLong(pid)); + PyTuple_SET_ITEM(r, 1, PyString_FromString(type)); return r; } @@ -1154,17 +1370,18 @@ static inline void PyList_AppendSteal(PyObject *list, PyObject *item) Py_DECREF(item); } +extern void PutToDict(ePyObject &dict, const char*key, ePyObject item); // defined in dvb/frontend.cpp + PyObject *eDVBServicePMTHandler::program::createPythonObject() { - PyObject *r = PyDict_New(); + ePyObject r = PyDict_New(); + ePyObject l = PyList_New(0); - PyObject *l = PyList_New(0); - PyList_AppendSteal(l, createTuple(0, "pat")); if (pmtPid != -1) PyList_AppendSteal(l, createTuple(pmtPid, "pmt")); - + for (std::vector::const_iterator i(videoStreams.begin()); i != videoStreams.end(); ++i) @@ -1184,7 +1401,8 @@ PyObject *eDVBServicePMTHandler::program::createPythonObject() if (textPid != -1) PyList_AppendSteal(l, createTuple(textPid, "text")); - - PyDict_SetItemString(r, "pids", l); + + PutToDict(r, "pids", l); + return r; }