]> git.vomp.tv Git - vompclient.git/blob - playerradiolive.h
Improve connection failure handling
[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 "log.h"
30 #include "playerlive.h"
31 #include "callback.h"
32 #include "defines.h"
33 #include "afeed.h"
34 #include "vdr.h"
35
36 class MessageQueue;
37 class Audio;
38 class LogNT;
39 class DemuxerTS;
40
41 class PlayerRadioLive : public PlayerLive, public Callback, public StreamReceiver
42 {
43   public:
44     PlayerRadioLive(MessageQueue* messageQueue, void* messageReceiver, ChannelList* chanList);
45     virtual ~PlayerRadioLive();
46
47     virtual int init();
48     virtual int shutdown();
49
50     virtual void go(ULONG index);
51     virtual void setChannel(ULONG index);
52     virtual void stop();
53     virtual void setAudioChannel(int newChannel, int type,int streamtype);
54     virtual void setSubtitleChannel(int newChannel);
55
56     virtual bool* getDemuxerMpegAudioChannels();
57     virtual bool* getDemuxerAc3AudioChannels();
58     virtual int getCurrentAudioChannel();
59     virtual int* getTeletxtSubtitlePages();
60     virtual int getCurrentSubtitleChannel();
61
62     void call(void*); // for callback interface
63
64     virtual void streamReceive(ULONG, void*, ULONG); // stream receiver interface
65     
66     // Player events
67
68     // FIXME so far this just duplicates the old system + the wss
69
70     const static UCHAR CONNECTION_LOST = 1;
71     const static UCHAR STOP_PLAYBACK = 2;
72     const static UCHAR STREAM_END = 3;
73     const static UCHAR ASPECT43 = 4;
74     const static UCHAR ASPECT169 = 5;
75     const static UCHAR PREBUFFERING = 6;
76
77   private:
78     MessageQueue* messageQueue;
79     void* messageReceiver;
80     LogNT* logger;
81     Audio* audio;
82     DemuxerTS* demuxer;
83     VDR* vdr;
84     AFeed afeed;
85     ChannelList* chanList;
86
87     std::queue<PLInstruction> instructions;
88     const static UCHAR I_SETCHANNEL = 1;
89     const static UCHAR I_STOP = 2;
90
91     std::queue<StreamChunk> streamChunks;
92
93     bool initted{};
94
95     UCHAR state{S_STOP};
96     const static UCHAR S_STOP = 1;
97     const static UCHAR S_PREBUFFERING = 2;
98     const static UCHAR S_PLAY = 3;
99     void switchState(UCHAR newState);
100     bool checkError();
101
102     int preBufferCount;
103     const static int preBufferAmount = 3;
104
105     std::thread playerThread;
106     std::mutex playerThreadMutex;
107     std::condition_variable playerThreadCond;
108     void threadMethod();
109
110     void clearStreamChunks();
111     void chunkToDemuxer();
112     void optimizeInstructionQueue();
113 };
114
115 #endif