]> git.vomp.tv Git - vompclient.git/blob - playerradio.h
Preparations for dynamic mode switching
[vompclient.git] / playerradio.h
1 /*\r
2     Copyright 2004-2006 Chris Tallon\r
3 \r
4     This file is part of VOMP.\r
5 \r
6     VOMP is free software; you can redistribute it and/or modify\r
7     it under the terms of the GNU General Public License as published by\r
8     the Free Software Foundation; either version 2 of the License, or\r
9     (at your option) any later version.\r
10 \r
11     VOMP is distributed in the hope that it will be useful,\r
12     but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14     GNU General Public License for more details.\r
15 \r
16     You should have received a copy of the GNU General Public License\r
17     along with VOMP; if not, write to the Free Software\r
18     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.\r
19 */\r
20 \r
21 #ifndef PLAYERRADIO_H\r
22 #define PLAYERRADIO_H\r
23 \r
24 #include <stdio.h>\r
25 #include <stdlib.h>\r
26 #ifndef WIN32\r
27 #include <sys/time.h>\r
28 #endif\r
29 #include <time.h>\r
30 \r
31 #include "threadsystem.h"\r
32 \r
33 #include "callback.h"\r
34 #include "defines.h"\r
35 #include "afeed.h"\r
36 \r
37 class Log;\r
38 class Audio;\r
39 class Video;\r
40 class Demuxer;\r
41 class VDR;\r
42 class MessageQueue;\r
43 \r
44 class PlayerRadio : public Thread_TYPE, public Callback\r
45 {\r
46   public:\r
47     PlayerRadio(MessageQueue* messageQueue, void* messageReceiver);\r
48     virtual ~PlayerRadio();\r
49 \r
50     int init(ULLONG lengthBytes, ULONG lengthPackets, bool IsPesRecording);\r
51     int shutdown();\r
52     void setStartBytes(ULLONG startBytes);\r
53 \r
54     void play();\r
55     void stop();\r
56     void pause();\r
57     void playpause();\r
58     void jumpToPercent(double percent);\r
59     void skipForward(UINT seconds);\r
60     void skipBackward(UINT seconds);\r
61 \r
62     UCHAR getState() { return state; }\r
63     ULONG getCurrentSeconds();\r
64     ULONG getLengthSeconds();\r
65 \r
66     void call(void*); // for callback interface\r
67 \r
68     const static UCHAR S_PLAY = 1;\r
69     const static UCHAR S_PAUSE_P = 2;\r
70     const static UCHAR S_STOP = 6;\r
71     const static UCHAR S_JUMP = 7;\r
72 \r
73     // Player events\r
74 \r
75     const static UCHAR CONNECTION_LOST = 1;\r
76     const static UCHAR STOP_PLAYBACK = 2;\r
77     const static UCHAR STREAM_END = 3;\r
78 \r
79   protected:\r
80     void threadMethod();\r
81     void threadPostStopCleanup();\r
82 \r
83   private:\r
84     void switchState(UCHAR newState, ULONG jumpPacket=0);\r
85 \r
86     void threadFeedPlay();\r
87     void threadFeedScan();\r
88 \r
89     void doConnectionLost();\r
90     void restartAtPacket(ULONG newPacket);\r
91     bool setLengthSeconds();\r
92 \r
93     MessageQueue* messageQueue;\r
94     void* messageReceiver;\r
95     Log* logger;\r
96     Audio* audio;\r
97     Demuxer* demuxer;\r
98     VDR* vdr;\r
99     AFeed afeed;\r
100 \r
101     bool initted;\r
102     bool startup;\r
103 \r
104     ULLONG startPTS;\r
105     ULONG lengthSeconds;\r
106 \r
107 #ifndef WIN32\r
108     pthread_mutex_t mutex;\r
109 #else\r
110     HANDLE mutex;\r
111 #endif\r
112     void lock();\r
113     void unLock();\r
114 \r
115     ULLONG lengthBytes;\r
116     ULLONG streamPos;\r
117     ULONG lengthPackets;\r
118     ULONG currentPacketNumber;\r
119     UINT blockSize;\r
120     UINT startupBlockSize;\r
121     UCHAR* threadBuffer;\r
122     UCHAR state;\r
123 };\r
124 \r
125 #endif\r
126 \r
127 \r
128 /*\r
129 \r
130 Possible states:\r
131 \r
132 Play, Pause, FFwd, FBwd, (Stop), [Jump]\r
133 \r
134                     Possible  Working\r
135 \r
136 Play   -> PauseP       *         *\r
137        -> Stop         *         *\r
138        -> Jump         *         *\r
139 \r
140 PauseP -> Play         *         *\r
141        -> Stop         *         *\r
142        -> Jump         *         *\r
143 \r
144 PauseI -> Play         *         *\r
145        -> PauseP\r
146        -> Stop         *         *\r
147        -> Jump         *         *\r
148 \r
149 Stop   -> Play         *         *\r
150        -> PauseP\r
151        -> Jump\r
152 \r
153 Jump   -> Play\r
154        -> PauseP\r
155        -> Stop\r
156 \r
157 */\r