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