]> git.vomp.tv Git - vompclient.git/blob - player.h
Update for windows
[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);
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 preBuffering;
131
132 #ifndef WIN32
133     pthread_mutex_t mutex;
134 #else
135   HANDLE mutex;
136 #endif
137     void lock();
138     void unLock();
139
140     ULLONG lengthBytes;
141     ULONG lengthFrames;
142     ULONG currentFrameNumber;
143     UINT blockSize;
144     UINT startupBlockSize;
145     UINT preBufferSize;
146     UCHAR* threadBuffer;
147     UCHAR state;
148     UCHAR ifactor;
149 };
150
151 #endif
152
153
154 /*
155
156 Possible states:
157
158 Play, Pause, FFwd, FBwd, (Stop), [Jump]
159
160                     Possible  Working
161
162 Play   -> PauseP       *         *
163        -> PauseI
164        -> FFwd         *         *
165        -> FBwd         *         *
166        -> Stop         *         *
167        -> Jump         *         *
168
169 PauseP -> Play         *         *
170        -> PauseI
171        -> FFwd         *         *
172        -> FBwd         *         *
173        -> Stop         *         *
174        -> Jump         *         *
175
176 PauseI -> Play         *         *
177        -> PauseP
178        -> FFwd         *         *
179        -> FBwd         *         *
180        -> Stop         *         *
181        -> Jump         *         *
182
183 FFwd   -> Play         *         *
184        -> PauseP
185        -> PauseI       *         *
186        -> FBwd         *         *
187        -> Stop         *         *
188        -> Jump         *         *
189
190 FBwd   -> Play         *         *
191        -> PauseP
192        -> PauseI       *         *
193        -> FFwd         *         *
194        -> Stop         *         *
195        -> Jump         *         *
196
197 Stop   -> Play         *         *
198        -> PauseP
199        -> PauseI
200        -> FFwd
201        -> FBwd
202        -> Jump
203
204 Jump   -> Play
205        -> PauseP
206        -> PauseI
207        -> FFwd
208        -> FBwd
209        -> Stop
210
211 */