📄 audioprocessor.h
字号:
//// 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#ifndef OUTPUT_AUDIOPROCESSOR_H#define OUTPUT_AUDIOPROCESSOR_H//------------------------------------------------------------------------------#include "config.h"#include "dvd/packet/PacketQueue.h"#include "dvd/packet/TimedPacketTemplate.h"#include "dvd/packet/TimedAudioPacket.h"#include "sched/Schedulable.h"#include "util/Reference.h"#include "util/AudioFormat.h"//------------------------------------------------------------------------------namespace dvd { namespace packet {class DataBlockType;class TimedDataBlockPacket;} }//------------------------------------------------------------------------------namespace output {//------------------------------------------------------------------------------class AudioDecoder;class AC3Decoder;//------------------------------------------------------------------------------/** * Class to process audio data. It decodes packets based on their * type, and outputs them to the output queue. */class AudioProcessor : public sched::Schedulable{private: /** * Type for a pair of associated data block type and audio * decoder. */ struct DecoderInfo { /// The data block type const dvd::packet::DataBlockType* type; /// The audio decoder. AudioDecoder* decoder; /// Initialize the structure. DecoderInfo() : type(0), decoder(0) {} /// Set the info void set(const dvd::packet::DataBlockType& t, AudioDecoder* d); }; /** * Our own data packet that references the our output buffer. */ class Packet : public dvd::packet::TimedPacketTemplate< dvd::packet::TimedAudioPacket > { private: /** * The audio processor this packet belongs to. */ AudioProcessor& audioProcessor; public: /** * Construct the processor packet. */ Packet(AudioProcessor& audioProcessor); /** * Destroy the packet by notifying the processor. */ virtual ~Packet(); /** * @see dvd::packet::DataBlockPacket::getData */ virtual const unsigned char* getData() const; /** * @see dvd::packet::DataBlockPacket::getLength */ virtual size_t getLength() const; }; friend class Packet; /** * The number of decoders. We currently support: AC-3, LPCM and * optionally MPEG. */#ifdef USE_MPEG_AUDIO static const size_t numberOfDecoders = 4;#else static const size_t numberOfDecoders = 3;#endif /** * The size of the output buffer. This should be enough for all * decoders we support. */ static const size_t outputBufferSize = 8192; /** * The input queue. */ dvd::packet::PacketQueue& inputQueue; /** * The output queue. */ dvd::packet::PacketQueue& outputQueue; /** * Type and decoder mapping. */ DecoderInfo decoders[numberOfDecoders]; /** * The output buffer. */ unsigned char* outputBuffer; /** * The output PTS. It should be set to the PTS value of the data * in the output buffer. */ pts_t outputPTS; /** * The length of the output. */ size_t outputLength; /** * The format of the output. */ AudioFormat outputFormat; /** * The wait condition of the packet being processed. */ sched::WaitCondition processedPacket;public: /** * Construct the audio processor. */ AudioProcessor(dvd::packet::PacketQueue& inputQueue, dvd::packet::PacketQueue& outputQueue); /** * Destroy the audio processor. */ ~AudioProcessor(); /** * @see sched::Schedulable::run */ virtual void run(); /** * Reset the processor. */ void reset(); /** * Reset the volume to some default value. It works only for AC-3 streams. * * @return the new volume (a value between 0 and 100). */ unsigned volumeReset(); /** * Increase the volume. It works only for AC-3 streams. * * @return the new volume (a value between 0 and 100). */ unsigned volumeUp(); /** * Decrease the volume. It works only for AC-3 streams. * * @return the new volume (a value between 0 and 100). */ unsigned volumeDown(); /** * Get the volume. It works only for AC-3 streams. */ unsigned getVolume() const; /** * Mute/unmute audio. It works only for AC-3 streams. * * @return true if the audio was enabled as a result of this call. */ bool toggleAudio(); /** * Get the output buffer. */ unsigned char* getOutputBuffer(); /** * Set the output length. */ void setOutputLength(size_t length); /** * Set the output PTS. */ void setOutputPTS(pts_t pts); /** * Transfer the PTS value from the given variable to the output * PTS. The variable will be reset to INVALID_PTS. */ void transferPTS(pts_t& pts); /** * Get the output format. */ AudioFormat& getOutputFormat(); /** * Set the output format. */ void setOutputFormat(const AudioFormat& format); /** * Output the packet. Data should be in the outputBuffer with the * output length, PTS and format setup correctly. */ void outputPacket();private: /** * Process a timed data block packet. Search for the decoder associated * with its type, and pass the data to it. */ void processTimedDataBlockPacket(Reference<dvd::packet::TimedDataBlockPacket> packet); /** * Callback function for our own packet to be called when it is * deleted, i.e. all data in the decoder has been processed. */ void packetProcessed(); /** * Get the AC-3 decoder. */ AC3Decoder& getAC3Decoder() const;};//------------------------------------------------------------------------------// Inline definitions//------------------------------------------------------------------------------inline unsigned char* AudioProcessor::getOutputBuffer(){ return outputBuffer;}//------------------------------------------------------------------------------inline void AudioProcessor::setOutputLength(size_t length){ outputLength = length;}//------------------------------------------------------------------------------inline void AudioProcessor::setOutputPTS(pts_t pts){ outputPTS = pts;}//------------------------------------------------------------------------------inline void AudioProcessor::transferPTS(pts_t& pts){ outputPTS = pts; pts = INVALID_PTS;}//------------------------------------------------------------------------------inline AudioFormat& AudioProcessor::getOutputFormat(){ return outputFormat;}//------------------------------------------------------------------------------inline void AudioProcessor::setOutputFormat(const AudioFormat& format){ outputFormat = format;}//------------------------------------------------------------------------------} /* namespace output *///------------------------------------------------------------------------------#endif // OUTPUT_AUDIOPROCESSOR_H// Local variables:// mode: c++// End:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -