]> git.vomp.tv Git - vompclient.git/blob - playerradio.h
Update for windows
[vompclient.git] / playerradio.h
1 /*
2     Copyright 2004-2006 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 PLAYERRADIO_H
22 #define PLAYERRADIO_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 "demuxervdr.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 PlayerRadio : public Thread_TYPE, public Callback
47 {
48   public:
49     PlayerRadio(MessageQueue* messageQueue, void* messageReceiver, bool isRecording);
50     virtual ~PlayerRadio();
51
52     int init(ULLONG lengthBytes, ULONG lengthPackets);
53     int shutdown();
54     void setStartBytes(ULLONG startBytes);
55
56     void play();
57     void stop();
58     void pause();
59     void jumpToPercent(int percent);
60     void skipForward(int seconds);
61     void skipBackward(int seconds);
62
63     UCHAR getState() { return state; }
64     ULONG getCurrentSeconds();
65     ULONG getLengthSeconds();
66
67     void call(void*); // for callback interface
68
69     const static UCHAR S_PLAY = 1;
70     const static UCHAR S_PAUSE_P = 2;
71     const static UCHAR S_STOP = 6;
72     const static UCHAR S_JUMP = 7;
73
74     // Player events
75
76     const static UCHAR CONNECTION_LOST = 1;
77     const static UCHAR STOP_PLAYBACK = 2;
78     const static UCHAR STREAM_END = 3;
79
80   protected:
81     void threadMethod();
82     void threadPostStopCleanup();
83
84   private:
85     void switchState(UCHAR newState, ULONG jumpPacket=0);
86
87     void threadFeedLive();
88     void threadFeedPlay();
89     void threadFeedScan();
90
91     void doConnectionLost();
92     void restartAtPacket(ULONG newPacket);
93     bool setLengthSeconds();
94
95     MessageQueue* messageQueue;
96     void* messageReceiver;
97     Log* logger;
98     Audio* audio;
99     Demuxer* demuxer;
100     VDR* vdr;
101     AFeed afeed;
102
103     bool initted;
104     bool startup;
105     bool isRecording;
106     bool preBuffering;
107
108     ULLONG startPTS;
109     ULONG lengthSeconds;
110
111 #ifndef WIN32
112     pthread_mutex_t mutex;
113 #else
114     HANDLE mutex;
115 #endif
116     void lock();
117     void unLock();
118
119     ULLONG lengthBytes;
120     ULLONG streamPos;
121     ULONG lengthPackets;
122     ULONG currentPacketNumber;
123     UINT blockSize;
124     UINT startupBlockSize;
125     UINT preBufferSize;
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   -> PauseP       *         *
142        -> Stop         *         *
143        -> Jump         *         *
144
145 PauseP -> Play         *         *
146        -> Stop         *         *
147        -> Jump         *         *
148
149 PauseI -> Play         *         *
150        -> PauseP
151        -> Stop         *         *
152        -> Jump         *         *
153
154 Stop   -> Play         *         *
155        -> PauseP
156        -> Jump
157
158 Jump   -> Play
159        -> PauseP
160        -> Stop
161
162 */