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