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