]> git.vomp.tv Git - vompclient.git/blob - playervideorec.h
43 CWFs
[vompclient.git] / playervideorec.h
1 /*
2     Copyright 2004-2008 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, write to the Free Software
18     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19 */
20
21 #ifndef PLAYERVIDEOREC_H
22 #define PLAYERVIDEOREC_H
23
24 #include <stdio.h>
25 #include <stdlib.h>
26 #ifndef WIN32
27 #include <sys/time.h>
28 #endif
29 #include <time.h>
30 #include <mutex>
31 #include <thread>
32 #include <condition_variable>
33
34 #include "callback.h"
35 #include "defines.h"
36 #include "vfeed.h"
37 #include "afeed.h"
38 #include "tfeed.h"
39
40 #include "teletextdecodervbiebu.h"
41
42 class MessageQueue;
43 class MessageReceiver;
44 class Audio;
45 class Video;
46 class VDR;
47 class LogNT;
48 class Demuxer;
49 class OSDReceiver;
50 class DVBSubtitles;
51 class Channel;
52
53 class PlayerVideoRec : public Callback
54 {
55   public:
56     PlayerVideoRec(MessageQueue* messageQueue, MessageReceiver* messageReceiver, OSDReceiver* osdReceiver);
57     virtual ~PlayerVideoRec();
58
59     int init(bool p_isPesRecording,double framespersec);
60     int shutdown();
61     void setStartFrame(ULONG frameNum);
62     void setLengthBytes(ULLONG length);
63     void setLengthFrames(ULONG length);
64     void setAudioChannel(int newChannel, int type, int streamtype);
65     void setSubtitleChannel(int newChannel);
66     bool toggleSubtitles();
67     void turnSubtitlesOn(bool ison); 
68     bool isSubtitlesOn() { return subtitlesShowing; }
69     void tellSubtitlesOSDVisible(bool visible);
70
71     void play();
72     void stop();
73     void pause();
74     void playpause();
75     void fastForward();
76     void fastBackward();
77     void jumpToPercent(double percent);
78     void skipForward(int seconds);
79     void skipBackward(int seconds);
80     void jumpToMark(int mark);
81     void jumpToFrameP(int newFrame);
82
83     UCHAR getState() { return state; }
84     ULONG getCurrentFrameNum();
85     ULONG getLengthFrames();
86     UCHAR getIScanRate() { return ifactor; }
87     bool* getDemuxerMpegAudioChannels();
88     bool* getDemuxerAc3AudioChannels();
89     bool* getDemuxerSubtitleChannels();
90     int *getTeletxtSubtitlePages();
91     int getCurrentAudioChannel();
92     int getCurrentSubtitleChannel();
93     bool isPesRecording() { return is_pesrecording; }
94     Channel *getDemuxerChannel();
95
96    TeletextDecoderVBIEBU * getTeletextDecoder() { return teletext; }
97
98     void call(void*); // for callback interface
99
100     const static UCHAR S_PLAY = 1;
101     const static UCHAR S_PAUSE_P = 2;
102     const static UCHAR S_PAUSE_I = 3;
103     const static UCHAR S_FFWD = 4;
104     const static UCHAR S_FBWD = 5;
105     const static UCHAR S_STOP = 6;
106     const static UCHAR S_JUMP = 7;
107     const static UCHAR S_JUMP_PI = 8; // Jump to Pause_I mode
108
109     // Player events
110
111     // FIXME so far this just duplicates the old system + the wss
112
113     const static UCHAR CONNECTION_LOST = 1;
114     const static UCHAR STOP_PLAYBACK = 2;
115     const static UCHAR STREAM_END = 3;
116     const static UCHAR ASPECT43 = 4;
117     const static UCHAR ASPECT169 = 5;
118
119 #ifdef DEV
120     void test1();
121     void test2();
122 #endif
123
124   private:
125     void switchState(UCHAR newState, ULONG jumpFrame=0);
126
127     void threadMethod();
128     void threadFeedPlay();
129     bool threadFeedScan();
130     bool threadPTSFeedScan();
131
132     void doConnectionLost();
133     void restartAtFrame(ULONG newFrame);
134     void restartAtFramePI(ULONG newFrame);
135
136     VFeed vfeed;
137     AFeed afeed;
138     TFeed tfeed;
139     OSDReceiver* osdReceiver;
140     MessageQueue* messageQueue;
141     MessageReceiver* messageReceiver;
142     LogNT* logger;
143     Audio* audio;
144     Video* video;
145     Demuxer* demuxer;
146     DVBSubtitles* subtitles;
147     VDR* vdr;
148
149     TeletextDecoderVBIEBU *teletext;
150
151     bool initted{};
152     bool startup;
153     bool videoStartup{};
154     bool subtitlesShowing{};
155     bool is_pesrecording{true};
156
157     double fps;
158
159     std::mutex stateMutex;
160
161     std::thread playerThread;
162     std::mutex playerThreadMutex;
163     std::condition_variable playerThreadCond;
164     bool threadReqQuit;
165     void threadStart();
166     void threadStop();
167
168     ULLONG lengthBytes{};
169     ULONG lengthFrames{};
170     ULONG currentFrameNumber{};
171     UINT blockSize{100000};
172     UINT startupBlockSize{250000};
173     UCHAR state{S_STOP};
174     UCHAR ifactor{4}; // 4, 8, 16, 32
175 };
176
177 #endif
178
179
180 /*
181
182 Possible states:
183
184 Play, Pause, FFwd, FBwd, (Stop), [Jump]
185
186                     Possible  Working
187
188 Play   -> PauseP       *         *
189        -> PauseI
190        -> FFwd         *         *
191        -> FBwd         *         *
192        -> Stop         *         *
193        -> Jump         *         *
194        -> Jump_PI      *         *
195
196 PauseP -> Play         *         *
197        -> PauseI
198        -> FFwd         *         *
199        -> FBwd         *         *
200        -> Stop         *         *
201        -> Jump         *         *
202        -> Jump_PI      *         *
203
204 PauseI -> Play         *         *
205        -> PauseP
206        -> FFwd         *         *
207        -> FBwd         *         *
208        -> Stop         *         *
209        -> Jump         *         *
210        -> Jump_PI      *         *
211
212 FFwd   -> Play         *         *
213        -> PauseP
214        -> PauseI       *         *
215        -> FBwd         *         *
216        -> Stop         *         *
217        -> Jump         *         *
218        -> Jump_PI      *         *
219
220 FBwd   -> Play         *         *
221        -> PauseP
222        -> PauseI       *         *
223        -> FFwd         *         *
224        -> Stop         *         *
225        -> Jump         *         *
226        -> Jump_PI      *         *
227
228 Stop   -> Play         *         *
229        -> PauseP
230        -> PauseI
231        -> FFwd
232        -> FBwd
233        -> Jump
234        -> Jump_PI
235
236 */