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