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