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