]> git.vomp.tv Git - vompclient.git/blob - player.h
Cut marks support
[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     void jumpToMark(int mark);
70
71     UCHAR getState() { return state; }
72     ULONG getCurrentFrameNum();
73     ULONG getLengthFrames();
74     UCHAR getIScanRate() { return ifactor; }
75     bool* getDemuxerAudioChannels();
76     int getCurrentAudioChannel();
77
78     void call(void*); // for callback interface
79
80     const static UCHAR S_PLAY = 1;
81     const static UCHAR S_PAUSE_P = 2;
82     const static UCHAR S_PAUSE_I = 3;
83     const static UCHAR S_FFWD = 4;
84     const static UCHAR S_FBWD = 5;
85     const static UCHAR S_STOP = 6;
86     const static UCHAR S_JUMP = 7;
87
88     // Player events
89
90     // FIXME so far this just duplicates the old system + the wss
91
92     const static UCHAR CONNECTION_LOST = 1;
93     const static UCHAR STOP_PLAYBACK = 2;
94     const static UCHAR STREAM_END = 3;
95     const static UCHAR ASPECT43 = 4;
96     const static UCHAR ASPECT169 = 5;
97
98 #ifdef DEV
99     void test1();
100     void test2();
101 #endif
102
103   protected:
104     void threadMethod();
105     void threadPostStopCleanup();
106
107   private:
108     void switchState(UCHAR newState, ULONG jumpFrame=0);
109
110     void threadFeedLive();
111     void threadFeedPlay();
112     void threadFeedScan();
113
114     void doConnectionLost();
115     void restartAtFrame(ULONG newFrame);
116
117     MessageQueue* messageQueue;
118     void* messageReceiver;
119     Log* logger;
120     Audio* audio;
121     Video* video;
122     Demuxer* demuxer;
123     VDR* vdr;
124     VFeed vfeed;
125     AFeed afeed;
126
127     bool initted;
128     bool startup;
129     bool videoStartup;
130     bool isRecording;
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 */