]> git.vomp.tv Git - vompclient.git/blob - player.h
Windows mods on new threadscan code
[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, 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 togglePause();
63     void toggleFastForward();
64     void toggleFastBackward();
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
73     void call(void*); // for callback interface
74
75     const static UCHAR S_PLAY = 1;
76     const static UCHAR S_PAUSE_P = 2;
77     const static UCHAR S_PAUSE_I = 3;
78     const static UCHAR S_FFWD = 4;
79     const static UCHAR S_FBWD = 5;
80     const static UCHAR S_STOP = 6;
81     const static UCHAR S_JUMP = 7;
82
83 #ifdef DEV
84     void test1();
85     void test2();
86 #endif
87
88   protected:
89     void threadMethod();
90     void threadPostStopCleanup();
91
92   private:
93     void switchState(UCHAR newState, ULONG jumpFrame=0);
94
95     void threadFeedLive();
96     void threadFeedPlay();
97     void threadFeedScan();
98
99     void setEndTS();
100     void doConnectionLost();
101     void restartAtFrame(ULONG newFrame);
102
103     MessageQueue* commandMessageQueue;
104     Log* logger;
105     Audio* audio;
106     Video* video;
107     Demuxer* demuxer;
108     VDR* vdr;
109     VFeed vfeed;
110     AFeed afeed;
111
112     bool initted;
113     bool startup;
114     bool videoStartup;
115     bool isRecording;
116     bool isRadio;
117     bool preBuffering;
118
119 #ifndef WIN32
120     pthread_mutex_t mutex;
121 #else
122   HANDLE mutex;
123 #endif
124     void lock();
125     void unLock();
126
127     ULLONG lengthBytes;
128     ULONG lengthFrames;
129     ULONG currentFrameNumber;
130     UINT blockSize;
131     UINT startupBlockSize;
132     UCHAR* threadBuffer;
133     UCHAR state;
134
135     const static UINT ifactor = 5;
136 };
137
138 #endif
139
140
141 /*
142
143 Possible states:
144
145 Play, Pause, FFwd, FBwd, (Stop), [Jump]
146
147                     Possible  Working
148
149 Play   -> PauseP       *         *
150        -> PauseI
151        -> FFwd         *         *
152        -> FBwd         *         *
153        -> Stop         *         *
154        -> Jump         *         *
155
156 PauseP -> Play         *         *
157        -> PauseI
158        -> FFwd         *         *
159        -> FBwd         *         *
160        -> Stop         *         *
161        -> Jump         *         *
162
163 PauseI -> Play         *         *
164        -> PauseP
165        -> FFwd         *         *
166        -> FBwd         *         *
167        -> Stop         *         *
168        -> Jump         *         *
169
170 FFwd   -> Play         *         *
171        -> PauseP
172        -> PauseI       *         *
173        -> FBwd         *         *
174        -> Stop         *         *
175        -> Jump         *         *
176
177 FBwd   -> Play         *         *
178        -> PauseP
179        -> PauseI       *         *
180        -> FFwd         *         *
181        -> Stop         *         *
182        -> Jump         *         *
183
184 Stop   -> Play         *         *
185        -> PauseP
186        -> PauseI
187        -> FFwd
188        -> FBwd
189        -> Jump
190
191 Jump   -> Play
192        -> PauseP
193        -> PauseI
194        -> FFwd
195        -> FBwd
196        -> Stop
197
198 */