📄 audioprocessor.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 "AudioProcessor.h"#include "AudioDecoder.h"#include "AC3Decoder.h"#include "LPCMDecoder.h"#include "DTSDecoder.h"#ifdef USE_MPEG_AUDIO#include "MPEGAudioDecoder.h"#endif#include "dvd/packet/TimedDataBlockPacket.h"#include "dvd/packet/DataBlockType.h"#include "dvd/packet/DataBlockTypes.h"#include "sched/Scheduler.h"#include "util/Config.h"//------------------------------------------------------------------------------using output::AudioProcessor;using output::AC3Decoder;using dvd::packet::PacketQueue;using dvd::packet::TimedDataBlockPacket;using dvd::packet::TimedPacketTemplate;using dvd::packet::TimedAudioPacket;using dvd::packet::DataBlockType;using dvd::packet::DataBlockTypes;using sched::Scheduler;//------------------------------------------------------------------------------//------------------------------------------------------------------------------inline void AudioProcessor::DecoderInfo::set(const DataBlockType& t, AudioDecoder* d){ type = &t; decoder = d;}//------------------------------------------------------------------------------//------------------------------------------------------------------------------AudioProcessor::Packet::Packet(AudioProcessor& audioProcessor) : TimedPacketTemplate<TimedAudioPacket>(DataBlockTypes::audio, audioProcessor.outputFormat, audioProcessor.outputPTS), audioProcessor(audioProcessor){} //------------------------------------------------------------------------------AudioProcessor::Packet::~Packet(){ audioProcessor.packetProcessed();}//------------------------------------------------------------------------------const unsigned char* AudioProcessor::Packet::getData() const{ return audioProcessor.outputBuffer;}//------------------------------------------------------------------------------size_t AudioProcessor::Packet::getLength() const{ return audioProcessor.outputLength;}//------------------------------------------------------------------------------//------------------------------------------------------------------------------inline AC3Decoder& AudioProcessor::getAC3Decoder() const{ return static_cast<AC3Decoder&>(*(decoders[0].decoder));}//------------------------------------------------------------------------------//------------------------------------------------------------------------------AudioProcessor::AudioProcessor(PacketQueue& inputQueue, PacketQueue& outputQueue) : Schedulable("output::AudioProcessor"), inputQueue(inputQueue), outputQueue(outputQueue), outputBuffer(new unsigned char[outputBufferSize]), outputPTS(INVALID_PTS), outputLength(0), processedPacket("output::AudioProcessor", "processedPacket"){ decoders[0].set(DataBlockTypes::ac3Audio, new AC3Decoder(this)); decoders[1].set(DataBlockTypes::lpcmAudio, new LPCMDecoder(this)); decoders[2].set(DataBlockTypes::dtsAudio, new DTSDecoder(this));#ifdef USE_MPEG_AUDIO decoders[3].set(DataBlockTypes::mpegAudio, new MPEGAudioDecoder(this));#endif}//------------------------------------------------------------------------------AudioProcessor::~AudioProcessor(){ delete[] outputBuffer;}//------------------------------------------------------------------------------void AudioProcessor::run(){ while(!shouldQuit()) { clearInterrupt(); Reference<dvd::packet::Packet> p = inputQueue.get(); Reference<TimedDataBlockPacket> packet = TimedDataBlockPacket::convert(p); if (packet.isValid()) { processTimedDataBlockPacket(packet); } if (isInterrupted()) { outputPTS = INVALID_PTS; } }}//------------------------------------------------------------------------------void AudioProcessor::reset(){ outputQueue.reset(); for(size_t i = 0; i<numberOfDecoders; ++i) { decoders[i].decoder->reset(); } interrupt();}//------------------------------------------------------------------------------unsigned AudioProcessor::volumeReset(){ unsigned defaultVolume = Config::get().defaultVolume; getAC3Decoder().setOutputLevel(defaultVolume); return defaultVolume;} //------------------------------------------------------------------------------unsigned AudioProcessor::volumeUp(){ AC3Decoder& decoder = getAC3Decoder(); unsigned level = decoder.getOutputLevel() ; if (level<=95) level += 5; else level = 100; decoder.setOutputLevel(level); return level;}//------------------------------------------------------------------------------unsigned AudioProcessor::volumeDown(){ AC3Decoder& decoder = getAC3Decoder(); unsigned level = decoder.getOutputLevel(); if (level>=5) level -= 5; else level = 0; decoder.setOutputLevel(level); return level;}//------------------------------------------------------------------------------unsigned AudioProcessor::getVolume() const{ return getAC3Decoder().getOutputLevel();}//------------------------------------------------------------------------------bool AudioProcessor::toggleAudio(){ return getAC3Decoder().toggleAudio();}//------------------------------------------------------------------------------void AudioProcessor::outputPacket(){ outputQueue.put(new Packet(*this)); if (!isInterrupted()) { Scheduler::waitInterruptible(processedPacket); }}//------------------------------------------------------------------------------void AudioProcessor::processTimedDataBlockPacket(Reference<TimedDataBlockPacket> packet){ const DataBlockType& type = packet->getType(); AudioDecoder* decoder = 0; for(size_t i = 0; i<numberOfDecoders && decoder==0; ++i) { if (*(decoders[i].type)==type) { decoder = decoders[i].decoder; } } if (decoder!=0) { decoder->decodePacket(packet->getData(), packet->getLength(), packet->getPTS()); } else { Log::debug("output::AudioProcessor::processTimedDataBlockPacket: unhandled packet of type %s\n", type.name); }}//------------------------------------------------------------------------------void AudioProcessor::packetProcessed(){ processedPacket.set();}//------------------------------------------------------------------------------//------------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -