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

📄 mpegdecoder.cc

📁 Linux下比较早的基于命令行的DVD播放器
💻 CC
📖 第 1 页 / 共 2 页
字号:
//// 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, but now handles other// hardware as well. These files contain a (mostly) user-space driver // for the Unichrome board found on Via's EPIA motherboards.//// The information for implementing this driver has been gathered// from the following sources://// - The DirectFB Unichrome driver//   Copyright (c) 2003 Andreas Robinson, All rights reserved.//// - Andreas Robinson's MPEG-2 decoder for the Unichrome board.//   Copyright (c) 2003 Andreas Robinson, All rights reserved.//// - Via's Unichrome Framebuffer driver//   Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.//   Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.// 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 "MPEGDecoder.h"#include "Unichrome.h"#include "Register.h"#include "Constant.h"#include "sched/Scheduler.h"#include "util/Log.h"#include "util/Util.h"#include <cassert>//#include <cstring>//------------------------------------------------------------------------------using unichrome::MPEGDecoder;using sched::Scheduler;using mpeg::SequenceHeader;using mpeg::PictureHeader;using mpeg::QuantMatrix;//------------------------------------------------------------------------------const unsigned char MPEGDecoder::defaultIntraQMX[64] = {     8, 16, 16, 19, 16, 19, 22, 22,    22, 22, 22, 22, 26, 24, 26, 27,    27, 27, 26, 26, 26, 26, 27, 27,    27, 29, 29, 29, 34, 34, 34, 29,    29, 29, 27, 27, 29, 29, 32, 32,    34, 34, 37, 38, 37, 35, 35, 34,    35, 38, 38, 40, 40, 40, 48, 48,    46, 46, 56, 56, 58, 69, 69, 83};//------------------------------------------------------------------------------const size_t MPEGDecoder::quantMatrixScan[64] = {     0,  1,  5,  6, 14, 15, 27, 28,     2,  4,  7, 13, 16, 26, 29, 42,     3,  8, 12, 17, 25, 30, 41, 43,     9, 11, 18, 24, 31, 40, 44, 53,     10, 19, 23, 32, 39, 45, 52, 54,    20, 22, 33, 38, 46, 51, 55, 60,    21, 34, 37, 47, 50, 56, 59, 61,    35, 36, 48, 49, 57, 58, 62, 63};//------------------------------------------------------------------------------const QuantMatrix& MPEGDecoder::getDefaultQuantMatrix(){    static bool initialized = false;    static QuantMatrix defaultQuantMatrix;    if (!initialized) {        memcpy(defaultQuantMatrix.intraQMX, defaultIntraQMX, sizeof(defaultIntraQMX));        defaultQuantMatrix.loadIntraQMX = true;        memset(defaultQuantMatrix.nonIntraQMX, 16, sizeof(defaultQuantMatrix.nonIntraQMX));        defaultQuantMatrix.loadNonIntraQMX = true;        memcpy(defaultQuantMatrix.chromaIntraQMX, defaultIntraQMX, sizeof(defaultIntraQMX));        defaultQuantMatrix.loadChromaIntraQMX = true;        defaultQuantMatrix.loadChromaNonIntraQMX = true;        memset(defaultQuantMatrix.chromaNonIntraQMX, 16, sizeof(defaultQuantMatrix.nonIntraQMX));        initialized = true;    }    return defaultQuantMatrix;}//------------------------------------------------------------------------------//------------------------------------------------------------------------------MPEGDecoder::PictureInfo::PictureInfo(){    reset();}//------------------------------------------------------------------------------void MPEGDecoder::PictureInfo::setup(const SequenceHeader& sequenceHeader,                                     const PictureHeader& pictureHeader,                                     pts_t& packetPTS){    codingType = pictureHeader.codingType;    if (codingType==PictureHeader::CODING_I) {        pts = packetPTS;        packetPTS = INVALID_PTS;    } else {        pts = INVALID_PTS;    }    if (sequenceHeader.progressive) {        numFields = pictureHeader.repeatFirstField ?             (pictureHeader.topFieldFirst ? 6 : 4) : 2;    } else {        numFields = pictureHeader.repeatFirstField ? 3 : 2;    }//     if (numFields!=2) {//         Log::debug("unichrome::MPEGDecoder::PictureInfo::setup: numFields=%u\n", numFields);//     }}//------------------------------------------------------------------------------void MPEGDecoder::PictureInfo::reset(){    codingType = PictureHeader::CODING_UNKNOWN;    numFields = 0;    pts = INVALID_PTS;}//------------------------------------------------------------------------------//------------------------------------------------------------------------------inline bool MPEGDecoder::isBusy(){    return (unichrome.io.reg(Register::MPEG_STATUS)&0x27f)!=0x204;}//------------------------------------------------------------------------------//------------------------------------------------------------------------------MPEGDecoder::MPEGDecoder(Unichrome& unichrome) :    unichrome(unichrome),    aspectRatio(AR_4_3),    sequenceAspectRatio(AR_4_3),    sequenceQuantMatrixLoaded(false),    isSecondField(true),    pictureOffset(0),    packetPTS(INVALID_PTS),    playIntra(false),    processSlice(false){    sequenceHeader.horizontalSize = 0;    sequenceHeader.verticalSize = 0;    reset();}//------------------------------------------------------------------------------void MPEGDecoder::reset(){    for(size_t i = 0; i<14; ++i) {        unichrome.io.reg(Register::MPEG_REGISTER1) = 0x00;    }    unichrome.io.reg(Register::MPEG_FCODE) = 0x400000;    for(size_t i = 0; i<6; ++i) {        unichrome.io.reg(Register::MPEG_REGISTER2) = 0x43;        for(size_t j = 0x10; j<0x20; j+=4) {            unichrome.io.reg(Register::MPEG_BASE + j) = 0;        }    }    unichrome.io.reg(Register::MPEG_REGISTER2) = 0xc3;    for(size_t j = 0x10; j<0x20; j+=4) {        unichrome.io.reg(Register::MPEG_BASE + j) = 0;    }        while( isBusy() );    setQuantMatrix(getDefaultQuantMatrix());    displayBuffer = INVALID_BUFFER;    flush();}//------------------------------------------------------------------------------void MPEGDecoder::flush(){    isSecondField = true;    bwRefBuffer = 0;    fwRefBuffer = 1;    bBuffer = 2;    idleBuffer = 3;    displayInfo.reset();    pendingIP = INVALID_BUFFER;    pendingInfo.reset();    packetPTS = INVALID_PTS;    playIntra = false;}//------------------------------------------------------------------------------void MPEGDecoder::setAspectRatio(aspectRatio_t ar){    aspectRatio = ar;}//------------------------------------------------------------------------------void MPEGDecoder::setPlayIntra(bool x){    playIntra = x;}//------------------------------------------------------------------------------void MPEGDecoder::setPTS(pts_t pts){    packetPTS = pts;}//------------------------------------------------------------------------------void MPEGDecoder::startSequence(const SequenceHeader& header){    size_t horizontalSize = (header.horizontalSize+31)&(~31);    size_t sequenceHorizontalSize = (sequenceHeader.horizontalSize+31)&(~31);    if (horizontalSize!=sequenceHorizontalSize ||        header.verticalSize!=sequenceHeader.verticalSize ||        aspectRatio!=sequenceAspectRatio)    {        assert(header.chromaFormat==SequenceHeader::CHROMA_4_2_0);        size_t sourceHorizontalSize = horizontalSize;        size_t sourceVerticalSize = header.verticalSize;        if (aspectRatio==AR_16_9) {            sourceVerticalSize = sourceHorizontalSize;        }        size_t outputWidth, outputHeight;        unichrome.getOutputSize(outputWidth, outputHeight);                size_t baseOffset =            unichrome.setupV1(sourceHorizontalSize, sourceVerticalSize,                              header.horizontalSize, sourceVerticalSize,                              0, 0, outputWidth, outputHeight);        unichrome.io.reg(Register::MPEG_STRIDE) =             (horizontalSize>>3) |            ((horizontalSize>>4)<<16);     // UV stride        size_t lumaSize = sourceHorizontalSize * sourceVerticalSize;        size_t chromaSize = lumaSize / 4;        size_t frameSize = lumaSize + 2 * chromaSize;        pictureOffset = ((sourceVerticalSize - header.verticalSize)/2) * sourceHorizontalSize;        for(size_t i = 0; i<4; ++i) {            size_t yOffset  = baseOffset + frameSize * i;

⌨️ 快捷键说明

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