]> git.vomp.tv Git - vompclient.git/blob - player.h
Rewritten vomp discovery protocol
[vompclient.git] / player.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 PLAYER_H
22 #define PLAYER_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
31 #ifdef WIN32
32 #include "threadwin.h"
33 #else
34 #include "threadp.h"
35 #endif
36
37 #include "callback.h"
38 #include "defines.h"
39 #include "vfeed.h"
40 #include "afeed.h"
41 #include "tfeed.h"
42
43 #include "teletextdecodervbiebu.h"
44
45 class MessageQueue;
46 class Audio;
47 class Video;
48 class VDR;
49 class Log;
50 class Demuxer;
51 class OSDReceiver;
52 class DVBSubtitles;
53 class Channel;
54
55 class Player : public Thread_TYPE, public Callback
56 {
57   public:
58     Player(MessageQueue* messageQueue, void* messageReceiver, OSDReceiver* osdReceiver);
59     virtual ~Player();
60
61     int init(bool p_isPesRecording,double framespersec);
62     int shutdown();
63     void setStartFrame(ULONG frameNum);
64     void setLengthBytes(ULLONG length);
65     void setLengthFrames(ULONG length);
66     void setAudioChannel(int newChannel, int type);
67     void setSubtitleChannel(int newChannel);
68     bool toggleSubtitles();
69     void turnSubtitlesOn(bool ison); 
70     bool isSubtitlesOn() { return subtitlesShowing; }
71
72     void play();
73     void stop();
74     void pause();
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   protected:
125     void threadMethod();
126     void threadPostStopCleanup();
127
128   private:
129     void switchState(UCHAR newState, ULONG jumpFrame=0);
130
131     void threadFeedPlay();
132     void threadFeedScan();
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     
154
155     bool initted;
156     bool startup;
157     bool videoStartup;
158
159     bool is_pesrecording;
160         double fps;
161
162 #ifndef WIN32
163     pthread_mutex_t mutex;
164 #else
165     HANDLE mutex;
166 #endif
167     void lock();
168     void unLock();
169
170     ULLONG lengthBytes;
171     ULONG lengthFrames;
172     ULONG currentFrameNumber;
173     UINT blockSize;
174     UINT startupBlockSize;
175     UCHAR* threadBuffer;
176     UCHAR state;
177     UCHAR ifactor;
178 };
179
180 #endif
181
182
183 /*
184
185 Possible states:
186
187 Play, Pause, FFwd, FBwd, (Stop), [Jump]
188
189                     Possible  Working
190
191 Play   -> PauseP       *         *
192        -> PauseI
193        -> FFwd         *         *
194        -> FBwd         *         *
195        -> Stop         *         *
196        -> Jump         *         *
197        -> Jump_PI      *         *
198
199 PauseP -> Play         *         *
200        -> PauseI
201        -> FFwd         *         *
202        -> FBwd         *         *
203        -> Stop         *         *
204        -> Jump         *         *
205        -> Jump_PI      *         *
206
207 PauseI -> Play         *         *
208        -> PauseP
209        -> FFwd         *         *
210        -> FBwd         *         *
211        -> Stop         *         *
212        -> Jump         *         *
213        -> Jump_PI      *         *
214
215 FFwd   -> Play         *         *
216        -> PauseP
217        -> PauseI       *         *
218        -> FBwd         *         *
219        -> Stop         *         *
220        -> Jump         *         *
221        -> Jump_PI      *         *
222
223 FBwd   -> Play         *         *
224        -> PauseP
225        -> PauseI       *         *
226        -> FFwd         *         *
227        -> Stop         *         *
228        -> Jump         *         *
229        -> Jump_PI      *         *
230
231 Stop   -> Play         *         *
232        -> PauseP
233        -> PauseI
234        -> FFwd
235        -> FBwd
236        -> Jump
237        -> Jump_PI
238
239 */