Sayonara Player
StreamWriter.h
1 /* StreamWriter.h */
2 
3 /* Copyright (C) 2011-2020 Michael Lugmair (Lucio Carreras)
4  *
5  * This file is part of sayonara player
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11 
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16 
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef STREAM_WRITER_H
22 #define STREAM_WRITER_H
23 
24 #include "StreamHttpParser.h"
25 #include "Interfaces/Engine/AudioDataReceiverInterface.h"
26 #include "Utils/Pimpl.h"
27 
28 #include <QObject>
29 
30 class MetaData;
31 class QTcpSocket;
32 
38 class StreamWriter :
39  public QObject,
41 {
42  Q_OBJECT
43  PIMPL(StreamWriter)
44 
45  signals:
46  void sigNewConnection(const QString& ip);
47  void sigDisconnected(StreamWriter* sw);
48 
49  public:
50  enum class Type : uint8_t
51  {
52  Undefined,
53  Standard,
54  Invalid,
55  Streaming
56  };
57 
64  StreamWriter(QTcpSocket* socket, const QString& ip, const MetaData& md);
65  ~StreamWriter() override;
66 
71  QString ip() const;
72 
77  void changeTrack(const MetaData& md);
78 
83  bool sendPlaylist();
84 
89  bool sendFavicon();
90 
95  bool sendMetadata();
96 
102 
107  bool sendHtml5();
108 
114  bool sendHeader(bool reject);
115 
116  StreamHttpParser::HttpAnswer parseMessage();
117 
121  void disconnect();
122 
126  void dismiss();
127 
133  void writeAudioData(const QByteArray& data) override;
134 
135  private:
136  void reset();
137 
138  private slots:
139  void socketDisconnected();
140  void dataAvailble();
141  void clearSocket();
142 };
143 
144 using StreamWriterPtr = std::shared_ptr<StreamWriter>;
145 #endif
StreamWriter::sendMetadata
bool sendMetadata()
Send track information (see StreamDataSender)
StreamWriter::sendFavicon
bool sendFavicon()
Send the http favicon (see StreamDataSender)
Engine::RawSoundReceiverInterface
The RawSoundReceiver interface.
Definition: AudioDataReceiverInterface.h:67
StreamWriter::dismiss
void dismiss()
stop sending sound over the client socket
StreamWriter::disconnect
void disconnect()
disconnect a client socket
StreamWriter::changeTrack
void changeTrack(const MetaData &md)
send new icy data to clients, and send new metadata to remote controls.
StreamWriter::sendBackground
bool sendBackground()
Send website background (see StreamDataSender)
StreamHttpParser::HttpAnswer
HttpAnswer
The HttpAnswer enum.
Definition: StreamHttpParser.h:40
StreamWriter::ip
QString ip() const
get client ip address
StreamWriter::sendHeader
bool sendHeader(bool reject)
send a appropriate header based on the type of request (see StreamDataSender)
MetaData
The MetaData class.
Definition: MetaData.h:47
StreamWriter::sendPlaylist
bool sendPlaylist()
Send a m3u playlist (see StreamDataSender)
StreamWriter::sendHtml5
bool sendHtml5()
send a html5 website (see StreamDataSender)
StreamWriter::writeAudioData
void writeAudioData(const QByteArray &data) override
new audio data has arrived and has to be forwarded to the socket
StreamWriter::StreamWriter
StreamWriter(QTcpSocket *socket, const QString &ip, const MetaData &md)
StreamWriter.
StreamWriter
The StreamWriter class. This class is the interface between StreamDataSender and StreamServer....
Definition: StreamWriter.h:41