1 /***************************************************************************
2  *   Copyright (C) 2017-2021 by Ilya Kotov                                 *
3  *   forkotov02@ya.ru                                                      *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
19  ***************************************************************************/
20 
21 #ifndef SHOUTOUTPUT_H
22 #define SHOUTOUTPUT_H
23 
24 #include <vorbis/vorbisenc.h>
25 #include <soxr.h>
26 #include <qmmp/output.h>
27 #include "shoutclient.h"
28 
29 class ShoutOutput : public Output
30 {
31 public:
32     explicit ShoutOutput(ShoutClient *m);
33     ~ShoutOutput();
34 
35     bool initialize(quint32 freq, ChannelMap map, Qmmp::AudioFormat) override;
36     qint64 latency() override;
37     qint64 writeAudio(unsigned char *data, qint64 maxSize) override;
38     void drain() override;
39     void reset() override;
40     void setTrackInfo(const TrackInfo &info) override;
41 
42 private:
43     void sendHeader();
44     ShoutClient *m_client;
45     ogg_stream_state m_os; //take physical pages, weld into a logical stream of packets
46     ogg_page         m_og; //one Ogg bitstream page.  Vorbis packets are inside */
47     ogg_packet       m_op; //one raw packet of data for decode
48     vorbis_info      m_vi; //struct that stores all the static vorbis bitstream settings
49     vorbis_comment   m_vc; //struct that stores all the user comments
50     vorbis_dsp_state m_vd; //central working state for the packet->PCM decoder
51     vorbis_block     m_vb; //local working space for packet->PCM decode
52     soxr_t m_soxr = nullptr;
53     float *m_soxr_buf = nullptr;
54     size_t m_soxr_buf_frames = 0;
55     double m_ratio = 0;
56 };
57 
58 #endif // SHOUTOUTPUT_H
59