Sayonara Player
StreamWriter.h
1 /* StreamWriter.h */
2 
3 /* Copyright (C) 2011-2016 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 "Helper/Settings/SayonaraClass.h"
25 #include "Interfaces/RawSoundReceiver/RawSoundReceiverInterface.h"
26 #include "StreamHttpParser.h"
27 
28 #include <QByteArray>
29 #include <QHostAddress>
30 #include <QTcpSocket>
31 
32 #include <memory>
33 
34 class StreamHttpParser;
35 class StreamDataSender;
36 class EngineHandler;
37 class MetaData;
38 
44 class StreamWriter :
45  public QObject,
47  protected SayonaraClass
48 
49 {
50  Q_OBJECT
51 
52 public:
53 
54  enum class Type : quint8 {
55  Undefined,
56  Standard,
57  Invalid,
58  Streaming
59  };
60 
61  signals:
62  void sig_new_connection(const QString& ip);
63  void sig_disconnected(StreamWriter* sw);
64 
65 
66  private:
67  EngineHandler* _engine=nullptr;
68  StreamHttpParser* _parser=nullptr;
69  StreamDataSender* _sender=nullptr;
70  QTcpSocket* _socket=nullptr;
71 
72  bool _dismissed; // after that, only trash will be sent
73  bool _send_data; // after that, no data at all will be sent
74 
75  QString _stream_title;
76  QString _ip;
77 
78  StreamWriter::Type _type;
79 
80  void reset();
81 
82 
83  public:
84 
91  StreamWriter(QTcpSocket* socket, const QString& ip, const MetaData& md);
92  virtual ~StreamWriter();
93 
98  QString get_ip() const;
99 
104  int get_sd() const;
105 
110  Type get_type() const;
111 
116  void change_track(const MetaData& md);
117 
118 
123  bool send_playlist();
124 
129  bool send_favicon();
130 
135  bool send_metadata();
136 
141  bool send_bg();
142 
147  bool send_html5();
148 
154  bool send_header(bool reject);
155 
156  StreamHttpParser::HttpAnswer parse_message();
157 
161  void disconnect();
162 
166  void dismiss();
167 
173  void new_audio_data(const uchar* data, quint64 size) override;
174 
175 
176  private slots:
177 
178  void socket_disconnected();
179  void data_available();
180 };
181 
182 typedef std::shared_ptr<StreamWriter> StreamWriterPtr;
183 #endif
The StreamWriter class. This class is the interface between StreamDataSender and StreamServer. It watches the client socket and spreads data to its client.
Definition: StreamWriter.h:44
StreamWriter(QTcpSocket *socket, const QString &ip, const MetaData &md)
StreamWriter.
void new_audio_data(const uchar *data, quint64 size) override
new audio data has arrived and has to be forwarded to the socket
The StreamDataSender class. This class is used for sending the raw bytes.
Definition: StreamDataSender.h:31
The SayonaraClass class provides access to Settings and notifications.
Definition: SayonaraClass.h:31
Definition: MetaData.h:49
Type get_type() const
get connection type
bool send_playlist()
Send a m3u playlist (see StreamDataSender)
void dismiss()
stop sending sound over the client socket
void disconnect()
disconnect a client socket
The RawSoundReceiver interface.
Definition: RawSoundReceiverInterface.h:32
bool send_html5()
send a html5 website (see StreamDataSender)
Definition: EngineHandler.h:36
Parses requests out of the Client.
Definition: StreamHttpParser.h:33
void change_track(const MetaData &md)
send new icy data to clients, and send new metadata to remote controls.
bool send_header(bool reject)
send a appropriate header based on the type of request (see StreamDataSender)
bool send_bg()
Send website background (see StreamDataSender)
HttpAnswer
The HttpAnswer enum.
Definition: StreamHttpParser.h:40
bool send_favicon()
Send the http favicon (see StreamDataSender)
int get_sd() const
get raw socket descriptor
QString get_ip() const
get client ip address
bool send_metadata()
Send track information (see StreamDataSender)