⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fulldvddump.cc

📁 Linux下比较早的基于命令行的DVD播放器
💻 CC
字号:
//// Copyright (c) 2004 by Istv醤 V醨adi//// This file is part of dxr3Player, a DVD player written specifically // for the DXR3 (aka Hollywood+) decoder card.// This program is free software; you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by// the Free Software Foundation; either version 2 of the License, or// (at your option) any later version.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the// GNU General Public License for more details.//// You should have received a copy of the GNU General Public License// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA//------------------------------------------------------------------------------#include "DVDDump.h"#include "FullDVDDump.h"#include "dvd/demux/Sector.h"#include "ifodump/IFOReader.h"#include "util/POSIX.h"#include "util/Log.h"#include <climits>#include <cstring>#include <cstdio>#include <unistd.h>#include <sys/types.h>#include <sys/stat.h>//------------------------------------------------------------------------------using dvd::FullDVDDump;using dvd::demux::SECTOR_SIZE;using ifodump::IFOReader;//------------------------------------------------------------------------------FullDVDDump::FileHandler::FileHandler(const char* dumpDirectory,                                       size_t vtsNumber, bool isMenu) :    fileNameTemplate(new char[PATH_MAX+1]),    chunkNumber(0),    fd(-1){    // FIXME: use the same routine as dvddump    sprintf(fileNameTemplate, "%s/vts%02u%s%%02u.dump", dumpDirectory,             vtsNumber, isMenu ? "m" : "");}//------------------------------------------------------------------------------FullDVDDump::FileHandler::~FileHandler(){    ::close(fd);    delete[] fileNameTemplate;}//------------------------------------------------------------------------------size_t FullDVDDump::FileHandler::getLength(){    // FIXME: we may need to make it meaningful    return 0;}//------------------------------------------------------------------------------void FullDVDDump::FileHandler::readSectors(void* dest, size_t offset,                                            size_t numSectors){    char* destination = reinterpret_cast<char*>(dest);    size_t endOffset = offset + numSectors;    while(offset<endOffset) {        size_t chunkNo = offset/chunkSize;        openChunk(chunkNo);        size_t chunkOffset = offset % chunkSize;        POSIX::lseek(fd, chunkOffset*SECTOR_SIZE, SEEK_SET, "Cannot seek in dump file");        size_t toRead = numSectors;        size_t chunkRemainder = chunkSize - chunkOffset;        if (toRead>chunkRemainder) toRead = chunkRemainder;                POSIX::read(fd, destination, toRead*SECTOR_SIZE);                offset += toRead;        numSectors -= toRead;        destination += toRead * SECTOR_SIZE;    }}   //------------------------------------------------------------------------------void FullDVDDump::FileHandler::openChunk(size_t chunkNo){    if (chunkNo==chunkNumber && fd>=0) return;    Log::debug("dvd::FullDVDDump::FileHandler::openChunk: chunkNo=%u\n",                chunkNo);    ::close(fd);    char fileName[PATH_MAX+1];    sprintf(fileName, fileNameTemplate, chunkNo);    fd = POSIX::open(fileName, O_RDONLY, "Cannot open dump file: %s", fileName);    chunkNumber = chunkNo;}//------------------------------------------------------------------------------//------------------------------------------------------------------------------const char* FullDVDDump::ifoDumpName = "ifo.dump";//------------------------------------------------------------------------------bool FullDVDDump::isDumpDirectory(const char* path){    struct stat statBuffer;    if (stat(path, &statBuffer)!=0) {        Log::debug("%s does not exist.\n", path);        return false;    }    bool isDumpDirectory =  S_ISDIR(statBuffer.st_mode);    if (!isDumpDirectory) {        Log::debug("%s is not a directory.\n", path);        return false;    }    char fileName[PATH_MAX+1];    sprintf(fileName, "%s/%s", path, ifoDumpName);        if (stat(fileName, &statBuffer)!=0 || !S_ISREG(statBuffer.st_mode)) {        Log::debug("Directory %s does not contain a DVD dump.\n", path);        return false;    }    Log::debug("Directory %s contains a DVD dump.\n", path);    return true;}//------------------------------------------------------------------------------FullDVDDump::FullDVDDump(const char* dumpDirectory) :    dumpDirectory(strdup(dumpDirectory)),    opened(false){    memset(ifoHandles, 0, sizeof(ifoHandles));    char ifoDumpFileName[PATH_MAX+1];    sprintf(ifoDumpFileName, "%s/%s", dumpDirectory, ifoDumpName);        FILE* ifoDump = fopen(ifoDumpFileName, "rb");    if (ifoDump==0) {        Log::fatal("Cannot open IFO dump file %s for reading!\n",                   ifoDumpFileName);        abort();    }        bool versioned = DVDDump::isVersioned(ifoDump);    IFOReader ifoReader(ifoDump, versioned);    unsigned version = ifoReader.getVersion();    if (version==0) Log::warning("dvd::FullDVDDump::FullDVDDump: dump is unversioned, may not work correctly!\n");    else Log::normal("dvd::FullDVDDump::FullDVDDump: dump is of version %u\n", version);    readIFO(ifoReader, 0);    size_t numVTs = ifoHandles[0].vmgi_mat->vmg_nr_of_title_sets;    for(size_t i = 1; i<=numVTs; ++i) {        readIFO(ifoReader, i);    }    fclose(ifoDump);}//------------------------------------------------------------------------------FullDVDDump::~FullDVDDump(){    free(dumpDirectory);}//------------------------------------------------------------------------------bool FullDVDDump::hasDisk(){    return true;}//------------------------------------------------------------------------------bool FullDVDDump::isOpen() const{    return opened;}    //------------------------------------------------------------------------------bool FullDVDDump::open(){    assert(!opened);    return opened = true;}//------------------------------------------------------------------------------void FullDVDDump::getID(unsigned char* dest) const{    memset(dest, 0, 16);}//------------------------------------------------------------------------------const ifo_handle_t* FullDVDDump::getIFOHandle(unsigned titleNo) const{    return &(ifoHandles[titleNo]);}    //------------------------------------------------------------------------------dvd::FileHandler* FullDVDDump::openFile(unsigned titleNo, bool isMenu) const{    Log::debug("dvd::FullDVDDump::openFile: titleNo=%u, isMenu: %d\n",                titleNo, isMenu);    return new FileHandler(dumpDirectory, titleNo, isMenu);}//------------------------------------------------------------------------------void FullDVDDump::close(){    assert(opened);    opened = false;}//------------------------------------------------------------------------------void FullDVDDump::eject(){    assert(!opened);}//------------------------------------------------------------------------------void FullDVDDump::readIFO(IFOReader& reader, size_t ifoIndex){    ifo_handle_t& ifoHandle = ifoHandles[ifoIndex];    if (ifoIndex==0) {        reader.readVMG(&ifoHandle);    } else {        reader.readVTS(&ifoHandle);    }}//------------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -