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