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