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