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