]> git.vomp.tv Git - vompclient.git/blob - player.h
*** empty log message ***
[vompclient.git] / player.h
1 /*
2     Copyright 2004-2005 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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 #include "audio.h"
32 #include "video.h"
33 #include "demuxervdr.h"
34 #include "vfeed.h"
35 #include "afeed.h"
36 #include "remote.h"
37 #include "vdr.h"
38 #include "callback.h"
39 #include "message.h"
40 #include "messagequeue.h"
41
42 #ifdef WIN32
43 #include "threadwin.h"
44 #else
45 #include "threadp.h"
46 #endif
47
48 class Player : public Thread_TYPE, public Callback
49 {
50   public:
51     Player(MessageQueue* messageQueue, void* messageReceiver, bool isRecording, bool isRadio);
52     virtual ~Player();
53
54     int init();
55     int shutdown();
56     void setStartFrame(ULONG frameNum);
57     void setLengthBytes(ULLONG length);
58     void setLengthFrames(ULONG length);
59
60     void play();
61     void stop();
62     void pause();
63     void fastForward();
64     void fastBackward();
65     void jumpToPercent(int percent);
66     void skipForward(int seconds);
67     void skipBackward(int seconds);
68
69     UCHAR getState() { return state; }
70     ULONG getCurrentFrameNum();
71     ULONG getLengthFrames();
72     UCHAR getIScanRate() { return ifactor; }
73
74     void call(void*); // for callback interface
75
76     const static UCHAR S_PLAY = 1;
77     const static UCHAR S_PAUSE_P = 2;
78     const static UCHAR S_PAUSE_I = 3;
79     const static UCHAR S_FFWD = 4;
80     const static UCHAR S_FBWD = 5;
81     const static UCHAR S_STOP = 6;
82     const static UCHAR S_JUMP = 7;
83
84     // Player events
85
86     // FIXME so far this just duplicates the old system + the wss
87
88     const static UCHAR CONNECTION_LOST = 1;
89     const static UCHAR STOP_PLAYBACK = 2;
90     const static UCHAR STREAM_END = 3;
91     const static UCHAR ASPECT43 = 4;
92     const static UCHAR ASPECT169 = 5;
93
94 #ifdef DEV
95     void test1();
96     void test2();
97 #endif
98
99   protected:
100     void threadMethod();
101     void threadPostStopCleanup();
102
103   private:
104     void switchState(UCHAR newState, ULONG jumpFrame=0);
105
106     void threadFeedLive();
107     void threadFeedPlay();
108     void threadFeedScan();
109
110     void setEndTS();
111     void doConnectionLost();
112     void restartAtFrame(ULONG newFrame);
113
114     MessageQueue* messageQueue;
115     void* messageReceiver;
116     Log* logger;
117     Audio* audio;
118     Video* video;
119     Demuxer* demuxer;
120     VDR* vdr;
121     VFeed vfeed;
122     AFeed afeed;
123
124     bool initted;
125     bool startup;
126     bool videoStartup;
127     bool isRecording;
128     bool isRadio;
129     bool preBuffering;
130
131 #ifndef WIN32
132     pthread_mutex_t mutex;
133 #else
134   HANDLE mutex;
135 #endif
136     void lock();
137     void unLock();
138
139     ULLONG lengthBytes;
140     ULONG lengthFrames;
141     ULONG currentFrameNumber;
142     UINT blockSize;
143     UINT startupBlockSize;
144     UINT preBufferSize;
145     UCHAR* threadBuffer;
146     UCHAR state;
147     UCHAR ifactor;
148 };
149
150 #endif
151
152
153 /*
154
155 Possible states:
156
157 Play, Pause, FFwd, FBwd, (Stop), [Jump]
158
159                     Possible  Working
160
161 Play   -> PauseP       *         *
162        -> PauseI
163        -> FFwd         *         *
164        -> FBwd         *         *
165        -> Stop         *         *
166        -> Jump         *         *
167
168 PauseP -> Play         *         *
169        -> PauseI
170        -> FFwd         *         *
171        -> FBwd         *         *
172        -> Stop         *         *
173        -> Jump         *         *
174
175 PauseI -> Play         *         *
176        -> PauseP
177        -> FFwd         *         *
178        -> FBwd         *         *
179        -> Stop         *         *
180        -> Jump         *         *
181
182 FFwd   -> Play         *         *
183        -> PauseP
184        -> PauseI       *         *
185        -> FBwd         *         *
186        -> Stop         *         *
187        -> Jump         *         *
188
189 FBwd   -> Play         *         *
190        -> PauseP
191        -> PauseI       *         *
192        -> FFwd         *         *
193        -> Stop         *         *
194        -> Jump         *         *
195
196 Stop   -> Play         *         *
197        -> PauseP
198        -> PauseI
199        -> FFwd
200        -> FBwd
201        -> Jump
202
203 Jump   -> Play
204        -> PauseP
205        -> PauseI
206        -> FFwd
207        -> FBwd
208        -> Stop
209
210 */