]> git.vomp.tv Git - vompclient.git/blob - playervideolive.h
Convert PlayerRadioRec to std::thread
[vompclient.git] / playervideolive.h
1 /*
2     Copyright 2004-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 PLAYERVIDEOLIVE_H
21 #define PLAYERVIDEOLIVE_H
22
23 #include <stdio.h>
24 #include <stdlib.h>
25 #ifndef WIN32
26 #include <sys/time.h>
27 #endif
28 #include <time.h>
29
30 #include <mutex>
31 #include <thread>
32 #include <condition_variable>
33
34 #include <queue>
35
36 #include "playerlive.h"
37
38 #include "callback.h"
39 #include "defines.h"
40 #include "vfeed.h"
41 #include "afeed.h"
42 #include "tfeed.h"
43 #include "vdr.h"
44
45 #include "teletextdecodervbiebu.h"
46
47 class MessageQueue;
48 class Audio;
49 class Video;
50 class Log;
51 class DemuxerTS;
52 class OSDReceiver;
53 class DVBSubtitles;
54
55 class PlayerVideoLive : public PlayerLive, public Callback, public StreamReceiver
56 {
57   public:
58     PlayerVideoLive(MessageQueue* messageQueue, void* messageReceiver, OSDReceiver* tosdReceiver, ChannelList* chanList);
59     virtual ~PlayerVideoLive();
60
61     virtual int init();
62     virtual int shutdown();
63
64     virtual void go(ULONG index);
65     virtual void setChannel(ULONG index);
66     virtual void stop();
67     virtual void setAudioChannel(int newChannel,int type,int streamtype);
68     virtual void setSubtitleChannel(int newChannel);
69     virtual bool toggleSubtitles();
70     virtual void turnSubtitlesOn(bool ison); 
71     virtual bool isSubtitlesOn() {return subtitlesShowing;};
72     virtual void tellSubtitlesOSDVisible(bool visible);
73
74     virtual bool* getDemuxerMpegAudioChannels();
75     virtual bool* getDemuxerAc3AudioChannels();
76     virtual int getCurrentAudioChannel();
77     virtual int getCurrentSubtitleChannel();
78     virtual int *getTeletxtSubtitlePages();
79
80     TeletextDecoderVBIEBU * getTeletextDecoder(){return teletext;};
81
82     void call(void*); // for callback interface
83
84     virtual void streamReceive(ULONG, void*, ULONG); // stream receiver interface
85     
86     // Player events
87
88     // FIXME so far this just duplicates the old system + the wss
89
90     const static UCHAR CONNECTION_LOST = 1;
91     const static UCHAR STOP_PLAYBACK = 2;
92     const static UCHAR STREAM_END = 3;
93     const static UCHAR ASPECT43 = 4;
94     const static UCHAR ASPECT169 = 5;
95     const static UCHAR PREBUFFERING = 6;
96
97   protected:
98     void threadMethod();
99
100   private:
101     VFeed vfeed;
102     AFeed afeed;
103     TFeed tfeed;
104     MessageQueue* messageQueue;
105     void* messageReceiver;
106     OSDReceiver* osdReceiver;
107     ChannelList* chanList;
108     Log* logger;
109     Audio* audio;
110     Video* video;
111     DemuxerTS* demuxer;
112     DVBSubtitles* subtitles;
113     TeletextDecoderVBIEBU *teletext;
114     VDR* vdr;
115
116     std::queue<PLInstruction> instructions;
117     const static UCHAR I_SETCHANNEL = 1;
118     const static UCHAR I_STOP = 2;
119
120     std::queue<StreamChunk> streamChunks;
121
122
123     std::thread playerThread;
124     std::mutex playerThreadMutex;
125     std::condition_variable playerThreadCond;
126
127     const static UCHAR S_STOP = 1;
128     const static UCHAR S_VIDEOSTARTUP = 2;
129     const static UCHAR S_PREBUFFERING = 3;
130     const static UCHAR S_PLAY = 4;
131     void switchState(UCHAR newState);
132     bool checkError();
133
134     bool initted{};
135     UCHAR state{S_STOP};
136     bool subtitlesShowing{};
137     bool firstStart{true};
138     bool videoStartup{};
139     bool pendingAudioPlay{};
140     bool h264;
141     int preBufferCount;
142     const static int preBufferAmount = 3;
143
144     void clearStreamChunks();
145     void chunkToDemuxer();
146     void optimizeInstructionQueue();
147 };
148
149 #endif
150