]> git.vomp.tv Git - vompclient.git/blob - playerradiolive.h
Rename TCP class to TCPOld
[vompclient.git] / playerradiolive.h
1 /*
2     Copyright 2008-2020 Chris Tallon
3
4     This file is part of VOMP.
5
6     VOMP is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     VOMP is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with VOMP.  If not, see <https://www.gnu.org/licenses/>.
18 */
19
20 #ifndef PLAYERRADIOLIVE_H
21 #define PLAYERRADIOLIVE_H
22
23 #include <mutex>
24 #include <thread>
25 #include <condition_variable>
26
27 #include <queue>
28
29 #include "playerlive.h"
30 #include "callback.h"
31 #include "defines.h"
32 #include "afeed.h"
33 #include "vdr.h"
34
35 class MessageQueue;
36 class Audio;
37 class Log;
38 class DemuxerTS;
39
40 class PlayerRadioLive : public PlayerLive, public Callback, public StreamReceiver
41 {
42   public:
43     PlayerRadioLive(MessageQueue* messageQueue, void* messageReceiver, ChannelList* chanList);
44     virtual ~PlayerRadioLive();
45
46     virtual int init();
47     virtual int shutdown();
48
49     virtual void go(ULONG index);
50     virtual void setChannel(ULONG index);
51     virtual void stop();
52     virtual void setAudioChannel(int newChannel, int type,int streamtype);
53     virtual void setSubtitleChannel(int newChannel);
54
55     virtual bool* getDemuxerMpegAudioChannels();
56     virtual bool* getDemuxerAc3AudioChannels();
57     virtual int getCurrentAudioChannel();
58     virtual int* getTeletxtSubtitlePages();
59     virtual int getCurrentSubtitleChannel();
60
61     void call(void*); // for callback interface
62
63     virtual void streamReceive(ULONG, void*, ULONG); // stream receiver interface
64     
65     // Player events
66
67     // FIXME so far this just duplicates the old system + the wss
68
69     const static UCHAR CONNECTION_LOST = 1;
70     const static UCHAR STOP_PLAYBACK = 2;
71     const static UCHAR STREAM_END = 3;
72     const static UCHAR ASPECT43 = 4;
73     const static UCHAR ASPECT169 = 5;
74     const static UCHAR PREBUFFERING = 6;
75
76   private:
77     MessageQueue* messageQueue;
78     void* messageReceiver;
79     Log* logger;
80     Audio* audio;
81     DemuxerTS* demuxer;
82     VDR* vdr;
83     AFeed afeed;
84     ChannelList* chanList;
85
86     std::queue<PLInstruction> instructions;
87     const static UCHAR I_SETCHANNEL = 1;
88     const static UCHAR I_STOP = 2;
89
90     std::queue<StreamChunk> streamChunks;
91
92     bool initted{};
93
94     UCHAR state{S_STOP};
95     const static UCHAR S_STOP = 1;
96     const static UCHAR S_PREBUFFERING = 2;
97     const static UCHAR S_PLAY = 3;
98     void switchState(UCHAR newState);
99     bool checkError();
100
101     int preBufferCount;
102     const static int preBufferAmount = 3;
103
104     std::thread playerThread;
105     std::mutex playerThreadMutex;
106     std::condition_variable playerThreadCond;
107     void threadMethod();
108
109     void clearStreamChunks();
110     void chunkToDemuxer();
111     void optimizeInstructionQueue();
112 };
113
114 #endif