📄 control.cc
字号:
{ if (isInterrupted()) return; DemultiplexerParameterPacket* packet = new DemultiplexerParameterPacket(); processorHandler.getDemultiplexerParameters(packet->parameters); outputQueue.put(packet);}//------------------------------------------------------------------------------void Control::insertProcessorUpdatingPacket(bool atEndPresentation){ if (isInterrupted()) return; size_t commandID = processorHandler.getLastCommandID();; if (commandID==ProcessorCommand::INVALID_ID) return; pts_t timestamp = atEndPresentation ? pci.getEndPresentation() : pci.getStartPresentation(); ProcessorUpdatePacket* packet = new ProcessorUpdatePacket(commandID, timestamp); outputQueue.put(packet);}//------------------------------------------------------------------------------bool Control::startNextVOBU(){ switch(playMode) { case FORWARD: case FAST_FORWARD_1: case FAST_FORWARD_2: case FAST_FORWARD_3: return startSucceedingVOBU(); break; case FAST_BACKWARD_1: case FAST_BACKWARD_2: case FAST_BACKWARD_3: return startPrecedingVOBU(); break; case PAUSED: return false; break; } return false;}//------------------------------------------------------------------------------bool Control::startSucceedingVOBU(){ assert(!isInterrupted()); size_t sectorNo; if (getNextVOBUSector(sectorNo)) { processorHandler.setSectorNumber(sectorNo); } else { unsigned stillTime = 0; bool wasNextCell = processorHandler.nextCell(stillTime); if (processorHandler.getPosition().atExit()) { insertProcessorUpdatingPacket(true); return false; } if (stillTime>0) { Log::debug("dvd::reader::Control::startSucceedingVOBU: still time: %u\n", stillTime); outputQueue.put(new StillPacket(stillTime)); if (isInterrupted()) return true; if (stillTime==PGC::infiniteStillTime) { outputQueue.flush(); Scheduler::sleepInterruptible("dvd::reader::Control::startSucceedingVOBU"); if (isInterrupted()) return true; } } insertCellPackets(); if (isInterrupted()) return true; if (!wasNextCell && playMode!=FORWARD) { playMode = FORWARD; outputQueue.put(new PlayModePacket(playMode)); } } return true;}//------------------------------------------------------------------------------bool Control::startPrecedingVOBU(){ size_t sectorNo; if (getPreviousVOBUSector(sectorNo)) { processorHandler.setSectorNumber(sectorNo); } else { bool wasPreviousCell = processorHandler.previousCell(); insertCellPackets(); if (!wasPreviousCell) { playMode = FORWARD; outputQueue.put(new PlayModePacket(playMode)); } } return true;}//------------------------------------------------------------------------------void Control::discardReadSectors(){ Sector* sector = thread.getReadDestination(); size_t numSectors = thread.discardRead(); buffer.discardRead(sector, numSectors);}//------------------------------------------------------------------------------void Control::makeReadSectorsAvailable(size_t numSectors){ Sector* sector = thread.getReadDestination(); numSectors = thread.discardRead(numSectors); buffer.makeAvailable(outputQueue, sector, numSectors);}//------------------------------------------------------------------------------void Control::openDVD(){ while(!thread.getDVD().isOpen() && !isInterrupted()) { if (listener!=0) listener->tryingDVD(); while(!thread.check() && !isInterrupted()) { Log::debug("Checking for DVD\n"); Scheduler::sleepInterruptible("dvd::reader::Control::openDVD", Util::currentTimeMillis()+500); } if (!isInterrupted()) { if (listener!=0) listener->decodingDVD(); Log::debug("Trying to open DVD\n"); thread.open(); } }}//------------------------------------------------------------------------------bool Control::readDVD(){ bool firstVOBU = true; processorHandler.resetProcessor(); playMode = FORWARD; while(!isInterrupted()) { processVOBU(firstVOBU); firstVOBU = false; if (!isInterrupted()) { bool hasNextVOBU = startNextVOBU(); if (!hasNextVOBU) return false; } if (isInterrupted()) { if (toBranch || toPause) { clearInterrupt(); if (toPause) { Scheduler::sleepInterruptible("dvd::reader::Control::readDVD"); if (shouldQuit()) break; clearInterrupt(); toPause = false; } else { toBranch = false; } outputQueue.put(new PlayModePacket(playMode)); insertCellPackets(); } } } return true;}//------------------------------------------------------------------------------void Control::insertCellPackets(){ insertAVAttributesPacket(); if (isInterrupted()) return; insertSPUPalettePacket(); if (isInterrupted()) return;}//------------------------------------------------------------------------------void Control::processVOBU(bool isFirst){ insertDemultiplexerParameterPacket(); if (isInterrupted()) return; Sector* sector = readNAV(); if (sector==0) return; if (isFirst || stateChanged) { if (listener!=0 && isFirst) listener->playingDVD(); if (stateChanged) { insertAVAttributesPacket(); } else { insertCellPackets(); } } processNAV(sector); size_t offset = 0; size_t vobuLength = getVOBULength(); while(offset<getVOBULength() && !isInterrupted()) { size_t numSectors = vobuLength - offset; sector = readVOBU(offset, numSectors); if (sector==0) break; makeReadSectorsAvailable(numSectors); offset += numSectors; }}//------------------------------------------------------------------------------Sector* Control::readNAV(){ size_t numSectors = 1; Sector* sector = buffer.requestForReading(numSectors); if (sector==0) return 0; assert(numSectors==1); return readSectors(sector, 0, 1);}//------------------------------------------------------------------------------void Control::processNAV(const Sector* sector){ pci.set(*sector); dsi.set(*sector); checkPlayMode(); if (isInterrupted()) return; makeReadSectorsAvailable(1); if (isInterrupted()) return; insertProcessorUpdatingPacket(); if (isInterrupted()) return; checkHighlight();}//------------------------------------------------------------------------------bool Control::checkPlayMode(){ if (!processorHandler.getPosition().isPlayModeAllowed(playMode)) { playMode = FORWARD; return outputQueue.put(new PlayModePacket(playMode)); } return true;}//------------------------------------------------------------------------------void Control::checkHighlight(){ GeneralHighlightInformation general = pci.getHighlightInformation().getGeneral(); if (general.getStatus()!=GeneralHighlightInformation::NEW) return; size_t buttonNo = general.getForcedSelectedButtonNumber(); if (buttonNo<=0) return; processorHandler.setHighlightedButtonNumber(buttonNo); insertProcessorUpdatingPacket();}//------------------------------------------------------------------------------Sector* Control::readVOBU(size_t offset, size_t& numSectors){ Sector* sector = buffer.requestForReading(numSectors); if (sector==0) return 0; assert(numSectors>0); return readSectors(sector, offset + 1, numSectors);}//------------------------------------------------------------------------------Sector* Control::readSectors(Sector* firstSector, size_t sectorOffset, size_t numSectors){ const Position& position = processorHandler.getPosition(); assert(position.getCellNumber()>0); SectorPosition source(position); source.setSectorNumber(source.getSectorNumber() + sectorOffset); thread.read(firstSector, source, numSectors); if (isInterrupted()) { thread.discardRead(); buffer.discardRead(firstSector, numSectors); firstSector = 0; } return firstSector;}//------------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -