File indexing completed on 2024-06-16 04:38:28
0001 /* 0002 SPDX-FileCopyrightText: 2003 Fabrice Bellard 0003 SPDX-FileCopyrightText: 2020-2022 Mladen Milinkovic <max@smoothware.net> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #ifndef AUDIODECODER_H 0009 #define AUDIODECODER_H 0010 0011 #include "videoplayer/backend/decoder.h" 0012 #include <AL/alc.h> 0013 0014 0015 struct SwrContext; 0016 0017 namespace SubtitleComposer { 0018 class VideoState; 0019 struct Frame; 0020 0021 class AudioDecoder : public Decoder 0022 { 0023 Q_OBJECT 0024 0025 public: 0026 AudioDecoder(VideoState *state, QObject *parent = nullptr); 0027 0028 void destroy() override; 0029 void abort() override; 0030 0031 void setListenerGain(double gain); 0032 double pitch() const; 0033 void setPitch(double pitch); 0034 0035 private: 0036 void run() override; 0037 0038 struct Params { 0039 int freq; 0040 int channels; 0041 uint64_t channelLayout; 0042 AVSampleFormat fmt; 0043 int frameSize; 0044 int bytesPerSec; 0045 }; 0046 0047 int decodeFrame(Frame *af); 0048 int getFrame(AVFrame *frame); 0049 void queueFrame(Frame *af); 0050 void queueBuffer(uint8_t *data, int len); 0051 int syncAudio(int nbSamples); 0052 0053 bool open(int64_t wanted_channel_layout, int wanted_nb_channels, int wanted_sample_rate); 0054 void close(); 0055 void flush(); 0056 void play(); 0057 void pause(); 0058 0059 VideoState *m_vs; 0060 0061 Params m_fmtSrc; 0062 Params m_fmtTgt; 0063 SwrContext *m_swrCtx; 0064 int m_hwBufQueueSize; // in bytes 0065 uint8_t *m_audioBuf; 0066 unsigned int m_bufSize; // in bytes 0067 uint8_t *m_audioBuf1; 0068 unsigned int m_buf1Size; 0069 0070 double m_diffCum; /* used for AV difference average computation */ 0071 double m_diffAvgCoef; 0072 int m_diffAvgCount; 0073 0074 ALCdevice *m_alDev; 0075 ALCcontext *m_alCtx; 0076 unsigned int m_alSrc; 0077 int m_bufCnt; 0078 int m_bufFmt; 0079 0080 friend class StreamDemuxer; 0081 }; 0082 } 0083 0084 #endif // AUDIODECODER_H