]> git.vomp.tv Git - vompclient.git/blob - player.h
Ac3 for Windows
[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 "demuxerts.h"
35 #include "vfeed.h"
36 #include "afeed.h"
37 #include "remote.h"
38 #include "vdr.h"
39 #include "callback.h"
40 #include "message.h"
41 #include "messagequeue.h"
42
43 #ifdef WIN32
44 #include "threadwin.h"
45 #else
46 #include "threadp.h"
47 #endif
48
49 class Player : public Thread_TYPE, public Callback
50 {
51   public:
52     Player(MessageQueue* messageQueue, void* messageReceiver, bool isRecording);
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);
61
62     void play();                         // Recording
63     void play(ULONG vpid, ULONG apid);   // Live TV
64     void stop();
65     void pause();
66     void fastForward();
67     void fastBackward();
68     void jumpToPercent(double percent);
69     void skipForward(int seconds);
70     void skipBackward(int seconds);
71     void jumpToMark(int mark);
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
91     // Player events
92
93     // FIXME so far this just duplicates the old system + the wss
94
95     const static UCHAR CONNECTION_LOST = 1;
96     const static UCHAR STOP_PLAYBACK = 2;
97     const static UCHAR STREAM_END = 3;
98     const static UCHAR ASPECT43 = 4;
99     const static UCHAR ASPECT169 = 5;
100
101 #ifdef DEV
102     void test1();
103     void test2();
104 #endif
105
106   protected:
107     void threadMethod();
108     void threadPostStopCleanup();
109
110   private:
111     void switchState(UCHAR newState, ULONG jumpFrame=0);
112
113     void threadFeedLive();
114     void threadFeedPlay();
115     void threadFeedScan();
116
117     void doConnectionLost();
118     void restartAtFrame(ULONG newFrame);
119
120     MessageQueue* messageQueue;
121     void* messageReceiver;
122     Log* logger;
123     Audio* audio;
124     Video* video;
125     Demuxer* demuxer;
126     VDR* vdr;
127     VFeed vfeed;
128     AFeed afeed;
129
130     bool initted;
131     bool startup;
132     bool videoStartup;
133     bool isRecording;
134     bool preBuffering;
135
136 #ifndef WIN32
137     pthread_mutex_t mutex;
138 #else
139   HANDLE mutex;
140 #endif
141     void lock();
142     void unLock();
143
144     ULLONG lengthBytes;
145     ULONG lengthFrames;
146     ULONG currentFrameNumber;
147     UINT blockSize;
148     UINT startupBlockSize;
149     UINT preBufferSize;
150     UCHAR* threadBuffer;
151     UCHAR state;
152     UCHAR ifactor;
153 };
154
155 #endif
156
157
158 /*
159
160 Possible states:
161
162 Play, Pause, FFwd, FBwd, (Stop), [Jump]
163
164                     Possible  Working
165
166 Play   -> PauseP       *         *
167        -> PauseI
168        -> FFwd         *         *
169        -> FBwd         *         *
170        -> Stop         *         *
171        -> Jump         *         *
172
173 PauseP -> Play         *         *
174        -> PauseI
175        -> FFwd         *         *
176        -> FBwd         *         *
177        -> Stop         *         *
178        -> Jump         *         *
179
180 PauseI -> Play         *         *
181        -> PauseP
182        -> FFwd         *         *
183        -> FBwd         *         *
184        -> Stop         *         *
185        -> Jump         *         *
186
187 FFwd   -> Play         *         *
188        -> PauseP
189        -> PauseI       *         *
190        -> FBwd         *         *
191        -> Stop         *         *
192        -> Jump         *         *
193
194 FBwd   -> Play         *         *
195        -> PauseP
196        -> PauseI       *         *
197        -> FFwd         *         *
198        -> Stop         *         *
199        -> Jump         *         *
200
201 Stop   -> Play         *         *
202        -> PauseP
203        -> PauseI
204        -> FFwd
205        -> FBwd
206        -> Jump
207
208 Jump   -> Play
209        -> PauseP
210        -> PauseI
211        -> FFwd
212        -> FBwd
213        -> Stop
214
215 */