]> git.vomp.tv Git - vompclient.git/blob - playervideorec.h
EventDispatcher: Switch to std::mutex/cond
[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
32 #include "threadsystem.h"
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 Thread_TYPE, 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   protected:
124     void threadMethod();
125     void threadPostStopCleanup();
126
127   private:
128     void switchState(UCHAR newState, ULONG jumpFrame=0);
129
130     void threadFeedPlay();
131     void threadFeedScan();
132     void threadPTSFeedScan();
133
134     void doConnectionLost();
135     void restartAtFrame(ULONG newFrame);
136     void restartAtFramePI(ULONG newFrame);
137
138     bool subtitlesShowing{};
139     MessageQueue* messageQueue;
140     void* messageReceiver;
141     OSDReceiver* osdReceiver;
142     Log* logger;
143     Audio* audio;
144     Video* video;
145     Demuxer* demuxer;
146     DVBSubtitles* subtitles;
147     VDR* vdr;
148     VFeed vfeed;
149     AFeed afeed;
150     TFeed tfeed;
151     TeletextDecoderVBIEBU *teletext;
152   
153     bool initted{};
154     bool startup;
155     bool videoStartup{};
156
157     bool is_pesrecording{true};
158     double fps;
159
160     std::mutex stateMutex;
161
162     ULLONG lengthBytes{};
163     ULONG lengthFrames{};
164     ULONG currentFrameNumber{};
165     UINT blockSize{100000};
166     UINT startupBlockSize{250000};
167     UCHAR* threadBuffer{};
168     UCHAR state{S_STOP};
169     UCHAR ifactor{4}; // 4, 8, 16, 32
170 };
171
172 #endif
173
174
175 /*
176
177 Possible states:
178
179 Play, Pause, FFwd, FBwd, (Stop), [Jump]
180
181                     Possible  Working
182
183 Play   -> PauseP       *         *
184        -> PauseI
185        -> FFwd         *         *
186        -> FBwd         *         *
187        -> Stop         *         *
188        -> Jump         *         *
189        -> Jump_PI      *         *
190
191 PauseP -> Play         *         *
192        -> PauseI
193        -> FFwd         *         *
194        -> FBwd         *         *
195        -> Stop         *         *
196        -> Jump         *         *
197        -> Jump_PI      *         *
198
199 PauseI -> Play         *         *
200        -> PauseP
201        -> FFwd         *         *
202        -> FBwd         *         *
203        -> Stop         *         *
204        -> Jump         *         *
205        -> Jump_PI      *         *
206
207 FFwd   -> Play         *         *
208        -> PauseP
209        -> PauseI       *         *
210        -> FBwd         *         *
211        -> Stop         *         *
212        -> Jump         *         *
213        -> Jump_PI      *         *
214
215 FBwd   -> Play         *         *
216        -> PauseP
217        -> PauseI       *         *
218        -> FFwd         *         *
219        -> Stop         *         *
220        -> Jump         *         *
221        -> Jump_PI      *         *
222
223 Stop   -> Play         *         *
224        -> PauseP
225        -> PauseI
226        -> FFwd
227        -> FBwd
228        -> Jump
229        -> Jump_PI
230
231 */