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

📄 audiohandler.h

📁 Linux下比较早的基于命令行的DVD播放器
💻 H
字号:
// Copyright (c) 2005 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_AUDIOHANDLER_H#define DXR3PLAYER_OUTPUT_AUDIOHANDLER_H//------------------------------------------------------------------------------#include "dvd/packet/TimedAudioPacket.h"#include "sched/Schedulable.h"#include "sched/WaitCondition.h"#include "util/Util.h"#include "util/Reference.h"#include "enums.h"//------------------------------------------------------------------------------namespace dvd { namespace packet {class PacketQueue;} /* namespace dvd::packet */ } /* namespace dvd *///------------------------------------------------------------------------------namespace output {//------------------------------------------------------------------------------class AudioDevice;class Timer;//------------------------------------------------------------------------------/** * Audio handler. */class AudioHandler : public sched::Schedulable{protected:    /**     * The buffer for filling gaps.     */    static const unsigned char gapBuffer[4096];    /**     * PTS tolerance for 20 milliseconds.     */    static const pts_t ptsTolerance = millis2PTS(20);    /**     * The number of milliseconds to prebuffer.     */    static const millis_t prebufferMillis = 100;    /**     * The minimal gap size to consider.     */    static const millis_t minGapMillis = 10;    /**     * The minimal number of milliseconds to allow to remain from the     * written data before starting to write a new block.     */    static const millis_t minPlayabaleMillis = 50;    /**     * The timer update interval.     */    static const ptsdiff_t timerUpdateInterval = 60 * Util::ptsFrequency;    /**     * Get the audio mode for the given encoding.     */    static audioMode_t getAudioMode(audioEncoding_t encoding);    /**     * The timer to use for timing.     */    Timer& timer;    /**     * The input queue.     */    dvd::packet::PacketQueue& inputQueue;    /**     * The current packet.     */    Reference<dvd::packet::TimedAudioPacket> currentPacket;    /**     * The audio device this player playes through.     */    AudioDevice& audioDevice;    /**     * Waiting condition for the audio handler to stop.     */    sched::WaitCondition audioStopped;        /**     * The start timestamp of the current data sequence. This is     * modified by the timer's PTS compensation, to be able to take     * into account future increases in the PTS compensation.     */    pts_t startPTS;    /**     * The number of samples written;     */    unsigned long long samplesWritten;    /**     * The end timestamp of the current data sequence.     */    pts_t endPTS;    /**     * The next PTS value after which we need to update the timer     * frequency.     */    pts_t updateTimerPTS;    /**     * Indicate that the interruption is for flushing the audio data.     */    bool toFlush;public:    /**     * Initialize the audio player.     */    AudioHandler(AudioDevice& audioDevice,                 output::Timer& timer,                  dvd::packet::PacketQueue& inputQueue);    /**     * @see sched::Schedulable::run     */    virtual void run();    /**     * Reset the audio handler.     */    void reset();    /**     * Flush the audio handler.     */    void flush();    /**     * Wait until the audio handler is stopped.     */    void waitStop();protected:    /**     * Set the audio format.     */    void setFormat(const AudioFormat& audioFormat);    /**     * Determine if the given audio format means a difference for the     * audio handler.     */    bool isDifferent(const AudioFormat& audioFormat) const;    /**     * Prebuffer the packets coming in.     */    void prebuffer();    /**     * Setup start timestamp if necessary from the given packet.     */    void setupStartPTS(Reference<dvd::packet::TimedAudioPacket> packet);    /**     * Start the playback of data. It performs the necessary timer     * compensation adjustments and/or waiting.     */    void startPlayback();         /**     * Play data until it arrives on time.     */    void play();    /**     * Finish the playback, i.e. do whatever there is needed to      * correctly finish the playback before stopping the audio device.     *     * This default implementation does nothing.     */    virtual void finish();    /**     * Calculate the gap size.     */    size_t calculateGapSize(Reference<dvd::packet::TimedAudioPacket> packet);    /**     * Update the value of the endPTS variable.     *     * @return if the timer frequency should be updated     */    bool updateEndPTS();    /**     * Write out the given packet.     */    void write(const unsigned char* buffer, size_t length, bool interruptible = true);    /**     * Write out a gap of the given size     */    void writeGap(size_t gapSize, bool interruptible = true);    /**     * Write the current packet. It nulls the current packet as well.     */    void writeCurrentPacket();    /**     * Get the size of a sample.     */    size_t getSampleSize() const;    /**     * Convert the given number of samples into bytes.     */    size_t samples2Bytes(size_t numSamples) const;    /**     * Convert the given PTS difference into number of samples.     */    size_t pts2Samples(pts_t diff) const;    /**     * Convert the given number of milliseconds into number of     *samples.     */    size_t millis2Samples(millis_t millis) const;    /**     * Convert the number of samples written into a PTS difference.     */    ptsdiff_t getPTSWritten() const;};//------------------------------------------------------------------------------} /* namespace output *///------------------------------------------------------------------------------#endif // DXR3PLAYER_OUTPUT_AUDIOHANDLER_H// Local Variables:// mode: C++// c-basic-offset: 4// indent-tabs-mode: nil// End:

⌨️ 快捷键说明

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