]> git.vomp.tv Git - vompclient.git/blob - playervideorec.h
Fix black background for 16:9 live TV on 4:3 screen
[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     VFeed vfeed;
139     AFeed afeed;
140     TFeed tfeed;
141     OSDReceiver* osdReceiver;
142     MessageQueue* messageQueue;
143     void* messageReceiver;
144     Log* logger;
145     Audio* audio;
146     Video* video;
147     Demuxer* demuxer;
148     DVBSubtitles* subtitles;
149     VDR* vdr;
150
151     TeletextDecoderVBIEBU *teletext;
152
153     bool initted{};
154     bool startup;
155     bool videoStartup{};
156     bool subtitlesShowing{};
157     bool is_pesrecording{true};
158
159     double fps;
160
161     std::mutex stateMutex;
162
163     ULLONG lengthBytes{};
164     ULONG lengthFrames{};
165     ULONG currentFrameNumber{};
166     UINT blockSize{100000};
167     UINT startupBlockSize{250000};
168     UCHAR* threadBuffer{};
169     UCHAR state{S_STOP};
170     UCHAR ifactor{4}; // 4, 8, 16, 32
171 };
172
173 #endif
174
175
176 /*
177
178 Possible states:
179
180 Play, Pause, FFwd, FBwd, (Stop), [Jump]
181
182                     Possible  Working
183
184 Play   -> PauseP       *         *
185        -> PauseI
186        -> FFwd         *         *
187        -> FBwd         *         *
188        -> Stop         *         *
189        -> Jump         *         *
190        -> Jump_PI      *         *
191
192 PauseP -> Play         *         *
193        -> PauseI
194        -> FFwd         *         *
195        -> FBwd         *         *
196        -> Stop         *         *
197        -> Jump         *         *
198        -> Jump_PI      *         *
199
200 PauseI -> Play         *         *
201        -> PauseP
202        -> FFwd         *         *
203        -> FBwd         *         *
204        -> Stop         *         *
205        -> Jump         *         *
206        -> Jump_PI      *         *
207
208 FFwd   -> Play         *         *
209        -> PauseP
210        -> PauseI       *         *
211        -> FBwd         *         *
212        -> Stop         *         *
213        -> Jump         *         *
214        -> Jump_PI      *         *
215
216 FBwd   -> Play         *         *
217        -> PauseP
218        -> PauseI       *         *
219        -> FFwd         *         *
220        -> Stop         *         *
221        -> Jump         *         *
222        -> Jump_PI      *         *
223
224 Stop   -> Play         *         *
225        -> PauseP
226        -> PauseI
227        -> FFwd
228        -> FBwd
229        -> Jump
230        -> Jump_PI
231
232 */