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