📄 mpegaudiodecoder.h
字号:
//// Copyright (c) 2003 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 DXR3PLAYER_OUTPUT_MPEGAUDIODECODER_H#define DXR3PLAYER_OUTPUT_MPEGAUDIODECODER_H//------------------------------------------------------------------------------#include "AudioDecoder.h"#include "util/AudioFormat.h"#include <cstdlib>#include <mad.h>//------------------------------------------------------------------------------namespace output {//------------------------------------------------------------------------------/** * MPEG audio decoder using MAD. * FIXME: this should be unified with AC3Decoder. */class MPEGAudioDecoder : public AudioDecoder{private: /** * The type of the samples. */ typedef unsigned short sampleType; /** * The size of a stereo sample */ static const size_t sampleSize = sizeof(sampleType) * 2; /** * The size of the frame buffer. */ static const size_t frameBufferSize = 4096; /** * The maximal number of output samples. */ static const size_t maxOutputSamples = 1152; /** * The table for bitrates. * * The first index is for the MPEG versions: 0 -> MPEG 2.5, 1 -> MPEG 1 * and 2. * The second index is for the layers: 0 -> III, 1 -> II, 2 -> I * The third index is the bitrate index */ static const size_t bitrateTable[2][3][16]; /** * The table for sample rates. * * The index is the sample rate index as found in the frame * header. The value is the sample rate for MPEG 2.5. It should be * multiplied by 2 for MPEG 2 and 4 for MPEG 1. */ static const size_t sampleRateTable[3]; /** * Convert the given sample to our sample type. */ static sampleType convertSample(mad_fixed_t sample);private: /** * Buffer for frame data. */ unsigned char frameBuffer[frameBufferSize]; /** * The offset of the next byte to be received from the frame. */ size_t frameOffset; /** * The frame length; */ size_t frameLength; /** * The MAD stream. */ mad_stream madStream; /** * The MAD frame. */ mad_frame madFrame; /** * The MAD synth structure */ mad_synth madSynth;public: /** * Construct the MPEG audio decoder. * * FIXME: remove the default value */ MPEGAudioDecoder(AudioProcessor* audioProcessor); /** * Reset the decoder. */ virtual void reset(); /** * @see AudioDecoder::decodePacket */ virtual void decodePacket(const unsigned char* data, size_t length, pts_t packetPTS);private: /** * Determine if the decoder is empty. */ bool isEmpty() const; /** * Decode the given data * * @param data the start of the data. Will be moved to the end of * the processed data. * * @return true, if a frame has been decoded, false otherwise. */ bool decode(const unsigned char*& data, const unsigned char* end); /** * Get the length of a frame. It should be called when the 4 * header bytes are available in the frame buffer. It also filles * the sample rate in the format structure. */ size_t getFrameLength(); /** * Copy the data from the given address into the frame buffer, * until the given target offset is reached. */ void copy(const unsigned char*& data, const unsigned char* end, size_t targetOffset); /** * Decode the frame from the buffer. * * @return if the decoding was successful. */ bool decodeFrame(); /** * Synthesize the frame into the output buffer. */ void synthesizeFrame();};//------------------------------------------------------------------------------} /* namespace output *///------------------------------------------------------------------------------#endif // DXR3PLAYER_OUTPUT_MPEGAUDIODECODER_H// Local variables:// mode: c++// End:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -